source: trunk/source/geometry/magneticfield/src/G4FieldManagerStore.cc@ 1313

Last change on this file since 1313 was 1231, checked in by garnier, 16 years ago

update from CVS

File size: 5.4 KB
RevLine 
[831]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,v 1.4 2008/01/17 10:56:23 gcosmo Exp $
[1231]28// GEANT4 tag $Name: $
[831]29//
30// G4FieldManagerStore
31//
32// Implementation for singleton container
33//
34// History:
35// 07.12.07 J.Apostolakis Adapted from G4LogicalVolumeStore
36// --------------------------------------------------------------------
37
38#include "G4Types.hh"
39#include "G4FieldManagerStore.hh"
40#include "G4ChordFinder.hh"
41
42// ***************************************************************************
43// Static class variables
44// ***************************************************************************
45//
46G4FieldManagerStore* G4FieldManagerStore::fgInstance = 0;
47G4bool G4FieldManagerStore::locked = false;
48
49// ***************************************************************************
50// Protected constructor: Construct underlying container with
51// initial size of 100 entries
52// ***************************************************************************
53//
54G4FieldManagerStore::G4FieldManagerStore()
55 : std::vector<G4FieldManager*>()
56{
57 reserve(100);
58}
59
60// ***************************************************************************
61// Destructor
62// ***************************************************************************
63//
64G4FieldManagerStore::~G4FieldManagerStore()
65{
66 Clean();
67}
68
69// ***************************************************************************
70// Delete all elements from the store
71// ***************************************************************************
72//
73void G4FieldManagerStore::Clean()
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;
81 G4FieldManagerStore* store = GetInstance();
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//
104void G4FieldManagerStore::Register(G4FieldManager* pFieldManager)
105{
106 GetInstance()->push_back(pFieldManager);
107}
108
109// ***************************************************************************
110// Remove volume from container
111// ***************************************************************************
112//
113void G4FieldManagerStore::DeRegister(G4FieldManager* pFieldMgr)
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//
132G4FieldManagerStore* G4FieldManagerStore::GetInstance()
133{
134 static G4FieldManagerStore worldStore;
135 if (!fgInstance)
136 {
137 fgInstance = &worldStore;
138 }
139 return fgInstance;
140}
141
142// ***************************************************************************
143// Globally reset the state
144// ***************************************************************************
145//
146void
147G4FieldManagerStore::ClearAllChordFindersState()
148{
149 G4ChordFinder *pChordFnd;
150
151 for (iterator i=GetInstance()->begin(); i!=GetInstance()->end(); i++)
152 {
153 pChordFnd = (*i)->GetChordFinder();
154 if( pChordFnd )
155 {
156 pChordFnd->ResetStepEstimate();
157 }
158 }
159}
Note: See TracBrowser for help on using the repository browser.