Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4WorkerRunManager Class Reference

#include <G4WorkerRunManager.hh>

+ Inheritance diagram for G4WorkerRunManager:

Public Types

using ProfilerConfig = G4ProfilerConfig<G4ProfileType::Run>
 
- Public Types inherited from G4RunManager
enum  RMType { sequentialRM , masterRM , workerRM }
 
using ProfilerConfig = G4ProfilerConfig<G4ProfileType::Run>
 

Public Member Functions

 G4WorkerRunManager ()
 
 ~G4WorkerRunManager () override
 
void InitializeGeometry () override
 
void RunInitialization () override
 
void DoEventLoop (G4int n_event, const char *macroFile=nullptr, G4int n_select=-1) override
 
void ProcessOneEvent (G4int i_event) override
 
G4EventGenerateEvent (G4int i_event) override
 
void RunTermination () override
 
void TerminateEventLoop () override
 
virtual void DoWork ()
 
void SetWorkerThread (G4WorkerThread *wc)
 
void SetUserInitialization (G4VUserPhysicsList *userInit) override
 
void SetUserInitialization (G4VUserDetectorConstruction *userInit) override
 
void SetUserInitialization (G4VUserActionInitialization *userInit) override
 
void SetUserInitialization (G4UserWorkerInitialization *userInit) override
 
void SetUserInitialization (G4UserWorkerThreadInitialization *userInit) override
 
void SetUserAction (G4UserRunAction *userAction) override
 
void SetUserAction (G4VUserPrimaryGeneratorAction *userAction) override
 
void SetUserAction (G4UserEventAction *userAction) override
 
void SetUserAction (G4UserStackingAction *userAction) override
 
void SetUserAction (G4UserTrackingAction *userAction) override
 
void SetUserAction (G4UserSteppingAction *userAction) override
 
void RestoreRndmEachEvent (G4bool flag) override
 
- Public Member Functions inherited from G4RunManager
 G4RunManager ()
 
virtual ~G4RunManager ()
 
 G4RunManager (const G4RunManager &)=delete
 
G4RunManageroperator= (const G4RunManager &)=delete
 
virtual void BeamOn (G4int n_event, const char *macroFile=nullptr, G4int n_select=-1)
 
virtual void Initialize ()
 
virtual void DefineWorldVolume (G4VPhysicalVolume *worldVol, G4bool topologyIsChanged=true)
 
virtual void AbortRun (G4bool softAbort=false)
 
virtual void AbortEvent ()
 
virtual void InitializePhysics ()
 
virtual G4bool ConfirmBeamOnCondition ()
 
virtual void InitializeEventLoop (G4int n_event, const char *macroFile=nullptr, G4int n_select=-1)
 
virtual void TerminateOneEvent ()
 
virtual void AnalyzeEvent (G4Event *anEvent)
 
virtual void ConfigureProfilers (const std::vector< std::string > &args={})
 
void ConfigureProfilers (G4int argc, char **argv)
 
virtual void SetNumberOfThreads (G4int)
 
virtual G4int GetNumberOfThreads () const
 
void DumpRegion (const G4String &rname) const
 
void DumpRegion (G4Region *region=nullptr) const
 
void GeometryHasBeenModified (G4bool prop=true)
 
void ReinitializeGeometry (G4bool destroyFirst=false, G4bool prop=true)
 
void PhysicsHasBeenModified ()
 
void CutOffHasBeenModified ()
 
void ReOptimizeMotherOf (G4VPhysicalVolume *)
 
void ReOptimize (G4LogicalVolume *)
 
void SetGeometryToBeOptimized (G4bool vl)
 
G4bool GetGeometryToBeOptimized ()
 
void GeometryDirectlyUpdated (G4bool val=true)
 
virtual void RestoreRandomNumberStatus (const G4String &fileN)
 
const G4VUserDetectorConstructionGetUserDetectorConstruction () const
 
const G4VUserPhysicsListGetUserPhysicsList () const
 
const G4VUserActionInitializationGetUserActionInitialization () const
 
G4VUserActionInitializationGetNonConstUserActionInitialization () const
 
const G4UserWorkerInitializationGetUserWorkerInitialization () const
 
const G4UserWorkerThreadInitializationGetUserWorkerThreadInitialization () const
 
const G4UserRunActionGetUserRunAction () const
 
const G4VUserPrimaryGeneratorActionGetUserPrimaryGeneratorAction () const
 
const G4UserEventActionGetUserEventAction () const
 
const G4UserStackingActionGetUserStackingAction () const
 
const G4UserTrackingActionGetUserTrackingAction () const
 
const G4UserSteppingActionGetUserSteppingAction () const
 
void SetNumberOfAdditionalWaitingStacks (G4int iAdd)
 
const G4StringGetVersionString () const
 
void SetPrimaryTransformer (G4PrimaryTransformer *pt)
 
void StoreRandomNumberStatusToG4Event (G4int vl)
 
G4int GetFlagRandomNumberStatusToG4Event () const
 
void SetRandomNumberStore (G4bool flag)
 
G4bool GetRandomNumberStore () const
 
void SetRandomNumberStoreDir (const G4String &dir)
 
const G4StringGetRandomNumberStoreDir () const
 
const G4StringGetRandomNumberStatusForThisRun () const
 
const G4StringGetRandomNumberStatusForThisEvent () const
 
void SetRandomNumberStorePerEvent (G4bool flag)
 
G4bool GetRandomNumberStorePerEvent () const
 
void SetVerboseLevel (G4int vl)
 
G4int GetVerboseLevel () const
 
