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 // 29 // ------------------------------------------- << 28 // 30 29 31 #include "G4RunManagerKernel.hh" 30 #include "G4RunManagerKernel.hh" 32 31 33 #include "G4AllocatorList.hh" << 32 #include <vector> >> 33 >> 34 #include "G4StateManager.hh" 34 #include "G4ApplicationState.hh" 35 #include "G4ApplicationState.hh" 35 #include "G4AutoLock.hh" << 36 #include "G4ExceptionHandler.hh" 36 #include "G4ExceptionHandler.hh" 37 #include "G4FieldManagerStore.hh" << 37 #include "G4PrimaryTransformer.hh" 38 #include "G4Geantino.hh" << 39 #include "G4GeometryManager.hh" 38 #include "G4GeometryManager.hh" 40 #include "G4IonConstructor.hh" << 39 #include "G4FieldManagerStore.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" << 47 #include "G4ParticleDefinition.hh" << 48 #include "G4ParticleTable.hh" << 49 #include "G4ParticleTableIterator.hh" << 50 #include "G4PathFinder.hh" 41 #include "G4PathFinder.hh" 51 #include "G4PrimaryTransformer.hh" << 42 #include "G4TransportationManager.hh" 52 #include "G4ProcessManager.hh" << 43 #include "G4VPhysicalVolume.hh" 53 #include "G4ProcessVector.hh" << 44 #include "G4LogicalVolume.hh" 54 #include "G4ProductionCuts.hh" << 45 #include "G4VUserPhysicsList.hh" 55 #include "G4ProductionCutsTable.hh" << 46 56 #include "G4RNGHelper.hh" << 47 #include "G4ParticleTable.hh" 57 #include "G4Region.hh" 48 #include "G4Region.hh" 58 #include "G4RegionStore.hh" 49 #include "G4RegionStore.hh" >> 50 #include "G4ProductionCuts.hh" >> 51 #include "G4ProductionCutsTable.hh" 59 #include "G4SDManager.hh" 52 #include "G4SDManager.hh" 60 #include "G4ScoreSplittingProcess.hh" << 53 #include "G4ParallelWorldProcessStore.hh" 61 #include "G4StateManager.hh" << 62 #include "G4TransportationManager.hh" << 63 #include "G4UImanager.hh" 54 #include "G4UImanager.hh" 64 #include "G4UnitsTable.hh" << 65 #include "G4VPhysicalVolume.hh" << 66 #include "G4VProcess.hh" << 67 #include "G4VUserPhysicsList.hh" << 68 #include "G4VVisManager.hh" 55 #include "G4VVisManager.hh" >> 56 #include "G4UnitsTable.hh" 69 #include "G4Version.hh" 57 #include "G4Version.hh" 70 #include "G4ios.hh" 58 #include "G4ios.hh" >> 59 #include "G4TiMemory.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 435 if (currentState != G4State_Init) { << 445 if(currentState!=G4State_Init) 436 if (currentState != G4State_Idle && curren << 446 { 437 G4cout << "Current application state is << 447 if(!(currentState==G4State_Idle||currentState==G4State_PreInit)) 438 << G4endl; << 448 { 439 G4Exception("G4RunManagerKernel::DefineW << 449 G4cout << "Current application state is " 440 FatalException, "Geant4 kern << 450 << stateManager->GetStateString(currentState) << G4endl; >> 451 G4Exception("G4RunManagerKernel::DefineWorldVolume", >> 452 "DefineWorldVolumeAtIncorrectState", >> 453 FatalException, >> 454 "Geant4 kernel is not Init state : Method ignored."); 441 return; 455 return; >> 456 } else { >> 457 //G4Exception("G4RunManagerKernel::DefineWorldVolume", >> 458 // "DefineWorldVolumeAtIncorrectState", >> 459 // JustWarning, >> 460 // "Geant4 kernel is not Init state : Assuming Init state."); >> 461 //G4cout<<"Warning : Geant4 kernel is not Init state : Assuming Init state." >> 462 // <<G4endl; >> 463 stateManager->SetNewState(G4State_Init); 442 } 464 } 443 << 444 stateManager->SetNewState(G4State_Init); << 445 } 465 } 446 466 447 // The world volume MUST NOT have a region d 467 // The world volume MUST NOT have a region defined by the user 448 if (worldVol->GetLogicalVolume()->GetRegion( << 468 if(worldVol->GetLogicalVolume()->GetRegion()) 449 if (worldVol->GetLogicalVolume()->GetRegio << 469 { >> 470 if(worldVol->GetLogicalVolume()->GetRegion()!=defaultRegion) >> 471 { 450 G4ExceptionDescription ED; 472 G4ExceptionDescription ED; 451 ED << "The world volume has a user-defin 473 ED << "The world volume has a user-defined region <" 452 << worldVol->GetLogicalVolume()->GetR << 474 << worldVol->GetLogicalVolume()->GetRegion()->GetName() 453 ED << "World would have a default region << 475 << ">." << G4endl; 454 G4Exception("G4RunManager::DefineWorldVo << 476 ED << "World would have a default region assigned by RunManagerKernel." >> 477 << G4endl; >> 478 G4Exception("G4RunManager::DefineWorldVolume", >> 479 "Run0004", FatalException, ED); 455 } 480 } 456 } 481 } 457 482 458 SetupDefaultRegion(); 483 SetupDefaultRegion(); 459 << 484 460 // Accept the world volume 485 // Accept the world volume 461 currentWorld = worldVol; << 486 currentWorld = worldVol; 462 487 463 // Set the default region to the world 488 // Set the default region to the world 464 489 465 G4LogicalVolume* worldLog = currentWorld->Ge 490 G4LogicalVolume* worldLog = currentWorld->GetLogicalVolume(); 466 worldLog->SetRegion(defaultRegion); 491 worldLog->SetRegion(defaultRegion); 467 defaultRegion->AddRootLogicalVolume(worldLog 492 defaultRegion->AddRootLogicalVolume(worldLog); 468 if (verboseLevel > 1) << 493 if(verboseLevel>1) G4cout << worldLog->GetName() 469 G4cout << worldLog->GetName() << " is regi << 494 << " is registered to the default region." << G4endl; 470 495 471 // Set the world volume, notify the Navigato 496 // Set the world volume, notify the Navigator and reset its state 472 G4TransportationManager::GetTransportationMa << 497 G4TransportationManager::GetTransportationManager() 473 if (topologyIsChanged) geometryNeedsToBeClos << 498 ->SetWorldForTracking(currentWorld); 474 << 499 if(topologyIsChanged) geometryNeedsToBeClosed = true; >> 500 475 // Notify the VisManager as well 501 // Notify the VisManager as well 476 if (G4Threading::IsMasterThread()) { << 502 if(G4Threading::IsMasterThread()) >> 503 { 477 G4VVisManager* pVVisManager = G4VVisManage 504 G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance(); 478 if (pVVisManager != nullptr) pVVisManager- << 505 if(pVVisManager) pVVisManager->GeometryHasChanged(); 479 } 506 } 480 507 481 geometryInitialized = true; 508 geometryInitialized = true; 482 stateManager->SetNewState(currentState); << 509 stateManager->SetNewState(currentState); 483 if (physicsInitialized && currentState != G4 << 510 if(physicsInitialized && currentState!=G4State_Idle) 484 stateManager->SetNewState(G4State_Idle); << 511 { stateManager->SetNewState(G4State_Idle); } 485 } << 512 } 486 } << 513 487 << 488 // ------------------------------------------- << 489 void G4RunManagerKernel::SetPhysics(G4VUserPhy 514 void G4RunManagerKernel::SetPhysics(G4VUserPhysicsList* uPhys) 490 { 515 { 491 physicsList = uPhys; 516 physicsList = uPhys; 492 517 493 if (runManagerKernelType == workerRMK) retur << 518 if(runManagerKernelType==workerRMK) return; 494 519 495 SetupPhysics(); 520 SetupPhysics(); 496 if (verboseLevel > 2) G4ParticleTable::GetPa << 521 if(verboseLevel>2) G4ParticleTable::GetParticleTable()->DumpTable(); 497 if (verboseLevel > 1) { << 522 if(verboseLevel>1) 498 G4cout << "List of instantiated particles << 523 { 499 "=============================== << 524 G4cout << "List of instantiated particles ============================================" << G4endl; 500 << G4endl; << 501 G4int nPtcl = G4ParticleTable::GetParticle 525 G4int nPtcl = G4ParticleTable::GetParticleTable()->entries(); 502 for (G4int i = 0; i < nPtcl; ++i) { << 526 for(G4int i=0;i<nPtcl;i++) >> 527 { 503 G4ParticleDefinition* pd = G4ParticleTab 528 G4ParticleDefinition* pd = G4ParticleTable::GetParticleTable()->GetParticle(i); 504 G4cout << pd->GetParticleName() << " "; 529 G4cout << pd->GetParticleName() << " "; 505 if (i % 10 == 9) G4cout << G4endl; << 530 if(i%10==9) G4cout << G4endl; 506 } 531 } 507 G4cout << G4endl; 532 G4cout << G4endl; 508 } 533 } 509 } 534 } 510 535 511 // ------------------------------------------- << 536 #include "G4IonTable.hh" >> 537 #include "G4ParticleTableIterator.hh" >> 538 #include "G4IonConstructor.hh" >> 539 #include "G4Geantino.hh" >> 540 512 void G4RunManagerKernel::SetupPhysics() 541 void G4RunManagerKernel::SetupPhysics() 513 { 542 { 514 G4ParticleTable::GetParticleTable()->SetRead << 543 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 544 526 auto pItr = G4ParticleTable::GetParticleTabl << 545 physicsList->ConstructParticle(); 527 pItr->reset(); << 528 while ((*pItr)()) { << 529 G4ParticleDefinition* particle = pItr->val << 530 if (!(particle->IsGeneralIon())) particle- << 531 } << 532 546 533 if (gion != nullptr) { << 547 // For sanity reason 534 G4int gionId = gion->GetParticleDefinition << 548 G4Geantino::GeantinoDefinition(); 535 pItr->reset(false); << 549 G4ParticleDefinition* gion = G4ParticleTable::GetParticleTable()->GetGenericIon(); 536 while ((*pItr)()) { << 550 if(gion) >> 551 { G4IonConstructor::ConstructParticle(); } >> 552 G4ParticleTable::GetParticleTable()->GetIonTable()->InitializeLightIons(); >> 553 >> 554 G4ParticleTable::G4PTblDicIterator* pItr = G4ParticleTable::GetParticleTable()->GetIterator(); >> 555 pItr->reset(); >> 556 while( (*pItr)() ) >> 557 { 537 G4ParticleDefinition* particle = pItr->v 558 G4ParticleDefinition* particle = pItr->value(); 538 if (particle->IsGeneralIon()) particle-> << 559 if(!(particle->IsGeneralIon())) particle->SetParticleDefinitionID(); >> 560 } >> 561 >> 562 if(gion) >> 563 { >> 564 G4int gionId = gion->GetParticleDefinitionID(); >> 565 pItr->reset(false); >> 566 while( (*pItr)() ) >> 567 { >> 568 G4ParticleDefinition* particle = pItr->value(); >> 569 if(particle->IsGeneralIon()) particle->SetParticleDefinitionID(gionId); >> 570 } 539 } 571 } 540 } << 541 #ifdef G4MULTITHREADED 572 #ifdef G4MULTITHREADED 542 G4UnitDefinition::GetUnitsTable().Synchroniz << 573 G4UnitDefinition::GetUnitsTable().Synchronize(); 543 #endif 574 #endif 544 } 575 } 545 576 546 // ------------------------------------------- << 577 namespace { 547 namespace << 578 G4Mutex initphysicsmutex = G4MUTEX_INITIALIZER; 548 { << 549 G4Mutex initphysicsmutex = G4MUTEX_INITIALIZER << 550 } 579 } 551 580 552 // ------------------------------------------- << 553 void G4RunManagerKernel::InitializePhysics() 581 void G4RunManagerKernel::InitializePhysics() 554 { 582 { 555 G4StateManager* stateManager = G4StateManage << 583 G4StateManager* stateManager = G4StateManager::GetStateManager(); 556 G4ApplicationState currentState = stateManag 584 G4ApplicationState currentState = stateManager->GetCurrentState(); 557 if (currentState != G4State_Init) { << 585 if(currentState!=G4State_Init) 558 G4cout << "Current application state is " << 586 { 559 << G4endl; << 587 G4cout << "Current application state is " 560 if (currentState != G4State_Idle && curren << 588 << stateManager->GetStateString(currentState) << G4endl; 561 G4Exception("G4RunManagerKernel::Initial << 589 if(!(currentState==G4State_Idle||currentState==G4State_PreInit)) 562 FatalException, "Geant4 kern << 590 { >> 591 G4Exception("G4RunManagerKernel::InitializePhysics", >> 592 "InitializePhysicsIncorrectState", >> 593 FatalException, >> 594 "Geant4 kernel is not Init state : Method ignored."); 563 return; 595 return; >> 596 } else { >> 597 //G4Exception("G4RunManagerKernel::DefineWorldVolume", >> 598 //"DefineWorldVolumeAtIncorrectState", >> 599 //JustWarning, >> 600 //"Geant4 kernel is not Init state : Assuming Init state."); >> 601 G4cout<<"Warning : Geant4 kernel is not Init state : Assuming Init state." >> 602 <<G4endl; >> 603 stateManager->SetNewState(G4State_Init); 564 } 604 } 565 << 566 G4cout << "Warning : Geant4 kernel is not << 567 stateManager->SetNewState(G4State_Init); << 568 } 605 } 569 606 570 if (physicsList == nullptr) { << 607 if(!physicsList) 571 G4Exception("G4RunManagerKernel::Initializ << 608 { >> 609 G4Exception("G4RunManagerKernel::InitializePhysics", >> 610 "Run0012", FatalException, 572 "G4VUserPhysicsList is not def 611 "G4VUserPhysicsList is not defined"); 573 return; 612 return; 574 } 613 } 575 614 576 if (verboseLevel > 1) G4cout << "physicsList << 615 if(verboseLevel>1) G4cout << "physicsList->Construct() start." << G4endl; 577 if (numberOfParallelWorld > 0) physicsList-> << 616 if(numberOfParallelWorld>0) physicsList->UseCoupledTransportation(); 578 physicsList->Construct(); 617 physicsList->Construct(); 579 << 618 580 if (verboseLevel > 1) G4cout << "physicsList << 619 if(verboseLevel>1) G4cout << "physicsList->CheckParticleList() start." << G4endl; 581 physicsList->CheckParticleList(); 620 physicsList->CheckParticleList(); 582 << 621 //Cannot assume that SetCuts and CheckRegions are thread safe. We need to mutex 583 // Cannot assume that SetCuts() and CheckReg << 622 //Report from valgrind --tool=drd 584 // We need to mutex (report from valgrind -- << 585 G4AutoLock l(&initphysicsmutex); 623 G4AutoLock l(&initphysicsmutex); 586 if (G4Threading::IsMasterThread()) { << 624 if ( G4Threading::IsMasterThread() ) { 587 if (verboseLevel > 1) G4cout << "physicsLi << 625 if(verboseLevel>1) G4cout << "physicsList->setCut() start." << G4endl; 588 physicsList->SetCuts(); << 626 physicsList->SetCuts(); >> 627 589 } 628 } 590 CheckRegions(); 629 CheckRegions(); 591 l.unlock(); 630 l.unlock(); 592 631 593 physicsInitialized = true; << 632 /******************* >> 633 // static G4bool createIsomerOnlyOnce = false; >> 634 // if(G4Threading::IsMultithreadedApplication() && G4Threading::IsMasterThread()) >> 635 // { >> 636 // if(!createIsomerOnlyOnce) >> 637 // { >> 638 // createIsomerOnlyOnce = true; >> 639 // G4ParticleDefinition* gion = G4ParticleTable::GetParticleTable()->GetGenericIon(); >> 640 // if(gion) >> 641 // { >> 642 // G4ParticleTable::GetParticleTable()->GetIonTable()->CreateAllIsomer(); >> 643 // PropagateGenericIonID(); >> 644 // } >> 645 // } >> 646 // } >> 647 *********************/ 594 648 >> 649 physicsInitialized = true; 595 #ifdef G4MULTITHREADED 650 #ifdef G4MULTITHREADED 596 G4UnitDefinition::GetUnitsTable().Synchroniz 651 G4UnitDefinition::GetUnitsTable().Synchronize(); 597 #endif 652 #endif 598 << 653 stateManager->SetNewState(currentState); 599 stateManager->SetNewState(currentState); << 654 if(geometryInitialized && currentState!=G4State_Idle) 600 if (geometryInitialized && currentState != G << 655 { stateManager->SetNewState(G4State_Idle); } 601 stateManager->SetNewState(G4State_Idle); << 602 } << 603 } 656 } 604 657 605 // ------------------------------------------- << 606 G4bool G4RunManagerKernel::RunInitialization(G 658 G4bool G4RunManagerKernel::RunInitialization(G4bool fakeRun) 607 { 659 { 608 G4StateManager* stateManager = G4StateManage << 660 TIMEMORY_AUTO_TIMER(""); >> 661 G4StateManager* stateManager = G4StateManager::GetStateManager(); 609 G4ApplicationState currentState = stateManag 662 G4ApplicationState currentState = stateManager->GetCurrentState(); 610 663 611 if (!geometryInitialized) { << 664 if(!geometryInitialized) 612 G4Exception("G4RunManagerKernel::RunInitia << 665 { >> 666 G4Exception("G4RunManagerKernel::RunInitialization", >> 667 "Run0021", >> 668 JustWarning, 613 "Geometry has not yet initiali 669 "Geometry has not yet initialized : method ignored."); 614 return false; 670 return false; 615 } 671 } 616 << 672 617 if (!physicsInitialized) { << 673 if(!physicsInitialized) 618 G4Exception("G4RunManagerKernel::RunInitia << 674 { >> 675 G4Exception("G4RunManagerKernel::RunInitialization", >> 676 "Run0022", >> 677 JustWarning, 619 "Physics has not yet initializ 678 "Physics has not yet initialized : method ignored."); 620 return false; 679 return false; 621 } 680 } 622 681 623 if (currentState != G4State_Idle) { << 682 if( currentState != G4State_Idle ) 624 G4Exception("G4RunManagerKernel::RunInitia << 683 { >> 684 G4Exception("G4RunManagerKernel::RunInitialization", >> 685 "Run0023", >> 686 JustWarning, 625 "Geant4 kernel not in Idle sta 687 "Geant4 kernel not in Idle state : method ignored."); 626 return false; 688 return false; 627 } 689 } 628 690 629 if (geometryNeedsToBeClosed) CheckRegularGeo << 691 if(geometryNeedsToBeClosed) CheckRegularGeometry(); 630 692 631 stateManager->SetNewState(G4State_Init); 693 stateManager->SetNewState(G4State_Init); 632 PropagateGenericIonID(); 694 PropagateGenericIonID(); 633 SetupShadowProcess(); 695 SetupShadowProcess(); 634 UpdateRegion(); 696 UpdateRegion(); 635 BuildPhysicsTables(fakeRun); 697 BuildPhysicsTables(fakeRun); 636 698 637 if (geometryNeedsToBeClosed) { << 699 if(geometryNeedsToBeClosed) 638 if(!fakeRun || resetNavigatorAtInitializat << 700 { >> 701 ResetNavigator(); 639 // CheckRegularGeometry(); 702 // CheckRegularGeometry(); 640 // Notify the VisManager as well 703 // Notify the VisManager as well 641 if (G4Threading::IsMasterThread()) { << 704 if(G4Threading::IsMasterThread()) >> 705 { 642 G4VVisManager* pVVisManager = G4VVisMana 706 G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance(); 643 if (pVVisManager != nullptr) pVVisManage << 707 if(pVVisManager) pVVisManager->GeometryHasChanged(); 644 } 708 } 645 } 709 } 646 << 710 647 GetPrimaryTransformer()->CheckUnknown(); 711 GetPrimaryTransformer()->CheckUnknown(); 648 712 649 #ifdef G4MULTITHREADED 713 #ifdef G4MULTITHREADED 650 G4UnitDefinition::GetUnitsTable().Synchroniz 714 G4UnitDefinition::GetUnitsTable().Synchronize(); 651 #endif 715 #endif 652 << 653 stateManager->SetNewState(G4State_Idle); 716 stateManager->SetNewState(G4State_Idle); 654 stateManager->SetNewState(G4State_GeomClosed 717 stateManager->SetNewState(G4State_GeomClosed); 655 return true; 718 return true; 656 } 719 } 657 720 658 // ------------------------------------------- << 659 void G4RunManagerKernel::PropagateGenericIonID 721 void G4RunManagerKernel::PropagateGenericIonID() 660 { 722 { 661 G4ParticleDefinition* gion = G4ParticleTable 723 G4ParticleDefinition* gion = G4ParticleTable::GetParticleTable()->GetGenericIon(); 662 if (gion != nullptr) { << 724 if(gion) >> 725 { >> 726 //G4ParticleTable::GetParticleTable()->GetIonTable()->CreateAllIsomer(); 663 G4int gionId = gion->GetParticleDefinition 727 G4int gionId = gion->GetParticleDefinitionID(); 664 auto pItr = G4ParticleTable::GetParticleTa << 728 G4ParticleTable::G4PTblDicIterator* pItr = G4ParticleTable::GetParticleTable()->GetIterator(); 665 pItr->reset(false); 729 pItr->reset(false); 666 while ((*pItr)()) { << 730 while( (*pItr)() ) >> 731 { 667 G4ParticleDefinition* particle = pItr->v 732 G4ParticleDefinition* particle = pItr->value(); 668 if (particle->IsGeneralIon()) particle-> << 733 if(particle->IsGeneralIon()) particle->SetParticleDefinitionID(gionId); 669 } 734 } 670 } 735 } 671 } 736 } 672 737 673 // ------------------------------------------- << 674 void G4RunManagerKernel::RunTermination() 738 void G4RunManagerKernel::RunTermination() 675 { 739 { 676 if (runManagerKernelType != workerRMK) << 740 if ( runManagerKernelType != workerRMK ) 677 { G4ProductionCutsTable::GetProductionCutsTa << 741 G4ProductionCutsTable::GetProductionCutsTable()->PhysicsTableUpdated(); 678 G4StateManager::GetStateManager()->SetNewSta << 742 G4StateManager::GetStateManager()->SetNewState(G4State_Idle); 679 } 743 } 680 744 681 // ------------------------------------------- << 682 void G4RunManagerKernel::ResetNavigator() 745 void G4RunManagerKernel::ResetNavigator() 683 { 746 { 684 G4GeometryManager* geomManager = G4GeometryM << 747 if(runManagerKernelType==workerRMK) 685 if (runManagerKernelType == workerRMK) { << 748 { 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 749 696 // We have to tweak the navigator's state in 750 // We have to tweak the navigator's state in case a geometry has been 697 // modified between runs. By the following c 751 // modified between runs. By the following calls we ensure that navigator's 698 // state is reset properly. It is required t 752 // state is reset properly. It is required the geometry to be closed 699 // and previous optimisations to be cleared. 753 // and previous optimisations to be cleared. 700 << 754 701 if (verboseLevel > 1) G4cout << "Start closi << 755 G4GeometryManager* geomManager = G4GeometryManager::GetInstance(); >> 756 if(verboseLevel>1) G4cout << "Start closing geometry." << G4endl; 702 757 703 geomManager->OpenGeometry(); 758 geomManager->OpenGeometry(); 704 geomManager->CloseGeometry(geometryToBeOptim << 759 geomManager->CloseGeometry(geometryToBeOptimized, verboseLevel>1); 705 << 760 706 geometryNeedsToBeClosed = false; 761 geometryNeedsToBeClosed = false; 707 } 762 } 708 763 709 // ------------------------------------------- << 710 void G4RunManagerKernel::UpdateRegion() 764 void G4RunManagerKernel::UpdateRegion() 711 { 765 { 712 G4StateManager* stateManager = G4StateManage << 766 G4StateManager* stateManager = G4StateManager::GetStateManager(); 713 G4ApplicationState currentState = stateManag 767 G4ApplicationState currentState = stateManager->GetCurrentState(); 714 if (currentState != G4State_Init) { << 768 if( currentState != G4State_Init ) 715 G4Exception("G4RunManagerKernel::UpdateReg << 769 { >> 770 G4Exception("G4RunManagerKernel::UpdateRegion", >> 771 "Run0024", >> 772 JustWarning, 716 "Geant4 kernel not in Init sta 773 "Geant4 kernel not in Init state : method ignored."); 717 return; 774 return; 718 } 775 } 719 776 720 if (runManagerKernelType == workerRMK) retur << 777 if(runManagerKernelType==workerRMK) return; 721 778 722 CheckRegions(); 779 CheckRegions(); 723 780 724 G4RegionStore::GetInstance()->UpdateMaterial 781 G4RegionStore::GetInstance()->UpdateMaterialList(currentWorld); 725 782 726 G4ProductionCutsTable::GetProductionCutsTabl 783 G4ProductionCutsTable::GetProductionCutsTable()->UpdateCoupleTable(currentWorld); 727 } 784 } 728 785 729 // ------------------------------------------- << 730 void G4RunManagerKernel::BuildPhysicsTables(G4 786 void G4RunManagerKernel::BuildPhysicsTables(G4bool fakeRun) 731 { 787 { 732 if (G4ProductionCutsTable::GetProductionCuts << 788 if( G4ProductionCutsTable::GetProductionCutsTable()->IsModified() >> 789 || physicsNeedsToBeReBuilt) >> 790 { >> 791 TIMEMORY_AUTO_TIMER(""); 733 #ifdef G4MULTITHREADED 792 #ifdef G4MULTITHREADED 734 if (runManagerKernelType == masterRMK) { << 793 if(runManagerKernelType==masterRMK) >> 794 { 735 // make sure workers also rebuild physic 795 // make sure workers also rebuild physics tables 736 G4UImanager* pUImanager = G4UImanager::G 796 G4UImanager* pUImanager = G4UImanager::GetUIpointer(); 737 pUImanager->ApplyCommand("/run/physicsMo 797 pUImanager->ApplyCommand("/run/physicsModified"); 738 } 798 } 739 #endif 799 #endif 740 physicsList->BuildPhysicsTable(); 800 physicsList->BuildPhysicsTable(); >> 801 ////G4ProductionCutsTable::GetProductionCutsTable()->PhysicsTableUpdated(); 741 physicsNeedsToBeReBuilt = false; 802 physicsNeedsToBeReBuilt = false; 742 } 803 } 743 804 744 if (!fakeRun && verboseLevel > 1) DumpRegion << 805 if(!fakeRun && verboseLevel>1) DumpRegion(); 745 if (!fakeRun && verboseLevel > 0) physicsLis << 806 if(!fakeRun && verboseLevel>0) physicsList->DumpCutValuesTable(); 746 if (!fakeRun) physicsList->DumpCutValuesTabl << 807 if(!fakeRun) physicsList->DumpCutValuesTableIfRequested(); 747 } 808 } 748 809 749 // ------------------------------------------- << 750 void G4RunManagerKernel::CheckRegions() 810 void G4RunManagerKernel::CheckRegions() 751 { 811 { 752 G4TransportationManager* transM = G4Transpor 812 G4TransportationManager* transM = G4TransportationManager::GetTransportationManager(); 753 std::size_t nWorlds = transM->GetNoWorlds(); << 813 size_t nWorlds = transM->GetNoWorlds(); 754 std::vector<G4VPhysicalVolume*>::iterator wI 814 std::vector<G4VPhysicalVolume*>::iterator wItr; 755 for (auto region : *G4RegionStore::GetInstan << 815 for(size_t i=0;i<G4RegionStore::GetInstance()->size();i++) 756 // Let each region have a pointer to the w << 816 { 757 // G4Region::SetWorld() checks if the regi << 817 G4Region* region = (*(G4RegionStore::GetInstance()))[i]; 758 // set it only if it does. Thus, here we g << 818 759 // volumes. << 819 //Let each region have a pointer to the world volume where it belongs to. 760 region->SetWorld(nullptr); // reset << 820 //G4Region::SetWorld() checks if the region belongs to the given world and set it >> 821 //only if it does. Thus, here we go through all the registered world volumes. >> 822 region->SetWorld(0); // reset 761 region->UsedInMassGeometry(false); 823 region->UsedInMassGeometry(false); 762 region->UsedInParallelGeometry(false); 824 region->UsedInParallelGeometry(false); 763 wItr = transM->GetWorldsIterator(); 825 wItr = transM->GetWorldsIterator(); 764 for (std::size_t iw = 0; iw < nWorlds; ++i << 826 for(size_t iw=0;iw<nWorlds;iw++) 765 if (region->BelongsTo(*wItr)) { << 827 { 766 if (*wItr == currentWorld) { << 828 if(region->BelongsTo(*wItr)) 767 region->UsedInMassGeometry(true); << 829 { 768 } << 830 if(*wItr==currentWorld) 769 else { << 831 { region->UsedInMassGeometry(true); } 770 region->UsedInParallelGeometry(true) << 832 else 771 } << 833 { region->UsedInParallelGeometry(true); } 772 } 834 } 773 region->SetWorld(*wItr); 835 region->SetWorld(*wItr); 774 ++wItr; << 836 wItr++; 775 } 837 } 776 838 777 G4ProductionCuts* cuts = region->GetProduc 839 G4ProductionCuts* cuts = region->GetProductionCuts(); 778 if (cuts == nullptr) { << 840 if(!cuts) 779 if (region->IsInMassGeometry() && verbos << 841 { >> 842 if(region->IsInMassGeometry()) >> 843 { 780 G4cout << "Warning : Region <" << regi 844 G4cout << "Warning : Region <" << region->GetName() 781 << "> does not have specific pr << 845 << "> does not have specific production cuts," << G4endl 782 << "even though it appears in t << 846 << "even though it appears in the current tracking world." << G4endl; 783 G4cout << "Default cuts are used for t 847 G4cout << "Default cuts are used for this region." << G4endl; 784 } 848 } 785 849 786 if (region->IsInMassGeometry() || region << 850 if(region->IsInMassGeometry()||region->IsInParallelGeometry()) >> 851 { 787 region->SetProductionCuts( 852 region->SetProductionCuts( 788 G4ProductionCutsTable::GetProduction << 853 G4ProductionCutsTable::GetProductionCutsTable() >> 854 ->GetDefaultProductionCuts()); 789 } 855 } 790 } 856 } 791 } 857 } 792 858 793 // 859 // 794 // If a parallel world has no region, set de 860 // If a parallel world has no region, set default region for parallel world 795 // 861 // 796 862 797 wItr = transM->GetWorldsIterator(); 863 wItr = transM->GetWorldsIterator(); 798 for (std::size_t iw = 0; iw < nWorlds; ++iw) << 864 for(size_t iw=0;iw<nWorlds;iw++) 799 if (*wItr != currentWorld) { << 865 { >> 866 //G4cout << "+++ " << (*wItr)->GetName() << G4endl; >> 867 if(*wItr!=currentWorld) >> 868 { 800 G4LogicalVolume* pwLogical = (*wItr)->Ge 869 G4LogicalVolume* pwLogical = (*wItr)->GetLogicalVolume(); 801 if (pwLogical->GetRegion() == nullptr) { << 870 if(!(pwLogical->GetRegion())) >> 871 { 802 pwLogical->SetRegion(defaultRegionForP 872 pwLogical->SetRegion(defaultRegionForParallelWorld); 803 defaultRegionForParallelWorld->AddRoot 873 defaultRegionForParallelWorld->AddRootLogicalVolume(pwLogical); >> 874 //G4cout << "+++++ defaultRegionForParallelWorld is set to " >> 875 // << (*wItr)->GetName() << " +++++" << G4endl; 804 } 876 } 805 } 877 } 806 ++wItr; << 878 wItr++; 807 } 879 } >> 880 808 } 881 } 809 882 810 // ------------------------------------------- << 811 void G4RunManagerKernel::DumpRegion(const G4St 883 void G4RunManagerKernel::DumpRegion(const G4String& rname) const 812 { 884 { 813 G4Region* region = G4RegionStore::GetInstanc 885 G4Region* region = G4RegionStore::GetInstance()->GetRegion(rname); 814 if (region != nullptr) DumpRegion(region); << 886 if(region) DumpRegion(region); 815 } 887 } 816 888 817 // ------------------------------------------- << 818 void G4RunManagerKernel::DumpRegion(G4Region* 889 void G4RunManagerKernel::DumpRegion(G4Region* region) const 819 { 890 { 820 if (region == nullptr) { << 891 if(!region) 821 for (const auto& i : *G4RegionStore::GetIn << 892 { 822 DumpRegion(i); << 893 for(size_t i=0;i<G4RegionStore::GetInstance()->size();i++) 823 } << 894 { DumpRegion((*(G4RegionStore::GetInstance()))[i]); } 824 } << 895 } 825 else { << 896 else 826 if (G4Threading::IsWorkerThread()) return; << 897 { >> 898 if(G4Threading::IsWorkerThread()) return; 827 G4cout << G4endl; 899 G4cout << G4endl; 828 G4cout << "Region <" << region->GetName() 900 G4cout << "Region <" << region->GetName() << "> -- "; 829 if (region->GetWorldPhysical() != nullptr) << 901 if(region->GetWorldPhysical()) 830 G4cout << " -- appears in <" << region-> << 902 { 831 } << 903 G4cout << " -- appears in <" 832 else { << 904 << region->GetWorldPhysical()->GetName() << "> world volume"; 833 G4cout << " -- is not associated to any << 834 } 905 } >> 906 else >> 907 { G4cout << " -- is not associated to any world."; } 835 G4cout << G4endl; 908 G4cout << G4endl; 836 if (region->IsInMassGeometry()) { << 909 if(region->IsInMassGeometry()) 837 G4cout << " This region is in the mass w << 910 { G4cout << " This region is in the mass world." << G4endl; } 838 } << 911 if(region->IsInParallelGeometry()) 839 if (region->IsInParallelGeometry()) { << 912 { G4cout << " This region is in the parallel world." << G4endl; } 840 G4cout << " This region is in the parall << 841 } << 842 913 843 G4cout << " Root logical volume(s) : "; 914 G4cout << " Root logical volume(s) : "; 844 std::size_t nRootLV = region->GetNumberOfR << 915 size_t nRootLV = region->GetNumberOfRootVolumes(); 845 auto lvItr = region->GetRootLogicalVolumeI << 916 std::vector<G4LogicalVolume*>::iterator lvItr = region->GetRootLogicalVolumeIterator(); 846 for (std::size_t j = 0; j < nRootLV; ++j) << 917 for(size_t j=0;j<nRootLV;j++) 847 G4cout << (*lvItr)->GetName() << " "; << 918 { G4cout << (*lvItr)->GetName() << " "; lvItr++; } 848 ++lvItr; << 849 } << 850 G4cout << G4endl; 919 G4cout << G4endl; 851 920 852 G4cout << " Pointers : G4VUserRegionInform << 921 G4cout << " Pointers : G4VUserRegionInformation[" << region->GetUserInformation() 853 << "], G4UserLimits[" << region->Ge << 922 << "], G4UserLimits[" << region->GetUserLimits() 854 << region->GetFastSimulationManager << 923 << "], G4FastSimulationManager[" << region->GetFastSimulationManager() 855 << region->GetRegionalSteppingActio << 924 << "], G4UserSteppingAction[" << region->GetRegionalSteppingAction() << "]" << G4endl; 856 << 925 857 G4cout << " Materials : "; 926 G4cout << " Materials : "; 858 auto mItr = region->GetMaterialIterator(); << 927 std::vector<G4Material*>::const_iterator mItr = region->GetMaterialIterator(); 859 std::size_t nMaterial = region->GetNumberO << 928 size_t nMaterial = region->GetNumberOfMaterials(); 860 for (std::size_t iMate = 0; iMate < nMater << 929 for(size_t iMate=0;iMate<nMaterial;iMate++) >> 930 { 861 G4cout << (*mItr)->GetName() << " "; 931 G4cout << (*mItr)->GetName() << " "; 862 ++mItr; << 932 mItr++; 863 } 933 } 864 G4cout << G4endl; 934 G4cout << G4endl; 865 G4ProductionCuts* cuts = region->GetProduc 935 G4ProductionCuts* cuts = region->GetProductionCuts(); 866 if ((cuts == nullptr) && region->IsInMassG << 936 if(!cuts && region->IsInMassGeometry()) >> 937 { 867 G4cerr << "Warning : Region <" << region 938 G4cerr << "Warning : Region <" << region->GetName() 868 << "> does not have specific prod 939 << "> does not have specific production cuts." << G4endl; 869 G4cerr << "Default cuts are used for thi 940 G4cerr << "Default cuts are used for this region." << G4endl; 870 region->SetProductionCuts( 941 region->SetProductionCuts( 871 G4ProductionCutsTable::GetProductionCu << 942 G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts()); 872 } 943 } 873 else if (cuts != nullptr) { << 944 else if(cuts) >> 945 { 874 G4cout << " Production cuts : " 946 G4cout << " Production cuts : " 875 << " gamma " << G4BestUnit(cuts- << 947 << " gamma " 876 << G4BestUnit(cuts->GetProduction << 948 << G4BestUnit(cuts->GetProductionCut("gamma"),"Length") 877 << G4BestUnit(cuts->GetProduction << 949 << " e- " 878 << G4BestUnit(cuts->GetProduction << 950 << G4BestUnit(cuts->GetProductionCut("e-"),"Length") >> 951 << " e+ " >> 952 << G4BestUnit(cuts->GetProductionCut("e+"),"Length") >> 953 << " proton " >> 954 << G4BestUnit(cuts->GetProductionCut("proton"),"Length") >> 955 << G4endl; 879 } 956 } 880 } 957 } 881 } 958 } 882 959 883 // ------------------------------------------- << 960 #include "G4LogicalVolumeStore.hh" 884 void G4RunManagerKernel::CheckRegularGeometry( 961 void G4RunManagerKernel::CheckRegularGeometry() 885 { 962 { 886 G4LogicalVolumeStore* store = G4LogicalVolum 963 G4LogicalVolumeStore* store = G4LogicalVolumeStore::GetInstance(); 887 for (const auto& pos : *store) { << 964 for(G4LogicalVolumeStore::iterator pos=store->begin(); pos!=store->end(); pos++) 888 if ((pos != nullptr) && (pos->GetNoDaughte << 965 { 889 if (pos->GetDaughter(0)->IsRegularStruct << 966 if((*pos)&&((*pos)->GetNoDaughters()==1)) >> 967 { >> 968 if((*pos)->GetDaughter(0)->IsRegularStructure()) >> 969 { 890 SetScoreSplitter(); 970 SetScoreSplitter(); 891 return; 971 return; 892 } 972 } 893 } 973 } 894 } 974 } 895 } 975 } 896 << 976 897 // ------------------------------------------- << 977 #include "G4ParticleTable.hh" >> 978 #include "G4ParticleDefinition.hh" >> 979 #include "G4ProcessManager.hh" >> 980 #include "G4ProcessVector.hh" >> 981 #include "G4VProcess.hh" 898 G4bool G4RunManagerKernel::ConfirmCoupledTrans 982 G4bool G4RunManagerKernel::ConfirmCoupledTransportation() 899 { 983 { 900 G4ParticleTable* theParticleTable = G4Partic 984 G4ParticleTable* theParticleTable = G4ParticleTable::GetParticleTable(); 901 auto theParticleIterator = theParticleTable- << 985 G4ParticleTable::G4PTblDicIterator* theParticleIterator = theParticleTable->GetIterator(); 902 theParticleIterator->reset(); 986 theParticleIterator->reset(); 903 while ((*theParticleIterator)()) { << 987 while((*theParticleIterator)()) >> 988 { 904 G4ParticleDefinition* pd = theParticleIter 989 G4ParticleDefinition* pd = theParticleIterator->value(); 905 G4ProcessManager* pm = pd->GetProcessManag 990 G4ProcessManager* pm = pd->GetProcessManager(); 906 if (pm != nullptr) { << 991 if(pm) >> 992 { 907 G4ProcessVector* pv = pm->GetAlongStepPr 993 G4ProcessVector* pv = pm->GetAlongStepProcessVector(typeDoIt); 908 G4VProcess* p = (*pv)[0]; 994 G4VProcess* p = (*pv)[0]; 909 return ((p->GetProcessName()) == "Couple << 995 return ( (p->GetProcessName()) == "CoupledTransportation" ); 910 } 996 } 911 } 997 } 912 return false; 998 return false; 913 } 999 } 914 1000 915 // ------------------------------------------- << 1001 #include "G4ScoreSplittingProcess.hh" 916 void G4RunManagerKernel::SetScoreSplitter() 1002 void G4RunManagerKernel::SetScoreSplitter() 917 { 1003 { 918 auto pSplitter = new G4ScoreSplittingProcess << 1004 G4ScoreSplittingProcess* pSplitter = new G4ScoreSplittingProcess(); 919 G4ParticleTable* theParticleTable = G4Partic 1005 G4ParticleTable* theParticleTable = G4ParticleTable::GetParticleTable(); 920 auto theParticleIterator = theParticleTable- << 1006 G4ParticleTable::G4PTblDicIterator* theParticleIterator = theParticleTable->GetIterator(); 921 1007 922 // Ensure that Process is added only once to 1008 // Ensure that Process is added only once to the particles' process managers 923 static G4ThreadLocal G4bool InitSplitter = f << 1009 static G4ThreadLocal bool InitSplitter=false; 924 if (!InitSplitter) { << 1010 if( ! InitSplitter ) { 925 InitSplitter = true; 1011 InitSplitter = true; 926 1012 927 theParticleIterator->reset(); 1013 theParticleIterator->reset(); 928 while ((*theParticleIterator)()) { << 1014 while( (*theParticleIterator)() ) >> 1015 { 929 G4ParticleDefinition* particle = thePart 1016 G4ParticleDefinition* particle = theParticleIterator->value(); 930 G4ProcessManager* pmanager = particle->G 1017 G4ProcessManager* pmanager = particle->GetProcessManager(); 931 if (pmanager != nullptr) { << 1018 if(pmanager) 932 pmanager->AddDiscreteProcess(pSplitter << 1019 { pmanager->AddDiscreteProcess(pSplitter); } 933 } << 934 } 1020 } 935 1021 936 if (verboseLevel > 0) { << 1022 if(verboseLevel>0) 937 G4cout << "G4RunManagerKernel -- G4Score << 1023 { 938 "particles." << 1024 G4cout << "G4RunManagerKernel -- G4ScoreSplittingProcess is appended to all particles." << G4endl; 939 << G4endl; << 940 } 1025 } 941 } 1026 } 942 } 1027 } 943 1028 944 // ------------------------------------------- << 945 void G4RunManagerKernel::SetupShadowProcess() 1029 void G4RunManagerKernel::SetupShadowProcess() const 946 { 1030 { 947 G4ParticleTable* theParticleTable = G4Partic << 1031 G4ParticleTable* theParticleTable = G4ParticleTable::GetParticleTable(); 948 auto theParticleIterator = theParticleTable- << 1032 G4ParticleTable::G4PTblDicIterator* theParticleIterator = theParticleTable->GetIterator(); 949 theParticleIterator->reset(); << 1033 theParticleIterator->reset(); 950 // loop on particles and get process manager << 1034 //loop on particles and get process manager from there list of processes 951 while ((*theParticleIterator)()) { << 1035 while((*theParticleIterator)()) 952 G4ParticleDefinition* pd = theParticleIter << 1036 { 953 G4ProcessManager* pm = pd->GetProcessManag << 1037 G4ParticleDefinition* pd = theParticleIterator->value(); 954 if (pm != nullptr) { << 1038 G4ProcessManager* pm = pd->GetProcessManager(); 955 G4ProcessVector& procs = *(pm->GetProces << 1039 if(pm) 956 for (G4int idx = 0; idx < (G4int)procs.s << 1040 { 957 const G4VProcess* masterP = procs[idx] << 1041 G4ProcessVector& procs = *(pm->GetProcessList()); 958 if (masterP == nullptr) { << 1042 for ( std::size_t idx = 0 ; idx<procs.size() ; ++idx) 959 // Process does not have an associat << 1043 { 960 // We are in master mode or sequenti << 1044 const G4VProcess* masterP = procs[idx]->GetMasterProcess(); 961 procs[idx]->SetMasterProcess(const_c << 1045 if ( ! masterP ) >> 1046 { >> 1047 //Process does not have an associated shadow master process >> 1048 //We are in master mode or sequential >> 1049 procs[idx]->SetMasterProcess(const_cast<G4VProcess*>(procs[idx])); >> 1050 } >> 1051 } 962 } 1052 } 963 } << 964 } 1053 } 965 } << 966 } 1054 } 967 1055