Geant4 11.3.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4RunManagerKernel Class Reference

#include <G4RunManagerKernel.hh>

+ Inheritance diagram for G4RunManagerKernel:

Public Types

enum  RMKType { sequentialRMK , masterRMK , workerRMK }
 

Public Member Functions

 G4RunManagerKernel ()
 
virtual ~G4RunManagerKernel ()
 
void DefineWorldVolume (G4VPhysicalVolume *worldVol, G4bool topologyIsChanged=true)
 
void WorkerDefineWorldVolume (G4VPhysicalVolume *worldVol, G4bool topologyIsChanged=true)
 
void SetPhysics (G4VUserPhysicsList *uPhys)
 
void InitializePhysics ()
 
G4bool RunInitialization (G4bool fakeRun=false)
 
void RunTermination ()
 
void UpdateRegion ()
 
void DumpRegion (const G4String &rname) const
 
void DumpRegion (G4Region *region=nullptr) const
 
void WorkerUpdateWorldVolume ()
 
void GeometryHasBeenModified ()
 
void PhysicsHasBeenModified ()
 
G4EventManagerGetEventManager () const
 
G4StackManagerGetStackManager () const
 
G4TrackingManagerGetTrackingManager () const
 
void SetPrimaryTransformer (G4PrimaryTransformer *pt)
 
G4PrimaryTransformerGetPrimaryTransformer () const
 
const G4StringGetVersionString () const
 
void SetVerboseLevel (G4int vl)
 
void SetGeometryToBeOptimized (G4bool vl)
 
void ResetNavigatorAtInitialization (G4bool val=true)
 
G4int GetNumberOfParallelWorld () const
 
void SetNumberOfParallelWorld (G4int i)
 
G4VUserPhysicsListGetPhysicsList () const
 
G4VPhysicalVolumeGetCurrentWorld () const
 
G4int GetNumberOfStaticAllocators () const
 

Static Public Member Functions

static G4RunManagerKernelGetRunManagerKernel ()
 

Protected Member Functions

 G4RunManagerKernel (RMKType rmkType)
 
void SetupDefaultRegion ()
 
void SetupPhysics ()
 
void ResetNavigator ()
 
void BuildPhysicsTables (G4bool fakeRun)
 
void CheckRegions ()
 
virtual void SetupShadowProcess () const
 
void PropagateGenericIonID ()
 

Protected Attributes

RMKType runManagerKernelType
 
G4RegiondefaultRegion = nullptr
 
G4RegiondefaultRegionForParallelWorld = nullptr
 
G4bool geometryNeedsToBeClosed = true
 

Detailed Description

Definition at line 64 of file G4RunManagerKernel.hh.

Member Enumeration Documentation

◆ RMKType

Enumerator
sequentialRMK 
masterRMK 
workerRMK 

Definition at line 166 of file G4RunManagerKernel.hh.

Constructor & Destructor Documentation

◆ G4RunManagerKernel() [1/2]

G4RunManagerKernel::G4RunManagerKernel ( )

Definition at line 97 of file G4RunManagerKernel.cc.

98{
99#ifdef G4FPE_DEBUG
100 InvalidOperationDetection();
101#endif
102
103#ifdef G4BT_DEBUG
104 auto _signals = G4GetEnv<std::string>("G4BACKTRACE", "");
105 if (_signals.empty()) {
107 }
108 else {
109 G4Backtrace::Enable(_signals);
110 }
111#endif
112
113 G4AllocatorList* allocList = G4AllocatorList::GetAllocatorListIfExist();
114 if (allocList != nullptr) numberOfStaticAllocators = (G4int)allocList->Size();
115
116 if (G4StateManager::GetStateManager()->GetExceptionHandler() == nullptr) {
117 defaultExceptionHandler = new G4ExceptionHandler();
118 }
119 if (fRunManagerKernel != nullptr) {
120 G4Exception("G4RunManagerKernel::G4RunManagerKernel()", "Run0001", FatalException,
121 "More than one G4RunManagerKernel is constructed.");
122 }
123 fRunManagerKernel = this;
124
125 G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
126 if (particleTable->entries() > 0) {
127 // No particle should be registered beforehand
129 ED << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << G4endl;
130 ED << " G4RunManagerKernel fatal exception" << G4endl;
131 ED << " -- Following particles have already been registered" << G4endl;
132 ED << " before G4RunManagerKernel is instantiated." << G4endl;
133 for (G4int i = 0; i < particleTable->entries(); ++i) {
134 ED << " " << particleTable->GetParticle(i)->GetParticleName() << G4endl;
135 }
136 ED << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << G4endl;
137 G4Exception("G4RunManagerKernel::G4RunManagerKernel()", "Run0002", FatalException, ED);
138 }
139
140 // construction of Geant4 kernel classes
141 eventManager = new G4EventManager();
142
143 defaultRegion = new G4Region("DefaultRegionForTheWorld"); // deleted by store
145 new G4Region("DefaultRegionForParallelWorld"); // deleted by store
146 defaultRegion->SetProductionCuts(
147 G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts());
148 defaultRegionForParallelWorld->SetProductionCuts(
149 G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts());
150
152 // set the initial application state
154
155 // version banner
156 G4String vs = G4Version;
157 vs = vs.substr(1, vs.size() - 2);
158 versionString = " Geant4 version ";
159 versionString += vs;
160 versionString += " ";
161 versionString += G4Date;
162 G4cout << G4endl << "**************************************************************" << G4endl
163 << versionString << G4endl << " Copyright : Geant4 Collaboration"
164 << G4endl << " References : NIM A 506 (2003), 250-303" << G4endl
165 << " : IEEE-TNS 53 (2006), 270-278" << G4endl
166 << " : NIM A 835 (2016), 186-225" << G4endl
167 << " WWW : http://geant4.org/" << G4endl
168 << "**************************************************************" << G4endl << G4endl;
169}
@ G4State_PreInit
_Tp G4GetEnv(const std::string &env_id, _Tp _default=_Tp())
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
int G4int
Definition G4Types.hh:85
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
static G4AllocatorList * GetAllocatorListIfExist()
std::size_t Size() const
static G4int Enable(const std::string &)
const G4String & GetParticleName() const
G4ParticleDefinition * GetParticle(G4int index) const
G4int entries() const
static G4ParticleTable * GetParticleTable()
static G4ProductionCutsTable * GetProductionCutsTable()
G4Region * defaultRegionForParallelWorld
static G4StateManager * GetStateManager()
G4bool SetNewState(const G4ApplicationState &requestedState)

