Geant4 10.7.0
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 ()
 
virtual void InitializeGeometry ()
 
virtual void RunInitialization ()
 
virtual void DoEventLoop (G4int n_event, const char *macroFile=0, G4int n_select=-1)
 
virtual void ProcessOneEvent (G4int i_event)
 
virtual G4EventGenerateEvent (G4int i_event)
 
virtual void RunTermination ()
 
virtual void TerminateEventLoop ()
 
virtual void DoWork ()
 
void SetWorkerThread (G4WorkerThread *wc)
 Sets the worker context.
 
virtual void SetUserInitialization (G4VUserPhysicsList *userInit)
 
virtual void SetUserInitialization (G4VUserDetectorConstruction *userInit)
 
virtual void SetUserInitialization (G4VUserActionInitialization *userInit)
 
virtual void SetUserInitialization (G4UserWorkerInitialization *userInit)
 
virtual void SetUserInitialization (G4UserWorkerThreadInitialization *userInit)
 
virtual void SetUserAction (G4UserRunAction *userAction)
 
virtual void SetUserAction (G4VUserPrimaryGeneratorAction *userAction)
 
virtual void SetUserAction (G4UserEventAction *userAction)
 
virtual void SetUserAction (G4UserStackingAction *userAction)
 
virtual void SetUserAction (G4UserTrackingAction *userAction)
 
virtual void SetUserAction (G4UserSteppingAction *userAction)
 
virtual void RestoreRndmEachEvent (G4bool flag)
 
- Public Member Functions inherited from G4RunManager
 G4RunManager ()
 
virtual ~G4RunManager ()
 
