Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/run/src/G4RunManagerKernel.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /run/src/G4RunManagerKernel.cc (Version 11.3.0) and /run/src/G4RunManagerKernel.cc (Version 9.6)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 // G4RunManagerKernel implementation           << 
 27 //                                                 26 //
 28 // Author: M.Asai, 1 August 2003               <<  27 // $Id$
 29 // ------------------------------------------- <<  28 //
                                                   >>  29 //
 30                                                    30 
 31 #include "G4RunManagerKernel.hh"                   31 #include "G4RunManagerKernel.hh"
 32                                                    32 
 33 #include "G4AllocatorList.hh"                  <<  33 #include <vector>
                                                   >>  34 
                                                   >>  35 #include "G4StateManager.hh"
 34 #include "G4ApplicationState.hh"                   36 #include "G4ApplicationState.hh"
 35 #include "G4AutoLock.hh"                       << 
 36 #include "G4ExceptionHandler.hh"                   37 #include "G4ExceptionHandler.hh"
 37 #include "G4FieldManagerStore.hh"              <<  38 #include "G4PrimaryTransformer.hh"
 38 #include "G4Geantino.hh"                       << 
 39 #include "G4GeometryManager.hh"                    39 #include "G4GeometryManager.hh"
 40 #include "G4IonConstructor.hh"                 <<  40 #include "G4TransportationManager.hh"
 41 #include "G4IonTable.hh"                       <<  41 #include "G4VPhysicalVolume.hh"
 42 #include "G4LogicalVolume.hh"                      42 #include "G4LogicalVolume.hh"
 43 #include "G4LogicalVolumeStore.hh"             <<  43 #include "G4VUserPhysicsList.hh"
 44 #include "G4MTRunManager.hh"                   << 
 45 #include "G4NavigationHistoryPool.hh"          << 
 46 #include "G4ParallelWorldProcessStore.hh"      << 
 47 #include "G4ParticleDefinition.hh"             << 
 48 #include "G4ParticleTable.hh"                      44 #include "G4ParticleTable.hh"
 49 #include "G4ParticleTableIterator.hh"          << 
 50 #include "G4PathFinder.hh"                     << 
 51 #include "G4PrimaryTransformer.hh"             << 
 52 #include "G4ProcessManager.hh"                 << 
 53 #include "G4ProcessVector.hh"                  << 
 54 #include "G4ProductionCuts.hh"                 << 
 55 #include "G4ProductionCutsTable.hh"            << 
 56 #include "G4RNGHelper.hh"                      << 
 57 #include "G4Region.hh"                             45 #include "G4Region.hh"
 58 #include "G4RegionStore.hh"                        46 #include "G4RegionStore.hh"
                                                   >>  47 #include "G4ProductionCuts.hh"
                                                   >>  48 #include "G4ProductionCutsTable.hh"
 59 #include "G4SDManager.hh"                          49 #include "G4SDManager.hh"
 60 #include "G4ScoreSplittingProcess.hh"          << 
 61 #include "G4StateManager.hh"                   << 
 62 #include "G4TransportationManager.hh"          << 
 63 #include "G4UImanager.hh"                          50 #include "G4UImanager.hh"
 64 #include "G4UnitsTable.hh"                     << 
 65 #include "G4VPhysicalVolume.hh"                << 
 66 #include "G4VProcess.hh"                       << 
 67 #include "G4VUserPhysicsList.hh"               << 
 68 #include "G4VVisManager.hh"                        51 #include "G4VVisManager.hh"
                                                   >>  52 #include "G4UnitsTable.hh"
 69 #include "G4Version.hh"                            53 #include "G4Version.hh"
 70 #include "G4ios.hh"                                54 #include "G4ios.hh"
 71                                                    55 
 72 #include <vector>                              << 
 73                                                << 
 74 #ifdef G4BT_DEBUG                              << 
 75 #  include "G4Backtrace.hh"                    << 
 76 #endif                                         << 
 77                                                << 
 78 #ifdef G4FPE_DEBUG                                 56 #ifdef G4FPE_DEBUG
 79 #  include "G4FPEDetection.hh"                 <<  57   #include "G4FPEDetection.hh"
 80 #endif                                         << 
 81                                                << 
 82 // The following lines are needed since G4VUse << 
 83 // uses a #define theParticleIterator          << 
 84 #ifdef theParticleIterator                     << 
 85 #  undef theParticleIterator                   << 
 86 #endif                                             58 #endif
 87                                                    59 
 88 G4ThreadLocal G4RunManagerKernel* G4RunManager <<  60 G4RunManagerKernel* G4RunManagerKernel::fRunManagerKernel = 0;
 89                                                    61 
 90 // ------------------------------------------- << 
 91 G4RunManagerKernel* G4RunManagerKernel::GetRun     62 G4RunManagerKernel* G4RunManagerKernel::GetRunManagerKernel()
 92 {                                              <<  63 { return fRunManagerKernel; }
 93   return fRunManagerKernel;                    << 
 94 }                                              << 
 95                                                    64 
 96 // ------------------------------------------- << 
 97 G4RunManagerKernel::G4RunManagerKernel()           65 G4RunManagerKernel::G4RunManagerKernel()
                                                   >>  66 :physicsList(0),currentWorld(0),
                                                   >>  67  geometryInitialized(false),physicsInitialized(false),
                                                   >>  68  geometryNeedsToBeClosed(true),geometryToBeOptimized(true),
                                                   >>  69  physicsNeedsToBeReBuilt(true),verboseLevel(0),
                                                   >>  70  numberOfParallelWorld(0)
 98 {                                                  71 {
 99 #ifdef G4FPE_DEBUG                                 72 #ifdef G4FPE_DEBUG
100   InvalidOperationDetection();                     73   InvalidOperationDetection();
101 #endif                                             74 #endif
102                                                    75 
103 #ifdef G4BT_DEBUG                              <<  76   defaultExceptionHandler = new G4ExceptionHandler();
104   auto _signals = G4GetEnv<std::string>("G4BAC <<  77   if(fRunManagerKernel)
105   if (_signals.empty()) {                      <<  78   {
106     G4Backtrace::Enable();                     <<  79     G4Exception("G4RunManagerKernel::G4RunManagerKernel()","Run0001",
107   }                                            <<  80                 FatalException,"More than one G4RunManagerKernel is constructed.");
108   else {                                       << 
109     G4Backtrace::Enable(_signals);             << 
110   }                                            << 
111 #endif                                         << 
112                                                << 
113   G4AllocatorList* allocList = G4AllocatorList << 
114   if (allocList != nullptr) numberOfStaticAllo << 
115                                                << 
116   if (G4StateManager::GetStateManager()->GetEx << 
117     defaultExceptionHandler = new G4ExceptionH << 
118   }                                            << 
119   if (fRunManagerKernel != nullptr) {          << 
120     G4Exception("G4RunManagerKernel::G4RunMana << 
121                 "More than one G4RunManagerKer << 
122   }                                                81   }
123   fRunManagerKernel = this;                        82   fRunManagerKernel = this;
124                                                    83 
125   G4ParticleTable* particleTable = G4ParticleT     84   G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
126   if (particleTable->entries() > 0) {          <<  85   if(particleTable->entries()>0)
                                                   >>  86   {
127     // No particle should be registered before     87     // No particle should be registered beforehand
128     G4ExceptionDescription ED;                     88     G4ExceptionDescription ED;
129     ED << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! <<  89     ED<<"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"<<G4endl;
130     ED << " G4RunManagerKernel fatal exception <<  90     ED<<" G4RunManagerKernel fatal exception"<<G4endl;
131     ED << "  -- Following particles have alrea <<  91     ED<<"  -- Following particles have already been registered"<<G4endl;
132     ED << "     before G4RunManagerKernel is i <<  92     ED<<"     before G4RunManagerKernel is instantiated."<<G4endl;
133     for (G4int i = 0; i < particleTable->entri <<  93     for(int i=0;i<particleTable->entries();i++)
134       ED << "     " << particleTable->GetParti <<  94     { ED<<"     "<<particleTable->GetParticle(i)->GetParticleName()<<G4endl; }
135     }                                          <<  95     ED<<"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"<<G4endl;
136     ED << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! <<  96     G4Exception("G4RunManagerKernel::G4RunManagerKernel()","Run0002",
137     G4Exception("G4RunManagerKernel::G4RunMana <<  97        FatalException,ED);
138   }                                                98   }
139                                                <<  99   
140   // construction of Geant4 kernel classes        100   // construction of Geant4 kernel classes
141   eventManager = new G4EventManager();            101   eventManager = new G4EventManager();
142                                                << 102   defaultRegion = new G4Region("DefaultRegionForTheWorld"); // deleted by store
143   defaultRegion = new G4Region("DefaultRegionF << 103   defaultRegionForParallelWorld = new G4Region("DefaultRegionForParallelWorld"); // deleted by store
144   defaultRegionForParallelWorld =              << 
145     new G4Region("DefaultRegionForParallelWorl << 
146   defaultRegion->SetProductionCuts(               104   defaultRegion->SetProductionCuts(
147     G4ProductionCutsTable::GetProductionCutsTa    105     G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts());
148   defaultRegionForParallelWorld->SetProduction    106   defaultRegionForParallelWorld->SetProductionCuts(
149     G4ProductionCutsTable::GetProductionCutsTa    107     G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts());
150                                                   108 
151   runManagerKernelType = sequentialRMK;        << 109   // Following line is tentatively moved from SetPhysics method
                                                   >> 110   // Commented out for introduction of non-static particle definition // G4ParticleTable::GetParticleTable()->SetReadiness();
152   // set the initial application state            111   // set the initial application state
153   G4StateManager::GetStateManager()->SetNewSta    112   G4StateManager::GetStateManager()->SetNewState(G4State_PreInit);
154                                                   113 
155   // version banner                               114   // version banner
156   G4String vs = G4Version;                        115   G4String vs = G4Version;
157   vs = vs.substr(1, vs.size() - 2);            << 116   vs = vs.substr(1,vs.size()-2);
158   versionString = " Geant4 version ";             117   versionString = " Geant4 version ";
159   versionString += vs;                            118   versionString += vs;
160   versionString += "   ";                         119   versionString += "   ";
161   versionString += G4Date;                        120   versionString += G4Date;
162   G4cout << G4endl << "*********************** << 121   G4cout << G4endl
163          << versionString << G4endl << "       << 122     << "*************************************************************" << G4endl
164          << G4endl << "                      R << 123     << versionString << G4endl
165          << "                                  << 124     << "                      Copyright : Geant4 Collaboration" << G4endl
166          << "                                  << 125     << "                      Reference : NIM A 506 (2003), 250-303" << G4endl
167          << "                             WWW  << 126     << "                            WWW : http://cern.ch/geant4" << G4endl
168          << "********************************* << 127     << "*************************************************************" << G4endl
169 }                                              << 128     << G4endl;
170                                                << 
171 // ------------------------------------------- << 
172 G4RunManagerKernel::G4RunManagerKernel(RMKType << 
173 {                                              << 
174 // This version of the constructor should neve << 
175 #ifndef G4MULTITHREADED                        << 
176   G4ExceptionDescription msg;                  << 
177   msg << "Geant4 code is compiled without mult << 
178          "(-DG4MULTITHREADED is set to off)."; << 
179   msg << " This type of RunManagerKernel can o << 
180          "applications.";                      << 
181   G4Exception("G4RunManagerKernel::G4RunManage << 
182 #endif                                         << 
183                                                << 
184 #ifdef G4FPE_DEBUG                             << 
185   if (G4Threading::IsMasterThread()) {         << 
186     InvalidOperationDetection();               << 
187   }                                            << 
188 #endif                                         << 
189                                                << 
190 #ifdef G4BT_DEBUG                              << 
191   auto _signals = G4GetEnv<std::string>("G4BAC << 
192   if (_signals.empty()) {                      << 
193     G4Backtrace::Enable();                     << 
194   }                                            << 
195   else {                                       << 
196     G4Backtrace::Enable(_signals);             << 
197   }                                            << 
198 #endif                                         << 
199                                                << 
200   if (G4StateManager::GetStateManager()->GetEx << 
201     defaultExceptionHandler = new G4ExceptionH << 
202   }                                            << 
203                                                << 
204   if (fRunManagerKernel != nullptr) {          << 
205     G4Exception("G4RunManagerKernel::G4RunMana << 
206                 "More than one G4RunManagerKer << 
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("DefaultReg << 
216       defaultRegionForParallelWorld =          << 
217         new G4Region("DefaultRegionForParallel << 
218       defaultRegion->SetProductionCuts(        << 
219         G4ProductionCutsTable::GetProductionCu << 
220       defaultRegionForParallelWorld->SetProduc << 
221         G4ProductionCutsTable::GetProductionCu << 
222       break;                                   << 
223     case workerRMK:                            << 
224       // Worker thread behavior                << 
225       defaultRegion = G4RegionStore::GetInstan << 
226       defaultRegionForParallelWorld =          << 
227         G4RegionStore::GetInstance()->GetRegio << 
228       break;                                   << 
229     default:                                   << 
230       defaultRegion = nullptr;                 << 
231       defaultRegionForParallelWorld = nullptr; << 
232       G4ExceptionDescription msgx;             << 
233       msgx << " This type of RunManagerKernel  << 
234               "applications.";                 << 
235       G4Exception("G4RunManagerKernel::G4RunMa << 
236                   msgx);                       << 
237   }                                            << 
238   runManagerKernelType = rmkType;              << 
239                                                << 
240   // set the initial application state         << 
241   G4StateManager::GetStateManager()->SetNewSta << 
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 << "******************* << 
253              << versionString << G4endl << "   << 
254              << "                       Copyri << 
255              << "                      Referen << 
256              << "                              << 
257              << "                              << 
258              << "                              << 
259              << "***************************** << 
260              << G4endl;                        << 
261       break;                                   << 
262     default:                                   << 
263       if (verboseLevel != 0) {                 << 
264         versionString = " Local thread RunMana << 
265         versionString += vs;                   << 
266         G4cout << G4endl                       << 
267                << "^^^^^^^^^^^^^^^^^^^^^^^^^^^ << 
268                   "^^^^^^^^^"                  << 
269                << G4endl << versionString << G << 
270                << "^^^^^^^^^^^^^^^^^^^^^^^^^^^ << 
271                   "^^^^^^^^^"                  << 
272                << G4endl << G4endl;            << 
273       }                                        << 
274   }                                            << 
275                                                << 
276 #ifdef G4MULTITHREADED                         << 
277   G4UnitDefinition::GetUnitsTable().Synchroniz << 
278 #endif                                         << 
279 }                                                 129 }
280                                                   130 
281 // ------------------------------------------- << 
282 void G4RunManagerKernel::SetupDefaultRegion()  << 
283 {                                              << 
284   if (runManagerKernelType == workerRMK) retur << 
285                                                << 
286   // Remove old world logical volume from the  << 
287   if (defaultRegion->GetNumberOfRootVolumes()  << 
288     if (defaultRegion->GetNumberOfRootVolumes( << 
289       G4Exception("G4RunManager::SetupDefaultR << 
290                   "Default world region should << 
291     }                                          << 
292     auto lvItr = defaultRegion->GetRootLogical << 
293     defaultRegion->RemoveRootLogicalVolume(*lv << 
294     if (verboseLevel > 1)                      << 
295       G4cout << "Obsolete world logical volume << 
296   }                                            << 
297 }                                              << 
298                                                << 
299 // ------------------------------------------- << 
300 G4RunManagerKernel::~G4RunManagerKernel()         131 G4RunManagerKernel::~G4RunManagerKernel()
301 {                                                 132 {
302   G4StateManager* pStateManager = G4StateManag    133   G4StateManager* pStateManager = G4StateManager::GetStateManager();
303   // set the application state to the quite st    134   // set the application state to the quite state
304   if (pStateManager->GetCurrentState() != G4St << 135   if(pStateManager->GetCurrentState()!=G4State_Quit)
305     if (verboseLevel > 1) G4cout << "G4 kernel << 136   {
                                                   >> 137     if(verboseLevel>0) G4cout << "G4 kernel has come to Quit state." << G4endl;
306     pStateManager->SetNewState(G4State_Quit);     138     pStateManager->SetNewState(G4State_Quit);
307   }                                               139   }
308                                                   140 
309   // open geometry for deletion                   141   // open geometry for deletion
310   G4GeometryManager::GetInstance()->OpenGeomet    142   G4GeometryManager::GetInstance()->OpenGeometry();
311                                                   143 
312   // deletion of Geant4 kernel classes            144   // deletion of Geant4 kernel classes
313   delete G4ParallelWorldProcessStore::GetInsta << 145   G4SDManager* fSDM = G4SDManager::GetSDMpointerIfExist();
314   delete G4SDManager::GetSDMpointerIfExist();  << 146   if(fSDM)
315   if (verboseLevel > 1) G4cout << "G4SDManager << 147   {
316   delete eventManager;                         << 148     delete fSDM;
317   if (verboseLevel > 1) G4cout << "EventManage << 149     if(verboseLevel>1) G4cout << "G4SDManager deleted." << G4endl;
318                                                << 
319   G4UnitDefinition::ClearUnitsTable();         << 
320   if (verboseLevel > 1) G4cout << "Units table << 
321                                                << 
322   // deletion of path-finder field-manager sto << 
323   // manager                                   << 
324   delete G4PathFinder::GetInstanceIfExist();   << 
325   delete G4FieldManagerStore::GetInstanceIfExi << 
326   delete G4GeometryManager::GetInstanceIfExist << 
327   delete G4TransportationManager::GetInstanceI << 
328   if (verboseLevel > 1) G4cout << "Transportat << 
329                                                << 
330   // deletion of navigation levels             << 
331   if (verboseLevel > 1) G4NavigationHistoryPoo << 
332   delete G4NavigationHistoryPool::GetInstance( << 
333                                                << 
334   // deletion of G4RNGHelper singleton         << 
335   if (runManagerKernelType != workerRMK) {     << 
336     delete G4RNGHelper::GetInstanceIfExist();  << 
337     if (verboseLevel > 1) G4cout << "G4RNGHelp << 
338   }                                            << 
339                                                << 
340   // deletion of allocators                    << 
341   G4AllocatorList* allocList = G4AllocatorList << 
342   if (allocList != nullptr) {                  << 
343     allocList->Destroy(numberOfStaticAllocator << 
344     delete allocList;                          << 
345     if (verboseLevel > 1) G4cout << "G4Allocat << 
346   }                                               150   }
347                                                << 151   delete eventManager;
                                                   >> 152   if(verboseLevel>1) G4cout << "EventManager deleted." << G4endl;
348   G4UImanager* pUImanager = G4UImanager::GetUI    153   G4UImanager* pUImanager = G4UImanager::GetUIpointer();
349   if ((runManagerKernelType == workerRMK) && ( << 154   {
350     G4cout << "Thread-local UImanager is to be << 155     if(pUImanager) delete pUImanager;
351            << "There should not be any thread- << 156     if(verboseLevel>1) G4cout << "UImanager deleted." << G4endl;
352   }                                               157   }
353   delete pUImanager;                           << 158   G4UnitDefinition::ClearUnitsTable();
354   if (verboseLevel > 1) G4cout << "UImanager d << 159   if(verboseLevel>1) G4cout << "Units table cleared." << G4endl;
355                                                << 160   delete pStateManager; 
356   delete pStateManager;                        << 161   if(verboseLevel>1) G4cout << "StateManager deleted." << G4endl;
357   if (verboseLevel > 1) G4cout << "StateManage << 
358   delete defaultExceptionHandler;                 162   delete defaultExceptionHandler;
359   if (verboseLevel > 1) G4cout << "RunManagerK << 163   if(verboseLevel>1) G4cout << "RunManagerKernel is deleted." << G4endl;
360   fRunManagerKernel = nullptr;                 << 164   fRunManagerKernel = 0;
361 }                                                 165 }
362                                                   166 
363 // ------------------------------------------- << 167 void G4RunManagerKernel::DefineWorldVolume(G4VPhysicalVolume* worldVol,
364 void G4RunManagerKernel::WorkerUpdateWorldVolu << 168                                      G4bool topologyIsChanged)
365 {                                                 169 {
366   G4MTRunManager* masterRM = G4MTRunManager::G << 170   G4StateManager*    stateManager = G4StateManager::GetStateManager();
367   G4TransportationManager* transM = G4Transpor << 
368   G4MTRunManager::masterWorlds_t masterWorlds  << 
369   for (const auto& masterWorld : masterWorlds) << 
370     G4VPhysicalVolume* wv = masterWorld.second << 
371     G4VPhysicalVolume* pWorld =                << 
372       G4TransportationManager::GetTransportati << 
373     if (pWorld == nullptr) {                   << 
374       transM->RegisterWorld(wv);               << 
375     }                                          << 
376   }                                            << 
377 }                                              << 
378                                                << 
379 // ------------------------------------------- << 
380 void G4RunManagerKernel::WorkerDefineWorldVolu << 
381                                                << 
382 {                                              << 
383   G4StateManager* stateManager = G4StateManage << 
384   G4ApplicationState currentState = stateManag    171   G4ApplicationState currentState = stateManager->GetCurrentState();
385   if (currentState != G4State_Init) {          << 172   if(!(currentState==G4State_Idle||currentState==G4State_PreInit))
386     if (currentState != G4State_Idle && curren << 173   { 
387       G4cout << "Current application state is  << 174     G4Exception("G4RunManagerKernel::DefineWorldVolume",
388              << G4endl;                        << 175                 "Run00031",
389       G4Exception("G4RunManagerKernel::DefineW << 176                 JustWarning,
390                   FatalException, "Geant4 kern << 177                 "Geant4 kernel is not PreInit or Idle state : Method ignored.");
391       return;                                  << 178     return;
392     }                                          << 
393                                                << 
394     stateManager->SetNewState(G4State_Init);   << 
395   }                                            << 
396                                                << 
397   currentWorld = worldVol;                     << 
398   G4MTRunManager* masterRM = G4MTRunManager::G << 
399   G4TransportationManager* transM = G4Transpor << 
400   G4MTRunManager::masterWorlds_t masterWorlds  << 
401   for (const auto& masterWorld : masterWorlds) << 
402     if (masterWorld.first == 0) {              << 
403       if (masterWorld.second != currentWorld)  << 
404         G4Exception("G4RunManagerKernel::Worke << 
405                     "Mass world is inconsisten << 
406       }                                        << 
407       transM->SetWorldForTracking(masterWorld. << 
408     }                                          << 
409     else {                                     << 
410       transM->RegisterWorld(masterWorld.second << 
411     }                                          << 
412   }                                            << 
413                                                << 
414   if (topologyIsChanged) geometryNeedsToBeClos << 
415                                                << 
416   // Notify the VisManager as well             << 
417   if (G4Threading::IsMasterThread()) {         << 
418     G4VVisManager* pVVisManager = G4VVisManage << 
419     if (pVVisManager != nullptr) pVVisManager- << 
420   }                                            << 
421                                                << 
422   geometryInitialized = true;                  << 
423   stateManager->SetNewState(currentState);     << 
424   if (physicsInitialized && currentState != G4 << 
425     stateManager->SetNewState(G4State_Idle);   << 
426   }                                            << 
427 }                                              << 
428                                                << 
429 // ------------------------------------------- << 
430 void G4RunManagerKernel::DefineWorldVolume(G4V << 
431 {                                              << 
432   G4StateManager* stateManager = G4StateManage << 
433   G4ApplicationState currentState = stateManag << 
434                                                << 
435   if (currentState != G4State_Init) {          << 
436     if (currentState != G4State_Idle && curren << 
437       G4cout << "Current application state is  << 
438              << G4endl;                        << 
439       G4Exception("G4RunManagerKernel::DefineW << 
440                   FatalException, "Geant4 kern << 
441       return;                                  << 
442     }                                          << 
443                                                << 
444     stateManager->SetNewState(G4State_Init);   << 
445   }                                               179   }
446                                                   180 
447   // The world volume MUST NOT have a region d    181   // The world volume MUST NOT have a region defined by the user
448   if (worldVol->GetLogicalVolume()->GetRegion( << 182   if(worldVol->GetLogicalVolume()->GetRegion())
449     if (worldVol->GetLogicalVolume()->GetRegio << 183   {
                                                   >> 184     if(worldVol->GetLogicalVolume()->GetRegion()!=defaultRegion)
                                                   >> 185     {
450       G4ExceptionDescription ED;                  186       G4ExceptionDescription ED;
451       ED << "The world volume has a user-defin    187       ED << "The world volume has a user-defined region <"
452          << worldVol->GetLogicalVolume()->GetR << 188            << worldVol->GetLogicalVolume()->GetRegion()->GetName()
453       ED << "World would have a default region << 189            << ">." << G4endl;
454       G4Exception("G4RunManager::DefineWorldVo << 190       ED << "World would have a default region assigned by RunManagerKernel."
                                                   >> 191          << G4endl;
                                                   >> 192       G4Exception("G4RunManager::DefineWorldVolume",
                                                   >> 193                 "Run0004", FatalException, ED);
455     }                                             194     }
456   }                                               195   }
457                                                   196 
458   SetupDefaultRegion();                        << 197   // Remove old world logical volume from the default region, if exist
                                                   >> 198   if(defaultRegion->GetNumberOfRootVolumes())
                                                   >> 199   {
                                                   >> 200     if(defaultRegion->GetNumberOfRootVolumes()>size_t(1))
                                                   >> 201     {
                                                   >> 202       G4Exception("G4RunManager::DefineWorldVolume",
                                                   >> 203                 "Run0005",
                                                   >> 204                 FatalException,
                                                   >> 205                 "Default world region should have a unique logical volume.");
                                                   >> 206     }
                                                   >> 207     std::vector<G4LogicalVolume*>::iterator lvItr
                                                   >> 208      = defaultRegion->GetRootLogicalVolumeIterator();
                                                   >> 209     defaultRegion->RemoveRootLogicalVolume(*lvItr,false);
                                                   >> 210     if(verboseLevel>1) G4cout 
                                                   >> 211      << "Obsolete world logical volume is removed from the default region." << G4endl;
                                                   >> 212   }
459                                                   213 
460   // Accept the world volume                      214   // Accept the world volume
461   currentWorld = worldVol;                     << 215   currentWorld = worldVol; 
462                                                   216 
463   // Set the default region to the world          217   // Set the default region to the world
464                                                << 
465   G4LogicalVolume* worldLog = currentWorld->Ge    218   G4LogicalVolume* worldLog = currentWorld->GetLogicalVolume();
466   worldLog->SetRegion(defaultRegion);             219   worldLog->SetRegion(defaultRegion);
467   defaultRegion->AddRootLogicalVolume(worldLog    220   defaultRegion->AddRootLogicalVolume(worldLog);
468   if (verboseLevel > 1)                        << 221   if(verboseLevel>1) G4cout << worldLog->GetName()
469     G4cout << worldLog->GetName() << " is regi << 222    << " is registered to the default region." << G4endl;
470                                                   223 
471   // Set the world volume, notify the Navigato    224   // Set the world volume, notify the Navigator and reset its state
472   G4TransportationManager::GetTransportationMa << 225   G4TransportationManager::GetTransportationManager()
473   if (topologyIsChanged) geometryNeedsToBeClos << 226       ->SetWorldForTracking(currentWorld);
474                                                << 227   if(topologyIsChanged) geometryNeedsToBeClosed = true;
                                                   >> 228   
475   // Notify the VisManager as well                229   // Notify the VisManager as well
476   if (G4Threading::IsMasterThread()) {         << 230   G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
477     G4VVisManager* pVVisManager = G4VVisManage << 231   if(pVVisManager) pVVisManager->GeometryHasChanged();
478     if (pVVisManager != nullptr) pVVisManager- << 
479   }                                            << 
480                                                   232 
481   geometryInitialized = true;                     233   geometryInitialized = true;
482   stateManager->SetNewState(currentState);     << 234   if(physicsInitialized && currentState!=G4State_Idle)
483   if (physicsInitialized && currentState != G4 << 235   { stateManager->SetNewState(G4State_Idle); }
484     stateManager->SetNewState(G4State_Idle);   << 236 } 
485   }                                            << 237   
486 }                                              << 
487                                                << 
488 // ------------------------------------------- << 
489 void G4RunManagerKernel::SetPhysics(G4VUserPhy    238 void G4RunManagerKernel::SetPhysics(G4VUserPhysicsList* uPhys)
490 {                                                 239 {
491   physicsList = uPhys;                            240   physicsList = uPhys;
492                                                << 241   G4ParticleTable::GetParticleTable()->SetReadiness();
493   if (runManagerKernelType == workerRMK) retur << 242   physicsList->ConstructParticle();
494                                                << 243   if(verboseLevel>2) G4ParticleTable::GetParticleTable()->DumpTable();
495   SetupPhysics();                              << 244   if(verboseLevel>1)
496   if (verboseLevel > 2) G4ParticleTable::GetPa << 245   {
497   if (verboseLevel > 1) {                      << 246     G4cout << "List of instantiated particles ============================================" << G4endl;
498     G4cout << "List of instantiated particles  << 
499               "=============================== << 
500            << G4endl;                          << 
501     G4int nPtcl = G4ParticleTable::GetParticle    247     G4int nPtcl = G4ParticleTable::GetParticleTable()->entries();
502     for (G4int i = 0; i < nPtcl; ++i) {        << 248     for(G4int i=0;i<nPtcl;i++)
                                                   >> 249     {
503       G4ParticleDefinition* pd = G4ParticleTab    250       G4ParticleDefinition* pd = G4ParticleTable::GetParticleTable()->GetParticle(i);
504       G4cout << pd->GetParticleName() << " ";     251       G4cout << pd->GetParticleName() << " ";
505       if (i % 10 == 9) G4cout << G4endl;       << 252       if(i%10==9) G4cout << G4endl;
506     }                                             253     }
507     G4cout << G4endl;                             254     G4cout << G4endl;
508   }                                               255   }
509 }                                                 256 }
510                                                << 257   
511 // ------------------------------------------- << 
512 void G4RunManagerKernel::SetupPhysics()        << 
513 {                                              << 
514   G4ParticleTable::GetParticleTable()->SetRead << 
515                                                << 
516   physicsList->ConstructParticle();            << 
517                                                << 
518   // For sanity reason                         << 
519   G4Geantino::GeantinoDefinition();            << 
520   G4ParticleDefinition* gion = G4ParticleTable << 
521   if (gion != nullptr) {                       << 
522     G4IonConstructor::ConstructParticle();     << 
523   }                                            << 
524   G4ParticleTable::GetParticleTable()->GetIonT << 
525                                                << 
526   auto pItr = G4ParticleTable::GetParticleTabl << 
527   pItr->reset();                               << 
528   while ((*pItr)()) {                          << 
529     G4ParticleDefinition* particle = pItr->val << 
530     if (!(particle->IsGeneralIon())) particle- << 
531   }                                            << 
532                                                << 
533   if (gion != nullptr) {                       << 
534     G4int gionId = gion->GetParticleDefinition << 
535     pItr->reset(false);                        << 
536     while ((*pItr)()) {                        << 
537       G4ParticleDefinition* particle = pItr->v << 
538       if (particle->IsGeneralIon()) particle-> << 
539     }                                          << 
540   }                                            << 
541 #ifdef G4MULTITHREADED                         << 
542   G4UnitDefinition::GetUnitsTable().Synchroniz << 
543 #endif                                         << 
544 }                                              << 
545                                                << 
546 // ------------------------------------------- << 
547 namespace                                      << 
548 {                                              << 
549 G4Mutex initphysicsmutex = G4MUTEX_INITIALIZER << 
550 }                                              << 
551                                                << 
552 // ------------------------------------------- << 
553 void G4RunManagerKernel::InitializePhysics()      258 void G4RunManagerKernel::InitializePhysics()
554 {                                                 259 {
555   G4StateManager* stateManager = G4StateManage << 260   G4StateManager*    stateManager = G4StateManager::GetStateManager();
556   G4ApplicationState currentState = stateManag    261   G4ApplicationState currentState = stateManager->GetCurrentState();
557   if (currentState != G4State_Init) {          << 262   if(!(currentState==G4State_Idle||currentState==G4State_PreInit))
558     G4cout << "Current application state is "  << 263   { 
559            << G4endl;                          << 264     G4Exception("G4RunManagerKernel::InitializePhysics",
560     if (currentState != G4State_Idle && curren << 265                 "Run0011", JustWarning,
561       G4Exception("G4RunManagerKernel::Initial << 266                 "Geant4 kernel is not PreInit or Idle state : Method ignored.");
562                   FatalException, "Geant4 kern << 267     return;
563       return;                                  << 
564     }                                          << 
565                                                << 
566     G4cout << "Warning : Geant4 kernel is not  << 
567     stateManager->SetNewState(G4State_Init);   << 
568   }                                               268   }
569                                                   269 
570   if (physicsList == nullptr) {                << 270   if(!physicsList)
571     G4Exception("G4RunManagerKernel::Initializ << 271   {
                                                   >> 272     G4Exception("G4RunManagerKernel::InitializePhysics",
                                                   >> 273                 "Run0012", FatalException,
572                 "G4VUserPhysicsList is not def    274                 "G4VUserPhysicsList is not defined");
573     return;                                       275     return;
574   }                                               276   }
575                                                   277 
576   if (verboseLevel > 1) G4cout << "physicsList << 278   if(verboseLevel>1) G4cout << "physicsList->Construct() start." << G4endl;
577   if (numberOfParallelWorld > 0) physicsList-> << 279   if(numberOfParallelWorld>0) physicsList->UseCoupledTransportation();
578   physicsList->Construct();                       280   physicsList->Construct();
579                                                   281 
580   if (verboseLevel > 1) G4cout << "physicsList << 282   if(verboseLevel>1) G4cout << "physicsList->CheckParticleList() start." << G4endl;
581   physicsList->CheckParticleList();               283   physicsList->CheckParticleList();
582                                                << 284   if(verboseLevel>1) G4cout << "physicsList->setCut() start." << G4endl;
583   // Cannot assume that SetCuts() and CheckReg << 285   physicsList->SetCuts();
584   // We need to mutex (report from valgrind -- << 
585   G4AutoLock l(&initphysicsmutex);             << 
586   if (G4Threading::IsMasterThread()) {         << 
587     if (verboseLevel > 1) G4cout << "physicsLi << 
588     physicsList->SetCuts();                    << 
589   }                                            << 
590   CheckRegions();                                 286   CheckRegions();
591   l.unlock();                                  << 
592                                                << 
593   physicsInitialized = true;                      287   physicsInitialized = true;
594                                                << 288   if(geometryInitialized && currentState!=G4State_Idle)
595 #ifdef G4MULTITHREADED                         << 289   { stateManager->SetNewState(G4State_Idle); }
596   G4UnitDefinition::GetUnitsTable().Synchroniz << 
597 #endif                                         << 
598                                                << 
599   stateManager->SetNewState(currentState);     << 
600   if (geometryInitialized && currentState != G << 
601     stateManager->SetNewState(G4State_Idle);   << 
602   }                                            << 
603 }                                                 290 }
604                                                   291 
605 // ------------------------------------------- << 292 G4bool G4RunManagerKernel::RunInitialization()
606 G4bool G4RunManagerKernel::RunInitialization(G << 
607 {                                                 293 {
608   G4StateManager* stateManager = G4StateManage << 294   G4StateManager*    stateManager = G4StateManager::GetStateManager();
609   G4ApplicationState currentState = stateManag    295   G4ApplicationState currentState = stateManager->GetCurrentState();
610                                                   296 
611   if (!geometryInitialized) {                  << 297   if(!geometryInitialized) 
612     G4Exception("G4RunManagerKernel::RunInitia << 298   { 
                                                   >> 299     G4Exception("G4RunManagerKernel::RunInitialization",
                                                   >> 300                 "Run0021",
                                                   >> 301                 JustWarning,
613                 "Geometry has not yet initiali    302                 "Geometry has not yet initialized : method ignored.");
614     return false;                                 303     return false;
615   }                                               304   }
616                                                << 305   
617   if (!physicsInitialized) {                   << 306   if(!physicsInitialized) 
618     G4Exception("G4RunManagerKernel::RunInitia << 307   { 
                                                   >> 308     G4Exception("G4RunManagerKernel::RunInitialization",
                                                   >> 309                 "Run0022",
                                                   >> 310                 JustWarning,
619                 "Physics has not yet initializ    311                 "Physics has not yet initialized : method ignored.");
620     return false;                                 312     return false;
621   }                                               313   }
622                                                   314 
623   if (currentState != G4State_Idle) {          << 315   if( currentState != G4State_Idle )
624     G4Exception("G4RunManagerKernel::RunInitia << 316   { 
                                                   >> 317     G4Exception("G4RunManagerKernel::RunInitialization",
                                                   >> 318                 "Run0023",
                                                   >> 319                 JustWarning,
625                 "Geant4 kernel not in Idle sta    320                 "Geant4 kernel not in Idle state : method ignored.");
626     return false;                                 321     return false;
627   }                                               322   }
628                                                   323 
629   if (geometryNeedsToBeClosed) CheckRegularGeo << 324   //if(numberOfParallelWorld>0)
630                                                << 325   //{ // Confirm G4CoupledTransportation is used 
631   stateManager->SetNewState(G4State_Init);     << 326   //  if(!ConfirmCoupledTransportation())
632   PropagateGenericIonID();                     << 327   //  { G4Exception("G4CoupledTransportation must be used for parallel world."); }
633   SetupShadowProcess();                        << 328   //}
                                                   >> 329     
634   UpdateRegion();                                 330   UpdateRegion();
635   BuildPhysicsTables(fakeRun);                 << 331   BuildPhysicsTables();
636                                                   332 
637   if (geometryNeedsToBeClosed) {               << 333   if(geometryNeedsToBeClosed)
638     if(!fakeRun || resetNavigatorAtInitializat << 334   {
639     // CheckRegularGeometry();                 << 335     ResetNavigator();
                                                   >> 336     CheckRegularGeometry();
640     // Notify the VisManager as well              337     // Notify the VisManager as well
641     if (G4Threading::IsMasterThread()) {       << 338     G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
642       G4VVisManager* pVVisManager = G4VVisMana << 339     if(pVVisManager) pVVisManager->GeometryHasChanged();
643       if (pVVisManager != nullptr) pVVisManage << 
644     }                                          << 
645   }                                               340   }
646                                                << 341  
647   GetPrimaryTransformer()->CheckUnknown();        342   GetPrimaryTransformer()->CheckUnknown();
648                                                   343 
649 #ifdef G4MULTITHREADED                         << 
650   G4UnitDefinition::GetUnitsTable().Synchroniz << 
651 #endif                                         << 
652                                                << 
653   stateManager->SetNewState(G4State_Idle);     << 
654   stateManager->SetNewState(G4State_GeomClosed    344   stateManager->SetNewState(G4State_GeomClosed);
655   return true;                                    345   return true;
656 }                                                 346 }
657                                                   347 
658 // ------------------------------------------- << 
659 void G4RunManagerKernel::PropagateGenericIonID << 
660 {                                              << 
661   G4ParticleDefinition* gion = G4ParticleTable << 
662   if (gion != nullptr) {                       << 
663     G4int gionId = gion->GetParticleDefinition << 
664     auto pItr = G4ParticleTable::GetParticleTa << 
665     pItr->reset(false);                        << 
666     while ((*pItr)()) {                        << 
667       G4ParticleDefinition* particle = pItr->v << 
668       if (particle->IsGeneralIon()) particle-> << 
669     }                                          << 
670   }                                            << 
671 }                                              << 
672                                                << 
673 // ------------------------------------------- << 
674 void G4RunManagerKernel::RunTermination()         348 void G4RunManagerKernel::RunTermination()
675 {                                              << 349 { G4StateManager::GetStateManager()->SetNewState(G4State_Idle); }
676   if (runManagerKernelType != workerRMK)       << 
677   { G4ProductionCutsTable::GetProductionCutsTa << 
678   G4StateManager::GetStateManager()->SetNewSta << 
679 }                                              << 
680                                                   350 
681 // ------------------------------------------- << 
682 void G4RunManagerKernel::ResetNavigator()         351 void G4RunManagerKernel::ResetNavigator()
683 {                                                 352 {
684   G4GeometryManager* geomManager = G4GeometryM << 
685   if (runManagerKernelType == workerRMK) {     << 
686     // To ensure that it is called when using  << 
687     if( geomManager->IsParallelOptimisationCon << 
688        !geomManager->IsParallelOptimisationFin << 
689     {                                          << 
690       geomManager->UndertakeOptimisation();    << 
691     }                                          << 
692     geometryNeedsToBeClosed = false;           << 
693     return;                                    << 
694   }                                            << 
695                                                << 
696   // We have to tweak the navigator's state in    353   // We have to tweak the navigator's state in case a geometry has been
697   // modified between runs. By the following c    354   // modified between runs. By the following calls we ensure that navigator's
698   // state is reset properly. It is required t    355   // state is reset properly. It is required the geometry to be closed
699   // and previous optimisations to be cleared.    356   // and previous optimisations to be cleared.
700                                                << 357   
701   if (verboseLevel > 1) G4cout << "Start closi << 358   G4GeometryManager* geomManager = G4GeometryManager::GetInstance();
702                                                << 359   if(verboseLevel>1) G4cout << "Start closing geometry." << G4endl;
703   geomManager->OpenGeometry();                    360   geomManager->OpenGeometry();
704   geomManager->CloseGeometry(geometryToBeOptim << 361   geomManager->CloseGeometry(geometryToBeOptimized, verboseLevel>1);
                                                   >> 362  
                                                   >> 363   // Reseting Navigator has been moved to G4Eventmanager, so that resetting
                                                   >> 364   // is now done for every event.  
                                                   >> 365   // G4ThreeVector center(0,0,0);
                                                   >> 366   // G4Navigator* navigator =
                                                   >> 367   //     G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking();
                                                   >> 368   // navigator->LocateGlobalPointAndSetup(center,0,false);
705                                                   369 
706   geometryNeedsToBeClosed = false;                370   geometryNeedsToBeClosed = false;
707 }                                                 371 }
708                                                   372 
709 // ------------------------------------------- << 
710 void G4RunManagerKernel::UpdateRegion()           373 void G4RunManagerKernel::UpdateRegion()
711 {                                                 374 {
712   G4StateManager* stateManager = G4StateManage << 375   G4StateManager*    stateManager = G4StateManager::GetStateManager();
713   G4ApplicationState currentState = stateManag    376   G4ApplicationState currentState = stateManager->GetCurrentState();
714   if (currentState != G4State_Init) {          << 377   if( currentState != G4State_Idle )
715     G4Exception("G4RunManagerKernel::UpdateReg << 378   { 
716                 "Geant4 kernel not in Init sta << 379     G4Exception("G4RunManagerKernel::UpdateRegion",
                                                   >> 380                 "Run0024",
                                                   >> 381                 JustWarning,
                                                   >> 382                 "Geant4 kernel not in Idle state : method ignored.");
717     return;                                       383     return;
718   }                                               384   }
719                                                   385 
720   if (runManagerKernelType == workerRMK) retur << 
721                                                << 
722   CheckRegions();                                 386   CheckRegions();
723                                                << 
724   G4RegionStore::GetInstance()->UpdateMaterial    387   G4RegionStore::GetInstance()->UpdateMaterialList(currentWorld);
725                                                << 
726   G4ProductionCutsTable::GetProductionCutsTabl    388   G4ProductionCutsTable::GetProductionCutsTable()->UpdateCoupleTable(currentWorld);
727 }                                                 389 }
728                                                   390 
729 // ------------------------------------------- << 391 void G4RunManagerKernel::BuildPhysicsTables()
730 void G4RunManagerKernel::BuildPhysicsTables(G4 << 392 { 
731 {                                              << 393   if(G4ProductionCutsTable::GetProductionCutsTable()->IsModified()
732   if (G4ProductionCutsTable::GetProductionCuts << 394   || physicsNeedsToBeReBuilt)
733 #ifdef G4MULTITHREADED                         << 395   {
734     if (runManagerKernelType == masterRMK) {   << 
735       // make sure workers also rebuild physic << 
736       G4UImanager* pUImanager = G4UImanager::G << 
737       pUImanager->ApplyCommand("/run/physicsMo << 
738     }                                          << 
739 #endif                                         << 
740     physicsList->BuildPhysicsTable();             396     physicsList->BuildPhysicsTable();
                                                   >> 397     G4ProductionCutsTable::GetProductionCutsTable()->PhysicsTableUpdated();
741     physicsNeedsToBeReBuilt = false;              398     physicsNeedsToBeReBuilt = false;
742   }                                               399   }
743                                                   400 
744   if (!fakeRun && verboseLevel > 1) DumpRegion << 401   if(verboseLevel>1) DumpRegion();
745   if (!fakeRun && verboseLevel > 0) physicsLis << 402   if(verboseLevel>0) physicsList->DumpCutValuesTable();
746   if (!fakeRun) physicsList->DumpCutValuesTabl << 403   physicsList->DumpCutValuesTableIfRequested();
747 }                                                 404 }
748                                                   405 
749 // ------------------------------------------- << 
750 void G4RunManagerKernel::CheckRegions()           406 void G4RunManagerKernel::CheckRegions()
751 {                                                 407 {
752   G4TransportationManager* transM = G4Transpor    408   G4TransportationManager* transM = G4TransportationManager::GetTransportationManager();
753   std::size_t nWorlds = transM->GetNoWorlds(); << 409   size_t nWorlds = transM->GetNoWorlds();
754   std::vector<G4VPhysicalVolume*>::iterator wI    410   std::vector<G4VPhysicalVolume*>::iterator wItr;
755   for (auto region : *G4RegionStore::GetInstan << 411   for(size_t i=0;i<G4RegionStore::GetInstance()->size();i++)
756     // Let each region have a pointer to the w << 412   { 
757     // G4Region::SetWorld() checks if the regi << 413     G4Region* region = (*(G4RegionStore::GetInstance()))[i];
758     // set it only if it does. Thus, here we g << 414 
759     // volumes.                                << 415     //Let each region have a pointer to the world volume where it belongs to.
760     region->SetWorld(nullptr);  // reset       << 416     //G4Region::SetWorld() checks if the region belongs to the given world and set it
                                                   >> 417     //only if it does. Thus, here we go through all the registered world volumes.
                                                   >> 418     region->SetWorld(0); // reset
761     region->UsedInMassGeometry(false);            419     region->UsedInMassGeometry(false);
762     region->UsedInParallelGeometry(false);        420     region->UsedInParallelGeometry(false);
763     wItr = transM->GetWorldsIterator();           421     wItr = transM->GetWorldsIterator();
764     for (std::size_t iw = 0; iw < nWorlds; ++i << 422     for(size_t iw=0;iw<nWorlds;iw++)
765       if (region->BelongsTo(*wItr)) {          << 423     {
766         if (*wItr == currentWorld) {           << 424       if(region->BelongsTo(*wItr))
767           region->UsedInMassGeometry(true);    << 425       {
768         }                                      << 426         if(*wItr==currentWorld)
769         else {                                 << 427         { region->UsedInMassGeometry(true); }
770           region->UsedInParallelGeometry(true) << 428         else
771         }                                      << 429         { region->UsedInParallelGeometry(true); }
772       }                                           430       }
773       region->SetWorld(*wItr);                    431       region->SetWorld(*wItr);
774       ++wItr;                                  << 432       wItr++;
775     }                                             433     }
776                                                   434 
777     G4ProductionCuts* cuts = region->GetProduc    435     G4ProductionCuts* cuts = region->GetProductionCuts();
778     if (cuts == nullptr) {                     << 436     if(!cuts)
779       if (region->IsInMassGeometry() && verbos << 437     {
780         G4cout << "Warning : Region <" << regi << 438       if(region->IsInMassGeometry())
781                << "> does not have specific pr << 439       {
782                << "even though it appears in t << 440         G4cerr << "Warning : Region <" << region->GetName()
783         G4cout << "Default cuts are used for t << 441              << "> does not have specific production cuts," << G4endl
                                                   >> 442              << "even though it appears in the current tracking world." << G4endl;
                                                   >> 443         G4cerr << "Default cuts are used for this region." << G4endl;
784       }                                           444       }
785                                                   445 
786       if (region->IsInMassGeometry() || region << 446       if(region->IsInMassGeometry()||region->IsInParallelGeometry())
                                                   >> 447       {
787         region->SetProductionCuts(                448         region->SetProductionCuts(
788           G4ProductionCutsTable::GetProduction << 449           G4ProductionCutsTable::GetProductionCutsTable()
                                                   >> 450              ->GetDefaultProductionCuts());
789       }                                           451       }
790     }                                             452     }
791   }                                               453   }
792                                                   454 
793   //                                              455   //
794   // If a parallel world has no region, set de    456   // If a parallel world has no region, set default region for parallel world
795   //                                              457   //
796                                                   458 
                                                   >> 459 //DumpRegion();
                                                   >> 460 //
                                                   >> 461 //  while(defaultRegionForParallelWorld->GetNumberOfRootVolumes()>0)
                                                   >> 462 //  {
                                                   >> 463 //    std::vector<G4LogicalVolume*>::iterator lvItr
                                                   >> 464 //      = defaultRegionForParallelWorld->GetRootLogicalVolumeIterator();
                                                   >> 465 //    defaultRegionForParallelWorld->RemoveRootLogicalVolume(*lvItr,false);
                                                   >> 466 //  }
                                                   >> 467 
797   wItr = transM->GetWorldsIterator();             468   wItr = transM->GetWorldsIterator();
798   for (std::size_t iw = 0; iw < nWorlds; ++iw) << 469   for(size_t iw=0;iw<nWorlds;iw++)
799     if (*wItr != currentWorld) {               << 470   {
                                                   >> 471     //G4cout << "+++ " << (*wItr)->GetName() << G4endl;
                                                   >> 472     if(*wItr!=currentWorld)
                                                   >> 473     {
800       G4LogicalVolume* pwLogical = (*wItr)->Ge    474       G4LogicalVolume* pwLogical = (*wItr)->GetLogicalVolume();
801       if (pwLogical->GetRegion() == nullptr) { << 475       if(!(pwLogical->GetRegion()))
                                                   >> 476       {
802         pwLogical->SetRegion(defaultRegionForP    477         pwLogical->SetRegion(defaultRegionForParallelWorld);
803         defaultRegionForParallelWorld->AddRoot    478         defaultRegionForParallelWorld->AddRootLogicalVolume(pwLogical);
                                                   >> 479         //G4cout << "+++++ defaultRegionForParallelWorld is set to "
                                                   >> 480         //       << (*wItr)->GetName() << " +++++" << G4endl;
804       }                                           481       }
805     }                                             482     }
806     ++wItr;                                    << 483     wItr++;
807   }                                               484   }
                                                   >> 485 
808 }                                                 486 }
809                                                   487 
810 // ------------------------------------------- << 
811 void G4RunManagerKernel::DumpRegion(const G4St    488 void G4RunManagerKernel::DumpRegion(const G4String& rname) const
812 {                                                 489 {
813   G4Region* region = G4RegionStore::GetInstanc    490   G4Region* region = G4RegionStore::GetInstance()->GetRegion(rname);
814   if (region != nullptr) DumpRegion(region);   << 491   if(region) DumpRegion(region);
815 }                                                 492 }
816                                                   493 
817 // ------------------------------------------- << 
818 void G4RunManagerKernel::DumpRegion(G4Region*     494 void G4RunManagerKernel::DumpRegion(G4Region* region) const
819 {                                                 495 {
820   if (region == nullptr) {                     << 496   if(!region)
821     for (const auto& i : *G4RegionStore::GetIn << 497   {
822       DumpRegion(i);                           << 498     for(size_t i=0;i<G4RegionStore::GetInstance()->size();i++)
823     }                                          << 499     { DumpRegion((*(G4RegionStore::GetInstance()))[i]); }
824   }                                               500   }
825   else {                                       << 501   else
826     if (G4Threading::IsWorkerThread()) return; << 502   {
827     G4cout << G4endl;                             503     G4cout << G4endl;
828     G4cout << "Region <" << region->GetName()     504     G4cout << "Region <" << region->GetName() << "> -- ";
829     if (region->GetWorldPhysical() != nullptr) << 505     if(region->GetWorldPhysical())
830       G4cout << " -- appears in <" << region-> << 506     {
831     }                                          << 507       G4cout << " -- appears in <" 
832     else {                                     << 508            << region->GetWorldPhysical()->GetName() << "> world volume";
833       G4cout << " -- is not associated to any  << 
834     }                                             509     }
                                                   >> 510     else
                                                   >> 511     { G4cout << " -- is not associated to any world."; }
835     G4cout << G4endl;                             512     G4cout << G4endl;
836     if (region->IsInMassGeometry()) {          << 513     if(region->IsInMassGeometry())
837       G4cout << " This region is in the mass w << 514     { G4cout << " This region is in the mass world." << G4endl; }
838     }                                          << 515     if(region->IsInParallelGeometry())
839     if (region->IsInParallelGeometry()) {      << 516     { G4cout << " This region is in the parallel world." << G4endl; }
840       G4cout << " This region is in the parall << 
841     }                                          << 
842                                                   517 
843     G4cout << " Root logical volume(s) : ";       518     G4cout << " Root logical volume(s) : ";
844     std::size_t nRootLV = region->GetNumberOfR << 519     size_t nRootLV = region->GetNumberOfRootVolumes();
845     auto lvItr = region->GetRootLogicalVolumeI << 520     std::vector<G4LogicalVolume*>::iterator lvItr = region->GetRootLogicalVolumeIterator();
846     for (std::size_t j = 0; j < nRootLV; ++j)  << 521     for(size_t j=0;j<nRootLV;j++)
847       G4cout << (*lvItr)->GetName() << " ";    << 522     { G4cout << (*lvItr)->GetName() << " "; lvItr++; }
848       ++lvItr;                                 << 
849     }                                          << 
850     G4cout << G4endl;                             523     G4cout << G4endl;
851                                                   524 
852     G4cout << " Pointers : G4VUserRegionInform << 525     G4cout << " Pointers : G4VUserRegionInformation[" << region->GetUserInformation() 
853            << "], G4UserLimits[" << region->Ge << 526            << "], G4UserLimits[" << region->GetUserLimits() 
854            << region->GetFastSimulationManager << 527            << "], G4FastSimulationManager[" << region->GetFastSimulationManager()
855            << region->GetRegionalSteppingActio << 528            << "], G4UserSteppingAction[" << region->GetRegionalSteppingAction() << "]" << G4endl;
856                                                << 529     
                                                   >> 530 //    if(region->GetWorldPhysical()!=currentWorld)
                                                   >> 531 //    {
                                                   >> 532 //      G4cout << G4endl;
                                                   >> 533 //      return;
                                                   >> 534 //    }
857     G4cout << " Materials : ";                    535     G4cout << " Materials : ";
858     auto mItr = region->GetMaterialIterator(); << 536     std::vector<G4Material*>::const_iterator mItr = region->GetMaterialIterator();
859     std::size_t nMaterial = region->GetNumberO << 537     size_t nMaterial = region->GetNumberOfMaterials();
860     for (std::size_t iMate = 0; iMate < nMater << 538     for(size_t iMate=0;iMate<nMaterial;iMate++)
                                                   >> 539     {
861       G4cout << (*mItr)->GetName() << " ";        540       G4cout << (*mItr)->GetName() << " ";
862       ++mItr;                                  << 541       mItr++;
863     }                                             542     }
864     G4cout << G4endl;                             543     G4cout << G4endl;
865     G4ProductionCuts* cuts = region->GetProduc    544     G4ProductionCuts* cuts = region->GetProductionCuts();
866     if ((cuts == nullptr) && region->IsInMassG << 545     if(!cuts && region->IsInMassGeometry())
                                                   >> 546     {
867       G4cerr << "Warning : Region <" << region    547       G4cerr << "Warning : Region <" << region->GetName()
868              << "> does not have specific prod    548              << "> does not have specific production cuts." << G4endl;
869       G4cerr << "Default cuts are used for thi    549       G4cerr << "Default cuts are used for this region." << G4endl;
870       region->SetProductionCuts(                  550       region->SetProductionCuts(
871         G4ProductionCutsTable::GetProductionCu << 551           G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts());
872     }                                             552     }
873     else if (cuts != nullptr) {                << 553     else if(cuts)
                                                   >> 554     {
874       G4cout << " Production cuts : "             555       G4cout << " Production cuts : "
875              << "  gamma " << G4BestUnit(cuts- << 556              << "  gamma "
876              << G4BestUnit(cuts->GetProduction << 557              << G4BestUnit(cuts->GetProductionCut("gamma"),"Length")
877              << G4BestUnit(cuts->GetProduction << 558              << "     e- "
878              << G4BestUnit(cuts->GetProduction << 559              << G4BestUnit(cuts->GetProductionCut("e-"),"Length")
                                                   >> 560              << "     e+ "
                                                   >> 561              << G4BestUnit(cuts->GetProductionCut("e+"),"Length")
                                                   >> 562              << " proton "
                                                   >> 563              << G4BestUnit(cuts->GetProductionCut("proton"),"Length")
                                                   >> 564              << G4endl;
879     }                                             565     }
880   }                                               566   }
881 }                                                 567 }
882                                                   568 
883 // ------------------------------------------- << 569 #include "G4LogicalVolumeStore.hh"
884 void G4RunManagerKernel::CheckRegularGeometry(    570 void G4RunManagerKernel::CheckRegularGeometry()
885 {                                                 571 {
886   G4LogicalVolumeStore* store = G4LogicalVolum    572   G4LogicalVolumeStore* store = G4LogicalVolumeStore::GetInstance();
887   for (const auto& pos : *store) {             << 573   for(G4LogicalVolumeStore::iterator pos=store->begin(); pos!=store->end(); pos++)
888     if ((pos != nullptr) && (pos->GetNoDaughte << 574   {
889       if (pos->GetDaughter(0)->IsRegularStruct << 575     if((*pos)&&((*pos)->GetNoDaughters()==1))
                                                   >> 576     {
                                                   >> 577       if((*pos)->GetDaughter(0)->IsRegularStructure())
                                                   >> 578       {
890         SetScoreSplitter();                       579         SetScoreSplitter();
891         return;                                   580         return;
892       }                                           581       }
893     }                                             582     }
894   }                                               583   }
895 }                                                 584 }
896                                                << 585         
897 // ------------------------------------------- << 586 #include "G4ParticleTable.hh"
                                                   >> 587 #include "G4ParticleDefinition.hh"
                                                   >> 588 #include "G4ProcessManager.hh"
                                                   >> 589 #include "G4ProcessVector.hh"
                                                   >> 590 #include "G4VProcess.hh"
898 G4bool G4RunManagerKernel::ConfirmCoupledTrans    591 G4bool G4RunManagerKernel::ConfirmCoupledTransportation()
899 {                                                 592 {
900   G4ParticleTable* theParticleTable = G4Partic    593   G4ParticleTable* theParticleTable = G4ParticleTable::GetParticleTable();
901   auto theParticleIterator = theParticleTable- << 594   G4ParticleTable::G4PTblDicIterator* theParticleIterator = theParticleTable->GetIterator();
902   theParticleIterator->reset();                   595   theParticleIterator->reset();
903   while ((*theParticleIterator)()) {           << 596   while((*theParticleIterator)())
                                                   >> 597   {
904     G4ParticleDefinition* pd = theParticleIter    598     G4ParticleDefinition* pd = theParticleIterator->value();
905     G4ProcessManager* pm = pd->GetProcessManag    599     G4ProcessManager* pm = pd->GetProcessManager();
906     if (pm != nullptr) {                       << 600     if(pm)
                                                   >> 601     {
907       G4ProcessVector* pv = pm->GetAlongStepPr    602       G4ProcessVector* pv = pm->GetAlongStepProcessVector(typeDoIt);
908       G4VProcess* p = (*pv)[0];                   603       G4VProcess* p = (*pv)[0];
909       return ((p->GetProcessName()) == "Couple << 604       return ( (p->GetProcessName()) == "CoupledTransportation" );
910     }                                             605     }
911   }                                               606   }
912   return false;                                   607   return false;
913 }                                                 608 }
914                                                   609 
915 // ------------------------------------------- << 610 #include "G4ScoreSplittingProcess.hh"
916 void G4RunManagerKernel::SetScoreSplitter()       611 void G4RunManagerKernel::SetScoreSplitter()
917 {                                                 612 {
918   auto pSplitter = new G4ScoreSplittingProcess << 613   G4ScoreSplittingProcess* pSplitter = new G4ScoreSplittingProcess();
919   G4ParticleTable* theParticleTable = G4Partic    614   G4ParticleTable* theParticleTable = G4ParticleTable::GetParticleTable();
920   auto theParticleIterator = theParticleTable- << 615   G4ParticleTable::G4PTblDicIterator* theParticleIterator = theParticleTable->GetIterator();
921                                                   616 
922   // Ensure that Process is added only once to    617   // Ensure that Process is added only once to the particles' process managers
923   static G4ThreadLocal G4bool InitSplitter = f << 618   static bool InitSplitter=false; 
924   if (!InitSplitter) {                         << 619   if( ! InitSplitter ) {
925     InitSplitter = true;                          620     InitSplitter = true;
926                                                   621 
927     theParticleIterator->reset();                 622     theParticleIterator->reset();
928     while ((*theParticleIterator)()) {         << 623     while( (*theParticleIterator)() )  
                                                   >> 624     {
929       G4ParticleDefinition* particle = thePart    625       G4ParticleDefinition* particle = theParticleIterator->value();
930       G4ProcessManager* pmanager = particle->G    626       G4ProcessManager* pmanager = particle->GetProcessManager();
931       if (pmanager != nullptr) {               << 627       if(pmanager)
932         pmanager->AddDiscreteProcess(pSplitter << 628   { pmanager->AddDiscreteProcess(pSplitter); }
933       }                                        << 
934     }                                             629     }
935                                                   630 
936     if (verboseLevel > 0) {                    << 631     if(verboseLevel>0) 
937       G4cout << "G4RunManagerKernel -- G4Score << 632     {
938                 "particles."                   << 633       G4cout << "G4RunManagerKernel -- G4ScoreSplittingProcess is appended to all particles." << G4endl;
939              << G4endl;                        << 
940     }                                             634     }
941   }                                               635   }
942 }                                                 636 }
943                                                   637 
944 // ------------------------------------------- << 
945 void G4RunManagerKernel::SetupShadowProcess()  << 
946 {                                              << 
947   G4ParticleTable* theParticleTable = G4Partic << 
948   auto theParticleIterator = theParticleTable- << 
949   theParticleIterator->reset();                << 
950   // loop on particles and get process manager << 
951   while ((*theParticleIterator)()) {           << 
952     G4ParticleDefinition* pd = theParticleIter << 
953     G4ProcessManager* pm = pd->GetProcessManag << 
954     if (pm != nullptr) {                       << 
955       G4ProcessVector& procs = *(pm->GetProces << 
956       for (G4int idx = 0; idx < (G4int)procs.s << 
957         const G4VProcess* masterP = procs[idx] << 
958         if (masterP == nullptr) {              << 
959           // Process does not have an associat << 
960           // We are in master mode or sequenti << 
961           procs[idx]->SetMasterProcess(const_c << 
962         }                                      << 
963       }                                        << 
964     }                                          << 
965   }                                            << 
966 }                                              << 
967                                                   638