96#ifdef theParticleIterator
97# undef theParticleIterator
122 "G4RunManager constructed twice.");
134 std::ostringstream oss;
135 G4Random::saveFullState(oss);
145#ifndef G4MULTITHREADED
147 msg <<
"Geant4 code is compiled without multi-threading support "
148 "(-DG4MULTITHREADED is set to off).";
149 msg <<
" This type of RunManager can only be used in mult-threaded "
151 G4Exception(
"G4RunManager::G4RunManager(G4bool)",
"Run0107",
155 if(fRunManager !=
nullptr)
158 "G4RunManager constructed twice.");
173 msgx <<
"This type of RunManager can only be used in multi-threaded "
175 G4Exception(
"G4RunManager::G4RunManager(G4bool)",
"Run0108",
189 std::ostringstream oss;
190 G4Random::saveFullState(oss);
206 G4cout <<
"G4 kernel has come to Quit state." <<
G4endl;
233 G4cout <<
"RunManager is deleting RunManagerKernel." <<
G4endl;
237 fRunManager =
nullptr;
249 G4cout <<
"UserDetectorConstruction deleted." <<
G4endl;
259 G4cout <<
"UserActionInitialization deleted." <<
G4endl;
264 G4cout <<
"UserWorkerInitialization deleted." <<
G4endl;
269 G4cout <<
"UserWorkerThreadInitialization deleted." <<
G4endl;
304 G4cerr <<
"Illegal application state - BeamOn() ignored." <<
G4endl;
310 G4cerr <<
" Geant4 kernel should be initialized" <<
G4endl;
311 G4cerr <<
"before the first BeamOn(). - BeamOn ignored." <<
G4endl;
324 G4cout <<
"has been modified since last Run." <<
G4endl;
372 std::ostringstream oss;
373 G4Random::saveFullState(oss);
389#if defined(GEANT4_USE_TIMEMORY)
403 std::ostringstream os;
418 for(
G4int i_event = 0; i_event < n_event; ++i_event)
487 <<
" events processed." <<
G4endl;
505 "G4VUserPrimaryGeneratorAction is not defined!");
514 std::ostringstream oss;
515 G4Random::saveFullState(oss);
525 std::ostringstream os;
544 G4Random::saveEngineStatus(fileN);
552 if(fPersM !=
nullptr)
553 fPersM->
Store(anEvent);
562#if defined(GEANT4_USE_TIMEMORY)
563 masterRunProfiler.reset();
574 if(fPersM !=
nullptr)
603 if(evt !=
nullptr && !(evt->
ToBeKept()))
673 G4cerr <<
"Illegal application state - "
674 <<
"G4RunManager::Initialize() ignored." <<
G4endl;
696 "G4VUserDetectorConstruction is not defined!");
721 if(pVVisManager !=
nullptr)
746 "G4VUserPhysicsList is not defined!");
769 G4cerr <<
"Run is not in progress. AbortRun() ignored." <<
G4endl;
786 G4cerr <<
"Event is not in progress. AbortEevnt() ignored." <<
G4endl;
805 G4cerr <<
"Warning from G4RunManager::rndmSaveThisRun():"
806 <<
" Random number status was not stored prior to this run."
807 <<
G4endl <<
"/random/setSavingFlag command must be issued. "
808 <<
"Command ignored." <<
G4endl;
814 std::ostringstream os;
815 os <<
"run" << runNumber <<
".rndm" <<
'\0';
819 G4String copCmd =
"/control/shell copy " + fileIn +
" " + fileOut;
821 G4String copCmd =
"/control/shell cp " + fileIn +
" " + fileOut;
826 G4cout << fileIn <<
" is copied to " << fileOut <<
G4endl;
835 G4cerr <<
"Warning from G4RunManager::rndmSaveThisEvent():"
836 <<
" there is no currentEvent available." <<
G4endl
837 <<
"Command ignored." <<
G4endl;
843 G4cerr <<
"Warning from G4RunManager::rndmSaveThisEvent():"
844 <<
" Random number engine status is not available." <<
G4endl
845 <<
"/random/setSavingFlag command must be issued "
846 <<
"prior to the start of the run. Command ignored." <<
G4endl;
852 std::ostringstream os;
858 G4String copCmd =
"/control/shell copy " + fileIn +
" " + fileOut;
860 G4String copCmd =
"/control/shell cp " + fileIn +
" " + fileOut;
865 G4cout << fileIn <<
" is copied to " << fileOut <<
G4endl;
873 if(fileN.find(
"/") == std::string::npos)
879 fileNameWithDirectory = fileN;
882 G4Random::restoreEngineStatus(fileNameWithDirectory);
884 G4cout <<
"RandomNumberEngineStatus restored from file: "
885 << fileNameWithDirectory <<
G4endl;
886 G4Random::showEngineStatus();
915 for(
G4int iw = 0; iw < nPar; ++iw)
921 if(mesh->
GetShape() != MeshShape::realWorldLogVol)
925 if(pWorld ==
nullptr)
933 if(theParallelWorldProcess !=
nullptr)
939 theParallelWorldProcess =
949 if(pmanager !=
nullptr)
951 pmanager->
AddProcess(theParallelWorldProcess);
992 for(
G4int i = 0; i < nColl; ++i)
1004 if(pMotherL !=
nullptr)
1054 "G4RunManager::SetUserInitialization()",
"Run3001",
FatalException,
1055 "Base-class G4RunManager cannot take G4UserWorkerInitialization. Use "
1064 "G4RunManager::SetUserThreadInitialization()",
"Run3001",
FatalException,
1065 "Base-class G4RunManager cannot take G4UserWorkerThreadInitialization. "
1066 "Use G4MTRunManager.");
1136 G4cout <<
"#### Assemblies, Volumes and Solids Stores are wiped out."
1148 for(
auto rItr = regionStore->cbegin(); rItr != regionStore->cend(); ++rItr)
1150 if((*rItr)->GetName() ==
"DefaultRegionForTheWorld")
1153 auto lvItr = (*rItr)->GetRootLogicalVolumeIterator();
1154 for(std::size_t iRLV=0; iRLV<(*rItr)->GetNumberOfRootVolumes(); ++iRLV)
1156 (*rItr)->RemoveRootLogicalVolume(*lvItr,
false);
1161 G4cout <<
"#### Region <" << (*rItr)->GetName() <<
"> is cleared."
1182 if(pVVisManager !=
nullptr)
1191 std::vector<std::string> _args;
1192 for(
G4int i = 0; i < argc; ++i)
1193 _args.push_back(argv[i]);
1200#ifdef GEANT4_USE_TIMEMORY
1210#if !defined(GEANT4_USE_TIMEMORY)
1211# define TIMEMORY_WEAK_PREFIX
1212# define TIMEMORY_WEAK_POSTFIX
1229#ifdef GEANT4_USE_TIMEMORY
1233 static G4bool _once =
false;
1238 puts(
">>> G4RunProfilerInit <<<");
1250 RunProfilerConfig::GetFallbackQueryFunctor() = [](
const G4Run* _run) {
1254 EventProfilerConfig::GetFallbackQueryFunctor() = [](
const G4Event* _event) {
1258 TrackProfilerConfig::GetFallbackQueryFunctor() = [](
const G4Track* _track) {
1260 _track->GetDynamicParticle();
1263 StepProfilerConfig::GetFallbackQueryFunctor() = [](
const G4Step* _step) {
1268 UserProfilerConfig::GetFallbackQueryFunctor() =
1269 [](
const std::string& _user) {
1277 RunProfilerConfig::GetFallbackLabelFunctor() = [](
const G4Run* _run) {
1281 EventProfilerConfig::GetFallbackLabelFunctor() =
1282 [](
const G4Event* _event) -> std::string {
1289 TrackProfilerConfig::GetFallbackLabelFunctor() = [](
const G4Track* _track) {
1290 auto pdef = _track->GetDynamicParticle()->GetParticleDefinition();
1291 return TIMEMORY_JOIN(
'/',
"G4Track", pdef->GetParticleName());
1294 StepProfilerConfig::GetFallbackLabelFunctor() = [](
const G4Step* _step) {
1295 auto pdef = _step->GetTrack()->GetParticleDefinition();
1296 return TIMEMORY_JOIN(
'/',
"G4Step", pdef->GetParticleName());
1299 UserProfilerConfig::GetFallbackLabelFunctor() =
1300 [](
const std::string& _user) {
return _user; };
1302 using RunTool =
typename RunProfilerConfig::type;
1303 using EventTool =
typename EventProfilerConfig::type;
1304 using TrackTool =
typename TrackProfilerConfig::type;
1305 using StepTool =
typename StepProfilerConfig::type;
1306 using UserTool =
typename UserProfilerConfig::type;
1308 RunProfilerConfig::GetFallbackToolFunctor() =
1309 [](
const std::string& _label) {
return new RunTool{ _label }; };
1311 EventProfilerConfig::GetFallbackToolFunctor() =
1312 [](
const std::string& _label) {
return new EventTool{ _label }; };
1314 TrackProfilerConfig::GetFallbackToolFunctor() =
1315 [](
const std::string& _label) {
1316 return new TrackTool(_label, tim::scope::config(tim::scope::flat{}));
1319 StepProfilerConfig::GetFallbackToolFunctor() =
1320 [](
const std::string& _label) {
1321 return new StepTool(_label, tim::scope::config(tim::scope::flat{}));
1324 UserProfilerConfig::GetFallbackToolFunctor() =
1325 [](
const std::string& _label) {
return new UserTool(_label); };
1327 auto comps =
"wall_clock, cpu_clock, cpu_util, peak_rss";
1328 auto run_env_comps =
1329 tim::get_env<std::string>(
"G4PROFILE_RUN_COMPONENTS", comps);
1330 auto event_env_comps =
1331 tim::get_env<std::string>(
"G4PROFILE_EVENT_COMPONENTS", comps);
1332 auto track_env_comps =
1333 tim::get_env<std::string>(
"G4PROFILE_TRACK_COMPONENTS", comps);
1334 auto step_env_comps =
1335 tim::get_env<std::string>(
"G4PROFILE_STEP_COMPONENTS", comps);
1336 auto user_env_comps =
1337 tim::get_env<std::string>(
"G4PROFILE_USER_COMPONENTS", comps);
1339 tim::configure<G4RunProfiler>(run_env_comps);
1340 tim::configure<G4EventProfiler>(event_env_comps);
1341 tim::configure<G4TrackProfiler>(track_env_comps);
1342 tim::configure<G4StepProfiler>(step_env_comps);
1343 tim::configure<G4UserProfiler>(user_env_comps);
1350#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 InitializeEventLoop(G4int n_event, const char *macroFile=nullptr, G4int n_select=-1)
G4UserEventAction * userEventAction
void ReinitializeGeometry(G4bool destroyFirst=false, G4bool prop=true)
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
virtual void BeamOn(G4int n_event, const char *macroFile=nullptr, G4int n_select=-1)
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 DoEventLoop(G4int n_event, const char *macroFile=nullptr, G4int n_select=-1)
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()
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)
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)
virtual 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 &&...)