Referenced by G4MTRunManagerKernel::G4MTRunManagerKernel(), G4TaskRunManagerKernel::G4TaskRunManagerKernel(), G4WorkerRunManagerKernel::G4WorkerRunManagerKernel(), G4WorkerTaskRunManagerKernel::G4WorkerTaskRunManagerKernel(), and GetRunManagerKernel().

◆ ~G4RunManagerKernel()

G4RunManagerKernel::~G4RunManagerKernel ( )
virtual

Definition at line 300 of file G4RunManagerKernel.cc.

301{
302 G4StateManager* pStateManager = G4StateManager::GetStateManager();
303 // set the application state to the quite state
304 if (pStateManager->GetCurrentState() != G4State_Quit) {
305 if (verboseLevel > 1) G4cout << "G4 kernel has come to Quit state." << G4endl;
306 pStateManager->SetNewState(G4State_Quit);
307 }
308
309 // open geometry for deletion
311
312 // deletion of Geant4 kernel classes
315 if (verboseLevel > 1) G4cout << "G4SDManager deleted." << G4endl;
316 delete eventManager;
317 if (verboseLevel > 1) G4cout << "EventManager deleted." << G4endl;
318
320 if (verboseLevel > 1) G4cout << "Units table cleared." << G4endl;
321
322 // deletion of path-finder field-manager store, geometry and transportation
323 // manager
328 if (verboseLevel > 1) G4cout << "TransportationManager deleted." << G4endl;
329
330 // deletion of navigation levels
331 if (verboseLevel > 1) G4NavigationHistoryPool::GetInstance()->Print();
333
334 // deletion of G4RNGHelper singleton
337 if (verboseLevel > 1) G4cout << "G4RNGHelper object is deleted." << G4endl;
338 }
339
340 // deletion of allocators
341 G4AllocatorList* allocList = G4AllocatorList::GetAllocatorListIfExist();
342 if (allocList != nullptr) {
343 allocList->Destroy(numberOfStaticAllocators, verboseLevel);
344 delete allocList;
345 if (verboseLevel > 1) G4cout << "G4Allocator objects are deleted." << G4endl;
346 }
347
348 G4UImanager* pUImanager = G4UImanager::GetUIpointer();
349 if ((runManagerKernelType == workerRMK) && (verboseLevel > 1)) {
350 G4cout << "Thread-local UImanager is to be deleted." << G4endl
351 << "There should not be any thread-local G4cout/G4cerr hereafter." << G4endl;
352 }
353 delete pUImanager;
354 if (verboseLevel > 1) G4cout << "UImanager deleted." << G4endl;
355
356 delete pStateManager;
357 if (verboseLevel > 1) G4cout << "StateManager deleted." << G4endl;
358 delete defaultExceptionHandler;
359 if (verboseLevel > 1) G4cout << "RunManagerKernel is deleted. Good bye :)" << G4endl;
360 fRunManagerKernel = nullptr;
361}
@ G4State_Quit
void Destroy(G4int nStat=0, G4int verboseLevel=0)
static G4FieldManagerStore * GetInstanceIfExist()
static G4GeometryManager * GetInstance()
void OpenGeometry(G4VPhysicalVolume *vol=nullptr)
static G4GeometryManager * GetInstanceIfExist()
static G4NavigationHistoryPool * GetInstance()
static G4ParallelWorldProcessStore * GetInstanceIfExist()
static G4PathFinder * GetInstanceIfExist()
static G4SDManager * GetSDMpointerIfExist()
const G4ApplicationState & GetCurrentState() const
static G4TemplateRNGHelper< G4long > * GetInstanceIfExist()
static G4TransportationManager * GetInstanceIfExist()
static G4UImanager * GetUIpointer()
static void ClearUnitsTable()

◆ G4RunManagerKernel() [2/2]

G4RunManagerKernel::G4RunManagerKernel ( RMKType rmkType)
protected

Definition at line 172 of file G4RunManagerKernel.cc.

