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

#include <G4WorkerTaskRunManager.hh>

+ Inheritance diagram for G4WorkerTaskRunManager:

Public Types

using G4StrVector = std::vector<G4String>
 
- Public Types inherited from G4RunManager
enum  RMType {
  sequentialRM , masterRM , workerRM , subEventMasterRM ,
  subEventWorkerRM
}
 

Public Member Functions

 G4WorkerTaskRunManager ()=default
 
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
 
void DoWork () override
 
void RestoreRndmEachEvent (G4bool flag) override
 
virtual void DoCleanup ()
 
virtual void ProcessUI ()
 
G4WorkerThreadGetWorkerThread () const
 
G4StrVector GetCommandStack () const
 
- Public Member Functions inherited from G4WorkerRunManager
 G4WorkerRunManager ()
 
 ~G4WorkerRunManager () override
 
void InitializeGeometry () override
 
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
 
- 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 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)
 
void SetDefaultClassification (G4TrackStatus ts, G4ClassificationOfNewTrack val, G4ExceptionSeverity es=G4ExceptionSeverity::IgnoreTheIssue)
 
void SetDefaultClassification (const G4ParticleDefinition *pd, G4ClassificationOfNewTrack val, G4ExceptionSeverity es=G4ExceptionSeverity::IgnoreTheIssue)
 
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
 
virtual void RegisterSubEventType (G4int, G4int)
 
virtual void MergeTrajectories (const G4SubEvent *, const G4Event *)
 
virtual void UpdateScoringForSubEvent (const G4SubEvent *, const G4Event *)
 
virtual const G4SubEventGetSubEvent (G4int, G4bool &, G4long &, G4long &, G4long &, G4bool)
 
virtual void SubEventFinished (const G4SubEvent *, const G4Event *)
 
virtual G4int GetSubEventType () const
 
virtual void SetSubEventType (G4int)
 
virtual std::size_t GetMaxNTrack () const
 
virtual void TrajectoriesToBeMerged (G4bool)
 
virtual void ReportEventDeletion (const G4Event *evt)
 
void ResetNavigatorAtInitialization (G4bool val=true)
 

Static Public Member Functions

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

Protected Member Functions

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

Protected Attributes

G4StrVector processedCommandStack
 
- Protected Attributes inherited from G4WorkerRunManager
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 G4WorkerTaskRunManager.hh.

Member Typedef Documentation

◆ G4StrVector

Definition at line 51 of file G4WorkerTaskRunManager.hh.

Constructor & Destructor Documentation

◆ G4WorkerTaskRunManager()

G4WorkerTaskRunManager::G4WorkerTaskRunManager ( )
default

Referenced by GetWorkerRunManager().

Member Function Documentation

◆ DoCleanup()

void G4WorkerTaskRunManager::DoCleanup ( )
virtual

Reimplemented in G4WorkerSubEvtRunManager.

Definition at line 418 of file G4WorkerTaskRunManager.cc.

419{
421
422 delete currentRun;
423 currentRun = nullptr;
424}
virtual void CleanUpPreviousEvents()
G4Run * currentRun

◆ DoEventLoop()

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

Reimplemented from G4WorkerRunManager.

Definition at line 163 of file G4WorkerTaskRunManager.cc.

164{
165 if (userPrimaryGeneratorAction == nullptr) {
166 G4Exception("G4RunManager::GenerateEvent()", "Run0032", FatalException,
167 "G4VUserPrimaryGeneratorAction is not defined!");
168 }
169
170 // This is the same as in the sequential case, just the for-loop indexes are
171 // different
172 InitializeEventLoop(n_event, macroFile, n_select);
173
174 // Reset random number seeds queue
175 while (!seedsQueue.empty())
176 seedsQueue.pop();
177 // for each run, worker should receive at least one set of random number
178 // seeds.
179 // runIsSeeded = false;
180
181 // Event loop
182 eventLoopOnGoing = true;
183 G4int i_event = -1;
184 nevModulo = -1;
185 currEvID = -1;
186
187 for (G4int evt = 0; evt < n_event; ++evt) {
188 ProcessOneEvent(i_event);
189 if (eventLoopOnGoing) {
191 if (runAborted) eventLoopOnGoing = false;
192 }
193 if (!eventLoopOnGoing) break;
194 }
195}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
int G4int
Definition G4Types.hh:85
virtual void InitializeEventLoop(G4int n_event, const char *macroFile=nullptr, G4int n_select=-1)
G4VUserPrimaryGeneratorAction * userPrimaryGeneratorAction
virtual void TerminateOneEvent()
void ProcessOneEvent(G4int i_event) override

