Geant4  10.01
G4NavigationHistoryPool.hh
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // $Id:$
28 //
29 // class G4NavigationHistoryPool
30 //
31 // Class description:
32 //
33 // Thread-local pool for navigation history levels collections being
34 // allocated by G4NavigationHistory. Allows for reuse of the vectors
35 // allocated according to lifetime of G4NavigationHistory objects.
36 
37 // History:
38 // 07.05.14 G.Cosmo Initial version
39 // --------------------------------------------------------------------
40 #ifndef G4NAVIGATIONHISTORYPOOL_HH
41 #define G4NAVIGATIONHISTORYPOOL_HH
42 
43 #include <vector>
44 
45 #include "G4NavigationLevel.hh"
46 
48 {
49  public: // with description
50 
52  // Return unique instance of G4NavigationHistoryPool.
53 
54  inline std::vector<G4NavigationLevel> * GetNewLevels();
55  // Return the pointer to a new collection of levels being allocated.
56 
57  std::vector<G4NavigationLevel> * GetLevels();
58  // Return the pointer of the first available collection of levels
59  // If none are available (i.e. non active) allocate collection.
60 
61  inline void DeRegister(std::vector<G4NavigationLevel> * pLevels);
62  // Deactivate levels collection in pool.
63 
64  void Clean();
65  // Delete all levels stored in the pool.
66 
68  // Destructor: takes care to delete allocated levels.
69 
70  private:
71 
73  // Default constructor.
74 
75  inline void Register(std::vector<G4NavigationLevel> * pLevels);
76  // Register levels collection to pool and activate it.
77 
78  void Reset();
79  // Set internal vectors content to zero.
80 
81  private:
82 
84 
85  std::vector<std::vector<G4NavigationLevel> *> fPool;
86  std::vector<G4bool> fActive;
87 };
88 
89 // ***************************************************************************
90 // Register levels collection to pool (add and/or activate)
91 // ***************************************************************************
92 //
93 inline void G4NavigationHistoryPool::
94 Register(std::vector<G4NavigationLevel> * pLevels)
95 {
96  fPool.push_back(pLevels);
97  fActive.push_back(true);
98 }
99 
100 // ***************************************************************************
101 // Deactivate levels collection in pool
102 // ***************************************************************************
103 //
104 inline void G4NavigationHistoryPool::
105 DeRegister(std::vector<G4NavigationLevel> * pLevels)
106 {
107  std::vector<std::vector<G4NavigationLevel> *>::iterator
108  pos = std::find(fPool.begin(), fPool.end(), pLevels);
109  fActive[pos-fPool.begin()]=false;
110 }
111 
112 // ***************************************************************************
113 // Return the pointer of a new collection of levels allocated
114 // ***************************************************************************
115 //
116 inline std::vector<G4NavigationLevel> * G4NavigationHistoryPool::GetNewLevels()
117 {
118  std::vector<G4NavigationLevel> * aLevelVec =
119  new std::vector<G4NavigationLevel>(kHistoryMax);
120  Register(aLevelVec);
121 
122  return aLevelVec;
123 }
124 
125 #endif
static const G4int kHistoryMax
Definition: geomdefs.hh:72
std::vector< G4NavigationLevel > * GetNewLevels()
#define G4ThreadLocal
Definition: tls.hh:84
void Register(std::vector< G4NavigationLevel > *pLevels)
static G4ThreadLocal G4NavigationHistoryPool * fgInstance
void DeRegister(std::vector< G4NavigationLevel > *pLevels)
std::vector< G4NavigationLevel > * GetLevels()
std::vector< std::vector< G4NavigationLevel > * > fPool
std::vector< G4bool > fActive
static G4NavigationHistoryPool * GetInstance()
static const G4double pos