virtual void BeamOn (G4int n_event, const char *macroFile=0, 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 InitializeGeometry ()
 
virtual void InitializePhysics ()
 
virtual G4bool ConfirmBeamOnCondition ()
 
virtual void RunInitialization ()
 
virtual void DoEventLoop (G4int n_event, const char *macroFile=0, G4int n_select=-1)
 
virtual void RunTermination ()
 
virtual void InitializeEventLoop (G4int n_event, const char *macroFile=0, G4int n_select=-1)
 
virtual void ProcessOneEvent (G4int i_event)
 
virtual void TerminateOneEvent ()
 
virtual void TerminateEventLoop ()
 
virtual G4EventGenerateEvent (G4int i_event)
 
virtual void AnalyzeEvent (G4Event *anEvent)
 
virtual void ConfigureProfilers (const std::vector< std::string > &args={})
 
void ConfigureProfilers (int argc, char **argv)
 
virtual void SetNumberOfThreads (G4int)
 
virtual G4int GetNumberOfThreads () const
 
void DumpRegion (const G4String &rname) const
 
void DumpRegion (G4Region *region=0) const
 
virtual void rndmSaveThisRun ()
 
virtual void rndmSaveThisEvent ()
 
virtual void RestoreRandomNumberStatus (const G4String &fileN)
 
virtual void SetUserInitialization (G4VUserDetectorConstruction *userInit)
 
virtual void SetUserInitialization (G4VUserPhysicsList *userInit)
 
virtual void SetUserInitialization (G4VUserActionInitialization *userInit)
 
virtual void SetUserInitialization (G4UserWorkerInitialization *userInit)
 
virtual void SetUserInitialization (G4UserWorkerThreadInitialization *userInit)
 
virtual void SetUserAction (G4UserRunAction *userAction)
 
virtual void SetUserAction (G4VUserPrimaryGeneratorAction *userAction)
 
virtual void SetUserAction (G4UserEventAction *userAction)
 
virtual void SetUserAction (G4UserStackingAction *userAction)
 
virtual void SetUserAction (G4UserTrackingAction *userAction)
 
virtual void SetUserAction (G4UserSteppingAction *userAction)
 
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 GeometryHasBeenModified (G4bool prop=true)
 
void ReinitializeGeometry (G4bool destroyFirst=false, G4bool prop=true)
 
void PhysicsHasBeenModified ()
 
void CutOffHasBeenModified ()
 
void ReOptimizeMotherOf (G4VPhysicalVolume *)
 
void ReOptimize (G4LogicalVolume *)
 
void SetVerboseLevel (G4int vl)
 
G4int GetVerboseLevel () const
 
G4int GetPrintProgress ()
 
void SetPrintProgress (G4int i)
 
void SetGeometryToBeOptimized (G4bool vl)
 
G4bool GetGeometryToBeOptimized ()
 
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
 
G4String GetSelectMacro () const
 
void SetDCtable (G4DCtable *DCtbl)
 
RMType GetRunManagerType () const
 
virtual void ConstructScoringWorlds ()
 
virtual void RestoreRndmEachEvent (G4bool)
 
void GeometryDirectlyUpdated (G4bool val=true)
 

Static Public Member Functions

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

Protected Member Functions

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

Protected Attributes

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

Additional Inherited Members

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

Detailed Description

Definition at line 47 of file G4WorkerRunManager.hh.

Member Typedef Documentation

◆ ProfilerConfig

Constructor & Destructor Documentation

◆ G4WorkerRunManager()

G4WorkerRunManager::G4WorkerRunManager ( )

Definition at line 64 of file G4WorkerRunManager.cc.

66{
67 // This constructor should never be called in non-multithreaded mode
68
69#ifndef G4MULTITHREADED
71 msg << "Geant4 code is compiled without multi-threading support "
72 "(-DG4MULTITHREADED "
73 "is set to off).";
74 msg << " This type of RunManager can only be used in mult-threaded "
75 "applications.";
76 G4Exception("G4WorkerRunManager::G4WorkerRunManager()", "Run0103",
77 FatalException, msg);
78#endif
81 if(masterScM)
82 G4ScoringManager::GetScoringManager(); // TLS instance for a worker
83
84 eventLoopOnGoing = false;
85 runIsSeeded = false;
86 nevModulo = -1;
87 currEvID = -1;
88 workerContext = 0;
89 readStatusFromFile = false;
90
91 // Properly initialise luxury level for Ranlux* engines...
92 //
93 if(dynamic_cast<const CLHEP::Ranlux64Engine*>(G4Random::getTheEngine()))
94 {
96 dynamic_cast<const CLHEP::Ranlux64Engine*>(G4Random::getTheEngine());
97 luxury = theEngine->getLuxury();
98 }
99 else if(dynamic_cast<const CLHEP::RanluxEngine*>(G4Random::getTheEngine()))
100 {
102 dynamic_cast<const CLHEP::RanluxEngine*>(G4Random::getTheEngine());
103 luxury = theEngine->getLuxury();
104 }
105 else
106 {
107 luxury = -1;
108 }
109
111
112#ifdef G4MULTITHREADED
114 if(pVVis)
115 {
116 pVVis->SetUpForAThread();
117 visIsSetUp = true;
118 }
119 else
120 {
121 visIsSetUp = false;
122 }
123#endif
124}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
std::shared_ptr< HepRandomEngine > theEngine
Definition: Random.cc:76
static G4ScoringManager * GetMasterScoringManager()
static G4ParticleTable * GetParticleTable()
void WorkerG4ParticleTable()
static G4ScoringManager * GetScoringManager()
void SetIgnoreCmdNotFound(G4bool val)
Definition: G4UImanager.hh:222
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:77
static G4VVisManager * GetConcreteInstance()
G4WorkerThread * workerContext

◆ ~G4WorkerRunManager()

G4WorkerRunManager::~G4WorkerRunManager ( )

Definition at line 128 of file G4WorkerRunManager.cc.

129{
130 // Delete thread-local data process manager objects
132 // physicsList->RemoveProcessManager();
133
134 // Put these pointers to zero: owned by master thread
135 // If not to zero, the base class destructor will attempt to
136 // delete them
137 userDetector = 0;
141 physicsList = 0;
142 if(verboseLevel > 0)
143 G4cout << "Destroying WorkerRunManager (" << this << ")" << G4endl;
144}
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
G4UserWorkerInitialization * userWorkerInitialization
G4UserWorkerThreadInitialization * userWorkerThreadInitialization
G4int verboseLevel
G4VUserActionInitialization * userActionInitialization
G4VUserDetectorConstruction * userDetector
G4VUserPhysicsList * physicsList
virtual void TerminateWorker()

Member Function Documentation

◆ ConstructScoringWorlds()

void G4WorkerRunManager::ConstructScoringWorlds ( )
protectedvirtual

Reimplemented from G4RunManager.

Definition at line 551 of file G4WorkerRunManager.cc.

552{
553 using MeshShape = G4VScoringMesh::MeshShape;
554
555 // Return if unnecessary
557 if(!ScM)
558 return;
559 G4int nPar = ScM->GetNumberOfMesh();
560 if(nPar < 1)
561 return;
562
563 // Update thread-local G4TransportationManager of all the world volumes
565
567 assert(masterScM != NULL);
568
571
572 for(G4int iw = 0; iw < nPar; iw++)
573 {
574 G4VScoringMesh* mesh = ScM->GetMesh(iw);
577 G4VPhysicalVolume* pWorld = nullptr;
578 if(mesh->GetShape() != MeshShape::realWorldLogVol)
579 {
580 pWorld =
582 ScM->GetWorldName(iw));
583 if(!pWorld)
584 {
586 ed << "Mesh name <" << ScM->GetWorldName(iw)
587 << "> is not found in the master thread.";
588 G4Exception("G4WorkerRunManager::ConstructScoringWorlds()", "RUN79001",
589 FatalException, ed);
590 }
591 }
592 if(!(mesh->GetMeshElementLogical()))
593 {
594 G4AutoLock l(&ConstructScoringWorldsMutex);
595 G4VScoringMesh* masterMesh = masterScM->GetMesh(iw);
596 mesh->SetMeshElementLogical(masterMesh->GetMeshElementLogical());
597 l.unlock();
598
599 if(mesh->GetShape() != MeshShape::realWorldLogVol)
600 {
601 G4ParallelWorldProcess* theParallelWorldProcess =
603 if(theParallelWorldProcess)
604 {
605 theParallelWorldProcess->SetParallelWorld(ScM->GetWorldName(iw));
606 }
607 else
608 {
609 theParallelWorldProcess =
611 mesh->SetParallelWorldProcess(theParallelWorldProcess);
612 theParallelWorldProcess->SetParallelWorld(ScM->GetWorldName(iw));
613
614 particleIterator->reset();
615 while((*particleIterator)())
616 {
617 G4ParticleDefinition* particle = particleIterator->value();
618 G4ProcessManager* pmanager = particle->GetProcessManager();
619 if(pmanager)
620 {
621 pmanager->AddProcess(theParallelWorldProcess);
622 if(theParallelWorldProcess->IsAtRestRequired(particle))
623 {
624 pmanager->SetProcessOrdering(theParallelWorldProcess, idxAtRest,
625 9900);
626 }
627 pmanager->SetProcessOrderingToSecond(theParallelWorldProcess,
629 pmanager->SetProcessOrdering(theParallelWorldProcess, idxPostStep,
630 9900);
631 } // if(pmanager)
632 } // while
633 }
634 theParallelWorldProcess->SetLayeredMaterialFlag(mesh->LayeredMassFlg());
635 }
636 }
637 mesh->WorkerConstruct(pWorld);
638 }
639}
std::vector< G4InuclElementaryParticle >::iterator particleIterator
Definition: G4BigBanger.cc:64
@ 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
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
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 = 0,
G4int  n_select = -1 
)
virtual