173{
174// This version of the constructor should never be called in sequential mode!
175#ifndef G4MULTITHREADED
177 msg << "Geant4 code is compiled without multi-threading support "
178 "(-DG4MULTITHREADED is set to off).";
179 msg << " This type of RunManagerKernel can only be used in mult-threaded "
180 "applications.";
181 G4Exception("G4RunManagerKernel::G4RunManagerKernel(G4bool)", "Run0105", FatalException, msg);
182#endif
183
184#ifdef G4FPE_DEBUG
186 InvalidOperationDetection();
187 }
188#endif
189
190#ifdef G4BT_DEBUG
191 auto _signals = G4GetEnv<std::string>("G4BACKTRACE", "");
192 if (_signals.empty()) {
194 }
195 else {
196 G4Backtrace::Enable(_signals);
197 }
198#endif
199
200 if (G4StateManager::GetStateManager()->GetExceptionHandler() == nullptr) {
201 defaultExceptionHandler = new G4ExceptionHandler();
202 }
203
204 if (fRunManagerKernel != nullptr) {
205 G4Exception("G4RunManagerKernel::G4RunManagerKernel()", "Run0001", FatalException,
206 "More than one G4RunManagerKernel is constructed.");
207 }
208 fRunManagerKernel = this;
209 // construction of Geant4 kernel classes
210 eventManager = new G4EventManager();
211
212 switch (rmkType) {
213 case masterRMK:
214 // Master thread behvior
215 defaultRegion = new G4Region("DefaultRegionForTheWorld"); // deleted by store
217 new G4Region("DefaultRegionForParallelWorld"); // deleted by store
218 defaultRegion->SetProductionCuts(
219 G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts());
220 defaultRegionForParallelWorld->SetProductionCuts(
221 G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts());
222 break;
223 case workerRMK:
224 // Worker thread behavior
225 defaultRegion = G4RegionStore::GetInstance()->GetRegion("DefaultRegionForTheWorld", true);
227 G4RegionStore::GetInstance()->GetRegion("DefaultRegionForParallelWorld", true);
228 break;
229 default:
230 defaultRegion = nullptr;
233 msgx << " This type of RunManagerKernel can only be used in mult-threaded "
234 "applications.";
235 G4Exception("G4RunManagerKernel::G4RunManagerKernel(G4bool)", "Run0106", FatalException,
236 msgx);
237 }
238 runManagerKernelType = rmkType;
239
240 // set the initial application state
242
243 // version banner
244 G4String vs = G4Version;
245 vs = vs.substr(1, vs.size() - 2);
246 switch (rmkType) {
247 case masterRMK:
248 versionString = " Geant4 version ";
249 versionString += vs;
250 versionString += " ";
251 versionString += G4Date;
252 G4cout << G4endl << "**************************************************************" << G4endl
253 << versionString << G4endl << " << in Multi-threaded mode >> " << G4endl
254 << " Copyright : Geant4 Collaboration" << G4endl
255 << " References : NIM A 506 (2003), 250-303" << G4endl
256 << " : IEEE-TNS 53 (2006), 270-278" << G4endl
257 << " : NIM A 835 (2016), 186-225" << G4endl
258 << " WWW : http://geant4.org/" << G4endl
259 << "**************************************************************" << G4endl
260 << G4endl;
261 break;
262 default:
263 if (verboseLevel != 0) {
264 versionString = " Local thread RunManagerKernel version ";
265 versionString += vs;
266 G4cout << G4endl
267 << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
268 "^^^^^^^^^"
269 << G4endl << versionString << G4endl
270 << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
271 "^^^^^^^^^"
272 << G4endl << G4endl;
273 }
274 }
275
276#ifdef G4MULTITHREADED
277 G4UnitDefinition::GetUnitsTable().Synchronize();
278#endif
279}
static G4RegionStore * GetInstance()
G4Region * GetRegion(const G4String &name, G4bool verbose=true) const
static G4UnitsTable & GetUnitsTable()
G4bool IsMasterThread()

Member Function Documentation

◆ BuildPhysicsTables()

void G4RunManagerKernel::BuildPhysicsTables ( G4bool fakeRun)
protected

Definition at line 730 of file G4RunManagerKernel.cc.

731{
732 if (G4ProductionCutsTable::GetProductionCutsTable()->IsModified() || physicsNeedsToBeReBuilt) {
733#ifdef G4MULTITHREADED
735 // make sure workers also rebuild physics tables
736 G4UImanager* pUImanager = G4UImanager::GetUIpointer();
737 pUImanager->ApplyCommand("/run/physicsModified");
738 }
739#endif
740 physicsList->BuildPhysicsTable();
741 physicsNeedsToBeReBuilt = false;
742 }
743
744 if (!fakeRun && verboseLevel > 1) DumpRegion();
745 if (!fakeRun && verboseLevel > 0) physicsList->DumpCutValuesTable();
746 if (!fakeRun) physicsList->DumpCutValuesTableIfRequested();
747}
void DumpRegion(const G4String &rname) const
G4int ApplyCommand(const char *aCommand)

Referenced by RunInitialization().

◆ CheckRegions()

void G4RunManagerKernel::CheckRegions ( )
protected

Definition at line 750 of file G4RunManagerKernel.cc.

751{
752 G4TransportationManager* transM = G4TransportationManager::GetTransportationManager();
753 std::size_t nWorlds = transM->GetNoWorlds();
754 std::vector<G4VPhysicalVolume*>::iterator wItr;
755 for (auto region : *G4RegionStore::GetInstance()) {
756 // Let each region have a pointer to the world volume where it belongs to.
757 // G4Region::SetWorld() checks if the region belongs to the given world and
758 // set it only if it does. Thus, here we go through all the registered world
759 // volumes.
760 region->SetWorld(nullptr); // reset
761 region->UsedInMassGeometry(false);
762 region->UsedInParallelGeometry(false);
763 wItr = transM->GetWorldsIterator();
764 for (std::size_t iw = 0; iw < nWorlds; ++iw) {
765 if (region->BelongsTo(*wItr)) {
766 if (*wItr == currentWorld) {
767 region->UsedInMassGeometry(true);
768 }
769 else {
770 region->UsedInParallelGeometry(true);
771 }
772 }
773 region->SetWorld(*wItr);
774 ++wItr;
775 }
776
777 G4ProductionCuts* cuts = region->GetProductionCuts();
778 if (cuts == nullptr) {
779 if (region->IsInMassGeometry() && verboseLevel > 0) {
780 G4cout << "Warning : Region <" << region->GetName()
781 << "> does not have specific production cuts," << G4endl
782 << "even though it appears in the current tracking world." << G4endl;
783 G4cout << "Default cuts are used for this region." << G4endl;
784 }
785
786 if (region->IsInMassGeometry() || region->IsInParallelGeometry()) {
787 region->SetProductionCuts(
788 G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts());
789 }
790 }
791 }
792
793 //
794 // If a parallel world has no region, set default region for parallel world
795 //
796
797 wItr = transM->GetWorldsIterator();
798 for (std::size_t iw = 0; iw < nWorlds; ++iw) {
799 if (*wItr != currentWorld) {
800 G4LogicalVolume* pwLogical = (*wItr)->GetLogicalVolume();
801 if (pwLogical->GetRegion() == nullptr) {
803 defaultRegionForParallelWorld->AddRootLogicalVolume(pwLogical);
804 }
805 }
806 ++wItr;
807 }
808}
void SetRegion(G4Region *reg)
G4Region * GetRegion() const
static G4TransportationManager * GetTransportationManager()
std::vector< G4VPhysicalVolume * >::iterator GetWorldsIterator()
std::size_t GetNoWorlds() const

