Geant4  10.01
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 #ifdef G4VERBOSE
74  G4cout << "Total navigation history collections cleaned: "
75  << fPool.size() << G4endl;
76 #endif
77  fPool.clear();
78  fActive.clear();
79 }
80 
81 // ***************************************************************************
82 // Delete all elements from the pool
83 // ***************************************************************************
84 //
86 {
87  for(size_t i=0; i<fPool.size(); ++i)
88  {
89  fPool[i] = 0; fActive[i] = false;
90  }
91 }
92 
93 // ***************************************************************************
94 // Return the pointer of the first available collection of levels
95 // If none are available (i.e. non active) allocate collection
96 // ***************************************************************************
97 //
98 std::vector<G4NavigationLevel> * G4NavigationHistoryPool::GetLevels()
99 {
100  std::vector<G4bool>::iterator
101  pos = std::find(fActive.begin(), fActive.end(), false);
102  if (pos != fActive.end())
103  {
104  *pos = true;
105  return fPool[pos-fActive.begin()];
106  }
107  return GetNewLevels();
108 }
109 
110 // ***************************************************************************
111 // Return ptr to Store, setting if necessary
112 // ***************************************************************************
113 //
115 {
116  if (!fgInstance)
117  {
119  }
120  return fgInstance;
121 }
std::vector< G4NavigationLevel > * GetNewLevels()
#define G4ThreadLocal
Definition: tls.hh:84
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