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5 ] [ 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/G4PhysicalVolumeStore.cc (Version 11.3.0) and /geometry/management/src/G4PhysicalVolumeStore.cc (Version 4.1.p1)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                    <<   3 // * DISCLAIMER                                                       *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th <<   5 // * The following disclaimer summarizes all the specific disclaimers *
  6 // * the Geant4 Collaboration.  It is provided <<   6 // * of contributors to this software. The specific disclaimers,which *
  7 // * conditions of the Geant4 Software License <<   7 // * govern, are listed with their locations in:                      *
  8 // * LICENSE and available at  http://cern.ch/ <<   8 // *   http://cern.ch/geant4/license                                  *
  9 // * include a list of copyright holders.      << 
 10 // *                                                9 // *                                                                  *
 11 // * Neither the authors of this software syst     10 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     11 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     12 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     13 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file  <<  14 // * use.                                                             *
 16 // * for the full disclaimer and the limitatio << 
 17 // *                                               15 // *                                                                  *
 18 // * This  code  implementation is the result  <<  16 // * This  code  implementation is the  intellectual property  of the *
 19 // * technical work of the GEANT4 collaboratio <<  17 // * GEANT4 collaboration.                                            *
 20 // * By using,  copying,  modifying or  distri <<  18 // * By copying,  distributing  or modifying the Program (or any work *
 21 // * any work based  on the software)  you  ag <<  19 // * based  on  the Program)  you indicate  your  acceptance of  this *
 22 // * use  in  resulting  scientific  publicati <<  20 // * statement, and all its terms.                                    *
 23 // * acceptance of all terms of the Geant4 Sof << 
 24 // *******************************************     21 // ********************************************************************
 25 //                                                 22 //
 26 // G4PhysicalVolumeStore implementation        << 
 27 //                                                 23 //
 28 // 25.07.95, P.Kent, G.Cosmo                   <<  24 // $Id: G4PhysicalVolumeStore.cc,v 1.9 2002/04/26 16:24:36 gcosmo Exp $
 29 // ------------------------------------------- <<  25 // GEANT4 tag $Name: geant4-04-01 $
                                                   >>  26 //
                                                   >>  27 // G4PhysicalVolumeStore
                                                   >>  28 //
                                                   >>  29 // Implementation for singleton container
                                                   >>  30 //
                                                   >>  31 // History:
                                                   >>  32 // 25.07.95 P.Kent Initial version
                                                   >>  33 // ********************************************************************
 30                                                    34 
 31 #include "G4Types.hh"                          <<  35 #include "globals.hh"
 32 #include "G4PhysicalVolumeStore.hh"                36 #include "G4PhysicalVolumeStore.hh"
 33 #include "G4GeometryManager.hh"                    37 #include "G4GeometryManager.hh"
 34 #include "G4LogicalVolume.hh"                  << 
 35                                                << 
 36 #include "G4AutoLock.hh"                       << 
 37                                                << 
 38 namespace                                      << 
 39 {                                              << 
 40   G4Mutex mapMutex = G4MUTEX_INITIALIZER;      << 
 41 }                                              << 
 42                                                    38 
 43 // *******************************************     39 // ***************************************************************************
 44 // Static class variables                          40 // Static class variables
 45 // *******************************************     41 // ***************************************************************************
 46 //                                                 42 //
 47 G4PhysicalVolumeStore* G4PhysicalVolumeStore:: <<  43 G4PhysicalVolumeStore* G4PhysicalVolumeStore::fgInstance = 0;
 48 G4ThreadLocal G4VStoreNotifier* G4PhysicalVolu <<  44 G4bool G4PhysicalVolumeStore::locked = false;
 49 G4ThreadLocal G4bool G4PhysicalVolumeStore::lo << 
 50                                                    45 
 51 // *******************************************     46 // ***************************************************************************
 52 // Protected constructor: Construct underlying     47 // Protected constructor: Construct underlying container with
 53 // initial size of 100 entries                     48 // initial size of 100 entries
 54 // *******************************************     49 // ***************************************************************************
 55 //                                                 50 //
 56 G4PhysicalVolumeStore::G4PhysicalVolumeStore()     51 G4PhysicalVolumeStore::G4PhysicalVolumeStore()
 57                                                <<  52   : G4std::vector<G4VPhysicalVolume*>()
 58 {                                                  53 {
 59   reserve(100);                                    54   reserve(100);
 60 }                                                  55 }
 61                                                    56 
 62 // *******************************************     57 // ***************************************************************************
 63 // Destructor                                      58 // Destructor
 64 // *******************************************     59 // ***************************************************************************
 65 //                                                 60 //
 66 G4PhysicalVolumeStore::~G4PhysicalVolumeStore(     61 G4PhysicalVolumeStore::~G4PhysicalVolumeStore()
 67 {                                                  62 {
 68   Clean();  // Delete all volumes in the store <<  63   Clean();
 69   G4VPhysicalVolume::Clean();  // Delete alloc << 
 70 }                                                  64 }
 71                                                    65 
 72 // *******************************************     66 // ***************************************************************************
 73 // Delete all elements from the store              67 // Delete all elements from the store
 74 // *******************************************     68 // ***************************************************************************
 75 //                                                 69 //
 76 void G4PhysicalVolumeStore::Clean()                70 void G4PhysicalVolumeStore::Clean()
 77 {                                                  71 {
 78   // Do nothing if geometry is closed              72   // Do nothing if geometry is closed
 79   //                                               73   //
 80   if (G4GeometryManager::GetInstance()->IsGeom     74   if (G4GeometryManager::GetInstance()->IsGeometryClosed())
 81   {                                                75   {
 82     G4cout << "WARNING - Attempt to delete the     76     G4cout << "WARNING - Attempt to delete the physical volume store"
 83            << " while geometry closed !" << G4     77            << " while geometry closed !" << G4endl;
 84     return;                                        78     return;
 85   }                                                79   }
 86                                                    80 
 87   // Locks store for deletion of volumes. De-r     81   // Locks store for deletion of volumes. De-registration will be
 88   // performed at this stage. G4VPhysicalVolum     82   // performed at this stage. G4VPhysicalVolumes will not de-register
 89   // themselves.                                   83   // themselves.
 90   //                                               84   //
 91   locked = true;                                   85   locked = true;
 92                                                    86 
                                                   >>  87   size_t i=0;
 93   G4PhysicalVolumeStore* store = GetInstance()     88   G4PhysicalVolumeStore* store = GetInstance();
                                                   >>  89   G4std::vector<G4VPhysicalVolume*>::iterator pos;
 94                                                    90 
 95   for(auto pos=store->cbegin(); pos!=store->ce <<  91 #ifdef G4GEOMETRY_VOXELDEBUG
                                                   >>  92   G4cout << "Deleting Physical Volumes ... ";
                                                   >>  93 #endif
                                                   >>  94 
                                                   >>  95   for(pos=store->begin(); pos!=store->end(); pos++)
 96   {                                                96   {
 97     if (fgNotifier != nullptr) { fgNotifier->N <<  97     if (*pos) delete *pos; i++;
 98     delete *pos;                               << 
 99   }                                                98   }
100                                                    99 
101   store->bmap.clear(); store->mvalid = false;  << 100 #ifdef G4GEOMETRY_VOXELDEBUG
                                                   >> 101   if (store->size() < i-1)
                                                   >> 102     { G4cout << "No volumes deleted. Already deleted by user ?" << G4endl; }
                                                   >> 103   else
                                                   >> 104     { G4cout << i-1 << " volumes deleted !" << G4endl; }
                                                   >> 105 #endif
                                                   >> 106 
102   locked = false;                                 107   locked = false;
103   store->clear();                                 108   store->clear();
104 }                                                 109 }
105                                                   110 
106 // *******************************************    111 // ***************************************************************************
107 // Associate user notifier to the store        << 112 // Add Solid to container
108 // ******************************************* << 
109 //                                             << 
110 void G4PhysicalVolumeStore::SetNotifier(G4VSto << 
111 {                                              << 
112   GetInstance();                               << 
113   fgNotifier = pNotifier;                      << 
114 }                                              << 
115                                                << 
116 // ******************************************* << 
117 // Bring contents of internal map up to date a << 
118 // ******************************************* << 
119 //                                             << 
120 void G4PhysicalVolumeStore::UpdateMap()        << 
121 {                                              << 
122   G4AutoLock l(&mapMutex);  // to avoid thread << 
123   if (mvalid) return;                          << 
124   bmap.clear();                                << 
125   for(auto pos=GetInstance()->cbegin(); pos!=G << 
126   {                                            << 
127     const G4String& vol_name = (*pos)->GetName << 
128     auto it = bmap.find(vol_name);             << 
129     if (it != bmap.cend())                     << 
130     {                                          << 
131       it->second.push_back(*pos);              << 
132     }                                          << 
133     else                                       << 
134     {                                          << 
135       std::vector<G4VPhysicalVolume*> vol_vec  << 
136       bmap.insert(std::make_pair(vol_name, vol << 
137     }                                          << 
138   }                                            << 
139   mvalid = true;                               << 
140   l.unlock();                                  << 
141 }                                              << 
142                                                << 
143 // ******************************************* << 
144 // Add Volume to container                     << 
145 // *******************************************    113 // ***************************************************************************
146 //                                                114 //
147 void G4PhysicalVolumeStore::Register(G4VPhysic    115 void G4PhysicalVolumeStore::Register(G4VPhysicalVolume* pVolume)
148 {                                                 116 {
149   G4PhysicalVolumeStore* store = GetInstance() << 117     GetInstance()->push_back(pVolume);
150   store->push_back(pVolume);                   << 
151   const G4String& vol_name = pVolume->GetName( << 
152   auto it = store->bmap.find(vol_name);        << 
153   if (it != store->bmap.cend())                << 
154   {                                            << 
155     it->second.push_back(pVolume);             << 
156   }                                            << 
157   else                                         << 
158   {                                            << 
159     std::vector<G4VPhysicalVolume*> vol_vec {  << 
160     store->bmap.insert(std::make_pair(vol_name << 
161   }                                            << 
162   if (fgNotifier != nullptr) { fgNotifier->Not << 
163   store->mvalid = true;                        << 
164 }                                                 118 }
165                                                   119 
166 // *******************************************    120 // ***************************************************************************
167 // Remove Volume from container and update the << 121 // Remove Solid from container
168 // of the mother's logical volume              << 
169 // *******************************************    122 // ***************************************************************************
170 //                                                123 //
171 void G4PhysicalVolumeStore::DeRegister(G4VPhys    124 void G4PhysicalVolumeStore::DeRegister(G4VPhysicalVolume* pVolume)
172 {                                                 125 {
173   G4PhysicalVolumeStore* store = GetInstance() << 
174   if (!locked)    // Do not de-register if loc    126   if (!locked)    // Do not de-register if locked !
175   {                                               127   {
176     if (fgNotifier != nullptr) { fgNotifier->N << 128     for (iterator i=GetInstance()->begin(); i!=GetInstance()->end(); i++)
177     G4LogicalVolume* motherLogical = pVolume-> << 
178     if (motherLogical != nullptr) { motherLogi << 
179     for (auto i=store->cbegin(); i!=store->cen << 
180     {                                             129     {
181       if (**i==*pVolume)                          130       if (**i==*pVolume)
182       {                                           131       {
183         store->erase(i);                       << 132         GetInstance()->erase(i);
184         break;                                    133         break;
185       }                                           134       }
186     }                                             135     }
187     const G4String& vol_name = pVolume->GetNam << 
188     auto it = store->bmap.find(vol_name);      << 
189     if (it != store->bmap.cend())              << 
190     {                                          << 
191       if (it->second.size() > 1)               << 
192       {                                        << 
193         for (auto i=it->second.cbegin(); i!=it << 
194         {                                      << 
195           if (**i==*pVolume)                   << 
196           {                                    << 
197             it->second.erase(i);               << 
198             break;                             << 
199           }                                    << 
200         }                                      << 
201       }                                        << 
202       else                                     << 
203       {                                        << 
204         store->bmap.erase(it);                 << 
205       }                                        << 
206     }                                          << 
207   }                                            << 
208 }                                              << 
209                                                << 
210 // ******************************************* << 
211 // Retrieve the first or last volume pointer i << 
212 // ******************************************* << 
213 //                                             << 
214 G4VPhysicalVolume*                             << 
215 G4PhysicalVolumeStore::GetVolume(const G4Strin << 
216                                  G4bool revers << 
217 {                                              << 
218   G4PhysicalVolumeStore* store = GetInstance() << 
219   if (!store->mvalid)  { store->UpdateMap(); } << 
220   auto pos = store->bmap.find(name);           << 
221   if(pos != store->bmap.cend())                << 
222   {                                            << 
223     if ((verbose) && (pos->second.size()>1))   << 
224     {                                          << 
225       std::ostringstream message;              << 
226       message << "There exists more than ONE p << 
227               << name << "!" << G4endl         << 
228               << "Returning the first found."; << 
229       G4Exception("G4PhysicalVolumeStore::GetV << 
230                   "GeomMgt1001", JustWarning,  << 
231     }                                          << 
232     if(reverseSearch)                          << 
233     {                                          << 
234       return pos->second[pos->second.size()-1] << 
235     }                                          << 
236     else                                       << 
237     {                                          << 
238       return pos->second[0];                   << 
239     }                                          << 
240   }                                               136   }
241   if (verbose)                                 << 
242   {                                            << 
243      std::ostringstream message;               << 
244      message << "Volume NOT found in store !"  << 
245             << "        Volume " << name << "  << 
246             << "        Returning NULL pointer << 
247      G4Exception("G4PhysicalVolumeStore::GetVo << 
248                  "GeomMgt1001", JustWarning, m << 
249   }                                            << 
250   return nullptr;                              << 
251 }                                                 137 }
252                                                   138 
253 // *******************************************    139 // ***************************************************************************
254 // Return ptr to Store, setting if necessary      140 // Return ptr to Store, setting if necessary
255 // *******************************************    141 // ***************************************************************************
256 //                                                142 //
257 G4PhysicalVolumeStore* G4PhysicalVolumeStore::    143 G4PhysicalVolumeStore* G4PhysicalVolumeStore::GetInstance()
258 {                                                 144 {
259   static G4PhysicalVolumeStore worldStore;     << 145     static G4PhysicalVolumeStore worldStore;
260   if (fgInstance == nullptr)                   << 146     if (!fgInstance)
261   {                                            << 147   {
262     fgInstance = &worldStore;                  << 148       fgInstance = &worldStore;
263   }                                            << 149   }
264   return fgInstance;                           << 150     return fgInstance;
265 }                                                 151 }
266                                                   152