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 // Class G4TransportationManager implementatio 26 // Class G4TransportationManager implementation 27 // 27 // 28 // Created : J.Apostolakis, 1997 28 // Created : J.Apostolakis, 1997 29 // Reviewed: G.Cosmo, 2006 29 // Reviewed: G.Cosmo, 2006 30 // ------------------------------------------- 30 // -------------------------------------------------------------------- 31 31 32 #include "G4TransportationManager.hh" 32 #include "G4TransportationManager.hh" 33 33 34 #include <algorithm> 34 #include <algorithm> 35 35 36 #include "G4GeometryMessenger.hh" 36 #include "G4GeometryMessenger.hh" 37 #include "G4PropagatorInField.hh" 37 #include "G4PropagatorInField.hh" 38 #include "G4FieldManager.hh" 38 #include "G4FieldManager.hh" 39 #include "G4LogicalVolume.hh" 39 #include "G4LogicalVolume.hh" 40 #include "G4PVPlacement.hh" 40 #include "G4PVPlacement.hh" 41 41 42 // Initialise the static instance of the singl 42 // Initialise the static instance of the singleton 43 // 43 // 44 G4ThreadLocal G4TransportationManager* 44 G4ThreadLocal G4TransportationManager* 45 G4TransportationManager::fTransportationManage 45 G4TransportationManager::fTransportationManager = nullptr; 46 46 47 // The first registered navigator -- expect th 47 // The first registered navigator -- expect this to be the master thread's navigator 48 // If it has an external sub-navigator, it wi 48 // If it has an external sub-navigator, it will be cloned for each worker thread. 49 G4Navigator* G4TransportationManager::fFirstTr 49 G4Navigator* G4TransportationManager::fFirstTrackingNavigator= nullptr; 50 50 51 // ------------------------------------------- 51 // ---------------------------------------------------------------------------- 52 // Constructor 52 // Constructor 53 // 53 // 54 G4TransportationManager::G4TransportationManag 54 G4TransportationManager::G4TransportationManager() 55 { 55 { 56 if (fTransportationManager != nullptr) 56 if (fTransportationManager != nullptr) 57 { 57 { 58 G4Exception("G4TransportationManager::G4Tr 58 G4Exception("G4TransportationManager::G4TransportationManager()", 59 "GeomNav0002", FatalException, 59 "GeomNav0002", FatalException, 60 "Only ONE instance of G4Transp 60 "Only ONE instance of G4TransportationManager is allowed!"); 61 } 61 } 62 62 63 // Create the navigator for tracking and act 63 // Create the navigator for tracking and activate it; add to collections 64 // 64 // 65 G4Navigator* trackingNavigator= nullptr; 65 G4Navigator* trackingNavigator= nullptr; 66 if( (fFirstTrackingNavigator != nullptr) && 66 if( (fFirstTrackingNavigator != nullptr) && (fFirstTrackingNavigator->GetExternalNavigation() != nullptr) ) 67 { 67 { 68 trackingNavigator = fFirstTrackingNavigat 68 trackingNavigator = fFirstTrackingNavigator->Clone(); 69 } 69 } 70 else 70 else 71 { 71 { 72 trackingNavigator = new G4Navigator(); 72 trackingNavigator = new G4Navigator(); 73 if( fFirstTrackingNavigator == nullptr ) 73 if( fFirstTrackingNavigator == nullptr ) 74 { 74 { 75 fFirstTrackingNavigator = trackingNavi 75 fFirstTrackingNavigator = trackingNavigator; 76 } 76 } 77 } 77 } 78 trackingNavigator->Activate(true); 78 trackingNavigator->Activate(true); 79 fNavigators.push_back(trackingNavigator); 79 fNavigators.push_back(trackingNavigator); 80 fActiveNavigators.push_back(trackingNavigato 80 fActiveNavigators.push_back(trackingNavigator); 81 fWorlds.push_back(trackingNavigator->GetWorl 81 fWorlds.push_back(trackingNavigator->GetWorldVolume()); // NULL registered 82 82 83 fGeomMessenger = new G4GeometryMessenger( 83 fGeomMessenger = new G4GeometryMessenger(this); 84 fFieldManager = new G4FieldManager(); // 84 fFieldManager = new G4FieldManager(); // deleted by G4FieldManagerStore 85 fPropagatorInField= new G4PropagatorInField( 85 fPropagatorInField= new G4PropagatorInField(trackingNavigator,fFieldManager); 86 fSafetyHelper = new G4SafetyHelper(); 86 fSafetyHelper = new G4SafetyHelper(); 87 << 88 G4FieldManager::SetGlobalFieldManager(fField << 89 } 87 } 90 88 91 // ------------------------------------------- 89 // ---------------------------------------------------------------------------- 92 // Destructor 90 // Destructor 93 // 91 // 94 G4TransportationManager::~G4TransportationMana 92 G4TransportationManager::~G4TransportationManager() 95 { 93 { 96 delete fSafetyHelper; 94 delete fSafetyHelper; 97 delete fPropagatorInField; 95 delete fPropagatorInField; 98 delete fGeomMessenger; 96 delete fGeomMessenger; 99 ClearNavigators(); 97 ClearNavigators(); 100 fTransportationManager = nullptr; 98 fTransportationManager = nullptr; 101 } 99 } 102 100 103 // ------------------------------------------- 101 // ---------------------------------------------------------------------------- 104 // GetTransportationManager() 102 // GetTransportationManager() 105 // 103 // 106 // Retrieve the static instance of the singlet 104 // Retrieve the static instance of the singleton and create it if not existing 107 // 105 // 108 G4TransportationManager* G4TransportationManag 106 G4TransportationManager* G4TransportationManager::GetTransportationManager() 109 { 107 { 110 if (fTransportationManager == nullptr) 108 if (fTransportationManager == nullptr) 111 { 109 { 112 fTransportationManager = new G4Transporta 110 fTransportationManager = new G4TransportationManager; 113 } 111 } 114 return fTransportationManager; 112 return fTransportationManager; 115 } 113 } 116 114 117 // ------------------------------------------- 115 // ---------------------------------------------------------------------------- 118 // GetInstanceIfExist() 116 // GetInstanceIfExist() 119 // 117 // 120 // Retrieve the static instance pointer of the 118 // Retrieve the static instance pointer of the singleton 121 // 119 // 122 G4TransportationManager* G4TransportationManag 120 G4TransportationManager* G4TransportationManager::GetInstanceIfExist() 123 { 121 { 124 return fTransportationManager; 122 return fTransportationManager; 125 } 123 } 126 124 127 // ------------------------------------------- 125 // ---------------------------------------------------------------------------- 128 // SetFieldManager() 126 // SetFieldManager() 129 // 127 // 130 // Set the associated field manager. 128 // Set the associated field manager. 131 // 129 // 132 void G4TransportationManager::SetFieldManager( 130 void G4TransportationManager::SetFieldManager(G4FieldManager* newFieldManager) 133 { 131 { 134 fFieldManager = newFieldManager; 132 fFieldManager = newFieldManager; 135 G4FieldManager::SetGlobalFieldManager(fFiel << 136 133 137 // Message the PropagatorInField, 134 // Message the PropagatorInField, 138 // which also maintains this information (t 135 // which also maintains this information (to be reviewed) 139 // 136 // 140 if( fPropagatorInField != nullptr ) 137 if( fPropagatorInField != nullptr ) 141 { 138 { 142 fPropagatorInField -> SetDetectorFieldMa 139 fPropagatorInField -> SetDetectorFieldManager( newFieldManager ); 143 } 140 } 144 } 141 } 145 142 146 // ------------------------------------------- 143 // ---------------------------------------------------------------------------- 147 // SetNavigatorForTracking() 144 // SetNavigatorForTracking() 148 // 145 // 149 // Set the active navigator for tracking, alwa 146 // Set the active navigator for tracking, always 150 // the first in the collection of registered n 147 // the first in the collection of registered navigators. 151 // 148 // 152 void G4TransportationManager::SetNavigatorForT 149 void G4TransportationManager::SetNavigatorForTracking(G4Navigator* newNavigator) 153 { 150 { 154 fNavigators[0] = newNavigator; 151 fNavigators[0] = newNavigator; 155 fActiveNavigators[0] = newNavigator; 152 fActiveNavigators[0] = newNavigator; 156 fPropagatorInField->SetNavigatorForPropagat 153 fPropagatorInField->SetNavigatorForPropagating(newNavigator); 157 } 154 } 158 155 159 // ------------------------------------------- 156 // ---------------------------------------------------------------------------- 160 // ClearNavigators() 157 // ClearNavigators() 161 // 158 // 162 // Clear collection of navigators and delete a 159 // Clear collection of navigators and delete allocated objects. 163 // Called only by the class destructor. 160 // Called only by the class destructor. 164 // 161 // 165 void G4TransportationManager::ClearNavigators( 162 void G4TransportationManager::ClearNavigators() 166 { 163 { 167 for (const auto & fNavigator : fNavigators) 164 for (const auto & fNavigator : fNavigators) 168 { 165 { 169 delete fNavigator; 166 delete fNavigator; 170 } 167 } 171 fNavigators.clear(); 168 fNavigators.clear(); 172 fActiveNavigators.clear(); 169 fActiveNavigators.clear(); 173 fWorlds.clear(); 170 fWorlds.clear(); 174 } 171 } 175 172 176 // ------------------------------------------- 173 // ---------------------------------------------------------------------------- 177 // GetParallelWorld() 174 // GetParallelWorld() 178 // 175 // 179 // Provided the name of a world volume, return 176 // Provided the name of a world volume, returns the associated world pointer. 180 // If not existing, create (allocate) and regi 177 // If not existing, create (allocate) and register it in the collection. 181 // 178 // 182 G4VPhysicalVolume* 179 G4VPhysicalVolume* 183 G4TransportationManager::GetParallelWorld( con 180 G4TransportationManager::GetParallelWorld( const G4String& worldName ) 184 { 181 { 185 G4VPhysicalVolume* wPV = IsWorldExisting(wo 182 G4VPhysicalVolume* wPV = IsWorldExisting(worldName); 186 if (wPV == nullptr) 183 if (wPV == nullptr) 187 { 184 { 188 wPV = GetNavigatorForTracking()->GetWorld 185 wPV = GetNavigatorForTracking()->GetWorldVolume(); 189 G4LogicalVolume* wLV = wPV->GetLogicalVol 186 G4LogicalVolume* wLV = wPV->GetLogicalVolume(); 190 wLV = new G4LogicalVolume(wLV->GetSolid() 187 wLV = new G4LogicalVolume(wLV->GetSolid(), nullptr, 191 worldName); 188 worldName); 192 wPV = new G4PVPlacement (wPV->GetRotation 189 wPV = new G4PVPlacement (wPV->GetRotation(), 193 wPV->GetTranslat 190 wPV->GetTranslation(), 194 wLV, worldName, 191 wLV, worldName, nullptr, false, 0); 195 RegisterWorld(wPV); 192 RegisterWorld(wPV); 196 } 193 } 197 return wPV; 194 return wPV; 198 } 195 } 199 196 200 // ------------------------------------------- 197 // ---------------------------------------------------------------------------- 201 // GetNavigator() 198 // GetNavigator() 202 // 199 // 203 // Provided the name of a world volume, return 200 // Provided the name of a world volume, returns the associated navigator. 204 // If not existing, create it and register it 201 // If not existing, create it and register it in the collection, throw an 205 // exception if the associated parallel world 202 // exception if the associated parallel world does not exist. 206 // 203 // 207 G4Navigator* G4TransportationManager::GetNavig 204 G4Navigator* G4TransportationManager::GetNavigator( const G4String& worldName ) 208 { 205 { 209 // If already existing, return the stored p 206 // If already existing, return the stored pointer to the navigator 210 // 207 // 211 for (const auto & fNavigator : fNavigators) 208 for (const auto & fNavigator : fNavigators) 212 { 209 { 213 if (fNavigator->GetWorldVolume()->GetNam 210 if (fNavigator->GetWorldVolume()->GetName() == worldName) 214 { 211 { 215 return fNavigator; 212 return fNavigator; 216 } 213 } 217 } 214 } 218 215 219 // Check if world of that name already exis 216 // Check if world of that name already exists, 220 // create a navigator and register it 217 // create a navigator and register it 221 // 218 // 222 G4Navigator* aNavigator = nullptr; 219 G4Navigator* aNavigator = nullptr; 223 G4VPhysicalVolume* aWorld = IsWorldExisting 220 G4VPhysicalVolume* aWorld = IsWorldExisting(worldName); 224 if(aWorld != nullptr) 221 if(aWorld != nullptr) 225 { 222 { 226 aNavigator = new G4Navigator(); 223 aNavigator = new G4Navigator(); 227 aNavigator->SetWorldVolume(aWorld); 224 aNavigator->SetWorldVolume(aWorld); 228 fNavigators.push_back(aNavigator); 225 fNavigators.push_back(aNavigator); 229 } 226 } 230 else 227 else 231 { 228 { 232 G4String message 229 G4String message 233 = "World volume with name -" + worldN 230 = "World volume with name -" + worldName 234 + "- does not exist. Create it first 231 + "- does not exist. Create it first by GetParallelWorld() method!"; 235 G4Exception("G4TransportationManager::Ge 232 G4Exception("G4TransportationManager::GetNavigator(name)", 236 "GeomNav0002", FatalExceptio 233 "GeomNav0002", FatalException, message); 237 } 234 } 238 235 239 return aNavigator; 236 return aNavigator; 240 } 237 } 241 238 242 // ------------------------------------------- 239 // ---------------------------------------------------------------------------- 243 // GetNavigator() 240 // GetNavigator() 244 // 241 // 245 // Provided a pointer to a world volume, retur 242 // Provided a pointer to a world volume, returns the associated navigator. 246 // Create it in case not existing and add it t 243 // Create it in case not existing and add it to the collection. 247 // If world volume not existing, issue an exce 244 // If world volume not existing, issue an exception. 248 // 245 // 249 G4Navigator* G4TransportationManager::GetNavig 246 G4Navigator* G4TransportationManager::GetNavigator( G4VPhysicalVolume* aWorld ) 250 { 247 { 251 for (const auto & fNavigator : fNavigators) 248 for (const auto & fNavigator : fNavigators) 252 { 249 { 253 if (fNavigator->GetWorldVolume() == aWorl 250 if (fNavigator->GetWorldVolume() == aWorld) { return fNavigator; } 254 } 251 } 255 G4Navigator* aNavigator = nullptr; 252 G4Navigator* aNavigator = nullptr; 256 auto pWorld = std::find(fWorlds.cbegin(), f 253 auto pWorld = std::find(fWorlds.cbegin(), fWorlds.cend(), aWorld); 257 if (pWorld != fWorlds.cend()) 254 if (pWorld != fWorlds.cend()) 258 { 255 { 259 aNavigator = new G4Navigator(); 256 aNavigator = new G4Navigator(); 260 aNavigator->SetWorldVolume(aWorld); 257 aNavigator->SetWorldVolume(aWorld); 261 fNavigators.push_back(aNavigator); 258 fNavigators.push_back(aNavigator); 262 } 259 } 263 else 260 else 264 { 261 { 265 G4String message 262 G4String message 266 = "World volume with name -" + aWorld 263 = "World volume with name -" + aWorld->GetName() 267 + "- does not exist. Create it first 264 + "- does not exist. Create it first by GetParallelWorld() method!"; 268 G4Exception("G4TransportationManager::Ge 265 G4Exception("G4TransportationManager::GetNavigator(pointer)", 269 "GeomNav0002", FatalExceptio 266 "GeomNav0002", FatalException, message); 270 } 267 } 271 268 272 return aNavigator; 269 return aNavigator; 273 } 270 } 274 271 275 // ------------------------------------------- 272 // ---------------------------------------------------------------------------- 276 // DeRegisterNavigator() 273 // DeRegisterNavigator() 277 // 274 // 278 // Provided a pointer to an already allocated 275 // Provided a pointer to an already allocated navigator object, removes the 279 // associated entry in the navigators collecti 276 // associated entry in the navigators collection (remove pair) but does not 280 // delete the actual pointed object, which is 277 // delete the actual pointed object, which is still owned by the caller. 281 // The navigator for tracking -cannot- be dere 278 // The navigator for tracking -cannot- be deregistered. 282 // 279 // 283 void G4TransportationManager::DeRegisterNaviga 280 void G4TransportationManager::DeRegisterNavigator( G4Navigator* aNavigator ) 284 { 281 { 285 if (aNavigator == fNavigators[0]) 282 if (aNavigator == fNavigators[0]) 286 { 283 { 287 G4Exception("G4TransportationManager::De 284 G4Exception("G4TransportationManager::DeRegisterNavigator()", 288 "GeomNav0003", FatalExceptio 285 "GeomNav0003", FatalException, 289 "The navigator for tracking 286 "The navigator for tracking CANNOT be deregistered!"); 290 } 287 } 291 auto pNav = std::find(fNavigators.cbegin(), 288 auto pNav = std::find(fNavigators.cbegin(), fNavigators.cend(), aNavigator); 292 if (pNav != fNavigators.cend()) 289 if (pNav != fNavigators.cend()) 293 { 290 { 294 // Deregister associated world volume 291 // Deregister associated world volume 295 // 292 // 296 DeRegisterWorld((*pNav)->GetWorldVolume( 293 DeRegisterWorld((*pNav)->GetWorldVolume()); 297 294 298 // Deregister the navigator 295 // Deregister the navigator 299 // 296 // 300 fNavigators.erase(pNav); 297 fNavigators.erase(pNav); 301 } 298 } 302 else 299 else 303 { 300 { 304 G4String message 301 G4String message 305 = "Navigator for volume -" + aNavigat 302 = "Navigator for volume -" + aNavigator->GetWorldVolume()->GetName() 306 + "- not found in memory!"; 303 + "- not found in memory!"; 307 G4Exception("G4TransportationManager::De 304 G4Exception("G4TransportationManager::DeRegisterNavigator()", 308 "GeomNav1002", JustWarning, 305 "GeomNav1002", JustWarning, message); 309 } 306 } 310 } 307 } 311 308 312 // ------------------------------------------- 309 // ---------------------------------------------------------------------------- 313 // ActivateNavigator() 310 // ActivateNavigator() 314 // 311 // 315 // Provided a pointer to an already allocated 312 // Provided a pointer to an already allocated navigator object, set to 'true' 316 // the associated activation flag for the navi 313 // the associated activation flag for the navigator in the collection. 317 // If the provided navigator is not already re 314 // If the provided navigator is not already registered, issue a warning 318 // Return the index of the activated navigator 315 // Return the index of the activated navigator. This index should be used for 319 // ComputeStep() method of G4PathFinder. 316 // ComputeStep() method of G4PathFinder. 320 // 317 // 321 G4int G4TransportationManager::ActivateNavigat 318 G4int G4TransportationManager::ActivateNavigator( G4Navigator* aNavigator ) 322 { 319 { 323 auto pNav = std::find(fNavigators.cbegin(), 320 auto pNav = std::find(fNavigators.cbegin(), fNavigators.cend(), aNavigator); 324 if (pNav == fNavigators.cend()) 321 if (pNav == fNavigators.cend()) 325 { 322 { 326 G4String message 323 G4String message 327 = "Navigator for volume -" + aNavigat 324 = "Navigator for volume -" + aNavigator->GetWorldVolume()->GetName() 328 + "- not found in memory!"; 325 + "- not found in memory!"; 329 G4Exception("G4TransportationManager::Ac 326 G4Exception("G4TransportationManager::ActivateNavigator()", 330 "GeomNav1002", FatalExceptio 327 "GeomNav1002", FatalException, message); 331 return -1; 328 return -1; 332 } 329 } 333 330 334 aNavigator->Activate(true); 331 aNavigator->Activate(true); 335 G4int id = 0; 332 G4int id = 0; 336 for(const auto & fActiveNavigator : fActive 333 for(const auto & fActiveNavigator : fActiveNavigators) 337 { 334 { 338 if (fActiveNavigator == aNavigator) { r 335 if (fActiveNavigator == aNavigator) { return id; } 339 ++id; 336 ++id; 340 } 337 } 341 338 342 fActiveNavigators.push_back(aNavigator); 339 fActiveNavigators.push_back(aNavigator); 343 return id; 340 return id; 344 } 341 } 345 342 346 // ------------------------------------------- 343 // ---------------------------------------------------------------------------- 347 // DeActivateNavigator() 344 // DeActivateNavigator() 348 // 345 // 349 // Provided a pointer to an already allocated 346 // Provided a pointer to an already allocated navigator object, set to 'false' 350 // the associated activation flag in the navig 347 // the associated activation flag in the navigators collection. 351 // If the provided navigator is not already re 348 // If the provided navigator is not already registered, issue a warning. 352 // 349 // 353 void G4TransportationManager::DeActivateNaviga 350 void G4TransportationManager::DeActivateNavigator( G4Navigator* aNavigator ) 354 { 351 { 355 auto pNav = std::find(fNavigators.cbegin(), 352 auto pNav = std::find(fNavigators.cbegin(), fNavigators.cend(), aNavigator); 356 if (pNav != fNavigators.cend()) 353 if (pNav != fNavigators.cend()) 357 { 354 { 358 (*pNav)->Activate(false); 355 (*pNav)->Activate(false); 359 } 356 } 360 else 357 else 361 { 358 { 362 G4String message 359 G4String message 363 = "Navigator for volume -" + aNavigat 360 = "Navigator for volume -" + aNavigator->GetWorldVolume()->GetName() 364 + "- not found in memory!"; 361 + "- not found in memory!"; 365 G4Exception("G4TransportationManager::De 362 G4Exception("G4TransportationManager::DeActivateNavigator()", 366 "GeomNav1002", JustWarning, 363 "GeomNav1002", JustWarning, message); 367 } 364 } 368 365 369 auto pActiveNav = std::find(fActiveNavigato 366 auto pActiveNav = std::find(fActiveNavigators.cbegin(), 370 fActiveNavigato 367 fActiveNavigators.cend(), aNavigator); 371 if (pActiveNav != fActiveNavigators.cend()) 368 if (pActiveNav != fActiveNavigators.cend()) 372 { 369 { 373 fActiveNavigators.erase(pActiveNav); 370 fActiveNavigators.erase(pActiveNav); 374 } 371 } 375 } 372 } 376 373 377 // ------------------------------------------- 374 // ---------------------------------------------------------------------------- 378 // InactivateAll() 375 // InactivateAll() 379 // 376 // 380 // Inactivate all the navigators except for th 377 // Inactivate all the navigators except for the tracking one, and clear the 381 // store of active navigators. 378 // store of active navigators. 382 // 379 // 383 void G4TransportationManager::InactivateAll( ) 380 void G4TransportationManager::InactivateAll( ) 384 { 381 { 385 for (const auto & fActiveNavigator : fActiv 382 for (const auto & fActiveNavigator : fActiveNavigators) 386 { 383 { 387 fActiveNavigator->Activate(false); 384 fActiveNavigator->Activate(false); 388 } 385 } 389 fActiveNavigators.clear(); 386 fActiveNavigators.clear(); 390 387 391 // Restore status for the navigator for tra 388 // Restore status for the navigator for tracking 392 // 389 // 393 fNavigators[0]->Activate(true); 390 fNavigators[0]->Activate(true); 394 fActiveNavigators.push_back(fNavigators[0]) 391 fActiveNavigators.push_back(fNavigators[0]); 395 } 392 } 396 393 397 // ------------------------------------------- 394 // ---------------------------------------------------------------------------- 398 // IsWorldExisting() 395 // IsWorldExisting() 399 // 396 // 400 // Verify existance or not of an istance of th 397 // Verify existance or not of an istance of the world volume with 401 // same name in the collection. Return the wor 398 // same name in the collection. Return the world pointer if existing. 402 // 399 // 403 G4VPhysicalVolume* 400 G4VPhysicalVolume* 404 G4TransportationManager::IsWorldExisting ( con 401 G4TransportationManager::IsWorldExisting ( const G4String& name ) 405 { 402 { 406 auto pWorld = fWorlds.begin(); 403 auto pWorld = fWorlds.begin(); 407 if ( *pWorld==nullptr ) { *pWorld=fNavigat 404 if ( *pWorld==nullptr ) { *pWorld=fNavigators[0]->GetWorldVolume(); } 408 405 409 for (const auto & fWorld : fWorlds) 406 for (const auto & fWorld : fWorlds) 410 { 407 { 411 if (fWorld->GetName() == name ) { return 408 if (fWorld->GetName() == name ) { return fWorld; } 412 } 409 } 413 return nullptr; 410 return nullptr; 414 } 411 } 415 412 416 // ------------------------------------------- 413 // ---------------------------------------------------------------------------- 417 // RegisterWorld() 414 // RegisterWorld() 418 // 415 // 419 // Provided a pointer to an already allocated 416 // Provided a pointer to an already allocated world object, check and add the 420 // associated entry in the worlds collection. 417 // associated entry in the worlds collection. Return 'true' if registration 421 // succeeds and the new entry is created. 418 // succeeds and the new entry is created. 422 // 419 // 423 G4bool G4TransportationManager::RegisterWorld( 420 G4bool G4TransportationManager::RegisterWorld( G4VPhysicalVolume* aWorld ) 424 { 421 { 425 G4bool done = false; 422 G4bool done = false; 426 423 427 auto pWorld = std::find(fWorlds.cbegin(), f 424 auto pWorld = std::find(fWorlds.cbegin(), fWorlds.cend(), aWorld); 428 if (pWorld == fWorlds.cend()) 425 if (pWorld == fWorlds.cend()) 429 { 426 { 430 fWorlds.push_back(aWorld); 427 fWorlds.push_back(aWorld); 431 done = true; 428 done = true; 432 } 429 } 433 return done; 430 return done; 434 } 431 } 435 432 436 // ------------------------------------------- 433 // ---------------------------------------------------------------------------- 437 // DeRegisterWorld() 434 // DeRegisterWorld() 438 // 435 // 439 // Provided a pointer to an already allocated 436 // Provided a pointer to an already allocated world object, removes the 440 // associated entry in the worlds collection b 437 // associated entry in the worlds collection but does not delete the actual 441 // pointed object, which is still owned by the 438 // pointed object, which is still owned by the caller. 442 // 439 // 443 void G4TransportationManager::DeRegisterWorld( 440 void G4TransportationManager::DeRegisterWorld( G4VPhysicalVolume* aWorld ) 444 { 441 { 445 auto pWorld = std::find(fWorlds.cbegin(), f 442 auto pWorld = std::find(fWorlds.cbegin(), fWorlds.cend(), aWorld); 446 if (pWorld != fWorlds.cend()) 443 if (pWorld != fWorlds.cend()) 447 { 444 { 448 fWorlds.erase(pWorld); 445 fWorlds.erase(pWorld); 449 } 446 } 450 else 447 else 451 { 448 { 452 G4String message 449 G4String message 453 = "World volume -" + aWorld->GetName() 450 = "World volume -" + aWorld->GetName() + "- not found in memory!"; 454 G4Exception("G4TransportationManager::DeR 451 G4Exception("G4TransportationManager::DeRegisterWorld()", 455 "GeomNav1002", JustWarning, m 452 "GeomNav1002", JustWarning, message); 456 } 453 } 457 } 454 } 458 455 459 // ------------------------------------------- 456 // ---------------------------------------------------------------------------- 460 // ClearParallelWorlds() 457 // ClearParallelWorlds() 461 // 458 // 462 // Clear collection of navigators and delete a 459 // Clear collection of navigators and delete allocated objects associated with 463 // parallel worlds. 460 // parallel worlds. 464 // Called only by the RunManager when the enti 461 // Called only by the RunManager when the entire geometry is rebuilt from 465 // scratch. 462 // scratch. 466 // 463 // 467 void G4TransportationManager::ClearParallelWor 464 void G4TransportationManager::ClearParallelWorlds() 468 { 465 { 469 auto pNav = fNavigators.cbegin(); 466 auto pNav = fNavigators.cbegin(); 470 G4Navigator* trackingNavigator = *pNav; 467 G4Navigator* trackingNavigator = *pNav; 471 for (pNav=fNavigators.cbegin(); pNav!=fNavi 468 for (pNav=fNavigators.cbegin(); pNav!=fNavigators.cend(); ++pNav) 472 { 469 { 473 if (*pNav != trackingNavigator) { delete 470 if (*pNav != trackingNavigator) { delete *pNav; } 474 } 471 } 475 fNavigators.clear(); 472 fNavigators.clear(); 476 fActiveNavigators.clear(); 473 fActiveNavigators.clear(); 477 fWorlds.clear(); 474 fWorlds.clear(); 478 475 479 fNavigators.push_back(trackingNavigator); 476 fNavigators.push_back(trackingNavigator); 480 fActiveNavigators.push_back(trackingNavigat 477 fActiveNavigators.push_back(trackingNavigator); 481 fWorlds.push_back(nullptr); // NULL registe 478 fWorlds.push_back(nullptr); // NULL registered 482 } 479 } 483 480 484 // ------------------------------------------- 481 // ---------------------------------------------------------------------------- 485 // GetFirstTrackingNavigator() 482 // GetFirstTrackingNavigator() 486 // 483 // 487 // Get pointer to the first tracking Navigator 484 // Get pointer to the first tracking Navigator created 488 // 485 // 489 G4Navigator* G4TransportationManager::GetFirst 486 G4Navigator* G4TransportationManager::GetFirstTrackingNavigator() 490 { 487 { 491 return fFirstTrackingNavigator; 488 return fFirstTrackingNavigator; 492 } 489 } 493 490 494 // ------------------------------------------- 491 // ---------------------------------------------------------------------------- 495 // GetFirstTrackingNavigator() 492 // GetFirstTrackingNavigator() 496 // 493 // 497 // Get pointer to the first tracking Navigator 494 // Get pointer to the first tracking Navigator created 498 495 499 void G4TransportationManager::SetFirstTracking 496 void G4TransportationManager::SetFirstTrackingNavigator(G4Navigator *nav) 500 { 497 { 501 fFirstTrackingNavigator= nav; 498 fFirstTrackingNavigator= nav; 502 } 499 } 503 500