From 8a4068eb316c4d783eb0c756dda47471383c9f47 Mon Sep 17 00:00:00 2001 From: tmadlener Date: Wed, 27 Sep 2023 12:42:07 +0200 Subject: [PATCH] Mark all utility functionalities inline to avoid linker issues --- tests/src/ComparisonUtils.h | 57 +++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/tests/src/ComparisonUtils.h b/tests/src/ComparisonUtils.h index 1bb565f7..b831e81e 100644 --- a/tests/src/ComparisonUtils.h +++ b/tests/src/ComparisonUtils.h @@ -20,13 +20,13 @@ #include #include -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 -std::ostream& printContainer(std::ostream& os, const T& cont) +inline std::ostream& printContainer(std::ostream& os, const T& cont) { os << "("; if (!cont.empty()) { @@ -40,25 +40,25 @@ std::ostream& printContainer(std::ostream& os, const T& cont) } template -std::ostream& operator<<(std::ostream& os, const std::vector& vec) +inline std::ostream& operator<<(std::ostream& os, const std::vector& vec) { return printContainer(os, vec); } template -std::ostream& operator<<(std::ostream& os, const std::array& arr) +inline std::ostream& operator<<(std::ostream& os, const std::array& arr) { return printContainer(os, arr); } template -std::ostream& operator<<(std::ostream& os, const podio::RelationRange& range) +inline std::ostream& operator<<(std::ostream& os, const podio::RelationRange& range) { return printContainer(os, range); } template -bool operator==(const std::vector& vec, const std::array& arr) +inline bool operator==(const std::vector& vec, const std::array& arr) { if (vec.size() != N) { return false; @@ -72,13 +72,13 @@ bool operator==(const std::vector& vec, const std::array& arr) } template -bool operator!=(const std::vector& vec, const std::array& arr) +inline bool operator!=(const std::vector& vec, const std::array& arr) { return !(vec == arr); } template -bool operator==(const std::vector& vec, const podio::RelationRange& range) +inline bool operator==(const std::vector& vec, const podio::RelationRange& range) { if (vec.size() != range.size()) { return false; @@ -92,13 +92,13 @@ bool operator==(const std::vector& vec, const podio::RelationRange& range) } template -bool operator!=(const std::vector& vec, const podio::RelationRange& range) +inline bool operator!=(const std::vector& vec, const podio::RelationRange& range) { return !(vec == range); } template -bool nanSafeComp(T x, U y) +inline bool nanSafeComp(T x, U y) { return (x == y) || (std::isnan(x) && std::isnan(y)); } @@ -106,19 +106,19 @@ bool nanSafeComp(T x, U y) // Macro for defining the comparison operators for edm4hep::Vector3X and // different return types (X* or vector 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& vals, const VT& vec) \ + inline bool operator!=(const FT* vals, const VT& vec) { return !(vals == vec); } \ + inline bool operator==(const std::vector& vals, const VT& vec) \ { \ if (vals.size() != 3) { \ return false; \ } \ return vals.data() == vec; \ } \ - bool operator!=(const std::vector& vals, const VT& vec) { return !(vals == vec); } + inline bool operator!=(const std::vector& vals, const VT& vec) { return !(vals == vec); } VECTOR3_COMPARE(float, edm4hep::Vector3f) VECTOR3_COMPARE(double, edm4hep::Vector3d) @@ -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 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& vals, const VT& vec) \ - { \ - if (vals.size() != 2) { \ - return false; \ - } \ - return vals.data() == vec; \ - } \ - bool operator!=(const std::vector& 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& vals, const VT& vec) \ + { \ + if (vals.size() != 2) { \ + return false; \ + } \ + return vals.data() == vec; \ + } \ + inline bool operator!=(const std::vector& vals, const VT& vec) { return !(vals == vec); } VECTOR2_COMPARE(int, edm4hep::Vector2i) VECTOR2_COMPARE(float, edm4hep::Vector2f) @@ -164,7 +164,8 @@ VECTOR2_COMPARE(float, edm4hep::Vector2f) * correct EDM4hep element (using the ObjectIDs) */ template -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; @@ -193,7 +194,7 @@ bool compareRelation(const LcioT* lcioElem, const EDM4hepT& edm4hepElem, const M * that dispatches this. */ template -bool compareRelation( +inline bool compareRelation( const std::vector& lcioRange, const podio::RelationRange& edm4hepRange, const MapT& objectMap, @@ -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 -bool compareCollection( +inline bool compareCollection( const lcio::LCCollection* lcioCollection, const EDM4hepCollT& edm4hepCollection, const ObjectMappings& objectMaps)