61 #ifndef G4MULTITHREADED
63 msg<<
"Geant4 code is compiled without multi-threading support (-DG4MULTITHREADED is set to off).";
64 msg<<
" This type of RunManager can only be used in mult-threaded applications.";
80 #ifdef G4MULTITHREADED
84 pVVis->SetUpForAThread();
88 { visIsSetUp =
false; }
114 G4Exception(
"G4RunManager::InitializeGeometry",
"Run0033",
138 #ifdef G4MULTITHREADED
144 pVVis->SetUpForAThread();
178 std::ostringstream oss;
179 G4Random::saveFullState(oss);
196 std::ostringstream os;
213 "G4VUserPrimaryGeneratorAction is not defined!");
272 G4bool eventHasToBeSeeded =
true;
274 { eventHasToBeSeeded =
false; }
318 else if(eventHasToBeSeeded)
322 s1 = helper->
GetSeed(i_event*2);
323 s2 = helper->
GetSeed(i_event*2+1);
326 if(eventHasToBeSeeded)
328 long seeds[3] = { s1, s2, 0 };
329 G4Random::setTheSeeds(seeds,-1);
341 const auto filename = [&] {
342 std::ostringstream os;
347 G4bool RNGstatusReadFromFile =
false;
350 std::ostringstream os;
351 os << filename() <<
".rndm";
352 const G4String& randomStatusFile = os.str();
353 std::ifstream ifile(randomStatusFile.c_str());
355 RNGstatusReadFromFile =
true;
356 G4Random::restoreEngineStatus(randomStatusFile.c_str());
363 std::ostringstream oss;
364 G4Random::saveFullState(oss);
380 if(eventHasToBeSeeded)
381 {
G4cout <<
" with initial seeds (" << s1 <<
"," << s2 <<
")"; }
461 assert( masterScM != NULL );
466 for(
G4int iw=0;iw<nPar;iw++)
476 ed<<
"Mesh name <"<<ScM->
GetWorldName(iw)<<
"> is not found in the master thread.";
477 G4Exception(
"G4WorkerRunManager::ConstructScoringWorlds()",
"RUN79001",
488 if(theParallelWorldProcess)
496 particleIterator->
reset();
497 while( (*particleIterator)() ){
502 pmanager->
AddProcess(theParallelWorldProcess);
517 G4Exception(
"G4RunManager::SetUserInitialization(G4UserWorkerInitialization*)",
"Run0118",
518 FatalException,
"This method should be used only with an instance of G4MTRunManager");
523 G4Exception(
"G4RunManager::SetUserInitialization(G4UserWorkerThreadInitialization*)",
"Run0119",
524 FatalException,
"This method should be used only with an instance of G4MTRunManager");
529 G4Exception(
"G4RunManager::SetUserInitialization(G4VUserActionInitialization*)",
"Run0120",
530 FatalException,
"This method should be used only with an instance of G4MTRunManager");
535 G4Exception(
"G4RunManager::SetUserInitialization(G4VUserDetectorConstruction*)",
"Run0121",
536 FatalException,
"This method should be used only with an instance of G4MTRunManager");
548 if(userAction) userAction->
SetMaster(
false);
589 std::ostringstream os;
591 G4Random::saveEngineStatus(os.str().c_str());
605 if(skipInitialization)
608 skipInitialization =
false;
619 std::vector<G4String>::const_iterator it = cmds.begin();
620 for(;it!=cmds.end();it++)
626 if ( macroFile ==
"" || macroFile ==
" " )
632 this->
BeamOn(numevents,macroFile,numSelect);
638 std::vector<G4String>::const_iterator it = cmds.begin();
639 for(;it!=cmds.end();it++)
646 d<<
"Cannot continue, this worker has been requested an unknwon action: "
647 <<
static_cast<std::underlying_type<G4MTRunManager::WorkerActionRequest>::type
>(nextAction);
G4bool RunInitialization(G4bool fakeRun=false)
void WorkerUpdateWorldVolume()
G4VUserDetectorConstruction * userDetector
static G4MTRunManager * GetMasterRunManager()
static G4RunManager * GetRunManager()
virtual void SetupRNGEngine(const CLHEP::HepRandomEngine *aRNGEngine) const
std::ostringstream G4ExceptionDescription
G4bool rngStatusEventsFlag
G4VUserActionInitialization * userActionInitialization
void SetHCtable(G4HCtable *HCtbl)
static G4ParticleTable * GetParticleTable()
void SetupDefaultRNGEngine()
G4VPhysicalVolume * GetCurrentWorld() const
size_t GetNumberOfMesh() const
virtual void BeginOfRunAction(const G4Run *aRun)
void SetDCtable(G4DCtable *DCtbl)
G4int GetNumberOfParallelWorld() const
static G4WorkerRunManager * GetWorkerRunManager()
G4int ApplyCommand(const char *aCommand)
void SetParallelWorld(G4String parallelWorldName)
static G4ParallelWorldProcessStore * GetInstance()
void ProcessOneEvent(G4Event *anEvent)
virtual void SetUserAction(G4UserRunAction *userAction)
G4bool IsAtRestRequired(G4ParticleDefinition *)
G4bool storeRandomNumberStatus
G4bool geometryInitialized
virtual void TerminateOneEvent()
std::vector< G4String > GetCommandStack()
virtual void DoEventLoop(G4int n_event, const char *macroFile=0, G4int n_select=-1)
virtual void RunInitialization()
static void UpdateGeometryAndPhysicsVectorFromMaster()
G4VUserPhysicsList * physicsList
void SetNumberOfParallelWorld(G4int i)
G4UserRunAction * userRunAction
virtual void RunTermination()
virtual const T GetSeed(const G4int &sdId)
G4PTblDicIterator * GetIterator() const
G4int GetNumberOfEventsToBeProcessed() const
G4ParallelWorldProcess * GetParallelWorldProcess() const
void reset(G4bool ifSkipIon=true)
void SetProcessOrdering(G4VProcess *aProcess, G4ProcessVectorDoItIndex idDoIt, G4int ordDoIt=ordDefault)
static G4UImanager * GetUIpointer()
const CLHEP::HepRandomEngine * getMasterRandomEngine() const
static G4VVisManager * GetConcreteInstance()
void SetProcessOrderingToSecond(G4VProcess *aProcess, G4ProcessVectorDoItIndex idDoIt)
G4WorkerThread * workerContext
G4VPhysicalVolume * IsWorldExisting(const G4String &worldName)
virtual void ThisWorkerEndEventLoop()
virtual void SetUserInitialization(G4VUserDetectorConstruction *userInit)
virtual void BeamOn(G4int n_event, const char *macroFile=0, G4int n_select=-1)
void ConstructParallelSD()
static G4ScoringManager * GetMasterScoringManager()
void SetRandomNumberStatus(G4String &st)
void ClearParallelWorlds()
G4bool readStatusFromFile
G4int numberOfEventProcessed
virtual void StoreRNGStatus(const G4String &filenamePrefix)
#define G4MUTEX_INITIALIZER
G4int AddProcess(G4VProcess *aProcess, G4int ordAtRestDoIt=ordInActive, G4int ordAlongSteptDoIt=ordInActive, G4int ordPostStepDoIt=ordInActive)
void SetRandomNumberStatus(G4String &st)
G4int GetNumberOfSelectEvents() const
virtual G4Event * GenerateEvent(G4int i_event)
virtual void TerminateEventLoop()
void CleanUpPreviousEvents()
virtual void SetUserAction(G4UserRunAction *userAction)
static G4ScoringManager * GetScoringManagerIfExist()
static G4SDManager * GetSDMpointerIfExist()
G4int storeRandomNumberStatusToG4Event
G4int GetEventModulo() const
G4VUserPrimaryGeneratorAction * userPrimaryGeneratorAction
virtual void AnalyzeEvent(G4Event *anEvent)
void MergeRun(const G4Run *localRun)
virtual G4bool SetUpAnEvent(G4Event *, long &s1, long &s2, long &s3, G4bool reseedRequired=true)
void SetIgnoreCmdNotFound(G4bool val)
G4int numberOfEventToBeProcessed
G4UserWorkerInitialization * userWorkerInitialization
static G4bool fGeometryHasBeenDestroyed
virtual void ProcessOneEvent(G4int i_event)
const G4UserWorkerInitialization * GetUserWorkerInitialization() const
virtual void ThisWorkerReady()
void GeometryHasBeenDestroyed()
virtual void ConstructScoringWorlds()
G4int GetThreadId() const
G4String randomNumberStatusForThisRun
static G4TransportationManager * GetTransportationManager()
G4LogicalVolume * GetMeshElementLogical() const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
void SetNumberOfEventToBeProcessed(G4int n_ev)
void SetMeshElementLogical(G4LogicalVolume *val)
virtual void InitializeGeometry()
static G4int SeedOncePerCommunication()
G4HCtable * GetHCtable() const
void MergeScores(const G4ScoringManager *localScoringManager)
G4ProcessManager * GetProcessManager() const
void WorkerG4ParticleTable()
virtual void SetUserInitialization(G4VUserPhysicsList *userInit)
G4UserWorkerThreadInitialization * userWorkerThreadInitialization
static G4WorkerRunManagerKernel * GetWorkerRunManagerKernel()
virtual G4Run * GenerateRun()
static G4RunManagerKernel * GetMasterRunManagerKernel()
std::vector< G4InuclElementaryParticle >::iterator particleIterator
virtual void ConstructSDandField()
void WorkerConstruct(G4VPhysicalVolume *fWorldPhys)
G4GLOB_DLL std::ostream G4cout
void WorkerDefineWorldVolume(G4VPhysicalVolume *worldVol, G4bool topologyIsChanged=true)
std::list< G4Event * > * previousEvents
virtual void InitializeEventLoop(G4int n_event, const char *macroFile=0, G4int n_select=-1)
virtual void TerminateWorker()
G4VScoringMesh * GetMesh(G4int i) const
virtual void GeneratePrimaries(G4Event *anEvent)=0
G4String GetSelectMacro() const
virtual G4int SetUpNEvents(G4Event *, G4SeedsQueue *seedsQueue, G4bool reseedRequired=true)
const G4UserWorkerThreadInitialization * GetUserWorkerThreadInitialization() const
#define TIMEMORY_AUTO_TIMER(str)
static G4TemplateRNGHelper< T > * GetInstance()
G4String randomNumberStatusForThisEvent
static G4ScoringManager * GetScoringManager()
virtual void SetMaster(G4bool val=true)
virtual void WorkerRunStart() const
virtual WorkerActionRequest ThisWorkerWaitForNextAction()
G4String randomNumberStatusDir
virtual void InitializeWorker()
void SetParallelWorldProcess(G4ParallelWorldProcess *proc)
virtual void ThisWorkerProcessCommandsStackDone()
virtual void WorkerRunEnd() const
G4int n_perviousEventsToBeStored
G4RunManagerKernel * kernel
virtual void RunTermination()
G4String GetWorldName(G4int i) const
virtual void MergePartialResults()
G4EventManager * eventManager