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] [ 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 /processes/electromagnetic/dna/management/src/G4ITTransportationManager.cc (Version 11.3.0) and /processes/electromagnetic/dna/management/src/G4ITTransportationManager.cc (Version 9.6.p1)


  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 // $Id: G4ITTransportationManager.cc 64374 2012-10-31 16:37:23Z gcosmo $
 26 //                                                 27 //
 27 /// \brief {Duplicated version of G4Transporta     28 /// \brief {Duplicated version of G4TransportationManager.
 28 ///         This class just contains the point     29 ///         This class just contains the pointer to the navigator object of the
 29 ///         simulation.}                           30 ///         simulation.}
 30 //                                                 31 //
 31 // History:                                        32 // History:
 32 // -----------                                     33 // -----------
 33 //                                                 34 //
 34 // -------------------------------------------     35 // -------------------------------------------------------------------
 35                                                    36 
 36 #include "G4ITTransportationManager.hh"            37 #include "G4ITTransportationManager.hh"
 37 #include "G4TransportationManager.hh"              38 #include "G4TransportationManager.hh"
 38 #include "G4ITNavigator.hh"                        39 #include "G4ITNavigator.hh"
 39 #include "G4ITSafetyHelper.hh"                 << 
 40 #include "G4PVPlacement.hh"                    << 
 41                                                    40 
 42 G4ThreadLocal G4ITTransportationManager*       <<  41 G4ITTransportationManager* G4ITTransportationManager::fpInstance (0);
 43 G4ITTransportationManager::fpInstance(nullptr) << 
 44                                                    42 
 45 G4ITTransportationManager::G4ITTransportationM     43 G4ITTransportationManager::G4ITTransportationManager()
 46 {                                                  44 {
 47   Initialize();                                <<  45     Initialize();
 48 }                                                  46 }
 49                                                    47 
 50 G4ITTransportationManager::~G4ITTransportation     48 G4ITTransportationManager::~G4ITTransportationManager()
 51 {                                                  49 {
 52   ClearNavigators();                           <<  50     if(fpNavigator) delete fpNavigator;
 53   delete fpSafetyHelper;                       << 
 54 }                                                  51 }
 55                                                    52 
 56 void G4ITTransportationManager::DeleteInstance     53 void G4ITTransportationManager::DeleteInstance()
 57 {                                                  54 {
 58   if (fpInstance != nullptr)                   <<  55     if(fpInstance)
 59   {                                            << 
 60     delete fpInstance;                         << 
 61     fpInstance = nullptr;                      << 
 62   }                                            << 
 63 }                                              << 
 64                                                << 
 65 // ------------------------------------------- << 
 66 // ClearNavigators()                           << 
 67 //                                             << 
 68 // Clear collection of navigators and delete a << 
 69 // Called only by the class destructor.        << 
 70 //                                             << 
 71 void G4ITTransportationManager::ClearNavigator << 
 72 {                                              << 
 73   std::vector<G4ITNavigator*>::iterator pNav;  << 
 74   for (pNav = fNavigators.begin(); pNav != fNa << 
 75   {                                            << 
 76     delete *pNav;                              << 
 77   }                                            << 
 78   fNavigators.clear();                         << 
 79   fActiveNavigators.clear();                   << 
 80   fWorlds.clear();                             << 
 81 }                                              << 
 82                                                << 
 83 void G4ITTransportationManager::Initialize()   << 
 84 {                                              << 
 85   // Create the navigator for tracking and act << 
 86   //                                           << 
 87   auto  trackingNavigator = new G4ITNavigator( << 
 88   trackingNavigator->Activate(true);           << 
 89   G4Navigator* navForTracking =                << 
 90       G4TransportationManager::GetTransportati << 
 91           ->GetNavigatorForTracking();         << 
 92   G4VPhysicalVolume* world = navForTracking->G << 
 93   trackingNavigator->SetWorldVolume(world);    << 
 94   fNavigators.push_back(trackingNavigator);    << 
 95   fActiveNavigators.push_back(trackingNavigato << 
 96   //fWorlds.push_back(world); // NULL register << 
 97                                                << 
 98   size_t n_worlds = G4TransportationManager::G << 
 99       ->GetNoWorlds();                         << 
100   auto it =                                    << 
101       G4TransportationManager::GetTransportati << 
102                                                << 
103   for (size_t i = 0; i < n_worlds; i++, it++)  << 
104   {                                            << 
105     fWorlds.push_back(*it);                    << 
106   }                                            << 
107   fpSafetyHelper = new G4ITSafetyHelper();     << 
108 }                                              << 
109                                                << 
110 G4ITTransportationManager* G4ITTransportationM << 
111 {                                              << 
112   if (fpInstance == nullptr) fpInstance = new  << 
113   return fpInstance;                           << 
114 }                                              << 
115                                                << 
116 // ------------------------------------------- << 
117 // GetParallelWorld()                          << 
118 //                                             << 
119 // Provided the name of a world volume, return << 
120 // If not existing, create (allocate) and regi << 
121 //                                             << 
122 G4VPhysicalVolume*                             << 
123 G4ITTransportationManager::GetParallelWorld(co << 
124 {                                              << 
125   G4VPhysicalVolume* wPV = IsWorldExisting(wor << 
126   if (wPV == nullptr)                          << 
127   {                                            << 
128     wPV = GetNavigatorForTracking()->GetWorldV << 
129     G4LogicalVolume* wLV = wPV->GetLogicalVolu << 
130     wLV = new G4LogicalVolume(wLV->GetSolid(), << 
131     wPV = new G4PVPlacement(wPV->GetRotation() << 
132                             worldName, nullptr << 
133     RegisterWorld(wPV);                        << 
134   }                                            << 
135   return wPV;                                  << 
136 }                                              << 
137                                                << 
138 // ------------------------------------------- << 
139 // GetNavigator()                              << 
140 //                                             << 
141 // Provided the name of a world volume, return << 
142 // If not existing, create it and register it  << 
143 // exception if the associated parallel world  << 
144 //                                             << 
145 G4ITNavigator* G4ITTransportationManager::GetN << 
146 {                                              << 
147   // If already existing, return the stored po << 
148   //                                           << 
149   std::vector<G4ITNavigator*>::iterator pNav;  << 
150   for (pNav = fNavigators.begin(); pNav != fNa << 
151   {                                            << 
152     if ((*pNav)->GetWorldVolume()->GetName() = << 
153     {                                          << 
154       return *pNav;                            << 
155     }                                          << 
156   }                                            << 
157                                                << 
158   // Check if world of that name already exist << 
159   // create a navigator and register it        << 
160   //                                           << 
161   G4ITNavigator* aNavigator = nullptr;         << 
162   G4VPhysicalVolume* aWorld = IsWorldExisting( << 
163   if (aWorld != nullptr)                       << 
164   {                                            << 
165     aNavigator = new G4ITNavigator();          << 
166     aNavigator->SetWorldVolume(aWorld);        << 
167     fNavigators.push_back(aNavigator);         << 
168   }                                            << 
169   else                                         << 
170   {                                            << 
171     G4String message = "World volume with name << 
172         + worldName                            << 
173         + "- does not exist. Create it first b << 
174     G4Exception("G4ITTransportationManager::Ge << 
175                 FatalException, message);      << 
176   }                                            << 
177                                                << 
178   return aNavigator;                           << 
179 }                                              << 
180                                                << 
181 // ------------------------------------------- << 
182 // GetNavigator()                              << 
183 //                                             << 
184 // Provided a pointer to a world volume, retur << 
185 // Create it in case not existing and add it t << 
186 // If world volume not existing, issue an exce << 
187 //                                             << 
188 G4ITNavigator* G4ITTransportationManager::GetN << 
189 {                                              << 
190   std::vector<G4ITNavigator*>::iterator pNav;  << 
191   for (pNav = fNavigators.begin(); pNav != fNa << 
192   {                                            << 
193     if ((*pNav)->GetWorldVolume() == aWorld)   << 
194     {                                          << 
195       return *pNav;                            << 
196     }                                          << 
197   }                                            << 
198   G4ITNavigator* aNavigator = nullptr;         << 
199   auto pWorld = std::find(fWorlds.begin(),     << 
200                                                << 
201                                                << 
202   if (pWorld != fWorlds.end())                 << 
203   {                                            << 
204     aNavigator = new G4ITNavigator();          << 
205     aNavigator->SetWorldVolume(aWorld);        << 
206     fNavigators.push_back(aNavigator);         << 
207   }                                            << 
208   else                                         << 
209   {                                            << 
210     G4String message = "World volume with name << 
211         + aWorld->GetName()                    << 
212         + "- does not exist. Create it first b << 
213     G4Exception("G4ITTransportationManager::Ge << 
214                 "GeomNav0002", FatalException, << 
215   }                                            << 
216                                                << 
217   return aNavigator;                           << 
218 }                                              << 
219                                                << 
220 // ------------------------------------------- << 
221 // DeRegisterNavigator()                       << 
222 //                                             << 
223 // Provided a pointer to an already allocated  << 
224 // associated entry in the navigators collecti << 
225 // delete the actual pointed object, which is  << 
226 // The navigator for tracking -cannot- be dere << 
227 //                                             << 
228 void G4ITTransportationManager::DeRegisterNavi << 
229 {                                              << 
230   if (aNavigator == fNavigators[0])            << 
231   {                                            << 
232     G4Exception("G4ITTransportationManager::De << 
233                 "GeomNav0003", FatalException, << 
234                 "The navigator for tracking CA << 
235   }                                            << 
236   auto pNav = std::find(fNavigators.begin(),   << 
237                                                << 
238                                                << 
239   if (pNav != fNavigators.end())               << 
240   {                                            << 
241     // Deregister associated world volume      << 
242     //                                         << 
243     DeRegisterWorld((*pNav)->GetWorldVolume()) << 
244                                                << 
245     // Deregister the navigator                << 
246     //                                         << 
247     fNavigators.erase(pNav);                   << 
248   }                                            << 
249   else                                         << 
250   {                                            << 
251     G4String message = "Navigator for volume - << 
252         + aNavigator->GetWorldVolume()->GetNam << 
253     G4Exception("G4ITTransportationManager::De << 
254                 "GeomNav1002", JustWarning, me << 
255   }                                            << 
256 }                                              << 
257                                                << 
258 // ------------------------------------------- << 
259 // ActivateNavigator()                         << 
260 //                                             << 
261 // Provided a pointer to an already allocated  << 
262 // the associated activation flag for the navi << 
263 // If the provided navigator is not already re << 
264 // Return the index of the activated navigator << 
265 // ComputeStep() method of G4PathFinder.       << 
266 //                                             << 
267 G4int G4ITTransportationManager::ActivateNavig << 
268 {                                              << 
269   auto pNav = std::find(fNavigators.begin(),   << 
270                                                << 
271                                                << 
272   if (pNav == fNavigators.end())               << 
273   {                                            << 
274     G4String message = "Navigator for volume - << 
275         + aNavigator->GetWorldVolume()->GetNam << 
276     G4Exception("G4ITTransportationManager::Ac << 
277                 JustWarning, message);         << 
278     return -1;                                 << 
279   }                                            << 
280                                                << 
281   aNavigator->Activate(true);                  << 
282   G4int id = 0;                                << 
283   std::vector<G4ITNavigator*>::iterator pActiv << 
284   for (pActiveNav = fActiveNavigators.begin(); << 
285       pActiveNav != fActiveNavigators.end(); p << 
286   {                                            << 
287     if (*pActiveNav == aNavigator)             << 
288     {                                              56     {
289       return id;                               <<  57         delete fpInstance;
                                                   >>  58         fpInstance = 0;
290     }                                              59     }
291     id++;                                      << 
292   }                                            << 
293                                                << 
294   fActiveNavigators.push_back(aNavigator);     << 
295   return id;                                   << 
296 }                                              << 
297                                                << 
298 // ------------------------------------------- << 
299 // DeActivateNavigator()                       << 
300 //                                             << 
301 // Provided a pointer to an already allocated  << 
302 // the associated activation flag in the navig << 
303 // If the provided navigator is not already re << 
304 //                                             << 
305 void G4ITTransportationManager::DeActivateNavi << 
306 {                                              << 
307   auto pNav = std::find(fNavigators.begin(),   << 
308                                                << 
309                                                << 
310   if (pNav != fNavigators.end())               << 
311   {                                            << 
312     (*pNav)->Activate(false);                  << 
313   }                                            << 
314   else                                         << 
315   {                                            << 
316     G4String message = "Navigator for volume - << 
317         + aNavigator->GetWorldVolume()->GetNam << 
318     G4Exception("G4ITTransportationManager::De << 
319                 "GeomNav1002", JustWarning, me << 
320   }                                            << 
321                                                << 
322   auto pActiveNav = std::find(                 << 
323       fActiveNavigators.begin(), fActiveNaviga << 
324   if (pActiveNav != fActiveNavigators.end())   << 
325   {                                            << 
326     fActiveNavigators.erase(pActiveNav);       << 
327   }                                            << 
328 }                                                  60 }
329                                                    61 
330 // ------------------------------------------- <<  62 void G4ITTransportationManager::Initialize()
331 // InactivateAll()                             << 
332 //                                             << 
333 // Inactivate all the navigators except for th << 
334 // store of active navigators.                 << 
335 //                                             << 
336 void G4ITTransportationManager::InactivateAll( << 
337 {                                              << 
338   std::vector<G4ITNavigator*>::iterator pNav;  << 
339   for (pNav = fActiveNavigators.begin(); pNav  << 
340       pNav++)                                  << 
341   {                                            << 
342     (*pNav)->Activate(false);                  << 
343   }                                            << 
344   fActiveNavigators.clear();                   << 
345                                                << 
346   // Restore status for the navigator for trac << 
347   //                                           << 
348   fNavigators[0]->Activate(true);              << 
349   fActiveNavigators.push_back(fNavigators[0]); << 
350 }                                              << 
351                                                << 
352 // ------------------------------------------- << 
353 // IsWorldExisting()                           << 
354 //                                             << 
355 // Verify existance or not of an istance of th << 
356 // same name in the collection. Return the wor << 
357 //                                             << 
358 G4VPhysicalVolume*                             << 
359 G4ITTransportationManager::IsWorldExisting(con << 
360 {                                                  63 {
361   auto pWorld = fWorlds.begin();               <<  64     fpNavigator = new G4ITNavigator();
362   if (*pWorld == 0)                            <<  65     fpNavigator->Activate(true);
363   {                                            <<  66     G4Navigator* navForTracking = G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking();
364     *pWorld = fNavigators[0]->GetWorldVolume() <<  67     G4VPhysicalVolume* world = navForTracking->GetWorldVolume();
365   }                                            <<  68     fpNavigator->SetWorldVolume(world);
366                                                << 
367   for (pWorld = fWorlds.begin(); pWorld != fWo << 
368   {                                            << 
369     if ((*pWorld)->GetName() == name)          << 
370     {                                          << 
371       return *pWorld;                          << 
372     }                                          << 
373   }                                            << 
374   return nullptr;                              << 
375 }                                                  69 }
376                                                    70 
377 // ------------------------------------------- <<  71 G4ITTransportationManager* G4ITTransportationManager::GetTransportationManager()
378 // RegisterWorld()                             << 
379 //                                             << 
380 // Provided a pointer to an already allocated  << 
381 // associated entry in the worlds collection.  << 
382 // succeeds and the new entry is created.      << 
383 //                                             << 
384 G4bool G4ITTransportationManager::RegisterWorl << 
385 {                                                  72 {
386   G4bool done = false;                         <<  73     if(fpInstance == 0) fpInstance = new G4ITTransportationManager;
387                                                <<  74     return fpInstance;
388   auto pWorld = std::find(fWorlds.begin(),     << 
389                                                << 
390                                                << 
391   if (pWorld == fWorlds.end())                 << 
392   {                                            << 
393     fWorlds.push_back(aWorld);                 << 
394     done = true;                               << 
395   }                                            << 
396   return done;                                 << 
397 }                                                  75 }
398                                                    76 
399 // ------------------------------------------- <<  77 G4ITNavigator* G4ITTransportationManager::GetNavigatorForTracking()
400 // DeRegisterWorld()                           << 
401 //                                             << 
402 // Provided a pointer to an already allocated  << 
403 // associated entry in the worlds collection b << 
404 // pointed object, which is still owned by the << 
405 //                                             << 
406 void G4ITTransportationManager::DeRegisterWorl << 
407 {                                                  78 {
408   auto pWorld = std::find(fWorlds.begin(),     <<  79     return fpNavigator;
409                                                << 
410                                                << 
411   if (pWorld != fWorlds.end())                 << 
412   {                                            << 
413     fWorlds.erase(pWorld);                     << 
414   }                                            << 
415   else                                         << 
416   {                                            << 
417     G4String message = "World volume -" + aWor << 
418                        + "- not found in memor << 
419     G4Exception("G4ITTransportationManager::De << 
420                 JustWarning, message);         << 
421   }                                            << 
422 }                                                  80 }
423                                                    81