Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/geometry/navigation/src/G4TransportationManager.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 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 10.7.p3)


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