Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4RegionStore.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: G4RegionStore.cc 103235 2017-03-22 15:53:48Z gcosmo $
28 //
29 // G4RegionStore
30 //
31 // Implementation for singleton container
32 //
33 // History:
34 // 18.09.02 G.Cosmo Initial version
35 // --------------------------------------------------------------------
36 
37 #include "G4Region.hh"
38 #include "G4RegionStore.hh"
39 #include "G4GeometryManager.hh"
40 #include "G4VPhysicalVolume.hh"
41 #include "G4PhysicalVolumeStore.hh"
42 
43 #include "G4ios.hh"
44 
45 // ***************************************************************************
46 // Static class variables
47 // ***************************************************************************
48 //
52 
53 // ***************************************************************************
54 // Protected constructor: Construct underlying container with
55 // initial size of 20 entries
56 // ***************************************************************************
57 //
59  : std::vector<G4Region*>()
60 {
61  reserve(20);
62 }
63 
64 // ***************************************************************************
65 // Destructor
66 // ***************************************************************************
67 //
69 {
70  Clean(); // Delete all regions in the store
71  G4Region::Clean(); // Delete allocated sub-instance data
72 }
73 
74 // ***************************************************************************
75 // Delete all regions from the store except for the world region
76 // ***************************************************************************
77 //
79 {
80  // Do nothing if geometry is closed
81  //
83  {
84  G4cout << "WARNING - Attempt to delete the region store"
85  << " while geometry closed !" << G4endl;
86  return;
87  }
88 
89  // Locks store for deletion of regions. De-registration will be
90  // performed at this stage. G4Regions will not de-register themselves.
91  //
92  locked = true;
93 
94  size_t i=0;
95  G4RegionStore* store = GetInstance();
96 
97 #ifdef G4GEOMETRY_VOXELDEBUG
98  G4cout << "Deleting Regions ... ";
99 #endif
100 
101  for(iterator pos=store->begin(); pos!=store->end(); ++pos)
102  {
104  if (*pos) { delete *pos; }
105  i++;
106  }
107 
108 #ifdef G4GEOMETRY_VOXELDEBUG
109  if (store->size() < i-1)
110  { G4cout << "No regions deleted. Already deleted by user ?" << G4endl; }
111  else
112  { G4cout << i-1 << " regions deleted !" << G4endl; }
113 #endif
114 
115  locked = false;
116  store->clear();
117 }
118 
119 // ***************************************************************************
120 // Associate user notifier to the store
121 // ***************************************************************************
122 //
124 {
125  GetInstance();
126  fgNotifier = pNotifier;
127 }
128 
129 // ***************************************************************************
130 // Add Region to container
131 // ***************************************************************************
132 //
134 {
135  GetInstance()->push_back(pRegion);
137 }
138 
139 // ***************************************************************************
140 // Remove Region from container
141 // ***************************************************************************
142 //
144 {
145  if (!locked) // Do not de-register if locked !
146  {
148  for (iterator i=GetInstance()->begin(); i!=GetInstance()->end(); i++)
149  {
150  if (**i==*pRegion)
151  {
152  GetInstance()->erase(i);
153  break;
154  }
155  }
156  }
157 }
158 
159 // ***************************************************************************
160 // Return ptr to Store, setting if necessary
161 // ***************************************************************************
162 //
164 {
165  static G4RegionStore worldStore;
166  if (!fgInstance)
167  {
168  fgInstance = &worldStore;
169  }
170  return fgInstance;
171 }
172 
173 // ***************************************************************************
174 // Loops through all regions to verify if a region has been modified.
175 // It returns TRUE if just one region is modified.
176 // ***************************************************************************
177 //
179 {
180  for (iterator i=GetInstance()->begin(); i!=GetInstance()->end(); i++)
181  {
182  if ((*i)->IsModified()) { return true; }
183  }
184  return false;
185 }
186 
187 // ***************************************************************************
188 // Loops through all regions to reset flag for modification to FALSE.
189 // Used by the run manager to notify that the physics table has been updated.
190 // ***************************************************************************
191 //
193 {
194  for (iterator i=GetInstance()->begin(); i!=GetInstance()->end(); i++)
195  {
196  (*i)->RegionModified(false);
197  }
198 }
199 
200 // ***************************************************************************
201 // Forces recomputation of material lists in all regions in the store.
202 // ***************************************************************************
203 //
205 {
206  for (iterator i=GetInstance()->begin(); i!=GetInstance()->end(); i++)
207  {
208  if((*i)->IsInMassGeometry() || (*i)->IsInParallelGeometry() || currentWorld)
209  { (*i)->UpdateMaterialList(); }
210  }
211 }
212 
213 // ***************************************************************************
214 // Returns a region through its name specification.
215 // ***************************************************************************
216 //
218 {
219  for (iterator i=GetInstance()->begin(); i!=GetInstance()->end(); i++)
220  {
221  if ((*i)->GetName() == name) { return *i; }
222  }
223  if (verbose)
224  {
225  std::ostringstream message;
226  message << "Region NOT found in store !" << G4endl
227  << " Region " << name << " NOT found in store !" << G4endl
228  << " Returning NULL pointer.";
229  G4Exception("G4RegionStore::GetRegion()",
230  "GeomMgt1001", JustWarning, message);
231  }
232  return 0;
233 }
234 
235 // ***************************************************************************
236 // Returns a region through its name specification, if it exists.
237 // If it does not exist it will allocate a new region with the given
238 // name, delegating the ownership to the caller client.
239 // ***************************************************************************
240 //
242 {
243  G4Region* target = GetRegion(name,false);
244  if (!target)
245  {
246  target = new G4Region(name);
247  }
248  return target;
249 }
250 
251 // **************************************************************************
252 // Set a world physical volume pointer to a region that belongs to it.
253 // Scan over all world volumes.
254 // **************************************************************************
255 //
257 {
258  // Reset all pointers first
259  //
260  for (iterator i=GetInstance()->begin(); i!=GetInstance()->end(); i++)
261  { (*i)->SetWorld(0); }
262 
263  // Find world volumes
264  //
265  G4PhysicalVolumeStore* fPhysicalVolumeStore
267  size_t nPhys = fPhysicalVolumeStore->size();
268  for(size_t iPhys=0; iPhys<nPhys; iPhys++)
269  {
270  G4VPhysicalVolume* fPhys = (*fPhysicalVolumeStore)[iPhys];
271  if(fPhys->GetMotherLogical()) { continue; } // not a world volume
272 
273  // Now 'fPhys' is a world volume, set it to regions that belong to it.
274  //
275  for (iterator i=GetInstance()->begin(); i!=GetInstance()->end(); i++)
276  { (*i)->SetWorld(fPhys); }
277  }
278 }
279 
const XML_Char * name
Definition: expat.h:151
virtual void NotifyDeRegistration()=0
static const G4double pos
const XML_Char * target
Definition: expat.h:268
#define G4endl
Definition: G4ios.hh:61
void message(RunManager *runmanager)
Definition: ts_scorers.cc:72
static G4ThreadLocal G4VStoreNotifier * fgNotifier
void SetWorldVolume()
#define G4ThreadLocal
Definition: tls.hh:69
void UpdateMaterialList(G4VPhysicalVolume *currentWorld=0)
G4Region * GetRegion(const G4String &name, G4bool verbose=true) const
virtual void NotifyRegistration()=0
bool G4bool
Definition: G4Types.hh:79
static void Clean()
Definition: G4Region.cc:348
G4LogicalVolume * GetMotherLogical() const
virtual ~G4RegionStore()
static void SetNotifier(G4VStoreNotifier *pNotifier)
static void Register(G4Region *pRegion)
G4bool IsModified() const
static G4ThreadLocal G4bool locked
static G4RegionStore * fgInstance
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.hh:65
static G4bool IsGeometryClosed()
static G4PhysicalVolumeStore * GetInstance()
static G4RegionStore * GetInstance()
static void DeRegister(G4Region *pRegion)
void ResetRegionModified()
G4GLOB_DLL std::ostream G4cout
static void Clean()
G4Region * FindOrCreateRegion(const G4String &name)