Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4tgrVolumeMgr.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // $Id: G4tgrVolumeMgr.cc 66872 2013-01-15 01:25:57Z japost $
28 //
29 //
30 // class G4tgrVolumeMgr
31 
32 // History:
33 // - Created. P.Arce, CIEMAT (November 2007)
34 // -------------------------------------------------------------------------
35 
36 #include "G4tgrVolumeMgr.hh"
37 #include "G4tgrUtils.hh"
38 #include "G4tgrMaterialFactory.hh"
40 #include "G4tgrFileReader.hh"
41 #include "G4tgrMessenger.hh"
42 #include "G4tgrSolid.hh"
43 #include "G4tgrSolidBoolean.hh"
44 
45 
46 G4ThreadLocal G4tgrVolumeMgr* G4tgrVolumeMgr::theInstance = 0;
47 
48 
49 //-------------------------------------------------------------
50 G4tgrVolumeMgr::G4tgrVolumeMgr()
51 {
52 }
53 
54 
55 //-------------------------------------------------------------
56 G4tgrVolumeMgr::~G4tgrVolumeMgr()
57 {
58  delete theInstance;
59 }
60 
61 
62 //-------------------------------------------------------------
64 {
65  if( !theInstance )
66  {
67  theInstance = new G4tgrVolumeMgr;
68  }
69  return theInstance;
70 }
71 
72 
73 //-------------------------------------------------------------------
75 G4tgrVolumeMgr::CreateSolid( const std::vector<G4String>& wl, G4bool bVOLUtag )
76 {
77  G4tgrSolid* sol = FindSolid( wl[1] );
78  if( sol )
79  {
80  G4String ErrMessage = "Solid already exists... " + wl[1];
81  G4Exception("G4tgrVolumeMgr::CreateSolid()", "InvalidSetup",
82  FatalException, ErrMessage);
83  }
84 
85  std::vector<G4String> wlc = wl;
86  if( bVOLUtag ) { wlc.pop_back(); }
87 
88  G4String wl2 = wlc[2];
89  for( size_t ii = 0; ii < wl2.length(); ii++ )
90  {
91  wl2[ii] = toupper( wl2[ii] );
92  }
93  if( (wl2 == "UNION") || (wl2 == "SUBTRACTION") || (wl2 == "INTERSECTION") )
94  {
95  //---------- Boolean solid
96  //---------- Create G4tgrSolidBoolean and fill the solid params
97  sol = new G4tgrSolidBoolean( wlc );
98  }
99  else
100  {
101  //---------- Create G4tgrSolidSimple and fill the solid params
102  sol = new G4tgrSolid( wlc );
103  }
104 
105  return sol;
106 }
107 
108 //-------------------------------------------------------------------
110 {
111  if( theG4tgrSolidMap.find( sol->GetName() ) != theG4tgrSolidMap.end() )
112  {
113  G4String ErrMessage = "Cannot be two solids with the same name... "
114  + sol->GetName();
115  G4Exception("G4tgrVolumeMgr::RegisterMe()", "InvalidSetup",
116  FatalException, ErrMessage);
117  }
118  theG4tgrSolidMap.insert(G4mapssol::value_type(sol->GetName(), sol) );
119 }
120 
121 
122 //-------------------------------------------------------------
124 {
125  if( theG4tgrSolidMap.find( sol->GetName() ) != theG4tgrSolidMap.end() )
126  {
127  G4String ErrMessage = "Cannot unregister a solid that is not registered... "
128  + sol->GetName();
129  G4Exception("G4tgrSolidMgr::unRegisterMe()", "InvalidSetup",
130  FatalException, ErrMessage);
131  }
132  else
133  {
134  theG4tgrSolidMap.erase( theG4tgrSolidMap.find( sol->GetName() ) );
135  }
136 }
137 
138 
139 //-------------------------------------------------------------
141 {
142  theG4tgrVolumeList.push_back( vol );
143  if( theG4tgrVolumeMap.find( vol->GetName() ) != theG4tgrVolumeMap.end() )
144  {
145  G4String ErrMessage = "Cannot be two volumes with the same name... "
146  + vol->GetName();
147  G4Exception("G4tgrVolumeMgr::RegisterMe()", "InvalidSetup",
148  FatalException, ErrMessage);
149  }
150  theG4tgrVolumeMap.insert(G4mapsvol::value_type(vol->GetName(), vol) );
151 }
152 
153 
154 //-------------------------------------------------------------
156 {
157  std::vector<G4tgrVolume*>::iterator ite;
158  for(ite = theG4tgrVolumeList.begin(); ite != theG4tgrVolumeList.end(); ite++)
159  {
160  if((*ite) == vol ) { break; }
161  }
162  if( ite == theG4tgrVolumeList.end() )
163  {
164  G4String ErrMessage = "Cannot unregister a volume not registered... "
165  + vol->GetName();
166  G4Exception("G4tgrVolumeMgr::unRegisterMe()", "InvalidSetup",
167  FatalException, ErrMessage);
168  }
169  else
170  {
171  theG4tgrVolumeList.erase( ite );
172  }
173  theG4tgrVolumeMap.erase( theG4tgrVolumeMap.find( vol->GetName() ) );
174 }
175 
176 
177 //-------------------------------------------------------------
178 
180  const G4tgrPlace* pl )
181 {
182  theG4tgrVolumeTree.insert(G4mmapspl::value_type(parentName, pl) );
183 }
184 
185 
186 //-------------------------------------------------------------
188 {
189  G4tgrSolid* vol = 0;
190 
191  G4mapssol::iterator svite = theG4tgrSolidMap.find( volname );
192  if( svite == theG4tgrSolidMap.end() )
193  {
194  if( exists )
195  {
196  for( svite = theG4tgrSolidMap.begin();
197  svite != theG4tgrSolidMap.end(); svite++ )
198  {
199  G4cerr << " VOL:" << (*svite).first << G4endl;
200  }
201  G4String ErrMessage = "Solid not found... " + volname;
202  G4Exception("G4tgrVolumeMgr::FindSolid()", "InvalidSetup",
203  FatalException, ErrMessage);
204  }
205  }
206  else
207  {
208  vol = const_cast<G4tgrSolid*>((*svite).second);
209  }
210 
211  return vol;
212 }
213 
214 
215 //-------------------------------------------------------------
217 G4tgrVolumeMgr::FindVolume( const G4String& volname, G4bool exists )
218 {
219  G4tgrVolume* vol = 0;
220 
221  G4mapsvol::iterator svite = theG4tgrVolumeMap.find( volname );
222  if( svite == theG4tgrVolumeMap.end() )
223  {
224  if( exists )
225  {
226  for( svite = theG4tgrVolumeMap.begin();
227  svite != theG4tgrVolumeMap.end(); svite++ )
228  {
229  G4cerr << " VOL:" << (*svite).first << G4endl;
230  }
231  G4String ErrMessage = "Volume not found... " + volname;
232  G4Exception("G4tgrVolumeMgr::FindVolume()", "InvalidSetup",
233  FatalException, ErrMessage);
234  }
235  else
236  {
237  G4String WarMessage = "Volume does not exists... " + volname;
238  G4Exception("G4tgrVolumeMgr::FindVolume()", "SearchFailed",
239  JustWarning, WarMessage);
240  }
241  }
242  else
243  {
244  vol = const_cast<G4tgrVolume*>((*svite).second);
245  }
246 
247  return vol;
248 }
249 
250 //-------------------------------------------------------------
251 std::vector<G4tgrVolume*>
252 G4tgrVolumeMgr::FindVolumes( const G4String& volname, G4bool exists )
253 {
254  std::vector<G4tgrVolume*> vols;
255 
256  G4mapsvol::iterator svite;
257  for( svite = theG4tgrVolumeMap.begin();
258  svite != theG4tgrVolumeMap.end(); svite++ )
259  {
260  if( G4tgrUtils::AreWordsEquivalent( volname, (*svite).second->GetName()) )
261  {
262  vols.push_back(const_cast<G4tgrVolume*>((*svite).second) );
263  }
264  }
265 
266  if( vols.size() == 0 )
267  {
268  if( exists )
269  {
270  for( svite = theG4tgrVolumeMap.begin();
271  svite != theG4tgrVolumeMap.end(); svite++ )
272  {
273  G4cerr << " VOL:" << (*svite).first << G4endl;
274  }
275  G4String ErrMessage = "Volume not found... " + volname;
276  G4Exception("G4tgrVolumeMgr::FindVolumes()", "InvalidSetup",
277  FatalException, ErrMessage);
278  }
279  else
280  {
281  G4String WarMessage = "Volume does not exists... " + volname;
282  G4Exception("G4tgrVolumeMgr::FindVolumes()", "SearchFailed",
283  JustWarning, WarMessage);
284  }
285  }
286 
287  return vols;
288 }
289 
290 
291 //-------------------------------------------------------------
293 {
294  //--- Start from any G4tgrVolume and go upwards until you get to the top.
295  // Check that indeed all volumes drive to the same top volume
296 
297  const G4tgrVolume* topVol = 0;
298  G4mapsvol::const_iterator itetv;
299  for( itetv = theG4tgrVolumeMap.begin();
300  itetv != theG4tgrVolumeMap.end(); itetv++ )
301  {
302  const G4tgrVolume* vol = (*itetv).second;
303 #ifdef G4VERBOSE
305  {
306  G4cout << " G4tgrVolumeMgr::GetTopVolume() - Vol: "
307  << vol->GetName() << " no place = "
308  << vol->GetPlacements().size() << G4endl;
309  }
310 #endif
311 
312  while( vol->GetPlacements().size() != 0 )
313  {
314  vol = FindVolume((*(vol->GetPlacements()).begin())->GetParentName(), 1);
315 #ifdef G4VERBOSE
317  {
318  G4cout << " G4tgrVolumeMgr::GetTopVolume() - Vol: "
319  << vol->GetName()<< " N place = "
320  << vol->GetPlacements().size() << G4endl;
321  }
322 #endif
323  }
324  if ( (topVol != 0) && (topVol != vol)
325  && (topVol->GetType() != "VOLDivision")
326  && (vol->GetType() != "VOLDivision") )
327  {
328  G4Exception("G4tgrVolumeMgr::GetTopVolume()",
329  "Two world volumes found, second will be taken", JustWarning,
330  (G4String("Both volumes are at the top of a hierarchy: ")
331  + topVol->GetName() + " & " + vol->GetName() ).c_str());
332  }
333  topVol = vol;
334  }
335 
336  return topVol;
337 }
338 
339 
340 //-------------------------------------------------------------
341 std::pair<G4mmapspl::iterator, G4mmapspl::iterator>
343 {
344  std::pair<G4mmapspl::iterator, G4mmapspl::iterator> dite;
345  dite = theG4tgrVolumeTree.equal_range( name );
346  return dite;
347 }
348 
349 
350 //-------------------------------------------------------------
352 {
353  G4cout << " @@@@@@@@@@@@@@@@ DUMPING G4tgrVolume's Tree " << G4endl;
354 
355  const G4tgrVolume* vol = GetTopVolume();
356 
357  DumpVolumeLeaf( vol, 0, 0);
358 }
359 
360 
361 //-------------------------------------------------------------
363  unsigned int copyNo,
364  unsigned int leafDepth)
365 {
366  for( size_t ii=0; ii < leafDepth; ii++ )
367  {
368  G4cout << " ";
369  }
370  G4cout << " VOL:(" << leafDepth << ")" << vol->GetName()
371  << " copy No " << copyNo << G4endl;
372 
373  //---------- construct the children of this VOL
374  std::pair<G4mmapspl::iterator, G4mmapspl::iterator> children
375  = GetChildren( vol->GetName() );
376  G4mmapspl::const_iterator cite;
377 
378  leafDepth++;
379  for( cite = children.first; cite != children.second; cite++ )
380  {
381  //---- find G4tgrVolume pointed by G4tgrPlace
382  const G4tgrPlace* pla = (*cite).second;
383  const G4tgrVolume* volchild = pla->GetVolume();
384  //--- find copyNo
385  unsigned int cn = pla->GetCopyNo();
386  DumpVolumeLeaf( volchild, cn, leafDepth );
387  }
388 }
389 
390 
391 //-------------------------------------------------------------
393 {
394  //---------- Dump number of objects of each class
395  G4cout << " @@@@@@@@@@@@@@@@@@ Dumping Detector Summary " << G4endl;
396  G4cout << " @@@ Geometry built inside world volume: "
397  << GetTopVolume()->GetName() << G4endl;
398  G4cout << " Number of G4tgrVolume's: "
399  << theG4tgrVolumeMap.size() << G4endl;
400  G4mapsvol::const_iterator cite;
401  unsigned int nPlace = 0;
402  for( cite = theG4tgrVolumeMap.begin();
403  cite != theG4tgrVolumeMap.end(); cite++ )
404  {
405  nPlace += ((*cite).second)->GetPlacements().size();
406  }
407  G4cout << " Number of G4tgrPlace's: " << nPlace << G4endl;
408 
410  G4cout << " Number of G4tgrIsotope's: "
411  << matef->GetIsotopeList().size() << G4endl;
412  G4cout << " Number of G4tgrElement's: "
413  << matef->GetElementList().size() << G4endl;
414  G4cout << " Number of G4tgrMaterial's: "
415  << matef->GetMaterialList().size() << G4endl;
416 
418  G4cout << " Number of G4tgrRotationMatrix's: "
419  << rotmf->GetRotMatList().size() << G4endl;
420 
421 
422  //---------- Dump detail list of objects of each class
423  DumpVolumeTree();
424 
425  matef->DumpIsotopeList();
426  matef->DumpElementList();
427  matef->DumpMaterialList();
428  rotmf->DumpRotmList();
429 }
const std::vector< G4tgrPlace * > GetPlacements() const
Definition: G4tgrVolume.hh:95
const XML_Char * name
Definition: expat.h:151
G4tgrSolid * FindSolid(const G4String &name, G4bool exists=false)
const G4mstgrisot & GetIsotopeList() const
G4tgrVolume * GetVolume() const
Definition: G4tgrPlace.hh:59
const G4mstgrmate & GetMaterialList() const
void UnRegisterMe(G4tgrSolid *vol)
static G4bool AreWordsEquivalent(const G4String &word1, const G4String &word2)
Definition: G4tgrUtils.cc:672
#define G4ThreadLocal
Definition: tls.hh:89
std::vector< G4tgrVolume * > FindVolumes(const G4String &volname, G4bool exists)
static G4tgrRotationMatrixFactory * GetInstance()
tuple pl
Definition: readPY.py:5
G4GLOB_DLL std::ostream G4cout
static G4int GetVerboseLevel()
bool G4bool
Definition: G4Types.hh:79
const G4String & GetName() const
Definition: G4tgrSolid.hh:61
static G4tgrVolumeMgr * GetInstance()
G4tgrVolume * FindVolume(const G4String &volname, G4bool exists=false)
void RegisterMe(G4tgrSolid *vol)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
const G4String & GetType() const
Definition: G4tgrVolume.hh:91
void DumpVolumeLeaf(const G4tgrVolume *vol, unsigned int copyNo, unsigned int leafDepth)
std::vector< G4tgrRotationMatrix * > GetRotMatList() const
unsigned int GetCopyNo() const
Definition: G4tgrPlace.hh:60
G4tgrSolid * CreateSolid(const std::vector< G4String > &wl, G4bool bVOLUtag)
void RegisterParentChild(const G4String &parentName, const G4tgrPlace *pl)
#define G4endl
Definition: G4ios.hh:61
const G4tgrVolume * GetTopVolume()
const G4mstgrelem & GetElementList() const
static G4tgrMaterialFactory * GetInstance()
const G4String & GetName() const
Definition: G4tgrVolume.hh:89
std::pair< G4mmapspl::iterator, G4mmapspl::iterator > GetChildren(const G4String &name)
G4GLOB_DLL std::ostream G4cerr