Geant4  10.03
G4SolidStore.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: G4SolidStore.cc 67975 2013-03-13 10:19:44Z gcosmo $
28 //
29 // G4SolidStore
30 //
31 // Implementation for singleton container
32 //
33 // History:
34 // 10.07.95 P.Kent Initial version
35 // --------------------------------------------------------------------
36 
37 #include "globals.hh"
38 #include "G4SolidStore.hh"
39 #include "G4GeometryManager.hh"
40 
41 // ***************************************************************************
42 // Static class variables
43 // ***************************************************************************
44 //
48 
49 // ***************************************************************************
50 // Protected constructor: Construct underlying container with
51 // initial size of 100 entries
52 // ***************************************************************************
53 //
55  : std::vector<G4VSolid*>()
56 {
57  reserve(100);
58 }
59 
60 // ***************************************************************************
61 // Destructor
62 // ***************************************************************************
63 //
65 {
66  // In multi-threaded mode, since parameterised solids are replicated
67  // by threads, the master thread can not free them when thread private
68  // malloc library is used. May let the master thread to replicate.
69 
70 #ifndef G4MULTITHREADED
71  Clean();
72 #endif
73 }
74 
75 // ***************************************************************************
76 // Delete all elements from the store
77 // ***************************************************************************
78 //
80 {
81  // Do nothing if geometry is closed
82  //
83  if (G4GeometryManager::GetInstance()->IsGeometryClosed())
84  {
85  G4cout << "WARNING - Attempt to delete the solid store"
86  << " while geometry closed !" << G4endl;
87  return;
88  }
89 
90  // Locks store for deletion of solids. De-registration will be
91  // performed at this stage. G4VSolids will not de-register themselves.
92  //
93  locked = true;
94 
95  size_t i=0;
96  G4SolidStore* store = GetInstance();
97 
98 #ifdef G4GEOMETRY_VOXELDEBUG
99  G4cout << "Deleting Solids ... ";
100 #endif
101 
102  for(iterator pos=store->begin(); pos!=store->end(); pos++)
103  {
105  if (*pos) { delete *pos; }
106  i++;
107  }
108 
109 #ifdef G4GEOMETRY_VOXELDEBUG
110  if (store->size() < i-1)
111  { G4cout << "No solids deleted. Already deleted by user ?" << G4endl; }
112  else
113  { G4cout << i-1 << " solids deleted !" << G4endl; }
114 #endif
115 
116  locked = false;
117  store->clear();
118 }
119 
120 // ***************************************************************************
121 // Associate user notifier to the store
122 // ***************************************************************************
123 //
125 {
126  GetInstance();
127  fgNotifier = pNotifier;
128 }
129 
130 // ***************************************************************************
131 // Add Solid to container
132 // ***************************************************************************
133 //
135 {
136  GetInstance()->push_back(pSolid);
138 }
139 
140 // ***************************************************************************
141 // Remove Solid from container
142 // ***************************************************************************
143 //
145 {
146  if (!locked) // Do not de-register if locked !
147  {
149  for (iterator i=GetInstance()->begin(); i!=GetInstance()->end(); i++)
150  {
151  if (**i==*pSolid)
152  {
153  GetInstance()->erase(i);
154  break;
155  }
156  }
157  }
158 }
159 
160 // ***************************************************************************
161 // Retrieve the first solid pointer in the container having that name
162 // ***************************************************************************
163 //
165 {
166  for (iterator i=GetInstance()->begin(); i!=GetInstance()->end(); i++)
167  {
168  if ((*i)->GetName() == name) { return *i; }
169  }
170  if (verbose)
171  {
172  std::ostringstream message;
173  message << "Solid " << name << " not found in store !" << G4endl
174  << "Returning NULL pointer.";
175  G4Exception("G4SolidStore::GetSolid()",
176  "GeomMgt1001", JustWarning, message);
177  }
178  return 0;
179 }
180 
181 // ***************************************************************************
182 // Return ptr to Store, setting if necessary
183 // ***************************************************************************
184 //
186 {
187  static G4SolidStore worldStore;
188  if (!fgInstance)
189  {
190  fgInstance = &worldStore;
191  }
192  return fgInstance;
193 }
G4VSolid * GetSolid(const G4String &name, G4bool verbose=true) const
static void SetNotifier(G4VStoreNotifier *pNotifier)
virtual void NotifyDeRegistration()=0
static void Register(G4VSolid *pSolid)
static void DeRegister(G4VSolid *pSolid)
static G4ThreadLocal G4VStoreNotifier * fgNotifier
Definition: G4SolidStore.hh:91
static void Clean()
Definition: G4SolidStore.cc:79
const char * name(G4int ptype)
#define G4ThreadLocal
Definition: tls.hh:89
G4GLOB_DLL std::ostream G4cout
bool G4bool
Definition: G4Types.hh:79
static G4SolidStore * GetInstance()
static G4GeometryManager * GetInstance()
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
static G4ThreadLocal G4bool locked
Definition: G4SolidStore.hh:92
static G4SolidStore * fgInstance
Definition: G4SolidStore.hh:90
#define G4endl
Definition: G4ios.hh:61
virtual void NotifyRegistration()=0
static const G4double pos
virtual ~G4SolidStore()
Definition: G4SolidStore.cc:64