Referenced by InitializePhysics(), and UpdateRegion().

◆ DefineWorldVolume()

void G4RunManagerKernel::DefineWorldVolume ( G4VPhysicalVolume * worldVol,
G4bool topologyIsChanged = true )

Definition at line 430 of file G4RunManagerKernel.cc.

431{
432 G4StateManager* stateManager = G4StateManager::GetStateManager();
433 G4ApplicationState currentState = stateManager->GetCurrentState();
434
435 if (currentState != G4State_Init) {
436 if (currentState != G4State_Idle && currentState != G4State_PreInit) {
437 G4cout << "Current application state is " << stateManager->GetStateString(currentState)
438 << G4endl;
439 G4Exception("G4RunManagerKernel::DefineWorldVolume", "DefineWorldVolumeAtIncorrectState",
440 FatalException, "Geant4 kernel is not Init state : Method ignored.");
441 return;
442 }
443
444 stateManager->SetNewState(G4State_Init);
445 }
446
447 // The world volume MUST NOT have a region defined by the user
448 if (worldVol->GetLogicalVolume()->GetRegion() != nullptr) {
449 if (worldVol->GetLogicalVolume()->GetRegion() != defaultRegion) {
451 ED << "The world volume has a user-defined region <"
452 << worldVol->GetLogicalVolume()->GetRegion()->GetName() << ">." << G4endl;
453 ED << "World would have a default region assigned by RunManagerKernel." << G4endl;
454 G4Exception("G4RunManager::DefineWorldVolume", "Run0004", FatalException, ED);
455 }
456 }
457
459
460 // Accept the world volume
461 currentWorld = worldVol;
462
463 // Set the default region to the world
464
465 G4LogicalVolume* worldLog = currentWorld->GetLogicalVolume();
466 worldLog->SetRegion(defaultRegion);
467 defaultRegion->AddRootLogicalVolume(worldLog);
468 if (verboseLevel > 1)
469 G4cout << worldLog->GetName() << " is registered to the default region." << G4endl;
470
471 // Set the world volume, notify the Navigator and reset its state
473 if (topologyIsChanged) geometryNeedsToBeClosed = true;
474
475 // Notify the VisManager as well
477 G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
478 if (pVVisManager != nullptr) pVVisManager->GeometryHasChanged();
479 }
480
481 geometryInitialized = true;
482 stateManager->SetNewState(currentState);
483 if (physicsInitialized && currentState != G4State_Idle) {
484 stateManager->SetNewState(G4State_Idle);
485 }
486}
G4ApplicationState
@ G4State_Init
@ G4State_Idle
const G4String & GetName() const
const G4String & GetName() const
G4String GetStateString(const G4ApplicationState &aState) const
void SetWorldForTracking(G4VPhysicalVolume *theWorld)
G4LogicalVolume * GetLogicalVolume() const
static G4VVisManager * GetConcreteInstance()
virtual void GeometryHasChanged()=0

◆ DumpRegion() [1/2]

void G4RunManagerKernel::DumpRegion ( const G4String & rname) const

Definition at line 811 of file G4RunManagerKernel.cc.

812{
813 G4Region* region = G4RegionStore::GetInstance()->GetRegion(rname);
814 if (region != nullptr) DumpRegion(region);
815}

Referenced by BuildPhysicsTables(), DumpRegion(), and DumpRegion().

◆ DumpRegion() [2/2]

void G4RunManagerKernel::DumpRegion ( G4Region * region = nullptr) const

Definition at line 818 of file G4RunManagerKernel.cc.

