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 9.0)


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