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

#include <G4SubEvtRunManager.hh>

+ Inheritance diagram for G4SubEvtRunManager:

Public Member Functions

 G4SubEvtRunManager (G4bool useTBB=G4GetEnv< G4bool >("G4USE_TBB", false))
 
 G4SubEvtRunManager (G4VUserTaskQueue *taskQueue, G4bool useTBB=G4GetEnv< G4bool >("G4USE_TBB", false), G4int evtGrainsize=0)
 
 ~G4SubEvtRunManager () override
 
void Initialize () override
 
void Initialize (uint64_t nthreads) override
 
void RunInitialization () override
 
void InitializeEventLoop (G4int n_event, const char *macroFile=nullptr, G4int n_select=-1) override
 
void TerminateOneEvent () override
 
void ProcessOneEvent (G4int i_event) override
 
void ConstructScoringWorlds () override
 
void RunTermination () override
 
void CleanUpPreviousEvents () override
 
G4bool SetUpAnEvent (G4Event *, G4long &, G4long &, G4long &, G4bool=true) override
 
G4int SetUpNEvents (G4Event *, G4SeedsQueue *, G4bool=true) override
 
void RegisterSubEventType (G4int ty, G4int maxEnt) override
 
void RegisterSubEvtWorker (G4WorkerSubEvtRunManager *, G4int)
 
const G4SubEventGetSubEvent (G4int ty, G4bool &notReady, G4long &s1, G4long &s2, G4long &s3, G4bool reseedRequired=true) override
 
void SubEventFinished (const G4SubEvent *se, const G4Event *evt) override
 
void MergeScores (const G4ScoringManager *localScoringManager) override
 
void MergeRun (const G4Run *) override
 
std::size_t GetNumberActiveThreads () const override
 
void SetUserInitialization (G4VUserPhysicsList *userPL) override
 
void SetUserInitialization (G4VUserDetectorConstruction *userDC) override
 
void SetUserInitialization (G4UserWorkerInitialization *userInit) override
 
void SetUserInitialization (G4UserWorkerThreadInitialization *userInit) override
 
void SetUserInitialization (G4VUserActionInitialization *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 RequestWorkersProcessCommandsStack () override
 
void ThisWorkerProcessCommandsStackDone () override
 
void WaitForReadyWorkers () override
 
void WaitForEndEventLoopWorkers () override
 
WorkerActionRequest ThisWorkerWaitForNextAction () override
 
void AbortRun (G4bool softAbort=false) override
 
void AbortEvent () override
 
void TrajectoriesToBeMerged (G4bool val=true) override
 
- Public Member Functions inherited from G4TaskRunManager
 G4TaskRunManager (G4bool useTBB=G4GetEnv< G4bool >("G4USE_TBB", false))
 
 G4TaskRunManager (G4VUserTaskQueue *taskQueue, G4bool useTBB=G4GetEnv< G4bool >("G4USE_TBB", false), G4int evtGrainsize=0)
 
 ~G4TaskRunManager () override
 
void SetGrainsize (G4int n)
 
G4int GetGrainsize () const
 
G4int GetNumberOfTasks () const
 
G4int GetNumberOfEventsPerTask () const
 
void SetNumberOfThreads (G4int n) override
 
G4int GetNumberOfThreads () const override
 
size_t GetNumberActiveThreads () const override
 
void Initialize () override
 
void InitializeEventLoop (G4int n_event, const char *macroFile=nullptr, G4int n_select=-1) override
 
void InitializeThreadPool () override
 
G4bool ThreadPoolIsInitialized () const
 
void Initialize (uint64_t nthreads) override
 
void TerminateOneEvent () override
 
void ProcessOneEvent (G4int i_event) override
 
void ConstructScoringWorlds () override
 
void RunTermination () override
 
G4bool SetUpAnEvent (G4Event *, G4long &s1, G4long &s2, G4long &s3, G4bool reseedRequired=true) override
 
G4int SetUpNEvents (G4Event *, G4SeedsQueue *seedsQueue, G4bool reseedRequired=true) override
 
void MergeScores (const G4ScoringManager *localScoringManager) override
 
void MergeRun (const G4Run *localRun) override
 
void RequestWorkersProcessCommandsStack () override
 
void ThisWorkerProcessCommandsStackDone () override
 
void WaitForReadyWorkers () override
 
void WaitForEndEventLoopWorkers () override
 
void ThisWorkerReady () override
 
void ThisWorkerEndEventLoop () override
 
WorkerActionRequest ThisWorkerWaitForNextAction () override
 
void SetInitializeSeedsCallback (InitializeSeedsCallback f)
 
void AbortRun (G4bool softAbort=false) override
 
void AbortEvent () override
 
- Public Member Functions inherited from G4MTRunManager
 G4MTRunManager ()
 
 ~G4MTRunManager () override
 
void SetPinAffinity (G4int n=1)
 
G4int GetPinAffinity () const
 
std::vector< G4StringGetCommandStack ()
 
const CLHEP::HepRandomEnginegetMasterRandomEngine () const
 
void SetEventModulo (G4int i=1)
 
G4int GetEventModulo () const
 
- 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 DefineWorldVolume (G4VPhysicalVolume *worldVol, G4bool topologyIsChanged=true)
 
virtual void InitializeGeometry ()
 
virtual void InitializePhysics ()
 
virtual G4bool ConfirmBeamOnCondition ()
 
virtual void DoEventLoop (G4int n_event, const char *macroFile=nullptr, G4int n_select=-1)
 
virtual void TerminateEventLoop ()
 
virtual G4EventGenerateEvent (G4int i_event)
 
virtual void AnalyzeEvent (G4Event *anEvent)
 
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)
 
virtual void RestoreRndmEachEvent (G4bool)
 
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 G4int GetSubEventType () const
 
virtual void SetSubEventType (G4int)
 
virtual std::size_t GetMaxNTrack () const
 
virtual void ReportEventDeletion (const G4Event *evt)
 
void ResetNavigatorAtInitialization (G4bool val=true)
 
- Public Member Functions inherited from PTL::TaskRunManager
 TaskRunManager (bool useTBB=false)
 
virtual ~TaskRunManager ()
 
virtual void Terminate ()
 
ThreadPoolGetThreadPool () const
 
TaskManagerGetTaskManager () const
 
bool IsInitialized () const
 

Static Public Member Functions

static G4SubEvtRunManagerGetMasterRunManager ()
 
- Static Public Member Functions inherited from G4TaskRunManager
static G4TaskRunManagerGetMasterRunManager ()
 
static G4TaskRunManagerKernelGetMTMasterRunManagerKernel ()
 
static G4ThreadId GetMasterThreadId ()
 
- Static Public Member Functions inherited from G4MTRunManager
static G4ThreadId GetMasterThreadId ()
 
static G4ScoringManagerGetMasterScoringManager ()
 