G4int GetPrintProgress ()
 
void SetPrintProgress (G4int i)
 
void SetNumberOfEventsToBeStored (G4int val)
 
const G4RunGetCurrentRun () const
 
G4RunGetNonConstCurrentRun () const
 
const G4EventGetCurrentEvent () const
 
const G4EventGetPreviousEvent (G4int i) const
 
void SetRunIDCounter (G4int i)
 
G4int GetNumberOfParallelWorld () const
 
void SetNumberOfEventsToBeProcessed (G4int val)
 
G4int GetNumberOfEventsToBeProcessed () const
 
G4int GetNumberOfSelectEvents () const
 
const G4StringGetSelectMacro () const
 
void SetDCtable (G4DCtable *DCtbl)
 
RMType GetRunManagerType () const
 

Static Public Member Functions

static G4WorkerRunManagerGetWorkerRunManager ()
 
static G4WorkerRunManagerKernelGetWorkerRunManagerKernel ()
 
- Static Public Member Functions inherited from G4RunManager
static G4RunManagerGetRunManager ()
 
static G4bool IfGeometryHasBeenDestroyed ()
 

Protected Member Functions

void ConstructScoringWorlds () override
 
void StoreRNGStatus (const G4String &filenamePrefix) override
 
void rndmSaveThisRun () override
 
void rndmSaveThisEvent () override
 
virtual void MergePartialResults ()
 
- Protected Member Functions inherited from G4RunManager
 G4RunManager (RMType rmType)
 
void CleanUpPreviousEvents ()
 
void CleanUpUnnecessaryEvents (G4int keepNEvents)
 
void StackPreviousEvent (G4Event *anEvent)
 
void UpdateScoring ()
 
virtual void DeleteUserInitializations ()
 

Protected Attributes

G4WorkerThreadworkerContext = nullptr
 
G4bool eventLoopOnGoing = false
 
G4bool runIsSeeded = false
 
G4int nevModulo = -1
 
G4int currEvID = -1
 
G4int luxury = -1
 
G4SeedsQueue seedsQueue
 
G4bool readStatusFromFile = false
 
- Protected Attributes inherited from G4RunManager
G4RunManagerKernelkernel = nullptr
 
G4EventManagereventManager = nullptr
 
G4VUserDetectorConstructionuserDetector = nullptr
 
G4VUserPhysicsListphysicsList = nullptr
 
G4VUserActionInitializationuserActionInitialization = nullptr
 
G4UserWorkerInitializationuserWorkerInitialization = nullptr
 
G4UserWorkerThreadInitializationuserWorkerThreadInitialization = nullptr
 
G4UserRunActionuserRunAction = nullptr
 
G4VUserPrimaryGeneratorActionuserPrimaryGeneratorAction = nullptr
 
G4UserEventActionuserEventAction = nullptr
 
G4UserStackingActionuserStackingAction = nullptr
 
G4UserTrackingActionuserTrackingAction = nullptr
 
G4UserSteppingActionuserSteppingAction = nullptr
 
G4bool geometryInitialized = false
 
G4bool physicsInitialized = false
 
G4bool runAborted = false
 
G4bool initializedAtLeastOnce = false
 
G4bool geometryToBeOptimized = true
 
G4int runIDCounter = 0
 
G4int verboseLevel = 0
 
G4int printModulo = -1
 
G4Timertimer = nullptr
 
G4DCtableDCtable = nullptr
 
G4RuncurrentRun = nullptr
 
G4EventcurrentEvent = nullptr
 
std::list< G4Event * > * previousEvents = nullptr
 
G4int n_perviousEventsToBeStored = 0
 
G4int numberOfEventToBeProcessed = 0
 
G4bool storeRandomNumberStatus = false
 
G4int storeRandomNumberStatusToG4Event = 0
 
G4String randomNumberStatusDir = "./"
 
G4String randomNumberStatusForThisRun = ""
 
G4String randomNumberStatusForThisEvent = ""
 
G4bool rngStatusEventsFlag = false
 
G4VPhysicalVolumecurrentWorld = nullptr
 
G4int nParallelWorlds = 0
 
G4String msgText = " "
 
G4int n_select_msg = -1
 
G4int numberOfEventProcessed = 0
 
G4String selectMacro = ""
 
G4bool fakeRun = false
 
G4bool isScoreNtupleWriter = false
 
G4bool geometryDirectlyUpdated = false
 
RMType runManagerType
 

Additional Inherited Members

- Static Protected Attributes inherited from G4RunManager
static G4RUN_DLL G4bool fGeometryHasBeenDestroyed = false
 

Detailed Description

Definition at line 48 of file G4WorkerRunManager.hh.

Member Typedef Documentation

◆ ProfilerConfig

Constructor & Destructor Documentation

◆ G4WorkerRunManager()

G4WorkerRunManager::G4WorkerRunManager ( )

Definition at line 75 of file G4WorkerRunManager.cc.

