Skip to content

Commit

Permalink
Mark all utility functionalities inline to avoid linker issues
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Sep 27, 2023
1 parent d088d6c commit 8a4068e
Showing 1 changed file with 29 additions and 28 deletions.
57 changes: 29 additions & 28 deletions tests/src/ComparisonUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
#include <vector>
#include <algorithm>

std::ostream& operator<<(std::ostream& os, const podio::ObjectID id)
inline std::ostream& operator<<(std::ostream& os, const podio::ObjectID id)
{
return os << "[" << id.collectionID << ": " << id.index << "]";
}

template<typename T>
std::ostream& printContainer(std::ostream& os, const T& cont)
inline std::ostream& printContainer(std::ostream& os, const T& cont)
{
os << "(";
if (!cont.empty()) {
Expand All @@ -40,25 +40,25 @@ std::ostream& printContainer(std::ostream& os, const T& cont)
}

template<typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec)
inline std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec)
{
return printContainer(os, vec);
}

template<typename T, size_t N>
std::ostream& operator<<(std::ostream& os, const std::array<T, N>& arr)
inline std::ostream& operator<<(std::ostream& os, const std::array<T, N>& arr)
{
return printContainer(os, arr);
}

template<typename T>
std::ostream& operator<<(std::ostream& os, const podio::RelationRange<T>& range)
inline std::ostream& operator<<(std::ostream& os, const podio::RelationRange<T>& range)
{
return printContainer(os, range);
}

template<typename T, size_t N>
bool operator==(const std::vector<T>& vec, const std::array<T, N>& arr)
inline bool operator==(const std::vector<T>& vec, const std::array<T, N>& arr)
{
if (vec.size() != N) {
return false;
Expand All @@ -72,13 +72,13 @@ bool operator==(const std::vector<T>& vec, const std::array<T, N>& arr)
}

template<typename T, size_t N>
bool operator!=(const std::vector<T>& vec, const std::array<T, N>& arr)
inline bool operator!=(const std::vector<T>& vec, const std::array<T, N>& arr)
{
return !(vec == arr);
}

template<typename T>
bool operator==(const std::vector<T>& vec, const podio::RelationRange<T>& range)
inline bool operator==(const std::vector<T>& vec, const podio::RelationRange<T>& range)
{
if (vec.size() != range.size()) {
return false;
Expand All @@ -92,33 +92,33 @@ bool operator==(const std::vector<T>& vec, const podio::RelationRange<T>& range)
}

template<typename T>
bool operator!=(const std::vector<T>& vec, const podio::RelationRange<T>& range)
inline bool operator!=(const std::vector<T>& vec, const podio::RelationRange<T>& range)
{
return !(vec == range);
}

template<typename T, typename U>
bool nanSafeComp(T x, U y)
inline bool nanSafeComp(T x, U y)
{
return (x == y) || (std::isnan(x) && std::isnan(y));
}

// Macro for defining the comparison operators for edm4hep::Vector3X and
// different return types (X* or vector<X> from LCIO)
#define VECTOR3_COMPARE(FT, VT) \
bool operator==(const FT* vals, const VT& vec) \
inline bool operator==(const FT* vals, const VT& vec) \
{ \
return nanSafeComp(vals[0], vec[0]) && nanSafeComp(vals[1], vec[1]) && nanSafeComp(vals[2], vec[2]); \
} \
bool operator!=(const FT* vals, const VT& vec) { return !(vals == vec); } \
bool operator==(const std::vector<FT>& vals, const VT& vec) \
inline bool operator!=(const FT* vals, const VT& vec) { return !(vals == vec); } \
inline bool operator==(const std::vector<FT>& vals, const VT& vec) \
{ \
if (vals.size() != 3) { \
return false; \
} \
return vals.data() == vec; \
} \
bool operator!=(const std::vector<FT>& vals, const VT& vec) { return !(vals == vec); }
inline bool operator!=(const std::vector<FT>& vals, const VT& vec) { return !(vals == vec); }

VECTOR3_COMPARE(float, edm4hep::Vector3f)
VECTOR3_COMPARE(double, edm4hep::Vector3d)
Expand All @@ -128,17 +128,17 @@ VECTOR3_COMPARE(double, edm4hep::Vector3f)

// Macro for defining the comparison operators for edm4hep::Vector3X and
// different return types (X* or vector<X> from LCIO)
#define VECTOR2_COMPARE(FT, VT) \
bool operator==(const FT* vals, const VT& vec) { return vals[0] == vec[0] && vals[1] == vec[1]; } \
bool operator!=(const FT* vals, const VT& vec) { return !(vals == vec); } \
bool operator==(const std::vector<FT>& vals, const VT& vec) \
{ \
if (vals.size() != 2) { \
return false; \
} \
return vals.data() == vec; \
} \
bool operator!=(const std::vector<FT>& vals, const VT& vec) { return !(vals == vec); }
#define VECTOR2_COMPARE(FT, VT) \
inline bool operator==(const FT* vals, const VT& vec) { return vals[0] == vec[0] && vals[1] == vec[1]; } \
inline bool operator!=(const FT* vals, const VT& vec) { return !(vals == vec); } \
inline bool operator==(const std::vector<FT>& vals, const VT& vec) \
{ \
if (vals.size() != 2) { \
return false; \
} \
return vals.data() == vec; \
} \
inline bool operator!=(const std::vector<FT>& vals, const VT& vec) { return !(vals == vec); }

VECTOR2_COMPARE(int, edm4hep::Vector2i)
VECTOR2_COMPARE(float, edm4hep::Vector2f)
Expand All @@ -164,7 +164,8 @@ VECTOR2_COMPARE(float, edm4hep::Vector2f)
* correct EDM4hep element (using the ObjectIDs)
*/
template<typename LcioT, typename EDM4hepT, typename MapT>
bool compareRelation(const LcioT* lcioElem, const EDM4hepT& edm4hepElem, const MapT& objectMap, const std::string& msg)
inline bool
compareRelation(const LcioT* lcioElem, const EDM4hepT& edm4hepElem, const MapT& objectMap, const std::string& msg)
{
if (lcioElem == nullptr && edm4hepElem.isAvailable()) {
std::cerr << msg << " LCIO element is empty but edm4hep element is not" << std::endl;
Expand Down Expand Up @@ -193,7 +194,7 @@ bool compareRelation(const LcioT* lcioElem, const EDM4hepT& edm4hepElem, const M
* that dispatches this.
*/
template<typename LcioT, typename EDM4hepT, typename MapT>
bool compareRelation(
inline bool compareRelation(
const std::vector<LcioT*>& lcioRange,
const podio::RelationRange<EDM4hepT>& edm4hepRange,
const MapT& objectMap,
Expand Down Expand Up @@ -231,7 +232,7 @@ bool compareRelation(
// Compare an LCIO collection and an EDM4hep collection. Assumes that a compare
// function working with the element types is available
template<typename LCIOT, typename EDM4hepCollT>
bool compareCollection(
inline bool compareCollection(
const lcio::LCCollection* lcioCollection,
const EDM4hepCollT& edm4hepCollection,
const ObjectMappings& objectMaps)
Expand Down

0 comments on commit 8a4068e

Please sign in to comment.