static masterWorlds_tGetMasterWorlds ()
 
static void addWorld (G4int counter, G4VPhysicalVolume *w)
 
static G4MTRunManagerGetMasterRunManager ()
 
static G4RunManagerKernelGetMasterRunManagerKernel ()
 
static G4MTRunManagerKernelGetMTMasterRunManagerKernel ()
 
static G4int SeedOncePerCommunication ()
 
static void SetSeedOncePerCommunication (G4int val)
 
- Static Public Member Functions inherited from G4RunManager
static G4RunManagerGetRunManager ()
 
static G4bool IfGeometryHasBeenDestroyed ()
 
- Static Public Member Functions inherited from PTL::TaskRunManager
static TaskRunManagerGetInstance (bool useTBB=false)
 
static TaskRunManagerGetMasterRunManager (bool useTBB=false)
 

Protected Member Functions

void ComputeNumberOfTasks () override
 
G4bool InitializeSeeds (G4int) override
 
void RefillSeeds () override
 
void CreateAndStartWorkers () override
 
void TerminateWorkers () override
 
void NewActionRequest (WorkerActionRequest) override
 
void AddEventTask (G4int) override
 
void SetUpSeedsForSubEvent (G4long &s1, G4long &s2, G4long &s3)
 
void MergeTrajectories (const G4SubEvent *se, const G4Event *evt) override
 
void UpdateScoringForSubEvent (const G4SubEvent *se, const G4Event *evt) override
 
void CleanUpUnnecessaryEvents (G4int keepNEvents) override
 
void StackPreviousEvent (G4Event *anEvent) override
 
- Protected Member Functions inherited from G4TaskRunManager
G4bool InitializeSeeds (G4int) override
 
void RefillSeeds () override
 
void StoreRNGStatus (const G4String &filenamePrefix) override
 
void CreateAndStartWorkers () override
 
void TerminateWorkers () override
 
void NewActionRequest (WorkerActionRequest) override
 
- Protected Member Functions inherited from G4MTRunManager
virtual void PrepareCommandsStack ()
 
void rndmSaveThisRun () override
 
void rndmSaveThisEvent () override
 
- Protected Member Functions inherited from G4RunManager
 G4RunManager (RMType rmType)
 
void UpdateScoring (const G4Event *evt=nullptr)
 
virtual void DeleteUserInitializations ()
 

Protected Attributes

std::atomic< G4boolrunInProgress = false
 
- Protected Attributes inherited from G4TaskRunManager
RunTaskGroupworkTaskGroup = nullptr
 
G4boolpoolInitialized = PTL::TaskRunManager::m_is_initialized
 
G4ThreadPool *& threadPool = PTL::TaskRunManager::m_thread_pool
 
G4VUserTaskQueue *& taskQueue = PTL::TaskRunManager::m_task_queue
 
G4TaskManager *& taskManager = PTL::TaskRunManager::m_task_manager
 
InitializeSeedsCallback initSeedsCallback
 
G4bool workersStarted = false
 
G4int eventGrainsize = 0
 
G4int numberOfEventsPerTask = -1
 
G4int numberOfTasks = -1
 
CLHEP::HepRandomEnginemasterRNGEngine = nullptr
 
G4TaskRunManagerKernelMTkernel = nullptr
 
- Protected Attributes inherited from G4MTRunManager
G4int nworkers = 2
 
G4int forcedNwokers = -1
 
G4int numberOfEventToBeProcessed = 0
 
WorkerActionRequest nextActionRequest = WorkerActionRequest::UNDEFINED
 
G4int eventModuloDef = 0
 
G4int eventModulo = 1
 
G4int nSeedsUsed = 0
 
G4int nSeedsFilled = 0
 
G4int nSeedsMax = 10000
 
G4int nSeedsPerEvent = 2
 
G4doublerandDbl = nullptr
 
G4MTBarrier beginOfEventLoopBarrier
 
G4MTBarrier endOfEventLoopBarrier
 
G4MTBarrier nextActionRequestBarrier
 
G4MTBarrier processUIBarrier
 
G4int pinAffinity = 0
 
G4ThreadsList threads
 
std::vector< G4StringuiCmdsForWorkers
 
CLHEP::HepRandomEnginemasterRNGEngine = nullptr
 
G4MTRunManagerKernelMTkernel = nullptr
 
- 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
 
- Protected Attributes inherited from PTL::TaskRunManager
bool m_is_initialized = false
 
uint64_t m_workers = 0
 
bool m_use_tbb = false
 
VUserTaskQueuem_task_queue = nullptr
 
ThreadPoolm_thread_pool = nullptr
 
TaskManagerm_task_manager = nullptr
 

Friends

class G4RunManagerFactory
 

Additional Inherited Members

- Public Types inherited from G4TaskRunManager
using InitializeSeedsCallback = std::function<G4bool(G4int, G4int&, G4int&)>
 
using RunTaskGroup = G4TaskGroup<void>
 
- Public Types inherited from G4MTRunManager
enum class  WorkerActionRequest { UNDEFINED , NEXTITERATION , PROCESSUI , ENDWORKER }
 
using masterWorlds_t = std::map<G4int, G4VPhysicalVolume*>
 
- Public Types inherited from G4RunManager
enum  RMType {
  sequentialRM , masterRM , workerRM , subEventMasterRM ,
  subEventWorkerRM
}
 
- Public Types inherited from PTL::TaskRunManager
using pointer = TaskRunManager*
 
- Protected Types inherited from G4MTRunManager
using G4ThreadsList = std::list<G4Thread*>
 
- Static Protected Attributes inherited from G4MTRunManager
static G4MTRUN_DLL G4ScoringManagermasterScM = nullptr
 
static G4MTRUN_DLL G4MTRunManagerfMasterRM = nullptr
 
static G4ThreadId masterThreadId = G4ThisThread::get_id()
 
static G4int seedOncePerCommunication = 0
 
- Static Protected Attributes inherited from G4RunManager
static G4RUN_DLL G4bool fGeometryHasBeenDestroyed = false
 

Detailed Description

Definition at line 49 of file G4SubEvtRunManager.hh.

Constructor & Destructor Documentation

◆ G4SubEvtRunManager() [1/2]

G4SubEvtRunManager::G4SubEvtRunManager ( G4bool useTBB = G4GetEnv<G4bool>("G4USE_TBB", false))

Definition at line 86 of file G4SubEvtRunManager.cc.

87 : G4SubEvtRunManager(nullptr, useTBB, 0)
RMType runManagerType
G4SubEvtRunManager(G4bool useTBB=G4GetEnv< G4bool >("G4USE_TBB", false))

Referenced by G4SubEvtRunManager(), and GetMasterRunManager().

◆ G4SubEvtRunManager() [2/2]