76{
77 // This constructor should never be called in non-multithreaded mode
78
79#ifndef G4MULTITHREADED
81 msg << "Geant4 code is compiled without multi-threading support "
82 "(-DG4MULTITHREADED "
83 "is set to off).";
84 msg << " This type of RunManager can only be used in mult-threaded "
85 "applications.";
86 G4Exception("G4WorkerRunManager::G4WorkerRunManager()", "Run0103", FatalException, msg);
87#endif
88 // G4ParticleTable::GetParticleTable()->WorkerG4ParticleTable();
89 // WorkerG4ParticleTable() would be performed twice,
90 // as it is called already from G4ParticleTable::GetParticleTable()
91 // which is called beforehand by other Geant4 classes
93 if (masterScM != nullptr) G4ScoringManager::GetScoringManager(); // TLS instance for a worker
94
95 // Properly initialise luxury level for Ranlux* engines...
96 //
97 if (dynamic_cast<const CLHEP::Ranlux64Engine*>(G4Random::getTheEngine()) != nullptr) {
98 const auto theEngine = dynamic_cast<const CLHEP::Ranlux64Engine*>(G4Random::getTheEngine());
100 }
101 else if (dynamic_cast<const CLHEP::RanluxEngine*>(G4Random::getTheEngine()) != nullptr) {
102 const auto theEngine = dynamic_cast<const CLHEP::RanluxEngine*>(G4Random::getTheEngine());
104 }
105
107
108#ifdef G4MULTITHREADED
110 if (pVVis != nullptr) {
111 pVVis->SetUpForAThread();
112 visIsSetUp = true;
113 }
114#endif
115}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
std::shared_ptr< HepRandomEngine > theEngine
Definition Random.cc:76
int getLuxury() const
static G4ScoringManager * GetMasterScoringManager()
static G4ScoringManager * GetScoringManager()
void SetIgnoreCmdNotFound(G4bool val)
static G4UImanager * GetUIpointer()
static G4VVisManager * GetConcreteInstance()

◆ ~G4WorkerRunManager()

G4WorkerRunManager::~G4WorkerRunManager ( )
override

Definition at line 118 of file G4WorkerRunManager.cc.

119{
121 // Put these pointers to zero: owned by master thread
122 // If not to zero, the base class destructor will attempt to
123 // delete them
124 userDetector = nullptr;
125 userWorkerInitialization = nullptr;
127 userActionInitialization = nullptr;
128 physicsList = nullptr;
129 if (verboseLevel > 1) G4cout << "Destroying WorkerRunManager (" << this << ")" << G4endl;
130}
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
void CleanUpPreviousEvents()
G4UserWorkerInitialization * userWorkerInitialization
G4UserWorkerThreadInitialization * userWorkerThreadInitialization
G4VUserActionInitialization * userActionInitialization
G4VUserDetectorConstruction * userDetector
G4VUserPhysicsList * physicsList

Member Function Documentation

◆ ConstructScoringWorlds()

void G4WorkerRunManager::ConstructScoringWorlds ( )
overrideprotectedvirtual

Reimplemented from G4RunManager.

Definition at line 467 of file G4WorkerRunManager.cc.

468{
469 using MeshShape = G4VScoringMesh::MeshShape;
470
471 // Return if unnecessary
473 if (ScM == nullptr) return;
474 auto nPar = (G4int)ScM->GetNumberOfMesh();
475 if (nPar < 1) return;
476
477 // Update thread-local G4TransportationManager of all the world volumes
479
481
483
484 for (G4int iw = 0; iw < nPar; ++iw) {
485 G4VScoringMesh* mesh = ScM->GetMesh(iw);
487 G4VPhysicalVolume* pWorld = nullptr;
488 if (mesh->GetShape() != MeshShape::realWorldLogVol) {
489 pWorld =
491 if (pWorld == nullptr) {
493 ed << "Mesh name <" << ScM->GetWorldName(iw) << "> is not found in the master thread.";
494 G4Exception("G4WorkerRunManager::ConstructScoringWorlds()", "RUN79001", FatalException, ed);
495 }
496 }
497 if ((mesh->GetMeshElementLogical()) == nullptr) {
498 G4AutoLock l(&ConstructScoringWorldsMutex);
499 G4VScoringMesh* masterMesh = masterScM->GetMesh(iw);
500 mesh->SetMeshElementLogical(masterMesh->GetMeshElementLogical());
501 l.unlock();
502
503 if (mesh->GetShape() != MeshShape::realWorldLogVol) {
504 G4ParallelWorldProcess* theParallelWorldProcess = mesh->GetParallelWorldProcess();
505 if (theParallelWorldProcess != nullptr) {
506 theParallelWorldProcess->SetParallelWorld(ScM->GetWorldName(iw));
507 }
508 else {
509 theParallelWorldProcess = new G4ParallelWorldProcess(ScM->GetWorldName(iw));
510 mesh->SetParallelWorldProcess(theParallelWorldProcess);
511 theParallelWorldProcess->SetParallelWorld(ScM->GetWorldName(iw));
512
513 particleIterator->reset();
514 while ((*particleIterator)()) {
515 G4ParticleDefinition* particle = particleIterator->value();
516 G4ProcessManager* pmanager = particle->GetProcessManager();
517 if (pmanager != nullptr) {
518 pmanager->AddProcess(theParallelWorldProcess);
519 if (theParallelWorldProcess->IsAtRestRequired(particle)) {
520 pmanager->SetProcessOrdering(theParallelWorldProcess, idxAtRest, 9900);
521 }
522 pmanager->SetProcessOrderingToSecond(theParallelWorldProcess, idxAlongStep);
523 pmanager->SetProcessOrdering(theParallelWorldProcess, idxPostStep, 9900);
524 } // if(pmanager)
525 } // while
526 }
527 theParallelWorldProcess->SetLayeredMaterialFlag(mesh->LayeredMassFlg());
528 }
529 }
530 mesh->WorkerConstruct(pWorld);
531 }
532}
std::vector< G4InuclElementaryParticle >::iterator particleIterator
@ idxPostStep
@ idxAtRest
@ idxAlongStep
int G4int
Definition G4Types.hh:85
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)
G4RunManagerKernel * kernel
static G4RUN_DLL G4bool fGeometryHasBeenDestroyed
G4VScoringMesh * GetMesh(G4int i) const
size_t GetNumberOfMesh() const
G4String GetWorldName(G4int i) const
static G4ScoringManager * GetScoringManagerIfExist()
static G4TransportationManager * GetTransportationManager()
G4VPhysicalVolume * IsWorldExisting(const G4String &worldName)
MeshShape GetShape() const
G4LogicalVolume * GetMeshElementLogical() const
virtual void WorkerConstruct(G4VPhysicalVolume *fWorldPhys)
void GeometryHasBeenDestroyed()
G4ParallelWorldProcess * GetParallelWorldProcess() const
void SetParallelWorldProcess(G4ParallelWorldProcess *proc)
void SetMeshElementLogical(G4LogicalVolume *val)
G4bool LayeredMassFlg()

