91#ifdef theParticleIterator
92# undef theParticleIterator
114 if (fRunManager !=
nullptr) {
116 "G4RunManager constructed twice.");
128 std::ostringstream oss;
129 G4Random::saveFullState(oss);
139#ifndef G4MULTITHREADED
141 msg <<
"Geant4 code is compiled without multi-threading support "
142 "(-DG4MULTITHREADED is set to off).";
143 msg <<
" This type of RunManager can only be used in mult-threaded "
148 if (fRunManager !=
nullptr) {
150 "G4RunManager constructed twice.");
164 msgx <<
"This type of RunManager can only be used in multi-threaded "
179 std::ostringstream oss;
180 G4Random::saveFullState(oss);
222 fRunManager =
nullptr;
274 G4cerr <<
"Illegal application state - BeamOn() ignored." <<
G4endl;
279 G4cerr <<
" Geant4 kernel should be initialized" <<
G4endl;
280 G4cerr <<
"before the first BeamOn(). - BeamOn ignored." <<
G4endl;
289 G4cout <<
"has been modified since last Run." <<
G4endl;
320 if (fSDM !=
nullptr) {
330 std::ostringstream oss;
331 G4Random::saveFullState(oss);
344#if defined(GEANT4_USE_TIMEMORY)
355 std::ostringstream os;
369 for (
G4int i_event = 0; i_event < n_event; ++i_event) {
388 if (macroFile !=
nullptr) {
441 "G4VUserPrimaryGeneratorAction is not defined!");
445 auto anEvent =
new G4Event(i_event);
448 std::ostringstream oss;
449 G4Random::saveFullState(oss);
457 std::ostringstream os;
465 G4cout <<
"--> Event " << anEvent->GetEventID() <<
" starts." <<
G4endl;
475 G4Random::saveEngineStatus(fileN);
482 if (fPersM !=
nullptr) fPersM->
Store(anEvent);
490#if defined(GEANT4_USE_TIMEMORY)
491 masterRunProfiler.reset();
525 if (evt !=
nullptr && !(evt->
ToBeKept()))
delete evt;
544 if (evt !=
nullptr) {
566 if (!(anEvent->
ToBeKept()))
delete anEvent;
581 G4cerr <<
"Illegal application state - "
582 <<
"G4RunManager::Initialize() ignored." <<
G4endl;
600 "G4VUserDetectorConstruction is not defined!");
642 "G4VUserPhysicsList is not defined!");
661 G4cerr <<
"Run is not in progress. AbortRun() ignored." <<
G4endl;
675 G4cerr <<
"Event is not in progress. AbortEevnt() ignored." <<
G4endl;
691 G4cerr <<
"Warning from G4RunManager::rndmSaveThisRun():"
692 <<
" Random number status was not stored prior to this run." <<
G4endl
693 <<
"/random/setSavingFlag command must be issued. "
694 <<
"Command ignored." <<
G4endl;
700 std::ostringstream os;
701 os <<
"run" << runNumber <<
".rndm" <<
'\0';
706 G4cout << fileIn <<
" is copied to " << fileOut <<
G4endl;
714 G4cerr <<
"Warning from G4RunManager::rndmSaveThisEvent():"
715 <<
" there is no currentEvent available." <<
G4endl <<
"Command ignored." <<
G4endl;
720 G4cerr <<
"Warning from G4RunManager::rndmSaveThisEvent():"
721 <<
" Random number engine status is not available." <<
G4endl
722 <<
"/random/setSavingFlag command must be issued "
723 <<
"prior to the start of the run. Command ignored." <<
G4endl;
729 std::ostringstream os;
735 G4cout << fileIn <<
" is copied to " << fileOut <<
G4endl;
743 if (fileN.find(
'/') == std::string::npos) {
747 fileNameWithDirectory = fileN;
750 G4Random::restoreEngineStatus(fileNameWithDirectory);
752 G4cout <<
"RandomNumberEngineStatus restored from file: " << fileNameWithDirectory <<
G4endl;
753 G4Random::showEngineStatus();
774 if (ScM ==
nullptr)
return;
777 if (nPar < 1)
return;
780 for (
G4int iw = 0; iw < nPar; ++iw) {
784 if (mesh->
GetShape() != MeshShape::realWorldLogVol) {
787 if (pWorld ==
nullptr) {
793 if (theParallelWorldProcess !=
nullptr) {
805 if (pmanager !=
nullptr) {
806 pmanager->
AddProcess(theParallelWorldProcess);
832 if (ScM ==
nullptr)
return;
834 if (nPar < 1)
return;
837 if (HCE ==
nullptr)
return;
839 for (
G4int i = 0; i < nColl; ++i) {
849 if (pMotherL !=
nullptr)
ReOptimize(pMotherL);
892 "Base-class G4RunManager cannot take G4UserWorkerInitialization. Use "
900 "Base-class G4RunManager cannot take G4UserWorkerThreadInitialization. "
901 "Use G4MTRunManager.");
967 G4cout <<
"#### Assemblies, Volumes and Solids Stores are wiped out." <<
G4endl;
978 for (
const auto& rItr : *regionStore) {
979 if (rItr->GetName() ==
"DefaultRegionForTheWorld")
continue;
980 auto lvItr = rItr->GetRootLogicalVolumeIterator();
981 for (std::size_t iRLV = 0; iRLV < rItr->GetNumberOfRootVolumes(); ++iRLV) {
982 rItr->RemoveRootLogicalVolume(*lvItr,
false);
986 G4cout <<
"#### Region <" << rItr->GetName() <<
"> is cleared." <<
G4endl;
1011 std::vector<std::string> _args;
1012 for (
G4int i = 0; i < argc; ++i)
1013 _args.emplace_back(argv[i]);
1020#ifdef GEANT4_USE_TIMEMORY
1030#if !defined(GEANT4_USE_TIMEMORY)
1031# define TIMEMORY_WEAK_PREFIX
1032# define TIMEMORY_WEAK_POSTFIX
1049#ifdef GEANT4_USE_TIMEMORY
1053 static G4bool _once =
false;
1057 puts(
">>> G4RunProfilerInit <<<");
1069 RunProfilerConfig::GetFallbackQueryFunctor() = [](
const G4Run* _run) {
1073 EventProfilerConfig::GetFallbackQueryFunctor() = [](
const G4Event* _event) {
1077 TrackProfilerConfig::GetFallbackQueryFunctor() = [](
const G4Track* _track) {
1081 StepProfilerConfig::GetFallbackQueryFunctor() = [](
const G4Step* _step) {
1085 UserProfilerConfig::GetFallbackQueryFunctor() = [](
const std::string& _user) {
1093 RunProfilerConfig::GetFallbackLabelFunctor() = [](
const G4Run* _run) {
1097 EventProfilerConfig::GetFallbackLabelFunctor() = [](
const G4Event* _event) -> std::string {
1104 TrackProfilerConfig::GetFallbackLabelFunctor() = [](
const G4Track* _track) {
1105 auto pdef = _track->GetDynamicParticle()->GetParticleDefinition();
1106 return TIMEMORY_JOIN(
'/',
"G4Track", pdef->GetParticleName());
1109 StepProfilerConfig::GetFallbackLabelFunctor() = [](
const G4Step* _step) {
1110 auto pdef = _step->GetTrack()->GetParticleDefinition();
1111 return TIMEMORY_JOIN(
'/',
"G4Step", pdef->GetParticleName());
1114 UserProfilerConfig::GetFallbackLabelFunctor() = [](
const std::string& _user) {
1118 using RunTool =
typename RunProfilerConfig::type;
1119 using EventTool =
typename EventProfilerConfig::type;
1120 using TrackTool =
typename TrackProfilerConfig::type;
1121 using StepTool =
typename StepProfilerConfig::type;
1122 using UserTool =
typename UserProfilerConfig::type;
1124 RunProfilerConfig::GetFallbackToolFunctor() = [](
const std::string& _label) {
1125 return new RunTool{_label};
1128 EventProfilerConfig::GetFallbackToolFunctor() = [](
const std::string& _label) {
1129 return new EventTool{_label};
1132 TrackProfilerConfig::GetFallbackToolFunctor() = [](
const std::string& _label) {
1133 return new TrackTool(_label, tim::scope::config(tim::scope::flat{}));
1136 StepProfilerConfig::GetFallbackToolFunctor() = [](
const std::string& _label) {
1137 return new StepTool(_label, tim::scope::config(tim::scope::flat{}));
1140 UserProfilerConfig::GetFallbackToolFunctor() = [](
const std::string& _label) {
1141 return new UserTool(_label);
1144 auto comps =
"wall_clock, cpu_clock, cpu_util, peak_rss";
1145 auto run_env_comps = tim::get_env<std::string>(
"G4PROFILE_RUN_COMPONENTS", comps);
1146 auto event_env_comps = tim::get_env<std::string>(
"G4PROFILE_EVENT_COMPONENTS", comps);
1147 auto track_env_comps = tim::get_env<std::string>(
"G4PROFILE_TRACK_COMPONENTS", comps);
1148 auto step_env_comps = tim::get_env<std::string>(
"G4PROFILE_STEP_COMPONENTS", comps);
1149 auto user_env_comps = tim::get_env<std::string>(
"G4PROFILE_USER_COMPONENTS", comps);
1151 tim::configure<G4RunProfiler>(run_env_comps);
1152 tim::configure<G4EventProfiler>(event_env_comps);
1153 tim::configure<G4TrackProfiler>(track_env_comps);
1154 tim::configure<G4StepProfiler>(step_env_comps);
1155 tim::configure<G4UserProfiler>(user_env_comps);
1162#ifdef GEANT4_USE_TIMEMORY
Helper function for copying random state files in G4run.
G4bool G4CopyRandomState(const G4fs::path &source, const G4fs::path &dest, const G4String &callsite)
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
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 *)
virtual G4Run * GenerateRun()
virtual void BeginOfRunAction(const G4Run *)
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 &&...)