G4SubEvtRunManager::G4SubEvtRunManager ( G4VUserTaskQueue * taskQueue,
G4bool useTBB = G4GetEnv<G4bool>("G4USE_TBB", false),
G4int evtGrainsize = 0 )

Definition at line 76 of file G4SubEvtRunManager.cc.

78 : G4TaskRunManager(task_queue, useTBB, grainsize)
79{
81 G4UImanager::GetUIpointer()->SetAlias("RunMode subEventParallel");
82}
G4TaskRunManager(G4bool useTBB=G4GetEnv< G4bool >("G4USE_TBB", false))
void SetAlias(const char *aliasLine)
static G4UImanager * GetUIpointer()

◆ ~G4SubEvtRunManager()

G4SubEvtRunManager::~G4SubEvtRunManager ( )
override

Definition at line 92 of file G4SubEvtRunManager.cc.

93{
94 // relying all the necessary deletion upon the base class
95 // G4TaskRunManager::~G4TaskRunManager()
96}

Member Function Documentation

◆ AbortEvent()

void G4SubEvtRunManager::AbortEvent ( )
overridevirtual

Reimplemented from G4MTRunManager.

Definition at line 812 of file G4SubEvtRunManager.cc.

813{
814 // nothing to do in the master thread
815}

◆ AbortRun()

void G4SubEvtRunManager::AbortRun ( G4bool softAbort = false)
overridevirtual

Reimplemented from G4MTRunManager.

Definition at line 797 of file G4SubEvtRunManager.cc.

798{
799 // This method is valid only for GeomClosed or EventProc state
801 if (currentState == G4State_GeomClosed || currentState == G4State_EventProc) {
802 runAborted = true;
803 MTkernel->BroadcastAbortRun(softAbort);
804 }
805 else {
806 G4cerr << "Run is not in progress. AbortRun() ignored." << G4endl;
807 }
808}
G4ApplicationState
@ G4State_EventProc
@ G4State_GeomClosed
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition G4ios.hh:67
G4MTRunManagerKernel * MTkernel
const G4ApplicationState & GetCurrentState() const
static G4StateManager * GetStateManager()

◆ AddEventTask()

void G4SubEvtRunManager::AddEventTask ( G4int nt)
overrideprotectedvirtual

Reimplemented from G4TaskRunManager.

Definition at line 351 of file G4SubEvtRunManager.cc.

352{
353 if (verboseLevel > 3) G4cout << "Adding task " << nt << " to task-group..." << G4endl;
355}
G4GLOB_DLL std::ostream G4cout
RunTaskGroup * workTaskGroup

Referenced by CreateAndStartWorkers().

◆ CleanUpPreviousEvents()

void G4SubEvtRunManager::CleanUpPreviousEvents ( )
overridevirtual

Reimplemented from G4RunManager.

Definition at line 740 of file G4SubEvtRunManager.cc.

741{
742 // Delete all events carried over from previous run.
743 // This method is invoked at the beginning of the next run
744 // or from the destructor of G4RunManager at the very end of
745 // the program.
746 auto evItr = previousEvents->cbegin();
747 while (evItr != previousEvents->cend()) {
748 G4Event* evt = *evItr;
749 if (evt != nullptr)
750 {
752 // remove evt from the event vector of G4Run as well
753 if(currentRun!=nullptr)
754 {
755 auto eventVector = currentRun->GetEventVector();
756 auto eItr = std::find(eventVector->cbegin(),eventVector->cend(),evt);
757 if(eItr != eventVector->cend()) eventVector->erase(eItr);
758 }
759 delete evt;
760 }
761 evItr = previousEvents->erase(evItr);
762 }
763 if(currentRun!=nullptr)
764 {
765 auto eventVector = currentRun->GetEventVector();
766 if(eventVector==nullptr || eventVector->empty()) return;
767 auto eItr = eventVector->cbegin();
768 while(eItr != eventVector->cend())
769 {
770 const G4Event* ev = *eItr;
771 if(ev!=nullptr)
772 {
774 delete ev;
775 }
776 eItr = eventVector->erase(eItr);
777 }
778 }
779}
virtual void ReportEventDeletion(const G4Event *evt)
std::list< G4Event * > * previousEvents
G4Run * currentRun

◆ CleanUpUnnecessaryEvents()

void G4SubEvtRunManager::CleanUpUnnecessaryEvents ( G4int keepNEvents)
overrideprotectedvirtual

Reimplemented from G4RunManager.

Definition at line 199 of file G4SubEvtRunManager.cc.

200{
201 // Delete events that are no longer necessary for post
202 // processing such as visualization.
203 // N.B. If ToBeKept() is true, the pointer of this event is
204 // kept in G4Run, and deleted along with the deletion of G4Run.
205
206 if(keepNEvents>0) {
208 ed << "G4RunManager::SetNumberOfEventsToBeStored() is not supported in sub-event parallel mode.\n"
209 << "User may still keep events bu G4EventManager::KeepTheCurrentEvent()";
210 G4Exception("G4SubEvtRunManager::CleanUpUnnecessaryEvents","SubEvtRM1201",FatalException,ed);
211 return;
212 }
213
214 assert(currentRun!=nullptr);
215
216 auto eventVector = currentRun->GetEventVector();
217 if(eventVector==nullptr || eventVector->empty()) return;
218 auto eItr = eventVector->cbegin();
219 while(eItr != eventVector->cend())
220 {
221 const G4Event* ev = *eItr;
222 if(ev!=nullptr)
223 {
224 if(!(ev->IsEventCompleted()))
225 {
227 { // This event has been completed since last time we were here
228 ev->EventCompleted();
229 if(userEventAction!=nullptr) userEventAction->EndOfEventAction(ev);
230 auto pVisManager = G4VVisManager::GetConcreteInstance();
231 if (pVisManager) pVisManager->EventReadyForVis(ev);
232 UpdateScoring(ev);
233 if(ev->ToBeKept() || ev->GetNumberOfGrips()>0)
234 { // we keep this event for post-processing (i.e. for vis)
235 eItr++;
236 }
237 else
238 { // this event is no longer needed
240 delete ev;
241 eItr = eventVector->erase(eItr);
242 }
243 }
244 else
245 { // this event is still incomplete
246 eItr++;
247 }
248 }
249 else if(ev->ToBeKept() || ev->GetNumberOfGrips()>0)
250 { // we still need this event
251 eItr++;
252 }
253 else
254 { // post-processing done. we no longer need this event
256 delete ev;
257 eItr = eventVector->erase(eItr);
258 }
259 }
260 else
261 { // ev is a null pointer
262 eItr = eventVector->erase(eItr);
263 }
264 }
265}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
G4bool ToBeKept() const
Definition G4Event.hh:105
G4int GetNumberOfGrips() const
Definition G4Event.hh:123
G4bool IsEventCompleted() const
Definition G4Event.hh:304
void EventCompleted() const
Definition G4Event.hh:303
G4int GetNumberOfRemainingSubEvents() const
Definition G4Event.cc:277
G4UserEventAction * userEventAction
void UpdateScoring(const G4Event *evt=nullptr)
static G4VVisManager * GetConcreteInstance()