819{
820 if (region == nullptr) {
821 for (const auto& i : *G4RegionStore::GetInstance()) {
822 DumpRegion(i);
823 }
824 }
825 else {
826 if (G4Threading::IsWorkerThread()) return;
827 G4cout << G4endl;
828 G4cout << "Region <" << region->GetName() << "> -- ";
829 if (region->GetWorldPhysical() != nullptr) {
830 G4cout << " -- appears in <" << region->GetWorldPhysical()->GetName() << "> world volume";
831 }
832 else {
833 G4cout << " -- is not associated to any world.";
834 }
835 G4cout << G4endl;
836 if (region->IsInMassGeometry()) {
837 G4cout << " This region is in the mass world." << G4endl;
838 }
839 if (region->IsInParallelGeometry()) {
840 G4cout << " This region is in the parallel world." << G4endl;
841 }
842
843 G4cout << " Root logical volume(s) : ";
844 std::size_t nRootLV = region->GetNumberOfRootVolumes();
845 auto lvItr = region->GetRootLogicalVolumeIterator();
846 for (std::size_t j = 0; j < nRootLV; ++j) {
847 G4cout << (*lvItr)->GetName() << " ";
848 ++lvItr;
849 }
850 G4cout << G4endl;
851
852 G4cout << " Pointers : G4VUserRegionInformation[" << region->GetUserInformation()
853 << "], G4UserLimits[" << region->GetUserLimits() << "], G4FastSimulationManager["
854 << region->GetFastSimulationManager() << "], G4UserSteppingAction["
855 << region->GetRegionalSteppingAction() << "]" << G4endl;
856
857 G4cout << " Materials : ";
858 auto mItr = region->GetMaterialIterator();
859 std::size_t nMaterial = region->GetNumberOfMaterials();
860 for (std::size_t iMate = 0; iMate < nMaterial; ++iMate) {
861 G4cout << (*mItr)->GetName() << " ";
862 ++mItr;
863 }
864 G4cout << G4endl;
865 G4ProductionCuts* cuts = region->GetProductionCuts();
866 if ((cuts == nullptr) && region->IsInMassGeometry()) {
867 G4cerr << "Warning : Region <" << region->GetName()
868 << "> does not have specific production cuts." << G4endl;
869 G4cerr << "Default cuts are used for this region." << G4endl;
870 region->SetProductionCuts(
871 G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts());
872 }
873 else if (cuts != nullptr) {
874 G4cout << " Production cuts : "
875 << " gamma " << G4BestUnit(cuts->GetProductionCut("gamma"), "Length") << " e- "
876 << G4BestUnit(cuts->GetProductionCut("e-"), "Length") << " e+ "
877 << G4BestUnit(cuts->GetProductionCut("e+"), "Length") << " proton "
878 << G4BestUnit(cuts->GetProductionCut("proton"), "Length") << G4endl;
879 }
880 }
881}
#define G4BestUnit(a, b)
G4GLOB_DLL std::ostream G4cerr
G4double GetProductionCut(G4int index) const
std::size_t GetNumberOfRootVolumes() const
std::size_t GetNumberOfMaterials() const
G4FastSimulationManager * GetFastSimulationManager() const
Definition G4Region.cc:140
G4VUserRegionInformation * GetUserInformation() const
G4bool IsInParallelGeometry() const
G4ProductionCuts * GetProductionCuts() const
G4VPhysicalVolume * GetWorldPhysical() const
void SetProductionCuts(G4ProductionCuts *cut)
G4UserLimits * GetUserLimits() const
G4bool IsInMassGeometry() const
G4UserSteppingAction * GetRegionalSteppingAction() const
Definition G4Region.cc:158
std::vector< G4Material * >::const_iterator GetMaterialIterator() const
std::vector< G4LogicalVolume * >::iterator GetRootLogicalVolumeIterator()
const G4String & GetName() const
G4bool IsWorkerThread()

◆ GeometryHasBeenModified()

void G4RunManagerKernel::GeometryHasBeenModified ( )
inline

Definition at line 119 of file G4RunManagerKernel.hh.

119{ geometryNeedsToBeClosed = true; }

◆ GetCurrentWorld()

G4VPhysicalVolume * G4RunManagerKernel::GetCurrentWorld ( ) const
inline

Definition at line 162 of file G4RunManagerKernel.hh.

162{ return currentWorld; }

Referenced by G4WorkerRunManager::InitializeGeometry().

◆ GetEventManager()

G4EventManager * G4RunManagerKernel::GetEventManager ( ) const
inline

Definition at line 127 of file G4RunManagerKernel.hh.

127{ return eventManager; }

◆ GetNumberOfParallelWorld()

G4int G4RunManagerKernel::GetNumberOfParallelWorld ( ) const
inline

Definition at line 157 of file G4RunManagerKernel.hh.

157{ return numberOfParallelWorld; }

Referenced by G4PhysicsListHelper::AddTransportation(), and G4WorkerRunManager::InitializeGeometry().

◆ GetNumberOfStaticAllocators()

G4int G4RunManagerKernel::GetNumberOfStaticAllocators ( ) const
inline

Definition at line 164 of file G4RunManagerKernel.hh.

164{ return numberOfStaticAllocators; }

◆ GetPhysicsList()

G4VUserPhysicsList * G4RunManagerKernel::GetPhysicsList ( ) const
inline

Definition at line 160 of file G4RunManagerKernel.hh.

160{ return physicsList; }

◆ GetPrimaryTransformer()

G4PrimaryTransformer * G4RunManagerKernel::GetPrimaryTransformer ( ) const
inline

Definition at line 137 of file G4RunManagerKernel.hh.

138 {
139 return eventManager->GetPrimaryTransformer();
140 }

Referenced by RunInitialization().

◆ GetRunManagerKernel()

G4RunManagerKernel * G4RunManagerKernel::GetRunManagerKernel ( )
static

Definition at line 91 of file G4RunManagerKernel.cc.

92{
93 return fRunManagerKernel;
94}

Referenced by G4PhysicsListHelper::AddTransportation(), G4VisManager::Disable(), and G4ErrorRunManagerHelper::G4ErrorRunManagerHelper().

◆ GetStackManager()

G4StackManager * G4RunManagerKernel::GetStackManager ( ) const
inline

Definition at line 128 of file G4RunManagerKernel.hh.

128{ return eventManager->GetStackManager(); }

◆ GetTrackingManager()

G4TrackingManager * G4RunManagerKernel::GetTrackingManager ( ) const
inline

Definition at line 129 of file G4RunManagerKernel.hh.

130 {
131 return eventManager->GetTrackingManager();
132 }

Referenced by G4VisManager::Disable().

◆ GetVersionString()

const G4String & G4RunManagerKernel::GetVersionString ( ) const
inline

Definition at line 142 of file G4RunManagerKernel.hh.

142{ return versionString; }

◆ InitializePhysics()

void G4RunManagerKernel::InitializePhysics ( )

Definition at line 553 of file G4RunManagerKernel.cc.

