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.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /persistency/ascii/src/G4tgrVolumeMgr.cc (Version 11.3.0) and /persistency/ascii/src/G4tgrVolumeMgr.cc (Version 6.0)


  1 //                                                  1 
  2 // *******************************************    
  3 // * License and Disclaimer                       
  4 // *                                              
  5 // * The  Geant4 software  is  copyright of th    
  6 // * the Geant4 Collaboration.  It is provided    
  7 // * conditions of the Geant4 Software License    
  8 // * LICENSE and available at  http://cern.ch/    
  9 // * include a list of copyright holders.         
 10 // *                                              
 11 // * Neither the authors of this software syst    
 12 // * institutes,nor the agencies providing fin    
 13 // * work  make  any representation or  warran    
 14 // * regarding  this  software system or assum    
 15 // * use.  Please see the license in the file     
 16 // * for the full disclaimer and the limitatio    
 17 // *                                              
 18 // * This  code  implementation is the result     
 19 // * technical work of the GEANT4 collaboratio    
 20 // * By using,  copying,  modifying or  distri    
 21 // * any work based  on the software)  you  ag    
 22 // * use  in  resulting  scientific  publicati    
 23 // * acceptance of all terms of the Geant4 Sof    
 24 // *******************************************    
 25 //                                                
 26 // G4tgrVolumeMgr implementation                  
 27 //                                                
 28 // Author: P.Arce, CIEMAT (November 2007)         
 29 // -------------------------------------------    
 30                                                   
 31 #include "G4tgrVolumeMgr.hh"                      
 32 #include "G4tgrUtils.hh"                          
 33 #include "G4tgrMaterialFactory.hh"                
 34 #include "G4tgrRotationMatrixFactory.hh"          
 35 #include "G4tgrFileReader.hh"                     
 36 #include "G4tgrMessenger.hh"                      
 37 #include "G4tgrSolid.hh"                          
 38 #include "G4tgrSolidBoolean.hh"                   
 39 #include "G4tgrSolidMultiUnion.hh"                
 40 #include "G4tgrSolidScaled.hh"                    
 41                                                   
 42 G4ThreadLocal G4tgrVolumeMgr* G4tgrVolumeMgr::    
 43                                                   
 44 // -------------------------------------------    
 45 G4tgrVolumeMgr::G4tgrVolumeMgr()                  
 46 {                                                 
 47 }                                                 
 48                                                   
 49 // -------------------------------------------    
 50 G4tgrVolumeMgr::~G4tgrVolumeMgr()                 
 51 {                                                 
 52   delete theInstance;                             
 53 }                                                 
 54                                                   
 55 // -------------------------------------------    
 56 G4tgrVolumeMgr* G4tgrVolumeMgr::GetInstance()     
 57 {                                                 
 58   if(theInstance == nullptr)                      
 59   {                                               
 60     theInstance = new G4tgrVolumeMgr;             
 61   }                                               
 62   return theInstance;                             
 63 }                                                 
 64                                                   
 65 // -------------------------------------------    
 66 G4tgrSolid* G4tgrVolumeMgr::CreateSolid(const     
 67                                         G4bool    
 68 {                                                 
 69   G4tgrSolid* sol = FindSolid(wl[1]);             
 70   if(sol != nullptr)                              
 71   {                                               
 72     G4String ErrMessage = "Solid already exist    
 73     G4Exception("G4tgrVolumeMgr::CreateSolid()    
 74                 ErrMessage);                      
 75   }                                               
 76                                                   
 77   std::vector<G4String> wlc = wl;                 
 78   if(bVOLUtag)                                    
 79   {                                               
 80     wlc.pop_back();                               
 81   }                                               
 82                                                   
 83   G4String wl2 = wlc[2];                          
 84   for(G4int ii = 0; ii < (G4int)wl2.length();     
 85   {                                               
 86     wl2[ii] = (char)std::toupper(wl2[ii]);        
 87   }                                               
 88   if((wl2 == "UNION") || (wl2 == "SUBTRACTION"    
 89   {                                               
 90     //---------- Boolean solid                    
 91     //---------- Create G4tgrSolidBoolean and     
 92     sol = new G4tgrSolidBoolean(wlc);             
 93   }                                               
 94   else if(wl2 == "SCALED")                        
 95   {                                               
 96     //---------- Create G4tgrSolidScaled and f    
 97     sol = new G4tgrSolidScaled(wlc);              
 98   }                                               
 99   else if(wl2 == "MULTIUNION")                    
100   {                                               
101     //---------- Create G4tgrSolidMultiUnion a    
102     sol = new G4tgrSolidMultiUnion(wlc);          
103   }                                               
104   else                                            
105   {                                               
106     //---------- Create G4tgrSolidSimple and f    
107     sol = new G4tgrSolid(wlc);                    
108   }                                               
109                                                   
110   return sol;                                     
111 }                                                 
112                                                   
113 // -------------------------------------------    
114 void G4tgrVolumeMgr::RegisterMe(G4tgrSolid* so    
115 {                                                 
116   if(theG4tgrSolidMap.find(sol->GetName()) !=     
117   {                                               
118     G4String ErrMessage =                         
119       "Cannot be two solids with the same name    
120     G4Exception("G4tgrVolumeMgr::RegisterMe()"    
121                 ErrMessage);                      
122   }                                               
123   theG4tgrSolidMap.insert(G4mapssol::value_typ    
124 }                                                 
125                                                   
126 // -------------------------------------------    
127 void G4tgrVolumeMgr::UnRegisterMe(G4tgrSolid*     
128 {                                                 
129   if(theG4tgrSolidMap.find(sol->GetName()) !=     
130   {                                               
131     G4String ErrMessage =                         
132       "Cannot unregister a solid that is not r    
133     G4Exception("G4tgrSolidMgr::unRegisterMe()    
134                 ErrMessage);                      
135   }                                               
136   else                                            
137   {                                               
138     theG4tgrSolidMap.erase(theG4tgrSolidMap.fi    
139   }                                               
140 }                                                 
141                                                   
142 // -------------------------------------------    
143 void G4tgrVolumeMgr::RegisterMe(G4tgrVolume* v    
144 {                                                 
145   theG4tgrVolumeList.push_back(vol);              
146   if(theG4tgrVolumeMap.find(vol->GetName()) !=    
147   {                                               
148     G4String ErrMessage =                         
149       "Cannot be two volumes with the same nam    
150     G4Exception("G4tgrVolumeMgr::RegisterMe()"    
151                 ErrMessage);                      
152   }                                               
153   theG4tgrVolumeMap.insert(G4mapsvol::value_ty    
154 }                                                 
155                                                   
156 // -------------------------------------------    
157 void G4tgrVolumeMgr::UnRegisterMe(G4tgrVolume*    
158 {                                                 
159   std::vector<G4tgrVolume*>::const_iterator it    
160   for(ite = theG4tgrVolumeList.cbegin();          
161       ite != theG4tgrVolumeList.cend(); ++ite)    
162   {                                               
163     if((*ite) == vol)                             
164     {                                             
165       break;                                      
166     }                                             
167   }                                               
168   if(ite == theG4tgrVolumeList.cend())            
169   {                                               
170     G4String ErrMessage =                         
171       "Cannot unregister a volume not register    
172     G4Exception("G4tgrVolumeMgr::unRegisterMe(    
173                 FatalException, ErrMessage);      
174   }                                               
175   else                                            
176   {                                               
177     theG4tgrVolumeList.erase(ite);                
178   }                                               
179   theG4tgrVolumeMap.erase(theG4tgrVolumeMap.fi    
180 }                                                 
181                                                   
182 // -------------------------------------------    
183 void G4tgrVolumeMgr::RegisterParentChild(const    
184                                          const    
185 {                                                 
186   theG4tgrVolumeTree.insert(G4mmapspl::value_t    
187 }                                                 
188                                                   
189 // -------------------------------------------    
190 G4tgrSolid* G4tgrVolumeMgr::FindSolid(const G4    
191 {                                                 
192   G4tgrSolid* vol = nullptr;                      
193                                                   
194   G4mapssol::const_iterator svite = theG4tgrSo    
195   if(svite == theG4tgrSolidMap.cend())            
196   {                                               
197     if(exists)                                    
198     {                                             
199       for(svite = theG4tgrSolidMap.cbegin();      
200           svite != theG4tgrSolidMap.cend(); ++    
201       {                                           
202         G4cerr << " VOL:" << (*svite).first <<    
203       }                                           
204       G4String ErrMessage = "Solid not found..    
205       G4Exception("G4tgrVolumeMgr::FindSolid()    
206                   ErrMessage);                    
207     }                                             
208   }                                               
209   else                                            
210   {                                               
211     vol = const_cast<G4tgrSolid*>((*svite).sec    
212   }                                               
213                                                   
214   return vol;                                     
215 }                                                 
216                                                   
217 // -------------------------------------------    
218 G4tgrVolume* G4tgrVolumeMgr::FindVolume(const     
219 {                                                 
220   G4tgrVolume* vol = nullptr;                     
221                                                   
222   G4mapsvol::const_iterator svite = theG4tgrVo    
223   if(svite == theG4tgrVolumeMap.cend())           
224   {                                               
225     if(exists)                                    
226     {                                             
227       for(svite = theG4tgrVolumeMap.cbegin();     
228           svite != theG4tgrVolumeMap.cend(); +    
229       {                                           
230         G4cerr << " VOL:" << (*svite).first <<    
231       }                                           
232       G4String ErrMessage = "Volume not found.    
233       G4Exception("G4tgrVolumeMgr::FindVolume(    
234                   FatalException, ErrMessage);    
235     }                                             
236     else                                          
237     {                                             
238       G4String WarMessage = "Volume does not e    
239       G4Exception("G4tgrVolumeMgr::FindVolume(    
240                   WarMessage);                    
241     }                                             
242   }                                               
243   else                                            
244   {                                               
245     vol = const_cast<G4tgrVolume*>((*svite).se    
246   }                                               
247                                                   
248   return vol;                                     
249 }                                                 
250                                                   
251 // -------------------------------------------    
252 std::vector<G4tgrVolume*> G4tgrVolumeMgr::Find    
253                                                   
254 {                                                 
255   std::vector<G4tgrVolume*> vols;                 
256                                                   
257   G4mapsvol::const_iterator svite;                
258   for(svite = theG4tgrVolumeMap.cbegin();         
259       svite != theG4tgrVolumeMap.cend(); ++svi    
260   {                                               
261     if(G4tgrUtils::AreWordsEquivalent(volname,    
262     {                                             
263       vols.push_back(const_cast<G4tgrVolume*>(    
264     }                                             
265   }                                               
266                                                   
267   if(vols.size() == 0)                            
268   {                                               
269     if(exists)                                    
270     {                                             
271       for(svite = theG4tgrVolumeMap.cbegin();     
272           svite != theG4tgrVolumeMap.cend(); +    
273       {                                           
274         G4cerr << " VOL:" << (*svite).first <<    
275       }                                           
276       G4String ErrMessage = "Volume not found.    
277       G4Exception("G4tgrVolumeMgr::FindVolumes    
278                   FatalException, ErrMessage);    
279     }                                             
280     else                                          
281     {                                             
282       G4String WarMessage = "Volume does not e    
283       G4Exception("G4tgrVolumeMgr::FindVolumes    
284                   WarMessage);                    
285     }                                             
286   }                                               
287                                                   
288   return vols;                                    
289 }                                                 
290                                                   
291 // -------------------------------------------    
292 const G4tgrVolume* G4tgrVolumeMgr::GetTopVolum    
293 {                                                 
294   //--- Start from any G4tgrVolume and go upwa    
295   //    Check that indeed all volumes drive to    
296                                                   
297   const G4tgrVolume* topVol = nullptr;            
298   for(auto itetv = theG4tgrVolumeMap.cbegin();    
299            itetv != theG4tgrVolumeMap.cend();     
300   {                                               
301     const G4tgrVolume* vol = (*itetv).second;     
302 #ifdef G4VERBOSE                                  
303     if(G4tgrMessenger::GetVerboseLevel() >= 3)    
304     {                                             
305       G4cout << " G4tgrVolumeMgr::GetTopVolume    
306              << " no place = " << vol->GetPlac    
307     }                                             
308 #endif                                            
309                                                   
310     while(vol->GetPlacements().size() != 0)       
311     {                                             
312       vol = FindVolume((*(vol->GetPlacements()    
313 #ifdef G4VERBOSE                                  
314       if(G4tgrMessenger::GetVerboseLevel() >=     
315       {                                           
316         G4cout << " G4tgrVolumeMgr::GetTopVolu    
317                << " N place = " << vol->GetPla    
318       }                                           
319 #endif                                            
320     }                                             
321     if((topVol != nullptr) && (topVol != vol)     
322        (topVol->GetType() != "VOLDivision") &&    
323        (vol->GetType() != "VOLDivision"))         
324     {                                             
325       G4Exception("G4tgrVolumeMgr::GetTopVolum    
326                   "Two world volumes found, se    
327                   (G4String("Both volumes are     
328                    topVol->GetName() + " & " +    
329                     .c_str());                    
330     }                                             
331     topVol = vol;                                 
332   }                                               
333                                                   
334   return topVol;                                  
335 }                                                 
336                                                   
337 // -------------------------------------------    
338 std::pair<G4mmapspl::iterator, G4mmapspl::iter    
339 G4tgrVolumeMgr::GetChildren(const G4String& na    
340 {                                                 
341   std::pair<G4mmapspl::iterator, G4mmapspl::it    
342   dite = theG4tgrVolumeTree.equal_range(name);    
343   return dite;                                    
344 }                                                 
345                                                   
346 // -------------------------------------------    
347 void G4tgrVolumeMgr::DumpVolumeTree()             
348 {                                                 
349   G4cout << " @@@@@@@@@@@@@@@@ DUMPING G4tgrVo    
350                                                   
351   const G4tgrVolume* vol = GetTopVolume();        
352                                                   
353   DumpVolumeLeaf(vol, 0, 0);                      
354 }                                                 
355                                                   
356 // -------------------------------------------    
357 void G4tgrVolumeMgr::DumpVolumeLeaf(const G4tg    
358                                     unsigned i    
359 {                                                 
360   for(std::size_t ii = 0; ii < leafDepth; ++ii    
361   {                                               
362     G4cout << "  ";                               
363   }                                               
364   G4cout << " VOL:(" << leafDepth << ")" << vo    
365          << copyNo << G4endl;                     
366                                                   
367   //---------- construct the children of this     
368   std::pair<G4mmapspl::iterator, G4mmapspl::it    
369     GetChildren(vol->GetName());                  
370   G4mmapspl::const_iterator cite;                 
371                                                   
372   ++leafDepth;                                    
373   for(cite = children.first; cite != children.    
374   {                                               
375     //---- find G4tgrVolume pointed by G4tgrPl    
376     const G4tgrPlace* pla       = (*cite).seco    
377     const G4tgrVolume* volchild = pla->GetVolu    
378     //--- find copyNo                             
379     unsigned int cn = pla->GetCopyNo();           
380     DumpVolumeLeaf(volchild, cn, leafDepth);      
381   }                                               
382 }                                                 
383                                                   
384 // -------------------------------------------    
385 void G4tgrVolumeMgr::DumpSummary()                
386 {                                                 
387   //---------- Dump number of objects of each     
388   G4cout << " @@@@@@@@@@@@@@@@@@ Dumping Detec    
389   G4cout << " @@@ Geometry built inside world     
390          << GetTopVolume()->GetName() << G4end    
391   G4cout << " Number of G4tgrVolume's: " << th    
392   unsigned int nPlace = 0;                        
393   for(auto cite = theG4tgrVolumeMap.cbegin();     
394       cite != theG4tgrVolumeMap.cend(); ++cite    
395   {                                               
396     nPlace += ((*cite).second)->GetPlacements(    
397   }                                               
398   G4cout << " Number of G4tgrPlace's: " << nPl    
399                                                   
400   G4tgrMaterialFactory* matef = G4tgrMaterialF    
401   G4cout << " Number of G4tgrIsotope's: " << m    
402          << G4endl;                               
403   G4cout << " Number of G4tgrElement's: " << m    
404          << G4endl;                               
405   G4cout << " Number of G4tgrMaterial's: " <<     
406          << G4endl;                               
407                                                   
408   G4tgrRotationMatrixFactory* rotmf = G4tgrRot    
409   G4cout << " Number of G4tgrRotationMatrix's:    
410          << rotmf->GetRotMatList().size() << G    
411                                                   
412   //---------- Dump detail list of objects of     
413   DumpVolumeTree();                               
414                                                   
415   matef->DumpIsotopeList();                       
416   matef->DumpElementList();                       
417   matef->DumpMaterialList();                      
418   rotmf->DumpRotmList();                          
419 }                                                 
420