Referenced by RunTermination(), and StackPreviousEvent().

◆ ComputeNumberOfTasks()

void G4SubEvtRunManager::ComputeNumberOfTasks ( )
inlineoverrideprotectedvirtual

Reimplemented from G4TaskRunManager.

Definition at line 165 of file G4SubEvtRunManager.hh.

166 {
167 // This method is not used for sub-event parallel mode
168 numberOfTasks = (G4int)threadPool->size();
170 eventModulo = -1;
171 }
int G4int
Definition G4Types.hh:85
G4ThreadPool *& threadPool

Referenced by CreateAndStartWorkers(), and InitializeEventLoop().

◆ ConstructScoringWorlds()

void G4SubEvtRunManager::ConstructScoringWorlds ( )
overridevirtual

Reimplemented from G4MTRunManager.

Definition at line 504 of file G4SubEvtRunManager.cc.

505{
507 // Call base class stuff...
509
510 GetMasterWorlds().clear();
513 for (G4int iWorld = 0; iWorld < nWorlds; ++iWorld) {
514 addWorld(iWorld, *itrW);
515 ++itrW;
516 }
517}
static void addWorld(G4int counter, G4VPhysicalVolume *w)
static G4MTRUN_DLL G4ScoringManager * masterScM
static masterWorlds_t & GetMasterWorlds()
virtual void ConstructScoringWorlds()
static G4ScoringManager * GetScoringManagerIfExist()
static G4TransportationManager * GetTransportationManager()
std::vector< G4VPhysicalVolume * >::iterator GetWorldsIterator()
std::size_t GetNoWorlds() const

◆ CreateAndStartWorkers()

void G4SubEvtRunManager::CreateAndStartWorkers ( )
overrideprotectedvirtual

Reimplemented from G4MTRunManager.

Definition at line 269 of file G4SubEvtRunManager.cc.

270{
271 // Now loop on requested number of workers
272 // This will also start the workers
273 // Currently we do not allow to change the
274 // number of threads: threads area created once
275 // Instead of pthread based workers, create tbbTask
276 static G4bool initializeStarted = false;
277
279
280 if (fakeRun) {
281 if (initializeStarted) {
282 auto initCmdStack = GetCommandStack();
283 if (!initCmdStack.empty()) {
284 threadPool->execute_on_all_threads([cmds = std::move(initCmdStack)]() {
285 for (auto& itr : cmds)
288 });
289 }
290 }
291 else {
292 std::stringstream msg;
293 msg << "--> G4SubEvtRunManager::CreateAndStartWorkers() --> "
294 << "Initializing workers...";
295
296 std::stringstream ss;
297 ss.fill('=');
298 ss << std::setw((G4int)msg.str().length()) << "";
299 G4cout << "\n" << ss.str() << "\n" << msg.str() << "\n" << ss.str() << "\n" << G4endl;
300
302 threadPool->execute_on_all_threads([]() { G4TaskRunManagerKernel::InitializeWorker(); });
303 }
304 initializeStarted = true;
305 }
306 else {
307 auto initCmdStack = GetCommandStack();
308 if (!initCmdStack.empty()) {
309 threadPool->execute_on_all_threads([cmds = std::move(initCmdStack)]() {
310 for (auto& itr : cmds)
312 });
313 }
314
315 // cleans up a previous run and events in case a thread
316 // does not execute any tasks
317 threadPool->execute_on_all_threads([]() { G4TaskRunManagerKernel::ExecuteWorkerInit(); });
318
319 {
320 std::stringstream msg;
321 msg << "--> G4SubEvtRunManager::CreateAndStartWorkers() --> "
322 << "Creating " << numberOfTasks << " tasks with " << numberOfEventsPerTask
323 << " events/task...";
324
325 std::stringstream ss;
326 ss.fill('=');
327 ss << std::setw((G4int)msg.str().length()) << "";
328 G4cout << "\n" << ss.str() << "\n" << msg.str() << "\n" << ss.str() << "\n" << G4endl;
329 }
330
331 /* TODO (PHASE-II): Better calculation of task/event/subevents
332 Currently, number of tasks is equal to number of threads
333 and each task has a loop that endlessly asks for next sub-event
334 until no additional sub-event is available in the master.
335 This is not ideal. We should make each task work only for some limited
336 number of sub-events, and create as many number of tasks as needed
337 on the fly during the event loop of the master thread., e.g.
338 G4int remaining = numberOfEventToBeProcessed;
339 for (G4int nt = 0; nt < numberOfTasks + 1; ++nt) {
340 if (remaining > 0) AddEventTask(nt);
341 remaining -= numberOfEventsPerTask;
342 }
343 */
344 for(G4int nt = 0; nt < numberOfTasks; ++nt)
345 { AddEventTask(nt); }
346 }
347}
bool G4bool
Definition G4Types.hh:86
std::vector< G4String > GetCommandStack()
void ComputeNumberOfTasks() override
void AddEventTask(G4int) override
static std::vector< G4String > & InitCommandStack()
G4int ApplyCommand(const char *aCommand)
static G4WorkerTaskRunManager * GetWorkerRunManager()

Referenced by InitializeEventLoop().

◆ GetMasterRunManager()

static G4SubEvtRunManager * G4SubEvtRunManager::GetMasterRunManager ( )
inlinestatic

Definition at line 54 of file G4SubEvtRunManager.hh.

55 {
57 return dynamic_cast<G4SubEvtRunManager*>(_rm);
58 }
static G4MTRunManager * GetMasterRunManager()

Referenced by G4WorkerSubEvtRunManager::DoWork(), and G4WorkerSubEvtRunManager::SetSubEventType().

◆ GetNumberActiveThreads()

std::size_t G4SubEvtRunManager::GetNumberActiveThreads ( ) const
inlineoverridevirtual

Reimplemented from G4MTRunManager.

Definition at line 117 of file G4SubEvtRunManager.hh.

118 { return threads.size(); }
G4ThreadsList threads

◆ GetSubEvent()

const G4SubEvent * G4SubEvtRunManager::GetSubEvent ( G4int ty,
G4bool & notReady,
G4long & s1,
G4long & s2,
G4long & s3,
G4bool reseedRequired = true )
overridevirtual

Reimplemented from G4RunManager.

Definition at line 527 of file G4SubEvtRunManager.cc.