Referenced by DoWork().

◆ DoWork()

void G4WorkerTaskRunManager::DoWork ( )
overridevirtual

Reimplemented from G4WorkerRunManager.

Definition at line 428 of file G4WorkerTaskRunManager.cc.

429{
430 G4TaskRunManager* mrm = G4TaskRunManager::GetMasterRunManager();
431 G4bool newRun = false;
432 const G4Run* run = mrm->GetCurrentRun();
433 G4ThreadLocalStatic G4int runId = -1;
434 if ((run != nullptr) && run->GetRunID() != runId) {
435 runId = run->GetRunID();
436 newRun = true;
437 if (runId > 0) {
438 ProcessUI();
439 assert(workerContext != nullptr);
440 }
441 workerContext->UpdateGeometryAndPhysicsVectorFromMaster();
442 }
443
444 // Start this run
445 G4int nevts = mrm->GetNumberOfEventsPerTask();
446 G4int numSelect = mrm->GetNumberOfSelectEvents();
447 G4String macroFile = mrm->GetSelectMacro();
448 G4bool empty_macro = (macroFile.empty() || macroFile == " ");
449
450 const char* macro = (empty_macro) ? nullptr : macroFile.c_str();
451 numSelect = (empty_macro) ? -1 : numSelect;
452
453 if (newRun) {
455 if (cond) {
458 }
459 }
460 DoEventLoop(nevts, macro, numSelect);
461}
bool G4bool
Definition G4Types.hh:86
virtual G4bool ConfirmBeamOnCondition()
const G4String & GetSelectMacro() const
const G4Run * GetCurrentRun() const
G4int GetNumberOfSelectEvents() const
G4int GetRunID() const
Definition G4Run.hh:82
static G4TaskRunManager * GetMasterRunManager()
G4int GetNumberOfEventsPerTask() const
G4WorkerThread * workerContext
void ConstructScoringWorlds() override
void DoEventLoop(G4int n_event, const char *macroFile=nullptr, G4int n_select=-1) override
#define G4ThreadLocalStatic
Definition tls.hh:76

Referenced by G4SubEvtRunManager::CreateAndStartWorkers(), and G4TaskRunManager::CreateAndStartWorkers().

◆ GenerateEvent()

G4Event * G4WorkerTaskRunManager::GenerateEvent ( G4int i_event)
overridevirtual

Reimplemented from G4WorkerRunManager.

Definition at line 216 of file G4WorkerTaskRunManager.cc.