Referenced by G4WorkerTaskRunManager::DoWork().

◆ DoEventLoop()

void G4WorkerRunManager::DoEventLoop ( G4int n_event,
const char * macroFile = nullptr,
G4int n_select = -1 )
overridevirtual

Reimplemented from G4RunManager.

Reimplemented in G4WorkerTaskRunManager.

Definition at line 243 of file G4WorkerRunManager.cc.

244{
245 if (userPrimaryGeneratorAction == nullptr) {
246 G4Exception("G4RunManager::GenerateEvent()", "Run0032", FatalException,
247 "G4VUserPrimaryGeneratorAction is not defined!");
248 }
249
250 // This is the same as in the sequential case, just the for-loop indexes are
251 // different
252 InitializeEventLoop(n_event, macroFile, n_select);
253
254 // Reset random number seeds queue
255 while (!seedsQueue.empty()) {
256 seedsQueue.pop();
257 }
258 // for each run, worker should receive at least one set of random number
259 // seeds.
260 runIsSeeded = false;
261
262 // Event loop
263 eventLoopOnGoing = true;
264 /////// G4int i_event = workerContext->GetThreadId();
265 G4int i_event = -1;
266 nevModulo = -1;
267 currEvID = -1;
268
269 while (eventLoopOnGoing) {
270 ProcessOneEvent(i_event);
271 if (eventLoopOnGoing) {
273 if (runAborted) {
274 eventLoopOnGoing = false;
275 }
276 }
277 }
278
280}
virtual void InitializeEventLoop(G4int n_event, const char *macroFile=nullptr, G4int n_select=-1)
G4VUserPrimaryGeneratorAction * userPrimaryGeneratorAction
virtual void TerminateOneEvent()
void TerminateEventLoop() override
void ProcessOneEvent(G4int i_event) override

◆ DoWork()

void G4WorkerRunManager::DoWork ( )
virtual

Reimplemented in G4WorkerTaskRunManager.

Definition at line 691 of file G4WorkerRunManager.cc.

692{
696 if (nextAction == G4MTRunManager::WorkerActionRequest::NEXTITERATION) // start the next
697 // run
698 {
699 // The following code deals with changing materials between runs
700 static G4ThreadLocal G4bool skipInitialization = true;
701 if (skipInitialization) {
702 // re-initialization is not necessary for the first run
703 skipInitialization = false;
704 }
705 else {
706 // ReinitializeGeometry();
708 }
709
710 // Execute UI commands stored in the master UI manager
711 std::vector<G4String> cmds = mrm->GetCommandStack();
712 G4UImanager* uimgr = G4UImanager::GetUIpointer(); // TLS instance
713 for (const auto& cmd : cmds) {
714 uimgr->ApplyCommand(cmd);
715 }
716 // Start this run
717 G4int numevents = mrm->GetNumberOfEventsToBeProcessed();
718 G4String macroFile = mrm->GetSelectMacro();
719 G4int numSelect = mrm->GetNumberOfSelectEvents();
720 if (macroFile.empty() || macroFile == " ") {
721 this->BeamOn(numevents);
722 }
723 else {
724 this->BeamOn(numevents, macroFile, numSelect);
725 }
726 }
727 else if (nextAction == G4MTRunManager::WorkerActionRequest::PROCESSUI) {
728 std::vector<G4String> cmds = mrm->GetCommandStack();
729 G4UImanager* uimgr = G4UImanager::GetUIpointer(); // TLS instance
730 for (const auto& cmd : cmds) {
731 uimgr->ApplyCommand(cmd);
732 }
734 }
735 else {
737 d << "Cannot continue, this worker has been requested an unknown action: "
738 << static_cast<std::underlying_type<G4MTRunManager::WorkerActionRequest>::type>(nextAction);
739 G4Exception("G4WorkerRunManager::DoWork", "Run0104", FatalException, d);
740 }
741
742 // Now wait for master thread to signal new action to be performed
743 nextAction = mrm->ThisWorkerWaitForNextAction();
744 } // No more actions to perform
745
746 return;
747}
bool G4bool
Definition G4Types.hh:86
virtual WorkerActionRequest ThisWorkerWaitForNextAction()
virtual void ThisWorkerProcessCommandsStackDone()
static G4MTRunManager * GetMasterRunManager()
std::vector< G4String > GetCommandStack()
G4int GetNumberOfEventsToBeProcessed() const
virtual void BeamOn(G4int n_event, const char *macroFile=nullptr, G4int n_select=-1)
const G4String & GetSelectMacro() const
G4int GetNumberOfSelectEvents() const
G4int ApplyCommand(const char *aCommand)
G4WorkerThread * workerContext
static void UpdateGeometryAndPhysicsVectorFromMaster()
#define G4ThreadLocal
Definition tls.hh:77

