Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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$
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"
39#include "G4ChordFinder.hh"
40
41// ***************************************************************************
42// Static class variables
43// ***************************************************************************
44//
45G4FieldManagerStore* G4FieldManagerStore::fgInstance = 0;
46G4bool 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}
67
68// ***************************************************************************
69// Delete all elements from the store
70// ***************************************************************************
71//
73{
74 // Locks store for deletion of field managers. De-registration will be
75 // performed at this stage. G4FieldManagers will not de-register themselves.
76 //
77 locked = true;
78
79 size_t i=0;
81
82 for(iterator pos=store->begin(); pos!=store->end(); pos++)
83 {
84 if (*pos) { delete *pos; }
85 i++;
86 }
87
88#ifdef G4GEOMETRY_DEBUG
89 if (store->size() < i-1)
90 { G4cout << "No field managers deleted. Already deleted by user ?" << G4endl; }
91 else
92 { G4cout << i-1 << " field managers deleted !" << G4endl; }
93#endif
94
95 locked = false;
96 store->clear();
97}
98
99// ***************************************************************************
100// Add field manager to container
101// ***************************************************************************
102//
104{
105 GetInstance()->push_back(pFieldManager);
106}
107
108// ***************************************************************************
109// Remove volume from container
110// ***************************************************************************
111//
113{
114 if (!locked) // Do not de-register if locked !
115 {
116 for (iterator i=GetInstance()->begin(); i!=GetInstance()->end(); i++)
117 {
118 if (*i==pFieldMgr) // For LogVol was **i == *pLogVolume ... Reason?
119 {
120 GetInstance()->erase(i);
121 break;
122 }
123 }
124 }
125}
126
127// ***************************************************************************
128// Return ptr to Store, setting if necessary
129// ***************************************************************************
130//
132{
133 static G4FieldManagerStore worldStore;
134 if (!fgInstance)
135 {
136 fgInstance = &worldStore;
137 }
138 return fgInstance;
139}
140
141// ***************************************************************************
142// Globally reset the state
143// ***************************************************************************
144//
145void
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}
bool G4bool
Definition: G4Types.hh:67
#define G4endl
Definition: G4ios.hh:52
G4DLLIMPORT std::ostream G4cout
void ResetStepEstimate()
static void DeRegister(G4FieldManager *pVolume)
static void Register(G4FieldManager *pVolume)
static G4FieldManagerStore * GetInstance()