217{
218 auto anEvent = new G4Event(i_event);
219 G4long s1 = 0;
220 G4long s2 = 0;
221 G4long s3 = 0;
222 G4bool eventHasToBeSeeded = true;
223 if (G4MTRunManager::SeedOncePerCommunication() == 1 && runIsSeeded) eventHasToBeSeeded = false;
224
225 if (i_event < 0) {
227 if (nevM == 1) {
229 eventHasToBeSeeded);
230 runIsSeeded = true;
231 }
232 else {
233 if (nevModulo <= 0) {
235 eventHasToBeSeeded);
236 if (nevToDo == 0)
237 eventLoopOnGoing = false;
238 else {
239 currEvID = anEvent->GetEventID();
240 nevModulo = nevToDo - 1;
241 }
242 }
243 else {
244 if (G4MTRunManager::SeedOncePerCommunication() > 0) eventHasToBeSeeded = false;
245 anEvent->SetEventID(++currEvID);
246 nevModulo--;
247 }
248 if (eventLoopOnGoing && eventHasToBeSeeded) {
249 s1 = seedsQueue.front();
250 seedsQueue.pop();
251 s2 = seedsQueue.front();
252 seedsQueue.pop();
253 }
254 }
255
256 if (!eventLoopOnGoing) {
257 anEvent->ScoresRecorded();
258 delete anEvent;
259 return nullptr;
260 }
261 }
262 else if (eventHasToBeSeeded) {
263 // Need to reseed random number generator
265 s1 = helper->GetSeed(i_event * 2);
266 s2 = helper->GetSeed(i_event * 2 + 1);
267 }
268
269 if (eventHasToBeSeeded) {
270 G4long seeds[3] = {s1, s2, 0};
271 G4Random::setTheSeeds(seeds, -1);
272 runIsSeeded = true;
273 }
274
275 // Read from file seed.
276 // Andrea Dotti 4 November 2015
277 // This is required for strong-reproducibility, in MT mode we have that each
278 // thread produces, for each event a status file, we want to do that.
279 // Search a random file with the format run{%d}evt{%d}.rndm
280
281 // This is the filename base constructed from run and event
282 const auto filename = [&] {
283 std::ostringstream os;
284 os << "run" << currentRun->GetRunID() << "evt" << anEvent->GetEventID();
285 return os.str();
286 };
287
288 G4bool RNGstatusReadFromFile = false;
289 if (readStatusFromFile) {
290 // Build full path of RNG status file for this event
291 std::ostringstream os;
292 os << filename() << ".rndm";
293 const G4String& randomStatusFile = os.str();
294 std::ifstream ifile(randomStatusFile.c_str());
295 if (ifile) {
296 // File valid and readable
297 RNGstatusReadFromFile = true;
298 G4Random::restoreEngineStatus(randomStatusFile.c_str());
299 }
300 }
301
303 std::ostringstream oss;
304 G4Random::saveFullState(oss);
306 anEvent->SetRandomNumberStatus(randomNumberStatusForThisEvent);
307 }
308
309 if (storeRandomNumberStatus && !RNGstatusReadFromFile) {
310 // If reading from file, avoid to rewrite the same
311 G4String fileN = "currentEvent";
312 if (rngStatusEventsFlag) fileN = filename();
313 StoreRNGStatus(fileN);
314 }
315
316 if (printModulo > 0 && anEvent->GetEventID() % printModulo == 0) {
317 G4cout << "--> Event " << anEvent->GetEventID() << " starts";
318 if (eventHasToBeSeeded) G4cout << " with initial seeds (" << s1 << "," << s2 << ")";
319 G4cout << "." << G4endl;
320 }
321 userPrimaryGeneratorAction->GeneratePrimaries(anEvent);
322 return anEvent;
323}
G4TemplateRNGHelper< G4long > G4RNGHelper
long G4long
Definition G4Types.hh:87
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
static G4int SeedOncePerCommunication()
virtual G4int SetUpNEvents(G4Event *, G4SeedsQueue *seedsQueue, G4bool reseedRequired=true)
G4int GetEventModulo() const
static G4MTRunManager * GetMasterRunManager()
virtual G4bool SetUpAnEvent(G4Event *, G4long &s1, G4long &s2, G4long &s3, G4bool reseedRequired=true)
G4int storeRandomNumberStatusToG4Event
G4bool rngStatusEventsFlag
G4String randomNumberStatusForThisEvent
G4bool storeRandomNumberStatus
static G4TemplateRNGHelper< G4long > * GetInstance()
virtual const T GetSeed(const G4int &sdId)
void StoreRNGStatus(const G4String &filenamePrefix) override

Referenced by ProcessOneEvent().

◆ GetCommandStack()

G4StrVector G4WorkerTaskRunManager::GetCommandStack ( ) const
inline

Definition at line 71 of file G4WorkerTaskRunManager.hh.

◆ GetWorkerRunManager()

G4WorkerTaskRunManager * G4WorkerTaskRunManager::GetWorkerRunManager ( )
static

◆ GetWorkerRunManagerKernel()

G4WorkerTaskRunManagerKernel * G4WorkerTaskRunManager::GetWorkerRunManagerKernel ( )
static

Definition at line 67 of file G4WorkerTaskRunManager.cc.

68{
69 return static_cast<G4WorkerTaskRunManagerKernel*>(GetWorkerRunManager()->kernel);
70}
G4RunManagerKernel * kernel
static G4WorkerTaskRunManager * GetWorkerRunManager()

◆ GetWorkerThread()

G4WorkerThread * G4WorkerTaskRunManager::GetWorkerThread ( ) const
inline

Definition at line 70 of file G4WorkerTaskRunManager.hh.

70{ return workerContext; }

◆ ProcessOneEvent()

void G4WorkerTaskRunManager::ProcessOneEvent ( G4int i_event)
overridevirtual

Reimplemented from G4WorkerRunManager.

Definition at line 199 of file G4WorkerTaskRunManager.cc.

200{
201 currentEvent = GenerateEvent(i_event);
202 if (eventLoopOnGoing) {
203 eventManager->ProcessOneEvent(currentEvent);
206 if (currentEvent->GetEventID() < n_select_msg) {
207 G4cout << "Applying command \"" << msgText << "\" @ " << __FUNCTION__ << ":" << __LINE__
208 << G4endl;
210 }
211 }
212}
G4String msgText
void UpdateScoring(const G4Event *evt=nullptr)
G4EventManager * eventManager
virtual void AnalyzeEvent(G4Event *anEvent)
G4Event * currentEvent
G4int ApplyCommand(const char *aCommand)
static G4UImanager * GetUIpointer()
G4Event * GenerateEvent(G4int i_event) override

