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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/biasing/src/G4IStore.cc (Version 11.3.0) and /geometry/biasing/src/G4IStore.cc (Version 10.6.p1)


  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 // G4IStore implementation                         26 // G4IStore implementation
 27 //                                                 27 //
 28 // Author: Michael Dressel (CERN), 2002            28 // Author: Michael Dressel (CERN), 2002
 29 // Modified: Alex Howard (CERN), 2013 - Change     29 // Modified: Alex Howard (CERN), 2013 - Changed class to a 'singleton'
 30 // -------------------------------------------     30 // ----------------------------------------------------------------------
 31                                                    31 
 32 #include "G4IStore.hh"                             32 #include "G4IStore.hh"
 33 #include "G4VPhysicalVolume.hh"                    33 #include "G4VPhysicalVolume.hh"
 34 #include "G4GeometryCell.hh"                       34 #include "G4GeometryCell.hh"
 35 #include "G4GeometryCellStepStream.hh"             35 #include "G4GeometryCellStepStream.hh"
 36 #include "G4LogicalVolume.hh"                      36 #include "G4LogicalVolume.hh"
 37 #include "G4TransportationManager.hh"              37 #include "G4TransportationManager.hh"
 38                                                    38 
 39 #include "G4AutoLock.hh"                       <<  39 #ifdef G4MULTITHREADED
 40                                                <<  40 G4Mutex G4IStore::IStoreMutex = G4MUTEX_INITIALIZER;
 41 namespace                                      <<  41 #endif
 42 {                                              << 
 43   G4Mutex IStoreMutex = G4MUTEX_INITIALIZER;   << 
 44 }                                              << 
 45                                                    42 
 46 // *******************************************     43 // ***************************************************************************
 47 // Static class variable: ptr to single instan     44 // Static class variable: ptr to single instance of class
 48 // *******************************************     45 // ***************************************************************************
 49 G4ThreadLocal G4IStore* G4IStore::fInstance =      46 G4ThreadLocal G4IStore* G4IStore::fInstance = nullptr;
 50                                                    47 
 51 G4IStore::G4IStore()                               48 G4IStore::G4IStore()
 52   : fWorldVolume(G4TransportationManager::GetT     49   : fWorldVolume(G4TransportationManager::GetTransportationManager()
 53                  ->GetNavigatorForTracking()->     50                  ->GetNavigatorForTracking()->GetWorldVolume())
 54 {                                                  51 {
 55 }                                                  52 }
 56                                                    53 
 57 G4IStore::G4IStore(const G4String& ParallelWor     54 G4IStore::G4IStore(const G4String& ParallelWorldName)
 58   : fWorldVolume(G4TransportationManager::GetT     55   : fWorldVolume(G4TransportationManager::GetTransportationManager()
 59                  ->GetParallelWorld(ParallelWo     56                  ->GetParallelWorld(ParallelWorldName))
 60 {                                                  57 {
 61 #ifdef G4VERBOSE                                   58 #ifdef G4VERBOSE
 62   G4cout << " G4IStore:: ParallelWorldName = "     59   G4cout << " G4IStore:: ParallelWorldName = "
 63          << ParallelWorldName << G4endl;           60          << ParallelWorldName << G4endl;
 64   G4cout << " G4IStore:: fParallelWorldVolume      61   G4cout << " G4IStore:: fParallelWorldVolume = "
 65          << fWorldVolume->GetName() << G4endl;     62          << fWorldVolume->GetName() << G4endl;
 66 #endif                                             63 #endif
 67 }                                                  64 }
 68                                                    65 
 69 G4IStore::~G4IStore() = default;               <<  66 G4IStore::~G4IStore()
                                                   >>  67 {
                                                   >>  68 }
 70                                                    69 
 71 void G4IStore::Clear()                             70 void G4IStore::Clear()
 72 {                                                  71 {
 73   fGeometryCelli.clear();                          72   fGeometryCelli.clear();
 74 }                                                  73 }
 75                                                    74 
 76 void G4IStore::SetWorldVolume()                    75 void G4IStore::SetWorldVolume()
 77 {                                                  76 {
 78   G4cout << " G4IStore:: SetWorldVolume " << G     77   G4cout << " G4IStore:: SetWorldVolume " << G4endl;
 79   fWorldVolume = G4TransportationManager::GetT     78   fWorldVolume = G4TransportationManager::GetTransportationManager()
 80                  ->GetNavigatorForTracking()->     79                  ->GetNavigatorForTracking()->GetWorldVolume();
 81   G4cout << " World volume is: " << fWorldVolu     80   G4cout << " World volume is: " << fWorldVolume->GetName() << G4endl;
 82   // fGeometryCelli = new G4GeometryCellImport     81   // fGeometryCelli = new G4GeometryCellImportance;
 83 }                                                  82 }
 84                                                    83 
 85 void G4IStore::SetParallelWorldVolume(const G4     84 void G4IStore::SetParallelWorldVolume(const G4String& paraName)
 86 {                                                  85 {
 87   G4cout << " G4IStore:: SetParallelWorldVolum     86   G4cout << " G4IStore:: SetParallelWorldVolume " << G4endl;
 88   fWorldVolume = G4TransportationManager::GetT     87   fWorldVolume = G4TransportationManager::GetTransportationManager()
 89                  ->GetParallelWorld(paraName);     88                  ->GetParallelWorld(paraName);
 90   G4cout << " ParallelWorld volume is: " << fW     89   G4cout << " ParallelWorld volume is: " << fWorldVolume->GetName() << G4endl;
 91   // fGeometryCelli = new G4GeometryCellImport     90   // fGeometryCelli = new G4GeometryCellImportance;
 92 }                                                  91 }
 93                                                    92 
 94 const G4VPhysicalVolume& G4IStore::GetWorldVol     93 const G4VPhysicalVolume& G4IStore::GetWorldVolume() const
 95 {                                                  94 {
 96   return *fWorldVolume;                            95   return *fWorldVolume;
 97 }                                                  96 }
 98                                                    97 
 99 const G4VPhysicalVolume* G4IStore::GetParallel     98 const G4VPhysicalVolume* G4IStore::GetParallelWorldVolumePointer() const
100 {                                                  99 {
101   return fWorldVolume;                            100   return fWorldVolume;
102 }                                                 101 }
103                                                   102 
104 void G4IStore::SetInternalIterator(const G4Geo    103 void G4IStore::SetInternalIterator(const G4GeometryCell& gCell) const
105 {                                                 104 {
106   fCurrentIterator = fGeometryCelli.find(gCell    105   fCurrentIterator = fGeometryCelli.find(gCell);
107 }                                                 106 }
108                                                   107 
109 void G4IStore::AddImportanceGeometryCell(G4dou    108 void G4IStore::AddImportanceGeometryCell(G4double importance,
110                                          const    109                                          const G4GeometryCell& gCell)
111 {                                                 110 {
112   if (importance < 0 )                            111   if (importance < 0 )
113   {                                               112   {
114     Error("AddImportanceGeometryCell() - Inval    113     Error("AddImportanceGeometryCell() - Invalid importance value given.");
115   }                                               114   }  
116   if (!IsInWorld(gCell.GetPhysicalVolume()) )     115   if (!IsInWorld(gCell.GetPhysicalVolume()) )
117   {                                               116   {
118     Error("AddImportanceGeometryCell() - Physi    117     Error("AddImportanceGeometryCell() - Physical volume not found!");
119   }                                               118   }
120   SetInternalIterator(gCell);                     119   SetInternalIterator(gCell);
121   if (fCurrentIterator != fGeometryCelli.cend(    120   if (fCurrentIterator != fGeometryCelli.cend())
122   {                                               121   {
123     Error("AddImportanceGeometryCell() - Regio    122     Error("AddImportanceGeometryCell() - Region already existing!");
124   }                                               123   }
125   fGeometryCelli[gCell] = importance;             124   fGeometryCelli[gCell] = importance;
126 }                                                 125 }
127                                                   126 
128 void G4IStore::AddImportanceGeometryCell(G4dou    127 void G4IStore::AddImportanceGeometryCell(G4double importance,
129                                          const    128                                          const G4VPhysicalVolume& aVolume,
130                                          G4int    129                                          G4int aRepNum)
131 {                                                 130 {
132   AddImportanceGeometryCell(importance, G4Geom    131   AddImportanceGeometryCell(importance, G4GeometryCell(aVolume, aRepNum));
133 }                                                 132 }
134                                                   133 
135 void G4IStore::ChangeImportance(G4double impor    134 void G4IStore::ChangeImportance(G4double importance,
136                                 const G4Geomet    135                                 const G4GeometryCell& gCell)
137 {                                                 136 {
138   if (importance < 0 )                            137   if (importance < 0 )
139   {                                               138   {
140     Error("ChangeImportance() - Invalid import    139     Error("ChangeImportance() - Invalid importance value given.");
141   }                                               140   }
142   if (!IsInWorld(gCell.GetPhysicalVolume()))      141   if (!IsInWorld(gCell.GetPhysicalVolume()))
143   {                                               142   {
144     Error("ChangeImportance() - Physical volum    143     Error("ChangeImportance() - Physical volume not found!");
145   }                                               144   }
146   SetInternalIterator(gCell);                     145   SetInternalIterator(gCell);
147   if (fCurrentIterator == fGeometryCelli.cend(    146   if (fCurrentIterator == fGeometryCelli.cend())
148   {                                               147   {
149     Error("ChangeImportance() - Region does no    148     Error("ChangeImportance() - Region does not exist!");
150   }                                               149   }
151   fGeometryCelli[gCell] = importance;             150   fGeometryCelli[gCell] = importance;
152                                                   151 
153 }                                                 152 }
154                                                   153 
155 void G4IStore::ChangeImportance(G4double impor    154 void G4IStore::ChangeImportance(G4double importance,
156                                 const G4VPhysi    155                                 const G4VPhysicalVolume& aVolume,
157                                 G4int aRepNum)    156                                 G4int aRepNum)
158 {                                                 157 {
159   ChangeImportance(importance, G4GeometryCell(    158   ChangeImportance(importance, G4GeometryCell(aVolume, aRepNum));
160 }                                                 159 }
161                                                   160 
162 G4double G4IStore::GetImportance(const G4VPhys    161 G4double G4IStore::GetImportance(const G4VPhysicalVolume& aVolume,
163                                  G4int aRepNum    162                                  G4int aRepNum) const
164 {                                                 163 {  
165   G4AutoLock l(&IStoreMutex);                  << 164 #ifdef G4MULTITHREADED
                                                   >> 165   G4MUTEXLOCK(&G4IStore::IStoreMutex);
                                                   >> 166 #endif
166   SetInternalIterator(G4GeometryCell(aVolume,     167   SetInternalIterator(G4GeometryCell(aVolume, aRepNum));
167   auto gCellIterator = fCurrentIterator;          168   auto gCellIterator = fCurrentIterator;
168   if (gCellIterator == fGeometryCelli.cend())     169   if (gCellIterator == fGeometryCelli.cend())
169   {                                               170   {
170     Error("GetImportance() - Region does not e    171     Error("GetImportance() - Region does not exist!");
171     return 0.;                                    172     return 0.;
172   }                                               173   }
173   G4double importance_value = (*fCurrentIterat    174   G4double importance_value = (*fCurrentIterator).second;
174   l.unlock();                                  << 175 #ifdef G4MULTITHREADED
175                                                << 176   G4MUTEXUNLOCK(&G4IStore::IStoreMutex);
                                                   >> 177 #endif
176   return importance_value;                        178   return importance_value;
177 }                                                 179 }
178                                                   180 
179 G4double G4IStore::GetImportance(const G4Geome    181 G4double G4IStore::GetImportance(const G4GeometryCell& gCell) const
180 {                                                 182 {
181   G4AutoLock l(&IStoreMutex);                  << 183 #ifdef G4MULTITHREADED
                                                   >> 184   G4MUTEXLOCK(&G4IStore::IStoreMutex);
                                                   >> 185 #endif
182   SetInternalIterator(gCell);                     186   SetInternalIterator(gCell);
183   auto gCellIterator = fCurrentIterator;          187   auto gCellIterator = fCurrentIterator;
184   if (gCellIterator == fGeometryCelli.cend())     188   if (gCellIterator == fGeometryCelli.cend())
185   {                                               189   {
186     std::ostringstream err_mess;                  190     std::ostringstream err_mess;
187     err_mess << "GetImportance() - Region does    191     err_mess << "GetImportance() - Region does not exist!" << G4endl
188              << "Geometry cell, " << gCell        192              << "Geometry cell, " << gCell
189              << ", not found in: " << fGeometr    193              << ", not found in: " << fGeometryCelli << ".";
190     Error(err_mess.str());                        194     Error(err_mess.str());
191     return 0.;                                    195     return 0.;
192   }                                               196   }
193   G4double importance_value = (*fCurrentIterat    197   G4double importance_value = (*fCurrentIterator).second;
194   l.unlock();                                  << 198 #ifdef G4MULTITHREADED
195                                                << 199   G4MUTEXUNLOCK(&G4IStore::IStoreMutex);
                                                   >> 200 #endif
196   return importance_value;                        201   return importance_value;
                                                   >> 202   // return (*fCurrentIterator).second;
197 }                                                 203 }
198                                                   204 
199 G4bool G4IStore::IsKnown(const G4GeometryCell&    205 G4bool G4IStore::IsKnown(const G4GeometryCell& gCell) const
200 {                                                 206 {
201   G4AutoLock l(&IStoreMutex);                  << 207 #ifdef G4MULTITHREADED
                                                   >> 208   G4MUTEXLOCK(&G4IStore::IStoreMutex);
                                                   >> 209 #endif
202   G4bool inWorldKnown(IsInWorld(gCell.GetPhysi    210   G4bool inWorldKnown(IsInWorld(gCell.GetPhysicalVolume()));
203                                                   211                       
204   if ( inWorldKnown )                             212   if ( inWorldKnown )
205   {                                               213   {
206     SetInternalIterator(gCell);                   214     SetInternalIterator(gCell);
207     inWorldKnown = (fCurrentIterator != fGeome    215     inWorldKnown = (fCurrentIterator != fGeometryCelli.cend());
208   }                                               216   }
209   l.unlock();                                  << 217 #ifdef G4MULTITHREADED
210                                                << 218   G4MUTEXUNLOCK(&G4IStore::IStoreMutex);
                                                   >> 219 #endif
211   return inWorldKnown;                            220   return inWorldKnown;
212 }                                                 221 }
213                                                   222 
214 G4bool G4IStore::IsInWorld(const G4VPhysicalVo    223 G4bool G4IStore::IsInWorld(const G4VPhysicalVolume& aVolume) const
215 {                                                 224 {
216   G4bool isIn(true);                              225   G4bool isIn(true);
217   if (!(aVolume == *fWorldVolume))                226   if (!(aVolume == *fWorldVolume))
218   {                                               227   {
219     isIn = fWorldVolume->GetLogicalVolume()->I    228     isIn = fWorldVolume->GetLogicalVolume()->IsAncestor(&aVolume);
220   }                                               229   }
221   return isIn;                                    230   return isIn;
222 }                                                 231 }
223                                                   232 
224 void G4IStore::Error(const G4String& msg) cons    233 void G4IStore::Error(const G4String& msg) const
225 {                                                 234 {
226   G4Exception("G4IStore::Error()", "GeomBias00    235   G4Exception("G4IStore::Error()", "GeomBias0002", FatalException, msg);
227 }                                                 236 }
228                                                   237 
229 // *******************************************    238 // ***************************************************************************
230 // Returns the instance of the singleton.         239 // Returns the instance of the singleton.
231 // Creates it in case it's called for the firs    240 // Creates it in case it's called for the first time.
232 // *******************************************    241 // ***************************************************************************
233 //                                                242 //
234 G4IStore* G4IStore::GetInstance()                 243 G4IStore* G4IStore::GetInstance()
235 {                                                 244 {
236   if (fInstance == nullptr)                       245   if (fInstance == nullptr)
237   {                                               246   {
238 #ifdef G4VERBOSE                                  247 #ifdef G4VERBOSE
239     G4cout << "G4IStore:: Creating new MASS IS    248     G4cout << "G4IStore:: Creating new MASS IStore " << G4endl;
240 #endif                                            249 #endif
241     fInstance = new G4IStore();                   250     fInstance = new G4IStore();
242   }                                               251   }
243   return fInstance;                               252   return fInstance;    
244 }                                                 253 }
245                                                   254 
246 // *******************************************    255 // ***************************************************************************
247 // Returns the instance of the singleton.         256 // Returns the instance of the singleton.
248 // Creates it in case it's called for the firs    257 // Creates it in case it's called for the first time.
249 // *******************************************    258 // ***************************************************************************
250 //                                                259 //
251 G4IStore* G4IStore::GetInstance(const G4String    260 G4IStore* G4IStore::GetInstance(const G4String& ParallelWorldName)
252 {                                                 261 {
253   if (fInstance == nullptr)                       262   if (fInstance == nullptr)
254   {                                               263   {
255 #ifdef G4VERBOSE                                  264 #ifdef G4VERBOSE
256     G4cout << "G4IStore:: Creating new Paralle    265     G4cout << "G4IStore:: Creating new Parallel IStore "
257            << ParallelWorldName << G4endl;        266            << ParallelWorldName << G4endl;
258 #endif                                            267 #endif
259     fInstance = new G4IStore(ParallelWorldName    268     fInstance = new G4IStore(ParallelWorldName);
260   }                                               269   }
261   return fInstance;                               270   return fInstance;    
262 }                                                 271 }
263                                                   272