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 10.3)


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