529{
530 G4AutoLock l(&accessSubEventMutex);
531
532// This method is invoked from the worker, the ownership of G4SubEvent object
533// remains to the master, i.e. will be deleted by the master thread through
534// TerminateSubEvent() method.
535
536 if(currentRun==nullptr)
537 {
538 // Run has not yet started.
539 notReady = true;
540 return nullptr;
541 }
542
543 auto eventVector = currentRun->GetEventVector();
544 // RACE HERE: against:
545 // 1 G4Run::StoreEvent(G4Event*) G4Run.cc:80
546 // 2 G4RunManager::StackPreviousEvent(G4Event*) G4RunManager.cc:572
547 for(auto& ev : *eventVector)
548 {
549 // looping over stored events
550 // RACE HERE: against:
551 // 1 G4Run::StoreEvent(G4Event*) G4Run.cc:80
552 // 2 G4RunManager::StackPreviousEvent(G4Event*) G4RunManager.cc:572
553 auto se = const_cast<G4Event*>(ev)->PopSubEvent(ty);
554 if(se!=nullptr)
555 {
556 // Sub-event is found in an event that is already finished its event-loop
557 notReady = false;
558 if(reseedRequired) SetUpSeedsForSubEvent(s1,s2,s3);
559 return se;
560 }
561 }
562
563 auto sep = eventManager->PopSubEvent(ty);
564 if(sep!=nullptr)
565 {
566 // Sub-event is found in an event that is still in the event loop
567 notReady = false;
568 if(reseedRequired) SetUpSeedsForSubEvent(s1,s2,s3);
569 return sep;
570 } else {
571 // No sub-event available
572 // RACE HERE vs line 345
573 if(runInProgress)
574 {
575 // Run is still in progress. Worker should wait until a sub-event is ready
576 notReady = true;
577 }
578 else
579 {
580 // Run is over. No more sub-event to come unless new run starts.
581 notReady = false;
582 }
583 return nullptr;
584 }
585}
G4TemplateAutoLock< G4Mutex > G4AutoLock
G4EventManager * eventManager
std::atomic< G4bool > runInProgress
void SetUpSeedsForSubEvent(G4long &s1, G4long &s2, G4long &s3)

Referenced by G4WorkerSubEvtRunManager::DoWork().

◆ Initialize() [1/2]

void G4SubEvtRunManager::Initialize ( )
overridevirtual

Reimplemented from G4MTRunManager.

Definition at line 100 of file G4SubEvtRunManager.cc.

101{
103 G4bool firstTime = (threadPool == nullptr);
105
107
108 // make sure all worker threads are set up.
110 if (firstTime) G4RunManager::SetRunIDCounter(0);
111 // G4UImanager::GetUIpointer()->SetIgnoreCmdNotFound(true);
112}
static void SetSeedOncePerCommunication(G4int val)
virtual void Initialize()
void SetRunIDCounter(G4int i)
virtual void BeamOn(G4int n_event, const char *macroFile=nullptr, G4int n_select=-1)
void InitializeThreadPool() override

◆ Initialize() [2/2]

void G4SubEvtRunManager::Initialize ( uint64_t nthreads)
inlineoverridevirtual

Reimplemented from PTL::TaskRunManager.

Definition at line 67 of file G4SubEvtRunManager.hh.

virtual void Initialize(uint64_t n=std::thread::hardware_concurrency())

◆ InitializeEventLoop()

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

Reimplemented from G4MTRunManager.

Definition at line 383 of file G4SubEvtRunManager.cc.

384{
385 MTkernel->SetUpDecayChannels();
388
389 if (!fakeRun) {
390 nSeedsUsed = 0;
391 nSeedsFilled = 0;
392
393 if (verboseLevel > 0) timer->Start();
394
395 n_select_msg = n_select;
396 if (macroFile != nullptr) {
397 if (n_select_msg < 0) n_select_msg = n_event;
398
399 msgText = "/control/execute ";
400 msgText += macroFile;
401 selectMacro = macroFile;
402 }
403 else {
404 n_select_msg = -1;
405 selectMacro = "";
406 }
407
409
410 // initialize seeds
411 // If user did not implement InitializeSeeds,
412 // use default: nSeedsPerEvent seeds per event
413
414 if (n_event > 0) {
415 G4bool _overload = InitializeSeeds(n_event);
416 G4bool _functor = false;
417 if (!_overload) _functor = initSeedsCallback(n_event, nSeedsPerEvent, nSeedsFilled);
418 if (!_overload && !_functor) {
420 switch (SeedOncePerCommunication()) {
421 case 1:
423 break;
424 default:
426 msgd << "Parameter value <" << SeedOncePerCommunication()
427 << "> of seedOncePerCommunication is invalid. It is reset "
428 "to 1.";
429 G4Exception("G4SubEvtRunManager::InitializeEventLoop()", "Run10036", JustWarning, msgd);
432 }
433
434 // Generates up to nSeedsMax seed pairs only.
437 helper->Fill(randDbl, nSeedsFilled, n_event, nSeedsPerEvent);
438 }
439 }
440 }
441
442 // Now initialize workers. Check if user defined a WorkerThreadInitialization
443 if (userWorkerThreadInitialization == nullptr)
444 userWorkerThreadInitialization = new G4UserSubEvtThreadInitialization();
445
446 // Prepare UI commands for threads
448
449 // Start worker threads
451}
@ JustWarning
G4TemplateRNGHelper< G4long > G4RNGHelper
static G4int SeedOncePerCommunication()
G4int numberOfEventToBeProcessed
CLHEP::HepRandomEngine * masterRNGEngine
virtual void PrepareCommandsStack()
G4Timer * timer
G4UserWorkerThreadInitialization * userWorkerThreadInitialization
G4int numberOfEventProcessed
G4String msgText
G4String selectMacro
void CreateAndStartWorkers() override
G4bool InitializeSeeds(G4int) override
InitializeSeedsCallback initSeedsCallback
static G4TemplateRNGHelper< G4long > * GetInstance()
void Fill(G4double *dbl, G4int nev, G4int nev_tot, G4int nrpe)

◆ InitializeSeeds()

G4bool G4SubEvtRunManager::InitializeSeeds ( G4int )
inlineoverrideprotectedvirtual

Reimplemented from G4MTRunManager.

Definition at line 177 of file G4SubEvtRunManager.hh.

177{ return false; };

Referenced by InitializeEventLoop().

◆ MergeRun()

void G4SubEvtRunManager::MergeRun ( const G4Run * )
inlineoverridevirtual

Reimplemented from G4MTRunManager.

Definition at line 110 of file G4SubEvtRunManager.hh.

111 {}

◆ MergeScores()

void G4SubEvtRunManager::MergeScores ( const G4ScoringManager * localScoringManager)
overridevirtual

Reimplemented from G4MTRunManager.

Definition at line 521 of file G4SubEvtRunManager.cc.

522{
523 G4AutoLock l(&scorerMergerMutex);
524 if (masterScM != nullptr) masterScM->Merge(localScoringManager);
525}

◆ MergeTrajectories()

