85 if (pVVis !=
nullptr) {
124 if (fSDM !=
nullptr) {
134 std::ostringstream oss;
135 G4Random::saveFullState(oss);
143 G4cout <<
"### Run " <<
currentRun->GetRunID() <<
" starts on worker thread "
156 std::ostringstream os;
177 "G4VUserPrimaryGeneratorAction is not defined!");
197 for (
G4int evt = 0; evt < n_event; ++evt) {
220 G4cout <<
"Applying command \"" <<
msgText <<
"\" @ " << __FUNCTION__ <<
":" << __LINE__
234 auto anEvent =
new G4Event(i_event);
238 G4bool eventHasToBeSeeded =
true;
277 else if (eventHasToBeSeeded) {
280 s1 = helper->
GetSeed(i_event * 2);
281 s2 = helper->
GetSeed(i_event * 2 + 1);
284 if (eventHasToBeSeeded) {
285 G4long seeds[3] = {s1, s2, 0};
286 G4Random::setTheSeeds(seeds, -1);
297 const auto filename = [&] {
298 std::ostringstream os;
299 os <<
"run" <<
currentRun->GetRunID() <<
"evt" << anEvent->GetEventID();
303 G4bool RNGstatusReadFromFile =
false;
306 std::ostringstream os;
307 os << filename() <<
".rndm";
308 const G4String& randomStatusFile = os.str();
309 std::ifstream ifile(randomStatusFile.c_str());
312 RNGstatusReadFromFile =
true;
313 G4Random::restoreEngineStatus(randomStatusFile.c_str());
318 std::ostringstream oss;
319 G4Random::saveFullState(oss);
332 G4cout <<
"--> Event " << anEvent->GetEventID() <<
" starts";
333 if (eventHasToBeSeeded)
G4cout <<
" with initial seeds (" << s1 <<
"," << s2 <<
")";
398 std::ostringstream os;
400 G4Random::saveEngineStatus(os.str().c_str());
408 if (mrm ==
nullptr)
return;
415 for (uintmax_t i = 0; i < command_stack.size(); ++i)
425 for (
const auto& itr : command_stack)
448 G4cout <<
"G4WorkerSubEvtRunManager::DoWork() starts.........." <<
G4endl;
456 if ((run !=
nullptr) && run->
GetRunID() != runId) {
462 G4bool reseedRequired =
false;
469 reseedRequired =
true;
477 G4bool needMoreWork =
true;
482 auto subEv = mrm->
GetSubEvent(fSubEventType, notReady, s1, s2, s3, reseedRequired);
483 if(subEv==
nullptr && notReady)
489 else if(subEv==
nullptr)
492 needMoreWork =
false;
499 G4long seeds[3] = {s1, s2, s3};
500 G4Random::setTheSeeds(seeds, -1);
501 reseedRequired =
false;
506 auto masterEvent = subEv->GetEvent();
513 for(
auto& stackedTrack : *subEv)
540 G4cout <<
"G4WorkerSubEvtRunManager::DoWork() completed.........." <<
G4endl;
548 mrm->RegisterSubEvtWorker(
this,ty);
556 G4Exception(
"G4WorkerSubEvtRunManager::SetUserInitialization(G4UserWorkerInitialization*)",
"RunSE0118",
557 FatalException,
"This method should be used only with an instance of the master thread");
563 G4Exception(
"G4WorkerSubEvtRunManager::SetUserInitialization(G4UserWorkerThreadInitialization*)",
"RunSE0119",
564 FatalException,
"This method should be used only with an instance of the master thread");
570 G4Exception(
"G4WorkerSubEvtRunManager::SetUserInitialization(G4VUserActionInitialization*)",
"RunSE0120",
571 FatalException,
"This method should be used only with an instance of the master thread");
577 G4Exception(
"G4WorkerSubEvtRunManager::SetUserInitialization(G4VUserDetectorConstruction*)",
"RunSE0121",
578 FatalException,
"This method should be used only with an instance of the master thread");
591 G4Exception(
"G4WorkerSubEvtRunManager::SetUserAction(G4UserRunAction*)",
"RunSE0221",
592 FatalException,
"This method should be used only with an instance of the master thread");
606 G4Exception(
"G4WorkerSubEvtRunManager::SetUserAction(G4VUserPrimaryGeneratorAction*)",
"RunSE0223",
607 FatalException,
"This method should be used only with an instance of the master thread");
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
G4TemplateRNGHelper< G4long > G4RNGHelper
#define G4THREADSLEEP(tick)
std::vector< G4Track * > G4TrackVector
G4WorkerTaskRunManagerKernel G4WorkerSubEvtRunManagerKernel
G4GLOB_DLL std::ostream G4cout
void FlagAsSubEvent(G4Event *me, G4int ty)
static G4int SeedOncePerCommunication()
virtual G4int SetUpNEvents(G4Event *, G4SeedsQueue *seedsQueue, G4bool reseedRequired=true)
const CLHEP::HepRandomEngine * getMasterRandomEngine() const
virtual void ThisWorkerReady()
G4int GetEventModulo() const
static G4MTRunManager * GetMasterRunManager()
std::vector< G4String > GetCommandStack()
virtual G4bool SetUpAnEvent(G4Event *, G4long &s1, G4long &s2, G4long &s3, G4bool reseedRequired=true)
virtual void ThisWorkerEndEventLoop()
static G4ParallelWorldProcessStore * GetInstance()
G4bool isScoreNtupleWriter
virtual void CleanUpPreviousEvents()
G4int storeRandomNumberStatusToG4Event
const G4UserWorkerInitialization * GetUserWorkerInitialization() const
std::list< G4Event * > * previousEvents
G4int numberOfEventProcessed
G4int GetNumberOfEventsToBeProcessed() const
virtual void InitializeEventLoop(G4int n_event, const char *macroFile=nullptr, G4int n_select=-1)
G4RunManagerKernel * kernel
virtual G4bool ConfirmBeamOnCondition()
static G4RunManager * GetRunManager()
G4String randomNumberStatusForThisRun
static G4bool IfGeometryHasBeenDestroyed()
G4UserRunAction * userRunAction
G4bool rngStatusEventsFlag
virtual void RunTermination()
G4VUserPrimaryGeneratorAction * userPrimaryGeneratorAction
void UpdateScoring(const G4Event *evt=nullptr)
const G4Run * GetCurrentRun() const
G4int numberOfEventToBeProcessed
G4String randomNumberStatusDir
virtual void SetUserAction(G4UserRunAction *userAction)
G4String randomNumberStatusForThisEvent
const G4UserWorkerThreadInitialization * GetUserWorkerThreadInitialization() const
G4int n_perviousEventsToBeStored
virtual void SetUserInitialization(G4VUserDetectorConstruction *userInit)
G4bool storeRandomNumberStatus
G4EventManager * eventManager
virtual void TerminateOneEvent()
virtual void AnalyzeEvent(G4Event *anEvent)
G4HCofThisEvent * PrepareNewEvent()
static G4SDManager * GetSDMpointerIfExist()
G4HCtable * GetHCtable() const
void SubEventFinished(const G4SubEvent *se, const G4Event *evt) override
static G4SubEvtRunManager * GetMasterRunManager()
const G4SubEvent * GetSubEvent(G4int ty, G4bool ¬Ready, G4long &s1, G4long &s2, G4long &s3, G4bool reseedRequired=true) override
static G4TaskRunManager * GetMasterRunManager()
static G4TemplateRNGHelper< G4long > * GetInstance()
virtual const T GetSeed(const G4int &sdId)
void CopyTrackInfo(const G4Track &, G4bool copyTouchables=true)
G4int ApplyCommand(const char *aCommand)
static G4UImanager * GetUIpointer()
virtual void WorkerRunEnd() const
virtual void WorkerRunStart() const
virtual void SetupRNGEngine(const CLHEP::HepRandomEngine *aRNGEngine) const
virtual G4bool Book(G4HCofThisEvent *hce)=0
static G4VScoreNtupleWriter * Instance()
virtual void OpenFile()=0
virtual void InitializeWorker()
static G4VVisManager * GetConcreteInstance()
virtual void SetUpForAThread()
virtual void MergePartialResults(G4bool mergeEvents=true)
G4bool readStatusFromFile
G4WorkerThread * workerContext
void ConstructScoringWorlds() override
void TerminateEventLoop() override
void DoCleanup() override
void RunInitialization() override
void DoEventLoop(G4int n_event, const char *macroFile=nullptr, G4int n_select=-1) override
void RunTermination() override
void SetupDefaultRNGEngine() override
static G4WorkerSubEvtRunManagerKernel * GetWorkerRunManagerKernel()
G4WorkerSubEvtRunManager(G4int subEventType=0)
static G4WorkerSubEvtRunManager * GetWorkerRunManager()
G4Event * GenerateEvent(G4int i_event) override
void StoreRNGStatus(const G4String &filenamePrefix) override
void SetUserAction(G4UserRunAction *userAction) override
void SetUserInitialization(G4VUserPhysicsList *userPL) override
void ProcessUI() override
void SetSubEventType(G4int) override
void ProcessOneEvent(G4int i_event) override
G4StrVector processedCommandStack
#define G4ThreadLocalStatic