Referenced by G4MTRunManagerKernel::StartThread().

◆ GenerateEvent()

G4Event * G4WorkerRunManager::GenerateEvent ( G4int i_event)
overridevirtual

Reimplemented from G4RunManager.

Reimplemented in G4WorkerTaskRunManager.

Definition at line 296 of file G4WorkerRunManager.cc.

297{
298 auto anEvent = new G4Event(i_event);
299 G4long s1 = 0;
300 G4long s2 = 0;
301 G4long s3 = 0;
302 G4bool eventHasToBeSeeded = true;
304 eventHasToBeSeeded = false;
305 }
306
307 if (i_event < 0) {
309 if (nevM == 1) {
311 eventHasToBeSeeded);
312 runIsSeeded = true;
313 }
314 else {
315 if (nevModulo <= 0) {
317 eventHasToBeSeeded);
318 if (nevToDo == 0) {
319 eventLoopOnGoing = false;
320 }
321 else {
322 currEvID = anEvent->GetEventID();
323 nevModulo = nevToDo - 1;
324 }
325 }
326 else {
327 if (G4MTRunManager::SeedOncePerCommunication() > 0) eventHasToBeSeeded = false;
328 anEvent->SetEventID(++currEvID);
329 --nevModulo;
330 }
331 if (eventLoopOnGoing && eventHasToBeSeeded) {
332 s1 = seedsQueue.front();
333 seedsQueue.pop();
334 s2 = seedsQueue.front();
335 seedsQueue.pop();
336 }
337 }
338
339 if (!eventLoopOnGoing) {
340 delete anEvent;
341 return nullptr;
342 }
343 }
344 else if (eventHasToBeSeeded) {
345 // Need to reseed random number generator
347 s1 = helper->GetSeed(i_event * 2);
348 s2 = helper->GetSeed(i_event * 2 + 1);
349 }
350
351 if (eventHasToBeSeeded) {
352 G4long seeds[3] = {s1, s2, 0};
353 G4Random::setTheSeeds(seeds, luxury);
354 runIsSeeded = true;
355 }
356
357 // Read from file seed.
358 // Andrea Dotti 4 November 2015
359 // This is required for strong-reproducibility, in MT mode we have that each
360 // thread produces, for each event a status file, we want to do that.
361 // Search a random file with the format run{%d}evt{%d}.rndm
362
363 // This is the filename base constructed from run and event
364 const auto filename = [&] {
365 std::ostringstream os;
366 os << "run" << currentRun->GetRunID() << "evt" << anEvent->GetEventID();
367 return os.str();
368 };
369
370 G4bool RNGstatusReadFromFile = false;
371 if (readStatusFromFile) {
372 // Build full path of RNG status file for this event
373 std::ostringstream os;
374 os << filename() << ".rndm";
375 const G4String& randomStatusFile = os.str();
376 std::ifstream ifile(randomStatusFile.c_str());
377 if (ifile) { // File valid and readable
378 RNGstatusReadFromFile = true;
379 G4Random::restoreEngineStatus(randomStatusFile.c_str());
380 }
381 }
382
384 std::ostringstream oss;
385 G4Random::saveFullState(oss);
387 anEvent->SetRandomNumberStatus(randomNumberStatusForThisEvent);
388 }
389
390 if (storeRandomNumberStatus && !RNGstatusReadFromFile)
391 { // If reading from file, avoid to rewrite the same
392 G4String fileN = "currentEvent";
394 fileN = filename();
395 }
396 StoreRNGStatus(fileN);
397 }
398
399 if (printModulo > 0 && anEvent->GetEventID() % printModulo == 0) {
400 G4cout << "--> Event " << anEvent->GetEventID() << " starts";
401 if (eventHasToBeSeeded) {
402 G4cout << " with initial seeds (" << s1 << "," << s2 << ")";
403 }
404 G4cout << "." << G4endl;
405 }
407 return anEvent;
408}
long G4long
Definition G4Types.hh:87
static G4int SeedOncePerCommunication()
virtual G4int SetUpNEvents(G4Event *, G4SeedsQueue *seedsQueue, G4bool reseedRequired=true)
G4int GetEventModulo() const
virtual G4bool SetUpAnEvent(G4Event *, G4long &s1, G4long &s2, G4long &s3, G4bool reseedRequired=true)
G4int storeRandomNumberStatusToG4Event
G4Run * currentRun
G4bool rngStatusEventsFlag
G4String randomNumberStatusForThisEvent
G4bool storeRandomNumberStatus
G4int GetRunID() const
Definition G4Run.hh:86
static G4TemplateRNGHelper< T > * GetInstance()
virtual const T GetSeed(const G4int &sdId)
virtual void GeneratePrimaries(G4Event *anEvent)=0
void StoreRNGStatus(const G4String &filenamePrefix) override

Referenced by ProcessOneEvent().

◆ GetWorkerRunManager()

G4WorkerRunManager * G4WorkerRunManager::GetWorkerRunManager ( )
static

◆ GetWorkerRunManagerKernel()

G4WorkerRunManagerKernel * G4WorkerRunManager::GetWorkerRunManagerKernel ( )
static

Definition at line 69 of file G4WorkerRunManager.cc.

70{
72}
static G4WorkerRunManager * GetWorkerRunManager()

◆ InitializeGeometry()

void G4WorkerRunManager::InitializeGeometry ( )
overridevirtual

Reimplemented from G4RunManager.

Definition at line 133 of file G4WorkerRunManager.cc.

