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