void G4SubEvtRunManager::MergeTrajectories ( const G4SubEvent * se,
const G4Event * evt )
overrideprotectedvirtual

Reimplemented from G4RunManager.

Definition at line 678 of file G4SubEvtRunManager.cc.

679{
680 auto masterEvt = se->GetEvent();
681 auto* trajVector = evt->GetTrajectoryContainer()->GetVector();
682 auto* masterTrajContainer = masterEvt->GetTrajectoryContainer();
683 if(masterTrajContainer==nullptr)
684 {
685 masterTrajContainer = new G4TrajectoryContainer;
686 masterEvt->SetTrajectoryContainer(masterTrajContainer);
687 }
688 for(auto& traj : *trajVector)
689 {
690 if(traj!=nullptr) {
691 auto* cloned = traj->CloneForMaster();
692 masterTrajContainer->push_back(cloned);
693 }
694 }
695}
G4TrajectoryContainer * GetTrajectoryContainer() const
Definition G4Event.hh:168
G4Event * GetEvent() const
Definition G4SubEvent.hh:76
TrajectoryVector * GetVector() const

Referenced by SubEventFinished().

◆ NewActionRequest()

void G4SubEvtRunManager::NewActionRequest ( WorkerActionRequest )
inlineoverrideprotectedvirtual

Reimplemented from G4MTRunManager.

Definition at line 188 of file G4SubEvtRunManager.hh.

188{}

◆ ProcessOneEvent()

void G4SubEvtRunManager::ProcessOneEvent ( G4int i_event)
overridevirtual

Reimplemented from G4MTRunManager.

Definition at line 125 of file G4SubEvtRunManager.cc.

126{
127 currentEvent = GenerateEvent(i_event);
128 eventManager->ProcessOneEvent(currentEvent);
129
130 // Following two lines should not be executed here, as spawned sub-events may
131 // be still being processed. These methods are invoked when all sub-events belongings
132 // to this event are processed and scores of these sub-events are marged to the
133 // corresponding master event.
134 //AnalyzeEvent(currentEvent);
135 //UpdateScoring();
136
138}
virtual G4Event * GenerateEvent(G4int i_event)
G4Event * currentEvent

◆ RefillSeeds()

void G4SubEvtRunManager::RefillSeeds ( )
overrideprotectedvirtual

Reimplemented from G4MTRunManager.

Definition at line 359 of file G4SubEvtRunManager.cc.

360{
362 G4int nFill = 0;
363 switch (SeedOncePerCommunication()) {
364 case 0:
366 break;
367 case 1:
368 nFill = numberOfTasks - nSeedsFilled;
369 break;
370 case 2:
371 default:
373 }
374 // Generates up to nSeedsMax seed pairs only.
375 if (nFill > nSeedsMax) nFill = nSeedsMax;
376 masterRNGEngine->flatArray(nSeedsPerEvent * nFill, randDbl);
377 helper->Refill(randDbl, nFill);
378 nSeedsFilled += nFill;
379}
void Refill(G4double *dbl, G4int nev)

Referenced by SetUpSeedsForSubEvent().

◆ RegisterSubEventType()

void G4SubEvtRunManager::RegisterSubEventType ( G4int ty,
G4int maxEnt )
overridevirtual

Reimplemented from G4RunManager.

Definition at line 854 of file G4SubEvtRunManager.cc.

855{
856 G4AutoLock l(&registerSubEvtWorkerMutex);
857 fSubEvtTypeMap[ty] = maxEnt;
858 eventManager->UseSubEventParallelism();
859 eventManager->GetStackManager()->RegisterSubEventType(ty,maxEnt);
860}

◆ RegisterSubEvtWorker()

void G4SubEvtRunManager::RegisterSubEvtWorker ( G4WorkerSubEvtRunManager * wrm,
G4int typ )

Definition at line 862 of file G4SubEvtRunManager.cc.

863{
864 G4AutoLock l(&registerSubEvtWorkerMutex);
865 fWorkerMap[wrm] = typ;
866}

◆ RequestWorkersProcessCommandsStack()

void G4SubEvtRunManager::RequestWorkersProcessCommandsStack ( )
overridevirtual

Reimplemented from G4MTRunManager.

Definition at line 831 of file G4SubEvtRunManager.cc.

832{
834
835 auto process_commands_stack = []() {
837 if (mrm != nullptr) {
838 auto cmds = mrm->GetCommandStack();
839 for (const auto& itr : cmds)
840 G4UImanager::GetUIpointer()->ApplyCommand(itr); // TLS instance
842 }
843 };
844
845 if (threadPool != nullptr) threadPool->execute_on_all_threads(process_commands_stack);
846}
virtual void ThisWorkerProcessCommandsStackDone()

Referenced by TerminateWorkers().

◆ RunInitialization()

void G4SubEvtRunManager::RunInitialization ( )
overridevirtual

Reimplemented from G4RunManager.

Definition at line 116 of file G4SubEvtRunManager.cc.

117{
119 if(!fakeRun)
120 { if(CheckSubEvtTypes()) runInProgress = true; }
121}
virtual void RunInitialization()

◆ RunTermination()

void G4SubEvtRunManager::RunTermination ( )
overridevirtual

Reimplemented from G4MTRunManager.

Definition at line 455 of file G4SubEvtRunManager.cc.

456{
457 // Wait for all worker threads to have finished the run
458 // i.e. wait for them to return from RunTermination()
459 // This guarantee that userrunaction for workers has been called
460
461 runInProgress = false;
462
463 //TODO (PHASE-II): do we need this???
464 workTaskGroup->wait();
465
466 // Wait now for all threads to finish event-loop
468
469 // Now call base-class method
472
473 if(currentRun!=nullptr)
474 {
475 auto eventVector = currentRun->GetEventVector();
476 if(eventVector!=nullptr)
477 {
478 G4int notReady = 1;
479 while(notReady>0)
480 {
481 notReady = 0;
482 for(auto ev:*eventVector)
483 {
484 if(ev->GetNumberOfRemainingSubEvents()>0 || ev->GetNumberOfGrips()>0 )
485 { notReady++; }
486 }
487 if(notReady>0)
488 {
489 if(verboseLevel>2)
490 {
491 G4cout << "G4SubEvtRunManager::RunTermination - " << notReady
492 << " events are still incomplete. Waiting for them." << G4endl;
493 }
494 G4THREADSLEEP(1);
495 }
496 }
497 }
499 }
500}
#define G4THREADSLEEP(tick)
virtual void RunTermination()
virtual void TerminateEventLoop()
void CleanUpUnnecessaryEvents(G4int keepNEvents) override
void WaitForEndEventLoopWorkers() override

◆ SetUpAnEvent()

G4bool G4SubEvtRunManager::SetUpAnEvent ( G4Event * ,
G4long & ,
G4long & ,
G4long & ,
G4bool = true )
inlineoverridevirtual