Reimplemented from G4RunManager.

Reimplemented in G4WorkerTaskRunManager.

Definition at line 277 of file G4WorkerRunManager.cc.

279{
281 {
282 G4Exception("G4RunManager::GenerateEvent()", "Run0032", FatalException,
283 "G4VUserPrimaryGeneratorAction is not defined!");
284 }
285
286 // This is the same as in the sequential case, just the for-loop indexes are
287 // different
288 InitializeEventLoop(n_event, macroFile, n_select);
289
290 // Reset random number seeds queue
291 while(seedsQueue.size() > 0)
292 {
293 seedsQueue.pop();
294 }
295 // for each run, worker should receive at least one set of random number
296 // seeds.
297 runIsSeeded = false;
298
299 // Event loop
300 eventLoopOnGoing = true;
301 /////// G4int i_event = workerContext->GetThreadId();
302 G4int i_event = -1;
303 nevModulo = -1;
304 currEvID = -1;
305
306 while(eventLoopOnGoing)
307 {
308 ProcessOneEvent(i_event);
310 {
312 if(runAborted)
313 {
314 eventLoopOnGoing = false;
315 }
316 ////// else
317 ////// {
318 ////// i_event += workerContext->GetNumberThreads();
319 ////// eventLoopOnGoing = i_event<n_event;
320 ////// }
321 }
322 }
323
325}
G4bool runAborted
G4VUserPrimaryGeneratorAction * userPrimaryGeneratorAction
virtual void TerminateOneEvent()
virtual void InitializeEventLoop(G4int n_event, const char *macroFile=0, G4int n_select=-1)
virtual void ProcessOneEvent(G4int i_event)
virtual void TerminateEventLoop()

◆ DoWork()

void G4WorkerRunManager::DoWork ( )
virtual

Reimplemented in G4WorkerTaskRunManager.

Definition at line 804 of file G4WorkerRunManager.cc.

