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