Reimplemented from G4MTRunManager.

Definition at line 78 of file G4SubEvtRunManager.hh.

79 { return false; }

◆ SetUpNEvents()

G4int G4SubEvtRunManager::SetUpNEvents ( G4Event * ,
G4SeedsQueue * ,
G4bool = true )
inlineoverridevirtual

Reimplemented from G4MTRunManager.

Definition at line 80 of file G4SubEvtRunManager.hh.

81 { return -1; }

◆ SetUpSeedsForSubEvent()

void G4SubEvtRunManager::SetUpSeedsForSubEvent ( G4long & s1,
G4long & s2,
G4long & s3 )
protected

Definition at line 587 of file G4SubEvtRunManager.cc.

588{
589 //TODO (PHASE-II): Seeding scheme for sub-event has to be revisited
591 G4int idx_rndm = nSeedsPerEvent * nSeedsUsed;
592 s1 = helper->GetSeed(idx_rndm);
593 s2 = helper->GetSeed(idx_rndm + 1);
594 if (nSeedsPerEvent == 3) s3 = helper->GetSeed(idx_rndm + 2);
595 ++nSeedsUsed;
597}
void RefillSeeds() override
virtual const T GetSeed(const G4int &sdId)

Referenced by GetSubEvent().

◆ SetUserAction() [1/6]

void G4SubEvtRunManager::SetUserAction ( G4UserEventAction * userAction)
overridevirtual

Reimplemented from G4MTRunManager.

Definition at line 931 of file G4SubEvtRunManager.cc.

932{
934}
virtual void SetUserAction(G4UserRunAction *userAction)

◆ SetUserAction() [2/6]

void G4SubEvtRunManager::SetUserAction ( G4UserRunAction * userAction)
overridevirtual

Reimplemented from G4MTRunManager.

Definition at line 924 of file G4SubEvtRunManager.cc.

925{
926 G4RunManager::SetUserAction(userAction);
927 if (userAction != nullptr) userAction->SetMaster(true);
928}
virtual void SetMaster(G4bool val=true)

◆ SetUserAction() [3/6]

void G4SubEvtRunManager::SetUserAction ( G4UserStackingAction * userAction)
overridevirtual

Reimplemented from G4MTRunManager.

Definition at line 943 of file G4SubEvtRunManager.cc.

944{
946}

◆ SetUserAction() [4/6]

void G4SubEvtRunManager::SetUserAction ( G4UserSteppingAction * userAction)
overridevirtual

Reimplemented from G4MTRunManager.

Definition at line 955 of file G4SubEvtRunManager.cc.

956{
958}

◆ SetUserAction() [5/6]

void G4SubEvtRunManager::SetUserAction ( G4UserTrackingAction * userAction)
overridevirtual

Reimplemented from G4MTRunManager.

Definition at line 949 of file G4SubEvtRunManager.cc.

950{
952}

◆ SetUserAction() [6/6]

void G4SubEvtRunManager::SetUserAction ( G4VUserPrimaryGeneratorAction * userAction)
overridevirtual

Reimplemented from G4MTRunManager.

Definition at line 937 of file G4SubEvtRunManager.cc.

938{
940}

◆ SetUserInitialization() [1/5]

void G4SubEvtRunManager::SetUserInitialization ( G4UserWorkerInitialization * userInit)
overridevirtual

Reimplemented from G4MTRunManager.

Definition at line 892 of file G4SubEvtRunManager.cc.

893{
894 userWorkerInitialization = userInit;
895}
G4UserWorkerInitialization * userWorkerInitialization

◆ SetUserInitialization() [2/5]

void G4SubEvtRunManager::SetUserInitialization ( G4UserWorkerThreadInitialization * userInit)
overridevirtual

Reimplemented from G4MTRunManager.

Definition at line 898 of file G4SubEvtRunManager.cc.

899{
901}

◆ SetUserInitialization() [3/5]

void G4SubEvtRunManager::SetUserInitialization ( G4VUserActionInitialization * userInit)
overridevirtual

Reimplemented from G4MTRunManager.

Definition at line 904 of file G4SubEvtRunManager.cc.

905{
906 userActionInitialization = userInit;
907 userActionInitialization->BuildForMaster();
908}
G4VUserActionInitialization * userActionInitialization

◆ SetUserInitialization() [4/5]

void G4SubEvtRunManager::SetUserInitialization ( G4VUserDetectorConstruction * userDC)
overridevirtual

Reimplemented from G4MTRunManager.

Definition at line 911 of file G4SubEvtRunManager.cc.

912{
914}
virtual void SetUserInitialization(G4VUserDetectorConstruction *userInit)

◆ SetUserInitialization() [5/5]

void G4SubEvtRunManager::SetUserInitialization ( G4VUserPhysicsList * userPL)
overridevirtual

Reimplemented from G4MTRunManager.

Definition at line 917 of file G4SubEvtRunManager.cc.

918{
919 pl->InitializeWorker();
921}

◆ StackPreviousEvent()

void G4SubEvtRunManager::StackPreviousEvent ( G4Event * anEvent)
overrideprotectedvirtual

Reimplemented from G4RunManager.

Definition at line 154 of file G4SubEvtRunManager.cc.

155{
158 ed << "G4RunManager::SetNumberOfEventsToBeStored() is not supported in sub-event parallel mode.\n"
159 << "User may still keep events bu G4EventManager::KeepTheCurrentEvent()";
160 G4Exception("G4SubEvtRunManager::StackPreviousEvent","SubEvtRM1200",FatalException,ed);
161 return;
162 }
163
164 if(anEvent->GetNumberOfRemainingSubEvents()>0)
165 // sub-events are still under processing. Event is not yet fully completed.
166 {
167 currentRun->StoreEvent(anEvent);
168 }
169 else
170 // Event is already completed.
171 {
172 // making sure this is the first path
173 if(!(anEvent->IsEventCompleted()))
174 {
175 anEvent->EventCompleted();
176 if(userEventAction!=nullptr) userEventAction->EndOfEventAction(anEvent);
177 auto pVisManager = G4VVisManager::GetConcreteInstance();
178 if (pVisManager) pVisManager->EventReadyForVis(anEvent);
179 UpdateScoring(anEvent);
180 if(anEvent->ToBeKept() || anEvent->GetNumberOfGrips()>0)
181 { // we keep this event for post-processing (i.e. for vis)
182 currentRun->StoreEvent(anEvent);
183 }
184 else
185 {
186 ReportEventDeletion(anEvent);
187 delete anEvent;
188 }
189 } else {
190 G4Exception("G4SubEvtRunManager::StackPreviousEvent","SubEvtRM1209",FatalException,"We should not be here!!");
191 }
192 }
193
195}
G4int n_perviousEventsToBeStored

Referenced by TerminateOneEvent().

◆ SubEventFinished()

void G4SubEvtRunManager::SubEventFinished ( const G4SubEvent * se,
const G4Event * evt )
overridevirtual

Reimplemented from G4RunManager.

Definition at line 657 of file G4SubEvtRunManager.cc.

658{
659 G4AutoLock l(&accessSubEventMutex);
660 auto masterEvt = se->GetEvent();
661 if(masterEvt==nullptr) {
662 G4Exception("G4SubEvtRunManager::SubEventFinished()","SERM0001",
663 FatalException,"Pointer of master event is null. PANIC!");
664 return; // NOLINT: required to help Coverity recognise FatalException as exit point
665 }
666
667 if(userEventAction) {
668 userEventAction->MergeSubEvent(masterEvt,evt);
669 }
670 if(trajectoriesToBeMerged) MergeTrajectories(se,evt);
672 evt->ScoresRecorded();
673 eventManager->TerminateSubEvent(se,evt);
674}
void ScoresRecorded() const
Definition G4Event.hh:301
void UpdateScoringForSubEvent(const G4SubEvent *se, const G4Event *evt) override
void MergeTrajectories(const G4SubEvent *se, const G4Event *evt) override

Referenced by G4WorkerSubEvtRunManager::DoWork().

◆ TerminateOneEvent()

void G4SubEvtRunManager::TerminateOneEvent ( )
overridevirtual

Reimplemented from G4MTRunManager.

Definition at line 142 of file G4SubEvtRunManager.cc.

143{
144 // We must serialize access here because workers may access Run/Event vectors
145 // and we can't override StackPreviousEvent
146 G4AutoLock l(&accessSubEventMutex);
148 currentEvent = nullptr;
150}
void StackPreviousEvent(G4Event *anEvent) override

◆ TerminateWorkers()

void G4SubEvtRunManager::TerminateWorkers ( )
overrideprotectedvirtual

Reimplemented from G4MTRunManager.

Definition at line 783 of file G4SubEvtRunManager.cc.

784{
785 // Force workers to execute (if any) all UI commands left in the stack
787
788 if (workTaskGroup != nullptr) {
789 workTaskGroup->join();
790 if (!fakeRun)
791 threadPool->execute_on_all_threads([]() { G4TaskRunManagerKernel::TerminateWorker(); });
792 }
793}
void RequestWorkersProcessCommandsStack() override

◆ ThisWorkerProcessCommandsStackDone()

void G4SubEvtRunManager::ThisWorkerProcessCommandsStackDone ( )
overridevirtual

Reimplemented from G4MTRunManager.

Definition at line 850 of file G4SubEvtRunManager.cc.

850{}

◆ ThisWorkerWaitForNextAction()

WorkerActionRequest G4SubEvtRunManager::ThisWorkerWaitForNextAction ( )
inlineoverridevirtual

Reimplemented from G4MTRunManager.

Definition at line 156 of file G4SubEvtRunManager.hh.

◆ TrajectoriesToBeMerged()

void G4SubEvtRunManager::TrajectoriesToBeMerged ( G4bool val = true)
inlineoverridevirtual

Reimplemented from G4RunManager.

Definition at line 210 of file G4SubEvtRunManager.hh.

211 { trajectoriesToBeMerged = val; }

◆ UpdateScoringForSubEvent()

void G4SubEvtRunManager::UpdateScoringForSubEvent ( const G4SubEvent * se,
const G4Event * evt )
overrideprotectedvirtual

Reimplemented from G4RunManager.

Definition at line 699 of file G4SubEvtRunManager.cc.

700{
701 auto masterEvt = se->GetEvent();
702
703 G4ScoringManager* ScM = G4ScoringManager::GetScoringManagerIfExist();
704 if (ScM == nullptr) return;
705 auto nPar = (G4int)ScM->GetNumberOfMesh();
706 if (nPar < 1) return;
707
708 if(verboseLevel>3) {
709 G4cout << "merging scores of sub-event belonging to event id #" << masterEvt->GetEventID()
710 << " --- sub-event has " << evt->GetHCofThisEvent()->GetCapacity()
711 << " hits collections" << G4endl;
712 }
713 G4HCofThisEvent* HCE = evt->GetHCofThisEvent();
714 if (HCE == nullptr) return;
715 auto nColl = (G4int)HCE->GetCapacity();
716 G4HCofThisEvent* masterHCE = masterEvt->GetHCofThisEvent();
717 if (masterHCE == nullptr || (G4int)masterHCE->GetCapacity() != nColl)
718 {
719 G4Exception("G4SubEvtRunManager::UpdateScoringForSubEvent()","SERM0002",
720 FatalException,"Number of hits colleactions for scrorers mismatch!! PANIC!!");
721 return;
722 }
723 for (G4int i = 0; i < nColl; ++i) {
724 auto* HC = dynamic_cast<G4THitsMap<G4double>*>(HCE->GetHC(i));
725 auto* masterHC = dynamic_cast<G4THitsMap<G4double>*>(masterHCE->GetHC(i));
726 if (HC != nullptr && masterHC != nullptr)
727 { *masterHC += *HC; }
728 else
729 {
730 G4Exception("G4SubEvtRunManager::UpdateScoringForSubEvent()","SERM0003",
731 FatalException,"HitsCollection is not type of G4THitsMap<G4double>. PANIC!!");
732 return;
733 }
734 }
735
736}
G4HCofThisEvent * GetHCofThisEvent() const
Definition G4Event.hh:164
std::size_t GetCapacity()
G4VHitsCollection * GetHC(G4int i)
std::size_t GetNumberOfMesh() const

Referenced by SubEventFinished().

◆ WaitForEndEventLoopWorkers()

void G4SubEvtRunManager::WaitForEndEventLoopWorkers ( )
overridevirtual

Reimplemented from G4MTRunManager.

Definition at line 819 of file G4SubEvtRunManager.cc.

820{
821 if (workTaskGroup != nullptr) {
822 workTaskGroup->join();
823 if (!fakeRun)
824 threadPool->execute_on_all_threads(
826 }
827}

Referenced by RunTermination().

◆ WaitForReadyWorkers()

void G4SubEvtRunManager::WaitForReadyWorkers ( )
inlineoverridevirtual

Reimplemented from G4MTRunManager.

Definition at line 152 of file G4SubEvtRunManager.hh.

152{}

Friends And Related Symbol Documentation

◆ G4RunManagerFactory

friend class G4RunManagerFactory
friend

Definition at line 51 of file G4SubEvtRunManager.hh.

Referenced by G4RunManagerFactory.

Member Data Documentation

◆ runInProgress

std::atomic<G4bool> G4SubEvtRunManager::runInProgress = false
protected

Definition at line 200 of file G4SubEvtRunManager.hh.

Referenced by GetSubEvent(), RunInitialization(), and RunTermination().


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