554{
555 G4StateManager* stateManager = G4StateManager::GetStateManager();
556 G4ApplicationState currentState = stateManager->GetCurrentState();
557 if (currentState != G4State_Init) {
558 G4cout << "Current application state is " << stateManager->GetStateString(currentState)
559 << G4endl;
560 if (currentState != G4State_Idle && currentState != G4State_PreInit) {
561 G4Exception("G4RunManagerKernel::InitializePhysics", "InitializePhysicsIncorrectState",
562 FatalException, "Geant4 kernel is not Init state : Method ignored.");
563 return;
564 }
565
566 G4cout << "Warning : Geant4 kernel is not Init state : Assuming Init state." << G4endl;
567 stateManager->SetNewState(G4State_Init);
568 }
569
570 if (physicsList == nullptr) {
571 G4Exception("G4RunManagerKernel::InitializePhysics", "Run0012", FatalException,
572 "G4VUserPhysicsList is not defined");
573 return;
574 }
575
576 if (verboseLevel > 1) G4cout << "physicsList->Construct() start." << G4endl;
577 if (numberOfParallelWorld > 0) physicsList->UseCoupledTransportation();
578 physicsList->Construct();
579
580 if (verboseLevel > 1) G4cout << "physicsList->CheckParticleList() start." << G4endl;
581 physicsList->CheckParticleList();
582
583 // Cannot assume that SetCuts() and CheckRegions() are thread safe.
584 // We need to mutex (report from valgrind --tool=drd)
585 G4AutoLock l(&initphysicsmutex);
587 if (verboseLevel > 1) G4cout << "physicsList->setCut() start." << G4endl;
588 physicsList->SetCuts();
589 }
590 CheckRegions();
591 l.unlock();
592
593 physicsInitialized = true;
594
595#ifdef G4MULTITHREADED
596 G4UnitDefinition::GetUnitsTable().Synchronize();
597#endif
598
599 stateManager->SetNewState(currentState);
600 if (geometryInitialized && currentState != G4State_Idle) {
601 stateManager->SetNewState(G4State_Idle);
602 }
603}
G4TemplateAutoLock< G4Mutex > G4AutoLock

◆ PhysicsHasBeenModified()

void G4RunManagerKernel::PhysicsHasBeenModified ( )
inline

Definition at line 125 of file G4RunManagerKernel.hh.

125{ physicsNeedsToBeReBuilt = true; }

◆ PropagateGenericIonID()

void G4RunManagerKernel::PropagateGenericIonID ( )
protected

Definition at line 659 of file G4RunManagerKernel.cc.

660{
661 G4ParticleDefinition* gion = G4ParticleTable::GetParticleTable()->GetGenericIon();
662 if (gion != nullptr) {
663 G4int gionId = gion->GetParticleDefinitionID();
665 pItr->reset(false);
666 while ((*pItr)()) {
667 G4ParticleDefinition* particle = pItr->value();
668 if (particle->IsGeneralIon()) particle->SetParticleDefinitionID(gionId);
669 }
670 }
671}
G4bool IsGeneralIon() const
void SetParticleDefinitionID(G4int id=-1)
G4int GetParticleDefinitionID() const
void reset(G4bool ifSkipIon=true)
G4PTblDicIterator * GetIterator() const
G4ParticleDefinition * GetGenericIon() const

Referenced by RunInitialization().

◆ ResetNavigator()

void G4RunManagerKernel::ResetNavigator ( )
protected

Definition at line 682 of file G4RunManagerKernel.cc.

683{
684 G4GeometryManager* geomManager = G4GeometryManager::GetInstance();
686 // To ensure that it is called when using G4TaskRunManagerKernel
687 if( geomManager->IsParallelOptimisationConfigured() &&
688 !geomManager->IsParallelOptimisationFinished() )
689 {
690 geomManager->UndertakeOptimisation();
691 }
693 return;
694 }
695
696 // We have to tweak the navigator's state in case a geometry has been
697 // modified between runs. By the following calls we ensure that navigator's
698 // state is reset properly. It is required the geometry to be closed
699 // and previous optimisations to be cleared.
700
701 if (verboseLevel > 1) G4cout << "Start closing geometry." << G4endl;
702
703 geomManager->OpenGeometry();
704 geomManager->CloseGeometry(geometryToBeOptimized, verboseLevel > 1);
705
707}
G4bool CloseGeometry(G4bool pOptimise=true, G4bool verbose=false, G4VPhysicalVolume *vol=nullptr)
G4bool IsParallelOptimisationConfigured()
G4bool IsParallelOptimisationFinished()

Referenced by RunInitialization().

◆ ResetNavigatorAtInitialization()

void G4RunManagerKernel::ResetNavigatorAtInitialization ( G4bool val = true)
inline

Definition at line 154 of file G4RunManagerKernel.hh.

155 { resetNavigatorAtInitialization = val; }

◆ RunInitialization()

G4bool G4RunManagerKernel::RunInitialization ( G4bool fakeRun = false)

Definition at line 606 of file G4RunManagerKernel.cc.

607{
608 G4StateManager* stateManager = G4StateManager::GetStateManager();
609 G4ApplicationState currentState = stateManager->GetCurrentState();
610
611 if (!geometryInitialized) {
612 G4Exception("G4RunManagerKernel::RunInitialization", "Run0021", JustWarning,
613 "Geometry has not yet initialized : method ignored.");
614 return false;
615 }
616
617 if (!physicsInitialized) {
618 G4Exception("G4RunManagerKernel::RunInitialization", "Run0022", JustWarning,
619 "Physics has not yet initialized : method ignored.");
620 return false;
621 }
622
623 if (currentState != G4State_Idle) {
624 G4Exception("G4RunManagerKernel::RunInitialization", "Run0023", JustWarning,
625 "Geant4 kernel not in Idle state : method ignored.");
626 return false;
627 }
628
629 if (geometryNeedsToBeClosed) CheckRegularGeometry();
630
631 stateManager->SetNewState(G4State_Init);
634 UpdateRegion();
635 BuildPhysicsTables(fakeRun);
636
638 if(!fakeRun || resetNavigatorAtInitialization) ResetNavigator();
639 // CheckRegularGeometry();
640 // Notify the VisManager as well
642 G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
643 if (pVVisManager != nullptr) pVVisManager->GeometryHasChanged();
644 }
645 }
646
648
649#ifdef G4MULTITHREADED
650 G4UnitDefinition::GetUnitsTable().Synchronize();
651#endif
652
653 stateManager->SetNewState(G4State_Idle);
654 stateManager->SetNewState(G4State_GeomClosed);
655 return true;
656}
@ G4State_GeomClosed
@ JustWarning
G4PrimaryTransformer * GetPrimaryTransformer() const
virtual void SetupShadowProcess() const
void BuildPhysicsTables(G4bool fakeRun)

