From 639c341cd432572479d3d273c00781990046c795 Mon Sep 17 00:00:00 2001
From: Wouter Deconinck <wdconinc@gmail.com>
Date: Mon, 15 May 2023 16:18:44 -0500
Subject: [PATCH] Geant4Output2EDM4hep: use collection object in map, not
 unique_ptr

---
 DDG4/edm4hep/Geant4Output2EDM4hep.cpp | 18 ++----------------
 1 file changed, 2 insertions(+), 16 deletions(-)

diff --git a/DDG4/edm4hep/Geant4Output2EDM4hep.cpp b/DDG4/edm4hep/Geant4Output2EDM4hep.cpp
index 55928a950..4e8f9453b 100644
--- a/DDG4/edm4hep/Geant4Output2EDM4hep.cpp
+++ b/DDG4/edm4hep/Geant4Output2EDM4hep.cpp
@@ -48,11 +48,8 @@ namespace dd4hep {
     protected:
       using writer_t = podio::ROOTFrameWriter;
       using stringmap_t = std::map< std::string, std::string >;
-      using trackerptr_t = std::unique_ptr< edm4hep::SimTrackerHitCollection >;
-      using trackermap_t = std::map< std::string, trackerptr_t >;
-      using calorimeterptr_t = std::unique_ptr< edm4hep::SimCalorimeterHitCollection >;
-      using contributionsptr_t = std::unique_ptr< edm4hep::CaloHitContributionCollection >;
-      using calorimeterpair_t = std::pair< calorimeterptr_t, contributionsptr_t >;
+      using trackermap_t = std::map< std::string, edm4hep::SimTrackerHitCollection >;
+      using calorimeterpair_t = std::pair< edm4hep::SimCalorimeterHitCollection, edm4hep::CaloHitContributionCollection >;
       using calorimetermap_t = std::map< std::string, calorimeterpair_t >;
       std::unique_ptr<writer_t>     m_file  { };
       podio::Frame                  m_frame { };
@@ -447,10 +444,6 @@ void Geant4Output2EDM4hep::saveCollection(OutputContext<G4Event>& /*ctxt*/, G4VH
   debug("+++ Saving EDM4hep collection %s with %d entries.", colName.c_str(), int(nhits));
   //-------------------------------------------------------------------
   if( typeid( Geant4Tracker::Hit ) == coll->type().type()  ){
-    // https://jguegant.github.io/blogs/tech/performing-try-emplace.html
-    if (m_trackerHits.find(colName) == m_trackerHits.end()) {
-      m_trackerHits[colName] = std::make_unique< edm4hep::SimTrackerHitCollection >();
-    }
     for(unsigned i=0 ; i < nhits ; ++i){
       auto sth = m_trackerHits[colName]->create();
       const Geant4Tracker::Hit* hit = coll->hit(i);
@@ -480,13 +473,6 @@ void Geant4Output2EDM4hep::saveCollection(OutputContext<G4Event>& /*ctxt*/, G4VH
   else if( typeid( Geant4Calorimeter::Hit ) == coll->type().type() ){
     Geant4Sensitive* sd = coll->sensitive();
     int hit_creation_mode = sd->hitCreationMode();
-
-    if (m_calorimeterHits.find(colName) == m_calorimeterHits.end()) {
-      m_calorimeterHits[colName] = std::make_pair(
-        std::make_unique< edm4hep::SimCalorimeterHitCollection >(),
-        std::make_unique< edm4hep::CaloHitContributionCollection >()
-      );
-    }
     for(unsigned i=0 ; i < nhits ; ++i){
       auto sch = m_calorimeterHits[colName].first->create();
       const Geant4Calorimeter::Hit* hit = coll->hit(i);
-- 
GitLab