60 #ifndef G4MULTITHREADED
62 msg<<
"Geant4 code is compiled without multi-threading support (-DG4MULTITHREADED is set to off).";
63 msg<<
" This type of RunManager can only be used in mult-threaded applications.";
79 #ifdef G4MULTITHREADED
83 pVVis->SetUpForAThread();
87 { visIsSetUp =
false; }
112 G4Exception(
"G4RunManager::InitializeGeometry",
"Run0033",
135 #ifdef G4MULTITHREADED
141 pVVis->SetUpForAThread();
175 std::ostringstream oss;
176 G4Random::saveFullState(oss);
193 std::ostringstream os;
209 "G4VUserPrimaryGeneratorAction is not defined!");
266 G4bool eventHasToBeSeeded =
true;
268 { eventHasToBeSeeded =
false; }
312 else if(eventHasToBeSeeded)
316 s1 = helper->
GetSeed(i_event*2);
317 s2 = helper->
GetSeed(i_event*2+1);
320 if(eventHasToBeSeeded)
322 long seeds[3] = { s1, s2, 0 };
323 G4Random::setTheSeeds(seeds,-1);
335 const auto filename = [&] {
336 std::ostringstream os;
341 G4bool RNGstatusReadFromFile =
false;
344 std::ostringstream os;
345 os << filename() <<
".rndm";
346 const G4String& randomStatusFile = os.str();
347 std::ifstream ifile(randomStatusFile.c_str());
349 RNGstatusReadFromFile =
true;
350 G4Random::restoreEngineStatus(randomStatusFile.c_str());
357 std::ostringstream oss;
358 G4Random::saveFullState(oss);
374 if(eventHasToBeSeeded)
375 {
G4cout <<
" with initial seeds (" << s1 <<
"," << s2 <<
")"; }
455 assert( masterScM != NULL );
460 for(
G4int iw=0;iw<nPar;iw++)
470 ed<<
"Mesh name <"<<ScM->
GetWorldName(iw)<<
"> is not found in the master thread.";
471 G4Exception(
"G4WorkerRunManager::ConstructScoringWorlds()",
"RUN79001",
482 if(theParallelWorldProcess)
490 particleIterator->
reset();
491 while( (*particleIterator)() ){
496 pmanager->
AddProcess(theParallelWorldProcess);
511 G4Exception(
"G4RunManager::SetUserInitialization(G4UserWorkerInitialization*)",
"Run0118",
512 FatalException,
"This method should be used only with an instance of G4MTRunManager");
517 G4Exception(
"G4RunManager::SetUserInitialization(G4UserWorkerThreadInitialization*)",
"Run0119",
518 FatalException,
"This method should be used only with an instance of G4MTRunManager");
523 G4Exception(
"G4RunManager::SetUserInitialization(G4VUserActionInitialization*)",
"Run0120",
524 FatalException,
"This method should be used only with an instance of G4MTRunManager");
529 G4Exception(
"G4RunManager::SetUserInitialization(G4VUserDetectorConstruction*)",
"Run0121",
530 FatalException,
"This method should be used only with an instance of G4MTRunManager");
545 void G4WorkerRunManager::SetupDefaultRNGEngine()
583 std::ostringstream os;
585 G4Random::saveEngineStatus(os.str().c_str());
598 if(skipInitialization)
601 skipInitialization =
false;
612 std::vector<G4String>::const_iterator it = cmds.begin();
613 for(;it!=cmds.end();it++)
619 if ( macroFile ==
"" || macroFile ==
" " )
625 this->
BeamOn(numevents,macroFile,numSelect);
631 std::vector<G4String>::const_iterator it = cmds.begin();
632 for(;it!=cmds.end();it++)
639 d<<
"Cannot continue, this worker has been requested an unknwon action: "
640 <<
static_cast<std::underlying_type<G4MTRunManager::WorkerActionRequest>::type
>(nextAction);
void SetNumberOfEventToBeProcessed(G4int n_ev)
G4VPhysicalVolume * IsWorldExisting(const G4String &worldName)
void WorkerG4ParticleTable()
G4int numberOfEventToBeProcessed
void SetDCtable(G4DCtable *DCtbl)
virtual G4int SetUpNEvents(G4Event *, G4SeedsQueue *seedsQueue, G4bool reseedRequired=true)
std::vector< G4String > GetCommandStack()
G4int GetNumberOfParallelWorld() const
virtual void SetUserInitialization(G4VUserDetectorConstruction *userInit)
void RemoveProcessManager()
void SetParallelWorldProcess(G4ParallelWorldProcess *proc)
G4int numberOfEventProcessed
G4String GetWorldName(G4int i) const
G4String randomNumberStatusForThisRun
virtual void RunTermination()
std::ostringstream G4ExceptionDescription
virtual void ThisWorkerEndEventLoop()
virtual void SetupRNGEngine(const CLHEP::HepRandomEngine *aRNGEngine) const
G4VUserPhysicsList * physicsList
virtual void InitializeGeometry()
G4String randomNumberStatusForThisEvent
static G4bool fGeometryHasBeenDestroyed
void GeometryHasBeenDestroyed()
static void UpdateGeometryAndPhysicsVectorFromMaster()
static G4VVisManager * GetConcreteInstance()
void SetIgnoreCmdNotFound(G4bool val)
void SetNumberOfParallelWorld(G4int i)
void SetProcessOrderingToSecond(G4VProcess *aProcess, G4ProcessVectorDoItIndex idDoIt)
G4VUserActionInitialization * userActionInitialization
void SetMeshElementLogical(G4LogicalVolume *val)
virtual void ConstructScoringWorlds()
static G4WorkerRunManager * GetWorkerRunManager()
virtual void WorkerRunEnd() const
G4bool storeRandomNumberStatus
G4String GetSelectMacro() const
G4bool IsAtRestRequired(G4ParticleDefinition *)
G4UserWorkerThreadInitialization * userWorkerThreadInitialization
virtual void TerminateEventLoop()
void ConstructParallelSD()
virtual void DoEventLoop(G4int n_event, const char *macroFile=0, G4int n_select=-1)
virtual void RunInitialization()
virtual void BeamOn(G4int n_event, const char *macroFile=0, G4int n_select=-1)
virtual const T GetSeed(const G4int &sdId)
virtual void WorkerRunStart() const
const G4UserWorkerInitialization * GetUserWorkerInitialization() const
void WorkerConstruct(G4VPhysicalVolume *fWorldPhys)
virtual void SetUserInitialization(G4VUserPhysicsList *userInit)
#define G4MUTEX_INITIALIZER
G4bool RunInitialization(G4bool fakeRun=false)
void WorkerDefineWorldVolume(G4VPhysicalVolume *worldVol, G4bool topologyIsChanged=true)
static G4UImanager * GetUIpointer()
static G4ParallelWorldProcessStore * GetInstance()
G4bool geometryInitialized
G4HCtable * GetHCtable() const
G4VUserPrimaryGeneratorAction * userPrimaryGeneratorAction
void SetParallelWorld(G4String parallelWorldName)
static G4RunManagerKernel * GetMasterRunManagerKernel()
G4GLOB_DLL std::ostream G4cout
void MergeRun(const G4Run *localRun)
void reset(G4bool ifSkipIon=true)
static G4ScoringManager * GetScoringManagerIfExist()
G4UserWorkerInitialization * userWorkerInitialization
G4String randomNumberStatusDir
G4bool rngStatusEventsFlag
virtual void AnalyzeEvent(G4Event *anEvent)
static G4MTRunManager * GetMasterRunManager()
G4int AddProcess(G4VProcess *aProcess, G4int ordAtRestDoIt=ordInActive, G4int ordAlongSteptDoIt=ordInActive, G4int ordPostStepDoIt=ordInActive)
G4int storeRandomNumberStatusToG4Event
virtual WorkerActionRequest ThisWorkerWaitForNextAction()
virtual void ThisWorkerProcessCommandsStackDone()
G4int GetThreadId() const
G4int GetNumberOfEventsToBeProcessed() const
G4bool readStatusFromFile
void SetProcessOrdering(G4VProcess *aProcess, G4ProcessVectorDoItIndex idDoIt, G4int ordDoIt=ordDefault)
virtual void SetMaster(G4bool val=true)
std::list< G4Event * > * previousEvents
G4UserRunAction * userRunAction
virtual void RunTermination()
virtual void ProcessOneEvent(G4int i_event)
void SetHCtable(G4HCtable *HCtbl)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
void SetRandomNumberStatus(G4String &st)
static G4TransportationManager * GetTransportationManager()
G4int GetNumberOfSelectEvents() const
const G4UserWorkerThreadInitialization * GetUserWorkerThreadInitialization() const
static G4RunManager * GetRunManager()
void ClearParallelWorlds()
static G4ScoringManager * GetMasterScoringManager()
virtual void ConstructSDandField()
virtual void GeneratePrimaries(G4Event *anEvent)=0
virtual void ThisWorkerReady()
static G4ParticleTable * GetParticleTable()
void CleanUpPreviousEvents()
virtual G4Event * GenerateEvent(G4int i_event)
G4ProcessManager * GetProcessManager() const
virtual G4bool SetUpAnEvent(G4Event *, long &s1, long &s2, long &s3, G4bool reseedRequired=true)
virtual void InitializeEventLoop(G4int n_event, const char *macroFile=0, G4int n_select=-1)
const CLHEP::HepRandomEngine * getMasterRandomEngine() const
G4int GetEventModulo() const
G4ParallelWorldProcess * GetParallelWorldProcess() const
virtual void BeginOfRunAction(const G4Run *aRun)
static G4int SeedOncePerCommunication()
static G4TemplateRNGHelper< T > * GetInstance()
G4LogicalVolume * GetMeshElementLogical() const
std::vector< G4InuclElementaryParticle >::iterator particleIterator
void ProcessOneEvent(G4Event *anEvent)
G4RunManagerKernel * kernel
static G4ScoringManager * GetScoringManager()
size_t GetNumberOfMesh() const
G4EventManager * eventManager
virtual void TerminateOneEvent()
G4VUserDetectorConstruction * userDetector
G4VScoringMesh * GetMesh(G4int i) const
virtual void SetUserAction(G4UserRunAction *userAction)
void SetRandomNumberStatus(G4String &st)
void WorkerUpdateWorldVolume()
virtual G4Run * GenerateRun()
void MergeScores(const G4ScoringManager *localScoringManager)
G4PTblDicIterator * GetIterator() const
G4int n_perviousEventsToBeStored
G4VPhysicalVolume * GetCurrentWorld() const
G4int ApplyCommand(const char *aCommand)
virtual void SetUserAction(G4UserRunAction *userAction)
static G4SDManager * GetSDMpointerIfExist()
static G4WorkerRunManagerKernel * GetWorkerRunManagerKernel()
virtual void MergePartialResults()
virtual void StoreRNGStatus(const G4String &filenamePrefix)