Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simulation: if -1 for number of events, simulate until EOF and end gracefully calling TerminateRun #429

Merged
merged 2 commits into from
Aug 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions DDG4/include/DDG4/Geant4Kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
#include <map>
#include <typeinfo>

class DD4hep_End_Of_File : public std::exception {
public:
DD4hep_End_Of_File() : std::exception() {}
virtual const char* what() const noexcept { return "Reached end of input file"; }

};

// Forward declarations
class G4RunManager;
class G4UIdirectory;
Expand Down
2 changes: 2 additions & 0 deletions DDG4/python/DDSim/DD4hepSimulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,8 @@ def _consistencyChecks( self ):
if self.enableGun and ( self.enableG4Gun or self.enableG4GPS ):
self._errorMessages.append("ERROR: Cannot use both DD4hepGun and Geant4 Gun or GeneralParticleSource")

if self.numberOfEvents < 0 and not self.inputFiles:
self._errorMessages.append("ERROR: Negative number of events only sensible for inputFiles")

def _enablePrimaryHandler( self ):
""" the geant4 Gun or GeneralParticleSource cannot be used together with the PrimaryHandler.
Expand Down
1 change: 1 addition & 0 deletions DDG4/src/Geant4GeneratorAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// Framework include files
#include "DD4hep/InstanceCount.h"
#include "DDG4/Geant4GeneratorAction.h"
#include "DDG4/Geant4Kernel.h"
// Geant4 headers
#include "G4Threading.hh"
#include "G4AutoLock.hh"
Expand Down
16 changes: 16 additions & 0 deletions DDG4/src/Geant4InputAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "DD4hep/Plugins.h"
#include "DDG4/Geant4Primary.h"
#include "DDG4/Geant4Context.h"
#include "DDG4/Geant4Kernel.h"
#include "DDG4/Geant4InputAction.h"

#include "G4Event.hh"
Expand Down Expand Up @@ -173,6 +174,14 @@ int Geant4InputAction::readParticles(int evt_number,
}
}
int status = m_reader->moveToEvent(evid);
if(status == Geant4EventReader::EVENT_READER_EOF ) {
long nEvents = context()->kernel().property("NumEvents").value<long>();
if(nEvents < 0) {
//context()->kernel().runManager().AbortRun(true);
throw DD4hep_End_Of_File();
}
}

if ( Geant4EventReader::EVENT_READER_OK != status ) {
string msg = issue(evid)+"Error when moving to event - ";
if ( status == Geant4EventReader::EVENT_READER_EOF ) msg += " EOF: [end of file].";
Expand All @@ -186,6 +195,13 @@ int Geant4InputAction::readParticles(int evt_number,
return status;
}
status = m_reader->readParticles(evid, vertices, particles);
if(status == Geant4EventReader::EVENT_READER_EOF ) {
long nEvents = context()->kernel().property("NumEvents").value<long>();
if(nEvents < 0) {
//context()->kernel().runManager().AbortRun(true);
throw DD4hep_End_Of_File();
}
}


if ( Geant4EventReader::EVENT_READER_OK != status ) {
Expand Down
8 changes: 7 additions & 1 deletion DDG4/src/Geant4UIManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,14 @@ void Geant4UIManager::start() {

// No UI. Pure batch mode: Simply execute requested number of events
long numEvent = context()->kernel().property("NumEvents").value<long>();
if(numEvent < 0) numEvent = std::numeric_limits<int>::max();
printout(INFO,"Geant4UIManager","++ Start run with %d events.",numEvent);
context()->kernel().runManager().BeamOn(numEvent);
try {
context()->kernel().runManager().BeamOn(numEvent);
} catch (DD4hep_End_Of_File& e) {
printout(INFO,"Geant4UIManager","++ End of file reached, ending run...");
context()->kernel().runManager().RunTermination();
}
}

/// Stop and release resources
Expand Down