◆ RunTermination()

void G4RunManagerKernel::RunTermination ( )

◆ SetGeometryToBeOptimized()

void G4RunManagerKernel::SetGeometryToBeOptimized ( G4bool vl)
inline

Definition at line 146 of file G4RunManagerKernel.hh.

147 {
148 if (geometryToBeOptimized != vl) {
149 geometryToBeOptimized = vl;
151 }
152 }

◆ SetNumberOfParallelWorld()

void G4RunManagerKernel::SetNumberOfParallelWorld ( G4int i)
inline

Definition at line 158 of file G4RunManagerKernel.hh.

158{ numberOfParallelWorld = i; }

◆ SetPhysics()

void G4RunManagerKernel::SetPhysics ( G4VUserPhysicsList * uPhys)

Definition at line 489 of file G4RunManagerKernel.cc.

490{
491 physicsList = uPhys;
492
493 if (runManagerKernelType == workerRMK) return;
494
495 SetupPhysics();
496 if (verboseLevel > 2) G4ParticleTable::GetParticleTable()->DumpTable();
497 if (verboseLevel > 1) {
498 G4cout << "List of instantiated particles "
499 "============================================"
500 << G4endl;
502 for (G4int i = 0; i < nPtcl; ++i) {
503 G4ParticleDefinition* pd = G4ParticleTable::GetParticleTable()->GetParticle(i);
504 G4cout << pd->GetParticleName() << " ";
505 if (i % 10 == 9) G4cout << G4endl;
506 }
507 G4cout << G4endl;
508 }
509}
void DumpTable(const G4String &particle_name="ALL")

◆ SetPrimaryTransformer()

void G4RunManagerKernel::SetPrimaryTransformer ( G4PrimaryTransformer * pt)
inline

Definition at line 133 of file G4RunManagerKernel.hh.

134 {
135 eventManager->SetPrimaryTransformer(pt);
136 }

◆ SetupDefaultRegion()

void G4RunManagerKernel::SetupDefaultRegion ( )
protected

Definition at line 282 of file G4RunManagerKernel.cc.

283{
284 if (runManagerKernelType == workerRMK) return;
285
286 // Remove old world logical volume from the default region, if exist
287 if (defaultRegion->GetNumberOfRootVolumes() != 0u) {
288 if (defaultRegion->GetNumberOfRootVolumes() > size_t(1)) {
289 G4Exception("G4RunManager::SetupDefaultRegion", "Run0005", FatalException,
290 "Default world region should have a unique logical volume.");
291 }
292 auto lvItr = defaultRegion->GetRootLogicalVolumeIterator();
293 defaultRegion->RemoveRootLogicalVolume(*lvItr, false);
294 if (verboseLevel > 1)
295 G4cout << "Obsolete world logical volume is removed from the default region." << G4endl;
296 }
297}

Referenced by DefineWorldVolume().

◆ SetupPhysics()

void G4RunManagerKernel::SetupPhysics ( )
protected

Definition at line 512 of file G4RunManagerKernel.cc.

513{
515
516 physicsList->ConstructParticle();
517
518 // For sanity reason
520 G4ParticleDefinition* gion = G4ParticleTable::GetParticleTable()->GetGenericIon();
521 if (gion != nullptr) {
523 }
525
527 pItr->reset();
528 while ((*pItr)()) {
529 G4ParticleDefinition* particle = pItr->value();
530 if (!(particle->IsGeneralIon())) particle->SetParticleDefinitionID();
531 }
532
533 if (gion != nullptr) {
534 G4int gionId = gion->GetParticleDefinitionID();
535 pItr->reset(false);
536 while ((*pItr)()) {
537 G4ParticleDefinition* particle = pItr->value();
538 if (particle->IsGeneralIon()) particle->SetParticleDefinitionID(gionId);
539 }
540 }
541#ifdef G4MULTITHREADED
542 G4UnitDefinition::GetUnitsTable().Synchronize();
543#endif
544}
static G4Geantino * GeantinoDefinition()
Definition G4Geantino.cc:76
static void ConstructParticle()
void InitializeLightIons()
G4IonTable * GetIonTable() const
void SetReadiness(G4bool val=true)

Referenced by SetPhysics().

◆ SetupShadowProcess()

void G4RunManagerKernel::SetupShadowProcess ( ) const
protectedvirtual

Reimplemented in G4MTRunManagerKernel, G4TaskRunManagerKernel, G4WorkerRunManagerKernel, and G4WorkerTaskRunManagerKernel.

Definition at line 945 of file G4RunManagerKernel.cc.

