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.0.p2)


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