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