134{
135 if (userDetector == nullptr) {
136 G4Exception("G4RunManager::InitializeGeometry", "Run0033", FatalException,
137 "G4VUserDetectorConstruction is not defined!");
138 return;
139 }
142 }
143
144 // Step1: Get pointer to the physiWorld (note: needs to get the "super
145 // pointer, i.e. the one shared by all threads"
147 G4VPhysicalVolume* worldVol = masterKernel->GetCurrentWorld();
148 // Step2:, Call a new "WorkerDefineWorldVolume( pointer from 2-, false);
149 kernel->WorkerDefineWorldVolume(worldVol, false);
151 // Step3: Call user's ConstructSDandField()
154 geometryInitialized = true;
155}
static G4RunManagerKernel * GetMasterRunManagerKernel()
G4VPhysicalVolume * GetCurrentWorld() const
void SetNumberOfParallelWorld(G4int i)
void WorkerDefineWorldVolume(G4VPhysicalVolume *worldVol, G4bool topologyIsChanged=true)
G4int GetNumberOfParallelWorld() const
G4bool geometryInitialized

◆ MergePartialResults()

void G4WorkerRunManager::MergePartialResults ( )
protectedvirtual

Definition at line 411 of file G4WorkerRunManager.cc.

412{
413 // Merge partial results into global run
416 if (ScM != nullptr) mtRM->MergeScores(ScM);
417 mtRM->MergeRun(currentRun);
418}
void MergeRun(const G4Run *localRun)
void MergeScores(const G4ScoringManager *localScoringManager)

Referenced by RunTermination(), and G4WorkerTaskRunManager::RunTermination().

◆ ProcessOneEvent()

void G4WorkerRunManager::ProcessOneEvent ( G4int i_event)
overridevirtual

Reimplemented from G4RunManager.

Reimplemented in G4WorkerTaskRunManager.

Definition at line 283 of file G4WorkerRunManager.cc.

284{
285 currentEvent = GenerateEvent(i_event);
286 if (eventLoopOnGoing) {
292 }
293}
void ProcessOneEvent(G4Event *anEvent)
G4int GetEventID() const
Definition G4Event.hh:123
G4String msgText
G4EventManager * eventManager
virtual void AnalyzeEvent(G4Event *anEvent)
void UpdateScoring()
G4Event * currentEvent
G4Event * GenerateEvent(G4int i_event) override

Referenced by DoEventLoop().

◆ RestoreRndmEachEvent()

void G4WorkerRunManager::RestoreRndmEachEvent ( G4bool flag)
inlineoverridevirtual

Reimplemented from G4RunManager.

Reimplemented in G4WorkerTaskRunManager.

Definition at line 88 of file G4WorkerRunManager.hh.

88{ readStatusFromFile = flag; }

◆ rndmSaveThisEvent()

void G4WorkerRunManager::rndmSaveThisEvent ( )
overrideprotectedvirtual

Reimplemented from G4RunManager.

Definition at line 657 of file G4WorkerRunManager.cc.

658{
659 if (currentEvent == nullptr) {
660 G4cerr << "Warning from G4RunManager::rndmSaveThisEvent():"
661 << " there is no currentEvent available." << G4endl << "Command ignored." << G4endl;
662 return;
663 }
664
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;
670 return;
671 }
672
673 std::ostringstream oos;
674 oos << "G4Worker" << workerContext->GetThreadId() << "_"
675 << "currentEvent.rndm"
676 << "\0";
677 G4fs::path fileIn = randomNumberStatusDir + oos.str();
678
679 std::ostringstream os;
680 os << "run" << currentRun->GetRunID() << "evt" << currentEvent->GetEventID() << ".rndm" << '\0';
681 G4fs::path fileOut = randomNumberStatusDir + os.str();
682
683 if (G4CopyRandomState(fileIn, fileOut, "G4WorkerRunManager::rndmSaveThisEvent()")
684 && verboseLevel > 0)
685 {
686 G4cout << fileIn << " is copied to " << fileOut << G4endl;
687 }
688}
G4bool G4CopyRandomState(const G4fs::path &source, const G4fs::path &dest, const G4String &callsite)
G4GLOB_DLL std::ostream G4cerr
G4String randomNumberStatusDir
G4int GetThreadId() const

◆ rndmSaveThisRun()

void G4WorkerRunManager::rndmSaveThisRun ( )
overrideprotectedvirtual

Reimplemented from G4RunManager.

Definition at line 627 of file G4WorkerRunManager.cc.

628{
629 G4int runNumber = 0;
630 if (currentRun != nullptr) runNumber = currentRun->GetRunID();
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;
636 return;
637 }
638
639 std::ostringstream oos;
640 oos << "G4Worker" << workerContext->GetThreadId() << "_"
641 << "currentRun.rndm"
642 << "\0";
643 G4fs::path fileIn = randomNumberStatusDir + oos.str();
644
645 std::ostringstream os;
646 os << "run" << runNumber << ".rndm" << '\0';
647 G4fs::path fileOut = randomNumberStatusDir + os.str();
648
649 if (G4CopyRandomState(fileIn, fileOut, "G4WorkerRunManager::rndmSaveThisRun()")
650 && verboseLevel > 0)
651 {
652 G4cout << fileIn << " is copied to " << fileOut << G4endl;
653 }
654}

◆ RunInitialization()

void G4WorkerRunManager::RunInitialization ( )
overridevirtual

Reimplemented from G4RunManager.

Reimplemented in G4WorkerTaskRunManager.

Definition at line 158 of file G4WorkerRunManager.cc.