946{
947 G4ParticleTable* theParticleTable = G4ParticleTable::GetParticleTable();
948 auto theParticleIterator = theParticleTable->GetIterator();
950 // loop on particles and get process manager from there list of processes
951 while ((*theParticleIterator)()) {
952 G4ParticleDefinition* pd = theParticleIterator->value();
953 G4ProcessManager* pm = pd->GetProcessManager();
954 if (pm != nullptr) {
955 G4ProcessVector& procs = *(pm->GetProcessList());
956 for (G4int idx = 0; idx < (G4int)procs.size(); ++idx) {
957 const G4VProcess* masterP = procs[idx]->GetMasterProcess();
958 if (masterP == nullptr) {
959 // Process does not have an associated shadow master process
960 // We are in master mode or sequential
961 procs[idx]->SetMasterProcess(const_cast<G4VProcess*>(procs[idx]));
962 }
963 }
964 }
965 }
966}
#define theParticleIterator
G4ProcessManager * GetProcessManager() const
G4ProcessVector * GetProcessList() const
std::size_t size() const

Referenced by RunInitialization(), G4MTRunManagerKernel::SetupShadowProcess(), and G4TaskRunManagerKernel::SetupShadowProcess().

◆ SetVerboseLevel()

void G4RunManagerKernel::SetVerboseLevel ( G4int vl)
inline

Definition at line 144 of file G4RunManagerKernel.hh.

144{ verboseLevel = vl; }

◆ UpdateRegion()

void G4RunManagerKernel::UpdateRegion ( )

Definition at line 710 of file G4RunManagerKernel.cc.

711{
712 G4StateManager* stateManager = G4StateManager::GetStateManager();
713 G4ApplicationState currentState = stateManager->GetCurrentState();
714 if (currentState != G4State_Init) {
715 G4Exception("G4RunManagerKernel::UpdateRegion", "Run0024", JustWarning,
716 "Geant4 kernel not in Init state : method ignored.");
717 return;
718 }
719
720 if (runManagerKernelType == workerRMK) return;
721
722 CheckRegions();
723
725
727}
void UpdateCoupleTable(G4VPhysicalVolume *currentWorld)
void UpdateMaterialList(G4VPhysicalVolume *currentWorld=nullptr)

Referenced by RunInitialization().

◆ WorkerDefineWorldVolume()

void G4RunManagerKernel::WorkerDefineWorldVolume ( G4VPhysicalVolume * worldVol,
G4bool topologyIsChanged = true )

Definition at line 380 of file G4RunManagerKernel.cc.

382{
383 G4StateManager* stateManager = G4StateManager::GetStateManager();
384 G4ApplicationState currentState = stateManager->GetCurrentState();
385 if (currentState != G4State_Init) {
386 if (currentState != G4State_Idle && currentState != G4State_PreInit) {
387 G4cout << "Current application state is " << stateManager->GetStateString(currentState)
388 << G4endl;
389 G4Exception("G4RunManagerKernel::DefineWorldVolume", "DefineWorldVolumeAtIncorrectState",
390 FatalException, "Geant4 kernel is not Init state : Method ignored.");
391 return;
392 }
393
394 stateManager->SetNewState(G4State_Init);
395 }
396
397 currentWorld = worldVol;
398 G4MTRunManager* masterRM = G4MTRunManager::GetMasterRunManager();
399 G4TransportationManager* transM = G4TransportationManager::GetTransportationManager();
400 G4MTRunManager::masterWorlds_t masterWorlds = masterRM->GetMasterWorlds();
401 for (const auto& masterWorld : masterWorlds) {
402 if (masterWorld.first == 0) {
403 if (masterWorld.second != currentWorld) {
404 G4Exception("G4RunManagerKernel::WorkerDefineWorldVolume", "RUN3091", FatalException,
405 "Mass world is inconsistent");
406 }
407 transM->SetWorldForTracking(masterWorld.second);
408 }
409 else {
410 transM->RegisterWorld(masterWorld.second);
411 }
412 }
413
414 if (topologyIsChanged) geometryNeedsToBeClosed = true;
415
416 // Notify the VisManager as well
418 G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
419 if (pVVisManager != nullptr) pVVisManager->GeometryHasChanged();
420 }
421
422 geometryInitialized = true;
423 stateManager->SetNewState(currentState);
424 if (physicsInitialized && currentState != G4State_Idle) {
425 stateManager->SetNewState(G4State_Idle);
426 }
427}
static G4MTRunManager * GetMasterRunManager()
std::map< G4int, G4VPhysicalVolume * > masterWorlds_t
static masterWorlds_t & GetMasterWorlds()
G4bool RegisterWorld(G4VPhysicalVolume *aWorld)

◆ WorkerUpdateWorldVolume()

void G4RunManagerKernel::WorkerUpdateWorldVolume ( )

Definition at line 364 of file G4RunManagerKernel.cc.

365{
366 G4MTRunManager* masterRM = G4MTRunManager::GetMasterRunManager();
367 G4TransportationManager* transM = G4TransportationManager::GetTransportationManager();
368 G4MTRunManager::masterWorlds_t masterWorlds = masterRM->GetMasterWorlds();
369 for (const auto& masterWorld : masterWorlds) {
370 G4VPhysicalVolume* wv = masterWorld.second;
371 G4VPhysicalVolume* pWorld =
373 if (pWorld == nullptr) {
374 transM->RegisterWorld(wv);
375 }
376 }
377}
G4VPhysicalVolume * IsWorldExisting(const G4String &worldName)

Member Data Documentation

◆ defaultRegion

G4Region* G4RunManagerKernel::defaultRegion = nullptr
protected

◆ defaultRegionForParallelWorld

G4Region* G4RunManagerKernel::defaultRegionForParallelWorld = nullptr
protected

Definition at line 199 of file G4RunManagerKernel.hh.

Referenced by CheckRegions(), G4RunManagerKernel(), and G4RunManagerKernel().

◆ geometryNeedsToBeClosed

G4bool G4RunManagerKernel::geometryNeedsToBeClosed = true
protected

◆ runManagerKernelType


The documentation for this class was generated from the following files: