Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4PhysicalVolumeStore.cc
이 파일의 문서화 페이지로 가기
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: G4PhysicalVolumeStore.cc 103235 2017-03-22 15:53:48Z gcosmo $
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"
38 #include "G4PhysicalVolumeStore.hh"
39 #include "G4GeometryManager.hh"
40 #include "G4LogicalVolume.hh"
41 
42 // ***************************************************************************
43 // Static class variables
44 // ***************************************************************************
45 //
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(); // Delete all volumes in the store
68  G4VPhysicalVolume::Clean(); // Delete allocated sub-instance data
69 }
70 
71 // ***************************************************************************
72 // Delete all elements from the store
73 // ***************************************************************************
74 //
76 {
77  // Do nothing if geometry is closed
78  //
80  {
81  G4cout << "WARNING - Attempt to delete the physical volume store"
82  << " while geometry closed !" << G4endl;
83  return;
84  }
85 
86  // Locks store for deletion of volumes. De-registration will be
87  // performed at this stage. G4VPhysicalVolumes will not de-register
88  // themselves.
89  //
90  locked = true;
91 
92  size_t i=0;
94 
95 #ifdef G4GEOMETRY_VOXELDEBUG
96  G4cout << "Deleting Physical Volumes ... ";
97 #endif
98 
99  for(iterator pos=store->begin(); pos!=store->end(); pos++)
100  {
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);
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  {
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 }
const XML_Char * name
Definition: expat.h:151
virtual void NotifyDeRegistration()=0
static const G4double pos
static G4ThreadLocal G4bool locked
#define G4endl
Definition: G4ios.hh:61
static void Register(G4VPhysicalVolume *pSolid)
static void SetNotifier(G4VStoreNotifier *pNotifier)
void message(RunManager *runmanager)
Definition: ts_scorers.cc:72
G4VPhysicalVolume * GetVolume(const G4String &name, G4bool verbose=true) const
#define G4ThreadLocal
Definition: tls.hh:69
static void DeRegister(G4VPhysicalVolume *pSolid)
static G4ThreadLocal G4VStoreNotifier * fgNotifier
virtual void NotifyRegistration()=0
bool G4bool
Definition: G4Types.hh:79
G4LogicalVolume * GetMotherLogical() const
void RemoveDaughter(const G4VPhysicalVolume *p)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.hh:65
static G4bool IsGeometryClosed()
static G4PhysicalVolumeStore * GetInstance()
G4GLOB_DLL std::ostream G4cout
static G4PhysicalVolumeStore * fgInstance