159{
160#ifdef G4MULTITHREADED
161 if (!visIsSetUp) {
163 if (pVVis != nullptr) {
164 pVVis->SetUpForAThread();
165 visIsSetUp = true;
166 }
167 }
168#endif
169
170 if (!(kernel->RunInitialization(fakeRun))) return;
171
172 // Signal this thread can start event loop.
173 // Note this will return only when all threads reach this point
175 if (fakeRun) return;
176
177 const G4UserWorkerInitialization* uwi =
180 delete currentRun;
181 currentRun = nullptr;
182
184 // Call a user hook: this is guaranteed all threads are "synchronized"
185 if (uwi != nullptr) uwi->WorkerRunStart();
186
188 if (currentRun == nullptr) currentRun = new G4Run();
189
192
195 if (fSDM != nullptr) {
197 }
198
199 if (G4VScoreNtupleWriter::Instance() != nullptr) {
200 auto hce = (fSDM != nullptr) ? fSDM->PrepareNewEvent() : nullptr;
202 delete hce;
203 }
204
205 std::ostringstream oss;
206 G4Random::saveFullState(oss);
209
210 for (G4int i_prev = 0; i_prev < n_perviousEventsToBeStored; ++i_prev) {
211 previousEvents->push_back(nullptr);
212 }
213
214 if (printModulo > 0 || verboseLevel > 0) {
215 G4cout << "### Run " << currentRun->GetRunID() << " starts on worker thread "
216 << G4Threading::G4GetThreadId() << "." << G4endl;
217 }
219
220#if defined(GEANT4_USE_TIMEMORY)
221 workerRunProfiler.reset(new ProfilerConfig(currentRun));
222#endif
223
226 }
227
229 G4String fileN = "currentRun";
231 std::ostringstream os;
232 os << "run" << currentRun->GetRunID();
233 fileN = os.str();
234 }
235 StoreRNGStatus(fileN);
236 }
237
238 runAborted = false;
240}
virtual void ThisWorkerReady()
static G4ParallelWorldProcessStore * GetInstance()
G4bool RunInitialization(G4bool fakeRun=false)
G4bool isScoreNtupleWriter
const G4UserWorkerInitialization * GetUserWorkerInitialization() const
std::list< G4Event * > * previousEvents
G4int numberOfEventProcessed
G4DCtable * DCtable
G4String randomNumberStatusForThisRun
G4UserRunAction * userRunAction
G4int numberOfEventToBeProcessed
G4int n_perviousEventsToBeStored
Definition G4Run.hh:49
void SetHCtable(G4HCtable *HCtbl)
Definition G4Run.hh:108
void SetNumberOfEventToBeProcessed(G4int n_ev)
Definition G4Run.hh:107
void SetRunID(G4int id)
Definition G4Run.hh:106
void SetDCtable(G4DCtable *DCtbl)
Definition G4Run.hh:109
void SetRandomNumberStatus(G4String &st)
Definition G4Run.hh:110
G4HCofThisEvent * PrepareNewEvent()
static G4SDManager * GetSDMpointerIfExist()
G4HCtable * GetHCtable() const
virtual G4Run * GenerateRun()
virtual void BeginOfRunAction(const G4Run *)
virtual G4bool Book(G4HCofThisEvent *hce)=0
static G4VScoreNtupleWriter * Instance()
virtual void OpenFile()=0
G4ProfilerConfig< G4ProfileType::Run > ProfilerConfig
G4int G4GetThreadId()

◆ RunTermination()

void G4WorkerRunManager::RunTermination ( )
overridevirtual

Reimplemented from G4RunManager.

Reimplemented in G4WorkerTaskRunManager.

Definition at line 421 of file G4WorkerRunManager.cc.

422{
423 if (!fakeRun) {
424#if defined(GEANT4_USE_TIMEMORY)
425 workerRunProfiler.reset();
426#endif
428
429 // Call a user hook: note this is before the next barrier
430 // so threads execute this method asyncrhonouzly
431 //(TerminateRun allows for synch via G4RunAction::EndOfRun)
432 const G4UserWorkerInitialization* uwi =
434 if (uwi != nullptr) uwi->WorkerRunEnd();
435 }
436
438 // Signal this thread has finished envent-loop.
439 // Note this will return only whan all threads reach this point
441}
virtual void ThisWorkerEndEventLoop()
virtual void RunTermination()
virtual void MergePartialResults()

◆ SetUserAction() [1/6]

void G4WorkerRunManager::SetUserAction ( G4UserEventAction * userAction)
overridevirtual

Reimplemented from G4RunManager.

Definition at line 589 of file G4WorkerRunManager.cc.

590{
592}
virtual void SetUserAction(G4UserRunAction *userAction)

◆ SetUserAction() [2/6]

void G4WorkerRunManager::SetUserAction ( G4UserRunAction * userAction)
overridevirtual

Reimplemented from G4RunManager.

Definition at line 570 of file G4WorkerRunManager.cc.

571{
572 G4RunManager::SetUserAction(userAction);
573 if (userAction != nullptr) userAction->SetMaster(false);
574}
virtual void SetMaster(G4bool val=true)

Referenced by G4RTWorkerInitialization::WorkerRunEnd(), and G4RTWorkerInitialization::WorkerRunStart().

◆ SetUserAction() [3/6]

void G4WorkerRunManager::SetUserAction ( G4UserStackingAction * userAction)
overridevirtual

Reimplemented from G4RunManager.

Definition at line 601 of file G4WorkerRunManager.cc.

602{
604}

◆ SetUserAction() [4/6]

void G4WorkerRunManager::SetUserAction ( G4UserSteppingAction * userAction)
overridevirtual