805{
810 {
811 if(nextAction ==
813 // run
814 {
815 // The following code deals with changing materials between runs
816 static G4ThreadLocal G4bool skipInitialization = true;
817 if(skipInitialization)
818 {
819 // re-initialization is not necessary for the first run
820 skipInitialization = false;
821 }
822 else
823 {
824 // ReinitializeGeometry();
826 }
827
828 // Execute UI commands stored in the master UI manager
829 std::vector<G4String> cmds = mrm->GetCommandStack();
830 G4UImanager* uimgr = G4UImanager::GetUIpointer(); // TLS instance
831 std::vector<G4String>::const_iterator it = cmds.begin();
832 for(; it != cmds.end(); it++)
833 {
834 uimgr->ApplyCommand(*it);
835 }
836 // Start this run
837 G4int numevents = mrm->GetNumberOfEventsToBeProcessed();
838 G4String macroFile = mrm->GetSelectMacro();
839 G4int numSelect = mrm->GetNumberOfSelectEvents();
840 if(macroFile == "" || macroFile == " ")
841 {
842 this->BeamOn(numevents);
843 }
844 else
845 {
846 this->BeamOn(numevents, macroFile, numSelect);
847 }
848 }
850 {
851 std::vector<G4String> cmds = mrm->GetCommandStack();
852 G4UImanager* uimgr = G4UImanager::GetUIpointer(); // TLS instance
853 std::vector<G4String>::const_iterator it = cmds.begin();
854 for(; it != cmds.end(); it++)
855 {
856 uimgr->ApplyCommand(*it);
857 }
859 }
860 else
861 {
863 d << "Cannot continue, this worker has been requested an unknown action: "
864 << static_cast<
865 std::underlying_type<G4MTRunManager::WorkerActionRequest>::type>(
866 nextAction);
867 G4Exception("G4WorkerRunManager::DoWork", "Run0104", FatalException, d);
868 }
869
870 // Now wait for master thread to signal new action to be performed
871 nextAction = mrm->ThisWorkerWaitForNextAction();
872 } // No more actions to perform
873
874 return;
875}
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=0, G4int n_select=-1)
G4String GetSelectMacro() const
G4int GetNumberOfSelectEvents() const
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:485
static void UpdateGeometryAndPhysicsVectorFromMaster()
#define G4ThreadLocal
Definition: tls.hh:77

Referenced by G4MTRunManagerKernel::StartThread().

◆ GenerateEvent()

G4Event * G4WorkerRunManager::GenerateEvent ( G4int  i_event)
virtual

virtual void BuildPhysicsTables();

G4cout<<"Event "<<currEvID<<" is seeded with { "<<s1<<", "<<s2<<" }"<<G4endl;

Reimplemented from G4RunManager.

Reimplemented in G4WorkerTaskRunManager.

Definition at line 340 of file G4WorkerRunManager.cc.

341{
342 G4Event* anEvent = new G4Event(i_event);
343 long s1 = 0;
344 long s2 = 0;
345 long s3 = 0;
346 G4bool eventHasToBeSeeded = true;
348 {
349 eventHasToBeSeeded = false;
350 }
351
352 if(i_event < 0)
353 {
355 if(nevM == 1)
356 {
358 anEvent, s1, s2, s3, eventHasToBeSeeded);
359 runIsSeeded = true;
360 }
361 else
362 {
363 if(nevModulo <= 0)
364 {
366 anEvent, &seedsQueue, eventHasToBeSeeded);
367 if(nevToDo == 0)
368 {
369 eventLoopOnGoing = false;
370 }
371 else
372 {
373 currEvID = anEvent->GetEventID();
374 nevModulo = nevToDo - 1;
375 }
376 }
377 else
378 {
380 eventHasToBeSeeded = false;
381 anEvent->SetEventID(++currEvID);
382 nevModulo--;
383 }
384 if(eventLoopOnGoing && eventHasToBeSeeded)
385 {
386 s1 = seedsQueue.front();
387 seedsQueue.pop();
388 s2 = seedsQueue.front();
389 seedsQueue.pop();
390 }
391 }
392
394 {
395 delete anEvent;
396 return 0;
397 }
398 }
399 else if(eventHasToBeSeeded)
400 {
401 // Need to reseed random number generator
403 s1 = helper->GetSeed(i_event * 2);
404 s2 = helper->GetSeed(i_event * 2 + 1);
405 }
406
407 if(eventHasToBeSeeded)
408 {
409 long seeds[3] = { s1, s2, 0 };
410 G4Random::setTheSeeds(seeds, luxury);
411 runIsSeeded = true;
412 ////G4cout<<"Event "<<currEvID<<" is seeded with { "<<s1<<", "<<s2<<"
413 ///}"<<G4endl;
414 }
415
416 // Read from file seed.
417 // Andrea Dotti 4 November 2015
418 // This is required for strong-reproducibility, in MT mode we have that each
419 // thread produces, for each event a status file, we want to do that.
420 // Search a random file with the format run{%d}evt{%d}.rndm
421
422 // This is the filename base constructed from run and event
423 const auto filename = [&] {
424 std::ostringstream os;
425 os << "run" << currentRun->GetRunID() << "evt" << anEvent->GetEventID();
426 return os.str();
427 };
428
429 G4bool RNGstatusReadFromFile = false;
431 {
432 // Build full path of RNG status file for this event
433 std::ostringstream os;
434 os << filename() << ".rndm";
435 const G4String& randomStatusFile = os.str();
436 std::ifstream ifile(randomStatusFile.c_str());
437 if(ifile)
438 { // File valid and readable
439 RNGstatusReadFromFile = true;
440 G4Random::restoreEngineStatus(randomStatusFile.c_str());
441 }
442 }
443
446 {
447 std::ostringstream oss;
448 G4Random::saveFullState(oss);
451 }
452
453 if(storeRandomNumberStatus && !RNGstatusReadFromFile)
454 { // If reading from file, avoid to rewrite the same
455 G4String fileN = "currentEvent";
457 {
458 fileN = filename();
459 }
460 StoreRNGStatus(fileN);
461 }
462
463 if(printModulo > 0 && anEvent->GetEventID() % printModulo == 0)
464 {
465 G4cout << "--> Event " << anEvent->GetEventID() << " starts";
466 if(eventHasToBeSeeded)
467 {
468 G4cout << " with initial seeds (" << s1 << "," << s2 << ")";
469 }
470 G4cout << "." << G4endl;
471 }
473 return anEvent;
474}
void SetRandomNumberStatus(G4String &st)
Definition: G4Event.hh:90
G4int GetEventID() const
Definition: G4Event.hh:118
void SetEventID(G4int i)
Definition: G4Event.hh:80
static G4int SeedOncePerCommunication()
virtual G4int SetUpNEvents(G4Event *, G4SeedsQueue *seedsQueue, G4bool reseedRequired=true)
virtual G4bool SetUpAnEvent(G4Event *, long &s1, long &s2, long &s3, G4bool reseedRequired=true)
G4int GetEventModulo() const
G4int storeRandomNumberStatusToG4Event
G4Run * currentRun
G4bool rngStatusEventsFlag
G4String randomNumberStatusForThisEvent
G4bool storeRandomNumberStatus
G4int GetRunID() const
Definition: G4Run.hh:82
static G4TemplateRNGHelper< T > * GetInstance()
Definition: G4RNGHelper.cc:37
virtual const T GetSeed(const G4int &sdId)
Definition: G4RNGHelper.hh:58
virtual void GeneratePrimaries(G4Event *anEvent)=0
virtual void StoreRNGStatus(const G4String &filenamePrefix)

Referenced by ProcessOneEvent().

◆ GetWorkerRunManager()

G4WorkerRunManager * G4WorkerRunManager::GetWorkerRunManager ( )
static

◆ GetWorkerRunManagerKernel()

G4WorkerRunManagerKernel * G4WorkerRunManager::GetWorkerRunManagerKernel ( )
static

Definition at line 59 of file G4WorkerRunManager.cc.

60{
62}
static G4WorkerRunManager * GetWorkerRunManager()

◆ InitializeGeometry()

void G4WorkerRunManager::InitializeGeometry ( )
virtual

virtual void BeamOn(G4int n_event,const char* macroFile=0,G4int n_select=-1);

Reimplemented from G4RunManager.

Definition at line 146 of file G4WorkerRunManager.cc.

147{
148 if(!userDetector)
149 {
150 G4Exception("G4RunManager::InitializeGeometry", "Run0033", FatalException,
151 "G4VUserDetectorConstruction is not defined!");
152 return;
153 }
155 {
157 }
158
159 // Step1: Get pointer to the physiWorld (note: needs to get the "super
160 // pointer, i.e. the one shared by all threads"
161 G4RunManagerKernel* masterKernel =
163 G4VPhysicalVolume* worldVol = masterKernel->GetCurrentWorld();
164 // Step2:, Call a new "WorkerDefineWorldVolume( pointer from 2-, false);
165 kernel->WorkerDefineWorldVolume(worldVol, false);
167 // Step3: Call user's ConstructSDandField()
170 geometryInitialized = true;
171}
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 476 of file G4WorkerRunManager.cc.

477{
478 // Merge partial results into global run
481 if(ScM)
482 mtRM->MergeScores(ScM);
483 mtRM->MergeRun(currentRun);
484}
void MergeRun(const G4Run *localRun)
void MergeScores(const G4ScoringManager *localScoringManager)

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

◆ ProcessOneEvent()

void G4WorkerRunManager::ProcessOneEvent ( G4int  i_event)
virtual

Reimplemented from G4RunManager.

Reimplemented in G4WorkerTaskRunManager.

Definition at line 327 of file G4WorkerRunManager.cc.

328{
329 currentEvent = GenerateEvent(i_event);
331 {
337 }
338}
void ProcessOneEvent(G4Event *anEvent)
G4int n_select_msg
G4String msgText
G4EventManager * eventManager
virtual void AnalyzeEvent(G4Event *anEvent)
void UpdateScoring()
G4Event * currentEvent
virtual G4Event * GenerateEvent(G4int i_event)

Referenced by DoEventLoop().

◆ RestoreRndmEachEvent()

virtual void G4WorkerRunManager::RestoreRndmEachEvent ( G4bool  flag)
inlinevirtual

Reimplemented from G4RunManager.

Reimplemented in G4WorkerTaskRunManager.

Definition at line 127 of file G4WorkerRunManager.hh.

127{ readStatusFromFile = flag; }

◆ rndmSaveThisEvent()

void G4WorkerRunManager::rndmSaveThisEvent ( )
protectedvirtual

Reimplemented from G4RunManager.

Definition at line 763 of file G4WorkerRunManager.cc.

764{
765 if(currentEvent == 0)
766 {
767 G4cerr
768 << "Warning from G4RunManager::rndmSaveThisEvent():"
769 << " there is no currentEvent available."
770 << G4endl << "Command ignored." << G4endl;
771 return;
772 }
773
775 {
776 G4cerr
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;
781 return;
782 }
783
784 std::ostringstream oos;
785 oos << "G4Worker" << workerContext->GetThreadId()
786 << "_" << "currentEvent.rndm" << "\0";
787 G4String fileIn = randomNumberStatusDir + oos.str();
788
789 std::ostringstream os;
790 os << "run" << currentRun->GetRunID() << "evt" << currentEvent->GetEventID()
791 << ".rndm" << '\0';
792 G4String fileOut = randomNumberStatusDir + os.str();
793
794#ifdef WIN32
795 G4String copCmd = "/control/shell copy " + fileIn + " " + fileOut;
796#else
797 G4String copCmd = "/control/shell cp " + fileIn + " " + fileOut;
798#endif
800 if(verboseLevel > 0)
801 { G4cout << fileIn << " is copied to " << fileOut << G4endl; }
802}
G4GLOB_DLL std::ostream G4cerr
G4String randomNumberStatusDir
G4int GetThreadId() const

◆ rndmSaveThisRun()

void G4WorkerRunManager::rndmSaveThisRun ( )
protectedvirtual

Reimplemented from G4RunManager.

Definition at line 731 of file G4WorkerRunManager.cc.

732{
733 G4int runNumber = 0;
734 if(currentRun) runNumber = currentRun->GetRunID();
736 {
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;
741 return;
742 }
743
744 std::ostringstream oos;
745 oos << "G4Worker" << workerContext->GetThreadId()
746 << "_" << "currentRun.rndm" << "\0";
747 G4String fileIn = randomNumberStatusDir + oos.str();
748
749 std::ostringstream os;
750 os << "run" << runNumber << ".rndm" << '\0';
751 G4String fileOut = randomNumberStatusDir + os.str();
752
753#ifdef WIN32
754 G4String copCmd = "/control/shell copy " + fileIn + " " + fileOut;
755#else
756 G4String copCmd = "/control/shell cp " + fileIn + " " + fileOut;
757#endif
759 if(verboseLevel > 0)
760 { G4cout << fileIn << " is copied to " << fileOut << G4endl; }
761}

◆ RunInitialization()

void G4WorkerRunManager::RunInitialization ( )
virtual

Reimplemented from G4RunManager.

Reimplemented in G4WorkerTaskRunManager.

Definition at line 175 of file G4WorkerRunManager.cc.

