69#ifndef G4MULTITHREADED
71 msg <<
"Geant4 code is compiled without multi-threading support "
74 msg <<
" This type of RunManager can only be used in mult-threaded "
76 G4Exception(
"G4WorkerRunManager::G4WorkerRunManager()",
"Run0103",
112#ifdef G4MULTITHREADED
116 pVVis->SetUpForAThread();
143 G4cout <<
"Destroying WorkerRunManager (" <<
this <<
")" <<
G4endl;
151 "G4VUserDetectorConstruction is not defined!");
177#ifdef G4MULTITHREADED
183 pVVis->SetUpForAThread();
233 std::ostringstream oss;
234 G4Random::saveFullState(oss);
252#if defined(GEANT4_USE_TIMEMORY)
266 std::ostringstream os;
283 "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 long seeds[3] = { s1, s2, 0 };
410 G4Random::setTheSeeds(seeds,
luxury);
423 const auto filename = [&] {
424 std::ostringstream os;
429 G4bool RNGstatusReadFromFile =
false;
433 std::ostringstream os;
434 os << filename() <<
".rndm";
435 const G4String& randomStatusFile = os.str();
436 std::ifstream ifile(randomStatusFile.c_str());
439 RNGstatusReadFromFile =
true;
440 G4Random::restoreEngineStatus(randomStatusFile.c_str());
447 std::ostringstream oss;
448 G4Random::saveFullState(oss);
466 if(eventHasToBeSeeded)
468 G4cout <<
" with initial seeds (" << s1 <<
"," << s2 <<
")";
490#if defined(GEANT4_USE_TIMEMORY)
491 workerRunProfiler.reset();
520 <<
" events processed." <<
G4endl;
567 assert(masterScM != NULL);
572 for(
G4int iw = 0; iw < nPar; iw++)
578 if(mesh->
GetShape() != MeshShape::realWorldLogVol)
587 <<
"> is not found in the master thread.";
588 G4Exception(
"G4WorkerRunManager::ConstructScoringWorlds()",
"RUN79001",
599 if(mesh->
GetShape() != MeshShape::realWorldLogVol)
603 if(theParallelWorldProcess)
609 theParallelWorldProcess =
621 pmanager->
AddProcess(theParallelWorldProcess);
644 "G4RunManager::SetUserInitialization(G4UserWorkerInitialization*)",
646 "This method should be used only with an instance of G4MTRunManager");
653 "G4RunManager::SetUserInitialization(G4UserWorkerThreadInitialization*)",
655 "This method should be used only with an instance of G4MTRunManager");
661 "G4RunManager::SetUserInitialization(G4VUserActionInitialization*)",
663 "This method should be used only with an instance of G4MTRunManager");
669 "G4RunManager::SetUserInitialization(G4VUserDetectorConstruction*)",
671 "This method should be used only with an instance of G4MTRunManager");
687void G4WorkerRunManager::SetupDefaultRNGEngine()
725 std::ostringstream os;
727 <<
"_" << fn <<
".rndm";
728 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;
746 <<
"_" <<
"currentRun.rndm" <<
"\0";
749 std::ostringstream os;
750 os <<
"run" << runNumber <<
".rndm" <<
'\0';
754 G4String copCmd =
"/control/shell copy " + fileIn +
" " + fileOut;
756 G4String copCmd =
"/control/shell cp " + fileIn +
" " + fileOut;
760 {
G4cout << fileIn <<
" is copied to " << fileOut <<
G4endl; }
768 <<
"Warning from G4RunManager::rndmSaveThisEvent():"
769 <<
" there is no currentEvent available."
777 <<
"Warning from G4RunManager::rndmSaveThisEvent():"
778 <<
" Random number engine status is not available."
779 <<
G4endl <<
"/random/setSavingFlag command must be issued "
780 <<
"prior to the start of the run. Command ignored." <<
G4endl;
784 std::ostringstream oos;
786 <<
"_" <<
"currentEvent.rndm" <<
"\0";
789 std::ostringstream os;
795 G4String copCmd =
"/control/shell copy " + fileIn +
" " + fileOut;
797 G4String copCmd =
"/control/shell cp " + fileIn +
" " + fileOut;
801 {
G4cout << fileIn <<
" is copied to " << fileOut <<
G4endl; }
817 if(skipInitialization)
820 skipInitialization =
false;
831 std::vector<G4String>::const_iterator it = cmds.begin();
832 for(; it != cmds.end(); it++)
840 if(macroFile ==
"" || macroFile ==
" ")
846 this->
BeamOn(numevents, macroFile, numSelect);
853 std::vector<G4String>::const_iterator it = cmds.begin();
854 for(; it != cmds.end(); it++)
863 d <<
"Cannot continue, this worker has been requested an unknown action: "
865 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 BeamOn(G4int n_event, const char *macroFile=0, G4int n_select=-1)
G4RunManagerKernel * kernel
static G4RunManager * GetRunManager()
G4String randomNumberStatusForThisRun
G4UserRunAction * userRunAction
G4bool rngStatusEventsFlag
virtual void RunTermination()
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)
G4String GetSelectMacro() const
G4bool storeRandomNumberStatus
G4EventManager * eventManager
virtual void TerminateOneEvent()
G4int GetNumberOfSelectEvents() const
G4VUserPhysicsList * physicsList
virtual void AnalyzeEvent(G4Event *anEvent)
virtual void InitializeEventLoop(G4int n_event, const char *macroFile=0, G4int n_select=-1)
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
void WorkerConstruct(G4VPhysicalVolume *fWorldPhys)
void GeometryHasBeenDestroyed()
G4ParallelWorldProcess * GetParallelWorldProcess() const
void SetParallelWorldProcess(G4ParallelWorldProcess *proc)
void SetMeshElementLogical(G4LogicalVolume *val)
virtual void ConstructSDandField()
void ConstructParallelSD()
virtual void TerminateWorker()
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()