Reimplemented from G4RunManager.

Definition at line 613 of file G4WorkerRunManager.cc.

614{
616}

◆ SetUserAction() [5/6]

void G4WorkerRunManager::SetUserAction ( G4UserTrackingAction * userAction)
overridevirtual

Reimplemented from G4RunManager.

Definition at line 607 of file G4WorkerRunManager.cc.

608{
610}

◆ SetUserAction() [6/6]

void G4WorkerRunManager::SetUserAction ( G4VUserPrimaryGeneratorAction * userAction)
overridevirtual

Reimplemented from G4RunManager.

Definition at line 595 of file G4WorkerRunManager.cc.

596{
598}

◆ SetUserInitialization() [1/5]

void G4WorkerRunManager::SetUserInitialization ( G4UserWorkerInitialization * userInit)
overridevirtual

Reimplemented from G4RunManager.

Definition at line 535 of file G4WorkerRunManager.cc.

536{
537 G4Exception("G4RunManager::SetUserInitialization(G4UserWorkerInitialization*)", "Run0118",
538 FatalException, "This method should be used only with an instance of G4MTRunManager");
539}

◆ SetUserInitialization() [2/5]

void G4WorkerRunManager::SetUserInitialization ( G4UserWorkerThreadInitialization * userInit)
overridevirtual

Reimplemented from G4RunManager.

Definition at line 542 of file G4WorkerRunManager.cc.

543{
544 G4Exception("G4RunManager::SetUserInitialization(G4UserWorkerThreadInitialization*)", "Run0119",
545 FatalException, "This method should be used only with an instance of G4MTRunManager");
546}

◆ SetUserInitialization() [3/5]

void G4WorkerRunManager::SetUserInitialization ( G4VUserActionInitialization * userInit)
overridevirtual

Reimplemented from G4RunManager.

Definition at line 549 of file G4WorkerRunManager.cc.

550{
551 G4Exception("G4RunManager::SetUserInitialization(G4VUserActionInitialization*)", "Run0120",
552 FatalException, "This method should be used only with an instance of G4MTRunManager");
553}

◆ SetUserInitialization() [4/5]

void G4WorkerRunManager::SetUserInitialization ( G4VUserDetectorConstruction * userInit)
overridevirtual

Reimplemented from G4RunManager.

Definition at line 556 of file G4WorkerRunManager.cc.

557{
558 G4Exception("G4RunManager::SetUserInitialization(G4VUserDetectorConstruction*)", "Run0121",
559 FatalException, "This method should be used only with an instance of G4MTRunManager");
560}

◆ SetUserInitialization() [5/5]

void G4WorkerRunManager::SetUserInitialization ( G4VUserPhysicsList * userInit)
overridevirtual

Reimplemented from G4RunManager.

Definition at line 563 of file G4WorkerRunManager.cc.

564{
565 pl->InitializeWorker();
567}
virtual void SetUserInitialization(G4VUserDetectorConstruction *userInit)

Referenced by G4MTRunManagerKernel::StartThread().

◆ SetWorkerThread()

void G4WorkerRunManager::SetWorkerThread ( G4WorkerThread * wc)
inline

Definition at line 74 of file G4WorkerRunManager.hh.

74{ workerContext = wc; }

Referenced by G4MTRunManagerKernel::StartThread().

◆ StoreRNGStatus()

void G4WorkerRunManager::StoreRNGStatus ( const G4String & filenamePrefix)
overrideprotectedvirtual

Reimplemented from G4RunManager.

Reimplemented in G4WorkerTaskRunManager.

Definition at line 619 of file G4WorkerRunManager.cc.

620{
621 std::ostringstream os;
622 os << randomNumberStatusDir << "G4Worker" << workerContext->GetThreadId() << "_" << fn << ".rndm";
623 G4Random::saveEngineStatus(os.str().c_str());
624}

Referenced by GenerateEvent(), and RunInitialization().

◆ TerminateEventLoop()

void G4WorkerRunManager::TerminateEventLoop ( )
overridevirtual

Reimplemented from G4RunManager.

Reimplemented in G4WorkerTaskRunManager.

Definition at line 444 of file G4WorkerRunManager.cc.

445{
446 if (verboseLevel > 0 && !fakeRun) {
447 timer->Stop();
448 G4cout << "Thread-local run terminated." << G4endl;
449 G4cout << "Run Summary" << G4endl;
450 if (runAborted) {
451 G4cout << " Run Aborted after " << numberOfEventProcessed << " events processed." << G4endl;
452 }
453 else {
454 G4cout << " Number of events processed : " << numberOfEventProcessed << G4endl;
455 }
456 G4cout << " " << *timer << G4endl;
457 }
458}
G4Timer * timer
void Stop()

Referenced by DoEventLoop().

Member Data Documentation

◆ currEvID

G4int G4WorkerRunManager::currEvID = -1
protected

◆ eventLoopOnGoing

◆ luxury

G4int G4WorkerRunManager::luxury = -1
protected

Definition at line 110 of file G4WorkerRunManager.hh.

Referenced by G4WorkerRunManager(), and GenerateEvent().

◆ nevModulo

G4int G4WorkerRunManager::nevModulo = -1
protected

◆ readStatusFromFile

G4bool G4WorkerRunManager::readStatusFromFile = false
protected

◆ runIsSeeded

G4bool G4WorkerRunManager::runIsSeeded = false
protected

◆ seedsQueue

G4SeedsQueue G4WorkerRunManager::seedsQueue
protected

◆ workerContext


The documentation for this class was generated from the following files: