Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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$
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//
45G4SolidStore* G4SolidStore::fgInstance = 0;
46G4VStoreNotifier* G4SolidStore::fgNotifier = 0;
47G4bool G4SolidStore::locked = false;
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 Clean();
67}
68
69// ***************************************************************************
70// Delete all elements from the store
71// ***************************************************************************
72//
74{
75 // Do nothing if geometry is closed
76 //
77 if (G4GeometryManager::GetInstance()->IsGeometryClosed())
78 {
79 G4cout << "WARNING - Attempt to delete the solid store"
80 << " while geometry closed !" << G4endl;
81 return;
82 }
83
84 // Locks store for deletion of solids. De-registration will be
85 // performed at this stage. G4VSolids will not de-register themselves.
86 //
87 locked = true;
88
89 size_t i=0;
90 G4SolidStore* store = GetInstance();
91
92#ifdef G4GEOMETRY_VOXELDEBUG
93 G4cout << "Deleting Solids ... ";
94#endif
95
96 for(iterator pos=store->begin(); pos!=store->end(); pos++)
97 {
98 if (fgNotifier) { fgNotifier->NotifyDeRegistration(); }
99 if (*pos) { delete *pos; }
100 i++;
101 }
102
103#ifdef G4GEOMETRY_VOXELDEBUG
104 if (store->size() < i-1)
105 { G4cout << "No solids deleted. Already deleted by user ?" << G4endl; }
106 else
107 { G4cout << i-1 << " solids deleted !" << G4endl; }
108#endif
109
110 locked = false;
111 store->clear();
112}
113
114// ***************************************************************************
115// Associate user notifier to the store
116// ***************************************************************************
117//
119{
120 GetInstance();
121 fgNotifier = pNotifier;
122}
123
124// ***************************************************************************
125// Add Solid to container
126// ***************************************************************************
127//
129{
130 GetInstance()->push_back(pSolid);
131 if (fgNotifier) { fgNotifier->NotifyRegistration(); }
132}
133
134// ***************************************************************************
135// Remove Solid from container
136// ***************************************************************************
137//
139{
140 if (!locked) // Do not de-register if locked !
141 {
142 if (fgNotifier) { fgNotifier->NotifyDeRegistration(); }
143 for (iterator i=GetInstance()->begin(); i!=GetInstance()->end(); i++)
144 {
145 if (**i==*pSolid)
146 {
147 GetInstance()->erase(i);
148 break;
149 }
150 }
151 }
152}
153
154// ***************************************************************************
155// Retrieve the first solid pointer in the container having that name
156// ***************************************************************************
157//
158G4VSolid* G4SolidStore::GetSolid(const G4String& name, G4bool verbose) const
159{
160 for (iterator i=GetInstance()->begin(); i!=GetInstance()->end(); i++)
161 {
162 if ((*i)->GetName() == name) { return *i; }
163 }
164 if (verbose)
165 {
166 std::ostringstream message;
167 message << "Solid " << name << " not found in store !" << G4endl
168 << "Returning NULL pointer.";
169 G4Exception("G4SolidStore::GetSolid()",
170 "GeomMgt1001", JustWarning, message);
171 }
172 return 0;
173}
174
175// ***************************************************************************
176// Return ptr to Store, setting if necessary
177// ***************************************************************************
178//
180{
181 static G4SolidStore worldStore;
182 if (!fgInstance)
183 {
184 fgInstance = &worldStore;
185 }
186 return fgInstance;
187}
@ JustWarning
bool G4bool
Definition: G4Types.hh:67
#define G4endl
Definition: G4ios.hh:52
G4DLLIMPORT std::ostream G4cout
static G4GeometryManager * GetInstance()
static void Register(G4VSolid *pSolid)
static void Clean()
Definition: G4SolidStore.cc:73
static void SetNotifier(G4VStoreNotifier *pNotifier)
static void DeRegister(G4VSolid *pSolid)
G4VSolid * GetSolid(const G4String &name, G4bool verbose=true) const
static G4SolidStore * GetInstance()
virtual ~G4SolidStore()
Definition: G4SolidStore.cc:64
virtual void NotifyRegistration()=0
virtual void NotifyDeRegistration()=0
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41