176{
177#ifdef G4MULTITHREADED
178 if(!visIsSetUp)
179 {
181 if(pVVis)
182 {
183 pVVis->SetUpForAThread();
184 visIsSetUp = true;
185 }
186 }
187#endif
188
190 return;
191
192 // Signal this thread can start event loop.
193 // Note this will return only when all threads reach this point
195 if(fakeRun)
196 return;
197
198 const G4UserWorkerInitialization* uwi =
201 if(currentRun)
202 delete currentRun;
203 currentRun = 0;
204
207 // Call a user hook: this is guaranteed all threads are "synchronized"
208 if(uwi)
209 uwi->WorkerRunStart();
210
211 if(userRunAction)
213 if(!currentRun)
214 currentRun = new G4Run();
215
218
221 if(fSDM)
222 {
224 }
225
227 {
228 auto hce = fSDM->PrepareNewEvent();
230 delete hce;
231 }
232
233 std::ostringstream oss;
234 G4Random::saveFullState(oss);
237
238 for(G4int i_prev = 0; i_prev < n_perviousEventsToBeStored; i_prev++)
239 {
240 previousEvents->push_back((G4Event*) 0);
241 }
242
243 if(printModulo > 0 || verboseLevel > 0)
244 {
245 G4cout << "### Run " << currentRun->GetRunID()
246 << " starts on worker thread " << G4Threading::G4GetThreadId() << "."
247 << G4endl;
248 }
249 if(userRunAction)
251
252#if defined(GEANT4_USE_TIMEMORY)
253 workerRunProfiler.reset(new ProfilerConfig(currentRun));
254#endif
255
257 {
259 }
260
262 {
263 G4String fileN = "currentRun";
265 {
266 std::ostringstream os;
267 os << "run" << currentRun->GetRunID();
268 fileN = os.str();
269 }
270 StoreRNGStatus(fileN);
271 }
272
273 runAborted = false;
275}
virtual void ThisWorkerReady()
static G4ParallelWorldProcessStore * GetInstance()
G4bool RunInitialization(G4bool fakeRun=false)
G4bool isScoreNtupleWriter
void CleanUpPreviousEvents()
const G4UserWorkerInitialization * GetUserWorkerInitialization() const
std::list< G4Event * > * previousEvents
G4int numberOfEventProcessed
G4int runIDCounter
G4DCtable * DCtable
G4String randomNumberStatusForThisRun
G4UserRunAction * userRunAction
G4int numberOfEventToBeProcessed
G4int n_perviousEventsToBeStored
Definition: G4Run.hh:49
void SetHCtable(G4HCtable *HCtbl)
Definition: G4Run.hh:106
void SetNumberOfEventToBeProcessed(G4int n_ev)
Definition: G4Run.hh:102
void SetRunID(G4int id)
Definition: G4Run.hh:101
void SetDCtable(G4DCtable *DCtbl)
Definition: G4Run.hh:107
void SetRandomNumberStatus(G4String &st)
Definition: G4Run.hh:108
G4HCofThisEvent * PrepareNewEvent()
Definition: G4SDManager.cc:109
static G4SDManager * GetSDMpointerIfExist()
Definition: G4SDManager.cc:48
G4HCtable * GetHCtable() const
Definition: G4SDManager.hh:103
virtual void BeginOfRunAction(const G4Run *aRun)
virtual G4Run * GenerateRun()
virtual G4bool Book(G4HCofThisEvent *hce)=0
static G4VScoreNtupleWriter * Instance()
virtual void OpenFile()=0
G4ProfilerConfig< G4ProfileType::Run > ProfilerConfig
G4int G4GetThreadId()
Definition: G4Threading.cc:122

◆ RunTermination()

void G4WorkerRunManager::RunTermination ( )
virtual

Reimplemented from G4RunManager.

Reimplemented in G4WorkerTaskRunManager.

Definition at line 486 of file G4WorkerRunManager.cc.

487{
488 if(!fakeRun)
489 {
490#if defined(GEANT4_USE_TIMEMORY)
491 workerRunProfiler.reset();
492#endif
494
495 // Call a user hook: note this is before the next barrier
496 // so threads execute this method asyncrhonouzly
497 //(TerminateRun allows for synch via G4RunAction::EndOfRun)
498 const G4UserWorkerInitialization* uwi =
500 if(uwi)
501 uwi->WorkerRunEnd();
502 }
503
505 // Signal this thread has finished envent-loop.
506 // Note this will return only whan all threads reach this point
508}
virtual void ThisWorkerEndEventLoop()
virtual void RunTermination()
virtual void MergePartialResults()

◆ SetUserAction() [1/6]

void G4WorkerRunManager::SetUserAction ( G4UserEventAction userAction)
virtual

Reimplemented from G4RunManager.

Definition at line 698 of file G4WorkerRunManager.cc.

699{
701}
virtual void SetUserAction(G4UserRunAction *userAction)

◆ SetUserAction() [2/6]

void G4WorkerRunManager::SetUserAction ( G4UserRunAction userAction)
virtual

Reimplemented from G4RunManager.

Definition at line 680 of file G4WorkerRunManager.cc.

681{
682 G4RunManager::SetUserAction(userAction);
683 if(userAction)
684 userAction->SetMaster(false);
685}
virtual void SetMaster(G4bool val=true)

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

◆ SetUserAction() [3/6]

void G4WorkerRunManager::SetUserAction ( G4UserStackingAction userAction)
virtual

Reimplemented from G4RunManager.

Definition at line 708 of file G4WorkerRunManager.cc.

709{
711}

◆ SetUserAction() [4/6]

void G4WorkerRunManager::SetUserAction ( G4UserSteppingAction userAction)
virtual

Reimplemented from G4RunManager.

Definition at line 718 of file G4WorkerRunManager.cc.

719{
721}

◆ SetUserAction() [5/6]

void G4WorkerRunManager::SetUserAction ( G4UserTrackingAction userAction)
virtual

Reimplemented from G4RunManager.

Definition at line 713 of file G4WorkerRunManager.cc.

714{
716}

◆ SetUserAction() [6/6]

