77#ifdef theParticleIterator
78# undef theParticleIterator
85 return fRunManagerKernel;
91 , geometryInitialized(false)
92 , physicsInitialized(false)
93 , geometryToBeOptimized(true)
94 , physicsNeedsToBeReBuilt(true)
96 , numberOfParallelWorld(0)
97 , geometryNeedsToBeClosed(true)
98 , numberOfStaticAllocators(0)
101 InvalidOperationDetection();
105 auto _signals = G4GetEnv<std::string>(
"G4BACKTRACE",
"");
118 numberOfStaticAllocators = allocList->
Size();
120 if(fRunManagerKernel)
122 G4Exception(
"G4RunManagerKernel::G4RunManagerKernel()",
"Run0001",
124 "More than one G4RunManagerKernel is constructed.");
126 fRunManagerKernel =
this;
129 if(particleTable->
entries() > 0)
133 ED <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" <<
G4endl;
134 ED <<
" G4RunManagerKernel fatal exception" <<
G4endl;
135 ED <<
" -- Following particles have already been registered" <<
G4endl;
136 ED <<
" before G4RunManagerKernel is instantiated." <<
G4endl;
137 for(
int i = 0; i < particleTable->
entries(); i++)
142 ED <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" <<
G4endl;
143 G4Exception(
"G4RunManagerKernel::G4RunManagerKernel()",
"Run0002",
152 new G4Region(
"DefaultRegionForParallelWorld");
155 ->GetDefaultProductionCuts());
158 ->GetDefaultProductionCuts());
166 vs = vs.substr(1, vs.size() - 2);
167 versionString =
" Geant4 version ";
169 versionString +=
" ";
170 versionString += G4Date;
172 <<
"**************************************************************"
174 <<
" Copyright : Geant4 Collaboration" <<
G4endl
175 <<
" References : NIM A 506 (2003), 250-303"
177 <<
" : IEEE-TNS 53 (2006), 270-278"
179 <<
" : NIM A 835 (2016), 186-225"
180 <<
G4endl <<
" WWW : http://geant4.org/"
182 <<
"**************************************************************"
189 , geometryInitialized(false)
190 , physicsInitialized(false)
191 , geometryToBeOptimized(true)
192 , physicsNeedsToBeReBuilt(true)
194 , numberOfParallelWorld(0)
195 , geometryNeedsToBeClosed(true)
196 , numberOfStaticAllocators(0)
199#ifndef G4MULTITHREADED
201 msg <<
"Geant4 code is compiled without multi-threading support "
202 "(-DG4MULTITHREADED "
204 msg <<
" This type of RunManagerKernel can only be used in mult-threaded "
206 G4Exception(
"G4RunManagerKernel::G4RunManagerKernel(G4bool)",
"Run0105",
213 InvalidOperationDetection();
218 auto _signals = G4GetEnv<std::string>(
"G4BACKTRACE",
"");
230 if(fRunManagerKernel)
232 G4Exception(
"G4RunManagerKernel::G4RunManagerKernel()",
"Run0001",
234 "More than one G4RunManagerKernel is constructed.");
236 fRunManagerKernel =
this;
245 new G4Region(
"DefaultRegionForTheWorld");
247 new G4Region(
"DefaultRegionForParallelWorld");
250 ->GetDefaultProductionCuts());
253 ->GetDefaultProductionCuts());
258 "DefaultRegionForTheWorld",
true);
260 "DefaultRegionForParallelWorld",
true);
267 <<
" This type of RunManagerKernel can only be used in mult-threaded "
269 G4Exception(
"G4RunManagerKernel::G4RunManagerKernel(G4bool)",
"Run0106",
279 vs = vs.substr(1, vs.size() - 2);
283 versionString =
" Geant4 version ";
285 versionString +=
" ";
286 versionString += G4Date;
288 <<
"**************************************************************"
290 <<
" << in Multi-threaded mode >> " <<
G4endl
291 <<
" Copyright : Geant4 Collaboration"
293 <<
" References : NIM A 506 (2003), 250-303"
295 <<
" : IEEE-TNS 53 (2006), 270-278"
297 <<
" : NIM A 835 (2016), 186-225"
299 <<
" WWW : http://geant4.org/"
301 <<
"**************************************************************"
307 versionString =
" Local thread RunManagerKernel version ";
311 <<
"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
314 <<
"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
320#ifdef G4MULTITHREADED
336 "Default world region should have a unique logical volume.");
338 std::vector<G4LogicalVolume*>::iterator lvItr =
343 <<
"Obsolete world logical volume is removed from the default region."
355 G4cout <<
"G4 kernel has come to Quit state." <<
G4endl;
423 allocList->
Destroy(numberOfStaticAllocators, verboseLevel);
432 G4cout <<
"Thread-local UImanager is to be deleted." <<
G4endl
433 <<
"There should not be any thread-local G4cout/G4cerr hereafter."
442 delete pStateManager;
445 delete defaultExceptionHandler;
447 G4cout <<
"RunManagerKernel is deleted. Good bye :)" <<
G4endl;
448 fRunManagerKernel = 0;
457 G4MTRunManager::masterWorlds_t::iterator itrMW = masterWorlds.begin();
458 for(; itrMW != masterWorlds.end(); itrMW++)
480 G4cout <<
"Current application state is "
482 G4Exception(
"G4RunManagerKernel::DefineWorldVolume",
484 "Geant4 kernel is not Init state : Method ignored.");
500 currentWorld = worldVol;
505 G4MTRunManager::masterWorlds_t::iterator itrMW = masterWorlds.begin();
506 for(; itrMW != masterWorlds.end(); itrMW++)
508 if((*itrMW).first == 0)
510 if((*itrMW).second != currentWorld)
512 G4Exception(
"G4RunManagerKernel::WorkerDefineWorldVolume",
"RUN3091",
523 if(topologyIsChanged)
534 geometryInitialized =
true;
552 G4cout <<
"Current application state is "
554 G4Exception(
"G4RunManagerKernel::DefineWorldVolume",
556 "Geant4 kernel is not Init state : Method ignored.");
578 ED <<
"The world volume has a user-defined region <"
581 ED <<
"World would have a default region assigned by RunManagerKernel."
591 currentWorld = worldVol;
599 G4cout << worldLog->
GetName() <<
" is registered to the default region."
605 if(topologyIsChanged)
616 geometryInitialized =
true;
636 G4cout <<
"List of instantiated particles "
637 "============================================"
640 for(
G4int i = 0; i < nPtcl; i++)
694#ifdef G4MULTITHREADED
710 G4cout <<
"Current application state is "
714 G4Exception(
"G4RunManagerKernel::InitializePhysics",
716 "Geant4 kernel is not Init state : Method ignored.");
726 <<
"Warning : Geant4 kernel is not Init state : Assuming Init state."
734 G4Exception(
"G4RunManagerKernel::InitializePhysics",
"Run0012",
741 if(numberOfParallelWorld > 0)
746 G4cout <<
"physicsList->CheckParticleList() start." <<
G4endl;
779 physicsInitialized =
true;
780#ifdef G4MULTITHREADED
795 if(!geometryInitialized)
798 "Geometry has not yet initialized : method ignored.");
802 if(!physicsInitialized)
805 "Physics has not yet initialized : method ignored.");
812 "Geant4 kernel not in Idle state : method ignored.");
817 CheckRegularGeometry();
840#ifdef G4MULTITHREADED
893 geomManager->
CloseGeometry(geometryToBeOptimized, verboseLevel > 1);
905 "Geant4 kernel not in Init state : method ignored.");
923 physicsNeedsToBeReBuilt)
925#ifdef G4MULTITHREADED
935 physicsNeedsToBeReBuilt =
false;
938 if(!fakeRun && verboseLevel > 1)
940 if(!fakeRun && verboseLevel > 0)
951 std::vector<G4VPhysicalVolume*>::iterator wItr;
964 for(
size_t iw = 0; iw < nWorlds; iw++)
968 if(*wItr == currentWorld)
987 <<
"> does not have specific production cuts," <<
G4endl
988 <<
"even though it appears in the current tracking world."
990 G4cout <<
"Default cuts are used for this region." <<
G4endl;
1007 for(
size_t iw = 0; iw < nWorlds; iw++)
1010 if(*wItr != currentWorld)
1050 <<
"> world volume";
1054 G4cout <<
" -- is not associated to any world.";
1059 G4cout <<
" This region is in the mass world." <<
G4endl;
1063 G4cout <<
" This region is in the parallel world." <<
G4endl;
1066 G4cout <<
" Root logical volume(s) : ";
1068 std::vector<G4LogicalVolume*>::iterator lvItr =
1070 for(
size_t j = 0; j < nRootLV; j++)
1072 G4cout << (*lvItr)->GetName() <<
" ";
1077 G4cout <<
" Pointers : G4VUserRegionInformation["
1083 G4cout <<
" Materials : ";
1084 std::vector<G4Material*>::const_iterator mItr =
1087 for(
size_t iMate = 0; iMate < nMaterial; iMate++)
1089 G4cout << (*mItr)->GetName() <<
" ";
1097 <<
"> does not have specific production cuts." <<
G4endl;
1098 G4cerr <<
"Default cuts are used for this region." <<
G4endl;
1100 ->GetDefaultProductionCuts());
1104 G4cout <<
" Production cuts : "
1117void G4RunManagerKernel::CheckRegularGeometry()
1120 for(G4LogicalVolumeStore::iterator pos = store->begin(); pos != store->end();
1123 if((*pos) && ((*pos)->GetNoDaughters() == 1))
1125 if((*pos)->GetDaughter(0)->IsRegularStructure())
1139G4bool G4RunManagerKernel::ConfirmCoupledTransportation()
1160void G4RunManagerKernel::SetScoreSplitter()
1171 InitSplitter =
true;
1184 if(verboseLevel > 0)
1187 <<
"G4RunManagerKernel -- G4ScoreSplittingProcess is appended to all "
1208 for(std::size_t idx = 0; idx < procs.
size(); ++idx)
1210 const G4VProcess* masterP = procs[idx]->GetMasterProcess();
1215 procs[idx]->SetMasterProcess(
const_cast<G4VProcess*
>(procs[idx]));
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
#define G4MUTEX_INITIALIZER
#define theParticleIterator
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
static G4AllocatorList * GetAllocatorListIfExist()
void Destroy(G4int nStat=0, G4int verboseLevel=0)
static int Enable(const std::string &)
static G4FieldManagerStore * GetInstanceIfExist()
static G4Geantino * GeantinoDefinition()
static G4GeometryManager * GetInstance()
G4bool CloseGeometry(G4bool pOptimise=true, G4bool verbose=false, G4VPhysicalVolume *vol=nullptr)
void OpenGeometry(G4VPhysicalVolume *vol=nullptr)
static G4GeometryManager * GetInstanceIfExist()
static void ConstructParticle()
void InitializeLightIons()
static G4LogicalVolumeStore * GetInstance()
void SetRegion(G4Region *reg)
G4Region * GetRegion() const
const G4String & GetName() const
std::map< G4int, G4VPhysicalVolume * > masterWorlds_t
static G4MTRunManager * GetMasterRunManager()
static masterWorlds_t & GetMasterWorlds()
static G4NavigationHistoryPool * GetInstance()
static G4ParallelWorldProcessStore * GetInstanceIfExist()
G4ProcessManager * GetProcessManager() const
G4bool IsGeneralIon() const
void SetParticleDefinitionID(G4int id=-1)
G4int GetParticleDefinitionID() const
const G4String & GetParticleName() const
void reset(G4bool ifSkipIon=true)
G4IonTable * GetIonTable() const
G4ParticleDefinition * GetParticle(G4int index) const
G4PTblDicIterator * GetIterator() const
static G4ParticleTable * GetParticleTable()
void SetReadiness(G4bool val=true)
G4ParticleDefinition * GetGenericIon() const
void DumpTable(const G4String &particle_name="ALL")
static G4PathFinder * GetInstanceIfExist()
G4int AddDiscreteProcess(G4VProcess *aProcess, G4int ord=ordDefault)
G4ProcessVector * GetAlongStepProcessVector(G4ProcessVectorTypeIndex typ=typeGPIL) const
G4ProcessVector * GetProcessList() const
void UpdateCoupleTable(G4VPhysicalVolume *currentWorld)
void PhysicsTableUpdated()
static G4ProductionCutsTable * GetProductionCutsTable()
G4ProductionCuts * GetDefaultProductionCuts() const
G4double GetProductionCut(G4int index) const
static G4RegionStore * GetInstance()
void UpdateMaterialList(G4VPhysicalVolume *currentWorld=0)
G4Region * GetRegion(const G4String &name, G4bool verbose=true) const
G4bool BelongsTo(G4VPhysicalVolume *thePhys) const
G4FastSimulationManager * GetFastSimulationManager() const
G4VUserRegionInformation * GetUserInformation() const
void SetWorld(G4VPhysicalVolume *wp)
G4bool IsInParallelGeometry() const
G4ProductionCuts * GetProductionCuts() const
void RemoveRootLogicalVolume(G4LogicalVolume *lv, G4bool scan=true)
G4VPhysicalVolume * GetWorldPhysical() const
void SetProductionCuts(G4ProductionCuts *cut)
G4UserLimits * GetUserLimits() const
const G4String & GetName() const
G4bool IsInMassGeometry() const
size_t GetNumberOfRootVolumes() const
G4UserSteppingAction * GetRegionalSteppingAction() const
size_t GetNumberOfMaterials() const
void UsedInParallelGeometry(G4bool val=true)
std::vector< G4Material * >::const_iterator GetMaterialIterator() const
void AddRootLogicalVolume(G4LogicalVolume *lv, G4bool search=true)
std::vector< G4LogicalVolume * >::iterator GetRootLogicalVolumeIterator()
void UsedInMassGeometry(G4bool val=true)
void SetupDefaultRegion()
G4PrimaryTransformer * GetPrimaryTransformer() const
G4Region * defaultRegionForParallelWorld
static G4RunManagerKernel * GetRunManagerKernel()
void SetPhysics(G4VUserPhysicsList *uPhys)
RMKType runManagerKernelType
void WorkerUpdateWorldVolume()
void DefineWorldVolume(G4VPhysicalVolume *worldVol, G4bool topologyIsChanged=true)
void PropagateGenericIonID()
G4bool RunInitialization(G4bool fakeRun=false)
void WorkerDefineWorldVolume(G4VPhysicalVolume *worldVol, G4bool topologyIsChanged=true)
virtual void SetupShadowProcess() const
virtual ~G4RunManagerKernel()
void DumpRegion(const G4String &rname) const
G4bool geometryNeedsToBeClosed
void BuildPhysicsTables(G4bool fakeRun)
static G4SDManager * GetSDMpointerIfExist()
const G4ApplicationState & GetCurrentState() const
G4String GetStateString(const G4ApplicationState &aState) const
static G4StateManager * GetStateManager()
G4bool SetNewState(const G4ApplicationState &requestedState)
static G4TemplateRNGHelper< T > * GetInstanceIfExist()
G4bool RegisterWorld(G4VPhysicalVolume *aWorld)
static G4TransportationManager * GetTransportationManager()
static G4TransportationManager * GetInstanceIfExist()
G4VPhysicalVolume * IsWorldExisting(const G4String &worldName)
void SetWorldForTracking(G4VPhysicalVolume *theWorld)
std::vector< G4VPhysicalVolume * >::iterator GetWorldsIterator()
size_t GetNoWorlds() const
G4int ApplyCommand(const char *aCommand)
static G4UImanager * GetUIpointer()
static void ClearUnitsTable()
static G4UnitsTable & GetUnitsTable()
G4LogicalVolume * GetLogicalVolume() const
const G4String & GetName() const
const G4String & GetProcessName() const
void UseCoupledTransportation(G4bool vl=true)
virtual void ConstructParticle()=0
void DumpCutValuesTableIfRequested()
void DumpCutValuesTable(G4int flag=1)
static G4VVisManager * GetConcreteInstance()
virtual void GeometryHasChanged()=0