From 721ccbdaabcc3c193a1f02bf390e6b2aa48923dd Mon Sep 17 00:00:00 2001 From: Andre Sailer Date: Tue, 10 Dec 2024 16:35:50 +0100 Subject: [PATCH] HitTupleAction: use Data* because that does not segfault in the test when filling the tree --- examples/DDG4/src/HitTupleAction.cpp | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/examples/DDG4/src/HitTupleAction.cpp b/examples/DDG4/src/HitTupleAction.cpp index f9257b17a..3eb7f4b00 100644 --- a/examples/DDG4/src/HitTupleAction.cpp +++ b/examples/DDG4/src/HitTupleAction.cpp @@ -50,7 +50,7 @@ namespace myanalysis { /// We want to write a separate branch for all deposits of one container(sub-detector) typedef std::pair > Data; /// The intermediate storage of the hit deposits to be written to ROOT - std::map > m_deposits; + std::map > m_deposits; public: /// Standard constructor @@ -162,13 +162,13 @@ void myanalysis::HitTupleAction::end(const G4Event* event) { // Seperate loop. We need fixed addresses when creating the branches for(const auto& c : m_containers) { m_deposits[c].first = 0; - m_deposits[c].second.first = 0e0; - m_deposits[c].second.second.clear(); + m_deposits[c].second = new Data(); + m_deposits[c].second->first = 0e0; + m_deposits[c].second->second.clear(); } for(const auto& c : m_containers) { - std::pair& e = m_deposits[c]; - TClass* cl = gROOT->GetClass(typeid(Data)); - e.first = m_outTree->Branch(c.c_str(), cl->GetName(), (void*)0); + std::pair& e = m_deposits[c]; + e.first = m_outTree->Branch(c.c_str(), &e.second); e.first->SetAutoDelete(false); printout(ALWAYS,"HitTupleAction","+++ Prepare hit branch %s in root file.",c.c_str()); } @@ -186,13 +186,12 @@ void myanalysis::HitTupleAction::end(const G4Event* event) { if ( find(m_containers.begin(),m_containers.end(),nam) != m_containers.end() ) { Geant4HitCollection* coll = dynamic_cast(hc); if ( coll ) { - std::pair& e = m_deposits[nam]; + std::pair& e = m_deposits[nam]; size_t nhits = coll->GetSize(); - Data* d = &e.second; + Data* d = e.second; + d->first = 0e0; + d->second.clear(); - e.second.first = 0e0; - e.second.second.clear(); - e.first->SetAddress(&d); for ( size_t j=0; jhit(j); @@ -208,8 +207,8 @@ void myanalysis::HitTupleAction::end(const G4Event* event) { continue; } if ( dep > 0 ) { - e.second.first += dep; - e.second.second.push_back(dep); + d->first += dep; + d->second.push_back(dep); } } }