79#ifndef G4MULTITHREADED
81 msg <<
"Geant4 code is compiled without multi-threading support "
84 msg <<
" This type of RunManager can only be used in mult-threaded "
86 G4Exception(
"G4WorkerRunManager::G4WorkerRunManager()",
"Run0103",
91 if(masterScM !=
nullptr)
111#ifdef G4MULTITHREADED
115 pVVis->SetUpForAThread();
140 G4cout <<
"Destroying WorkerRunManager (" <<
this <<
")" <<
G4endl;
149 "G4VUserDetectorConstruction is not defined!");
174#ifdef G4MULTITHREADED
180 pVVis->SetUpForAThread();
229 std::ostringstream oss;
230 G4Random::saveFullState(oss);
242 <<
" starts on worker thread "
249#if defined(GEANT4_USE_TIMEMORY)
263 std::ostringstream os;
281 "G4VUserPrimaryGeneratorAction is not defined!");
346 G4bool eventHasToBeSeeded =
true;
349 eventHasToBeSeeded =
false;
358 anEvent, s1, s2, s3, eventHasToBeSeeded);
380 eventHasToBeSeeded =
false;
399 else if(eventHasToBeSeeded)
403 s1 = helper->
GetSeed(i_event * 2);
404 s2 = helper->
GetSeed(i_event * 2 + 1);
407 if(eventHasToBeSeeded)
409 G4long seeds[3] = { s1, s2, 0 };
410 G4Random::setTheSeeds(seeds,
luxury);
421 const auto filename = [&] {
422 std::ostringstream os;
427 G4bool RNGstatusReadFromFile =
false;
431 std::ostringstream os;
432 os << filename() <<
".rndm";
433 const G4String& randomStatusFile = os.str();
434 std::ifstream ifile(randomStatusFile.c_str());
437 RNGstatusReadFromFile =
true;
438 G4Random::restoreEngineStatus(randomStatusFile.c_str());
445 std::ostringstream oss;
446 G4Random::saveFullState(oss);
464 if(eventHasToBeSeeded)
466 G4cout <<
" with initial seeds (" << s1 <<
"," << s2 <<
")";
490#if defined(GEANT4_USE_TIMEMORY)
491 workerRunProfiler.reset();
521 <<
" events processed." <<
G4endl;
558 for(
G4int iw = 0; iw < nPar; ++iw)
564 if(mesh->
GetShape() != MeshShape::realWorldLogVol)
568 if(pWorld ==
nullptr)
572 <<
"> is not found in the master thread.";
573 G4Exception(
"G4WorkerRunManager::ConstructScoringWorlds()",
"RUN79001",
584 if(mesh->
GetShape() != MeshShape::realWorldLogVol)
588 if(theParallelWorldProcess !=
nullptr)
594 theParallelWorldProcess =
604 if(pmanager !=
nullptr)
606 pmanager->
AddProcess(theParallelWorldProcess);
630 "G4RunManager::SetUserInitialization(G4UserWorkerInitialization*)",
632 "This method should be used only with an instance of G4MTRunManager");
640 "G4RunManager::SetUserInitialization(G4UserWorkerThreadInitialization*)",
642 "This method should be used only with an instance of G4MTRunManager");
649 "G4RunManager::SetUserInitialization(G4VUserActionInitialization*)",
651 "This method should be used only with an instance of G4MTRunManager");
658 "G4RunManager::SetUserInitialization(G4VUserDetectorConstruction*)",
660 "This method should be used only with an instance of G4MTRunManager");
674 if(userAction !=
nullptr)
679void G4WorkerRunManager::SetupDefaultRNGEngine()
723 std::ostringstream os;
725 <<
"_" << fn <<
".rndm";
726 G4Random::saveEngineStatus(os.str().c_str());
737 G4cerr <<
"Warning from G4RunManager::rndmSaveThisRun():"
738 <<
" Random number status was not stored prior to this run."
739 <<
G4endl <<
"/random/setSavingFlag command must be issued. "
740 <<
"Command ignored." <<
G4endl;
744 std::ostringstream oos;
750 std::ostringstream os;
751 os <<
"run" << runNumber <<
".rndm" <<
'\0';
755 G4String copCmd =
"/control/shell copy " + fileIn +
" " + fileOut;
757 G4String copCmd =
"/control/shell cp " + fileIn +
" " + fileOut;
762 G4cout << fileIn <<
" is copied to " << fileOut <<
G4endl;
771 G4cerr <<
"Warning from G4RunManager::rndmSaveThisEvent():"
772 <<
" there is no currentEvent available." <<
G4endl
773 <<
"Command ignored." <<
G4endl;
779 G4cerr <<
"Warning from G4RunManager::rndmSaveThisEvent():"
780 <<
" Random number engine status is not available." <<
G4endl
781 <<
"/random/setSavingFlag command must be issued "
782 <<
"prior to the start of the run. Command ignored." <<
G4endl;
786 std::ostringstream oos;
788 <<
"currentEvent.rndm"
792 std::ostringstream os;
798 G4String copCmd =
"/control/shell copy " + fileIn +
" " + fileOut;
800 G4String copCmd =
"/control/shell cp " + fileIn +
" " + fileOut;
805 G4cout << fileIn <<
" is copied to " << fileOut <<
G4endl;
823 if(skipInitialization)
826 skipInitialization =
false;
837 for(
auto it = cmds.cbegin(); it != cmds.cend(); ++it)
845 if(macroFile ==
"" || macroFile ==
" ")
851 this->
BeamOn(numevents, macroFile, numSelect);
858 for(
auto it = cmds.cbegin(); it != cmds.cend(); ++it)
867 d <<
"Cannot continue, this worker has been requested an unknown action: "
869 std::underlying_type<G4MTRunManager::WorkerActionRequest>::type
>(
std::vector< G4InuclElementaryParticle >::iterator particleIterator
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
#define G4MUTEX_INITIALIZER
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
std::shared_ptr< HepRandomEngine > theEngine
void ProcessOneEvent(G4Event *anEvent)
void SetRandomNumberStatus(G4String &st)
static G4int SeedOncePerCommunication()
virtual WorkerActionRequest ThisWorkerWaitForNextAction()
virtual void ThisWorkerProcessCommandsStackDone()
virtual G4int SetUpNEvents(G4Event *, G4SeedsQueue *seedsQueue, G4bool reseedRequired=true)
virtual G4bool SetUpAnEvent(G4Event *, long &s1, long &s2, long &s3, G4bool reseedRequired=true)
const CLHEP::HepRandomEngine * getMasterRandomEngine() const
static G4ScoringManager * GetMasterScoringManager()
virtual void ThisWorkerReady()
G4int GetEventModulo() const
static G4MTRunManager * GetMasterRunManager()
void MergeRun(const G4Run *localRun)
static G4RunManagerKernel * GetMasterRunManagerKernel()
void MergeScores(const G4ScoringManager *localScoringManager)
std::vector< G4String > GetCommandStack()
virtual void ThisWorkerEndEventLoop()
static G4ParallelWorldProcessStore * GetInstance()
void SetLayeredMaterialFlag(G4bool flg=true)
void SetParallelWorld(G4String parallelWorldName)
G4bool IsAtRestRequired(G4ParticleDefinition *)
G4ProcessManager * GetProcessManager() const
G4PTblDicIterator * GetIterator() const
static G4ParticleTable * GetParticleTable()
void WorkerG4ParticleTable()
void SetProcessOrdering(G4VProcess *aProcess, G4ProcessVectorDoItIndex idDoIt, G4int ordDoIt=ordDefault)
void SetProcessOrderingToSecond(G4VProcess *aProcess, G4ProcessVectorDoItIndex idDoIt)
G4int AddProcess(G4VProcess *aProcess, G4int ordAtRestDoIt=ordInActive, G4int ordAlongSteptDoIt=ordInActive, G4int ordPostStepDoIt=ordInActive)
G4VPhysicalVolume * GetCurrentWorld() const
void WorkerUpdateWorldVolume()
void SetNumberOfParallelWorld(G4int i)
G4bool RunInitialization(G4bool fakeRun=false)
void WorkerDefineWorldVolume(G4VPhysicalVolume *worldVol, G4bool topologyIsChanged=true)
G4int GetNumberOfParallelWorld() const
G4bool isScoreNtupleWriter
G4bool geometryInitialized
void CleanUpPreviousEvents()
G4int storeRandomNumberStatusToG4Event
G4UserWorkerInitialization * userWorkerInitialization
const G4UserWorkerInitialization * GetUserWorkerInitialization() const
std::list< G4Event * > * previousEvents
G4UserWorkerThreadInitialization * userWorkerThreadInitialization
G4int numberOfEventProcessed
G4int GetNumberOfEventsToBeProcessed() const
virtual void InitializeEventLoop(G4int n_event, const char *macroFile=nullptr, G4int n_select=-1)
G4RunManagerKernel * kernel
static G4RunManager * GetRunManager()
G4String randomNumberStatusForThisRun
virtual void BeamOn(G4int n_event, const char *macroFile=nullptr, G4int n_select=-1)
G4UserRunAction * userRunAction
G4bool rngStatusEventsFlag
virtual void RunTermination()
const G4String & GetSelectMacro() const
G4VUserActionInitialization * userActionInitialization
static G4RUN_DLL G4bool fGeometryHasBeenDestroyed
G4VUserDetectorConstruction * userDetector
G4VUserPrimaryGeneratorAction * userPrimaryGeneratorAction
G4int numberOfEventToBeProcessed
G4String randomNumberStatusDir
virtual void SetUserAction(G4UserRunAction *userAction)
G4String randomNumberStatusForThisEvent
const G4UserWorkerThreadInitialization * GetUserWorkerThreadInitialization() const
G4int n_perviousEventsToBeStored
virtual void SetUserInitialization(G4VUserDetectorConstruction *userInit)
G4bool storeRandomNumberStatus
G4EventManager * eventManager
virtual void TerminateOneEvent()
G4int GetNumberOfSelectEvents() const
G4VUserPhysicsList * physicsList
virtual void AnalyzeEvent(G4Event *anEvent)
void SetHCtable(G4HCtable *HCtbl)
void SetNumberOfEventToBeProcessed(G4int n_ev)
void SetDCtable(G4DCtable *DCtbl)
void SetRandomNumberStatus(G4String &st)
G4HCofThisEvent * PrepareNewEvent()
static G4SDManager * GetSDMpointerIfExist()
G4HCtable * GetHCtable() const
G4VScoringMesh * GetMesh(G4int i) const
size_t GetNumberOfMesh() const
static G4ScoringManager * GetScoringManager()
G4String GetWorldName(G4int i) const
static G4ScoringManager * GetScoringManagerIfExist()
static G4TemplateRNGHelper< T > * GetInstance()
virtual const T GetSeed(const G4int &sdId)
static G4TransportationManager * GetTransportationManager()
G4VPhysicalVolume * IsWorldExisting(const G4String &worldName)
void ClearParallelWorlds()
void SetIgnoreCmdNotFound(G4bool val)
G4int ApplyCommand(const char *aCommand)
static G4UImanager * GetUIpointer()
virtual void BeginOfRunAction(const G4Run *aRun)
virtual G4Run * GenerateRun()
virtual void SetMaster(G4bool val=true)
virtual void WorkerRunEnd() const
virtual void WorkerRunStart() const
virtual void SetupRNGEngine(const CLHEP::HepRandomEngine *aRNGEngine) const
virtual G4bool Book(G4HCofThisEvent *hce)=0
static G4VScoreNtupleWriter * Instance()
virtual void OpenFile()=0
MeshShape GetShape() const
G4LogicalVolume * GetMeshElementLogical() const
virtual void WorkerConstruct(G4VPhysicalVolume *fWorldPhys)
void GeometryHasBeenDestroyed()
G4ParallelWorldProcess * GetParallelWorldProcess() const
void SetParallelWorldProcess(G4ParallelWorldProcess *proc)
void SetMeshElementLogical(G4LogicalVolume *val)
virtual void ConstructSDandField()
void ConstructParallelSD()
virtual void InitializeWorker()
virtual void GeneratePrimaries(G4Event *anEvent)=0
static G4VVisManager * GetConcreteInstance()
virtual void ConstructScoringWorlds()
static G4WorkerRunManagerKernel * GetWorkerRunManagerKernel()
virtual void RunTermination()
G4bool readStatusFromFile
virtual void rndmSaveThisEvent()
virtual void MergePartialResults()
G4WorkerThread * workerContext
virtual void SetUserAction(G4UserRunAction *userAction)
virtual void SetUserInitialization(G4VUserPhysicsList *userInit)
virtual void rndmSaveThisRun()
static G4WorkerRunManager * GetWorkerRunManager()
virtual void ProcessOneEvent(G4int i_event)
virtual void TerminateEventLoop()
virtual void RunInitialization()
virtual void DoEventLoop(G4int n_event, const char *macroFile=0, G4int n_select=-1)
G4ProfilerConfig< G4ProfileType::Run > ProfilerConfig
virtual void InitializeGeometry()
virtual G4Event * GenerateEvent(G4int i_event)
virtual void StoreRNGStatus(const G4String &filenamePrefix)
G4int GetThreadId() const
static void UpdateGeometryAndPhysicsVectorFromMaster()