Referenced by DoEventLoop().

◆ ProcessUI()

void G4WorkerTaskRunManager::ProcessUI ( )
virtual

Reimplemented in G4WorkerSubEvtRunManager.

Definition at line 390 of file G4WorkerTaskRunManager.cc.

391{
392 G4TaskRunManager* mrm = G4TaskRunManager::GetMasterRunManager();
393 if (mrm == nullptr) return;
394
395 //------------------------------------------------------------------------//
396 // Check UI commands not already processed
397 auto command_stack = mrm->GetCommandStack();
398 bool matching = (command_stack.size() == processedCommandStack.size());
399 if (matching) {
400 for (uintmax_t i = 0; i < command_stack.size(); ++i)
401 if (processedCommandStack.at(i) != command_stack.at(i)) {
402 matching = false;
403 break;
404 }
405 }
406
407 //------------------------------------------------------------------------//
408 // Execute UI commands stored in the master UI manager
409 if (!matching) {
410 for (const auto& itr : command_stack)
412 processedCommandStack = std::move(command_stack);
413 }
414}
std::vector< G4String > GetCommandStack()

Referenced by DoWork().

◆ RestoreRndmEachEvent()

void G4WorkerTaskRunManager::RestoreRndmEachEvent ( G4bool flag)
inlineoverridevirtual

Reimplemented from G4WorkerRunManager.

Definition at line 66 of file G4WorkerTaskRunManager.hh.

66{ readStatusFromFile = flag; }

◆ RunInitialization()

void G4WorkerTaskRunManager::RunInitialization ( )
overridevirtual

Reimplemented from G4WorkerRunManager.

Definition at line 74 of file G4WorkerTaskRunManager.cc.

75{
76#ifdef G4MULTITHREADED
77 if (!visIsSetUp) {
78 G4VVisManager* pVVis = G4VVisManager::GetConcreteInstance();
79 if (pVVis != nullptr) {
80 pVVis->SetUpForAThread();
81 visIsSetUp = true;
82 }
83 }
84#endif
85 runIsSeeded = false;
86
87 if (!(kernel->RunInitialization(fakeRun))) return;
88
89 // Signal this thread can start event loop.
90 // Note this will return only when all threads reach this point
92 if (fakeRun) return;
93
94 const G4UserWorkerInitialization* uwi =
96
98
99 delete currentRun;
100
101 currentRun = nullptr;
102
104
105 // Call a user hook: this is guaranteed all threads are "synchronized"
106 if (uwi != nullptr) uwi->WorkerRunStart();
107
108 if (userRunAction != nullptr) currentRun = userRunAction->GenerateRun();
109 if (currentRun == nullptr) currentRun = new G4Run();
110
111 currentRun->SetRunID(runIDCounter);
112 G4TaskRunManager* mrm = G4TaskRunManager::GetMasterRunManager();
114 currentRun->SetNumberOfEventToBeProcessed(numberOfEventToBeProcessed);
115
116 currentRun->SetDCtable(DCtable);
117 G4SDManager* fSDM = G4SDManager::GetSDMpointerIfExist();
118 if (fSDM != nullptr) {
119 currentRun->SetHCtable(fSDM->GetHCtable());
120 }
121
122 if (G4VScoreNtupleWriter::Instance() != nullptr) {
123 auto hce = (fSDM != nullptr) ? fSDM->PrepareNewEvent() : nullptr;
125 delete hce;
126 }
127
128 std::ostringstream oss;
129 G4Random::saveFullState(oss);
131 currentRun->SetRandomNumberStatus(randomNumberStatusForThisRun);
132
133 for (G4int i_prev = 0; i_prev < n_perviousEventsToBeStored; ++i_prev)
134 previousEvents->push_back(nullptr);
135
136 if (printModulo > 0 || verboseLevel > 0) {
137 G4cout << "### Run " << currentRun->GetRunID() << " starts on worker thread "
138 << G4Threading::G4GetThreadId() << "." << G4endl;
139 }
140
141 if (userRunAction != nullptr) userRunAction->BeginOfRunAction(currentRun);
142
145 }
146
148 G4String fileN = "currentRun";
150 std::ostringstream os;
151 os << "run" << currentRun->GetRunID();
152 fileN = os.str();
153 }
154 StoreRNGStatus(fileN);
155 }
156
157 runAborted = false;
159}
virtual void ThisWorkerReady()
static G4ParallelWorldProcessStore * GetInstance()
G4bool isScoreNtupleWriter
const G4UserWorkerInitialization * GetUserWorkerInitialization() const
std::list< G4Event * > * previousEvents
G4int numberOfEventProcessed
G4int GetNumberOfEventsToBeProcessed() const
G4DCtable * DCtable
G4String randomNumberStatusForThisRun
static G4bool IfGeometryHasBeenDestroyed()
G4UserRunAction * userRunAction
G4int numberOfEventToBeProcessed
G4int n_perviousEventsToBeStored
G4HCofThisEvent * PrepareNewEvent()
static G4SDManager * GetSDMpointerIfExist()
G4HCtable * GetHCtable() const
virtual G4bool Book(G4HCofThisEvent *hce)=0
static G4VScoreNtupleWriter * Instance()
virtual void OpenFile()=0
static G4VVisManager * GetConcreteInstance()
virtual void SetUpForAThread()
G4int G4GetThreadId()

