diff --git a/DDG4/examples/readHEPMC.py b/DDG4/examples/readHEPMC.py index 9834519b57edd7b24687b860860b99698f7f842d..ee48bf21224e881d8324772e13b9a56654944939 100644 --- a/DDG4/examples/readHEPMC.py +++ b/DDG4/examples/readHEPMC.py @@ -17,6 +17,7 @@ def run(input_file): gen.Input = "Geant4EventReaderHepMC|/home/frankm/SW/data/" gen.Input = "Geant4EventReaderHepMC|"+input_file gen.OutputLevel = Output.DEBUG + gen.HaveAbort = False prim_vtx = DDG4.Geant4Vertex() prim_vtx.x = 0.0 prim_vtx.y = 0.0 @@ -24,7 +25,11 @@ def run(input_file): parts = gen.new_particles() ret = 1 while ret: - ret = gen.readParticles(0,prim_vtx,parts) + try: + ret = gen.readParticles(0,prim_vtx,parts) + except Exception,X: + print '\nException: readParticles:',str(X) + ret = None if ret: for p in parts: print 'ID:%5d PDG-id:%8d Charge:%1d Mass:%8.3g Momentum:(%8.2g,%8.2g,%8.2g) '\ diff --git a/DDG4/include/DDG4/Geant4InputAction.h b/DDG4/include/DDG4/Geant4InputAction.h index b71b03715ef8197fde9823d67b6b23b242bd1b0e..4333e996d4e67e83a75ab7989ec5cb7b34f251ad 100644 --- a/DDG4/include/DDG4/Geant4InputAction.h +++ b/DDG4/include/DDG4/Geant4InputAction.h @@ -123,6 +123,8 @@ namespace DD4hep { Geant4EventReader* m_reader; /// current event number without initially skipped events int m_currentEventNumber; + /// Flag to call abortEvent in case of failure (default: true) + bool m_abort; public: /// Read an event and return a LCCollectionVec of MCParticles. diff --git a/DDG4/src/Geant4InputAction.cpp b/DDG4/src/Geant4InputAction.cpp index 9f311250262c35019aa0e349a388ef7e93a42e5e..559ea45f378349631d9fe9d57156648d2bff4871 100644 --- a/DDG4/src/Geant4InputAction.cpp +++ b/DDG4/src/Geant4InputAction.cpp @@ -84,6 +84,7 @@ Geant4InputAction::Geant4InputAction(Geant4Context* ctxt, const string& nam) declareProperty("Sync", m_firstEvent=0); declareProperty("Mask", m_mask = 0); declareProperty("MomentumScale", m_momScale = 1.0); + declareProperty("HaveAbort", m_abort = true); m_needsControl = true; } @@ -131,13 +132,22 @@ int Geant4InputAction::readParticles(int evt_number, } int status = m_reader->moveToEvent(evid); if ( Geant4EventReader::EVENT_READER_OK != status ) { - abortRun(issue(evid)+"Error when moving to event - may be end of file.", - "Error when reading file %s",m_input.c_str()); + string msg = issue(evid)+"Error when moving to event - may be end of file."; + if ( m_abort ) { + abortRun(msg,"Error when reading file %s",m_input.c_str()); + return status; + } + except("%s Error when reading file %s.", msg.c_str(), m_input.c_str()); + return status; } status = m_reader->readParticles(evid, prim_vertex, particles); if ( Geant4EventReader::EVENT_READER_OK != status ) { - abortRun(issue(evid)+"Error when reading file - may be end of file.", - "Error when reading file %s",m_input.c_str()); + string msg = issue(evid)+"Error when moving to event - may be end of file."; + if ( m_abort ) { + abortRun(msg,"Error when reading file %s",m_input.c_str()); + return status; + } + except("%s Error when reading file %s.", msg.c_str(), m_input.c_str()); } return status; } diff --git a/examples/DDG4/CMakeLists.txt b/examples/DDG4/CMakeLists.txt index e662c4f98fb7f49592cfc0268fd8a153b44d9f05..c7edeba44055772ccb044ed6c4637efe12bf3774 100644 --- a/examples/DDG4/CMakeLists.txt +++ b/examples/DDG4/CMakeLists.txt @@ -28,8 +28,8 @@ if (DD4HEP_USE_GEANT4) # Test HepMC input reader dd4hep_add_test_reg( test_DDG4_HepMC_reader COMMAND "${CMAKE_INSTALL_PREFIX}/bin/run_test_DDG4.sh" - EXEC_ARGS python ${CMAKE_INSTALL_PREFIX}/python/examples/DDG4/examples/readHEPMC.py + EXEC_ARGS python ${DD4hep_DIR}/examples/DDG4/examples/readHEPMC.py ${CMAKE_INSTALL_PREFIX}/examples/DDG4/data/hepmc_geant4.dat REQUIRES DDG4 Geant4 - REGEX_PASS "EventReaderHepMC::moveToEvent INFO Current event number: 10") + REGEX_PASS "EventReaderHepMC::moveToEvent INFO Current event number: 9") endif()