Geant4  10.01.p01
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 
67  void Print() const;
68  // Print number of entries.
69 
71  // Destructor: takes care to delete allocated levels.
72 
73  private:
74 
76  // Default constructor.
77 
78  inline void Register(std::vector<G4NavigationLevel> * pLevels);
79  // Register levels collection to pool and activate it.
80 
81  void Reset();
82  // Set internal vectors content to zero.
83 
84  private:
85 
87 
88  std::vector<std::vector<G4NavigationLevel> *> fPool;
89  std::vector<G4bool> fActive;
90 };
91 
92 // ***************************************************************************
93 // Register levels collection to pool (add and/or activate)
94 // ***************************************************************************
95 //
96 inline void G4NavigationHistoryPool::
97 Register(std::vector<G4NavigationLevel> * pLevels)
98 {
99  fPool.push_back(pLevels);
100  fActive.push_back(true);
101 }
102 
103 // ***************************************************************************
104 // Deactivate levels collection in pool
105 // ***************************************************************************
106 //
107 inline void G4NavigationHistoryPool::
108 DeRegister(std::vector<G4NavigationLevel> * pLevels)
109 {
110  std::vector<std::vector<G4NavigationLevel> *>::iterator
111  pos = std::find(fPool.begin(), fPool.end(), pLevels);
112  fActive[pos-fPool.begin()]=false;
113 }
114 
115 // ***************************************************************************
116 // Return the pointer of a new collection of levels allocated
117 // ***************************************************************************
118 //
119 inline std::vector<G4NavigationLevel> * G4NavigationHistoryPool::GetNewLevels()
120 {
121  std::vector<G4NavigationLevel> * aLevelVec =
122  new std::vector<G4NavigationLevel>(kHistoryMax);
123  Register(aLevelVec);
124 
125  return aLevelVec;
126 }
127 
128 #endif
static const G4int kHistoryMax
Definition: geomdefs.hh:72
std::vector< G4NavigationLevel > * GetNewLevels()
#define G4ThreadLocal
Definition: tls.hh:89
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