From 760b9584b392f0f8acb07ea5bb232ab5edca649f Mon Sep 17 00:00:00 2001 From: tmadlener Date: Thu, 16 May 2024 13:16:08 +0200 Subject: [PATCH] Transparently switch to optional parameter values --- .../k4EDM4hep2LcioConv/k4EDM4hep2LcioConv.h | 34 +++++++----- .../k4EDM4hep2LcioConv/k4EDM4hep2LcioConv.ipp | 55 +++++++++++++++---- 2 files changed, 64 insertions(+), 25 deletions(-) diff --git a/k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4EDM4hep2LcioConv.h b/k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4EDM4hep2LcioConv.h index 5115c59..1bde0d0 100644 --- a/k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4EDM4hep2LcioConv.h +++ b/k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4EDM4hep2LcioConv.h @@ -36,6 +36,7 @@ using TrackerHit3D = edm4hep::TrackerHit; #include #include "podio/Frame.h" +#include "podio/podioVersion.h" // LCIO #include @@ -74,6 +75,12 @@ using ObjectMapT = k4EDM4hep2LcioConv::VecMapT; template using vec_pair [[deprecated("Use a more descriptive alias")]] = ObjectMapT; +#if PODIO_BUILD_VERSION > PODIO_VERSION(0, 99, 0) +using CellIDStrType = const std::optional; +#else +using CellIDStrType = const std::string; +#endif + struct CollectionsPairVectors { ObjectMapT tracks{}; ObjectMapT trackerHits{}; @@ -144,11 +151,12 @@ convTracks(const edm4hep::TrackCollection* const tracks_coll, TrackMapT& tracks_ */ template std::unique_ptr convertTrackerHits(const edm4hep::TrackerHit3DCollection* const edmCollection, - const std::string& cellIDStr, TrackerHitMapT& trackerHitMap); + const CellIDStrType& cellIDStr, + TrackerHitMapT& trackerHitMap); template [[deprecated("Use convertTrackerHits instead")]] lcio::LCCollectionVec* -convTrackerHits(const edm4hep::TrackerHit3DCollection* const trackerhits_coll, const std::string& cellIDstr, +convTrackerHits(const edm4hep::TrackerHit3DCollection* const trackerhits_coll, const CellIDStrType& cellIDstr, TrackerHitMapT& trackerhits_vec) { return convertTrackerHits(trackerhits_coll, cellIDstr, trackerhits_vec).release(); } @@ -159,12 +167,12 @@ convTrackerHits(const edm4hep::TrackerHit3DCollection* const trackerhits_coll, c */ template std::unique_ptr -convertTrackerHitPlanes(const edm4hep::TrackerHitPlaneCollection* const edmCollection, const std::string& cellIDstr, +convertTrackerHitPlanes(const edm4hep::TrackerHitPlaneCollection* const edmCollection, const CellIDStrType& cellIDstr, TrackerHitPlaneMapT& trackerHitsMap); template [[deprecated("Use convertTrackerHitPlanes instead")]] lcio::LCCollectionVec* -convTrackerHitPlanes(const edm4hep::TrackerHitPlaneCollection* const trackerhits_coll, const std::string& cellIDstr, +convTrackerHitPlanes(const edm4hep::TrackerHitPlaneCollection* const trackerhits_coll, const CellIDStrType& cellIDstr, TrackerHitPlaneMapT& trackerhits_vec) { return convertTrackerHitPlanes(trackerhits_coll, cellIDstr, trackerhits_vec).release(); } @@ -175,12 +183,12 @@ convTrackerHitPlanes(const edm4hep::TrackerHitPlaneCollection* const trackerhits */ template std::unique_ptr -convertSimTrackerHits(const edm4hep::SimTrackerHitCollection* const edmCollection, const std::string& cellIDstr, +convertSimTrackerHits(const edm4hep::SimTrackerHitCollection* const edmCollection, const CellIDStrType& cellIDstr, SimTrHitMapT& simTrHitMap); template [[deprecated("Use convertSimTrackerHits instead")]] lcio::LCCollectionVec* -convSimTrackerHits(const edm4hep::SimTrackerHitCollection* const simtrackerhits_coll, const std::string& cellIDstr, +convSimTrackerHits(const edm4hep::SimTrackerHitCollection* const simtrackerhits_coll, const CellIDStrType& cellIDstr, SimTrHitMapT& simtrackerhits_vec, const MCParticleMapT&) { return convertSimTrackerHits(simtrackerhits_coll, cellIDstr, simtrackerhits_vec).release(); } @@ -191,12 +199,12 @@ convSimTrackerHits(const edm4hep::SimTrackerHitCollection* const simtrackerhits_ */ template std::unique_ptr -convertCalorimeterHits(const edm4hep::CalorimeterHitCollection* const edmCollection, const std::string& cellIDstr, +convertCalorimeterHits(const edm4hep::CalorimeterHitCollection* const edmCollection, const CellIDStrType& cellIDstr, CaloHitMapT& caloHitMap); template [[deprecated("Use convertCalorimeterHits instead")]] lcio::LCCollectionVec* -convCalorimeterHits(const edm4hep::CalorimeterHitCollection* const calohit_coll, const std::string& cellIDstr, +convCalorimeterHits(const edm4hep::CalorimeterHitCollection* const calohit_coll, const CellIDStrType& cellIDstr, CaloHitMapT& calo_hits_vec) { return convertCalorimeterHits(calohit_coll, cellIDstr, calo_hits_vec).release(); } @@ -223,19 +231,19 @@ convRawCalorimeterHits(const edm4hep::RawCalorimeterHitCollection* const rawcalo */ template std::unique_ptr -convertSimCalorimeterHits(const edm4hep::SimCalorimeterHitCollection* const edmCollection, const std::string& cellIDstr, - SimCaloHitMapT& simCaloHitMap); +convertSimCalorimeterHits(const edm4hep::SimCalorimeterHitCollection* const edmCollection, + const CellIDStrType& cellIDstr, SimCaloHitMapT& simCaloHitMap); template lcio::LCCollectionVec* convSimCalorimeterHits(const edm4hep::SimCalorimeterHitCollection* const simcalohit_coll, - const std::string& cellIDstr, SimCaloHitMapT& sim_calo_hits_vec) { + const CellIDStrType& cellIDstr, SimCaloHitMapT& sim_calo_hits_vec) { return convertSimCalorimeterHits(simcalohit_coll, cellIDstr, sim_calo_hits_vec).release(); } template [[deprecated("remove MCParticleMap argument since it is unused")]] lcio::LCCollectionVec* -convSimCalorimeterHits(const edm4hep::SimCalorimeterHitCollection* const simcalohit_coll, const std::string& cellIDstr, - SimCaloHitMapT& sim_calo_hits_vec, const MCParticleMapT&) { +convSimCalorimeterHits(const edm4hep::SimCalorimeterHitCollection* const simcalohit_coll, + const CellIDStrType& cellIDstr, SimCaloHitMapT& sim_calo_hits_vec, const MCParticleMapT&) { return convSimCalorimeterHits(simcalohit_coll, cellIDstr, sim_calo_hits_vec); } diff --git a/k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4EDM4hep2LcioConv.ipp b/k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4EDM4hep2LcioConv.ipp index 434f503..cf26fe5 100644 --- a/k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4EDM4hep2LcioConv.ipp +++ b/k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4EDM4hep2LcioConv.ipp @@ -65,12 +65,19 @@ std::unique_ptr convertTracks(const edm4hep::TrackCollect template std::unique_ptr convertTrackerHits(const edm4hep::TrackerHit3DCollection* const edmColection, - const std::string& cellIDstr, TrackerHitMapT& trackerHitMap) { + const CellIDStrType& cellIDstr, + TrackerHitMapT& trackerHitMap) { auto trackerhits = std::make_unique(lcio::LCIO::TRACKERHIT); - if (cellIDstr != "") { +#if PODIO_BUILD_VERSION > PODIO_VERSION(0, 99, 0) + if (cellIDstr.has_value()) { + lcio::CellIDEncoder idEnc(cellIDstr.value(), trackerhits.get()); + } +#else + if (!cellIDstr.empty()) { lcio::CellIDEncoder idEnc(cellIDstr, trackerhits.get()); } +#endif // Loop over EDM4hep trackerhits converting them to lcio trackerhits for (const auto& edm_trh : (*edmColection)) { @@ -103,13 +110,19 @@ std::unique_ptr convertTrackerHits(const edm4hep::Tracker template std::unique_ptr -convertTrackerHitPlanes(const edm4hep::TrackerHitPlaneCollection* const edmCollection, const std::string& cellIDstr, +convertTrackerHitPlanes(const edm4hep::TrackerHitPlaneCollection* const edmCollection, const CellIDStrType& cellIDstr, TrackerHitPlaneMapT& trackerHitsMap) { auto trackerHitPlanes = std::make_unique(lcio::LCIO::TRACKERHITPLANE); - if (cellIDstr != "") { +#if PODIO_BUILD_VERSION > PODIO_VERSION(0, 99, 0) + if (cellIDstr.has_value()) { + lcio::CellIDEncoder idEnc(cellIDstr.value(), trackerHitPlanes.get()); + } +#else + if (!cellIDstr.empty()) { lcio::CellIDEncoder idEnc(cellIDstr, trackerHitPlanes.get()); } +#endif for (const auto& edm_trh : (*edmCollection)) { if (edm_trh.isAvailable()) { @@ -147,13 +160,19 @@ convertTrackerHitPlanes(const edm4hep::TrackerHitPlaneCollection* const edmColle template std::unique_ptr -convertSimTrackerHits(const edm4hep::SimTrackerHitCollection* const edmCollection, const std::string& cellIDstr, +convertSimTrackerHits(const edm4hep::SimTrackerHitCollection* const edmCollection, const CellIDStrType& cellIDstr, SimTrHitMapT& simTrHitMap) { auto simtrackerhits = std::make_unique(lcio::LCIO::SIMTRACKERHIT); - if (cellIDstr != "") { - lcio::CellIDEncoder idEnc(cellIDstr, simtrackerhits.get()); +#if PODIO_BUILD_VERSION > PODIO_VERSION(0, 99, 0) + if (cellIDstr.has_value()) { + lcio::CellIDEncoder idEnc(cellIDstr.value(), simtrackerhits.get()); + } +#else + if (!cellIDstr.empty()) { + lcio::CellIDEncoder idEnc(cellIDstr, simtrackerhits.get()); } +#endif // Loop over EDM4hep simtrackerhits converting them to LCIO simtrackerhits for (const auto& edm_strh : (*edmCollection)) { @@ -191,13 +210,19 @@ convertSimTrackerHits(const edm4hep::SimTrackerHitCollection* const edmCollectio // Add converted LCIO Collection Vector to LCIO event template std::unique_ptr -convertCalorimeterHits(const edm4hep::CalorimeterHitCollection* const edmCollection, const std::string& cellIDstr, +convertCalorimeterHits(const edm4hep::CalorimeterHitCollection* const edmCollection, const CellIDStrType& cellIDstr, CaloHitMapT& caloHitMap) { auto calohits = std::make_unique(lcio::LCIO::CALORIMETERHIT); - if (cellIDstr != "") { +#if PODIO_BUILD_VERSION > PODIO_VERSION(0, 99, 0) + if (cellIDstr.has_value()) { + lcio::CellIDEncoder idEnc(cellIDstr.value(), calohits.get()); + } +#else + if (!cellIDstr.empty()) { lcio::CellIDEncoder idEnc(cellIDstr, calohits.get()); } +#endif for (const auto& edm_calohit : (*edmCollection)) { if (edm_calohit.isAvailable()) { @@ -259,13 +284,19 @@ convertRawCalorimeterHits(const edm4hep::RawCalorimeterHitCollection* const edmC template std::unique_ptr -convertSimCalorimeterHits(const edm4hep::SimCalorimeterHitCollection* const edmCollection, const std::string& cellIDstr, - SimCaloHitMapT& simCaloHitMap) { +convertSimCalorimeterHits(const edm4hep::SimCalorimeterHitCollection* const edmCollection, + const CellIDStrType& cellIDstr, SimCaloHitMapT& simCaloHitMap) { auto simcalohits = std::make_unique(lcio::LCIO::SIMCALORIMETERHIT); - if (cellIDstr != "") { +#if PODIO_BUILD_VERSION > PODIO_VERSION(0, 99, 0) + if (cellIDstr.has_value()) { + lcio::CellIDEncoder idEnc(cellIDstr.value(), simcalohits.get()); + } +#else + if (!cellIDstr.empty()) { lcio::CellIDEncoder idEnc(cellIDstr, simcalohits.get()); } +#endif for (const auto& edm_sim_calohit : (*edmCollection)) { if (edm_sim_calohit.isAvailable()) {