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