Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4PhysicalVolumeStore.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// G4PhysicalVolumeStore
30//
31// Implementation for singleton container
32//
33// History:
34// 25.07.95 P.Kent Initial version
35// --------------------------------------------------------------------
36
37#include "G4Types.hh"
39#include "G4GeometryManager.hh"
40#include "G4LogicalVolume.hh"
41
42// ***************************************************************************
43// Static class variables
44// ***************************************************************************
45//
46G4PhysicalVolumeStore* G4PhysicalVolumeStore::fgInstance = 0;
47G4VStoreNotifier* G4PhysicalVolumeStore::fgNotifier = 0;
48G4bool G4PhysicalVolumeStore::locked = false;
49
50// ***************************************************************************
51// Protected constructor: Construct underlying container with
52// initial size of 100 entries
53// ***************************************************************************
54//
56 : std::vector<G4VPhysicalVolume*>()
57{
58 reserve(100);
59}
60
61// ***************************************************************************
62// Destructor
63// ***************************************************************************
64//
66{
67 Clean();
68}
69
70// ***************************************************************************
71// Delete all elements from the store
72// ***************************************************************************
73//
75{
76 // Do nothing if geometry is closed
77 //
78 if (G4GeometryManager::GetInstance()->IsGeometryClosed())
79 {
80 G4cout << "WARNING - Attempt to delete the physical volume store"
81 << " while geometry closed !" << G4endl;
82 return;
83 }
84
85 // Locks store for deletion of volumes. De-registration will be
86 // performed at this stage. G4VPhysicalVolumes will not de-register
87 // themselves.
88 //
89 locked = true;
90
91 size_t i=0;
93 std::vector<G4VPhysicalVolume*>::iterator pos;
94
95#ifdef G4GEOMETRY_VOXELDEBUG
96 G4cout << "Deleting Physical Volumes ... ";
97#endif
98
99 for(pos=store->begin(); pos!=store->end(); pos++)
100 {
101 if (fgNotifier) { fgNotifier->NotifyDeRegistration(); }
102 if (*pos) { delete *pos; }
103 i++;
104 }
105
106#ifdef G4GEOMETRY_VOXELDEBUG
107 if (store->size() < i-1)
108 { G4cout << "No volumes deleted. Already deleted by user ?" << G4endl; }
109 else
110 { G4cout << i-1 << " volumes deleted !" << G4endl; }
111#endif
112
113 locked = false;
114 store->clear();
115}
116
117// ***************************************************************************
118// Associate user notifier to the store
119// ***************************************************************************
120//
122{
123 GetInstance();
124 fgNotifier = pNotifier;
125}
126
127// ***************************************************************************
128// Add Volume to container
129// ***************************************************************************
130//
132{
133 GetInstance()->push_back(pVolume);
134 if (fgNotifier) { fgNotifier->NotifyRegistration(); }
135}
136
137// ***************************************************************************
138// Remove Volume from container and update the list of daughters
139// of the mother's logical volume
140// ***************************************************************************
141//
143{
144 if (!locked) // Do not de-register if locked !
145 {
146 if (fgNotifier) { fgNotifier->NotifyDeRegistration(); }
147 G4LogicalVolume* motherLogical = pVolume->GetMotherLogical();
148 if (motherLogical) { motherLogical->RemoveDaughter(pVolume); }
149 for (iterator i=GetInstance()->begin(); i!=GetInstance()->end(); i++)
150 {
151 if (**i==*pVolume)
152 {
153 GetInstance()->erase(i);
154 break;
155 }
156 }
157 }
158}
159
160// ***************************************************************************
161// Retrieve the first volume pointer in the container having that name
162// ***************************************************************************
163//
166{
167 for (iterator i=GetInstance()->begin(); i!=GetInstance()->end(); i++)
168 {
169 if ((*i)->GetName() == name) { return *i; }
170 }
171 if (verbose)
172 {
173 std::ostringstream message;
174 message << "Volume NOT found in store !" << G4endl
175 << " Volume " << name << " NOT found in store !" << G4endl
176 << " Returning NULL pointer.";
177 G4Exception("G4PhysicalVolumeStore::GetVolume()",
178 "GeomMgt1001", JustWarning, message);
179 }
180 return 0;
181}
182
183// ***************************************************************************
184// Return ptr to Store, setting if necessary
185// ***************************************************************************
186//
188{
189 static G4PhysicalVolumeStore worldStore;
190 if (!fgInstance)
191 {
192 fgInstance = &worldStore;
193 }
194 return fgInstance;
195}
@ JustWarning
bool G4bool
Definition: G4Types.hh:67
#define G4endl
Definition: G4ios.hh:52
G4DLLIMPORT std::ostream G4cout
static G4GeometryManager * GetInstance()
void RemoveDaughter(const G4VPhysicalVolume *p)
static G4PhysicalVolumeStore * GetInstance()
G4VPhysicalVolume * GetVolume(const G4String &name, G4bool verbose=true) const
static void Register(G4VPhysicalVolume *pSolid)
static void SetNotifier(G4VStoreNotifier *pNotifier)
static void DeRegister(G4VPhysicalVolume *pSolid)
virtual void NotifyRegistration()=0
virtual void NotifyDeRegistration()=0
G4LogicalVolume * GetMotherLogical() const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41