Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4FieldManagerStore.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: G4FieldManagerStore.cc 69589 2013-05-08 14:35:28Z gcosmo $
28 //
29 // G4FieldManagerStore
30 //
31 // Implementation for singleton container
32 //
33 // History:
34 // 07.12.07 J.Apostolakis Adapted from G4LogicalVolumeStore
35 // --------------------------------------------------------------------
36 
37 #include "G4Types.hh"
38 #include "G4FieldManagerStore.hh"
39 #include "G4ChordFinder.hh"
40 
41 // ***************************************************************************
42 // Static class variables
43 // ***************************************************************************
44 //
45 G4ThreadLocal G4FieldManagerStore* G4FieldManagerStore::fgInstance = 0;
46 G4ThreadLocal G4bool G4FieldManagerStore::locked = false;
47 
48 // ***************************************************************************
49 // Protected constructor: Construct underlying container with
50 // initial size of 100 entries
51 // ***************************************************************************
52 //
54  : std::vector<G4FieldManager*>()
55 {
56  reserve(100);
57 }
58 
59 // ***************************************************************************
60 // Destructor
61 // ***************************************************************************
62 //
64 {
65  Clean();
66  if (fgInstance) { delete fgInstance; fgInstance=0; }
67 }
68 
69 // ***************************************************************************
70 // Delete all elements from the store
71 // ***************************************************************************
72 //
74 {
75  // Locks store for deletion of field managers. De-registration will be
76  // performed at this stage. G4FieldManagers will not de-register themselves.
77  //
78  locked = true;
79 
80  size_t i=0;
82 
83  for(iterator pos=store->begin(); pos!=store->end(); pos++)
84  {
85  if (*pos) { delete *pos; }
86  i++;
87  }
88 
89 #ifdef G4GEOMETRY_DEBUG
90  if (store->size() < i-1)
91  { G4cout << "No field managers deleted. Already deleted by user ?" << G4endl; }
92  else
93  { G4cout << i-1 << " field managers deleted !" << G4endl; }
94 #endif
95 
96  locked = false;
97  store->clear();
98 }
99 
100 // ***************************************************************************
101 // Add field manager to container
102 // ***************************************************************************
103 //
105 {
106  GetInstance()->push_back(pFieldManager);
107 }
108 
109 // ***************************************************************************
110 // Remove volume from container
111 // ***************************************************************************
112 //
114 {
115  if (!locked) // Do not de-register if locked !
116  {
117  for (iterator i=GetInstance()->begin(); i!=GetInstance()->end(); i++)
118  {
119  if (*i==pFieldMgr) // For LogVol was **i == *pLogVolume ... Reason?
120  {
121  GetInstance()->erase(i);
122  break;
123  }
124  }
125  }
126 }
127 
128 // ***************************************************************************
129 // Return ptr to Store, setting if necessary
130 // ***************************************************************************
131 //
133 {
134  if (!fgInstance)
135  {
136  fgInstance = new G4FieldManagerStore;
137  }
138  return fgInstance;
139 }
140 
141 // ***************************************************************************
142 // Globally reset the state
143 // ***************************************************************************
144 //
145 void
147 {
148  G4ChordFinder *pChordFnd;
149 
150  for (iterator i=GetInstance()->begin(); i!=GetInstance()->end(); i++)
151  {
152  pChordFnd = (*i)->GetChordFinder();
153  if( pChordFnd )
154  {
155  pChordFnd->ResetStepEstimate();
156  }
157  }
158 }
#define G4ThreadLocal
Definition: tls.hh:89
G4GLOB_DLL std::ostream G4cout
bool G4bool
Definition: G4Types.hh:79
static G4FieldManagerStore * GetInstance()
static void Register(G4FieldManager *pVolume)
#define G4endl
Definition: G4ios.hh:61
static void DeRegister(G4FieldManager *pVolume)
static const G4double pos
void ResetStepEstimate()