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