71G4Mutex registerSubEvtWorkerMutex;
158 ed <<
"G4RunManager::SetNumberOfEventsToBeStored() is not supported in sub-event parallel mode.\n"
159 <<
"User may still keep events bu G4EventManager::KeepTheCurrentEvent()";
178 if (pVisManager) pVisManager->EventReadyForVis(anEvent);
208 ed <<
"G4RunManager::SetNumberOfEventsToBeStored() is not supported in sub-event parallel mode.\n"
209 <<
"User may still keep events bu G4EventManager::KeepTheCurrentEvent()";
216 auto eventVector =
currentRun->GetEventVector();
217 if(eventVector==
nullptr || eventVector->empty())
return;
218 auto eItr = eventVector->cbegin();
219 while(eItr != eventVector->cend())
231 if (pVisManager) pVisManager->EventReadyForVis(ev);
241 eItr = eventVector->erase(eItr);
257 eItr = eventVector->erase(eItr);
262 eItr = eventVector->erase(eItr);
276 static G4bool initializeStarted =
false;
281 if (initializeStarted) {
283 if (!initCmdStack.empty()) {
284 threadPool->execute_on_all_threads([cmds = std::move(initCmdStack)]() {
285 for (
auto& itr : cmds)
292 std::stringstream msg;
293 msg <<
"--> G4SubEvtRunManager::CreateAndStartWorkers() --> "
294 <<
"Initializing workers...";
296 std::stringstream ss;
298 ss << std::setw((
G4int)msg.str().length()) <<
"";
299 G4cout <<
"\n" << ss.str() <<
"\n" << msg.str() <<
"\n" << ss.str() <<
"\n" <<
G4endl;
304 initializeStarted =
true;
308 if (!initCmdStack.empty()) {
309 threadPool->execute_on_all_threads([cmds = std::move(initCmdStack)]() {
310 for (
auto& itr : cmds)
320 std::stringstream msg;
321 msg <<
"--> G4SubEvtRunManager::CreateAndStartWorkers() --> "
323 <<
" events/task...";
325 std::stringstream ss;
327 ss << std::setw((
G4int)msg.str().length()) <<
"";
328 G4cout <<
"\n" << ss.str() <<
"\n" << msg.str() <<
"\n" << ss.str() <<
"\n" <<
G4endl;
396 if (macroFile !=
nullptr) {
418 if (!_overload && !_functor) {
427 <<
"> of seedOncePerCommunication is invalid. It is reset "
475 auto eventVector =
currentRun->GetEventVector();
476 if(eventVector!=
nullptr)
482 for(
auto ev:*eventVector)
484 if(ev->GetNumberOfRemainingSubEvents()>0 || ev->GetNumberOfGrips()>0 )
491 G4cout <<
"G4SubEvtRunManager::RunTermination - " << notReady
492 <<
" events are still incomplete. Waiting for them." <<
G4endl;
513 for (
G4int iWorld = 0; iWorld < nWorlds; ++iWorld) {
543 auto eventVector =
currentRun->GetEventVector();
547 for(
auto& ev : *eventVector)
553 auto se =
const_cast<G4Event*
>(ev)->PopSubEvent(ty);
592 s1 = helper->
GetSeed(idx_rndm);
593 s2 = helper->
GetSeed(idx_rndm + 1);
661 if(masterEvt==
nullptr) {
662 G4Exception(
"G4SubEvtRunManager::SubEventFinished()",
"SERM0001",
682 auto* masterTrajContainer = masterEvt->GetTrajectoryContainer();
683 if(masterTrajContainer==
nullptr)
686 masterEvt->SetTrajectoryContainer(masterTrajContainer);
688 for(
auto& traj : *trajVector)
691 auto* cloned = traj->CloneForMaster();
692 masterTrajContainer->push_back(cloned);
704 if (ScM ==
nullptr)
return;
706 if (nPar < 1)
return;
709 G4cout <<
"merging scores of sub-event belonging to event id #" << masterEvt->GetEventID()
711 <<
" hits collections" <<
G4endl;
714 if (HCE ==
nullptr)
return;
719 G4Exception(
"G4SubEvtRunManager::UpdateScoringForSubEvent()",
"SERM0002",
720 FatalException,
"Number of hits colleactions for scrorers mismatch!! PANIC!!");
723 for (
G4int i = 0; i < nColl; ++i) {
726 if (HC !=
nullptr && masterHC !=
nullptr)
727 { *masterHC += *HC; }
730 G4Exception(
"G4SubEvtRunManager::UpdateScoringForSubEvent()",
"SERM0003",
731 FatalException,
"HitsCollection is not type of G4THitsMap<G4double>. PANIC!!");
755 auto eventVector =
currentRun->GetEventVector();
756 auto eItr = std::find(eventVector->cbegin(),eventVector->cend(),evt);
757 if(eItr != eventVector->cend()) eventVector->erase(eItr);
765 auto eventVector =
currentRun->GetEventVector();
766 if(eventVector==
nullptr || eventVector->empty())
return;
767 auto eItr = eventVector->cbegin();
768 while(eItr != eventVector->cend())
776 eItr = eventVector->erase(eItr);
803 MTkernel->BroadcastAbortRun(softAbort);
806 G4cerr <<
"Run is not in progress. AbortRun() ignored." <<
G4endl;
835 auto process_commands_stack = []() {
837 if (mrm !=
nullptr) {
839 for (
const auto& itr : cmds)
857 fSubEvtTypeMap[ty] = maxEnt;
859 eventManager->GetStackManager()->RegisterSubEventType(ty,maxEnt);
865 fWorkerMap[wrm] = typ;
868G4bool G4SubEvtRunManager::CheckSubEvtTypes()
870 for(
auto& seT : fSubEvtTypeMap)
872 G4int ty = seT.first;
874 for(
auto& worker : fWorkerMap)
876 if(worker.second==ty)
877 { seTyp = ty;
break; }
882 ed <<
"There is no worker with sub-event type " << ty
883 <<
" registered. There must be at least one worker who is responsible.";
884 G4Exception(
"G4SubEvtRunManager::CheckSubEvtTypes",
927 if (userAction !=
nullptr) userAction->
SetMaster(
true);
G4TemplateAutoLock< G4Mutex > G4AutoLock
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
G4TemplateRNGHelper< G4long > G4RNGHelper
#define G4THREADSLEEP(tick)
PTL::VUserTaskQueue G4VUserTaskQueue
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
G4int GetNumberOfGrips() const
G4TrajectoryContainer * GetTrajectoryContainer() const
G4HCofThisEvent * GetHCofThisEvent() const
G4bool IsEventCompleted() const
void ScoresRecorded() const
void EventCompleted() const
G4int GetNumberOfRemainingSubEvents() const
std::size_t GetCapacity()
G4VHitsCollection * GetHC(G4int i)
static G4int SeedOncePerCommunication()
static void SetSeedOncePerCommunication(G4int val)
G4int numberOfEventToBeProcessed
virtual void ThisWorkerProcessCommandsStackDone()
static void addWorld(G4int counter, G4VPhysicalVolume *w)
virtual void PrepareCommandsStack()
static G4MTRUN_DLL G4ScoringManager * masterScM
static G4MTRunManager * GetMasterRunManager()
static masterWorlds_t & GetMasterWorlds()
std::vector< G4String > GetCommandStack()
G4UserWorkerInitialization * userWorkerInitialization
virtual void Initialize()
virtual void ReportEventDeletion(const G4Event *evt)
std::list< G4Event * > * previousEvents
void SetRunIDCounter(G4int i)
G4UserWorkerThreadInitialization * userWorkerThreadInitialization
G4int numberOfEventProcessed
G4UserEventAction * userEventAction
virtual void BeamOn(G4int n_event, const char *macroFile=nullptr, G4int n_select=-1)
virtual void RunTermination()
G4VUserActionInitialization * userActionInitialization
void UpdateScoring(const G4Event *evt=nullptr)
virtual void TerminateEventLoop()
virtual void SetUserAction(G4UserRunAction *userAction)
G4int n_perviousEventsToBeStored
virtual void SetUserInitialization(G4VUserDetectorConstruction *userInit)
virtual G4Event * GenerateEvent(G4int i_event)
G4EventManager * eventManager
virtual void RunInitialization()
virtual void ConstructScoringWorlds()
std::size_t GetNumberOfMesh() const
static G4ScoringManager * GetScoringManagerIfExist()
const G4ApplicationState & GetCurrentState() const
static G4StateManager * GetStateManager()
G4Event * GetEvent() const
void RunTermination() override
void RegisterSubEvtWorker(G4WorkerSubEvtRunManager *, G4int)
void ConstructScoringWorlds() override
void AbortEvent() override
void CleanUpUnnecessaryEvents(G4int keepNEvents) override
void CleanUpPreviousEvents() override
void AbortRun(G4bool softAbort=false) override
G4SubEvtRunManager(G4bool useTBB=G4GetEnv< G4bool >("G4USE_TBB", false))
void ComputeNumberOfTasks() override
void ProcessOneEvent(G4int i_event) override
void UpdateScoringForSubEvent(const G4SubEvent *se, const G4Event *evt) override
void RunInitialization() override
void StackPreviousEvent(G4Event *anEvent) override
std::atomic< G4bool > runInProgress
void AddEventTask(G4int) override
~G4SubEvtRunManager() override
void TerminateOneEvent() override
void SetUserInitialization(G4VUserPhysicsList *userPL) override
void MergeTrajectories(const G4SubEvent *se, const G4Event *evt) override
void InitializeEventLoop(G4int n_event, const char *macroFile=nullptr, G4int n_select=-1) override
void SubEventFinished(const G4SubEvent *se, const G4Event *evt) override
void WaitForEndEventLoopWorkers() override
void SetUpSeedsForSubEvent(G4long &s1, G4long &s2, G4long &s3)
void MergeScores(const G4ScoringManager *localScoringManager) override
void TerminateWorkers() override
void Initialize() override
void CreateAndStartWorkers() override
void ThisWorkerProcessCommandsStackDone() override
void RequestWorkersProcessCommandsStack() override
void RegisterSubEventType(G4int ty, G4int maxEnt) override
void RefillSeeds() override
G4bool InitializeSeeds(G4int) override
const G4SubEvent * GetSubEvent(G4int ty, G4bool ¬Ready, G4long &s1, G4long &s2, G4long &s3, G4bool reseedRequired=true) override
void SetUserAction(G4UserRunAction *userAction) override
static void ExecuteWorkerTask()
static void InitializeWorker()
static void TerminateWorker()
static void TerminateWorkerRunEventLoop()
static void ExecuteWorkerInit()
static std::vector< G4String > & InitCommandStack()
void InitializeThreadPool() override
InitializeSeedsCallback initSeedsCallback
RunTaskGroup * workTaskGroup
CLHEP::HepRandomEngine * masterRNGEngine
G4int numberOfEventsPerTask
G4TaskRunManagerKernel * MTkernel
G4ThreadPool *& threadPool
G4TaskRunManager(G4bool useTBB=G4GetEnv< G4bool >("G4USE_TBB", false))
static G4TemplateRNGHelper< G4long > * GetInstance()
virtual const T GetSeed(const G4int &sdId)
void Fill(G4double *dbl, G4int nev, G4int nev_tot, G4int nrpe)
void Refill(G4double *dbl, G4int nev)
TrajectoryVector * GetVector() const
static G4TransportationManager * GetTransportationManager()
std::vector< G4VPhysicalVolume * >::iterator GetWorldsIterator()
G4int ApplyCommand(const char *aCommand)
void SetAlias(const char *aliasLine)
static G4UImanager * GetUIpointer()
virtual void SetMaster(G4bool val=true)
virtual void InitializeWorker()
static G4VVisManager * GetConcreteInstance()
static G4WorkerTaskRunManager * GetWorkerRunManager()