85#ifdef theParticleIterator
86# undef theParticleIterator
94 return fRunManagerKernel;
101 InvalidOperationDetection();
106 if (_signals.empty()) {
115 if (allocList !=
nullptr) numberOfStaticAllocators = (
G4int)allocList->
Size();
120 if (fRunManagerKernel !=
nullptr) {
122 "More than one G4RunManagerKernel is constructed.");
124 fRunManagerKernel =
this;
127 if (particleTable->
entries() > 0) {
130 ED <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" <<
G4endl;
131 ED <<
" G4RunManagerKernel fatal exception" <<
G4endl;
132 ED <<
" -- Following particles have already been registered" <<
G4endl;
133 ED <<
" before G4RunManagerKernel is instantiated." <<
G4endl;
137 ED <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" <<
G4endl;
146 new G4Region(
"DefaultRegionForParallelWorld");
158 vs = vs.substr(1, vs.size() - 2);
159 versionString =
" Geant4 version ";
161 versionString +=
" ";
162 versionString += G4Date;
163 G4cout <<
G4endl <<
"**************************************************************" <<
G4endl
164 << versionString <<
G4endl <<
" Copyright : Geant4 Collaboration"
165 <<
G4endl <<
" References : NIM A 506 (2003), 250-303" <<
G4endl
166 <<
" : IEEE-TNS 53 (2006), 270-278" <<
G4endl
167 <<
" : NIM A 835 (2016), 186-225" <<
G4endl
168 <<
" WWW : http://geant4.org/" <<
G4endl
169 <<
"**************************************************************" <<
G4endl <<
G4endl;
176#ifndef G4MULTITHREADED
178 msg <<
"Geant4 code is compiled without multi-threading support "
179 "(-DG4MULTITHREADED is set to off).";
180 msg <<
" This type of RunManagerKernel can only be used in mult-threaded "
187 InvalidOperationDetection();
193 if (_signals.empty()) {
205 if (fRunManagerKernel !=
nullptr) {
207 "More than one G4RunManagerKernel is constructed.");
209 fRunManagerKernel =
this;
218 new G4Region(
"DefaultRegionForParallelWorld");
234 msgx <<
" This type of RunManagerKernel can only be used in mult-threaded "
246 vs = vs.substr(1, vs.size() - 2);
249 versionString =
" Geant4 version ";
251 versionString +=
" ";
252 versionString += G4Date;
253 G4cout <<
G4endl <<
"**************************************************************" <<
G4endl
254 << versionString <<
G4endl <<
" << in Multi-threaded mode >> " <<
G4endl
255 <<
" Copyright : Geant4 Collaboration" <<
G4endl
256 <<
" References : NIM A 506 (2003), 250-303" <<
G4endl
257 <<
" : IEEE-TNS 53 (2006), 270-278" <<
G4endl
258 <<
" : NIM A 835 (2016), 186-225" <<
G4endl
259 <<
" WWW : http://geant4.org/" <<
G4endl
260 <<
"**************************************************************" <<
G4endl
264 if (verboseLevel != 0) {
265 versionString =
" Local thread RunManagerKernel version ";
268 <<
"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
271 <<
"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
277#ifdef G4MULTITHREADED
291 "Default world region should have a unique logical volume.");
295 if (verboseLevel > 1)
296 G4cout <<
"Obsolete world logical volume is removed from the default region." <<
G4endl;
306 if (verboseLevel > 1)
G4cout <<
"G4 kernel has come to Quit state." <<
G4endl;
316 if (verboseLevel > 1)
G4cout <<
"G4SDManager deleted." <<
G4endl;
318 if (verboseLevel > 1)
G4cout <<
"EventManager deleted." <<
G4endl;
321 if (verboseLevel > 1)
G4cout <<
"Units table cleared." <<
G4endl;
329 if (verboseLevel > 1)
G4cout <<
"TransportationManager deleted." <<
G4endl;
338 if (verboseLevel > 1)
G4cout <<
"G4RNGHelper object is deleted." <<
G4endl;
343 if (allocList !=
nullptr) {
344 allocList->
Destroy(numberOfStaticAllocators, verboseLevel);
346 if (verboseLevel > 1)
G4cout <<
"G4Allocator objects are deleted." <<
G4endl;
351 G4cout <<
"Thread-local UImanager is to be deleted." <<
G4endl
352 <<
"There should not be any thread-local G4cout/G4cerr hereafter." <<
G4endl;
355 if (verboseLevel > 1)
G4cout <<
"UImanager deleted." <<
G4endl;
357 delete pStateManager;
358 if (verboseLevel > 1)
G4cout <<
"StateManager deleted." <<
G4endl;
359 delete defaultExceptionHandler;
360 if (verboseLevel > 1)
G4cout <<
"RunManagerKernel is deleted. Good bye :)" <<
G4endl;
361 fRunManagerKernel =
nullptr;
370 for (
const auto& masterWorld : masterWorlds) {
374 if (pWorld ==
nullptr) {
390 G4Exception(
"G4RunManagerKernel::DefineWorldVolume",
"DefineWorldVolumeAtIncorrectState",
391 FatalException,
"Geant4 kernel is not Init state : Method ignored.");
398 currentWorld = worldVol;
402 for (
const auto& masterWorld : masterWorlds) {
403 if (masterWorld.first == 0) {
404 if (masterWorld.second != currentWorld) {
406 "Mass world is inconsistent");
423 geometryInitialized =
true;
425 if (physicsInitialized && currentState !=
G4State_Idle) {
440 G4Exception(
"G4RunManagerKernel::DefineWorldVolume",
"DefineWorldVolumeAtIncorrectState",
441 FatalException,
"Geant4 kernel is not Init state : Method ignored.");
452 ED <<
"The world volume has a user-defined region <"
454 ED <<
"World would have a default region assigned by RunManagerKernel." <<
G4endl;
462 currentWorld = worldVol;
469 if (verboseLevel > 1)
482 geometryInitialized =
true;
484 if (physicsInitialized && currentState !=
G4State_Idle) {
498 if (verboseLevel > 1) {
499 G4cout <<
"List of instantiated particles "
500 "============================================"
503 for (
G4int i = 0; i < nPtcl; ++i) {
522 if (gion !=
nullptr) {
534 if (gion !=
nullptr) {
542#ifdef G4MULTITHREADED
562 G4Exception(
"G4RunManagerKernel::InitializePhysics",
"InitializePhysicsIncorrectState",
563 FatalException,
"Geant4 kernel is not Init state : Method ignored.");
567 G4cout <<
"Warning : Geant4 kernel is not Init state : Assuming Init state." <<
G4endl;
571 if (physicsList ==
nullptr) {
573 "G4VUserPhysicsList is not defined");
577 if (verboseLevel > 1)
G4cout <<
"physicsList->Construct() start." <<
G4endl;
581 if (verboseLevel > 1)
G4cout <<
"physicsList->CheckParticleList() start." <<
G4endl;
588 if (verboseLevel > 1)
G4cout <<
"physicsList->setCut() start." <<
G4endl;
594 physicsInitialized =
true;
596#ifdef G4MULTITHREADED
601 if (geometryInitialized && currentState !=
G4State_Idle) {
612 if (!geometryInitialized) {
614 "Geometry has not yet initialized : method ignored.");
618 if (!physicsInitialized) {
620 "Physics has not yet initialized : method ignored.");
626 "Geant4 kernel not in Idle state : method ignored.");
650#ifdef G4MULTITHREADED
663 if (gion !=
nullptr) {
696 if (verboseLevel > 1)
G4cout <<
"Start closing geometry." <<
G4endl;
699 geomManager->
CloseGeometry(geometryToBeOptimized, verboseLevel > 1);
711 "Geant4 kernel not in Init state : method ignored.");
728#ifdef G4MULTITHREADED
736 physicsNeedsToBeReBuilt =
false;
739 if (!fakeRun && verboseLevel > 1)
DumpRegion();
749 std::vector<G4VPhysicalVolume*>::iterator wItr;
755 region->SetWorld(
nullptr);
756 region->UsedInMassGeometry(
false);
757 region->UsedInParallelGeometry(
false);
759 for (std::size_t iw = 0; iw < nWorlds; ++iw) {
760 if (region->BelongsTo(*wItr)) {
761 if (*wItr == currentWorld) {
762 region->UsedInMassGeometry(
true);
765 region->UsedInParallelGeometry(
true);
768 region->SetWorld(*wItr);
773 if (cuts ==
nullptr) {
774 if (region->IsInMassGeometry() && verboseLevel > 0) {
775 G4cout <<
"Warning : Region <" << region->GetName()
776 <<
"> does not have specific production cuts," <<
G4endl
777 <<
"even though it appears in the current tracking world." <<
G4endl;
778 G4cout <<
"Default cuts are used for this region." <<
G4endl;
781 if (region->IsInMassGeometry() || region->IsInParallelGeometry()) {
782 region->SetProductionCuts(
793 for (std::size_t iw = 0; iw < nWorlds; ++iw) {
794 if (*wItr != currentWorld) {
815 if (region ==
nullptr) {
828 G4cout <<
" -- is not associated to any world.";
832 G4cout <<
" This region is in the mass world." <<
G4endl;
835 G4cout <<
" This region is in the parallel world." <<
G4endl;
838 G4cout <<
" Root logical volume(s) : ";
841 for (std::size_t j = 0; j < nRootLV; ++j) {
842 G4cout << (*lvItr)->GetName() <<
" ";
848 <<
"], G4UserLimits[" << region->
GetUserLimits() <<
"], G4FastSimulationManager["
852 G4cout <<
" Materials : ";
855 for (std::size_t iMate = 0; iMate < nMaterial; ++iMate) {
856 G4cout << (*mItr)->GetName() <<
" ";
863 <<
"> does not have specific production cuts." <<
G4endl;
864 G4cerr <<
"Default cuts are used for this region." <<
G4endl;
868 else if (cuts !=
nullptr) {
869 G4cout <<
" Production cuts : "
879void G4RunManagerKernel::CheckRegularGeometry()
882 for (
const auto& pos : *store) {
883 if ((pos !=
nullptr) && (pos->GetNoDaughters() == 1)) {
884 if (pos->GetDaughter(0)->IsRegularStructure()) {
893G4bool G4RunManagerKernel::ConfirmCoupledTransportation()
911void G4RunManagerKernel::SetScoreSplitter()
926 if (pmanager !=
nullptr) {
931 if (verboseLevel > 0) {
932 G4cout <<
"G4RunManagerKernel -- G4ScoreSplittingProcess is appended to all "
952 const G4VProcess* masterP = procs[idx]->GetMasterProcess();
953 if (masterP ==
nullptr) {
956 procs[idx]->SetMasterProcess(
const_cast<G4VProcess*
>(procs[idx]));
_Tp G4GetEnv(const std::string &env_id, _Tp _default=_Tp())
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 G4int 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
static G4MTRunManager * GetMasterRunManager()
std::map< G4int, G4VPhysicalVolume * > masterWorlds_t
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()
G4double GetProductionCut(G4int index) const
const std::vector< G4double > & GetProductionCuts() const
static G4RegionStore * GetInstance()
void UpdateMaterialList(G4VPhysicalVolume *currentWorld=nullptr)
G4Region * GetRegion(const G4String &name, G4bool verbose=true) const
std::size_t GetNumberOfRootVolumes() const
std::size_t GetNumberOfMaterials() const
G4FastSimulationManager * GetFastSimulationManager() const
G4VUserRegionInformation * GetUserInformation() const
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
G4UserSteppingAction * GetRegionalSteppingAction() const
std::vector< G4Material * >::const_iterator GetMaterialIterator() const
void AddRootLogicalVolume(G4LogicalVolume *lv, G4bool search=true)
std::vector< G4LogicalVolume * >::iterator GetRootLogicalVolumeIterator()
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()
std::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