80#ifdef theParticleIterator
81# undef theParticleIterator
89 , userActionInitialization(0)
90 , userWorkerInitialization(0)
91 , userWorkerThreadInitialization(0)
93 , userPrimaryGeneratorAction(0)
95 , userStackingAction(0)
96 , userTrackingAction(0)
97 , userSteppingAction(0)
98 , geometryInitialized(false)
99 , physicsInitialized(false)
101 , initializedAtLeastOnce(false)
102 , geometryToBeOptimized(true)
109 , n_perviousEventsToBeStored(0)
110 , numberOfEventToBeProcessed(0)
111 , storeRandomNumberStatus(false)
112 , storeRandomNumberStatusToG4Event(0)
113 , rngStatusEventsFlag(false)
118 , numberOfEventProcessed(0)
121 , isScoreNtupleWriter(false)
122 , geometryDirectlyUpdated(false)
127 "G4RunManager constructed twice.");
140 std::ostringstream oss;
141 G4Random::saveFullState(oss);
150 , userActionInitialization(0)
151 , userWorkerInitialization(0)
152 , userWorkerThreadInitialization(0)
154 , userPrimaryGeneratorAction(0)
156 , userStackingAction(0)
157 , userTrackingAction(0)
158 , userSteppingAction(0)
159 , geometryInitialized(false)
160 , physicsInitialized(false)
162 , initializedAtLeastOnce(false)
163 , geometryToBeOptimized(true)
170 , n_perviousEventsToBeStored(0)
171 , numberOfEventToBeProcessed(0)
172 , storeRandomNumberStatus(false)
173 , storeRandomNumberStatusToG4Event(0)
174 , rngStatusEventsFlag(false)
179 , numberOfEventProcessed(0)
182 , isScoreNtupleWriter(false)
183 , geometryDirectlyUpdated(false)
186#ifndef G4MULTITHREADED
188 msg <<
"Geant4 code is compiled without multi-threading support "
189 "(-DG4MULTITHREADED "
191 msg <<
" This type of RunManager can only be used in mult-threaded "
200 "G4RunManager constructed twice.");
215 msgx <<
" This type of RunManager can only be used in mult-threaded "
217 G4Exception(
"G4RunManager::G4RunManager(G4bool)",
"Run0108",
231 std::ostringstream oss;
232 G4Random::saveFullState(oss);
247 G4cout <<
"G4 kernel has come to Quit state." <<
G4endl;
280 G4cout <<
"RunManager is deleting RunManagerKernel." <<
G4endl;
294 G4cout <<
"UserDetectorConstruction deleted." <<
G4endl;
308 G4cout <<
"UserActionInitialization deleted." <<
G4endl;
315 G4cout <<
"UserWorkerInitialization deleted." <<
G4endl;
322 G4cout <<
"UserWorkerThreadInitialization deleted." <<
G4endl;
356 G4cerr <<
"Illegal application state - BeamOn() ignored." <<
G4endl;
362 G4cerr <<
" Geant4 kernel should be initialized" <<
G4endl;
363 G4cerr <<
"before the first BeamOn(). - BeamOn ignored." <<
G4endl;
376 G4cout <<
"has been modified since last Run." <<
G4endl;
424 std::ostringstream oss;
425 G4Random::saveFullState(oss);
441#if defined(GEANT4_USE_TIMEMORY)
455 std::ostringstream os;
469 for(
G4int i_event = 0; i_event < n_event; i_event++)
534 <<
" events processed." <<
G4endl;
553 "G4VUserPrimaryGeneratorAction is not defined!");
562 std::ostringstream oss;
563 G4Random::saveFullState(oss);
573 std::ostringstream os;
591 G4Random::saveEngineStatus(fileN);
599 fPersM->
Store(anEvent);
607#if defined(GEANT4_USE_TIMEMORY)
608 masterRunProfiler.reset();
715 G4cerr <<
"Illegal application state - "
716 <<
"G4RunManager::Initialize() ignored." <<
G4endl;
737 "G4VUserDetectorConstruction is not defined!");
786 "G4VUserPhysicsList is not defined!");
808 G4cerr <<
"Run is not in progress. AbortRun() ignored." <<
G4endl;
824 G4cerr <<
"Event is not in progress. AbortEevnt() ignored." <<
G4endl;
840 G4cerr <<
"Warning from G4RunManager::rndmSaveThisRun():"
841 <<
" Random number status was not stored prior to this run."
842 <<
G4endl <<
"/random/setSavingFlag command must be issued. "
843 <<
"Command ignored." <<
G4endl;
849 std::ostringstream os;
850 os <<
"run" << runNumber <<
".rndm" <<
'\0';
854 G4String copCmd =
"/control/shell copy " + fileIn +
" " + fileOut;
856 G4String copCmd =
"/control/shell cp " + fileIn +
" " + fileOut;
860 {
G4cout << fileIn <<
" is copied to " << fileOut <<
G4endl; }
868 <<
"Warning from G4RunManager::rndmSaveThisEvent():"
869 <<
" there is no currentEvent available."
877 <<
"Warning from G4RunManager::rndmSaveThisEvent():"
878 <<
" Random number engine status is not available."
879 <<
G4endl <<
"/random/setSavingFlag command must be issued "
880 <<
"prior to the start of the run. Command ignored." <<
G4endl;
886 std::ostringstream os;
892 G4String copCmd =
"/control/shell copy " + fileIn +
" " + fileOut;
894 G4String copCmd =
"/control/shell cp " + fileIn +
" " + fileOut;
898 {
G4cout << fileIn <<
" is copied to " << fileOut <<
G4endl; }
904 if(fileN.
index(
"/") == std::string::npos)
910 fileNameWithDirectory = fileN;
913 G4Random::restoreEngineStatus(fileNameWithDirectory);
915 G4cout <<
"RandomNumberEngineStatus restored from file: "
916 << fileNameWithDirectory <<
G4endl;
917 G4Random::showEngineStatus();
957 for(
G4int iw = 0; iw < nPar; iw++)
963 if(mesh->
GetShape() != MeshShape::realWorldLogVol)
977 if(theParallelWorldProcess)
983 theParallelWorldProcess =
995 pmanager->
AddProcess(theParallelWorldProcess);
1036 for(
G4int i = 0; i < nColl; i++)
1098 "G4RunManager::SetUserInitialization()",
"Run3001",
FatalException,
1099 "Base-class G4RunManager cannot take G4UserWorkerInitialization. Use "
1107 "G4RunManager::SetUserThreadInitialization()",
"Run3001",
FatalException,
1108 "Base-class G4RunManager cannot take G4UserWorkerThreadInitialization. "
1109 "Use G4MTRunManager.");
1177 G4cout <<
"#### Assemblies, Volumes and Solids Stores are wiped out."
1189 std::vector<G4Region*>::iterator rItr;
1190 for(rItr = regionStore->begin(); rItr != regionStore->end(); rItr++)
1192 if((*rItr)->GetName() ==
"DefaultRegionForTheWorld")
1195 std::vector<G4LogicalVolume*>::iterator lvItr =
1196 (*rItr)->GetRootLogicalVolumeIterator();
1197 for(
size_t iRLV = 0; iRLV < (*rItr)->GetNumberOfRootVolumes(); iRLV++)
1199 (*rItr)->RemoveRootLogicalVolume(*lvItr,
false);
1204 G4cout <<
"#### Region <" << (*rItr)->GetName() <<
"> is cleared."
1235 std::vector<std::string> _args;
1236 for(
int i = 0; i < argc; ++i)
1237 _args.push_back(argv[i]);
1245#ifdef GEANT4_USE_TIMEMORY
1255#if !defined(GEANT4_USE_TIMEMORY)
1256# define TIMEMORY_WEAK_PREFIX
1257# define TIMEMORY_WEAK_POSTFIX
1274#ifdef GEANT4_USE_TIMEMORY
1278 static bool _once =
false;
1283 puts(
">>> G4RunProfilerInit <<<");
1295 RunProfilerConfig::GetFallbackQueryFunctor() = [](
const G4Run* _run) {
1299 EventProfilerConfig::GetFallbackQueryFunctor() = [](
const G4Event* _event) {
1303 TrackProfilerConfig::GetFallbackQueryFunctor() = [](
const G4Track* _track) {
1305 _track->GetDynamicParticle();
1308 StepProfilerConfig::GetFallbackQueryFunctor() = [](
const G4Step* _step) {
1313 UserProfilerConfig::GetFallbackQueryFunctor() =
1314 [](
const std::string& _user) {
1322 RunProfilerConfig::GetFallbackLabelFunctor() = [](
const G4Run* _run) {
1326 EventProfilerConfig::GetFallbackLabelFunctor() =
1327 [](
const G4Event* _event) -> std::string {
1334 TrackProfilerConfig::GetFallbackLabelFunctor() = [](
const G4Track* _track) {
1335 auto pdef = _track->GetDynamicParticle()->GetParticleDefinition();
1336 return TIMEMORY_JOIN(
'/',
"G4Track", pdef->GetParticleName());
1339 StepProfilerConfig::GetFallbackLabelFunctor() = [](
const G4Step* _step) {
1340 auto pdef = _step->GetTrack()->GetParticleDefinition();
1341 return TIMEMORY_JOIN(
'/',
"G4Step", pdef->GetParticleName());
1344 UserProfilerConfig::GetFallbackLabelFunctor() =
1345 [](
const std::string& _user) {
return _user; };
1347 using RunTool =
typename RunProfilerConfig::type;
1348 using EventTool =
typename EventProfilerConfig::type;
1349 using TrackTool =
typename TrackProfilerConfig::type;
1350 using StepTool =
typename StepProfilerConfig::type;
1351 using UserTool =
typename UserProfilerConfig::type;
1353 RunProfilerConfig::GetFallbackToolFunctor() =
1354 [](
const std::string& _label) {
return new RunTool{ _label }; };
1356 EventProfilerConfig::GetFallbackToolFunctor() =
1357 [](
const std::string& _label) {
return new EventTool{ _label }; };
1359 TrackProfilerConfig::GetFallbackToolFunctor() =
1360 [](
const std::string& _label) {
1361 return new TrackTool(_label, tim::scope::config(tim::scope::flat{}));
1364 StepProfilerConfig::GetFallbackToolFunctor() =
1365 [](
const std::string& _label) {
1366 return new StepTool(_label, tim::scope::config(tim::scope::flat{}));
1369 UserProfilerConfig::GetFallbackToolFunctor() =
1370 [](
const std::string& _label) {
return new UserTool(_label); };
1372 auto comps =
"wall_clock, cpu_clock, cpu_util, peak_rss";
1373 auto run_env_comps =
1374 tim::get_env<std::string>(
"G4PROFILE_RUN_COMPONENTS", comps);
1375 auto event_env_comps =
1376 tim::get_env<std::string>(
"G4PROFILE_EVENT_COMPONENTS", comps);
1377 auto track_env_comps =
1378 tim::get_env<std::string>(
"G4PROFILE_TRACK_COMPONENTS", comps);
1379 auto step_env_comps =
1380 tim::get_env<std::string>(
"G4PROFILE_STEP_COMPONENTS", comps);
1381 auto user_env_comps =
1382 tim::get_env<std::string>(
"G4PROFILE_USER_COMPONENTS", comps);
1384 tim::configure<G4RunProfiler>(run_env_comps);
1385 tim::configure<G4EventProfiler>(event_env_comps);
1386 tim::configure<G4TrackProfiler>(track_env_comps);
1387 tim::configure<G4StepProfiler>(step_env_comps);
1388 tim::configure<G4UserProfiler>(user_env_comps);
1395#ifdef GEANT4_USE_TIMEMORY
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
TIMEMORY_WEAK_PREFIX void G4RunProfilerInit(void) TIMEMORY_WEAK_POSTFIX
#define TIMEMORY_WEAK_PREFIX
void G4ProfilerInit(void)
#define TIMEMORY_WEAK_POSTFIX
#define TIMEMORY_JOIN(...)
#define theParticleIterator
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
static G4AssemblyStore * GetInstance()
void SetUserAction(G4UserEventAction *userAction)
void ProcessOneEvent(G4Event *anEvent)
G4int GetNumberOfGrips() const
void SetRandomNumberStatus(G4String &st)
G4HCofThisEvent * GetHCofThisEvent() const
static G4GeometryManager * GetInstance()
void OpenGeometry(G4VPhysicalVolume *vol=nullptr)
G4VHitsCollection * GetHC(G4int i)
static G4LogicalVolumeStore * GetInstance()
void SetVoxelHeader(G4SmartVoxelHeader *pVoxel)
const G4String & GetName() const
G4SmartVoxelHeader * GetVoxelHeader() const
static G4ParallelWorldProcessStore * GetInstance()
void SetLayeredMaterialFlag(G4bool flg=true)
void SetParallelWorld(G4String parallelWorldName)
G4bool IsAtRestRequired(G4ParticleDefinition *)
G4ProcessManager * GetProcessManager() const
G4PTblDicIterator * GetIterator() const
static G4ParticleTable * GetParticleTable()
G4UImessenger * CreateMessenger()
static G4PhysicalVolumeStore * GetInstance()
void SetProcessOrdering(G4VProcess *aProcess, G4ProcessVectorDoItIndex idDoIt, G4int ordDoIt=ordDefault)
void SetProcessOrderingToSecond(G4VProcess *aProcess, G4ProcessVectorDoItIndex idDoIt)
G4int AddProcess(G4VProcess *aProcess, G4int ordAtRestDoIt=ordInActive, G4int ordAlongSteptDoIt=ordInActive, G4int ordPostStepDoIt=ordInActive)
static G4ProcessTable * GetProcessTable()
static void Configure(const std::vector< std::string > &args)
static bool GetPerEvent()
static G4RegionStore * GetInstance()
void GeometryHasBeenModified()
void SetPhysics(G4VUserPhysicsList *uPhys)
void DefineWorldVolume(G4VPhysicalVolume *worldVol, G4bool topologyIsChanged=true)
void SetNumberOfParallelWorld(G4int i)
G4EventManager * GetEventManager() const
G4bool RunInitialization(G4bool fakeRun=false)
void DumpRegion(const G4String &rname) const
G4bool isScoreNtupleWriter
G4bool geometryInitialized
void CleanUpPreviousEvents()
void CleanUpUnnecessaryEvents(G4int keepNEvents)
G4int storeRandomNumberStatusToG4Event
G4UserWorkerInitialization * userWorkerInitialization
virtual void AbortRun(G4bool softAbort=false)
virtual void Initialize()
std::list< G4Event * > * previousEvents
G4UserWorkerThreadInitialization * userWorkerThreadInitialization
G4bool geometryDirectlyUpdated
G4int numberOfEventProcessed
virtual void RestoreRandomNumberStatus(const G4String &fileN)
virtual void BeamOn(G4int n_event, const char *macroFile=0, G4int n_select=-1)
G4UserEventAction * userEventAction
void ReinitializeGeometry(G4bool destroyFirst=false, G4bool prop=true)
virtual void DoEventLoop(G4int n_event, const char *macroFile=0, G4int n_select=-1)
virtual void rndmSaveThisEvent()
virtual void DeleteUserInitializations()
G4RunManagerKernel * kernel
virtual G4bool ConfirmBeamOnCondition()
static G4RunManager * GetRunManager()
virtual void AbortEvent()
virtual void rndmSaveThisRun()
virtual void InitializePhysics()
G4String randomNumberStatusForThisRun
static G4bool IfGeometryHasBeenDestroyed()
G4UserRunAction * userRunAction
virtual void DefineWorldVolume(G4VPhysicalVolume *worldVol, G4bool topologyIsChanged=true)
G4bool rngStatusEventsFlag
virtual void InitializeGeometry()
virtual void RunTermination()
G4bool physicsInitialized
G4VUserActionInitialization * userActionInitialization
void StackPreviousEvent(G4Event *anEvent)
static G4RUN_DLL G4bool fGeometryHasBeenDestroyed
void ReOptimize(G4LogicalVolume *)
G4VUserDetectorConstruction * userDetector
G4VUserPrimaryGeneratorAction * userPrimaryGeneratorAction
G4int numberOfEventToBeProcessed
G4String randomNumberStatusDir
virtual void TerminateEventLoop()
virtual void SetUserAction(G4UserRunAction *userAction)
G4String randomNumberStatusForThisEvent
void GeometryHasBeenModified(G4bool prop=true)
G4UserTrackingAction * userTrackingAction
G4int n_perviousEventsToBeStored
virtual void SetUserInitialization(G4VUserDetectorConstruction *userInit)
void ReOptimizeMotherOf(G4VPhysicalVolume *)
virtual void ProcessOneEvent(G4int i_event)
virtual void ConfigureProfilers(const std::vector< std::string > &args={})
G4bool storeRandomNumberStatus
virtual G4Event * GenerateEvent(G4int i_event)
G4bool initializedAtLeastOnce
G4EventManager * eventManager
virtual void StoreRNGStatus(const G4String &filenamePrefix)
virtual void TerminateOneEvent()
virtual void RunInitialization()
void DumpRegion(const G4String &rname) const
G4ProfilerConfig< G4ProfileType::Run > ProfilerConfig
G4VUserPhysicsList * physicsList
virtual void AnalyzeEvent(G4Event *anEvent)
G4UserStackingAction * userStackingAction
virtual void ConstructScoringWorlds()
virtual void InitializeEventLoop(G4int n_event, const char *macroFile=0, G4int n_select=-1)
G4UserSteppingAction * userSteppingAction
void SetHCtable(G4HCtable *HCtbl)
void StoreEvent(G4Event *evt)
virtual void RecordEvent(const G4Event *)
void SetNumberOfEventToBeProcessed(G4int n_ev)
void SetDCtable(G4DCtable *DCtbl)
void SetRandomNumberStatus(G4String &st)
G4HCofThisEvent * PrepareNewEvent()
static G4SDManager * GetSDMpointerIfExist()
G4HCtable * GetHCtable() const
G4VScoringMesh * GetMesh(G4int i) const
void Accumulate(G4VHitsCollection *map)
size_t GetNumberOfMesh() const
G4String GetWorldName(G4int i) const
static G4ScoringManager * GetScoringManagerIfExist()
G4long GetMemoryUse() const
G4double GetTotalTime() const
G4long GetNumberPointers() const
G4long GetNumberHeads() const
G4double GetSysTime() const
G4long GetNumberNodes() const
static G4SolidStore * GetInstance()
const G4ApplicationState & GetCurrentState() const
static G4StateManager * GetStateManager()
G4bool SetNewState(const G4ApplicationState &requestedState)
str_size index(const char *, G4int pos=0) const
G4double GetSystemElapsed() const
G4double GetUserElapsed() const
G4VPhysicalVolume * GetParallelWorld(const G4String &worldName)
static G4TransportationManager * GetTransportationManager()
G4VPhysicalVolume * IsWorldExisting(const G4String &worldName)
void ClearParallelWorlds()
G4int ApplyCommand(const char *aCommand)
static G4UImanager * GetUIpointer()
virtual void EndOfRunAction(const G4Run *aRun)
virtual void BeginOfRunAction(const G4Run *aRun)
virtual G4Run * GenerateRun()
static G4VPersistencyManager * GetPersistencyManager()
virtual G4bool Store(const G4Event *anEvent)=0
G4LogicalVolume * GetMotherLogical() const
void SetName(const G4String &pName)
virtual void Fill(G4HCofThisEvent *hce, G4int eventNumber)=0
virtual G4bool Book(G4HCofThisEvent *hce)=0
static G4VScoreNtupleWriter * Instance()
virtual void OpenFile()=0
MeshShape GetShape() const
void GeometryHasBeenDestroyed()
G4ParallelWorldProcess * GetParallelWorldProcess() const
void SetParallelWorldProcess(G4ParallelWorldProcess *proc)
void Construct(G4VPhysicalVolume *fWorldPhys)
virtual void Build() const =0
virtual G4VPhysicalVolume * Construct()=0
virtual void ConstructSDandField()
G4int ConstructParallelGeometries()
void ConstructParallelSD()
virtual void GeneratePrimaries(G4Event *anEvent)=0
static G4VVisManager * GetConcreteInstance()
virtual void GeometryHasChanged()=0
void G4ConsumeParameters(_Args &&...)