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 11.0.p2)


  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               26 // G4RunManagerKernel implementation
 27 //                                                 27 //
 28 // Author: M.Asai, 1 August 2003                   28 // Author: M.Asai, 1 August 2003
 29 // -------------------------------------------     29 // --------------------------------------------------------------------
 30                                                    30 
                                                   >>  31 #include <vector>
                                                   >>  32 
 31 #include "G4RunManagerKernel.hh"                   33 #include "G4RunManagerKernel.hh"
 32                                                    34 
 33 #include "G4AllocatorList.hh"                  << 
 34 #include "G4ApplicationState.hh"                   35 #include "G4ApplicationState.hh"
 35 #include "G4AutoLock.hh"                       << 
 36 #include "G4ExceptionHandler.hh"                   36 #include "G4ExceptionHandler.hh"
 37 #include "G4FieldManagerStore.hh"                  37 #include "G4FieldManagerStore.hh"
 38 #include "G4Geantino.hh"                       << 
 39 #include "G4GeometryManager.hh"                    38 #include "G4GeometryManager.hh"
 40 #include "G4IonConstructor.hh"                 << 
 41 #include "G4IonTable.hh"                       << 
 42 #include "G4LogicalVolume.hh"                      39 #include "G4LogicalVolume.hh"
 43 #include "G4LogicalVolumeStore.hh"             << 
 44 #include "G4MTRunManager.hh"                   << 
 45 #include "G4NavigationHistoryPool.hh"              40 #include "G4NavigationHistoryPool.hh"
 46 #include "G4ParallelWorldProcessStore.hh"      << 
 47 #include "G4ParticleDefinition.hh"             << 
 48 #include "G4ParticleTable.hh"                  << 
 49 #include "G4ParticleTableIterator.hh"          << 
 50 #include "G4PathFinder.hh"                         41 #include "G4PathFinder.hh"
 51 #include "G4PrimaryTransformer.hh"                 42 #include "G4PrimaryTransformer.hh"
 52 #include "G4ProcessManager.hh"                 <<  43 #include "G4StateManager.hh"
 53 #include "G4ProcessVector.hh"                  <<  44 #include "G4TransportationManager.hh"
                                                   >>  45 #include "G4VPhysicalVolume.hh"
                                                   >>  46 #include "G4VUserPhysicsList.hh"
                                                   >>  47 #include "G4LogicalVolumeStore.hh"
                                                   >>  48 
                                                   >>  49 #include "G4ParallelWorldProcessStore.hh"
                                                   >>  50 #include "G4ParticleTable.hh"
 54 #include "G4ProductionCuts.hh"                     51 #include "G4ProductionCuts.hh"
 55 #include "G4ProductionCutsTable.hh"                52 #include "G4ProductionCutsTable.hh"
 56 #include "G4RNGHelper.hh"                      << 
 57 #include "G4Region.hh"                             53 #include "G4Region.hh"
 58 #include "G4RegionStore.hh"                        54 #include "G4RegionStore.hh"
 59 #include "G4SDManager.hh"                          55 #include "G4SDManager.hh"
 60 #include "G4ScoreSplittingProcess.hh"          <<  56 #include "G4TiMemory.hh"
 61 #include "G4StateManager.hh"                   << 
 62 #include "G4TransportationManager.hh"          << 
 63 #include "G4UImanager.hh"                          57 #include "G4UImanager.hh"
 64 #include "G4UnitsTable.hh"                         58 #include "G4UnitsTable.hh"
 65 #include "G4VPhysicalVolume.hh"                << 
 66 #include "G4VProcess.hh"                       << 
 67 #include "G4VUserPhysicsList.hh"               << 
 68 #include "G4VVisManager.hh"                        59 #include "G4VVisManager.hh"
 69 #include "G4Version.hh"                            60 #include "G4Version.hh"
 70 #include "G4ios.hh"                                61 #include "G4ios.hh"
 71                                                    62 
 72 #include <vector>                              <<  63 #include "G4Geantino.hh"
                                                   >>  64 #include "G4IonConstructor.hh"
                                                   >>  65 #include "G4IonTable.hh"
                                                   >>  66 #include "G4ParticleTableIterator.hh"
                                                   >>  67 #include "G4ParticleDefinition.hh"
                                                   >>  68 #include "G4ParticleTable.hh"
                                                   >>  69 #include "G4ProcessManager.hh"
                                                   >>  70 #include "G4ProcessVector.hh"
                                                   >>  71 #include "G4VProcess.hh"
                                                   >>  72 #include "G4ScoreSplittingProcess.hh"
                                                   >>  73 
                                                   >>  74 #include "G4AllocatorList.hh"
                                                   >>  75 #include "G4MTRunManager.hh"
                                                   >>  76 
                                                   >>  77 #include "G4AutoLock.hh"
                                                   >>  78 #include "G4RNGHelper.hh"
 73                                                    79 
 74 #ifdef G4BT_DEBUG                                  80 #ifdef G4BT_DEBUG
 75 #  include "G4Backtrace.hh"                        81 #  include "G4Backtrace.hh"
 76 #endif                                             82 #endif
 77                                                    83 
 78 #ifdef G4FPE_DEBUG                                 84 #ifdef G4FPE_DEBUG
 79 #  include "G4FPEDetection.hh"                     85 #  include "G4FPEDetection.hh"
 80 #endif                                             86 #endif
 81                                                    87 
 82 // The following lines are needed since G4VUse     88 // The following lines are needed since G4VUserPhysicsList
 83 // uses a #define theParticleIterator              89 // uses a #define theParticleIterator
 84 #ifdef theParticleIterator                         90 #ifdef theParticleIterator
 85 #  undef theParticleIterator                       91 #  undef theParticleIterator
 86 #endif                                             92 #endif
 87                                                    93 
 88 G4ThreadLocal G4RunManagerKernel* G4RunManager <<  94 G4ThreadLocal G4RunManagerKernel*
                                                   >>  95 G4RunManagerKernel::fRunManagerKernel = nullptr;
 89                                                    96 
 90 // -------------------------------------------     97 // --------------------------------------------------------------------
 91 G4RunManagerKernel* G4RunManagerKernel::GetRun     98 G4RunManagerKernel* G4RunManagerKernel::GetRunManagerKernel()
 92 {                                                  99 {
 93   return fRunManagerKernel;                       100   return fRunManagerKernel;
 94 }                                                 101 }
 95                                                   102 
 96 // -------------------------------------------    103 // --------------------------------------------------------------------
 97 G4RunManagerKernel::G4RunManagerKernel()          104 G4RunManagerKernel::G4RunManagerKernel()
 98 {                                                 105 {
 99 #ifdef G4FPE_DEBUG                             << 106   #ifdef G4FPE_DEBUG
100   InvalidOperationDetection();                 << 107     InvalidOperationDetection();
101 #endif                                         << 108   #endif
102                                                   109 
103 #ifdef G4BT_DEBUG                              << 110   #ifdef G4BT_DEBUG
104   auto _signals = G4GetEnv<std::string>("G4BAC << 111     auto _signals = G4GetEnv<std::string>("G4BACKTRACE", "");
105   if (_signals.empty()) {                      << 112     if(_signals.empty())
106     G4Backtrace::Enable();                     << 113     {
107   }                                            << 114       G4Backtrace::Enable();
108   else {                                       << 115     }
109     G4Backtrace::Enable(_signals);             << 116     else
110   }                                            << 117     {
111 #endif                                         << 118       G4Backtrace::Enable(_signals);
                                                   >> 119     }
                                                   >> 120   #endif
112                                                   121 
113   G4AllocatorList* allocList = G4AllocatorList    122   G4AllocatorList* allocList = G4AllocatorList::GetAllocatorListIfExist();
114   if (allocList != nullptr) numberOfStaticAllo << 123   if(allocList != nullptr)
                                                   >> 124     numberOfStaticAllocators = allocList->Size();
115                                                   125 
116   if (G4StateManager::GetStateManager()->GetEx << 126   if(G4StateManager::GetStateManager()->GetExceptionHandler() == nullptr)
117     defaultExceptionHandler = new G4ExceptionH << 127   {  
118   }                                            << 128      defaultExceptionHandler = new G4ExceptionHandler();
119   if (fRunManagerKernel != nullptr) {          << 129   }
120     G4Exception("G4RunManagerKernel::G4RunMana << 130   if(fRunManagerKernel != nullptr)
                                                   >> 131   {
                                                   >> 132     G4Exception("G4RunManagerKernel::G4RunManagerKernel()", "Run0001",
                                                   >> 133                 FatalException,
121                 "More than one G4RunManagerKer    134                 "More than one G4RunManagerKernel is constructed.");
122   }                                               135   }
123   fRunManagerKernel = this;                       136   fRunManagerKernel = this;
124                                                   137 
125   G4ParticleTable* particleTable = G4ParticleT    138   G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
126   if (particleTable->entries() > 0) {          << 139   if(particleTable->entries() > 0)
                                                   >> 140   {
127     // No particle should be registered before    141     // No particle should be registered beforehand
128     G4ExceptionDescription ED;                    142     G4ExceptionDescription ED;
129     ED << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    143     ED << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << G4endl;
130     ED << " G4RunManagerKernel fatal exception    144     ED << " G4RunManagerKernel fatal exception" << G4endl;
131     ED << "  -- Following particles have alrea    145     ED << "  -- Following particles have already been registered" << G4endl;
132     ED << "     before G4RunManagerKernel is i    146     ED << "     before G4RunManagerKernel is instantiated." << G4endl;
133     for (G4int i = 0; i < particleTable->entri << 147     for(G4int i = 0; i < particleTable->entries(); ++i)
134       ED << "     " << particleTable->GetParti << 148     {
                                                   >> 149       ED << "     " << particleTable->GetParticle(i)->GetParticleName()
                                                   >> 150          << G4endl;
135     }                                             151     }
136     ED << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    152     ED << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << G4endl;
137     G4Exception("G4RunManagerKernel::G4RunMana << 153     G4Exception("G4RunManagerKernel::G4RunManagerKernel()", "Run0002",
                                                   >> 154                 FatalException, ED);
138   }                                               155   }
139                                                   156 
140   // construction of Geant4 kernel classes        157   // construction of Geant4 kernel classes
141   eventManager = new G4EventManager();            158   eventManager = new G4EventManager();
142                                                   159 
143   defaultRegion = new G4Region("DefaultRegionF    160   defaultRegion = new G4Region("DefaultRegionForTheWorld");  // deleted by store
144   defaultRegionForParallelWorld =                 161   defaultRegionForParallelWorld =
145     new G4Region("DefaultRegionForParallelWorl    162     new G4Region("DefaultRegionForParallelWorld");  // deleted by store
146   defaultRegion->SetProductionCuts(               163   defaultRegion->SetProductionCuts(
147     G4ProductionCutsTable::GetProductionCutsTa << 164     G4ProductionCutsTable::GetProductionCutsTable()
                                                   >> 165       ->GetDefaultProductionCuts());
148   defaultRegionForParallelWorld->SetProduction    166   defaultRegionForParallelWorld->SetProductionCuts(
149     G4ProductionCutsTable::GetProductionCutsTa << 167     G4ProductionCutsTable::GetProductionCutsTable()
                                                   >> 168       ->GetDefaultProductionCuts());
150                                                   169 
151   runManagerKernelType = sequentialRMK;           170   runManagerKernelType = sequentialRMK;
152   // set the initial application state            171   // set the initial application state
153   G4StateManager::GetStateManager()->SetNewSta    172   G4StateManager::GetStateManager()->SetNewState(G4State_PreInit);
154                                                   173 
155   // version banner                               174   // version banner
156   G4String vs = G4Version;                     << 175   G4String vs   = G4Version;
157   vs = vs.substr(1, vs.size() - 2);            << 176   vs            = vs.substr(1, vs.size() - 2);
158   versionString = " Geant4 version ";             177   versionString = " Geant4 version ";
159   versionString += vs;                            178   versionString += vs;
160   versionString += "   ";                         179   versionString += "   ";
161   versionString += G4Date;                        180   versionString += G4Date;
162   G4cout << G4endl << "*********************** << 181   G4cout << G4endl
163          << versionString << G4endl << "       << 182          << "**************************************************************"
164          << G4endl << "                      R << 183          << G4endl << versionString << G4endl
165          << "                                  << 184          << "                       Copyright : Geant4 Collaboration" << G4endl
166          << "                                  << 185          << "                      References : NIM A 506 (2003), 250-303"
167          << "                             WWW  << 186          << G4endl
168          << "********************************* << 187          << "                                 : IEEE-TNS 53 (2006), 270-278"
                                                   >> 188          << G4endl
                                                   >> 189          << "                                 : NIM A 835 (2016), 186-225"
                                                   >> 190          << G4endl << "                             WWW : http://geant4.org/"
                                                   >> 191          << G4endl
                                                   >> 192          << "**************************************************************"
                                                   >> 193          << G4endl << G4endl;
169 }                                                 194 }
170                                                   195 
171 // -------------------------------------------    196 // --------------------------------------------------------------------
172 G4RunManagerKernel::G4RunManagerKernel(RMKType    197 G4RunManagerKernel::G4RunManagerKernel(RMKType rmkType)
173 {                                                 198 {
174 // This version of the constructor should neve << 199   // This version of the constructor should never be called in sequential mode!
175 #ifndef G4MULTITHREADED                        << 200   #ifndef G4MULTITHREADED
176   G4ExceptionDescription msg;                  << 201     G4ExceptionDescription msg;
177   msg << "Geant4 code is compiled without mult << 202     msg << "Geant4 code is compiled without multi-threading support "
178          "(-DG4MULTITHREADED is set to off)."; << 203            "(-DG4MULTITHREADED is set to off).";
179   msg << " This type of RunManagerKernel can o << 204     msg << " This type of RunManagerKernel can only be used in mult-threaded "
180          "applications.";                      << 205            "applications.";
181   G4Exception("G4RunManagerKernel::G4RunManage << 206     G4Exception("G4RunManagerKernel::G4RunManagerKernel(G4bool)", "Run0105",
182 #endif                                         << 207                 FatalException, msg);
                                                   >> 208   #endif
183                                                   209 
184 #ifdef G4FPE_DEBUG                             << 210   #ifdef G4FPE_DEBUG
185   if (G4Threading::IsMasterThread()) {         << 211     if(G4Threading::IsMasterThread())
186     InvalidOperationDetection();               << 212     {
187   }                                            << 213       InvalidOperationDetection();
188 #endif                                         << 214     }
                                                   >> 215   #endif
189                                                   216 
190 #ifdef G4BT_DEBUG                              << 217   #ifdef G4BT_DEBUG
191   auto _signals = G4GetEnv<std::string>("G4BAC << 218     auto _signals = G4GetEnv<std::string>("G4BACKTRACE", "");
192   if (_signals.empty()) {                      << 219     if(_signals.empty())
193     G4Backtrace::Enable();                     << 220     {
194   }                                            << 221       G4Backtrace::Enable();
195   else {                                       << 222     }
196     G4Backtrace::Enable(_signals);             << 223     else
197   }                                            << 224     {
198 #endif                                         << 225       G4Backtrace::Enable(_signals);
                                                   >> 226     }
                                                   >> 227   #endif
199                                                   228 
200   if (G4StateManager::GetStateManager()->GetEx << 229   if(G4StateManager::GetStateManager()->GetExceptionHandler() == nullptr)
201     defaultExceptionHandler = new G4ExceptionH << 230   {
                                                   >> 231      defaultExceptionHandler = new G4ExceptionHandler();
202   }                                               232   }
203                                                   233 
204   if (fRunManagerKernel != nullptr) {          << 234   if(fRunManagerKernel != nullptr)
205     G4Exception("G4RunManagerKernel::G4RunMana << 235   {
                                                   >> 236     G4Exception("G4RunManagerKernel::G4RunManagerKernel()", "Run0001",
                                                   >> 237                 FatalException,
206                 "More than one G4RunManagerKer    238                 "More than one G4RunManagerKernel is constructed.");
207   }                                               239   }
208   fRunManagerKernel = this;                       240   fRunManagerKernel = this;
209   // construction of Geant4 kernel classes        241   // construction of Geant4 kernel classes
210   eventManager = new G4EventManager();            242   eventManager = new G4EventManager();
211                                                   243 
212   switch (rmkType) {                           << 244   switch(rmkType)
                                                   >> 245   {
213     case masterRMK:                               246     case masterRMK:
214       // Master thread behvior                    247       // Master thread behvior
215       defaultRegion = new G4Region("DefaultReg << 248       defaultRegion =
                                                   >> 249         new G4Region("DefaultRegionForTheWorld");  // deleted by store
216       defaultRegionForParallelWorld =             250       defaultRegionForParallelWorld =
217         new G4Region("DefaultRegionForParallel    251         new G4Region("DefaultRegionForParallelWorld");  // deleted by store
218       defaultRegion->SetProductionCuts(           252       defaultRegion->SetProductionCuts(
219         G4ProductionCutsTable::GetProductionCu << 253         G4ProductionCutsTable::GetProductionCutsTable()
                                                   >> 254           ->GetDefaultProductionCuts());
220       defaultRegionForParallelWorld->SetProduc    255       defaultRegionForParallelWorld->SetProductionCuts(
221         G4ProductionCutsTable::GetProductionCu << 256         G4ProductionCutsTable::GetProductionCutsTable()
                                                   >> 257           ->GetDefaultProductionCuts());
222       break;                                      258       break;
223     case workerRMK:                               259     case workerRMK:
224       // Worker thread behavior                   260       // Worker thread behavior
225       defaultRegion = G4RegionStore::GetInstan << 261       defaultRegion = G4RegionStore::GetInstance()->GetRegion(
226       defaultRegionForParallelWorld =          << 262         "DefaultRegionForTheWorld", true);
227         G4RegionStore::GetInstance()->GetRegio << 263       defaultRegionForParallelWorld = G4RegionStore::GetInstance()->GetRegion(
                                                   >> 264         "DefaultRegionForParallelWorld", true);
228       break;                                      265       break;
229     default:                                      266     default:
230       defaultRegion = nullptr;                 << 267       defaultRegion                 = nullptr;
231       defaultRegionForParallelWorld = nullptr;    268       defaultRegionForParallelWorld = nullptr;
232       G4ExceptionDescription msgx;                269       G4ExceptionDescription msgx;
233       msgx << " This type of RunManagerKernel  << 270       msgx
234               "applications.";                 << 271         << " This type of RunManagerKernel can only be used in mult-threaded "
235       G4Exception("G4RunManagerKernel::G4RunMa << 272            "applications.";
236                   msgx);                       << 273       G4Exception("G4RunManagerKernel::G4RunManagerKernel(G4bool)", "Run0106",
                                                   >> 274                   FatalException, msgx);
237   }                                               275   }
238   runManagerKernelType = rmkType;                 276   runManagerKernelType = rmkType;
239                                                   277 
240   // set the initial application state            278   // set the initial application state
241   G4StateManager::GetStateManager()->SetNewSta    279   G4StateManager::GetStateManager()->SetNewState(G4State_PreInit);
242                                                   280 
243   // version banner                               281   // version banner
244   G4String vs = G4Version;                        282   G4String vs = G4Version;
245   vs = vs.substr(1, vs.size() - 2);            << 283   vs          = vs.substr(1, vs.size() - 2);
246   switch (rmkType) {                           << 284   switch(rmkType)
                                                   >> 285   {
247     case masterRMK:                               286     case masterRMK:
248       versionString = " Geant4 version ";         287       versionString = " Geant4 version ";
249       versionString += vs;                        288       versionString += vs;
250       versionString += "   ";                     289       versionString += "   ";
251       versionString += G4Date;                    290       versionString += G4Date;
252       G4cout << G4endl << "******************* << 291       G4cout << G4endl
253              << versionString << G4endl << "   << 292              << "**************************************************************"
254              << "                       Copyri << 293              << G4endl << versionString << G4endl
255              << "                      Referen << 294              << "  << in Multi-threaded mode >> " << G4endl
256              << "                              << 295              << "                       Copyright : Geant4 Collaboration"
257              << "                              << 296              << G4endl
258              << "                              << 297              << "                      References : NIM A 506 (2003), 250-303"
259              << "***************************** << 298              << G4endl
260              << G4endl;                        << 299              << "                                 : IEEE-TNS 53 (2006), 270-278"
                                                   >> 300              << G4endl
                                                   >> 301              << "                                 : NIM A 835 (2016), 186-225"
                                                   >> 302              << G4endl
                                                   >> 303              << "                             WWW : http://geant4.org/"
                                                   >> 304              << G4endl
                                                   >> 305              << "**************************************************************"
                                                   >> 306              << G4endl << G4endl;
261       break;                                      307       break;
262     default:                                      308     default:
263       if (verboseLevel != 0) {                 << 309       if(verboseLevel)
                                                   >> 310       {
264         versionString = " Local thread RunMana    311         versionString = " Local thread RunManagerKernel version ";
265         versionString += vs;                      312         versionString += vs;
266         G4cout << G4endl                       << 313         G4cout
267                << "^^^^^^^^^^^^^^^^^^^^^^^^^^^ << 314           << G4endl
268                   "^^^^^^^^^"                  << 315           << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
269                << G4endl << versionString << G << 316              "^^^^^^^^^"
270                << "^^^^^^^^^^^^^^^^^^^^^^^^^^^ << 317           << G4endl << versionString << G4endl
271                   "^^^^^^^^^"                  << 318           << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
272                << G4endl << G4endl;            << 319              "^^^^^^^^^"
                                                   >> 320           << G4endl << G4endl;
273       }                                           321       }
274   }                                               322   }
275                                                   323 
276 #ifdef G4MULTITHREADED                         << 324   #ifdef G4MULTITHREADED
277   G4UnitDefinition::GetUnitsTable().Synchroniz << 325     G4UnitDefinition::GetUnitsTable().Synchronize();
278 #endif                                         << 326   #endif
279 }                                                 327 }
280                                                   328 
281 // -------------------------------------------    329 // --------------------------------------------------------------------
282 void G4RunManagerKernel::SetupDefaultRegion()     330 void G4RunManagerKernel::SetupDefaultRegion()
283 {                                                 331 {
284   if (runManagerKernelType == workerRMK) retur << 332   if(runManagerKernelType == workerRMK)
                                                   >> 333     return;
285                                                   334 
286   // Remove old world logical volume from the     335   // Remove old world logical volume from the default region, if exist
287   if (defaultRegion->GetNumberOfRootVolumes()  << 336   if(defaultRegion->GetNumberOfRootVolumes())
288     if (defaultRegion->GetNumberOfRootVolumes( << 337   {
                                                   >> 338     if(defaultRegion->GetNumberOfRootVolumes() > size_t(1))
                                                   >> 339     {
289       G4Exception("G4RunManager::SetupDefaultR    340       G4Exception("G4RunManager::SetupDefaultRegion", "Run0005", FatalException,
290                   "Default world region should    341                   "Default world region should have a unique logical volume.");
291     }                                             342     }
292     auto lvItr = defaultRegion->GetRootLogical    343     auto lvItr = defaultRegion->GetRootLogicalVolumeIterator();
293     defaultRegion->RemoveRootLogicalVolume(*lv    344     defaultRegion->RemoveRootLogicalVolume(*lvItr, false);
294     if (verboseLevel > 1)                      << 345     if(verboseLevel > 1)
295       G4cout << "Obsolete world logical volume << 346       G4cout
                                                   >> 347         << "Obsolete world logical volume is removed from the default region."
                                                   >> 348         << G4endl;
296   }                                               349   }
297 }                                                 350 }
298                                                   351 
299 // -------------------------------------------    352 // --------------------------------------------------------------------
300 G4RunManagerKernel::~G4RunManagerKernel()         353 G4RunManagerKernel::~G4RunManagerKernel()
301 {                                                 354 {
302   G4StateManager* pStateManager = G4StateManag    355   G4StateManager* pStateManager = G4StateManager::GetStateManager();
303   // set the application state to the quite st    356   // set the application state to the quite state
304   if (pStateManager->GetCurrentState() != G4St << 357   if(pStateManager->GetCurrentState() != G4State_Quit)
305     if (verboseLevel > 1) G4cout << "G4 kernel << 358   {
                                                   >> 359     if(verboseLevel > 0)
                                                   >> 360       G4cout << "G4 kernel has come to Quit state." << G4endl;
306     pStateManager->SetNewState(G4State_Quit);     361     pStateManager->SetNewState(G4State_Quit);
307   }                                               362   }
308                                                   363 
309   // open geometry for deletion                   364   // open geometry for deletion
310   G4GeometryManager::GetInstance()->OpenGeomet    365   G4GeometryManager::GetInstance()->OpenGeometry();
311                                                   366 
312   // deletion of Geant4 kernel classes            367   // deletion of Geant4 kernel classes
313   delete G4ParallelWorldProcessStore::GetInsta    368   delete G4ParallelWorldProcessStore::GetInstanceIfExist();
314   delete G4SDManager::GetSDMpointerIfExist();     369   delete G4SDManager::GetSDMpointerIfExist();
315   if (verboseLevel > 1) G4cout << "G4SDManager << 370   if(verboseLevel > 1)
                                                   >> 371     G4cout << "G4SDManager deleted." << G4endl;
316   delete eventManager;                            372   delete eventManager;
317   if (verboseLevel > 1) G4cout << "EventManage << 373   if(verboseLevel > 1)
                                                   >> 374     G4cout << "EventManager deleted." << G4endl;
318                                                   375 
319   G4UnitDefinition::ClearUnitsTable();            376   G4UnitDefinition::ClearUnitsTable();
320   if (verboseLevel > 1) G4cout << "Units table << 377   if(verboseLevel > 1)
                                                   >> 378     G4cout << "Units table cleared." << G4endl;
321                                                   379 
322   // deletion of path-finder field-manager sto    380   // deletion of path-finder field-manager store, geometry and transportation
323   // manager                                      381   // manager
324   delete G4PathFinder::GetInstanceIfExist();      382   delete G4PathFinder::GetInstanceIfExist();
325   delete G4FieldManagerStore::GetInstanceIfExi    383   delete G4FieldManagerStore::GetInstanceIfExist();
326   delete G4GeometryManager::GetInstanceIfExist    384   delete G4GeometryManager::GetInstanceIfExist();
327   delete G4TransportationManager::GetInstanceI    385   delete G4TransportationManager::GetInstanceIfExist();
328   if (verboseLevel > 1) G4cout << "Transportat << 386   if(verboseLevel > 1)
                                                   >> 387     G4cout << "TransportationManager deleted." << G4endl;
329                                                   388 
330   // deletion of navigation levels                389   // deletion of navigation levels
331   if (verboseLevel > 1) G4NavigationHistoryPoo << 390   if(verboseLevel > 1)
                                                   >> 391     G4NavigationHistoryPool::GetInstance()->Print();
332   delete G4NavigationHistoryPool::GetInstance(    392   delete G4NavigationHistoryPool::GetInstance();
333                                                   393 
334   // deletion of G4RNGHelper singleton            394   // deletion of G4RNGHelper singleton
335   if (runManagerKernelType != workerRMK) {     << 395   if(runManagerKernelType != workerRMK)
                                                   >> 396   {
336     delete G4RNGHelper::GetInstanceIfExist();     397     delete G4RNGHelper::GetInstanceIfExist();
337     if (verboseLevel > 1) G4cout << "G4RNGHelp << 398     if(verboseLevel > 1)
                                                   >> 399       G4cout << "G4RNGHelper object is deleted." << G4endl;
338   }                                               400   }
339                                                   401 
340   // deletion of allocators                       402   // deletion of allocators
341   G4AllocatorList* allocList = G4AllocatorList    403   G4AllocatorList* allocList = G4AllocatorList::GetAllocatorListIfExist();
342   if (allocList != nullptr) {                  << 404   if(allocList)
                                                   >> 405   {
343     allocList->Destroy(numberOfStaticAllocator    406     allocList->Destroy(numberOfStaticAllocators, verboseLevel);
344     delete allocList;                             407     delete allocList;
345     if (verboseLevel > 1) G4cout << "G4Allocat << 408     if(verboseLevel > 1)
                                                   >> 409       G4cout << "G4Allocator objects are deleted." << G4endl;
346   }                                               410   }
347                                                   411 
348   G4UImanager* pUImanager = G4UImanager::GetUI    412   G4UImanager* pUImanager = G4UImanager::GetUIpointer();
349   if ((runManagerKernelType == workerRMK) && ( << 413   if((runManagerKernelType == workerRMK) && (verboseLevel > 0))
                                                   >> 414   {
350     G4cout << "Thread-local UImanager is to be    415     G4cout << "Thread-local UImanager is to be deleted." << G4endl
351            << "There should not be any thread- << 416            << "There should not be any thread-local G4cout/G4cerr hereafter."
                                                   >> 417            << G4endl;
                                                   >> 418     verboseLevel = 0;
352   }                                               419   }
353   delete pUImanager;                              420   delete pUImanager;
354   if (verboseLevel > 1) G4cout << "UImanager d << 421   if(verboseLevel > 1)
                                                   >> 422     G4cout << "UImanager deleted." << G4endl;
355                                                   423 
356   delete pStateManager;                           424   delete pStateManager;
357   if (verboseLevel > 1) G4cout << "StateManage << 425   if(verboseLevel > 1)
                                                   >> 426     G4cout << "StateManager deleted." << G4endl;
358   delete defaultExceptionHandler;                 427   delete defaultExceptionHandler;
359   if (verboseLevel > 1) G4cout << "RunManagerK << 428   if(verboseLevel > 0)
                                                   >> 429     G4cout << "RunManagerKernel is deleted. Good bye :)" << G4endl;
360   fRunManagerKernel = nullptr;                    430   fRunManagerKernel = nullptr;
361 }                                                 431 }
362                                                   432 
363 // -------------------------------------------    433 // --------------------------------------------------------------------
364 void G4RunManagerKernel::WorkerUpdateWorldVolu    434 void G4RunManagerKernel::WorkerUpdateWorldVolume()
365 {                                                 435 {
366   G4MTRunManager* masterRM = G4MTRunManager::G    436   G4MTRunManager* masterRM = G4MTRunManager::GetMasterRunManager();
367   G4TransportationManager* transM = G4Transpor << 437   G4TransportationManager* transM =
368   G4MTRunManager::masterWorlds_t masterWorlds  << 438     G4TransportationManager::GetTransportationManager();
369   for (const auto& masterWorld : masterWorlds) << 439   G4MTRunManager::masterWorlds_t masterWorlds    = masterRM->GetMasterWorlds();
370     G4VPhysicalVolume* wv = masterWorld.second << 440   for(auto itrMW = masterWorlds.cbegin();
                                                   >> 441            itrMW != masterWorlds.cend(); ++itrMW)
                                                   >> 442   {
                                                   >> 443     G4VPhysicalVolume* wv = (*itrMW).second;
371     G4VPhysicalVolume* pWorld =                   444     G4VPhysicalVolume* pWorld =
372       G4TransportationManager::GetTransportati << 445       G4TransportationManager::GetTransportationManager()
373     if (pWorld == nullptr) {                   << 446       ->IsWorldExisting(wv->GetName());
                                                   >> 447     if(pWorld == nullptr)
                                                   >> 448     {
374       transM->RegisterWorld(wv);                  449       transM->RegisterWorld(wv);
375     }                                             450     }
376   }                                               451   }
377 }                                                 452 }
378                                                   453 
379 // -------------------------------------------    454 // --------------------------------------------------------------------
380 void G4RunManagerKernel::WorkerDefineWorldVolu    455 void G4RunManagerKernel::WorkerDefineWorldVolume(G4VPhysicalVolume* worldVol,
381                                                   456                                                  G4bool topologyIsChanged)
382 {                                                 457 {
383   G4StateManager* stateManager = G4StateManage << 458   G4StateManager* stateManager    = G4StateManager::GetStateManager();
384   G4ApplicationState currentState = stateManag    459   G4ApplicationState currentState = stateManager->GetCurrentState();
385   if (currentState != G4State_Init) {          << 460   if(currentState != G4State_Init)
386     if (currentState != G4State_Idle && curren << 461   {
387       G4cout << "Current application state is  << 462     if(!(currentState == G4State_Idle || currentState == G4State_PreInit))
388              << G4endl;                        << 463     {
389       G4Exception("G4RunManagerKernel::DefineW << 464       G4cout << "Current application state is "
390                   FatalException, "Geant4 kern << 465              << stateManager->GetStateString(currentState) << G4endl;
                                                   >> 466       G4Exception("G4RunManagerKernel::DefineWorldVolume",
                                                   >> 467                   "DefineWorldVolumeAtIncorrectState", FatalException,
                                                   >> 468                   "Geant4 kernel is not Init state : Method ignored.");
391       return;                                     469       return;
392     }                                             470     }
393                                                << 471     else
394     stateManager->SetNewState(G4State_Init);   << 472     {
                                                   >> 473       stateManager->SetNewState(G4State_Init);
                                                   >> 474     }
395   }                                               475   }
396                                                   476 
397   currentWorld = worldVol;                     << 477   currentWorld             = worldVol;
398   G4MTRunManager* masterRM = G4MTRunManager::G    478   G4MTRunManager* masterRM = G4MTRunManager::GetMasterRunManager();
399   G4TransportationManager* transM = G4Transpor << 479   G4TransportationManager* transM =
                                                   >> 480     G4TransportationManager::GetTransportationManager();
400   G4MTRunManager::masterWorlds_t masterWorlds     481   G4MTRunManager::masterWorlds_t masterWorlds = masterRM->GetMasterWorlds();
401   for (const auto& masterWorld : masterWorlds) << 482   for(auto itrMW = masterWorlds.cbegin();
402     if (masterWorld.first == 0) {              << 483            itrMW != masterWorlds.cend(); ++itrMW)
403       if (masterWorld.second != currentWorld)  << 484   {
404         G4Exception("G4RunManagerKernel::Worke << 485     if((*itrMW).first == 0)
405                     "Mass world is inconsisten << 486     {
                                                   >> 487       if((*itrMW).second != currentWorld)
                                                   >> 488       {
                                                   >> 489         G4Exception("G4RunManagerKernel::WorkerDefineWorldVolume", "RUN3091",
                                                   >> 490                     FatalException, "Mass world is inconsistent");
406       }                                           491       }
407       transM->SetWorldForTracking(masterWorld. << 492       transM->SetWorldForTracking((*itrMW).second);
408     }                                             493     }
409     else {                                     << 494     else
410       transM->RegisterWorld(masterWorld.second << 495     {
                                                   >> 496       transM->RegisterWorld((*itrMW).second);
411     }                                             497     }
412   }                                               498   }
413                                                   499 
414   if (topologyIsChanged) geometryNeedsToBeClos << 500   if(topologyIsChanged)
                                                   >> 501     geometryNeedsToBeClosed = true;
415                                                   502 
416   // Notify the VisManager as well                503   // Notify the VisManager as well
417   if (G4Threading::IsMasterThread()) {         << 504   if(G4Threading::IsMasterThread())
                                                   >> 505   {
418     G4VVisManager* pVVisManager = G4VVisManage    506     G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
419     if (pVVisManager != nullptr) pVVisManager- << 507     if(pVVisManager != nullptr)
                                                   >> 508       pVVisManager->GeometryHasChanged();
420   }                                               509   }
421                                                   510 
422   geometryInitialized = true;                     511   geometryInitialized = true;
423   stateManager->SetNewState(currentState);        512   stateManager->SetNewState(currentState);
424   if (physicsInitialized && currentState != G4 << 513   if(physicsInitialized && currentState != G4State_Idle)
                                                   >> 514   {
425     stateManager->SetNewState(G4State_Idle);      515     stateManager->SetNewState(G4State_Idle);
426   }                                               516   }
427 }                                                 517 }
428                                                   518 
429 // -------------------------------------------    519 // --------------------------------------------------------------------
430 void G4RunManagerKernel::DefineWorldVolume(G4V << 520 void G4RunManagerKernel::DefineWorldVolume(G4VPhysicalVolume* worldVol,
                                                   >> 521                                            G4bool topologyIsChanged)
431 {                                                 522 {
432   G4StateManager* stateManager = G4StateManage << 523   G4StateManager* stateManager    = G4StateManager::GetStateManager();
433   G4ApplicationState currentState = stateManag    524   G4ApplicationState currentState = stateManager->GetCurrentState();
434                                                   525 
435   if (currentState != G4State_Init) {          << 526   if(currentState != G4State_Init)
436     if (currentState != G4State_Idle && curren << 527   {
437       G4cout << "Current application state is  << 528     if(!(currentState == G4State_Idle || currentState == G4State_PreInit))
438              << G4endl;                        << 529     {
439       G4Exception("G4RunManagerKernel::DefineW << 530       G4cout << "Current application state is "
440                   FatalException, "Geant4 kern << 531              << stateManager->GetStateString(currentState) << G4endl;
                                                   >> 532       G4Exception("G4RunManagerKernel::DefineWorldVolume",
                                                   >> 533                   "DefineWorldVolumeAtIncorrectState", FatalException,
                                                   >> 534                   "Geant4 kernel is not Init state : Method ignored.");
441       return;                                     535       return;
442     }                                             536     }
443                                                << 537     else
444     stateManager->SetNewState(G4State_Init);   << 538     {
                                                   >> 539       stateManager->SetNewState(G4State_Init);
                                                   >> 540     }
445   }                                               541   }
446                                                   542 
447   // The world volume MUST NOT have a region d    543   // The world volume MUST NOT have a region defined by the user
448   if (worldVol->GetLogicalVolume()->GetRegion( << 544   if(worldVol->GetLogicalVolume()->GetRegion() != nullptr)
449     if (worldVol->GetLogicalVolume()->GetRegio << 545   {
                                                   >> 546     if(worldVol->GetLogicalVolume()->GetRegion() != defaultRegion)
                                                   >> 547     {
450       G4ExceptionDescription ED;                  548       G4ExceptionDescription ED;
451       ED << "The world volume has a user-defin    549       ED << "The world volume has a user-defined region <"
452          << worldVol->GetLogicalVolume()->GetR << 550          << worldVol->GetLogicalVolume()->GetRegion()->GetName() << ">."
453       ED << "World would have a default region << 551          << G4endl;
454       G4Exception("G4RunManager::DefineWorldVo << 552       ED << "World would have a default region assigned by RunManagerKernel."
                                                   >> 553          << G4endl;
                                                   >> 554       G4Exception("G4RunManager::DefineWorldVolume", "Run0004", FatalException,
                                                   >> 555                   ED);
455     }                                             556     }
456   }                                               557   }
457                                                   558 
458   SetupDefaultRegion();                           559   SetupDefaultRegion();
459                                                   560 
460   // Accept the world volume                      561   // Accept the world volume
461   currentWorld = worldVol;                        562   currentWorld = worldVol;
462                                                   563 
463   // Set the default region to the world          564   // Set the default region to the world
464                                                   565 
465   G4LogicalVolume* worldLog = currentWorld->Ge    566   G4LogicalVolume* worldLog = currentWorld->GetLogicalVolume();
466   worldLog->SetRegion(defaultRegion);             567   worldLog->SetRegion(defaultRegion);
467   defaultRegion->AddRootLogicalVolume(worldLog    568   defaultRegion->AddRootLogicalVolume(worldLog);
468   if (verboseLevel > 1)                        << 569   if(verboseLevel > 1)
469     G4cout << worldLog->GetName() << " is regi << 570     G4cout << worldLog->GetName() << " is registered to the default region."
                                                   >> 571            << G4endl;
470                                                   572 
471   // Set the world volume, notify the Navigato    573   // Set the world volume, notify the Navigator and reset its state
472   G4TransportationManager::GetTransportationMa << 574   G4TransportationManager::GetTransportationManager()
473   if (topologyIsChanged) geometryNeedsToBeClos << 575     ->SetWorldForTracking(currentWorld);
                                                   >> 576   if(topologyIsChanged)
                                                   >> 577     geometryNeedsToBeClosed = true;
474                                                   578 
475   // Notify the VisManager as well                579   // Notify the VisManager as well
476   if (G4Threading::IsMasterThread()) {         << 580   if(G4Threading::IsMasterThread())
                                                   >> 581   {
477     G4VVisManager* pVVisManager = G4VVisManage    582     G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
478     if (pVVisManager != nullptr) pVVisManager- << 583     if(pVVisManager != nullptr)
                                                   >> 584       pVVisManager->GeometryHasChanged();
479   }                                               585   }
480                                                   586 
481   geometryInitialized = true;                     587   geometryInitialized = true;
482   stateManager->SetNewState(currentState);        588   stateManager->SetNewState(currentState);
483   if (physicsInitialized && currentState != G4 << 589   if(physicsInitialized && currentState != G4State_Idle)
                                                   >> 590   {
484     stateManager->SetNewState(G4State_Idle);      591     stateManager->SetNewState(G4State_Idle);
485   }                                               592   }
486 }                                                 593 }
487                                                   594 
488 // -------------------------------------------    595 // --------------------------------------------------------------------
489 void G4RunManagerKernel::SetPhysics(G4VUserPhy    596 void G4RunManagerKernel::SetPhysics(G4VUserPhysicsList* uPhys)
490 {                                                 597 {
491   physicsList = uPhys;                            598   physicsList = uPhys;
492                                                   599 
493   if (runManagerKernelType == workerRMK) retur << 600   if(runManagerKernelType == workerRMK)
                                                   >> 601     return;
494                                                   602 
495   SetupPhysics();                                 603   SetupPhysics();
496   if (verboseLevel > 2) G4ParticleTable::GetPa << 604   if(verboseLevel > 2)
497   if (verboseLevel > 1) {                      << 605     G4ParticleTable::GetParticleTable()->DumpTable();
                                                   >> 606   if(verboseLevel > 1)
                                                   >> 607   {
498     G4cout << "List of instantiated particles     608     G4cout << "List of instantiated particles "
499               "===============================    609               "============================================"
500            << G4endl;                             610            << G4endl;
501     G4int nPtcl = G4ParticleTable::GetParticle    611     G4int nPtcl = G4ParticleTable::GetParticleTable()->entries();
502     for (G4int i = 0; i < nPtcl; ++i) {        << 612     for(G4int i = 0; i < nPtcl; ++i)
503       G4ParticleDefinition* pd = G4ParticleTab << 613     {
                                                   >> 614       G4ParticleDefinition* pd =
                                                   >> 615         G4ParticleTable::GetParticleTable()->GetParticle(i);
504       G4cout << pd->GetParticleName() << " ";     616       G4cout << pd->GetParticleName() << " ";
505       if (i % 10 == 9) G4cout << G4endl;       << 617       if(i % 10 == 9)
                                                   >> 618         G4cout << G4endl;
506     }                                             619     }
507     G4cout << G4endl;                             620     G4cout << G4endl;
508   }                                               621   }
509 }                                                 622 }
510                                                   623 
511 // -------------------------------------------    624 // --------------------------------------------------------------------
512 void G4RunManagerKernel::SetupPhysics()           625 void G4RunManagerKernel::SetupPhysics()
513 {                                                 626 {
514   G4ParticleTable::GetParticleTable()->SetRead    627   G4ParticleTable::GetParticleTable()->SetReadiness();
515                                                   628 
516   physicsList->ConstructParticle();               629   physicsList->ConstructParticle();
517                                                   630 
518   // For sanity reason                            631   // For sanity reason
519   G4Geantino::GeantinoDefinition();               632   G4Geantino::GeantinoDefinition();
520   G4ParticleDefinition* gion = G4ParticleTable << 633   G4ParticleDefinition* gion =
521   if (gion != nullptr) {                       << 634     G4ParticleTable::GetParticleTable()->GetGenericIon();
                                                   >> 635   if(gion != nullptr)
                                                   >> 636   {
522     G4IonConstructor::ConstructParticle();        637     G4IonConstructor::ConstructParticle();
523   }                                               638   }
524   G4ParticleTable::GetParticleTable()->GetIonT    639   G4ParticleTable::GetParticleTable()->GetIonTable()->InitializeLightIons();
525                                                   640 
526   auto pItr = G4ParticleTable::GetParticleTabl    641   auto pItr = G4ParticleTable::GetParticleTable()->GetIterator();
527   pItr->reset();                                  642   pItr->reset();
528   while ((*pItr)()) {                          << 643   while((*pItr)())
                                                   >> 644   {
529     G4ParticleDefinition* particle = pItr->val    645     G4ParticleDefinition* particle = pItr->value();
530     if (!(particle->IsGeneralIon())) particle- << 646     if(!(particle->IsGeneralIon()))
                                                   >> 647       particle->SetParticleDefinitionID();
531   }                                               648   }
532                                                   649 
533   if (gion != nullptr) {                       << 650   if(gion != nullptr)
                                                   >> 651   {
534     G4int gionId = gion->GetParticleDefinition    652     G4int gionId = gion->GetParticleDefinitionID();
535     pItr->reset(false);                           653     pItr->reset(false);
536     while ((*pItr)()) {                        << 654     while((*pItr)())
                                                   >> 655     {
537       G4ParticleDefinition* particle = pItr->v    656       G4ParticleDefinition* particle = pItr->value();
538       if (particle->IsGeneralIon()) particle-> << 657       if(particle->IsGeneralIon())
                                                   >> 658         particle->SetParticleDefinitionID(gionId);
539     }                                             659     }
540   }                                               660   }
541 #ifdef G4MULTITHREADED                            661 #ifdef G4MULTITHREADED
542   G4UnitDefinition::GetUnitsTable().Synchroniz    662   G4UnitDefinition::GetUnitsTable().Synchronize();
543 #endif                                            663 #endif
544 }                                                 664 }
545                                                   665 
546 // -------------------------------------------    666 // --------------------------------------------------------------------
547 namespace                                         667 namespace
548 {                                                 668 {
549 G4Mutex initphysicsmutex = G4MUTEX_INITIALIZER << 669   G4Mutex initphysicsmutex = G4MUTEX_INITIALIZER;
550 }                                                 670 }
551                                                   671 
552 // -------------------------------------------    672 // --------------------------------------------------------------------
553 void G4RunManagerKernel::InitializePhysics()      673 void G4RunManagerKernel::InitializePhysics()
554 {                                                 674 {
555   G4StateManager* stateManager = G4StateManage << 675   G4StateManager* stateManager    = G4StateManager::GetStateManager();
556   G4ApplicationState currentState = stateManag    676   G4ApplicationState currentState = stateManager->GetCurrentState();
557   if (currentState != G4State_Init) {          << 677   if(currentState != G4State_Init)
558     G4cout << "Current application state is "  << 678   {
559            << G4endl;                          << 679     G4cout << "Current application state is "
560     if (currentState != G4State_Idle && curren << 680            << stateManager->GetStateString(currentState) << G4endl;
561       G4Exception("G4RunManagerKernel::Initial << 681     if(!(currentState == G4State_Idle || currentState == G4State_PreInit))
562                   FatalException, "Geant4 kern << 682     {
                                                   >> 683       G4Exception("G4RunManagerKernel::InitializePhysics",
                                                   >> 684                   "InitializePhysicsIncorrectState", FatalException,
                                                   >> 685                   "Geant4 kernel is not Init state : Method ignored.");
563       return;                                     686       return;
564     }                                             687     }
565                                                << 688     else
566     G4cout << "Warning : Geant4 kernel is not  << 689     {
567     stateManager->SetNewState(G4State_Init);   << 690       // G4Exception("G4RunManagerKernel::DefineWorldVolume",
                                                   >> 691       //             "DefineWorldVolumeAtIncorrectState", JustWarning,
                                                   >> 692       // "Geant4 kernel is not Init state : Assuming Init state.");
                                                   >> 693       G4cout
                                                   >> 694         << "Warning : Geant4 kernel is not Init state : Assuming Init state."
                                                   >> 695         << G4endl;
                                                   >> 696       stateManager->SetNewState(G4State_Init);
                                                   >> 697     }
568   }                                               698   }
569                                                   699 
570   if (physicsList == nullptr) {                << 700   if(physicsList == nullptr)
571     G4Exception("G4RunManagerKernel::Initializ << 701   {
572                 "G4VUserPhysicsList is not def << 702     G4Exception("G4RunManagerKernel::InitializePhysics", "Run0012",
                                                   >> 703                 FatalException, "G4VUserPhysicsList is not defined");
573     return;                                       704     return;
574   }                                               705   }
575                                                   706 
576   if (verboseLevel > 1) G4cout << "physicsList << 707   if(verboseLevel > 1)
577   if (numberOfParallelWorld > 0) physicsList-> << 708     G4cout << "physicsList->Construct() start." << G4endl;
                                                   >> 709   if(numberOfParallelWorld > 0)
                                                   >> 710     physicsList->UseCoupledTransportation();
578   physicsList->Construct();                       711   physicsList->Construct();
579                                                   712 
580   if (verboseLevel > 1) G4cout << "physicsList << 713   if(verboseLevel > 1)
                                                   >> 714     G4cout << "physicsList->CheckParticleList() start." << G4endl;
581   physicsList->CheckParticleList();               715   physicsList->CheckParticleList();
582                                                   716 
583   // Cannot assume that SetCuts() and CheckReg    717   // Cannot assume that SetCuts() and CheckRegions() are thread safe.
584   // We need to mutex (report from valgrind --    718   // We need to mutex (report from valgrind --tool=drd)
585   G4AutoLock l(&initphysicsmutex);                719   G4AutoLock l(&initphysicsmutex);
586   if (G4Threading::IsMasterThread()) {         << 720   if(G4Threading::IsMasterThread())
587     if (verboseLevel > 1) G4cout << "physicsLi << 721   {
                                                   >> 722     if(verboseLevel > 1)
                                                   >> 723       G4cout << "physicsList->setCut() start." << G4endl;
588     physicsList->SetCuts();                       724     physicsList->SetCuts();
589   }                                               725   }
590   CheckRegions();                                 726   CheckRegions();
591   l.unlock();                                     727   l.unlock();
592                                                   728 
593   physicsInitialized = true;                   << 729   /*******************
                                                   >> 730   // static G4bool createIsomerOnlyOnce = false;
                                                   >> 731   // if(G4Threading::IsMultithreadedApplication() &&
                                                   >> 732         G4Threading::IsMasterThread())
                                                   >> 733   // {
                                                   >> 734   //   if(!createIsomerOnlyOnce)
                                                   >> 735   //   {
                                                   >> 736   //     createIsomerOnlyOnce = true;
                                                   >> 737   //     G4ParticleDefinition* gion =
                                                   >> 738          G4ParticleTable::GetParticleTable()->GetGenericIon();
                                                   >> 739   //     if(gion != nullptr)
                                                   >> 740   //     {
                                                   >> 741   //       G4ParticleTable::GetParticleTable()
                                                   >> 742            ->GetIonTable()->CreateAllIsomer();
                                                   >> 743   //       PropagateGenericIonID();
                                                   >> 744   //     }
                                                   >> 745   //   }
                                                   >> 746   // }
                                                   >> 747   *********************/
594                                                   748 
                                                   >> 749   physicsInitialized = true;
595 #ifdef G4MULTITHREADED                            750 #ifdef G4MULTITHREADED
596   G4UnitDefinition::GetUnitsTable().Synchroniz    751   G4UnitDefinition::GetUnitsTable().Synchronize();
597 #endif                                            752 #endif
598                                                << 
599   stateManager->SetNewState(currentState);        753   stateManager->SetNewState(currentState);
600   if (geometryInitialized && currentState != G << 754   if(geometryInitialized && currentState != G4State_Idle)
                                                   >> 755   {
601     stateManager->SetNewState(G4State_Idle);      756     stateManager->SetNewState(G4State_Idle);
602   }                                               757   }
603 }                                                 758 }
604                                                   759 
605 // -------------------------------------------    760 // --------------------------------------------------------------------
606 G4bool G4RunManagerKernel::RunInitialization(G    761 G4bool G4RunManagerKernel::RunInitialization(G4bool fakeRun)
607 {                                                 762 {
608   G4StateManager* stateManager = G4StateManage << 763   G4StateManager* stateManager    = G4StateManager::GetStateManager();
609   G4ApplicationState currentState = stateManag    764   G4ApplicationState currentState = stateManager->GetCurrentState();
610                                                   765 
611   if (!geometryInitialized) {                  << 766   if(!geometryInitialized)
                                                   >> 767   {
612     G4Exception("G4RunManagerKernel::RunInitia    768     G4Exception("G4RunManagerKernel::RunInitialization", "Run0021", JustWarning,
613                 "Geometry has not yet initiali    769                 "Geometry has not yet initialized : method ignored.");
614     return false;                                 770     return false;
615   }                                               771   }
616                                                   772 
617   if (!physicsInitialized) {                   << 773   if(!physicsInitialized)
                                                   >> 774   {
618     G4Exception("G4RunManagerKernel::RunInitia    775     G4Exception("G4RunManagerKernel::RunInitialization", "Run0022", JustWarning,
619                 "Physics has not yet initializ    776                 "Physics has not yet initialized : method ignored.");
620     return false;                                 777     return false;
621   }                                               778   }
622                                                   779 
623   if (currentState != G4State_Idle) {          << 780   if(currentState != G4State_Idle)
                                                   >> 781   {
624     G4Exception("G4RunManagerKernel::RunInitia    782     G4Exception("G4RunManagerKernel::RunInitialization", "Run0023", JustWarning,
625                 "Geant4 kernel not in Idle sta    783                 "Geant4 kernel not in Idle state : method ignored.");
626     return false;                                 784     return false;
627   }                                               785   }
628                                                   786 
629   if (geometryNeedsToBeClosed) CheckRegularGeo << 787   if(geometryNeedsToBeClosed)
                                                   >> 788     CheckRegularGeometry();
630                                                   789 
631   stateManager->SetNewState(G4State_Init);        790   stateManager->SetNewState(G4State_Init);
632   PropagateGenericIonID();                        791   PropagateGenericIonID();
633   SetupShadowProcess();                           792   SetupShadowProcess();
634   UpdateRegion();                                 793   UpdateRegion();
635   BuildPhysicsTables(fakeRun);                    794   BuildPhysicsTables(fakeRun);
636                                                   795 
637   if (geometryNeedsToBeClosed) {               << 796   if(geometryNeedsToBeClosed)
638     if(!fakeRun || resetNavigatorAtInitializat << 797   {
                                                   >> 798     ResetNavigator();
639     // CheckRegularGeometry();                    799     // CheckRegularGeometry();
640     // Notify the VisManager as well              800     // Notify the VisManager as well
641     if (G4Threading::IsMasterThread()) {       << 801     if(G4Threading::IsMasterThread())
                                                   >> 802     {
642       G4VVisManager* pVVisManager = G4VVisMana    803       G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
643       if (pVVisManager != nullptr) pVVisManage << 804       if(pVVisManager != nullptr)
                                                   >> 805         pVVisManager->GeometryHasChanged();
644     }                                             806     }
645   }                                               807   }
646                                                   808 
647   GetPrimaryTransformer()->CheckUnknown();        809   GetPrimaryTransformer()->CheckUnknown();
648                                                   810 
649 #ifdef G4MULTITHREADED                            811 #ifdef G4MULTITHREADED
650   G4UnitDefinition::GetUnitsTable().Synchroniz    812   G4UnitDefinition::GetUnitsTable().Synchronize();
651 #endif                                            813 #endif
652                                                << 
653   stateManager->SetNewState(G4State_Idle);        814   stateManager->SetNewState(G4State_Idle);
654   stateManager->SetNewState(G4State_GeomClosed    815   stateManager->SetNewState(G4State_GeomClosed);
655   return true;                                    816   return true;
656 }                                                 817 }
657                                                   818 
658 // -------------------------------------------    819 // --------------------------------------------------------------------
659 void G4RunManagerKernel::PropagateGenericIonID    820 void G4RunManagerKernel::PropagateGenericIonID()
660 {                                                 821 {
661   G4ParticleDefinition* gion = G4ParticleTable << 822   G4ParticleDefinition* gion =
662   if (gion != nullptr) {                       << 823     G4ParticleTable::GetParticleTable()->GetGenericIon();
                                                   >> 824   if(gion != nullptr)
                                                   >> 825   {
                                                   >> 826     // G4ParticleTable::GetParticleTable()->GetIonTable()->CreateAllIsomer();
663     G4int gionId = gion->GetParticleDefinition    827     G4int gionId = gion->GetParticleDefinitionID();
664     auto pItr = G4ParticleTable::GetParticleTa    828     auto pItr = G4ParticleTable::GetParticleTable()->GetIterator();
665     pItr->reset(false);                           829     pItr->reset(false);
666     while ((*pItr)()) {                        << 830     while((*pItr)())
                                                   >> 831     {
667       G4ParticleDefinition* particle = pItr->v    832       G4ParticleDefinition* particle = pItr->value();
668       if (particle->IsGeneralIon()) particle-> << 833       if(particle->IsGeneralIon())
                                                   >> 834         particle->SetParticleDefinitionID(gionId);
669     }                                             835     }
670   }                                               836   }
671 }                                                 837 }
672                                                   838 
673 // -------------------------------------------    839 // --------------------------------------------------------------------
674 void G4RunManagerKernel::RunTermination()         840 void G4RunManagerKernel::RunTermination()
675 {                                                 841 {
676   if (runManagerKernelType != workerRMK)       << 842   if(runManagerKernelType != workerRMK)
677   { G4ProductionCutsTable::GetProductionCutsTa << 843     G4ProductionCutsTable::GetProductionCutsTable()->PhysicsTableUpdated();
678   G4StateManager::GetStateManager()->SetNewSta    844   G4StateManager::GetStateManager()->SetNewState(G4State_Idle);
679 }                                                 845 }
680                                                   846 
681 // -------------------------------------------    847 // --------------------------------------------------------------------
682 void G4RunManagerKernel::ResetNavigator()         848 void G4RunManagerKernel::ResetNavigator()
683 {                                                 849 {
684   G4GeometryManager* geomManager = G4GeometryM << 850   if(runManagerKernelType == workerRMK)
685   if (runManagerKernelType == workerRMK) {     << 851   {
686     // To ensure that it is called when using  << 
687     if( geomManager->IsParallelOptimisationCon << 
688        !geomManager->IsParallelOptimisationFin << 
689     {                                          << 
690       geomManager->UndertakeOptimisation();    << 
691     }                                          << 
692     geometryNeedsToBeClosed = false;              852     geometryNeedsToBeClosed = false;
693     return;                                       853     return;
694   }                                               854   }
695                                                   855 
696   // We have to tweak the navigator's state in    856   // We have to tweak the navigator's state in case a geometry has been
697   // modified between runs. By the following c    857   // modified between runs. By the following calls we ensure that navigator's
698   // state is reset properly. It is required t    858   // state is reset properly. It is required the geometry to be closed
699   // and previous optimisations to be cleared.    859   // and previous optimisations to be cleared.
700                                                   860 
701   if (verboseLevel > 1) G4cout << "Start closi << 861   G4GeometryManager* geomManager = G4GeometryManager::GetInstance();
                                                   >> 862   if(verboseLevel > 1)
                                                   >> 863     G4cout << "Start closing geometry." << G4endl;
702                                                   864 
703   geomManager->OpenGeometry();                    865   geomManager->OpenGeometry();
704   geomManager->CloseGeometry(geometryToBeOptim    866   geomManager->CloseGeometry(geometryToBeOptimized, verboseLevel > 1);
705                                                   867 
706   geometryNeedsToBeClosed = false;                868   geometryNeedsToBeClosed = false;
707 }                                                 869 }
708                                                   870 
709 // -------------------------------------------    871 // --------------------------------------------------------------------
710 void G4RunManagerKernel::UpdateRegion()           872 void G4RunManagerKernel::UpdateRegion()
711 {                                                 873 {
712   G4StateManager* stateManager = G4StateManage << 874   G4StateManager* stateManager    = G4StateManager::GetStateManager();
713   G4ApplicationState currentState = stateManag    875   G4ApplicationState currentState = stateManager->GetCurrentState();
714   if (currentState != G4State_Init) {          << 876   if(currentState != G4State_Init)
                                                   >> 877   {
715     G4Exception("G4RunManagerKernel::UpdateReg    878     G4Exception("G4RunManagerKernel::UpdateRegion", "Run0024", JustWarning,
716                 "Geant4 kernel not in Init sta    879                 "Geant4 kernel not in Init state : method ignored.");
717     return;                                       880     return;
718   }                                               881   }
719                                                   882 
720   if (runManagerKernelType == workerRMK) retur << 883   if(runManagerKernelType == workerRMK)
                                                   >> 884     return;
721                                                   885 
722   CheckRegions();                                 886   CheckRegions();
723                                                   887 
724   G4RegionStore::GetInstance()->UpdateMaterial    888   G4RegionStore::GetInstance()->UpdateMaterialList(currentWorld);
725                                                   889 
726   G4ProductionCutsTable::GetProductionCutsTabl << 890   G4ProductionCutsTable::GetProductionCutsTable()->UpdateCoupleTable(
                                                   >> 891     currentWorld);
727 }                                                 892 }
728                                                   893 
729 // -------------------------------------------    894 // --------------------------------------------------------------------
730 void G4RunManagerKernel::BuildPhysicsTables(G4    895 void G4RunManagerKernel::BuildPhysicsTables(G4bool fakeRun)
731 {                                                 896 {
732   if (G4ProductionCutsTable::GetProductionCuts << 897   if(G4ProductionCutsTable::GetProductionCutsTable()->IsModified() ||
733 #ifdef G4MULTITHREADED                         << 898      physicsNeedsToBeReBuilt)
734     if (runManagerKernelType == masterRMK) {   << 899   {
                                                   >> 900   #ifdef G4MULTITHREADED
                                                   >> 901     if(runManagerKernelType == masterRMK)
                                                   >> 902     {
735       // make sure workers also rebuild physic    903       // make sure workers also rebuild physics tables
736       G4UImanager* pUImanager = G4UImanager::G    904       G4UImanager* pUImanager = G4UImanager::GetUIpointer();
737       pUImanager->ApplyCommand("/run/physicsMo    905       pUImanager->ApplyCommand("/run/physicsModified");
738     }                                             906     }
739 #endif                                         << 907   #endif
740     physicsList->BuildPhysicsTable();             908     physicsList->BuildPhysicsTable();
                                                   >> 909     ////G4ProductionCutsTable::GetProductionCutsTable()->PhysicsTableUpdated();
741     physicsNeedsToBeReBuilt = false;              910     physicsNeedsToBeReBuilt = false;
742   }                                               911   }
743                                                   912 
744   if (!fakeRun && verboseLevel > 1) DumpRegion << 913   if(!fakeRun && verboseLevel > 1)
745   if (!fakeRun && verboseLevel > 0) physicsLis << 914     DumpRegion();
746   if (!fakeRun) physicsList->DumpCutValuesTabl << 915   if(!fakeRun && verboseLevel > 0)
                                                   >> 916     physicsList->DumpCutValuesTable();
                                                   >> 917   if(!fakeRun)
                                                   >> 918     physicsList->DumpCutValuesTableIfRequested();
747 }                                                 919 }
748                                                   920 
749 // -------------------------------------------    921 // --------------------------------------------------------------------
750 void G4RunManagerKernel::CheckRegions()           922 void G4RunManagerKernel::CheckRegions()
751 {                                                 923 {
752   G4TransportationManager* transM = G4Transpor << 924   G4TransportationManager* transM =
                                                   >> 925     G4TransportationManager::GetTransportationManager();
753   std::size_t nWorlds = transM->GetNoWorlds();    926   std::size_t nWorlds = transM->GetNoWorlds();
754   std::vector<G4VPhysicalVolume*>::iterator wI    927   std::vector<G4VPhysicalVolume*>::iterator wItr;
755   for (auto region : *G4RegionStore::GetInstan << 928   for(std::size_t i = 0; i < G4RegionStore::GetInstance()->size(); ++i)
                                                   >> 929   {
                                                   >> 930     G4Region* region = (*(G4RegionStore::GetInstance()))[i];
                                                   >> 931 
756     // Let each region have a pointer to the w    932     // Let each region have a pointer to the world volume where it belongs to.
757     // G4Region::SetWorld() checks if the regi    933     // G4Region::SetWorld() checks if the region belongs to the given world and
758     // set it only if it does. Thus, here we g    934     // set it only if it does. Thus, here we go through all the registered world
759     // volumes.                                   935     // volumes.
760     region->SetWorld(nullptr);  // reset          936     region->SetWorld(nullptr);  // reset
761     region->UsedInMassGeometry(false);            937     region->UsedInMassGeometry(false);
762     region->UsedInParallelGeometry(false);        938     region->UsedInParallelGeometry(false);
763     wItr = transM->GetWorldsIterator();           939     wItr = transM->GetWorldsIterator();
764     for (std::size_t iw = 0; iw < nWorlds; ++i << 940     for(std::size_t iw = 0; iw < nWorlds; ++iw)
765       if (region->BelongsTo(*wItr)) {          << 941     {
766         if (*wItr == currentWorld) {           << 942       if(region->BelongsTo(*wItr))
                                                   >> 943       {
                                                   >> 944         if(*wItr == currentWorld)
                                                   >> 945         {
767           region->UsedInMassGeometry(true);       946           region->UsedInMassGeometry(true);
768         }                                         947         }
769         else {                                 << 948         else
                                                   >> 949         {
770           region->UsedInParallelGeometry(true)    950           region->UsedInParallelGeometry(true);
771         }                                         951         }
772       }                                           952       }
773       region->SetWorld(*wItr);                    953       region->SetWorld(*wItr);
774       ++wItr;                                     954       ++wItr;
775     }                                             955     }
776                                                   956 
777     G4ProductionCuts* cuts = region->GetProduc    957     G4ProductionCuts* cuts = region->GetProductionCuts();
778     if (cuts == nullptr) {                     << 958     if(cuts == nullptr)
779       if (region->IsInMassGeometry() && verbos << 959     {
                                                   >> 960       if(region->IsInMassGeometry() && verboseLevel > 0)
                                                   >> 961       {
780         G4cout << "Warning : Region <" << regi    962         G4cout << "Warning : Region <" << region->GetName()
781                << "> does not have specific pr    963                << "> does not have specific production cuts," << G4endl
782                << "even though it appears in t << 964                << "even though it appears in the current tracking world."
                                                   >> 965                << G4endl;
783         G4cout << "Default cuts are used for t    966         G4cout << "Default cuts are used for this region." << G4endl;
784       }                                           967       }
785                                                   968 
786       if (region->IsInMassGeometry() || region << 969       if(region->IsInMassGeometry() || region->IsInParallelGeometry())
                                                   >> 970       {
787         region->SetProductionCuts(                971         region->SetProductionCuts(
788           G4ProductionCutsTable::GetProduction << 972           G4ProductionCutsTable::GetProductionCutsTable()
                                                   >> 973             ->GetDefaultProductionCuts());
789       }                                           974       }
790     }                                             975     }
791   }                                               976   }
792                                                   977 
793   //                                              978   //
794   // If a parallel world has no region, set de    979   // If a parallel world has no region, set default region for parallel world
795   //                                              980   //
796                                                   981 
797   wItr = transM->GetWorldsIterator();             982   wItr = transM->GetWorldsIterator();
798   for (std::size_t iw = 0; iw < nWorlds; ++iw) << 983   for(std::size_t iw = 0; iw < nWorlds; ++iw)
799     if (*wItr != currentWorld) {               << 984   {
                                                   >> 985     if(*wItr != currentWorld)
                                                   >> 986     {
800       G4LogicalVolume* pwLogical = (*wItr)->Ge    987       G4LogicalVolume* pwLogical = (*wItr)->GetLogicalVolume();
801       if (pwLogical->GetRegion() == nullptr) { << 988       if(pwLogical->GetRegion() == nullptr)
                                                   >> 989       {
802         pwLogical->SetRegion(defaultRegionForP    990         pwLogical->SetRegion(defaultRegionForParallelWorld);
803         defaultRegionForParallelWorld->AddRoot    991         defaultRegionForParallelWorld->AddRootLogicalVolume(pwLogical);
804       }                                           992       }
805     }                                             993     }
806     ++wItr;                                       994     ++wItr;
807   }                                               995   }
808 }                                                 996 }
809                                                   997 
810 // -------------------------------------------    998 // --------------------------------------------------------------------
811 void G4RunManagerKernel::DumpRegion(const G4St    999 void G4RunManagerKernel::DumpRegion(const G4String& rname) const
812 {                                                 1000 {
813   G4Region* region = G4RegionStore::GetInstanc    1001   G4Region* region = G4RegionStore::GetInstance()->GetRegion(rname);
814   if (region != nullptr) DumpRegion(region);   << 1002   if(region != nullptr)
                                                   >> 1003     DumpRegion(region);
815 }                                                 1004 }
816                                                   1005 
817 // -------------------------------------------    1006 // --------------------------------------------------------------------
818 void G4RunManagerKernel::DumpRegion(G4Region*     1007 void G4RunManagerKernel::DumpRegion(G4Region* region) const
819 {                                                 1008 {
820   if (region == nullptr) {                     << 1009   if(region == nullptr)
821     for (const auto& i : *G4RegionStore::GetIn << 1010   {
822       DumpRegion(i);                           << 1011     for(std::size_t i = 0; i < G4RegionStore::GetInstance()->size(); ++i)
                                                   >> 1012     {
                                                   >> 1013       DumpRegion((*(G4RegionStore::GetInstance()))[i]);
823     }                                             1014     }
824   }                                               1015   }
825   else {                                       << 1016   else
826     if (G4Threading::IsWorkerThread()) return; << 1017   {
                                                   >> 1018     if(G4Threading::IsWorkerThread())
                                                   >> 1019       return;
827     G4cout << G4endl;                             1020     G4cout << G4endl;
828     G4cout << "Region <" << region->GetName()     1021     G4cout << "Region <" << region->GetName() << "> -- ";
829     if (region->GetWorldPhysical() != nullptr) << 1022     if(region->GetWorldPhysical())
830       G4cout << " -- appears in <" << region-> << 1023     {
                                                   >> 1024       G4cout << " -- appears in <" << region->GetWorldPhysical()->GetName()
                                                   >> 1025              << "> world volume";
831     }                                             1026     }
832     else {                                     << 1027     else
                                                   >> 1028     {
833       G4cout << " -- is not associated to any     1029       G4cout << " -- is not associated to any world.";
834     }                                             1030     }
835     G4cout << G4endl;                             1031     G4cout << G4endl;
836     if (region->IsInMassGeometry()) {          << 1032     if(region->IsInMassGeometry())
                                                   >> 1033     {
837       G4cout << " This region is in the mass w    1034       G4cout << " This region is in the mass world." << G4endl;
838     }                                             1035     }
839     if (region->IsInParallelGeometry()) {      << 1036     if(region->IsInParallelGeometry())
                                                   >> 1037     {
840       G4cout << " This region is in the parall    1038       G4cout << " This region is in the parallel world." << G4endl;
841     }                                             1039     }
842                                                   1040 
843     G4cout << " Root logical volume(s) : ";       1041     G4cout << " Root logical volume(s) : ";
844     std::size_t nRootLV = region->GetNumberOfR    1042     std::size_t nRootLV = region->GetNumberOfRootVolumes();
845     auto lvItr = region->GetRootLogicalVolumeI    1043     auto lvItr = region->GetRootLogicalVolumeIterator();
846     for (std::size_t j = 0; j < nRootLV; ++j)  << 1044     for(std::size_t j = 0; j < nRootLV; ++j)
                                                   >> 1045     {
847       G4cout << (*lvItr)->GetName() << " ";       1046       G4cout << (*lvItr)->GetName() << " ";
848       ++lvItr;                                    1047       ++lvItr;
849     }                                             1048     }
850     G4cout << G4endl;                             1049     G4cout << G4endl;
851                                                   1050 
852     G4cout << " Pointers : G4VUserRegionInform << 1051     G4cout << " Pointers : G4VUserRegionInformation["
853            << "], G4UserLimits[" << region->Ge << 1052            << region->GetUserInformation() << "], G4UserLimits["
                                                   >> 1053            << region->GetUserLimits() << "], G4FastSimulationManager["
854            << region->GetFastSimulationManager    1054            << region->GetFastSimulationManager() << "], G4UserSteppingAction["
855            << region->GetRegionalSteppingActio    1055            << region->GetRegionalSteppingAction() << "]" << G4endl;
856                                                   1056 
857     G4cout << " Materials : ";                    1057     G4cout << " Materials : ";
858     auto mItr = region->GetMaterialIterator();    1058     auto mItr = region->GetMaterialIterator();
859     std::size_t nMaterial = region->GetNumberO    1059     std::size_t nMaterial = region->GetNumberOfMaterials();
860     for (std::size_t iMate = 0; iMate < nMater << 1060     for(std::size_t iMate = 0; iMate < nMaterial; ++iMate)
                                                   >> 1061     {
861       G4cout << (*mItr)->GetName() << " ";        1062       G4cout << (*mItr)->GetName() << " ";
862       ++mItr;                                     1063       ++mItr;
863     }                                             1064     }
864     G4cout << G4endl;                             1065     G4cout << G4endl;
865     G4ProductionCuts* cuts = region->GetProduc    1066     G4ProductionCuts* cuts = region->GetProductionCuts();
866     if ((cuts == nullptr) && region->IsInMassG << 1067     if(!cuts && region->IsInMassGeometry())
                                                   >> 1068     {
867       G4cerr << "Warning : Region <" << region    1069       G4cerr << "Warning : Region <" << region->GetName()
868              << "> does not have specific prod    1070              << "> does not have specific production cuts." << G4endl;
869       G4cerr << "Default cuts are used for thi    1071       G4cerr << "Default cuts are used for this region." << G4endl;
870       region->SetProductionCuts(               << 1072       region->SetProductionCuts(G4ProductionCutsTable::GetProductionCutsTable()
871         G4ProductionCutsTable::GetProductionCu << 1073                                   ->GetDefaultProductionCuts());
872     }                                             1074     }
873     else if (cuts != nullptr) {                << 1075     else if(cuts != nullptr)
                                                   >> 1076     {
874       G4cout << " Production cuts : "             1077       G4cout << " Production cuts : "
875              << "  gamma " << G4BestUnit(cuts- << 1078              << "  gamma "
876              << G4BestUnit(cuts->GetProduction << 1079              << G4BestUnit(cuts->GetProductionCut("gamma"), "Length")
877              << G4BestUnit(cuts->GetProduction << 1080              << "     e- " << G4BestUnit(cuts->GetProductionCut("e-"), "Length")
878              << G4BestUnit(cuts->GetProduction << 1081              << "     e+ " << G4BestUnit(cuts->GetProductionCut("e+"), "Length")
                                                   >> 1082              << " proton "
                                                   >> 1083              << G4BestUnit(cuts->GetProductionCut("proton"), "Length")
                                                   >> 1084              << G4endl;
879     }                                             1085     }
880   }                                               1086   }
881 }                                                 1087 }
882                                                   1088 
883 // -------------------------------------------    1089 // --------------------------------------------------------------------
884 void G4RunManagerKernel::CheckRegularGeometry(    1090 void G4RunManagerKernel::CheckRegularGeometry()
885 {                                                 1091 {
886   G4LogicalVolumeStore* store = G4LogicalVolum    1092   G4LogicalVolumeStore* store = G4LogicalVolumeStore::GetInstance();
887   for (const auto& pos : *store) {             << 1093   for(auto pos = store->cbegin(); pos != store->cend(); ++pos)
888     if ((pos != nullptr) && (pos->GetNoDaughte << 1094   {
889       if (pos->GetDaughter(0)->IsRegularStruct << 1095     if((*pos) && ((*pos)->GetNoDaughters() == 1))
                                                   >> 1096     {
                                                   >> 1097       if((*pos)->GetDaughter(0)->IsRegularStructure())
                                                   >> 1098       {
890         SetScoreSplitter();                       1099         SetScoreSplitter();
891         return;                                   1100         return;
892       }                                           1101       }
893     }                                             1102     }
894   }                                               1103   }
895 }                                                 1104 }
896                                                   1105 
897 // -------------------------------------------    1106 // --------------------------------------------------------------------
898 G4bool G4RunManagerKernel::ConfirmCoupledTrans    1107 G4bool G4RunManagerKernel::ConfirmCoupledTransportation()
899 {                                                 1108 {
900   G4ParticleTable* theParticleTable = G4Partic    1109   G4ParticleTable* theParticleTable = G4ParticleTable::GetParticleTable();
901   auto theParticleIterator = theParticleTable-    1110   auto theParticleIterator = theParticleTable->GetIterator();
902   theParticleIterator->reset();                   1111   theParticleIterator->reset();
903   while ((*theParticleIterator)()) {           << 1112   while((*theParticleIterator)())
                                                   >> 1113   {
904     G4ParticleDefinition* pd = theParticleIter    1114     G4ParticleDefinition* pd = theParticleIterator->value();
905     G4ProcessManager* pm = pd->GetProcessManag << 1115     G4ProcessManager* pm     = pd->GetProcessManager();
906     if (pm != nullptr) {                       << 1116     if(pm)
                                                   >> 1117     {
907       G4ProcessVector* pv = pm->GetAlongStepPr    1118       G4ProcessVector* pv = pm->GetAlongStepProcessVector(typeDoIt);
908       G4VProcess* p = (*pv)[0];                << 1119       G4VProcess* p       = (*pv)[0];
909       return ((p->GetProcessName()) == "Couple    1120       return ((p->GetProcessName()) == "CoupledTransportation");
910     }                                             1121     }
911   }                                               1122   }
912   return false;                                   1123   return false;
913 }                                                 1124 }
914                                                   1125 
915 // -------------------------------------------    1126 // --------------------------------------------------------------------
916 void G4RunManagerKernel::SetScoreSplitter()       1127 void G4RunManagerKernel::SetScoreSplitter()
917 {                                                 1128 {
918   auto pSplitter = new G4ScoreSplittingProcess << 1129   G4ScoreSplittingProcess* pSplitter = new G4ScoreSplittingProcess();
919   G4ParticleTable* theParticleTable = G4Partic << 1130   G4ParticleTable* theParticleTable  = G4ParticleTable::GetParticleTable();
920   auto theParticleIterator = theParticleTable-    1131   auto theParticleIterator = theParticleTable->GetIterator();
921                                                   1132 
922   // Ensure that Process is added only once to    1133   // Ensure that Process is added only once to the particles' process managers
923   static G4ThreadLocal G4bool InitSplitter = f    1134   static G4ThreadLocal G4bool InitSplitter = false;
924   if (!InitSplitter) {                         << 1135   if(!InitSplitter)
                                                   >> 1136   {
925     InitSplitter = true;                          1137     InitSplitter = true;
926                                                   1138 
927     theParticleIterator->reset();                 1139     theParticleIterator->reset();
928     while ((*theParticleIterator)()) {         << 1140     while((*theParticleIterator)())
                                                   >> 1141     {
929       G4ParticleDefinition* particle = thePart    1142       G4ParticleDefinition* particle = theParticleIterator->value();
930       G4ProcessManager* pmanager = particle->G << 1143       G4ProcessManager* pmanager     = particle->GetProcessManager();
931       if (pmanager != nullptr) {               << 1144       if(pmanager)
                                                   >> 1145       {
932         pmanager->AddDiscreteProcess(pSplitter    1146         pmanager->AddDiscreteProcess(pSplitter);
933       }                                           1147       }
934     }                                             1148     }
935                                                   1149 
936     if (verboseLevel > 0) {                    << 1150     if(verboseLevel > 0)
937       G4cout << "G4RunManagerKernel -- G4Score << 1151     {
938                 "particles."                   << 1152       G4cout
939              << G4endl;                        << 1153         << "G4RunManagerKernel -- G4ScoreSplittingProcess is appended to all "
                                                   >> 1154            "particles."
                                                   >> 1155         << G4endl;
940     }                                             1156     }
941   }                                               1157   }
942 }                                                 1158 }
943                                                   1159 
944 // -------------------------------------------    1160 // --------------------------------------------------------------------
945 void G4RunManagerKernel::SetupShadowProcess()     1161 void G4RunManagerKernel::SetupShadowProcess() const
946 {                                                 1162 {
947   G4ParticleTable* theParticleTable = G4Partic    1163   G4ParticleTable* theParticleTable = G4ParticleTable::GetParticleTable();
948   auto theParticleIterator = theParticleTable-    1164   auto theParticleIterator = theParticleTable->GetIterator();
949   theParticleIterator->reset();                   1165   theParticleIterator->reset();
950   // loop on particles and get process manager    1166   // loop on particles and get process manager from there list of processes
951   while ((*theParticleIterator)()) {           << 1167   while((*theParticleIterator)())
                                                   >> 1168   {
952     G4ParticleDefinition* pd = theParticleIter    1169     G4ParticleDefinition* pd = theParticleIterator->value();
953     G4ProcessManager* pm = pd->GetProcessManag << 1170     G4ProcessManager* pm     = pd->GetProcessManager();
954     if (pm != nullptr) {                       << 1171     if(pm != nullptr)
                                                   >> 1172     {
955       G4ProcessVector& procs = *(pm->GetProces    1173       G4ProcessVector& procs = *(pm->GetProcessList());
956       for (G4int idx = 0; idx < (G4int)procs.s << 1174       for(std::size_t idx = 0; idx < procs.size(); ++idx)
                                                   >> 1175       {
957         const G4VProcess* masterP = procs[idx]    1176         const G4VProcess* masterP = procs[idx]->GetMasterProcess();
958         if (masterP == nullptr) {              << 1177         if(masterP == nullptr)
                                                   >> 1178         {
959           // Process does not have an associat    1179           // Process does not have an associated shadow master process
960           // We are in master mode or sequenti    1180           // We are in master mode or sequential
961           procs[idx]->SetMasterProcess(const_c    1181           procs[idx]->SetMasterProcess(const_cast<G4VProcess*>(procs[idx]));
962         }                                         1182         }
963       }                                           1183       }
964     }                                             1184     }
965   }                                               1185   }
966 }                                                 1186 }
967                                                   1187