ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4RegionStore.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file 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 // G4RegionStore implementation for singleton container
27 //
28 // 18.09.02, G.Cosmo - Initial version
29 // --------------------------------------------------------------------
30 
31 #include "G4Region.hh"
32 #include "G4RegionStore.hh"
33 #include "G4GeometryManager.hh"
34 #include "G4VPhysicalVolume.hh"
35 #include "G4PhysicalVolumeStore.hh"
36 
37 #include "G4ios.hh"
38 
39 // ***************************************************************************
40 // Static class variables
41 // ***************************************************************************
42 //
46 
47 // ***************************************************************************
48 // Protected constructor: Construct underlying container with
49 // initial size of 20 entries
50 // ***************************************************************************
51 //
53  : std::vector<G4Region*>()
54 {
55  reserve(20);
56 }
57 
58 // ***************************************************************************
59 // Destructor
60 // ***************************************************************************
61 //
63 {
64  Clean(); // Delete all regions in the store
65  G4Region::Clean(); // Delete allocated sub-instance data
66 }
67 
68 // ***************************************************************************
69 // Delete all regions from the store except for the world region
70 // ***************************************************************************
71 //
73 {
74  // Do nothing if geometry is closed
75  //
77  {
78  G4cout << "WARNING - Attempt to delete the region store"
79  << " while geometry closed !" << G4endl;
80  return;
81  }
82 
83  // Locks store for deletion of regions. De-registration will be
84  // performed at this stage. G4Regions will not de-register themselves.
85  //
86  locked = true;
87 
88  size_t i=0;
89  G4RegionStore* store = GetInstance();
90 
91 #ifdef G4GEOMETRY_VOXELDEBUG
92  G4cout << "Deleting Regions ... ";
93 #endif
94 
95  for(auto pos=store->cbegin(); pos!=store->cend(); ++pos)
96  {
97  if (fgNotifier != nullptr) { fgNotifier->NotifyDeRegistration(); }
98  delete *pos; ++i;
99  }
100 
101 #ifdef G4GEOMETRY_VOXELDEBUG
102  if (store->size() < i-1)
103  { G4cout << "No regions deleted. Already deleted by user ?" << G4endl; }
104  else
105  { G4cout << i-1 << " regions deleted !" << G4endl; }
106 #endif
107 
108  locked = false;
109  store->clear();
110 }
111 
112 // ***************************************************************************
113 // Associate user notifier to the store
114 // ***************************************************************************
115 //
117 {
118  GetInstance();
119  fgNotifier = pNotifier;
120 }
121 
122 // ***************************************************************************
123 // Add Region to container
124 // ***************************************************************************
125 //
127 {
128  GetInstance()->push_back(pRegion);
130 }
131 
132 // ***************************************************************************
133 // Remove Region from container
134 // ***************************************************************************
135 //
137 {
138  if (!locked) // Do not de-register if locked !
139  {
140  if (fgNotifier != nullptr) { fgNotifier->NotifyDeRegistration(); }
141  for (auto i=GetInstance()->cbegin(); i!=GetInstance()->cend(); ++i)
142  {
143  if (**i==*pRegion)
144  {
145  GetInstance()->erase(i);
146  break;
147  }
148  }
149  }
150 }
151 
152 // ***************************************************************************
153 // Return ptr to Store, setting if necessary
154 // ***************************************************************************
155 //
157 {
158  static G4RegionStore worldStore;
159  if (fgInstance == nullptr)
160  {
161  fgInstance = &worldStore;
162  }
163  return fgInstance;
164 }
165 
166 // ***************************************************************************
167 // Loops through all regions to verify if a region has been modified.
168 // It returns TRUE if just one region is modified.
169 // ***************************************************************************
170 //
172 {
173  for (auto i=GetInstance()->cbegin(); i!=GetInstance()->cend(); ++i)
174  {
175  if ((*i)->IsModified()) { return true; }
176  }
177  return false;
178 }
179 
180 // ***************************************************************************
181 // Loops through all regions to reset flag for modification to FALSE.
182 // Used by the run manager to notify that the physics table has been updated.
183 // ***************************************************************************
184 //
186 {
187  for (auto i=GetInstance()->cbegin(); i!=GetInstance()->cend(); ++i)
188  {
189  (*i)->RegionModified(false);
190  }
191 }
192 
193 // ***************************************************************************
194 // Forces recomputation of material lists in all regions in the store.
195 // ***************************************************************************
196 //
198 {
199  for (auto i=GetInstance()->cbegin(); i!=GetInstance()->cend(); ++i)
200  {
201  if((*i)->IsInMassGeometry() || (*i)->IsInParallelGeometry()
202  || (currentWorld != nullptr))
203  { (*i)->UpdateMaterialList(); }
204  }
205 }
206 
207 // ***************************************************************************
208 // Returns a region through its name specification.
209 // ***************************************************************************
210 //
212 {
213  for (auto i=GetInstance()->cbegin(); i!=GetInstance()->cend(); ++i)
214  {
215  if ((*i)->GetName() == name) { return *i; }
216  }
217  if (verbose)
218  {
219  std::ostringstream message;
220  message << "Region NOT found in store !" << G4endl
221  << " Region " << name << " NOT found in store !" << G4endl
222  << " Returning NULL pointer.";
223  G4Exception("G4RegionStore::GetRegion()",
224  "GeomMgt1001", JustWarning, message);
225  }
226  return 0;
227 }
228 
229 // ***************************************************************************
230 // Returns a region through its name specification, if it exists.
231 // If it does not exist it will allocate a new region with the given
232 // name, delegating the ownership to the caller client.
233 // ***************************************************************************
234 //
236 {
237  G4Region* target = GetRegion(name,false);
238  if (target == nullptr)
239  {
240  target = new G4Region(name);
241  }
242  return target;
243 }
244 
245 // **************************************************************************
246 // Set a world physical volume pointer to a region that belongs to it.
247 // Scan over all world volumes.
248 // **************************************************************************
249 //
251 {
252  // Reset all pointers first
253  //
254  for (auto i=GetInstance()->cbegin(); i!=GetInstance()->cend(); ++i)
255  { (*i)->SetWorld(nullptr); }
256 
257  // Find world volumes
258  //
259  G4PhysicalVolumeStore* fPhysicalVolumeStore
261  size_t nPhys = fPhysicalVolumeStore->size();
262  for(size_t iPhys=0; iPhys<nPhys; ++iPhys)
263  {
264  G4VPhysicalVolume* fPhys = (*fPhysicalVolumeStore)[iPhys];
265  if(fPhys->GetMotherLogical() != nullptr) { continue; } // not a world volume
266 
267  // Now 'fPhys' is a world volume, set it to regions that belong to it.
268  //
269  for (auto i=GetInstance()->cbegin(); i!=GetInstance()->cend(); ++i)
270  { (*i)->SetWorld(fPhys); }
271  }
272 }
273