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 "
108#ifdef G4MULTITHREADED
110 if (pVVis !=
nullptr) {
111 pVVis->SetUpForAThread();
137 "G4VUserDetectorConstruction is not defined!");
160#ifdef G4MULTITHREADED
163 if (pVVis !=
nullptr) {
164 pVVis->SetUpForAThread();
195 if (fSDM !=
nullptr) {
205 std::ostringstream oss;
206 G4Random::saveFullState(oss);
220#if defined(GEANT4_USE_TIMEMORY)
231 std::ostringstream os;
247 "G4VUserPrimaryGeneratorAction is not defined!");
298 auto anEvent =
new G4Event(i_event);
302 G4bool eventHasToBeSeeded =
true;
304 eventHasToBeSeeded =
false;
344 else if (eventHasToBeSeeded) {
347 s1 = helper->
GetSeed(i_event * 2);
348 s2 = helper->
GetSeed(i_event * 2 + 1);
351 if (eventHasToBeSeeded) {
352 G4long seeds[3] = {s1, s2, 0};
353 G4Random::setTheSeeds(seeds,
luxury);
364 const auto filename = [&] {
365 std::ostringstream os;
370 G4bool RNGstatusReadFromFile =
false;
373 std::ostringstream os;
374 os << filename() <<
".rndm";
375 const G4String& randomStatusFile = os.str();
376 std::ifstream ifile(randomStatusFile.c_str());
378 RNGstatusReadFromFile =
true;
379 G4Random::restoreEngineStatus(randomStatusFile.c_str());
384 std::ostringstream oss;
385 G4Random::saveFullState(oss);
400 G4cout <<
"--> Event " << anEvent->GetEventID() <<
" starts";
401 if (eventHasToBeSeeded) {
402 G4cout <<
" with initial seeds (" << s1 <<
"," << s2 <<
")";
424#if defined(GEANT4_USE_TIMEMORY)
425 workerRunProfiler.reset();
473 if (ScM ==
nullptr)
return;
475 if (nPar < 1)
return;
484 for (
G4int iw = 0; iw < nPar; ++iw) {
488 if (mesh->
GetShape() != MeshShape::realWorldLogVol) {
491 if (pWorld ==
nullptr) {
493 ed <<
"Mesh name <" << ScM->
GetWorldName(iw) <<
"> is not found in the master thread.";
503 if (mesh->
GetShape() != MeshShape::realWorldLogVol) {
505 if (theParallelWorldProcess !=
nullptr) {
517 if (pmanager !=
nullptr) {
518 pmanager->
AddProcess(theParallelWorldProcess);
537 G4Exception(
"G4RunManager::SetUserInitialization(G4UserWorkerInitialization*)",
"Run0118",
538 FatalException,
"This method should be used only with an instance of G4MTRunManager");
544 G4Exception(
"G4RunManager::SetUserInitialization(G4UserWorkerThreadInitialization*)",
"Run0119",
545 FatalException,
"This method should be used only with an instance of G4MTRunManager");
551 G4Exception(
"G4RunManager::SetUserInitialization(G4VUserActionInitialization*)",
"Run0120",
552 FatalException,
"This method should be used only with an instance of G4MTRunManager");
558 G4Exception(
"G4RunManager::SetUserInitialization(G4VUserDetectorConstruction*)",
"Run0121",
559 FatalException,
"This method should be used only with an instance of G4MTRunManager");
573 if (userAction !=
nullptr) userAction->
SetMaster(
false);
577void G4WorkerRunManager::SetupDefaultRNGEngine()
621 std::ostringstream os;
623 G4Random::saveEngineStatus(os.str().c_str());
632 G4cerr <<
"Warning from G4RunManager::rndmSaveThisRun():"
633 <<
" Random number status was not stored prior to this run." <<
G4endl
634 <<
"/random/setSavingFlag command must be issued. "
635 <<
"Command ignored." <<
G4endl;
639 std::ostringstream oos;
645 std::ostringstream os;
646 os <<
"run" << runNumber <<
".rndm" <<
'\0';
652 G4cout << fileIn <<
" is copied to " << fileOut <<
G4endl;
660 G4cerr <<
"Warning from G4RunManager::rndmSaveThisEvent():"
661 <<
" there is no currentEvent available." <<
G4endl <<
"Command ignored." <<
G4endl;
666 G4cerr <<
"Warning from G4RunManager::rndmSaveThisEvent():"
667 <<
" Random number engine status is not available." <<
G4endl
668 <<
"/random/setSavingFlag command must be issued "
669 <<
"prior to the start of the run. Command ignored." <<
G4endl;
673 std::ostringstream oos;
675 <<
"currentEvent.rndm"
679 std::ostringstream os;
683 if (
G4CopyRandomState(fileIn, fileOut,
"G4WorkerRunManager::rndmSaveThisEvent()")
686 G4cout << fileIn <<
" is copied to " << fileOut <<
G4endl;
701 if (skipInitialization) {
703 skipInitialization =
false;
713 for (
const auto& cmd : cmds) {
720 if (macroFile.empty() || macroFile ==
" ") {
724 this->
BeamOn(numevents, macroFile, numSelect);
730 for (
const auto& cmd : cmds) {
737 d <<
"Cannot continue, this worker has been requested an unknown action: "
738 <<
static_cast<std::underlying_type<G4MTRunManager::WorkerActionRequest>::type
>(nextAction);
std::vector< G4InuclElementaryParticle >::iterator particleIterator
Helper function for copying random state files in G4run.
G4bool G4CopyRandomState(const G4fs::path &source, const G4fs::path &dest, const G4String &callsite)
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)
static G4int SeedOncePerCommunication()
virtual WorkerActionRequest ThisWorkerWaitForNextAction()
virtual void ThisWorkerProcessCommandsStackDone()
virtual G4int SetUpNEvents(G4Event *, G4SeedsQueue *seedsQueue, 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 G4bool SetUpAnEvent(G4Event *, G4long &s1, G4long &s2, G4long &s3, G4bool reseedRequired=true)
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 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 SetMaster(G4bool val=true)
virtual G4Run * GenerateRun()
virtual void BeginOfRunAction(const G4Run *)
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()
static G4WorkerRunManagerKernel * GetWorkerRunManagerKernel()
void InitializeGeometry() override
void rndmSaveThisRun() override
void RunTermination() override
void SetUserAction(G4UserRunAction *userAction) override
G4Event * GenerateEvent(G4int i_event) override
G4bool readStatusFromFile
virtual void MergePartialResults()
G4WorkerThread * workerContext
void rndmSaveThisEvent() override
void TerminateEventLoop() override
~G4WorkerRunManager() override
void RunInitialization() override
void SetUserInitialization(G4VUserPhysicsList *userInit) override
void ProcessOneEvent(G4int i_event) override
static G4WorkerRunManager * GetWorkerRunManager()
void ConstructScoringWorlds() override
G4ProfilerConfig< G4ProfileType::Run > ProfilerConfig
void DoEventLoop(G4int n_event, const char *macroFile=nullptr, G4int n_select=-1) override
void StoreRNGStatus(const G4String &filenamePrefix) override
G4int GetThreadId() const
static void UpdateGeometryAndPhysicsVectorFromMaster()