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] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /geometry/navigation/src/G4TransportationManager.cc (Version 11.3.0) and /geometry/navigation/src/G4TransportationManager.cc (Version ReleaseNotes)


** Warning: Cannot open xref database.

  1 //                                                  1 
  2 // *******************************************    
  3 // * License and Disclaimer                       
  4 // *                                              
  5 // * The  Geant4 software  is  copyright of th    
  6 // * the Geant4 Collaboration.  It is provided    
  7 // * conditions of the Geant4 Software License    
  8 // * LICENSE and available at  http://cern.ch/    
  9 // * include a list of copyright holders.         
 10 // *                                              
 11 // * Neither the authors of this software syst    
 12 // * institutes,nor the agencies providing fin    
 13 // * work  make  any representation or  warran    
 14 // * regarding  this  software system or assum    
 15 // * use.  Please see the license in the file     
 16 // * for the full disclaimer and the limitatio    
 17 // *                                              
 18 // * This  code  implementation is the result     
 19 // * technical work of the GEANT4 collaboratio    
 20 // * By using,  copying,  modifying or  distri    
 21 // * any work based  on the software)  you  ag    
 22 // * use  in  resulting  scientific  publicati    
 23 // * acceptance of all terms of the Geant4 Sof    
 24 // *******************************************    
 25 //                                                
 26 // Class G4TransportationManager implementatio    
 27 //                                                
 28 // Created : J.Apostolakis, 1997                  
 29 // Reviewed: G.Cosmo, 2006                        
 30 // -------------------------------------------    
 31                                                   
 32 #include "G4TransportationManager.hh"             
 33                                                   
 34 #include <algorithm>                              
 35                                                   
 36 #include "G4GeometryMessenger.hh"                 
 37 #include "G4PropagatorInField.hh"                 
 38 #include "G4FieldManager.hh"                      
 39 #include "G4LogicalVolume.hh"                     
 40 #include "G4PVPlacement.hh"                       
 41                                                   
 42 // Initialise the static instance of the singl    
 43 //                                                
 44 G4ThreadLocal G4TransportationManager*            
 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                                                   
 51 // -------------------------------------------    
 52 // Constructor                                    
 53 //                                                
 54 G4TransportationManager::G4TransportationManag    
 55 {                                                 
 56   if (fTransportationManager != nullptr)          
 57   {                                               
 58     G4Exception("G4TransportationManager::G4Tr    
 59                 "GeomNav0002", FatalException,    
 60                 "Only ONE instance of G4Transp    
 61   }                                               
 62                                                   
 63   // Create the navigator for tracking and act    
 64   //                                              
 65   G4Navigator* trackingNavigator= nullptr;        
 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);              
 79   fNavigators.push_back(trackingNavigator);       
 80   fActiveNavigators.push_back(trackingNavigato    
 81   fWorlds.push_back(trackingNavigator->GetWorl    
 82                                                   
 83   fGeomMessenger    = new G4GeometryMessenger(    
 84   fFieldManager     = new G4FieldManager(); //    
 85   fPropagatorInField= new G4PropagatorInField(    
 86   fSafetyHelper     = new G4SafetyHelper();       
 87                                                   
 88   G4FieldManager::SetGlobalFieldManager(fField    
 89 }                                                 
 90                                                   
 91 // -------------------------------------------    
 92 // Destructor                                     
 93 //                                                
 94 G4TransportationManager::~G4TransportationMana    
 95 {                                                 
 96   delete fSafetyHelper;                           
 97   delete fPropagatorInField;                      
 98   delete fGeomMessenger;                          
 99   ClearNavigators();                              
100   fTransportationManager = nullptr;               
101 }                                                 
102                                                   
103 // -------------------------------------------    
104 // GetTransportationManager()                     
105 //                                                
106 // Retrieve the static instance of the singlet    
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 //                                                
122 G4TransportationManager* G4TransportationManag    
123 {                                                 
124    return fTransportationManager;                 
125 }                                                 
126                                                   
127 // -------------------------------------------    
128 // SetFieldManager()                              
129 //                                                
130 // Set the associated field manager.              
131 //                                                
132 void G4TransportationManager::SetFieldManager(    
133 {                                                 
134    fFieldManager = newFieldManager;               
135    G4FieldManager::SetGlobalFieldManager(fFiel    
136                                                   
137    // Message the PropagatorInField,              
138    // which also maintains this information (t    
139    //                                             
140    if( fPropagatorInField != nullptr )            
141    {                                              
142       fPropagatorInField -> SetDetectorFieldMa    
143    }                                              
144 }                                                 
145                                                   
146 // -------------------------------------------    
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()                              
161 //                                                
162 // Clear collection of navigators and delete a    
163 // Called only by the class destructor.           
164 //                                                
165 void G4TransportationManager::ClearNavigators(    
166 {                                                 
167    for (const auto & fNavigator : fNavigators)    
168    {                                              
169      delete fNavigator;                           
170    }                                              
171    fNavigators.clear();                           
172    fActiveNavigators.clear();                     
173    fWorlds.clear();                               
174 }                                                 
175                                                   
176 // -------------------------------------------    
177 // GetParallelWorld()                             
178 //                                                
179 // Provided the name of a world volume, return    
180 // If not existing, create (allocate) and regi    
181 //                                                
182 G4VPhysicalVolume*                                
183 G4TransportationManager::GetParallelWorld( con    
184 {                                                 
185    G4VPhysicalVolume* wPV = IsWorldExisting(wo    
186    if (wPV == nullptr)                            
187    {                                              
188      wPV = GetNavigatorForTracking()->GetWorld    
189      G4LogicalVolume* wLV = wPV->GetLogicalVol    
190      wLV = new G4LogicalVolume(wLV->GetSolid()    
191                                worldName);        
192      wPV = new G4PVPlacement (wPV->GetRotation    
193                               wPV->GetTranslat    
194                               wLV, worldName,     
195      RegisterWorld(wPV);                          
196    }                                              
197    return wPV;                                    
198 }                                                 
199                                                   
200 // -------------------------------------------    
201 // GetNavigator()                                 
202 //                                                
203 // Provided the name of a world volume, return    
204 // If not existing, create it and register it     
205 // exception if the associated parallel world     
206 //                                                
207 G4Navigator* G4TransportationManager::GetNavig    
208 {                                                 
209    // If already existing, return the stored p    
210    //                                             
211    for (const auto & fNavigator : fNavigators)    
212    {                                              
213       if (fNavigator->GetWorldVolume()->GetNam    
214       {                                           
215         return fNavigator;                        
216       }                                           
217    }                                              
218                                                   
219    // Check if world of that name already exis    
220    // create a navigator and register it          
221    //                                             
222    G4Navigator* aNavigator = nullptr;             
223    G4VPhysicalVolume* aWorld = IsWorldExisting    
224    if(aWorld != nullptr)                          
225    {                                              
226       aNavigator = new G4Navigator();             
227       aNavigator->SetWorldVolume(aWorld);         
228       fNavigators.push_back(aNavigator);          
229    }                                              
230    else                                           
231    {                                              
232       G4String message                            
233          = "World volume with name -" + worldN    
234          + "- does not exist. Create it first     
235       G4Exception("G4TransportationManager::Ge    
236                   "GeomNav0002", FatalExceptio    
237    }                                              
238                                                   
239    return aNavigator;                             
240 }                                                 
241                                                   
242 // -------------------------------------------    
243 // GetNavigator()                                 
244 //                                                
245 // Provided a pointer to a world volume, retur    
246 // Create it in case not existing and add it t    
247 // If world volume not existing, issue an exce    
248 //                                                
249 G4Navigator* G4TransportationManager::GetNavig    
250 {                                                 
251    for (const auto & fNavigator : fNavigators)    
252    {                                              
253      if (fNavigator->GetWorldVolume() == aWorl    
254    }                                              
255    G4Navigator* aNavigator = nullptr;             
256    auto pWorld = std::find(fWorlds.cbegin(), f    
257    if (pWorld != fWorlds.cend())                  
258    {                                              
259       aNavigator = new G4Navigator();             
260       aNavigator->SetWorldVolume(aWorld);         
261       fNavigators.push_back(aNavigator);          
262    }                                              
263    else                                           
264    {                                              
265       G4String message                            
266          = "World volume with name -" + aWorld    
267          + "- does not exist. Create it first     
268       G4Exception("G4TransportationManager::Ge    
269                   "GeomNav0002", FatalExceptio    
270    }                                              
271                                                   
272    return aNavigator;                             
273 }                                                 
274                                                   
275 // -------------------------------------------    
276 // DeRegisterNavigator()                          
277 //                                                
278 // Provided a pointer to an already allocated     
279 // associated entry in the navigators collecti    
280 // delete the actual pointed object, which is     
281 // The navigator for tracking -cannot- be dere    
282 //                                                
283 void G4TransportationManager::DeRegisterNaviga    
284 {                                                 
285    if (aNavigator == fNavigators[0])              
286    {                                              
287       G4Exception("G4TransportationManager::De    
288                   "GeomNav0003", FatalExceptio    
289                   "The navigator for tracking     
290    }                                              
291    auto pNav = std::find(fNavigators.cbegin(),    
292    if (pNav != fNavigators.cend())                
293    {                                              
294       // Deregister associated world volume       
295       //                                          
296       DeRegisterWorld((*pNav)->GetWorldVolume(    
297                                                   
298       // Deregister the navigator                 
299       //                                          
300       fNavigators.erase(pNav);                    
301    }                                              
302    else                                           
303    {                                              
304       G4String message                            
305          = "Navigator for volume -" + aNavigat    
306          + "- not found in memory!";              
307       G4Exception("G4TransportationManager::De    
308                   "GeomNav1002", JustWarning,     
309    }                                              
310 }                                                 
311                                                   
312 // -------------------------------------------    
313 // ActivateNavigator()                            
314 //                                                
315 // Provided a pointer to an already allocated     
316 // the associated activation flag for the navi    
317 // If the provided navigator is not already re    
318 // Return the index of the activated navigator    
319 // ComputeStep() method of G4PathFinder.          
320 //                                                
321 G4int G4TransportationManager::ActivateNavigat    
322 {                                                 
323    auto pNav = std::find(fNavigators.cbegin(),    
324    if (pNav == fNavigators.cend())                
325    {                                              
326       G4String message                            
327          = "Navigator for volume -" + aNavigat    
328          + "- not found in memory!";              
329       G4Exception("G4TransportationManager::Ac    
330                   "GeomNav1002", FatalExceptio    
331       return -1;                                  
332    }                                              
333                                                   
334    aNavigator->Activate(true);                    
335    G4int id = 0;                                  
336    for(const auto & fActiveNavigator : fActive    
337    {                                              
338       if (fActiveNavigator == aNavigator)  { r    
339       ++id;                                       
340    }                                              
341                                                   
342    fActiveNavigators.push_back(aNavigator);       
343    return id;                                     
344 }                                                 
345                                                   
346 // -------------------------------------------    
347 // DeActivateNavigator()                          
348 //                                                
349 // Provided a pointer to an already allocated     
350 // the associated activation flag in the navig    
351 // If the provided navigator is not already re    
352 //                                                
353 void G4TransportationManager::DeActivateNaviga    
354 {                                                 
355    auto pNav = std::find(fNavigators.cbegin(),    
356    if (pNav != fNavigators.cend())                
357    {                                              
358       (*pNav)->Activate(false);                   
359    }                                              
360    else                                           
361    {                                              
362       G4String message                            
363          = "Navigator for volume -" + aNavigat    
364          + "- not found in memory!";              
365       G4Exception("G4TransportationManager::De    
366                   "GeomNav1002", JustWarning,     
367    }                                              
368                                                   
369    auto pActiveNav = std::find(fActiveNavigato    
370                                fActiveNavigato    
371    if (pActiveNav != fActiveNavigators.cend())    
372    {                                              
373       fActiveNavigators.erase(pActiveNav);        
374    }                                              
375 }                                                 
376                                                   
377 // -------------------------------------------    
378 // InactivateAll()                                
379 //                                                
380 // Inactivate all the navigators except for th    
381 // store of active navigators.                    
382 //                                                
383 void G4TransportationManager::InactivateAll( )    
384 {                                                 
385    for (const auto & fActiveNavigator : fActiv    
386    {                                              
387       fActiveNavigator->Activate(false);          
388    }                                              
389    fActiveNavigators.clear();                     
390                                                   
391    // Restore status for the navigator for tra    
392    //                                             
393    fNavigators[0]->Activate(true);                
394    fActiveNavigators.push_back(fNavigators[0])    
395 }                                                 
396                                                   
397 // -------------------------------------------    
398 // IsWorldExisting()                              
399 //                                                
400 // Verify existance or not of an istance of th    
401 // same name in the collection. Return the wor    
402 //                                                
403 G4VPhysicalVolume*                                
404 G4TransportationManager::IsWorldExisting ( con    
405 {                                                 
406    auto pWorld = fWorlds.begin();                 
407    if ( *pWorld==nullptr )  { *pWorld=fNavigat    
408                                                   
409    for (const auto & fWorld : fWorlds)            
410    {                                              
411       if (fWorld->GetName() == name ) { return    
412    }                                              
413    return nullptr;                                
414 }                                                 
415                                                   
416 // -------------------------------------------    
417 // RegisterWorld()                                
418 //                                                
419 // Provided a pointer to an already allocated     
420 // associated entry in the worlds collection.     
421 // succeeds and the new entry is created.         
422 //                                                
423 G4bool G4TransportationManager::RegisterWorld(    
424 {                                                 
425    G4bool done = false;                           
426                                                   
427    auto pWorld = std::find(fWorlds.cbegin(), f    
428    if (pWorld == fWorlds.cend())                  
429    {                                              
430      fWorlds.push_back(aWorld);                   
431      done = true;                                 
432    }                                              
433    return done;                                   
434 }                                                 
435                                                   
436 // -------------------------------------------    
437 // DeRegisterWorld()                              
438 //                                                
439 // Provided a pointer to an already allocated     
440 // associated entry in the worlds collection b    
441 // pointed object, which is still owned by the    
442 //                                                
443 void G4TransportationManager::DeRegisterWorld(    
444 {                                                 
445    auto pWorld = std::find(fWorlds.cbegin(), f    
446    if (pWorld != fWorlds.cend())                  
447    {                                              
448       fWorlds.erase(pWorld);                      
449    }                                              
450    else                                           
451    {                                              
452      G4String message                             
453        = "World volume -" + aWorld->GetName()     
454      G4Exception("G4TransportationManager::DeR    
455                  "GeomNav1002", JustWarning, m    
456    }                                              
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 }                                                 
503