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 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /geometry/management/src/G4RegionStore.cc (Version 11.3.0) and /geometry/management/src/G4RegionStore.cc (Version 10.2)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 // G4RegionStore implementation                << 
 27 //                                                 26 //
 28 // 18.09.02, G.Cosmo - Initial version         <<  27 // $Id: G4RegionStore.cc 66872 2013-01-15 01:25:57Z japost $
                                                   >>  28 //
                                                   >>  29 // G4RegionStore
                                                   >>  30 //
                                                   >>  31 // Implementation for singleton container
                                                   >>  32 //
                                                   >>  33 // History:
                                                   >>  34 // 18.09.02 G.Cosmo Initial version
 29 // -------------------------------------------     35 // --------------------------------------------------------------------
 30                                                    36 
 31 #include "G4Region.hh"                             37 #include "G4Region.hh"
 32 #include "G4RegionStore.hh"                        38 #include "G4RegionStore.hh"
 33 #include "G4GeometryManager.hh"                    39 #include "G4GeometryManager.hh"
 34 #include "G4VPhysicalVolume.hh"                    40 #include "G4VPhysicalVolume.hh"
 35 #include "G4PhysicalVolumeStore.hh"                41 #include "G4PhysicalVolumeStore.hh"
 36                                                    42 
 37 #include "G4ios.hh"                                43 #include "G4ios.hh"
 38 #include "G4AutoLock.hh"                       << 
 39                                                << 
 40 namespace                                      << 
 41 {                                              << 
 42   G4Mutex mapMutex = G4MUTEX_INITIALIZER;      << 
 43 }                                              << 
 44                                                    44 
 45 // *******************************************     45 // ***************************************************************************
 46 // Static class variables                          46 // Static class variables
 47 // *******************************************     47 // ***************************************************************************
 48 //                                                 48 //
 49 G4RegionStore* G4RegionStore::fgInstance = nul <<  49 G4RegionStore* G4RegionStore::fgInstance = 0;
 50 G4ThreadLocal G4VStoreNotifier* G4RegionStore: <<  50 G4ThreadLocal G4VStoreNotifier* G4RegionStore::fgNotifier = 0;
 51 G4ThreadLocal G4bool G4RegionStore::locked = f     51 G4ThreadLocal G4bool G4RegionStore::locked = false;
 52                                                    52 
 53 // *******************************************     53 // ***************************************************************************
 54 // Protected constructor: Construct underlying     54 // Protected constructor: Construct underlying container with
 55 // initial size of 20 entries                      55 // initial size of 20 entries
 56 // *******************************************     56 // ***************************************************************************
 57 //                                                 57 //
 58 G4RegionStore::G4RegionStore()                     58 G4RegionStore::G4RegionStore()
 59                                                <<  59   : std::vector<G4Region*>()
 60 {                                                  60 {
 61   reserve(20);                                     61   reserve(20);
 62 }                                                  62 }
 63                                                    63 
 64 // *******************************************     64 // ***************************************************************************
 65 // Destructor                                      65 // Destructor
 66 // *******************************************     66 // ***************************************************************************
 67 //                                                 67 //
 68 G4RegionStore::~G4RegionStore()                    68 G4RegionStore::~G4RegionStore() 
 69 {                                                  69 {
 70   Clean();  // Delete all regions in the store <<  70   Clean();
 71   G4Region::Clean();  // Delete allocated sub- << 
 72 }                                                  71 }
 73                                                    72 
 74 // *******************************************     73 // ***************************************************************************
 75 // Delete all regions from the store except fo     74 // Delete all regions from the store except for the world region
 76 // *******************************************     75 // ***************************************************************************
 77 //                                                 76 //
 78 void G4RegionStore::Clean()                        77 void G4RegionStore::Clean()
 79 {                                                  78 {
 80   // Do nothing if geometry is closed              79   // Do nothing if geometry is closed
 81   //                                               80   //
 82   if (G4GeometryManager::GetInstance()->IsGeom     81   if (G4GeometryManager::GetInstance()->IsGeometryClosed())
 83   {                                                82   {
 84     G4cout << "WARNING - Attempt to delete the     83     G4cout << "WARNING - Attempt to delete the region store"
 85            << " while geometry closed !" << G4     84            << " while geometry closed !" << G4endl;
 86     return;                                        85     return;
 87   }                                                86   }
 88                                                    87 
 89   // Locks store for deletion of regions. De-r     88   // Locks store for deletion of regions. De-registration will be
 90   // performed at this stage. G4Regions will n     89   // performed at this stage. G4Regions will not de-register themselves.
 91   //                                               90   //
 92   locked = true;                                   91   locked = true;  
 93                                                    92 
                                                   >>  93   size_t i=0;
 94   G4RegionStore* store = GetInstance();            94   G4RegionStore* store = GetInstance();
 95                                                    95 
 96   for(auto pos=store->cbegin(); pos!=store->ce <<  96 #ifdef G4GEOMETRY_VOXELDEBUG
                                                   >>  97   G4cout << "Deleting Regions ... ";
                                                   >>  98 #endif
                                                   >>  99 
                                                   >> 100   for(iterator pos=store->begin(); pos!=store->end(); ++pos)
 97   {                                               101   {
 98     if (fgNotifier != nullptr) { fgNotifier->N << 102     if (fgNotifier) { fgNotifier->NotifyDeRegistration(); }
 99     delete *pos;                               << 103     if (*pos) { delete *pos; }
                                                   >> 104     i++;
100   }                                               105   }
101                                                   106 
102   store->bmap.clear(); store->mvalid = false;  << 107 #ifdef G4GEOMETRY_VOXELDEBUG
                                                   >> 108   if (store->size() < i-1)
                                                   >> 109     { G4cout << "No regions deleted. Already deleted by user ?" << G4endl; }
                                                   >> 110   else
                                                   >> 111     { G4cout << i-1 << " regions deleted !" << G4endl; }
                                                   >> 112 #endif
                                                   >> 113 
103   locked = false;                                 114   locked = false;
104   store->clear();                                 115   store->clear();
105 }                                                 116 }
106                                                   117 
107 // *******************************************    118 // ***************************************************************************
108 // Associate user notifier to the store           119 // Associate user notifier to the store
109 // *******************************************    120 // ***************************************************************************
110 //                                                121 //
111 void G4RegionStore::SetNotifier(G4VStoreNotifi    122 void G4RegionStore::SetNotifier(G4VStoreNotifier* pNotifier)
112 {                                                 123 {
113   GetInstance();                                  124   GetInstance();
114   fgNotifier = pNotifier;                         125   fgNotifier = pNotifier;
115 }                                                 126 }
116                                                   127 
117 // *******************************************    128 // ***************************************************************************
118 // Bring contents of internal map up to date a << 
119 // ******************************************* << 
120 //                                             << 
121 void G4RegionStore::UpdateMap()                << 
122 {                                              << 
123   G4AutoLock l(&mapMutex);  // to avoid thread << 
124   if (mvalid) return;                          << 
125   bmap.clear();                                << 
126   for(auto pos=GetInstance()->cbegin(); pos!=G << 
127   {                                            << 
128     const G4String& reg_name = (*pos)->GetName << 
129     auto it = bmap.find(reg_name);             << 
130     if (it != bmap.cend())                     << 
131     {                                          << 
132       it->second.push_back(*pos);              << 
133     }                                          << 
134     else                                       << 
135     {                                          << 
136       std::vector<G4Region*> reg_vec { *pos }; << 
137       bmap.insert(std::make_pair(reg_name, reg << 
138     }                                          << 
139   }                                            << 
140   mvalid = true;                               << 
141   l.unlock();                                  << 
142 }                                              << 
143                                                << 
144 // ******************************************* << 
145 // Add Region to container                        129 // Add Region to container
146 // *******************************************    130 // ***************************************************************************
147 //                                                131 //
148 void G4RegionStore::Register(G4Region* pRegion    132 void G4RegionStore::Register(G4Region* pRegion)
149 {                                                 133 {
150   G4RegionStore* store = GetInstance();        << 134   GetInstance()->push_back(pRegion);
151   store->push_back(pRegion);                   << 135   if (fgNotifier)  { fgNotifier->NotifyRegistration(); }
152   const G4String& reg_name = pRegion->GetName( << 
153   auto it = store->bmap.find(reg_name);        << 
154   if (it != store->bmap.cend())                << 
155   {                                            << 
156     it->second.push_back(pRegion);             << 
157   }                                            << 
158   else                                         << 
159   {                                            << 
160     std::vector<G4Region*> reg_vec { pRegion } << 
161     store->bmap.insert(std::make_pair(reg_name << 
162   }                                            << 
163   if (fgNotifier != nullptr) { fgNotifier->Not << 
164   store->mvalid = true;                        << 
165 }                                                 136 }
166                                                   137 
167 // *******************************************    138 // ***************************************************************************
168 // Remove Region from container                   139 // Remove Region from container
169 // *******************************************    140 // ***************************************************************************
170 //                                                141 //
171 void G4RegionStore::DeRegister(G4Region* pRegi    142 void G4RegionStore::DeRegister(G4Region* pRegion)
172 {                                                 143 {
173   G4RegionStore* store = GetInstance();        << 
174   if (!locked)    // Do not de-register if loc    144   if (!locked)    // Do not de-register if locked !
175   {                                               145   {
176     if (fgNotifier != nullptr)  { fgNotifier-> << 146     if (fgNotifier)  { fgNotifier->NotifyDeRegistration(); }
177     for (auto i=store->cbegin(); i!=store->cen << 147     for (iterator i=GetInstance()->begin(); i!=GetInstance()->end(); i++)
178     {                                             148     {
179       if (**i==*pRegion)                          149       if (**i==*pRegion)
180       {                                           150       {
181         store->erase(i);                       << 151         GetInstance()->erase(i);
182         break;                                    152         break;
183       }                                           153       }
184     }                                             154     }
185     const G4String& reg_name = pRegion->GetNam << 
186     auto it = store->bmap.find(reg_name);      << 
187     if (it != store->bmap.cend())              << 
188     {                                          << 
189       if (it->second.size() > 1)               << 
190       {                                        << 
191         for (auto i=it->second.cbegin(); i!=it << 
192         {                                      << 
193           if (**i==*pRegion)                   << 
194           {                                    << 
195             it->second.erase(i);               << 
196             break;                             << 
197           }                                    << 
198         }                                      << 
199       }                                        << 
200       else                                     << 
201       {                                        << 
202         store->bmap.erase(it);                 << 
203       }                                        << 
204     }                                          << 
205   }                                               155   }
206 }                                                 156 }
207                                                   157 
208 // *******************************************    158 // ***************************************************************************
209 // Return ptr to Store, setting if necessary      159 // Return ptr to Store, setting if necessary
210 // *******************************************    160 // ***************************************************************************
211 //                                                161 //
212 G4RegionStore* G4RegionStore::GetInstance()       162 G4RegionStore* G4RegionStore::GetInstance()
213 {                                                 163 {
214   static G4RegionStore worldStore;                164   static G4RegionStore worldStore;
215   if (fgInstance == nullptr)                   << 165   if (!fgInstance)
216   {                                               166   {
217     fgInstance = &worldStore;                     167     fgInstance = &worldStore;
218   }                                               168   }
219   return fgInstance;                              169   return fgInstance;
220 }                                                 170 }
221                                                   171 
222 // *******************************************    172 // ***************************************************************************
223 // Loops through all regions to verify if a re    173 // Loops through all regions to verify if a region has been modified.
224 // It returns TRUE if just one region is modif    174 // It returns TRUE if just one region is modified.
225 // *******************************************    175 // ***************************************************************************
226 //                                                176 //
227 G4bool G4RegionStore::IsModified() const          177 G4bool G4RegionStore::IsModified() const
228 {                                                 178 {
229   for (auto i=GetInstance()->cbegin(); i!=GetI << 179   for (iterator i=GetInstance()->begin(); i!=GetInstance()->end(); i++)
230   {                                               180   {
231     if ((*i)->IsModified()) { return true; }      181     if ((*i)->IsModified()) { return true; }
232   }                                               182   }
233   return false;                                   183   return false;
234 }                                                 184 }
235                                                   185 
236 // *******************************************    186 // ***************************************************************************
237 // Loops through all regions to reset flag for    187 // Loops through all regions to reset flag for modification to FALSE.
238 // Used by the run manager to notify that the     188 // Used by the run manager to notify that the physics table has been updated.
239 // *******************************************    189 // ***************************************************************************
240 //                                                190 //
241 void G4RegionStore::ResetRegionModified()         191 void G4RegionStore::ResetRegionModified()
242 {                                                 192 {
243   for (auto i=GetInstance()->cbegin(); i!=GetI << 193   for (iterator i=GetInstance()->begin(); i!=GetInstance()->end(); i++)
244   {                                               194   {
245     (*i)->RegionModified(false);                  195     (*i)->RegionModified(false);
246   }                                               196   }
247 }                                                 197 }
248                                                   198 
249 // *******************************************    199 // ***************************************************************************
250 // Forces recomputation of material lists in a    200 // Forces recomputation of material lists in all regions in the store.
251 // *******************************************    201 // ***************************************************************************
252 //                                                202 //
253 void G4RegionStore::UpdateMaterialList(G4VPhys    203 void G4RegionStore::UpdateMaterialList(G4VPhysicalVolume* currentWorld)
254 {                                                 204 {
255   for (auto i=GetInstance()->cbegin(); i!=GetI << 205   for (iterator i=GetInstance()->begin(); i!=GetInstance()->end(); i++)
256   {                                               206   {
257     if((*i)->IsInMassGeometry() || (*i)->IsInP << 207     if((*i)->IsInMassGeometry() || (*i)->IsInParallelGeometry() || currentWorld)
258                                 || (currentWor << 
259     { (*i)->UpdateMaterialList(); }               208     { (*i)->UpdateMaterialList(); }
260   }                                               209   }
261 }                                                 210 }
262                                                   211 
263 // *******************************************    212 // ***************************************************************************
264 // Returns a region through its name specifica    213 // Returns a region through its name specification.
265 // *******************************************    214 // ***************************************************************************
266 //                                                215 //
267 G4Region* G4RegionStore::GetRegion(const G4Str    216 G4Region* G4RegionStore::GetRegion(const G4String& name, G4bool verbose) const
268 {                                                 217 {
269   G4RegionStore* store = GetInstance();        << 218   for (iterator i=GetInstance()->begin(); i!=GetInstance()->end(); i++)
270   if (!store->mvalid)  { store->UpdateMap(); } << 
271   auto pos = store->bmap.find(name);           << 
272   if(pos != store->bmap.cend())                << 
273   {                                               219   {
274     if ((verbose) && (pos->second.size()>1))   << 220     if ((*i)->GetName() == name) { return *i; }
275     {                                          << 
276       std::ostringstream message;              << 
277       message << "There exists more than ONE r << 
278               << name << "!" << G4endl         << 
279               << "Returning the first found."; << 
280       G4Exception("G4RegionStore::GetSolid()", << 
281                   "GeomMgt1001", JustWarning,  << 
282     }                                          << 
283     return pos->second[0];                     << 
284   }                                               221   }
285   if (verbose)                                    222   if (verbose)
286   {                                               223   {
287     std::ostringstream message;                   224     std::ostringstream message;
288     message << "Region NOT found in store !" <    225     message << "Region NOT found in store !" << G4endl
289             << "        Region " << name << "     226             << "        Region " << name << " NOT found in store !" << G4endl
290             << "        Returning NULL pointer    227             << "        Returning NULL pointer.";
291     G4Exception("G4RegionStore::GetRegion()",     228     G4Exception("G4RegionStore::GetRegion()",
292                 "GeomMgt1001", JustWarning, me    229                 "GeomMgt1001", JustWarning, message);
293   }                                               230   }
294   return nullptr;                              << 231   return 0;
295 }                                                 232 }
296                                                   233 
297 // *******************************************    234 // ***************************************************************************
298 // Returns a region through its name specifica    235 // Returns a region through its name specification, if it exists.
299 // If it does not exist it will allocate a new    236 // If it does not exist it will allocate a new region with the given
300 // name, delegating the ownership to the calle    237 // name, delegating the ownership to the caller client.
301 // *******************************************    238 // ***************************************************************************
302 //                                                239 //
303 G4Region* G4RegionStore::FindOrCreateRegion(co    240 G4Region* G4RegionStore::FindOrCreateRegion(const G4String& name)
304 {                                                 241 {
305   G4Region* target = GetRegion(name,false);       242   G4Region* target = GetRegion(name,false);
306   if (target == nullptr)                       << 243   if (!target)
307   {                                               244   {
308     target = new G4Region(name);                  245     target = new G4Region(name);
309   }                                               246   }
310   return target;                                  247   return target;
311 }                                                 248 }
312                                                   249 
313 // *******************************************    250 // **************************************************************************
314 // Set a world physical volume pointer to a re    251 // Set a world physical volume pointer to a region that belongs to it.
315 // Scan over all world volumes.                   252 // Scan over all world volumes.
316 // *******************************************    253 // **************************************************************************
317 //                                                254 //
318 void G4RegionStore::SetWorldVolume()              255 void G4RegionStore::SetWorldVolume()
319 {                                                 256 {
320   // Reset all pointers first                     257   // Reset all pointers first
321   //                                              258   //
322   for (auto i=GetInstance()->cbegin(); i!=GetI << 259   for (iterator i=GetInstance()->begin(); i!=GetInstance()->end(); i++)
323   { (*i)->SetWorld(nullptr); }                 << 260   { (*i)->SetWorld(0); }
324                                                   261 
325   // Find world volumes                           262   // Find world volumes
326   //                                              263   //
327   G4PhysicalVolumeStore* fPhysicalVolumeStore     264   G4PhysicalVolumeStore* fPhysicalVolumeStore
328     = G4PhysicalVolumeStore::GetInstance();       265     = G4PhysicalVolumeStore::GetInstance();
329   std::size_t nPhys = fPhysicalVolumeStore->si << 266   size_t nPhys = fPhysicalVolumeStore->size();
330   for(std::size_t iPhys=0; iPhys<nPhys; ++iPhy << 267   for(size_t iPhys=0; iPhys<nPhys; iPhys++)
331   {                                               268   {
332     G4VPhysicalVolume* fPhys = (*fPhysicalVolu    269     G4VPhysicalVolume* fPhys = (*fPhysicalVolumeStore)[iPhys];
333     if(fPhys->GetMotherLogical() != nullptr) { << 270     if(fPhys->GetMotherLogical()) { continue; } // not a world volume
334                                                   271 
335     // Now 'fPhys' is a world volume, set it t    272     // Now 'fPhys' is a world volume, set it to regions that belong to it.
336     //                                            273     //
337     for (auto i=GetInstance()->cbegin(); i!=Ge << 274     for (iterator i=GetInstance()->begin(); i!=GetInstance()->end(); i++)
338     { (*i)->SetWorld(fPhys); }                    275     { (*i)->SetWorld(fPhys); }
339   }                                               276   }
340 }                                                 277 }
341                                                   278 
342                                                   279