From 6d6ead264f2fb13ebbd4843db82da8e7269e283a Mon Sep 17 00:00:00 2001 From: Frank Gaede <frank.gaede@desy.de> Date: Wed, 2 Jul 2014 15:21:05 +0000 Subject: [PATCH] - some code cleanup --- DDG4/lcio/Geant4Output2LCIO.cpp | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/DDG4/lcio/Geant4Output2LCIO.cpp b/DDG4/lcio/Geant4Output2LCIO.cpp index b2b58f81a..bbfc9c29c 100644 --- a/DDG4/lcio/Geant4Output2LCIO.cpp +++ b/DDG4/lcio/Geant4Output2LCIO.cpp @@ -93,13 +93,16 @@ namespace DD4hep { #include "IMPL/LCRunHeaderImpl.h" #include "IMPL/LCCollectionVec.h" + using namespace DD4hep::Simulation; using namespace DD4hep; using namespace std; + #include "DDG4/Factories.h" DECLARE_GEANT4ACTION(Geant4Output2LCIO) + /// Standard constructor Geant4Output2LCIO::Geant4Output2LCIO(Geant4Context* ctxt, const string& nam) : Geant4OutputAction(ctxt,nam), m_volMgr(), m_file(0), m_runNo(0) @@ -116,7 +119,7 @@ Geant4Output2LCIO::~Geant4Output2LCIO() { InstanceCount::decrement(this); } -/// Callback to store the Geant4 run information +// Callback to store the Geant4 run information void Geant4Output2LCIO::beginRun(const G4Run* ) { if ( 0 == m_file && !m_output.empty() ) { m_file = lcio::LCFactory::getInstance()->createLCWriter(); @@ -133,10 +136,9 @@ void Geant4Output2LCIO::endRun(const G4Run* ) { /// Commit data at end of filling procedure void Geant4Output2LCIO::commit( OutputContext<G4Event>& ctxt) { - //lcio::LCEventImpl* e = ctxt.data<lcio::LCEventImpl>(); lcio::LCEventImpl* e = context()->event().extension<lcio::LCEventImpl>(); m_file->writeEvent(e); - std::cout << " ########### Geant4Output2LCIO::commit() : writing LCIO event to file .... " << std::endl ; + // std::cout << " ########### Geant4Output2LCIO::commit() : writing LCIO event to file .... " << std::endl ; } /// Callback to store the Geant4 run information @@ -150,14 +152,19 @@ void Geant4Output2LCIO::saveRun(const G4Run* run) { void Geant4Output2LCIO::begin(const G4Event* event){ + lcio::LCEventImpl* e = new lcio::LCEventImpl; - //fg: fixme: should be this call (deleting the pointer in the end) but that does not compile ... - context()->event().addExtension<lcio::LCEventImpl>( e ); - //context()->event().addExtension(e); - //context()->event().addExtension( e , typeid( lcio::LCEventImpl ), 0); - // std::cout << " ########### Geant4Output2LCIO::begin add new LCIO event event context " << std::endl ; + + //fg: fixme: should be this call taking ownership of the LCEvent + // deleting it at the end - however does not seem to work + // see fixme in Geant4Output2LCIO::saveCollection() below + //context()->event().addExtension<lcio::LCEventImpl>( e , 1 ); + context()->event().addExtension<lcio::LCEventImpl>( e , 0 ); + + } + /// Callback to store the Geant4 event void Geant4Output2LCIO::saveEvent(OutputContext<G4Event>& ctxt) { lcio::LCEventImpl* e = context()->event().extension<lcio::LCEventImpl>(); @@ -180,4 +187,9 @@ void Geant4Output2LCIO::saveCollection(OutputContext<G4Event>& ctxt, G4VHitsColl lcio::LCCollectionVec* col = cnv(_A(m_volMgr,collection)); evt->addCollection(col,hc_nam); } + //fg: fixme: for the memory handling with LCIO we need to take away the ownership from + // the Geant4HitCollection - however this creates a seg fault at the end of event... + // Geant4HitCollection* g4hcol = (Geant4HitCollection* ) collection ; + // std::vector<void*> v ; + // g4hcol->releaseHitsUnchecked(v) ; } -- GitLab