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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/G4SolidStore.cc (Version 11.3.0) and /geometry/management/src/G4SolidStore.cc (Version 5.2)


  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 // G4SolidStore implementation                 << 
 27 //                                                 23 //
 28 // 10.07.95, P.Kent, G.Cosmo                   <<  24 // $Id: G4SolidStore.cc,v 1.10 2003/06/16 16:52:10 gunter Exp $
 29 // ------------------------------------------- <<  25 // GEANT4 tag $Name: geant4-05-02 $
                                                   >>  26 //
                                                   >>  27 // G4SolidStore
                                                   >>  28 //
                                                   >>  29 // Implementation for singleton container
                                                   >>  30 //
                                                   >>  31 // History:
                                                   >>  32 // 10.07.95 P.Kent Initial version
                                                   >>  33 // ********************************************************************
 30                                                    34 
 31 #include "globals.hh"                              35 #include "globals.hh"
 32 #include "G4SolidStore.hh"                         36 #include "G4SolidStore.hh"
 33 #include "G4GeometryManager.hh"                    37 #include "G4GeometryManager.hh"
 34                                                    38 
 35 #include "G4AutoLock.hh"                       << 
 36                                                << 
 37 namespace                                      << 
 38 {                                              << 
 39   G4Mutex mapMutex = G4MUTEX_INITIALIZER;      << 
 40 }                                              << 
 41                                                << 
 42 // *******************************************     39 // ***************************************************************************
 43 // Static class variables                          40 // Static class variables
 44 // *******************************************     41 // ***************************************************************************
 45 //                                                 42 //
 46 G4SolidStore* G4SolidStore::fgInstance = nullp <<  43 G4SolidStore* G4SolidStore::fgInstance = 0;
 47 G4ThreadLocal G4VStoreNotifier* G4SolidStore:: <<  44 G4bool G4SolidStore::locked = false;
 48 G4ThreadLocal G4bool G4SolidStore::locked = fa << 
 49                                                    45 
 50 // *******************************************     46 // ***************************************************************************
 51 // Protected constructor: Construct underlying     47 // Protected constructor: Construct underlying container with
 52 // initial size of 100 entries                     48 // initial size of 100 entries
 53 // *******************************************     49 // ***************************************************************************
 54 //                                                 50 //
 55 G4SolidStore::G4SolidStore()                       51 G4SolidStore::G4SolidStore()
 56                                                <<  52   : std::vector<G4VSolid*>()
 57 {                                                  53 {
 58   reserve(100);                                    54   reserve(100);
 59 }                                                  55 }
 60                                                    56 
 61 // *******************************************     57 // ***************************************************************************
 62 // Destructor                                      58 // Destructor
 63 // *******************************************     59 // ***************************************************************************
 64 //                                                 60 //
 65 G4SolidStore::~G4SolidStore()                      61 G4SolidStore::~G4SolidStore() 
 66 {                                                  62 {
                                                   >>  63   // NOTE: destruction of solids is client responsibility !
                                                   >>  64   // clear();
 67   Clean();                                         65   Clean();
 68 }                                                  66 }
 69                                                    67 
 70 // *******************************************     68 // ***************************************************************************
 71 // Delete all elements from the store              69 // Delete all elements from the store
 72 // *******************************************     70 // ***************************************************************************
 73 //                                                 71 //
 74 void G4SolidStore::Clean()                         72 void G4SolidStore::Clean()
 75 {                                                  73 {
 76   // Do nothing if geometry is closed              74   // Do nothing if geometry is closed
 77   //                                               75   //
 78   if (G4GeometryManager::GetInstance()->IsGeom     76   if (G4GeometryManager::GetInstance()->IsGeometryClosed())
 79   {                                                77   {
 80     G4cout << "WARNING - Attempt to delete the     78     G4cout << "WARNING - Attempt to delete the solid store"
 81            << " while geometry closed !" << G4     79            << " while geometry closed !" << G4endl;
 82     return;                                        80     return;
 83   }                                                81   }
 84                                                    82 
 85   // Locks store for deletion of solids. De-re     83   // Locks store for deletion of solids. De-registration will be
 86   // performed at this stage. G4VSolids will n     84   // performed at this stage. G4VSolids will not de-register themselves.
 87   //                                               85   //
 88   locked = true;                                   86   locked = true;  
 89                                                    87 
                                                   >>  88   size_t i=0;
 90   G4SolidStore* store = GetInstance();             89   G4SolidStore* store = GetInstance();
                                                   >>  90   std::vector<G4VSolid*>::iterator pos;
 91                                                    91 
 92   for(auto pos=store->cbegin(); pos!=store->ce <<  92 #ifdef G4GEOMETRY_VOXELDEBUG
                                                   >>  93   G4cout << "Deleting Solids ... ";
                                                   >>  94 #endif
                                                   >>  95 
                                                   >>  96   for(pos=store->begin(); pos!=store->end(); pos++)
 93   {                                                97   {
 94     if (fgNotifier != nullptr) { fgNotifier->N <<  98     if (*pos) delete *pos; i++;
 95     delete *pos;                               << 
 96   }                                                99   }
 97                                                   100 
 98   store->bmap.clear(); store->mvalid = false;  << 101 #ifdef G4GEOMETRY_VOXELDEBUG
                                                   >> 102   if (store->size() < i-1)
                                                   >> 103     { G4cout << "No solids deleted. Already deleted by user ?" << G4endl; }
                                                   >> 104   else
                                                   >> 105     { G4cout << i-1 << " solids deleted !" << G4endl; }
                                                   >> 106 #endif
                                                   >> 107 
 99   locked = false;                                 108   locked = false;
100   store->clear();                                 109   store->clear();
101 }                                                 110 }
102                                                   111 
103 // *******************************************    112 // ***************************************************************************
104 // Associate user notifier to the store        << 
105 // ******************************************* << 
106 //                                             << 
107 void G4SolidStore::SetNotifier(G4VStoreNotifie << 
108 {                                              << 
109   GetInstance();                               << 
110   fgNotifier = pNotifier;                      << 
111 }                                              << 
112                                                << 
113 // ******************************************* << 
114 // Bring contents of internal map up to date a << 
115 // ******************************************* << 
116 //                                             << 
117 void G4SolidStore::UpdateMap()                 << 
118 {                                              << 
119   G4AutoLock l(&mapMutex);  // to avoid thread << 
120   if (mvalid) return;                          << 
121   bmap.clear();                                << 
122   for(auto pos=GetInstance()->cbegin(); pos!=G << 
123   {                                            << 
124     const G4String& sol_name = (*pos)->GetName << 
125     auto it = bmap.find(sol_name);             << 
126     if (it != bmap.cend())                     << 
127     {                                          << 
128       it->second.push_back(*pos);              << 
129     }                                          << 
130     else                                       << 
131     {                                          << 
132       std::vector<G4VSolid*> sol_vec { *pos }; << 
133       bmap.insert(std::make_pair(sol_name, sol << 
134     }                                          << 
135   }                                            << 
136   mvalid = true;                               << 
137   l.unlock();                                  << 
138 }                                              << 
139                                                << 
140 // ******************************************* << 
141 // Add Solid to container                         113 // Add Solid to container
142 // *******************************************    114 // ***************************************************************************
143 //                                                115 //
144 void G4SolidStore::Register(G4VSolid* pSolid)     116 void G4SolidStore::Register(G4VSolid* pSolid)
145 {                                                 117 {
146   G4SolidStore* store = GetInstance();         << 118   GetInstance()->push_back(pSolid);
147   store->push_back(pSolid);                    << 
148   const G4String& sol_name = pSolid->GetName() << 
149   auto it = store->bmap.find(sol_name);        << 
150   if (it != store->bmap.cend())                << 
151   {                                            << 
152     it->second.push_back(pSolid);              << 
153   }                                            << 
154   else                                         << 
155   {                                            << 
156     std::vector<G4VSolid*> sol_vec { pSolid }; << 
157     store->bmap.insert(std::make_pair(sol_name << 
158   }                                            << 
159   if (fgNotifier != nullptr) { fgNotifier->Not << 
160   store->mvalid = true;                        << 
161 }                                                 119 }
162                                                   120 
163 // *******************************************    121 // ***************************************************************************
164 // Remove Solid from container                    122 // Remove Solid from container
165 // *******************************************    123 // ***************************************************************************
166 //                                                124 //
167 void G4SolidStore::DeRegister(G4VSolid* pSolid    125 void G4SolidStore::DeRegister(G4VSolid* pSolid)
168 {                                                 126 {
169   G4SolidStore* store = GetInstance();         << 
170   if (!locked)    // Do not de-register if loc    127   if (!locked)    // Do not de-register if locked !
171   {                                               128   {
172     if (fgNotifier != nullptr) { fgNotifier->N << 129     for (iterator i=GetInstance()->begin(); i!=GetInstance()->end(); i++)
173     for (auto i=store->crbegin(); i!=store->cr << 
174     {                                             130     {
175       if (**i==*pSolid)                           131       if (**i==*pSolid)
176       {                                           132       {
177         store->erase(std::next(i).base());     << 133         GetInstance()->erase(i);
178         store->mvalid = false;                 << 
179         break;                                    134         break;
180       }                                           135       }
181     }                                             136     }
182     const G4String& sol_name = pSolid->GetName << 
183     auto it = store->bmap.find(sol_name);      << 
184     if (it != store->bmap.cend())              << 
185     {                                          << 
186       if (it->second.size() > 1)               << 
187       {                                        << 
188         for (auto i=it->second.cbegin(); i!=it << 
189         {                                      << 
190           if (**i==*pSolid)                    << 
191           {                                    << 
192             it->second.erase(i);               << 
193             break;                             << 
194           }                                    << 
195         }                                      << 
196       }                                        << 
197       else                                     << 
198       {                                        << 
199         store->bmap.erase(it);                 << 
200       }                                        << 
201     }                                          << 
202   }                                            << 
203 }                                              << 
204                                                << 
205 // ******************************************* << 
206 // Retrieve the first or last solid pointer in << 
207 // ******************************************* << 
208 //                                             << 
209 G4VSolid* G4SolidStore::GetSolid(const G4Strin << 
210                                  G4bool revers << 
211 {                                              << 
212   G4SolidStore* store = GetInstance();         << 
213   if (!store->mvalid)  { store->UpdateMap(); } << 
214   auto pos = store->bmap.find(name);           << 
215   if(pos != store->bmap.cend())                << 
216   {                                            << 
217     if ((verbose) && (pos->second.size()>1))   << 
218     {                                          << 
219       std::ostringstream message;              << 
220       message << "There exists more than ONE s << 
221               << name << "!" << G4endl         << 
222               << "Returning the first found."; << 
223       G4Exception("G4SolidStore::GetSolid()",  << 
224                   "GeomMgt1001", JustWarning,  << 
225     }                                          << 
226     if(reverseSearch)                          << 
227     {                                          << 
228       return pos->second[pos->second.size()-1] << 
229     }                                          << 
230     else                                       << 
231     {                                          << 
232       return pos->second[0];                   << 
233     }                                          << 
234   }                                            << 
235   if (verbose)                                 << 
236   {                                            << 
237     std::ostringstream message;                << 
238     message << "Solid " << name << " not found << 
239             << "Returning NULL pointer.";      << 
240     G4Exception("G4SolidStore::GetSolid()",    << 
241                 "GeomMgt1001", JustWarning, me << 
242   }                                               137   }
243   return nullptr;                              << 
244 }                                                 138 }
245                                                   139 
246 // *******************************************    140 // ***************************************************************************
247 // Return ptr to Store, setting if necessary      141 // Return ptr to Store, setting if necessary
248 // *******************************************    142 // ***************************************************************************
249 //                                                143 //
250 G4SolidStore* G4SolidStore::GetInstance()         144 G4SolidStore* G4SolidStore::GetInstance()
251 {                                                 145 {
252   static G4SolidStore worldStore;                 146   static G4SolidStore worldStore;
253   if (fgInstance == nullptr)                   << 147   if (!fgInstance)
254   {                                               148   {
255     fgInstance = &worldStore;                     149     fgInstance = &worldStore;
256   }                                               150   }
257   return fgInstance;                              151   return fgInstance;
258 }                                                 152 }
259                                                   153