diff --git a/k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4EDM4hep2LcioConv.h b/k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4EDM4hep2LcioConv.h index b2bfc9c7..568165ce 100644 --- a/k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4EDM4hep2LcioConv.h +++ b/k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4EDM4hep2LcioConv.h @@ -60,81 +60,103 @@ namespace edm4hep { #include template -using vec_pair = k4EDM4hep2LcioConv::VecMapT; +using TypeMapT = k4EDM4hep2LcioConv::MapT; struct CollectionsPairVectors { - vec_pair tracks; - vec_pair trackerhits; - vec_pair simtrackerhits; - vec_pair calohits; - vec_pair rawcalohits; - vec_pair simcalohits; - vec_pair tpchits; - vec_pair clusters; - vec_pair vertices; - vec_pair recoparticles; - vec_pair mcparticles; + TypeMapT tracks {}; + TypeMapT trackerhits {}; + TypeMapT simtrackerhits {}; + TypeMapT calohits {}; + TypeMapT rawcalohits {}; + TypeMapT simcalohits {}; + TypeMapT tpchits {}; + TypeMapT clusters {}; + TypeMapT vertices {}; + TypeMapT recoparticles {}; + TypeMapT mcparticles {}; }; +template< + typename TrackMapT = TypeMapT, + typename TrackerHitMapT = TypeMapT> lcio::LCCollectionVec* convTracks( const edm4hep::TrackCollection* const tracks_coll, - vec_pair& tracks_vec, - const vec_pair& trackerhits_vec); + TrackMapT& tracks_vec, + const TrackerHitMapT& trackerhits_vec); +template> lcio::LCCollectionVec* convTrackerHits( const edm4hep::TrackerHitCollection* const trackerhits_coll, const std::string cellIDstr, - vec_pair& trackerhits_vec); + TrackerHitMapT& trackerhits_vec); +template< + typename SimTrHitMapT = TypeMapT, + typename MCParticleMapT = TypeMapT> lcio::LCCollectionVec* convSimTrackerHits( const edm4hep::SimTrackerHitCollection* const simtrackerhits_coll, const std::string cellIDstr, - vec_pair& simtrackerhits_vec, - const vec_pair& mcparticles_vec); + SimTrHitMapT& simtrackerhits_vec, + const MCParticleMapT& mcparticles_vec); +template> lcio::LCCollectionVec* convCalorimeterHits( const edm4hep::CalorimeterHitCollection* const calohit_coll, const std::string cellIDstr, - vec_pair& calo_hits_vec); + CaloHitMapT& calo_hits_vec); +template> lcio::LCCollectionVec* convRawCalorimeterHits( const edm4hep::RawCalorimeterHitCollection* const rawcalohit_coll, - vec_pair& raw_calo_hits_vec); + RawCaloHitMapT& raw_calo_hits_vec); +template> lcio::LCCollectionVec* convSimCalorimeterHits( const edm4hep::SimCalorimeterHitCollection* const simcalohit_coll, const std::string cellIDstr, - vec_pair& sim_calo_hits_vec, - const vec_pair& mcparticles); + SimCaloHitMapT& sim_calo_hits_vec, + const MCParticleMapT& mcparticles); -lcio::LCCollectionVec* convTPCHits( - const edm4hep::RawTimeSeriesCollection* const tpchit_coll, - vec_pair& tpc_hits_vec); +template> +lcio::LCCollectionVec* convTPCHits(const edm4hep::RawTimeSeriesCollection* const tpchit_coll, TPCHitMapT& tpc_hits_vec); +template< + typename ClusterMapT = TypeMapT, + typename CaloHitMapT = TypeMapT> lcio::LCCollectionVec* convClusters( const edm4hep::ClusterCollection* const cluster_coll, - vec_pair& cluster_vec, - const vec_pair& calohits_vec); + ClusterMapT& cluster_vec, + const CaloHitMapT& calohits_vec); +template< + typename VertexMapT = TypeMapT, + typename RecoPartMapT = TypeMapT> lcio::LCCollectionVec* convVertices( const edm4hep::VertexCollection* const vertex_coll, - vec_pair& vertex_vec, - const vec_pair& recoparticles_vec); - + VertexMapT& vertex_vec, + const RecoPartMapT& recoparticles_vec); + +template< + typename RecoPartMapT = TypeMapT, + typename TrackMapT = TypeMapT, + typename VertexMapT = TypeMapT, + typename ClusterMapT = TypeMapT> lcio::LCCollectionVec* convReconstructedParticles( const edm4hep::ReconstructedParticleCollection* const recos_coll, - vec_pair& recoparticles_vec, - const vec_pair& tracks_vec, - const vec_pair& vertex_vec, - const vec_pair& clusters_vec); + RecoPartMapT& recoparticles_vec, + const TrackMapT& tracks_vec, + const VertexMapT& vertex_vec, + const ClusterMapT& clusters_vec); +template> lcio::LCCollectionVec* convMCParticles( const edm4hep::MCParticleCollection* const mcparticle_coll, - vec_pair& mc_particles_vec); + MCPartMapT& mc_particles_vec); void convEventHeader(const edm4hep::EventHeaderCollection* const header_coll, lcio::LCEventImpl* const lcio_event); -void FillMissingCollections(CollectionsPairVectors& collection_pairs); +template +void FillMissingCollections(ObjectMappingT& collection_pairs); bool collectionExist(const std::string& collection_name, const lcio::LCEventImpl* lcio_event); diff --git a/k4EDM4hep2LcioConv/src/k4EDM4hep2LcioConv.cpp b/k4EDM4hep2LcioConv/src/k4EDM4hep2LcioConv.cpp index 6b7311ea..6026d81a 100644 --- a/k4EDM4hep2LcioConv/src/k4EDM4hep2LcioConv.cpp +++ b/k4EDM4hep2LcioConv/src/k4EDM4hep2LcioConv.cpp @@ -18,10 +18,11 @@ // Convert EDM4hep Tracks to LCIO // Add converted LCIO ptr and original EDM4hep collection to vector of pairs // Add LCIO Collection Vector to LCIO event +template lcio::LCCollectionVec* convTracks( const edm4hep::TrackCollection* const tracks_coll, - vec_pair& tracks_vec, - const vec_pair& trackerhits_vec) + TrackMapT& tracks_vec, + const TrackerHitMapT& trackerhits_vec) { auto* tracks = new lcio::LCCollectionVec(lcio::LCIO::TRACK); @@ -102,7 +103,7 @@ lcio::LCCollectionVec* convTracks( } // Save intermediate tracks ref - tracks_vec.emplace_back(std::make_pair(lcio_tr, edm_tr)); + k4EDM4hep2LcioConv::detail::mapInsert(lcio_tr, edm_tr, tracks_vec); // Add to lcio tracks collection tracks->addElement(lcio_tr); @@ -128,10 +129,11 @@ lcio::LCCollectionVec* convTracks( // Convert EDM4hep TrackerHits to LCIO // Add converted LCIO ptr and original EDM4hep collection to vector of pairs // Add LCIO Collection Vector to LCIO event +template lcio::LCCollectionVec* convTrackerHits( const edm4hep::TrackerHitCollection* const trackerhits_coll, const std::string cellIDstr, - vec_pair& trackerhits_vec) + TrackerHitMapT& trackerhits_vec) { auto* trackerhits = new lcio::LCCollectionVec(lcio::LCIO::TRACKERHIT); @@ -162,7 +164,7 @@ lcio::LCCollectionVec* convTrackerHits( } // Save intermediate trackerhits ref - trackerhits_vec.emplace_back(std::make_pair(lcio_trh, edm_trh)); + k4EDM4hep2LcioConv::detail::mapInsert(lcio_trh, edm_trh, trackerhits_vec); // Add to lcio trackerhits collection trackerhits->addElement(lcio_trh); @@ -175,11 +177,12 @@ lcio::LCCollectionVec* convTrackerHits( // Convert EDM4hep SimTrackerHits to LCIO // Add converted LCIO ptr and original EDM4hep collection to vector of pairs // Add LCIO Collection Vector to LCIO event +template lcio::LCCollectionVec* convSimTrackerHits( const edm4hep::SimTrackerHitCollection* const simtrackerhits_coll, const std::string cellIDstr, - vec_pair& simtrackerhits_vec, - const vec_pair& mcparticles_vec) + SimTrHitMapT& simtrackerhits_vec, + const MCParticleMapT& mcparticles_vec) { auto* simtrackerhits = new lcio::LCCollectionVec(lcio::LCIO::SIMTRACKERHIT); @@ -220,7 +223,7 @@ lcio::LCCollectionVec* convSimTrackerHits( } // Save intermediate simtrackerhits ref - simtrackerhits_vec.emplace_back(std::make_pair(lcio_strh, edm_strh)); + k4EDM4hep2LcioConv::detail::mapInsert(lcio_strh, edm_strh, simtrackerhits_vec); // Add to lcio simtrackerhits collection simtrackerhits->addElement(lcio_strh); @@ -233,10 +236,12 @@ lcio::LCCollectionVec* convSimTrackerHits( // Convert EDM4hep Calorimeter Hits to LCIO // Add converted LCIO ptr and original EDM4hep collection to vector of pairs // Add converted LCIO Collection Vector to LCIO event + +template lcio::LCCollectionVec* convCalorimeterHits( const edm4hep::CalorimeterHitCollection* const calohit_coll, const std::string cellIDstr, - vec_pair& calo_hits_vec) + CaloHitMapT& calo_hits_vec) { auto* calohits = new lcio::LCCollectionVec(lcio::LCIO::CALORIMETERHIT); @@ -264,7 +269,7 @@ lcio::LCCollectionVec* convCalorimeterHits( // lcio_calohit->setRawHit(EVENT::LCObject* rawHit ); // Save Calorimeter Hits LCIO and EDM4hep collections - calo_hits_vec.emplace_back(std::make_pair(lcio_calohit, edm_calohit)); + k4EDM4hep2LcioConv::detail::mapInsert(lcio_calohit, edm_calohit, calo_hits_vec); // Add to lcio tracks collection calohits->addElement(lcio_calohit); @@ -277,9 +282,10 @@ lcio::LCCollectionVec* convCalorimeterHits( // Convert EDM4hep RAW Calorimeter Hits to LCIO // Add converted LCIO ptr and original EDM4hep collection to vector of pairs // Add converted LCIO Collection Vector to LCIO event +template lcio::LCCollectionVec* convRawCalorimeterHits( const edm4hep::RawCalorimeterHitCollection* const rawcalohit_coll, - vec_pair& raw_calo_hits_vec) + RawCaloHitMapT& raw_calo_hits_vec) { auto* rawcalohits = new lcio::LCCollectionVec(lcio::LCIO::RAWCALORIMETERHIT); @@ -295,7 +301,7 @@ lcio::LCCollectionVec* convRawCalorimeterHits( lcio_rawcalohit->setTimeStamp(edm_raw_calohit.getTimeStamp()); // Save Raw Calorimeter Hits LCIO and EDM4hep collections - raw_calo_hits_vec.emplace_back(std::make_pair(lcio_rawcalohit, edm_raw_calohit)); + k4EDM4hep2LcioConv::detail::mapInsert(lcio_rawcalohit, edm_raw_calohit, raw_calo_hits_vec); // Add to lcio tracks collection rawcalohits->addElement(lcio_rawcalohit); @@ -308,11 +314,12 @@ lcio::LCCollectionVec* convRawCalorimeterHits( // Convert EDM4hep Sim Calorimeter Hits to LCIO // Add converted LCIO ptr and original EDM4hep collection to vector of pairs // Add converted LCIO Collection Vector to LCIO event +template lcio::LCCollectionVec* convSimCalorimeterHits( const edm4hep::SimCalorimeterHitCollection* const simcalohit_coll, const std::string cellIDstr, - vec_pair& sim_calo_hits_vec, - const vec_pair& mcparticles) + SimCaloHitMapT& sim_calo_hits_vec, + const MCParticleMapT& mcparticles) { auto* simcalohits = new lcio::LCCollectionVec(lcio::LCIO::SIMCALORIMETERHIT); @@ -337,7 +344,7 @@ lcio::LCCollectionVec* convSimCalorimeterHits( // MCParticles converted // Save Sim Calorimeter Hits LCIO and EDM4hep collections - sim_calo_hits_vec.emplace_back(std::make_pair(lcio_simcalohit, edm_sim_calohit)); + k4EDM4hep2LcioConv::detail::mapInsert(lcio_simcalohit, edm_sim_calohit, sim_calo_hits_vec); // Add to sim calo hits collection simcalohits->addElement(lcio_simcalohit); @@ -350,9 +357,8 @@ lcio::LCCollectionVec* convSimCalorimeterHits( // Convert EDM4hep TPC Hits to LCIO // Add converted LCIO ptr and original EDM4hep collection to vector of pairs // Add converted LCIO Collection Vector to LCIO event -lcio::LCCollectionVec* convTPCHits( - const edm4hep::RawTimeSeriesCollection* const tpchit_coll, - vec_pair& tpc_hits_vec) +template +lcio::LCCollectionVec* convTPCHits(const edm4hep::RawTimeSeriesCollection* const tpchit_coll, TPCHitMapT& tpc_hits_vec) { auto* tpchits = new lcio::LCCollectionVec(lcio::LCIO::TPCHIT); @@ -382,7 +388,7 @@ lcio::LCCollectionVec* convTPCHits( #endif // Save TPC Hits LCIO and EDM4hep collections - tpc_hits_vec.emplace_back(std::make_pair(lcio_tpchit, edm_tpchit)); + k4EDM4hep2LcioConv::detail::mapInsert(lcio_tpchit, edm_tpchit, tpc_hits_vec); // Add to lcio tracks collection tpchits->addElement(lcio_tpchit); @@ -395,10 +401,11 @@ lcio::LCCollectionVec* convTPCHits( // Convert EDM4hep Clusters to LCIO // Add converted LCIO ptr and original EDM4hep collection to vector of pairs // Add converted LCIO Collection Vector to LCIO event +template lcio::LCCollectionVec* convClusters( const edm4hep::ClusterCollection* const cluster_coll, - vec_pair& cluster_vec, - const vec_pair& calohits_vec) + ClusterMapT& cluster_vec, + const CaloHitMapT& calohits_vec) { auto* clusters = new lcio::LCCollectionVec(lcio::LCIO::CLUSTER); @@ -449,7 +456,7 @@ lcio::LCCollectionVec* convClusters( } // Add LCIO and EDM4hep pair collections to vec - cluster_vec.emplace_back(std::make_pair(lcio_cluster, edm_cluster)); + k4EDM4hep2LcioConv::detail::mapInsert(lcio_cluster, edm_cluster, cluster_vec); // Add to lcio tracks collection clusters->addElement(lcio_cluster); @@ -474,10 +481,11 @@ lcio::LCCollectionVec* convClusters( // Convert EDM4hep Vertices to LCIO // Add converted LCIO ptr and original EDM4hep collection to vector of pairs // Add converted LCIO Collection Vector to LCIO event +template lcio::LCCollectionVec* convVertices( const edm4hep::VertexCollection* const vertex_coll, - vec_pair& vertex_vec, - const vec_pair& recoparticles_vec) + VertexMapT& vertex_vec, + const RecoPartMapT& recoparticles_vec) { auto* vertices = new lcio::LCCollectionVec(lcio::LCIO::VERTEX); @@ -508,7 +516,7 @@ lcio::LCCollectionVec* convVertices( } // Add LCIO and EDM4hep pair collections to vec - vertex_vec.emplace_back(std::make_pair(lcio_vertex, edm_vertex)); + k4EDM4hep2LcioConv::detail::mapInsert(lcio_vertex, edm_vertex, vertex_vec); // Add to lcio tracks collection vertices->addElement(lcio_vertex); @@ -521,12 +529,13 @@ lcio::LCCollectionVec* convVertices( // Convert EDM4hep RecoParticles to LCIO // Add converted LCIO ptr and original EDM4hep collection to vector of pairs // Add converted LCIO Collection Vector to LCIO event +template lcio::LCCollectionVec* convReconstructedParticles( const edm4hep::ReconstructedParticleCollection* const recos_coll, - vec_pair& recoparticles_vec, - const vec_pair& tracks_vec, - const vec_pair& vertex_vec, - const vec_pair& clusters_vec) + RecoPartMapT& recoparticles_vec, + const TrackMapT& tracks_vec, + const VertexMapT& vertex_vec, + const ClusterMapT& clusters_vec) { auto* recops = new lcio::LCCollectionVec(lcio::LCIO::RECONSTRUCTEDPARTICLE); @@ -616,7 +625,7 @@ lcio::LCCollectionVec* convReconstructedParticles( } // Add LCIO and EDM4hep pair collections to vec - recoparticles_vec.push_back(std::make_pair(lcio_recp, edm_rp)); + k4EDM4hep2LcioConv::detail::mapInsert(lcio_recp, edm_rp, recoparticles_vec); // Add to reconstructed particles collection recops->addElement(lcio_recp); @@ -641,9 +650,10 @@ lcio::LCCollectionVec* convReconstructedParticles( // Convert MC Particles to LCIO // Add converted LCIO ptr and original EDM4hep collection to vector of pairs // Add converted LCIO Collection Vector to LCIO event +template lcio::LCCollectionVec* convMCParticles( const edm4hep::MCParticleCollection* const mcparticle_coll, - vec_pair& mc_particles_vec) + MCPartMapT& mc_particles_vec) { auto* mcparticles = new lcio::LCCollectionVec(lcio::LCIO::MCPARTICLE); @@ -684,7 +694,7 @@ lcio::LCCollectionVec* convMCParticles( lcio_mcp->setOverlay(edm_mcp.isOverlay()); // Add LCIO and EDM4hep pair collections to vec - mc_particles_vec.push_back(std::make_pair(lcio_mcp, edm_mcp)); + k4EDM4hep2LcioConv::detail::mapInsert(lcio_mcp, edm_mcp, mc_particles_vec); // Add to reconstructed particles collection mcparticles->addElement(lcio_mcp); @@ -723,7 +733,8 @@ void convEventHeader(const edm4hep::EventHeaderCollection* const header_coll, lc // Depending on the order of the collections in the parameters, // and for the mutual dependencies between some collections, // go over the possible missing associated collections and fill them. -void FillMissingCollections(CollectionsPairVectors& collection_pairs) +template +void FillMissingCollections(ObjectMappingT& collection_pairs) { // Fill missing Tracks collections for (auto& [lcio_tr, edm_tr] : collection_pairs.tracks) {