From c6c7aa3b136bee6e42bd552e516d8416ed2ea5ed Mon Sep 17 00:00:00 2001 From: tmadlener Date: Tue, 20 Feb 2024 19:30:58 +0100 Subject: [PATCH] Fix most warnings in tests --- tests/compare_contents.cpp | 2 +- tests/src/CompareEDM4hepLCIO.cc | 32 ++++++++++++------------------ tests/src/ComparisonUtils.h | 8 +++----- tests/src/EDM4hep2LCIOUtilities.cc | 18 ++++++++--------- tests/src/EDM4hep2LCIOUtilities.h | 4 ++-- 5 files changed, 28 insertions(+), 36 deletions(-) diff --git a/tests/compare_contents.cpp b/tests/compare_contents.cpp index 9df07909..3977efc5 100644 --- a/tests/compare_contents.cpp +++ b/tests/compare_contents.cpp @@ -68,7 +68,7 @@ int main(int argc, char* argv[]) return 1; } - if (edmEvent.get(name)->size() != lcioColl->getNumberOfElements()) { + if (edmEvent.get(name)->size() != (unsigned) lcioColl->getNumberOfElements()) { std::cerr << "Collection " << name << " has different sizes. LCIO: " << lcioColl->getNumberOfElements() << ", EDM4hep: " << coll->size() << std::endl; return 1; diff --git a/tests/src/CompareEDM4hepLCIO.cc b/tests/src/CompareEDM4hepLCIO.cc index 0b86d8d8..56077782 100644 --- a/tests/src/CompareEDM4hepLCIO.cc +++ b/tests/src/CompareEDM4hepLCIO.cc @@ -35,10 +35,7 @@ auto to64BitCellID(LcioT* obj) // ================= CalorimeterHit ================ -bool compare( - const EVENT::CalorimeterHit* lcioElem, - const edm4hep::CalorimeterHit& edm4hepElem, - const ObjectMappings& objectMaps) +bool compare(const EVENT::CalorimeterHit* lcioElem, const edm4hep::CalorimeterHit& edm4hepElem, const ObjectMappings&) { const auto lcioCellID = to64BitCellID(lcioElem); ASSERT_COMPARE_VALS(lcioCellID, edm4hepElem.getCellID(), "cellID in CalorimeterHit"); @@ -155,7 +152,7 @@ bool compare(const EVENT::ParticleID* lcioElem, const edm4hep::ParticleID& edm4h bool compare( const EVENT::RawCalorimeterHit* lcioElem, const edm4hep::RawCalorimeterHit& edm4hepElem, - const ObjectMappings& objectMaps) + const ObjectMappings&) { const auto lcioCellID = to64BitCellID(lcioElem); ASSERT_COMPARE_VALS(lcioCellID, edm4hepElem.getCellID(), "cellID in RawCalorimeterHit"); @@ -250,7 +247,8 @@ bool compare( // Contributions are not part of the "proper LCIO" const auto edmContributions = edm4hepElem.getContributions(); - ASSERT_COMPARE_VALS(lcioElem->getNMCContributions(), edmContributions.size(), "number of CaloHitContributions"); + ASSERT_COMPARE_VALS( + (unsigned) lcioElem->getNMCContributions(), edmContributions.size(), "number of CaloHitContributions"); for (int iCont = 0; iCont < lcioElem->getNMCContributions(); ++iCont) { const auto& edmContrib = edmContributions[iCont]; @@ -290,7 +288,8 @@ bool compare( const edm4hep::SimTrackerHit& edm4hepElem, const ObjectMappings& objectMaps) { - ASSERT_COMPARE(lcioElem, edm4hepElem, getCellID, "cellID in SimTrackerHit"); + const auto lcioCellID = to64BitCellID(lcioElem); + ASSERT_COMPARE_VALS(lcioCellID, edm4hepElem.getCellID(), "cellID in SimTrackerHit"); ASSERT_COMPARE(lcioElem, edm4hepElem, getEDep, "EDep in SimTrackerHit"); ASSERT_COMPARE(lcioElem, edm4hepElem, getTime, "time in SimTrackerHit"); ASSERT_COMPARE(lcioElem, edm4hepElem, getPathLength, "pathLength in SimTrackerHit"); @@ -313,9 +312,10 @@ bool compare( // ================= TPCHit ================ -bool compare(const EVENT::TPCHit* lcioElem, const edm4hep::RawTimeSeries& edm4hepElem, const ObjectMappings& objectMaps) +bool compare(const EVENT::TPCHit* lcioElem, const edm4hep::RawTimeSeries& edm4hepElem, const ObjectMappings&) { - ASSERT_COMPARE(lcioElem, edm4hepElem, getCellID, "cellID in TPCHit"); + const uint64_t lcioCellID = lcioElem->getCellID(); + ASSERT_COMPARE_VALS(lcioCellID, edm4hepElem.getCellID(), "cellID in TPCHit"); ASSERT_COMPARE(lcioElem, edm4hepElem, getQuality, "quality in TPCHit"); ASSERT_COMPARE(lcioElem, edm4hepElem, getTime, "time in TPCHit"); ASSERT_COMPARE(lcioElem, edm4hepElem, getCharge, "charge in TPCHit"); @@ -412,10 +412,7 @@ bool compare( // ================= TrackerHit ================ -bool compare( - const EVENT::TrackerHit* lcioElem, - const edm4hep::TrackerHit3D& edm4hepElem, - const ObjectMappings& objectMaps) +bool compare(const EVENT::TrackerHit* lcioElem, const edm4hep::TrackerHit3D& edm4hepElem, const ObjectMappings&) { const auto lcioCellID = to64BitCellID(lcioElem); ASSERT_COMPARE_VALS(lcioCellID, edm4hepElem.getCellID(), "cellID in TrackerHit"); @@ -440,10 +437,7 @@ bool compare( // ================= TrackerHitPlane ================ -bool compare( - const EVENT::TrackerHitPlane* lcioElem, - const edm4hep::TrackerHitPlane& edm4hepElem, - const ObjectMappings& objectMaps) +bool compare(const EVENT::TrackerHitPlane* lcioElem, const edm4hep::TrackerHitPlane& edm4hepElem, const ObjectMappings&) { const auto lcioCellID = to64BitCellID(lcioElem); ASSERT_COMPARE_VALS(lcioCellID, edm4hepElem.getCellID(), "cellID in TrackerHitPlane"); @@ -503,12 +497,12 @@ bool compare( bool compareEventHeader(const EVENT::LCEvent* lcevt, const podio::Frame* edmEvent) { - const auto& edmEventHeader = edmEvent->get("EventHeader")[0]; ASSERT_COMPARE(lcevt, edmEventHeader, getEventNumber, "Event Number is not the same"); ASSERT_COMPARE(lcevt, edmEventHeader, getRunNumber, "Run Number is not the same"); - ASSERT_COMPARE(lcevt, edmEventHeader, getTimeStamp, "TimeStamp in EventHeader is not the same"); + const uint64_t lcioTimeStamp = lcevt->getTimeStamp(); + ASSERT_COMPARE_VALS(lcioTimeStamp, edmEventHeader.getTimeStamp(), "TimeStamp in EventHeader is not the same"); ASSERT_COMPARE(lcevt, edmEventHeader, getWeight, "Weight in EventHeader is not the same"); return true; diff --git a/tests/src/ComparisonUtils.h b/tests/src/ComparisonUtils.h index a98619e4..b022b7d1 100644 --- a/tests/src/ComparisonUtils.h +++ b/tests/src/ComparisonUtils.h @@ -59,12 +59,10 @@ inline bool nanSafeComp(T x, U y) // Only enable for vectors template -struct has_size_method : std::false_type { -}; +struct has_size_method : std::false_type {}; template -struct has_size_method().size())>> : std::true_type { -}; +struct has_size_method().size())>> : std::true_type {}; template constexpr bool isAnyOf = (std::is_same_v || ...); @@ -178,7 +176,7 @@ inline bool compareRelation( // not fill relations if the original relations in LCIO were empty const auto nonNullLcio = std::count_if(lcioRange.begin(), lcioRange.end(), [](const auto e) { return e != nullptr; }); - if (nonNullLcio != edm4hepRange.size()) { + if ((unsigned) nonNullLcio != edm4hepRange.size()) { std::cerr << msg << " different sizes (even after taking null values into account)" << std::endl; return false; } diff --git a/tests/src/EDM4hep2LCIOUtilities.cc b/tests/src/EDM4hep2LCIOUtilities.cc index 6f09e6b4..f760294c 100644 --- a/tests/src/EDM4hep2LCIOUtilities.cc +++ b/tests/src/EDM4hep2LCIOUtilities.cc @@ -47,8 +47,8 @@ constexpr auto createCov() return i * (2 * N - i - 1) / 2 + j; }; - for (int i = 0; i < N; ++i) { - for (int j = 0; j < i; ++j) { + for (auto i = 0u; i < N; ++i) { + for (auto j = 0u; j < i; ++j) { const auto index = to_lower_tri(i, j); result[index] = i + 10 * j; } @@ -313,11 +313,11 @@ edm4hep::ClusterCollection createClusters( } } - for (const auto [cluIdx, hitIdx] : clusterHitIdcs) { + for (const auto& [cluIdx, hitIdx] : clusterHitIdcs) { clusterColl[cluIdx].addToHits(caloHits[hitIdx]); } - for (const auto [targetI, sourceI] : clusterHitIdcs) { + for (const auto& [targetI, sourceI] : clusterClusterIdcs) { clusterColl[targetI].addToClusters(clusterColl[sourceI]); } @@ -332,11 +332,11 @@ podio::Frame createExampleEvent() const auto& mcParticles = event.put(createMCParticles(test_config::nMCParticles, test_config::mcpParentIdcs), "mcParticles"); const auto& caloHits = event.put(createCalorimeterHits(test_config::nCaloHits), "caloHits"); - const auto& rawCaloHits = event.put(createRawCalorimeterHits(test_config::nRawCaloHits), "rawCaloHits"); - const auto& tpcHits = event.put(createTPCHits(test_config::nTPCHits, test_config::nTPCRawWords), "tpcHits"); + event.put(createRawCalorimeterHits(test_config::nRawCaloHits), "rawCaloHits"); + event.put(createTPCHits(test_config::nTPCHits, test_config::nTPCRawWords), "tpcHits"); const auto& trackerHits = event.put(createTrackerHits(test_config::nTrackerHits), "trackerHits"); - const auto& trackerHitPlanes = event.put(createTrackerHitPlanes(test_config::nTrackerHits), "trackerHitPlanes"); - const auto& tracks = event.put( + event.put(createTrackerHitPlanes(test_config::nTrackerHits), "trackerHitPlanes"); + event.put( createTracks( test_config::nTracks, test_config::nSubdetectorHitNumbers, @@ -356,7 +356,7 @@ podio::Frame createExampleEvent() auto [tmpSimCaloHits, tmpCaloHitConts] = createSimCalorimeterHits( test_config::nSimCaloHits, test_config::nCaloHitContributions, mcParticles, test_config::simCaloHitMCIdcs); - const auto& simCaloHits = event.put(std::move(tmpSimCaloHits), "simCaloHits"); + event.put(std::move(tmpSimCaloHits), "simCaloHits"); event.put(std::move(tmpCaloHitConts), "caloHitContributions"); return event; diff --git a/tests/src/EDM4hep2LCIOUtilities.h b/tests/src/EDM4hep2LCIOUtilities.h index b4cda5df..3b93f770 100644 --- a/tests/src/EDM4hep2LCIOUtilities.h +++ b/tests/src/EDM4hep2LCIOUtilities.h @@ -35,7 +35,7 @@ namespace podio { namespace test_config { constexpr static int nMCParticles = 5; ///< The number of MCParticles to generate - using IdxPair = std::pair; + using IdxPair = std::pair; /// How to create the MC particle hierarchy, e.g. {4, 0} means that mc[4] will /// have mc[0] as a parent, and mc[0] will get mc[4] as a daughter const static std::vector mcpParentIdcs = {{4, 0}, {4, 1}, {3, 2}, {3, 0}, {3, 1}, {2, 1}}; @@ -61,7 +61,7 @@ namespace test_config { constexpr static int nCaloHitContributions = 4; ///< The number of CalorimeterHit Contributions /// idcs to setup relations between SimCalorimeterHits, CaloHitContributions /// and MCParticles (in this order) - using CaloContIdx = std::tuple; + using CaloContIdx = std::tuple; /// The index values to use for setting up the relations const static std::vector simCaloHitMCIdcs = { {0, 0, 0},