Geant4  10.01.p01
G4NavigationHistoryPool.cc
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 // G4NavigationHistoryPool
30 //
31 // Implementation for singleton container
32 //
33 // History:
34 // 07.05.14 G.Cosmo Initial version
35 // --------------------------------------------------------------------
36 
37 #include "globals.hh"
39 
40 // ***************************************************************************
41 // Static class variables
42 // ***************************************************************************
43 //
45 
46 // ***************************************************************************
47 // Private constructor: Construct underlying containers
48 // ***************************************************************************
49 //
51 {
52 }
53 
54 // ***************************************************************************
55 // Destructor
56 // ***************************************************************************
57 //
59 {
60  Clean(); fgInstance = 0;
61 }
62 
63 // ***************************************************************************
64 // Delete all elements from the pool
65 // ***************************************************************************
66 //
68 {
69  for(size_t i=0; i<fPool.size(); ++i)
70  {
71  delete fPool[i];
72  }
73  fPool.clear();
74  fActive.clear();
75 }
76 
77 // ***************************************************************************
78 // Print number of entries
79 // ***************************************************************************
80 //
82 {
83 #ifdef G4VERBOSE
84  G4cout << "Total navigation history collections cleaned: "
85  << fPool.size() << G4endl;
86 #endif
87 }
88 
89 // ***************************************************************************
90 // Delete all elements from the pool
91 // ***************************************************************************
92 //
94 {
95  for(size_t i=0; i<fPool.size(); ++i)
96  {
97  fPool[i] = 0; fActive[i] = false;
98  }
99 }
100 
101 // ***************************************************************************
102 // Return the pointer of the first available collection of levels
103 // If none are available (i.e. non active) allocate collection
104 // ***************************************************************************
105 //
106 std::vector<G4NavigationLevel> * G4NavigationHistoryPool::GetLevels()
107 {
108  std::vector<G4bool>::iterator
109  pos = std::find(fActive.begin(), fActive.end(), false);
110  if (pos != fActive.end())
111  {
112  *pos = true;
113  return fPool[pos-fActive.begin()];
114  }
115  return GetNewLevels();
116 }
117 
118 // ***************************************************************************
119 // Return ptr to Store, setting if necessary
120 // ***************************************************************************
121 //
123 {
124  if (!fgInstance)
125  {
127  }
128  return fgInstance;
129 }
std::vector< G4NavigationLevel > * GetNewLevels()
#define G4ThreadLocal
Definition: tls.hh:89
static G4ThreadLocal G4NavigationHistoryPool * fgInstance
G4GLOB_DLL std::ostream G4cout
std::vector< G4NavigationLevel > * GetLevels()
std::vector< std::vector< G4NavigationLevel > * > fPool
std::vector< G4bool > fActive
#define G4endl
Definition: G4ios.hh:61
static G4NavigationHistoryPool * GetInstance()
static const G4double pos