Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/geometry/management/src/G4Region.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.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/G4Region.cc (Version 11.3.0) and /geometry/management/src/G4Region.cc (Version 10.0.p2)


  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 //
                                                   >>  26 //
                                                   >>  27 // $Id: G4Region.cc 81594 2014-06-03 14:05:18Z gcosmo $
                                                   >>  28 //
 25 //                                                 29 // 
 26 // G4Region class implementation               <<  30 // class G4Region Implementation
 27 //                                                 31 //
 28 // 18.09.02, G.Cosmo - Initial version         << 
 29 // -------------------------------------------     32 // --------------------------------------------------------------------
 30                                                    33 
 31 #include "G4Region.hh"                             34 #include "G4Region.hh"
 32 #include "G4RegionStore.hh"                        35 #include "G4RegionStore.hh"
 33 #include "G4LogicalVolume.hh"                      36 #include "G4LogicalVolume.hh"
 34 #include "G4VPhysicalVolume.hh"                    37 #include "G4VPhysicalVolume.hh"
 35 #include "G4LogicalVolumeStore.hh"                 38 #include "G4LogicalVolumeStore.hh"
 36 #include "G4VNestedParameterisation.hh"            39 #include "G4VNestedParameterisation.hh"
 37 #include "G4VUserRegionInformation.hh"             40 #include "G4VUserRegionInformation.hh"
 38 #include "G4Material.hh"                           41 #include "G4Material.hh"
 39                                                    42 
 40 // These macros changes the references to fiel <<  43 // This static member is thread local. For each thread, it points to the
 41 // in the class G4RegionData.                  <<  44 // array of G4RegionData instances.
 42 //                                                 45 //
 43 #define G4MT_fsmanager ((subInstanceManager.of <<  46 template <class G4RegionData> G4ThreadLocal
 44 #define G4MT_rsaction ((subInstanceManager.off <<  47 G4RegionData* G4GeomSplitter<G4RegionData>::offset = 0;  
 45                                                    48 
 46 // This new field helps to use the class G4Reg     49 // This new field helps to use the class G4RegionManager
 47 //                                                 50 //
 48 G4RegionManager G4Region::subInstanceManager;      51 G4RegionManager G4Region::subInstanceManager;
 49                                                    52 
 50 // *******************************************     53 // *******************************************************************
 51 // GetSubInstanceManager:                          54 // GetSubInstanceManager:
 52 //  - Returns the private data instance manage     55 //  - Returns the private data instance manager.
 53 // *******************************************     56 // *******************************************************************
 54 //                                                 57 //
 55 const G4RegionManager& G4Region::GetSubInstanc     58 const G4RegionManager& G4Region::GetSubInstanceManager()
 56 {                                                  59 {
 57   return subInstanceManager;                       60   return subInstanceManager;
 58 }                                                  61 }
 59                                                    62 
 60 // *******************************************     63 // *******************************************************************
 61 // Constructor:                                    64 // Constructor:
 62 //  - Adds self to region Store                    65 //  - Adds self to region Store
 63 // *******************************************     66 // *******************************************************************
 64 //                                                 67 //
 65 G4Region::G4Region(const G4String& pName)          68 G4Region::G4Region(const G4String& pName)
 66   : fName(pName)                               <<  69   : fName(pName), fRegionMod(true), fCut(0), fUserInfo(0), fUserLimits(0),
                                                   >>  70     fFieldManager(0), fWorldPhys(0),
                                                   >>  71     fInMassGeometry(false), fInParallelGeometry(false)
 67 {                                                  72 {
 68                                                    73 
 69   instanceID = subInstanceManager.CreateSubIns     74   instanceID = subInstanceManager.CreateSubInstance();
 70   G4MT_fsmanager = nullptr;                    <<  75   G4MT_fsmanager = 0;
 71   G4MT_rsaction = nullptr;                     <<  76   G4MT_rsaction = 0;
 72                                                    77 
 73   G4RegionStore* rStore = G4RegionStore::GetIn     78   G4RegionStore* rStore = G4RegionStore::GetInstance();
 74   if (rStore->GetRegion(pName, false) != nullp <<  79   if (rStore->GetRegion(pName,false))
 75   {                                                80   {
 76     std::ostringstream message;                    81     std::ostringstream message;
 77     message << "The region has NOT been regist     82     message << "The region has NOT been registered !" << G4endl
 78             << "          Region " << pName <<     83             << "          Region " << pName << " already existing in store !"
 79             << G4endl;                             84             << G4endl;
 80     G4Exception("G4Region::G4Region()", "GeomM     85     G4Exception("G4Region::G4Region()", "GeomMgt1001",
 81                 JustWarning, message);             86                 JustWarning, message);
 82   }                                                87   }
 83   else                                             88   else
 84   {                                                89   {
 85     rStore->Register(this);                        90     rStore->Register(this);
 86   }                                                91   }
 87 }                                                  92 }
 88                                                    93 
 89 // *******************************************     94 // ********************************************************************
 90 // Fake default constructor - sets only member     95 // Fake default constructor - sets only member data and allocates memory
 91 //                            for usage restri     96 //                            for usage restricted to object persistency.
 92 // *******************************************     97 // ********************************************************************
 93 //                                                 98 //
 94 G4Region::G4Region( __void__& )                    99 G4Region::G4Region( __void__& )
 95   : fName("")                                  << 100   : fName(""), fRegionMod(true), fCut(0), fUserInfo(0), fUserLimits(0),
                                                   >> 101     fFieldManager(0), fWorldPhys(0),
                                                   >> 102     fInMassGeometry(false), fInParallelGeometry(false)
 96 {                                                 103 {
 97   instanceID = subInstanceManager.CreateSubIns    104   instanceID = subInstanceManager.CreateSubInstance();
 98   G4MT_fsmanager = nullptr;                    << 105   G4MT_fsmanager = 0;
 99   G4MT_rsaction = nullptr;                     << 106   G4MT_rsaction = 0;
100                                                   107 
101   // Register to store                            108   // Register to store
102   //                                              109   //
103   G4RegionStore::GetInstance()->Register(this)    110   G4RegionStore::GetInstance()->Register(this);
104 }                                                 111 }
105                                                   112 
106 // *******************************************    113 // *******************************************************************
107 // Destructor:                                    114 // Destructor:
108 //  - Removes self from region Store              115 //  - Removes self from region Store
109 // *******************************************    116 // *******************************************************************
110 //                                                117 //
111 G4Region::~G4Region()                             118 G4Region::~G4Region()
112 {                                                 119 {
113   G4RegionStore::GetInstance()->DeRegister(thi    120   G4RegionStore::GetInstance()->DeRegister(this);
114   delete fUserInfo;                            << 121   if(fUserInfo) delete fUserInfo;
115 }                                              << 
116                                                << 
117 // ******************************************* << 
118 // SetName - Set region name and notify store  << 
119 // ******************************************* << 
120 //                                             << 
121 void G4Region::SetName(const G4String& pName)  << 
122 {                                              << 
123   fName = pName;                               << 
124   G4RegionStore::GetInstance()->SetMapValid(fa << 
125 }                                              << 
126                                                << 
127 // ******************************************* << 
128 // SetFastSimulationManager                    << 
129 // ******************************************* << 
130 //                                             << 
131 void G4Region::SetFastSimulationManager(G4Fast << 
132 {                                              << 
133   G4MT_fsmanager = fsm;                        << 
134 }                                              << 
135                                                << 
136 // ******************************************* << 
137 // GetFastSimulationManager                    << 
138 // ******************************************* << 
139 //                                             << 
140 G4FastSimulationManager* G4Region::GetFastSimu << 
141 {                                              << 
142   return G4MT_fsmanager;                       << 
143 }                                              << 
144                                                << 
145 // ******************************************* << 
146 // SetRegionalSteppingAction                   << 
147 // ******************************************* << 
148 //                                             << 
149 void G4Region::SetRegionalSteppingAction(G4Use << 
150 {                                              << 
151   G4MT_rsaction = rusa;                        << 
152 }                                              << 
153                                                << 
154 // ******************************************* << 
155 // GetRegionalSteppingAction                   << 
156 // ******************************************* << 
157 //                                             << 
158 G4UserSteppingAction* G4Region::GetRegionalSte << 
159 {                                              << 
160   return G4MT_rsaction;                        << 
161 }                                                 122 }
162                                                   123 
163 // *******************************************    124 // *******************************************************************
164 // ScanVolumeTree:                                125 // ScanVolumeTree:
165 //  - Scans recursively the 'lv' logical volum    126 //  - Scans recursively the 'lv' logical volume tree, retrieves
166 //    and places all materials in the list.       127 //    and places all materials in the list.
167 //  - The boolean flag 'region' identifies if     128 //  - The boolean flag 'region' identifies if the volume tree must
168 //    have region reset (false) or if the curr    129 //    have region reset (false) or if the current region must be
169 //    associated to the logical volume 'lv' an    130 //    associated to the logical volume 'lv' and its tree (true).
170 // *******************************************    131 // *******************************************************************
171 //                                                132 //
172 void G4Region::ScanVolumeTree(G4LogicalVolume*    133 void G4Region::ScanVolumeTree(G4LogicalVolume* lv, G4bool region)
173 {                                                 134 {
174   // If logical volume is going to become a re    135   // If logical volume is going to become a region, add 
175   // its material to the list if not already p    136   // its material to the list if not already present
176   //                                              137   //
177   G4Region* currentRegion = nullptr;           << 138   G4Region* currentRegion = 0;
178   std::size_t noDaughters = lv->GetNoDaughters << 139   size_t noDaughters = lv->GetNoDaughters();
179   G4Material* volMat = lv->GetMaterial();         140   G4Material* volMat = lv->GetMaterial();
180   if((volMat == nullptr) && fInMassGeometry)   << 141   if(!volMat && fInMassGeometry)
181   {                                               142   {
182     std::ostringstream message;                   143     std::ostringstream message;
183     message << "Logical volume <" << lv->GetNa    144     message << "Logical volume <" << lv->GetName() << ">" << G4endl
184             << "does not have a valid material    145             << "does not have a valid material pointer." << G4endl
185             << "A logical volume belonging to     146             << "A logical volume belonging to the (tracking) world volume "
186             << "must have a valid material.";     147             << "must have a valid material.";
187     G4Exception("G4Region::ScanVolumeTree()",     148     G4Exception("G4Region::ScanVolumeTree()", "GeomMgt0002",
188                 FatalException, message, "Chec    149                 FatalException, message, "Check your geometry construction.");
189   }                                               150   }
190   if (region)                                     151   if (region)
191   {                                               152   {
192     currentRegion = this;                         153     currentRegion = this;
193     if (volMat != nullptr)                     << 154     if (volMat)
194     {                                             155     { 
195       AddMaterial(volMat);                        156       AddMaterial(volMat); 
196       auto  baseMat = const_cast<G4Material*>( << 157       G4Material* baseMat = const_cast<G4Material*>(volMat->GetBaseMaterial());
197       if (baseMat != nullptr) { AddMaterial(ba << 158       if (baseMat) { AddMaterial(baseMat); }
198     }                                             159     }
199   }                                               160   }
200                                                   161 
201   // Set the LV region to be either the curren    162   // Set the LV region to be either the current region or NULL,
202   // according to the boolean selector            163   // according to the boolean selector
203   //                                              164   //
204   lv->SetRegion(currentRegion);                   165   lv->SetRegion(currentRegion);
205                                                   166 
206   // Stop recursion here if no further daughte    167   // Stop recursion here if no further daughters are involved
207   //                                              168   //
208   if(noDaughters==0) return;                      169   if(noDaughters==0) return;
209                                                   170 
210   G4VPhysicalVolume* daughterPVol = lv->GetDau    171   G4VPhysicalVolume* daughterPVol = lv->GetDaughter(0);
211   if (daughterPVol->IsParameterised())            172   if (daughterPVol->IsParameterised())
212   {                                               173   {
213     // Adopt special treatment in case of para    174     // Adopt special treatment in case of parameterised volumes,
214     // where parameterisation involves a new m    175     // where parameterisation involves a new material scan
215     //                                            176     //
216     G4VPVParameterisation* pParam = daughterPV    177     G4VPVParameterisation* pParam = daughterPVol->GetParameterisation();
217                                                   178 
218     if (pParam->GetMaterialScanner() != nullpt << 179     if (pParam->GetMaterialScanner())
219     {                                             180     {
220       std::size_t matNo = pParam->GetMaterialS << 181       size_t matNo = pParam->GetMaterialScanner()->GetNumberOfMaterials();
221       for (std::size_t mat=0; mat<matNo; ++mat << 182       for (size_t mat=0; mat<matNo; mat++)
222       {                                           183       {
223         volMat = pParam->GetMaterialScanner()- << 184         volMat = pParam->GetMaterialScanner()->GetMaterial(mat);
224         if((volMat == nullptr) && fInMassGeome << 185         if(!volMat && fInMassGeometry)
225         {                                         186         {
226           std::ostringstream message;             187           std::ostringstream message;
227           message << "The parameterisation for    188           message << "The parameterisation for the physical volume <"
228                   << daughterPVol->GetName() <    189                   << daughterPVol->GetName() << ">" << G4endl
229                   << "does not return a valid     190                   << "does not return a valid material pointer." << G4endl
230                   << "A volume belonging to th    191                   << "A volume belonging to the (tracking) world volume must "
231                   << "have a valid material.";    192                   << "have a valid material.";
232           G4Exception("G4Region::ScanVolumeTre    193           G4Exception("G4Region::ScanVolumeTree()", "GeomMgt0002",
233                       FatalException, message,    194                       FatalException, message, "Check your parameterisation.");
234         }                                         195         }
235         if (volMat != nullptr)                 << 196         if (volMat)
236         {                                         197         { 
237           AddMaterial(volMat);                    198           AddMaterial(volMat); 
238           auto  baseMat = const_cast<G4Materia << 199           G4Material* baseMat = const_cast<G4Material*>(volMat->GetBaseMaterial());
239           if (baseMat != nullptr) { AddMateria << 200           if (baseMat) { AddMaterial(baseMat); }
240         }                                         201         }
241       }                                           202       }
242     }                                             203     }
243     else                                          204     else
244     {                                             205     {
245       std::size_t repNo = daughterPVol->GetMul << 206       size_t repNo = daughterPVol->GetMultiplicity();
246       for (std::size_t rep=0; rep<repNo; ++rep << 207       for (size_t rep=0; rep<repNo; rep++)
247       {                                           208       {
248         volMat = pParam->ComputeMaterial((G4in << 209         volMat = pParam->ComputeMaterial(rep, daughterPVol);
249         if((volMat == nullptr) && fInMassGeome << 210         if(!volMat && fInMassGeometry)
250         {                                         211         {
251           std::ostringstream message;             212           std::ostringstream message;
252           message << "The parameterisation for    213           message << "The parameterisation for the physical volume <"
253                   << daughterPVol->GetName() <    214                   << daughterPVol->GetName() << ">" << G4endl
254                   << "does not return a valid     215                   << "does not return a valid material pointer." << G4endl
255                   << "A volume belonging to th    216                   << "A volume belonging to the (tracking) world volume must "
256                   << "have a valid material.";    217                   << "have a valid material.";
257           G4Exception("G4Region::ScanVolumeTre    218           G4Exception("G4Region::ScanVolumeTree()", "GeomMgt0002",
258                       FatalException, message,    219                       FatalException, message, "Check your parameterisation.");
259         }                                         220         }
260         if(volMat != nullptr)                  << 221         if(volMat)
261         {                                         222         { 
262           AddMaterial(volMat);                    223           AddMaterial(volMat);
263           auto  baseMat = const_cast<G4Materia << 224           G4Material* baseMat = const_cast<G4Material*>(volMat->GetBaseMaterial());
264           if (baseMat != nullptr) { AddMateria << 225           if (baseMat) { AddMaterial(baseMat); }
265         }                                         226         }
266       }                                           227       }
267     }                                             228     }
268     G4LogicalVolume* daughterLVol = daughterPV    229     G4LogicalVolume* daughterLVol = daughterPVol->GetLogicalVolume();
269     ScanVolumeTree(daughterLVol, region);         230     ScanVolumeTree(daughterLVol, region);
270   }                                               231   }
271   else                                            232   else
272   {                                               233   {
273     for (std::size_t i=0; i<noDaughters; ++i)  << 234     for (size_t i=0; i<noDaughters; i++)
274     {                                             235     {
275       G4LogicalVolume* daughterLVol = lv->GetD    236       G4LogicalVolume* daughterLVol = lv->GetDaughter(i)->GetLogicalVolume();
276       if (!daughterLVol->IsRootRegion())          237       if (!daughterLVol->IsRootRegion())
277       {                                           238       {
278         // Set daughter's LV to be a region an    239         // Set daughter's LV to be a region and store materials in
279         // the materials list, if the LV is no    240         // the materials list, if the LV is not already a root region
280         //                                        241         //
281         ScanVolumeTree(daughterLVol, region);     242         ScanVolumeTree(daughterLVol, region);
282       }                                           243       }
283     }                                             244     }
284   }                                               245   }
285 }                                                 246 }
286                                                   247 
287 // *******************************************    248 // *******************************************************************
288 // AddRootLogicalVolume:                          249 // AddRootLogicalVolume:
289 //  - Adds a root logical volume and sets its     250 //  - Adds a root logical volume and sets its daughters flags as
290 //    regions. It also recomputes the material    251 //    regions. It also recomputes the materials list for the region.
291 // *******************************************    252 // *******************************************************************
292 //                                                253 //
293 void G4Region::AddRootLogicalVolume(G4LogicalV << 254 void G4Region::AddRootLogicalVolume(G4LogicalVolume* lv)
294 {                                                 255 {
295   // Check if logical volume is already belong << 
296   //                                           << 
297   if ((lv->IsRootRegion()) && (lv->GetRegion() << 
298   {                                            << 
299     std::ostringstream message;                << 
300     message << "Logical volume <" << lv->GetNa << 
301             << "root for region <" << lv->GetR << 
302             << "It cannot be root logical volu << 
303             << ">" << G4endl;                  << 
304     G4Exception("G4Region::AddRootLogicalVolum << 
305                 message, "A logical volume can << 
306     return;                                    << 
307   }                                            << 
308                                                << 
309   // Check the logical volume is not already i    256   // Check the logical volume is not already in the list
310   //                                              257   //
311   if (search)                                  << 258   G4RootLVList::iterator pos;
                                                   >> 259   pos = std::find(fRootVolumes.begin(),fRootVolumes.end(),lv);
                                                   >> 260   if (pos == fRootVolumes.end())
312   {                                               261   {
313     auto pos = std::find(fRootVolumes.cbegin() << 262     // Insert the root volume in the list and set it as root region
314     if (pos == fRootVolumes.cend())            << 263     //
315     {                                          << 
316       // Insert the root volume in the list an << 
317       //                                       << 
318       fRootVolumes.push_back(lv);              << 
319       lv->SetRegionRootFlag(true);             << 
320     }                                          << 
321   }                                            << 
322   else  // WARNING: user *MUST* guarantee lv i << 
323   {     // Providing speedup for very complex  << 
324     fRootVolumes.push_back(lv);                   264     fRootVolumes.push_back(lv);
325     lv->SetRegionRootFlag(true);                  265     lv->SetRegionRootFlag(true);
326   }                                               266   }
                                                   >> 267 
327   // Scan recursively the tree of daugther vol    268   // Scan recursively the tree of daugther volumes and set regions
328   //                                              269   //
329   ScanVolumeTree(lv, true);                       270   ScanVolumeTree(lv, true);
330                                                   271 
331   // Set region as modified                       272   // Set region as modified
332   //                                              273   //
333   fRegionMod = true;                              274   fRegionMod = true;
334 }                                                 275 }
335                                                   276 
336 // *******************************************    277 // *******************************************************************
337 // RemoveRootLogicalVolume:                       278 // RemoveRootLogicalVolume:
338 //  - Removes a root logical volume and resets    279 //  - Removes a root logical volume and resets its daughters flags as
339 //    regions. It also recomputes the material    280 //    regions. It also recomputes the materials list for the region.
340 // *******************************************    281 // *******************************************************************
341 //                                                282 //
342 void G4Region::RemoveRootLogicalVolume(G4Logic    283 void G4Region::RemoveRootLogicalVolume(G4LogicalVolume* lv, G4bool scan)
343 {                                                 284 {
344   // Find and remove logical volume from the l    285   // Find and remove logical volume from the list
345   //                                              286   //
346   auto pos = std::find(fRootVolumes.cbegin(),f << 287   G4RootLVList::iterator pos;
347   if (pos != fRootVolumes.cend())              << 288   pos = std::find(fRootVolumes.begin(),fRootVolumes.end(),lv);
                                                   >> 289   if (pos != fRootVolumes.end())
348   {                                               290   {
349     if (fRootVolumes.size() != 1)  // Avoid re    291     if (fRootVolumes.size() != 1)  // Avoid resetting flag for world since
350     {                              // volume m    292     {                              // volume may be already deleted !
351       lv->SetRegionRootFlag(false);               293       lv->SetRegionRootFlag(false);
352     }                                             294     }
353     fRootVolumes.erase(pos);                      295     fRootVolumes.erase(pos);
354   }                                               296   }
355                                                   297 
356   if (scan)  // Update the materials list         298   if (scan)  // Update the materials list
357   {                                               299   {
358     UpdateMaterialList();                         300     UpdateMaterialList();
359   }                                               301   }
360                                                   302 
361   // Set region as modified                       303   // Set region as modified
362   //                                              304   //
363   fRegionMod = true;                              305   fRegionMod = true;
364 }                                                 306 }
365                                                   307 
366 // ******************************************* << 
367 // Clean                                       << 
368 // ******************************************* << 
369 //                                             << 
370 void G4Region::Clean()                         << 
371 {                                              << 
372   subInstanceManager.FreeSlave();              << 
373 }                                              << 
374                                                << 
375 // *******************************************    308 // *******************************************************************
376 // ClearMaterialList:                             309 // ClearMaterialList:
377 //  - Clears the material list.                   310 //  - Clears the material list.
378 // *******************************************    311 // *******************************************************************
379 //                                                312 //
380 void G4Region::ClearMaterialList()                313 void G4Region::ClearMaterialList()
381 {                                                 314 {
382   fMaterials.clear();                             315   fMaterials.clear();
383 }                                                 316 }
384                                                   317 
385 // *******************************************    318 // *******************************************************************
386 // UpdateMaterialList:                            319 // UpdateMaterialList:
387 //  - computes material list looping through      320 //  - computes material list looping through
388 //    each root logical volume in the region.     321 //    each root logical volume in the region.
389 // *******************************************    322 // *******************************************************************
390 //                                                323 //
391 void G4Region::UpdateMaterialList()               324 void G4Region::UpdateMaterialList()
392 {                                                 325 {
393   // Reset the materials list                     326   // Reset the materials list
394   //                                              327   //
395   ClearMaterialList();                            328   ClearMaterialList();
396                                                   329 
397   // Loop over the root logical volumes and re    330   // Loop over the root logical volumes and rebuild the list
398   // of materials from scratch                    331   // of materials from scratch
399   //                                              332   //
400   for (auto pLV=fRootVolumes.cbegin(); pLV!=fR << 333   G4RootLVList::iterator pLV;
                                                   >> 334   for (pLV=fRootVolumes.begin(); pLV!=fRootVolumes.end(); pLV++)
401   {                                               335   {
402     ScanVolumeTree(*pLV, true);                   336     ScanVolumeTree(*pLV, true);
403   }                                               337   }
404 }                                                 338 }
405                                                   339 
406 // *******************************************    340 // *******************************************************************
407 // SetWorld:                                      341 // SetWorld:
408 //  - Set the world physical volume if this re    342 //  - Set the world physical volume if this region belongs to this
409 //    world. If the given pointer is null, res    343 //    world. If the given pointer is null, reset the pointer.
410 // *******************************************    344 // *******************************************************************
411 //                                                345 //
412 void G4Region::SetWorld(G4VPhysicalVolume* wp)    346 void G4Region::SetWorld(G4VPhysicalVolume* wp)
413 {                                                 347 {
414   if(wp == nullptr)                            << 348   if(!wp)
415   { fWorldPhys = nullptr; }                    << 349   { fWorldPhys = 0; }
416   else                                            350   else
417   { if(BelongsTo(wp)) fWorldPhys = wp; }          351   { if(BelongsTo(wp)) fWorldPhys = wp; }
418                                                   352 
419   return;                                         353   return;
420 }                                                 354 }
421                                                   355 
422 // *******************************************    356 // *******************************************************************
423 // BelongsTo:                                     357 // BelongsTo:
424 //  - Returns whether this region belongs to t    358 //  - Returns whether this region belongs to the given physical volume
425 //    (recursively scanned to the bottom of th    359 //    (recursively scanned to the bottom of the hierarchy)
426 // *******************************************    360 // *******************************************************************
427 //                                                361 // 
428 G4bool G4Region::BelongsTo(G4VPhysicalVolume*     362 G4bool G4Region::BelongsTo(G4VPhysicalVolume* thePhys) const
429 {                                                 363 {
430   G4LogicalVolume* currLog = thePhys->GetLogic    364   G4LogicalVolume* currLog = thePhys->GetLogicalVolume();
431   if (currLog->GetRegion()==this) {return true    365   if (currLog->GetRegion()==this) {return true;}
432                                                   366 
433   std::size_t nDaughters = currLog->GetNoDaugh << 367   G4int nDaughters = currLog->GetNoDaughters();
434   while ((nDaughters--) != 0)  // Loop checkin << 368   while (nDaughters--)
435   {                                               369   {
436     if (BelongsTo(currLog->GetDaughter(nDaught    370     if (BelongsTo(currLog->GetDaughter(nDaughters))) {return true;}
437   }                                               371   }
438                                                   372 
439   return false;                                   373   return false;
440 }                                                 374 }
441                                                   375 
442 // *******************************************    376 // *******************************************************************
443 // ClearFastSimulationManager:                    377 // ClearFastSimulationManager:
444 //  - Set G4FastSimulationManager pointer to t    378 //  - Set G4FastSimulationManager pointer to the one for the parent region
445 //    if it exists. Otherwise set to null.        379 //    if it exists. Otherwise set to null.
446 // *******************************************    380 // *******************************************************************
447 //                                                381 //
448 void G4Region::ClearFastSimulationManager()       382 void G4Region::ClearFastSimulationManager()
449 {                                                 383 {
450   G4bool isUnique;                                384   G4bool isUnique;
451   G4Region* parent = GetParentRegion(isUnique)    385   G4Region* parent = GetParentRegion(isUnique);
452   if(parent != nullptr)                        << 386   if(parent)
453   {                                               387   {
454     if (isUnique)                                 388     if (isUnique)
455     {                                             389     {
456       G4MT_fsmanager = parent->GetFastSimulati    390       G4MT_fsmanager = parent->GetFastSimulationManager();
457     }                                             391     }
458     else                                          392     else
459     {                                             393     {
460       std::ostringstream message;                 394       std::ostringstream message;
461       message << "Region <" << fName << "> bel    395       message << "Region <" << fName << "> belongs to more than"
462               << " one parent region !" << G4e    396               << " one parent region !" << G4endl
463               << "A region cannot belong to mo    397               << "A region cannot belong to more than one direct parent region,"
464               << G4endl                           398               << G4endl
465               << "to have fast-simulation assi    399               << "to have fast-simulation assigned.";
466       G4Exception("G4Region::ClearFastSimulati    400       G4Exception("G4Region::ClearFastSimulationManager()",
467                   "GeomMgt1002", JustWarning,     401                   "GeomMgt1002", JustWarning, message);
468       G4MT_fsmanager = nullptr;                << 402       G4MT_fsmanager = 0;
469     }                                             403     }
470   }                                               404   }
471   else                                            405   else
472   {                                               406   {
473     G4MT_fsmanager = nullptr;                  << 407     G4MT_fsmanager = 0;
474   }                                               408   }
475 }                                                 409 }
476                                                   410 
477 // *******************************************    411 // *******************************************************************
478 // GetParentRegion:                               412 // GetParentRegion:
479 //  - Returns a region that contains this regi    413 //  - Returns a region that contains this region.
480 //    Otherwise null is returned.                 414 //    Otherwise null is returned.
481 // *******************************************    415 // *******************************************************************
482 //                                                416 // 
483 G4Region* G4Region::GetParentRegion(G4bool& un    417 G4Region* G4Region::GetParentRegion(G4bool& unique) const
484 {                                                 418 {
485   G4Region* parent = nullptr; unique = true;   << 419   G4Region* parent = 0; unique = true;
486   G4LogicalVolumeStore* lvStore = G4LogicalVol    420   G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();
                                                   >> 421   G4LogicalVolumeStore::iterator lvItr;
487                                                   422 
488   // Loop over all logical volumes in the stor    423   // Loop over all logical volumes in the store
489   //                                              424   //
490   for(auto lvItr=lvStore->cbegin(); lvItr!=lvS << 425   for(lvItr=lvStore->begin(); lvItr!=lvStore->end(); lvItr++)
491   {                                               426   {
492     std::size_t nD = (*lvItr)->GetNoDaughters( << 427     G4int nD = (*lvItr)->GetNoDaughters();
493     G4Region* aR = (*lvItr)->GetRegion();         428     G4Region* aR = (*lvItr)->GetRegion();
494                                                   429 
495     // Loop over all daughters of each logical    430     // Loop over all daughters of each logical volume
496     //                                            431     //
497     for(std::size_t iD=0; iD<nD; ++iD)         << 432     for(G4int iD=0; iD<nD; iD++)
498     {                                             433     {
499       if((*lvItr)->GetDaughter(iD)->GetLogical    434       if((*lvItr)->GetDaughter(iD)->GetLogicalVolume()->GetRegion()==this)
500       {                                           435       { 
501         if(parent != nullptr)                  << 436         if(parent)
502         {                                         437         {
503           if(parent!=aR) { unique = false; }      438           if(parent!=aR) { unique = false; }
504         }                                         439         }
505         else  // Cache LV parent region which     440         else  // Cache LV parent region which includes a daughter volume
506               // with the same associated regi    441               // with the same associated region as the current one
507         {                                         442         {
508           parent = aR;                            443           parent = aR;
509         }                                         444         }
510       }                                           445       }
511     }                                             446     }
512   }                                               447   }
513   return parent;                                  448   return parent;
514 }                                                 449 }
515                                                   450