void G4WorkerRunManager::SetUserAction ( G4VUserPrimaryGeneratorAction userAction)
virtual

Reimplemented from G4RunManager.

Definition at line 703 of file G4WorkerRunManager.cc.

704{
706}

◆ SetUserInitialization() [1/5]

void G4WorkerRunManager::SetUserInitialization ( G4UserWorkerInitialization userInit)
virtual

Reimplemented from G4RunManager.

Definition at line 641 of file G4WorkerRunManager.cc.

642{
644 "G4RunManager::SetUserInitialization(G4UserWorkerInitialization*)",
645 "Run0118", FatalException,
646 "This method should be used only with an instance of G4MTRunManager");
647}

◆ SetUserInitialization() [2/5]

void G4WorkerRunManager::SetUserInitialization ( G4UserWorkerThreadInitialization userInit)
virtual

Reimplemented from G4RunManager.

Definition at line 649 of file G4WorkerRunManager.cc.

651{
653 "G4RunManager::SetUserInitialization(G4UserWorkerThreadInitialization*)",
654 "Run0119", FatalException,
655 "This method should be used only with an instance of G4MTRunManager");
656}

◆ SetUserInitialization() [3/5]

void G4WorkerRunManager::SetUserInitialization ( G4VUserActionInitialization userInit)
virtual

Reimplemented from G4RunManager.

Definition at line 658 of file G4WorkerRunManager.cc.

659{
661 "G4RunManager::SetUserInitialization(G4VUserActionInitialization*)",
662 "Run0120", FatalException,
663 "This method should be used only with an instance of G4MTRunManager");
664}

◆ SetUserInitialization() [4/5]

void G4WorkerRunManager::SetUserInitialization ( G4VUserDetectorConstruction userInit)
virtual

Reimplemented from G4RunManager.

Definition at line 666 of file G4WorkerRunManager.cc.

667{
669 "G4RunManager::SetUserInitialization(G4VUserDetectorConstruction*)",
670 "Run0121", FatalException,
671 "This method should be used only with an instance of G4MTRunManager");
672}

◆ SetUserInitialization() [5/5]

void G4WorkerRunManager::SetUserInitialization ( G4VUserPhysicsList userInit)
virtual

Reimplemented from G4RunManager.

Definition at line 674 of file G4WorkerRunManager.cc.

675{
676 pl->InitializeWorker();
678}
virtual void SetUserInitialization(G4VUserDetectorConstruction *userInit)

Referenced by G4MTRunManagerKernel::StartThread().

◆ SetWorkerThread()

void G4WorkerRunManager::SetWorkerThread ( G4WorkerThread wc)
inline

Sets the worker context.

Definition at line 89 of file G4WorkerRunManager.hh.

89{ workerContext = wc; }

Referenced by G4MTRunManagerKernel::StartThread().

◆ StoreRNGStatus()

void G4WorkerRunManager::StoreRNGStatus ( const G4String filenamePrefix)
protectedvirtual

Reimplemented from G4RunManager.

Reimplemented in G4WorkerTaskRunManager.

Definition at line 723 of file G4WorkerRunManager.cc.

724{
725 std::ostringstream os;
726 os << randomNumberStatusDir << "G4Worker" << workerContext->GetThreadId()
727 << "_" << fn << ".rndm";
728 G4Random::saveEngineStatus(os.str().c_str());
729}

Referenced by GenerateEvent(), and RunInitialization().

◆ TerminateEventLoop()

void G4WorkerRunManager::TerminateEventLoop ( )
virtual

Reimplemented from G4RunManager.

Reimplemented in G4WorkerTaskRunManager.

Definition at line 510 of file G4WorkerRunManager.cc.

511{
512 if(verboseLevel > 0 && !fakeRun)
513 {
514 timer->Stop();
515 G4cout << "Thread-local run terminated." << G4endl;
516 G4cout << "Run Summary" << G4endl;
517 if(runAborted)
518 {
519 G4cout << " Run Aborted after " << numberOfEventProcessed
520 << " events processed." << G4endl;
521 }
522 else
523 {
524 G4cout << " Number of events processed : " << numberOfEventProcessed
525 << G4endl;
526 }
527 G4cout << " " << *timer << G4endl;
528 }
529}
G4Timer * timer
void Stop()

Referenced by DoEventLoop().

Member Data Documentation

◆ currEvID

◆ eventLoopOnGoing

◆ luxury

G4int G4WorkerRunManager::luxury
protected

Definition at line 119 of file G4WorkerRunManager.hh.

Referenced by G4WorkerRunManager(), and GenerateEvent().

◆ nevModulo

◆ readStatusFromFile

◆ runIsSeeded

◆ seedsQueue

G4SeedsQueue G4WorkerRunManager::seedsQueue
protected

◆ workerContext


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