Referenced by DoWork().

◆ RunTermination()

void G4WorkerTaskRunManager::RunTermination ( )
overridevirtual

Reimplemented from G4WorkerRunManager.

Definition at line 327 of file G4WorkerTaskRunManager.cc.

328{
329 if (!fakeRun && (currentRun != nullptr)) {
331
332 // Call a user hook: note this is before the next barrier
333 // so threads execute this method asyncrhonouzly
334 //(TerminateRun allows for synch via G4RunAction::EndOfRun)
335 const G4UserWorkerInitialization* uwi =
337 if (uwi != nullptr) uwi->WorkerRunEnd();
338 }
339
340 if (currentRun != nullptr) {
342 }
343 // Signal this thread has finished envent-loop.
344 // Note this will return only whan all threads reach this point
346}
virtual void ThisWorkerEndEventLoop()
virtual void RunTermination()
virtual void MergePartialResults(G4bool mergeEvents=true)

Referenced by G4TaskRunManagerKernel::TerminateWorkerRunEventLoop().

◆ SetupDefaultRNGEngine()

void G4WorkerTaskRunManager::SetupDefaultRNGEngine ( )
overrideprotectedvirtual

Reimplemented from G4WorkerRunManager.

Definition at line 369 of file G4WorkerTaskRunManager.cc.

370{
371 const CLHEP::HepRandomEngine* mrnge =
373 assert(mrnge); // Master has created RNG
374 const G4UserWorkerThreadInitialization* uwti =
376 uwti->SetupRNGEngine(mrnge);
377}
const CLHEP::HepRandomEngine * getMasterRandomEngine() const
const G4UserWorkerThreadInitialization * GetUserWorkerThreadInitialization() const
virtual void SetupRNGEngine(const CLHEP::HepRandomEngine *aRNGEngine) const

◆ StoreRNGStatus()

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

Reimplemented from G4WorkerRunManager.

Definition at line 381 of file G4WorkerTaskRunManager.cc.

382{
383 std::ostringstream os;
384 os << randomNumberStatusDir << "G4Worker" << workerContext->GetThreadId() << "_" << fn << ".rndm";
385 G4Random::saveEngineStatus(os.str().c_str());
386}
G4String randomNumberStatusDir

Referenced by GenerateEvent(), and RunInitialization().

◆ TerminateEventLoop()

void G4WorkerTaskRunManager::TerminateEventLoop ( )
overridevirtual

Reimplemented from G4WorkerRunManager.

Definition at line 350 of file G4WorkerTaskRunManager.cc.

351{
352 if (verboseLevel > 0 && !fakeRun) {
353 timer->Stop();
354 // prefix with thread # info due to how TBB calls this function
355 G4String prefix = "[thread " + std::to_string(workerContext->GetThreadId()) + "] ";
356 G4cout << prefix << "Thread-local run terminated." << G4endl;
357 G4cout << prefix << "Run Summary" << G4endl;
358 if (runAborted)
359 G4cout << prefix << " Run Aborted after " << numberOfEventProcessed << " events processed."
360 << G4endl;
361 else
362 G4cout << prefix << " Number of events processed : " << numberOfEventProcessed << G4endl;
363 G4cout << prefix << " " << *timer << G4endl;
364 }
365}
G4Timer * timer

Referenced by G4TaskRunManagerKernel::TerminateWorkerRunEventLoop().

Member Data Documentation

◆ processedCommandStack

G4StrVector G4WorkerTaskRunManager::processedCommandStack
protected

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