ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4tgrVolumeMgr.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4tgrVolumeMgr.cc
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 //
28 //
29 // class G4tgrVolumeMgr
30 
31 // History:
32 // - Created. P.Arce, CIEMAT (November 2007)
33 // -------------------------------------------------------------------------
34 
35 #include "G4tgrVolumeMgr.hh"
36 #include "G4tgrUtils.hh"
37 #include "G4tgrMaterialFactory.hh"
39 #include "G4tgrFileReader.hh"
40 #include "G4tgrMessenger.hh"
41 #include "G4tgrSolid.hh"
42 #include "G4tgrSolidBoolean.hh"
43 
44 
46 
47 
48 //-------------------------------------------------------------
50 {
51 }
52 
53 
54 //-------------------------------------------------------------
56 {
57  delete theInstance;
58 }
59 
60 
61 //-------------------------------------------------------------
63 {
64  if( !theInstance )
65  {
67  }
68  return theInstance;
69 }
70 
71 
72 //-------------------------------------------------------------------
74 G4tgrVolumeMgr::CreateSolid( const std::vector<G4String>& wl, G4bool bVOLUtag )
75 {
76  G4tgrSolid* sol = FindSolid( wl[1] );
77  if( sol )
78  {
79  G4String ErrMessage = "Solid already exists... " + wl[1];
80  G4Exception("G4tgrVolumeMgr::CreateSolid()", "InvalidSetup",
81  FatalException, ErrMessage);
82  }
83 
84  std::vector<G4String> wlc = wl;
85  if( bVOLUtag ) { wlc.pop_back(); }
86 
87  G4String wl2 = wlc[2];
88  for( size_t ii = 0; ii < wl2.length(); ii++ )
89  {
90  wl2[ii] = toupper( wl2[ii] );
91  }
92  if( (wl2 == "UNION") || (wl2 == "SUBTRACTION") || (wl2 == "INTERSECTION") )
93  {
94  //---------- Boolean solid
95  //---------- Create G4tgrSolidBoolean and fill the solid params
96  sol = new G4tgrSolidBoolean( wlc );
97  }
98  else
99  {
100  //---------- Create G4tgrSolidSimple and fill the solid params
101  sol = new G4tgrSolid( wlc );
102  }
103 
104  return sol;
105 }
106 
107 //-------------------------------------------------------------------
109 {
110  if( theG4tgrSolidMap.find( sol->GetName() ) != theG4tgrSolidMap.end() )
111  {
112  G4String ErrMessage = "Cannot be two solids with the same name... "
113  + sol->GetName();
114  G4Exception("G4tgrVolumeMgr::RegisterMe()", "InvalidSetup",
115  FatalException, ErrMessage);
116  }
117  theG4tgrSolidMap.insert(G4mapssol::value_type(sol->GetName(), sol) );
118 }
119 
120 
121 //-------------------------------------------------------------
123 {
124  if( theG4tgrSolidMap.find( sol->GetName() ) != theG4tgrSolidMap.end() )
125  {
126  G4String ErrMessage = "Cannot unregister a solid that is not registered... "
127  + sol->GetName();
128  G4Exception("G4tgrSolidMgr::unRegisterMe()", "InvalidSetup",
129  FatalException, ErrMessage);
130  }
131  else
132  {
133  theG4tgrSolidMap.erase( theG4tgrSolidMap.find( sol->GetName() ) );
134  }
135 }
136 
137 
138 //-------------------------------------------------------------
140 {
141  theG4tgrVolumeList.push_back( vol );
142  if( theG4tgrVolumeMap.find( vol->GetName() ) != theG4tgrVolumeMap.end() )
143  {
144  G4String ErrMessage = "Cannot be two volumes with the same name... "
145  + vol->GetName();
146  G4Exception("G4tgrVolumeMgr::RegisterMe()", "InvalidSetup",
147  FatalException, ErrMessage);
148  }
149  theG4tgrVolumeMap.insert(G4mapsvol::value_type(vol->GetName(), vol) );
150 }
151 
152 
153 //-------------------------------------------------------------
155 {
156  std::vector<G4tgrVolume*>::iterator ite;
157  for(ite = theG4tgrVolumeList.begin(); ite != theG4tgrVolumeList.end(); ite++)
158  {
159  if((*ite) == vol ) { break; }
160  }
161  if( ite == theG4tgrVolumeList.end() )
162  {
163  G4String ErrMessage = "Cannot unregister a volume not registered... "
164  + vol->GetName();
165  G4Exception("G4tgrVolumeMgr::unRegisterMe()", "InvalidSetup",
166  FatalException, ErrMessage);
167  }
168  else
169  {
170  theG4tgrVolumeList.erase( ite );
171  }
172  theG4tgrVolumeMap.erase( theG4tgrVolumeMap.find( vol->GetName() ) );
173 }
174 
175 
176 //-------------------------------------------------------------
177 
179  const G4tgrPlace* pl )
180 {
181  theG4tgrVolumeTree.insert(G4mmapspl::value_type(parentName, pl) );
182 }
183 
184 
185 //-------------------------------------------------------------
187 {
188  G4tgrSolid* vol = 0;
189 
190  G4mapssol::iterator svite = theG4tgrSolidMap.find( volname );
191  if( svite == theG4tgrSolidMap.end() )
192  {
193  if( exists )
194  {
195  for( svite = theG4tgrSolidMap.begin();
196  svite != theG4tgrSolidMap.end(); svite++ )
197  {
198  G4cerr << " VOL:" << (*svite).first << G4endl;
199  }
200  G4String ErrMessage = "Solid not found... " + volname;
201  G4Exception("G4tgrVolumeMgr::FindSolid()", "InvalidSetup",
202  FatalException, ErrMessage);
203  }
204  }
205  else
206  {
207  vol = const_cast<G4tgrSolid*>((*svite).second);
208  }
209 
210  return vol;
211 }
212 
213 
214 //-------------------------------------------------------------
217 {
218  G4tgrVolume* vol = 0;
219 
220  G4mapsvol::iterator svite = theG4tgrVolumeMap.find( volname );
221  if( svite == theG4tgrVolumeMap.end() )
222  {
223  if( exists )
224  {
225  for( svite = theG4tgrVolumeMap.begin();
226  svite != theG4tgrVolumeMap.end(); svite++ )
227  {
228  G4cerr << " VOL:" << (*svite).first << G4endl;
229  }
230  G4String ErrMessage = "Volume not found... " + volname;
231  G4Exception("G4tgrVolumeMgr::FindVolume()", "InvalidSetup",
232  FatalException, ErrMessage);
233  }
234  else
235  {
236  G4String WarMessage = "Volume does not exists... " + volname;
237  G4Exception("G4tgrVolumeMgr::FindVolume()", "SearchFailed",
238  JustWarning, WarMessage);
239  }
240  }
241  else
242  {
243  vol = const_cast<G4tgrVolume*>((*svite).second);
244  }
245 
246  return vol;
247 }
248 
249 //-------------------------------------------------------------
250 std::vector<G4tgrVolume*>
252 {
253  std::vector<G4tgrVolume*> vols;
254 
255  G4mapsvol::iterator svite;
256  for( svite = theG4tgrVolumeMap.begin();
257  svite != theG4tgrVolumeMap.end(); svite++ )
258  {
259  if( G4tgrUtils::AreWordsEquivalent( volname, (*svite).second->GetName()) )
260  {
261  vols.push_back(const_cast<G4tgrVolume*>((*svite).second) );
262  }
263  }
264 
265  if( vols.size() == 0 )
266  {
267  if( exists )
268  {
269  for( svite = theG4tgrVolumeMap.begin();
270  svite != theG4tgrVolumeMap.end(); svite++ )
271  {
272  G4cerr << " VOL:" << (*svite).first << G4endl;
273  }
274  G4String ErrMessage = "Volume not found... " + volname;
275  G4Exception("G4tgrVolumeMgr::FindVolumes()", "InvalidSetup",
276  FatalException, ErrMessage);
277  }
278  else
279  {
280  G4String WarMessage = "Volume does not exists... " + volname;
281  G4Exception("G4tgrVolumeMgr::FindVolumes()", "SearchFailed",
282  JustWarning, WarMessage);
283  }
284  }
285 
286  return vols;
287 }
288 
289 
290 //-------------------------------------------------------------
292 {
293  //--- Start from any G4tgrVolume and go upwards until you get to the top.
294  // Check that indeed all volumes drive to the same top volume
295 
296  const G4tgrVolume* topVol = 0;
297  G4mapsvol::const_iterator itetv;
298  for( itetv = theG4tgrVolumeMap.begin();
299  itetv != theG4tgrVolumeMap.end(); itetv++ )
300  {
301  const G4tgrVolume* vol = (*itetv).second;
302 #ifdef G4VERBOSE
304  {
305  G4cout << " G4tgrVolumeMgr::GetTopVolume() - Vol: "
306  << vol->GetName() << " no place = "
307  << vol->GetPlacements().size() << G4endl;
308  }
309 #endif
310 
311  while( vol->GetPlacements().size() != 0 )
312  {
313  vol = FindVolume((*(vol->GetPlacements()).begin())->GetParentName(), 1);
314 #ifdef G4VERBOSE
316  {
317  G4cout << " G4tgrVolumeMgr::GetTopVolume() - Vol: "
318  << vol->GetName()<< " N place = "
319  << vol->GetPlacements().size() << G4endl;
320  }
321 #endif
322  }
323  if ( (topVol != 0) && (topVol != vol)
324  && (topVol->GetType() != "VOLDivision")
325  && (vol->GetType() != "VOLDivision") )
326  {
327  G4Exception("G4tgrVolumeMgr::GetTopVolume()",
328  "Two world volumes found, second will be taken", JustWarning,
329  (G4String("Both volumes are at the top of a hierarchy: ")
330  + topVol->GetName() + " & " + vol->GetName() ).c_str());
331  }
332  topVol = vol;
333  }
334 
335  return topVol;
336 }
337 
338 
339 //-------------------------------------------------------------
340 std::pair<G4mmapspl::iterator, G4mmapspl::iterator>
342 {
343  std::pair<G4mmapspl::iterator, G4mmapspl::iterator> dite;
344  dite = theG4tgrVolumeTree.equal_range( name );
345  return dite;
346 }
347 
348 
349 //-------------------------------------------------------------
351 {
352  G4cout << " @@@@@@@@@@@@@@@@ DUMPING G4tgrVolume's Tree " << G4endl;
353 
354  const G4tgrVolume* vol = GetTopVolume();
355 
356  DumpVolumeLeaf( vol, 0, 0);
357 }
358 
359 
360 //-------------------------------------------------------------
362  unsigned int copyNo,
363  unsigned int leafDepth)
364 {
365  for( size_t ii=0; ii < leafDepth; ii++ )
366  {
367  G4cout << " ";
368  }
369  G4cout << " VOL:(" << leafDepth << ")" << vol->GetName()
370  << " copy No " << copyNo << G4endl;
371 
372  //---------- construct the children of this VOL
373  std::pair<G4mmapspl::iterator, G4mmapspl::iterator> children
374  = GetChildren( vol->GetName() );
375  G4mmapspl::const_iterator cite;
376 
377  leafDepth++;
378  for( cite = children.first; cite != children.second; cite++ )
379  {
380  //---- find G4tgrVolume pointed by G4tgrPlace
381  const G4tgrPlace* pla = (*cite).second;
382  const G4tgrVolume* volchild = pla->GetVolume();
383  //--- find copyNo
384  unsigned int cn = pla->GetCopyNo();
385  DumpVolumeLeaf( volchild, cn, leafDepth );
386  }
387 }
388 
389 
390 //-------------------------------------------------------------
392 {
393  //---------- Dump number of objects of each class
394  G4cout << " @@@@@@@@@@@@@@@@@@ Dumping Detector Summary " << G4endl;
395  G4cout << " @@@ Geometry built inside world volume: "
396  << GetTopVolume()->GetName() << G4endl;
397  G4cout << " Number of G4tgrVolume's: "
398  << theG4tgrVolumeMap.size() << G4endl;
399  G4mapsvol::const_iterator cite;
400  unsigned int nPlace = 0;
401  for( cite = theG4tgrVolumeMap.begin();
402  cite != theG4tgrVolumeMap.end(); cite++ )
403  {
404  nPlace += ((*cite).second)->GetPlacements().size();
405  }
406  G4cout << " Number of G4tgrPlace's: " << nPlace << G4endl;
407 
409  G4cout << " Number of G4tgrIsotope's: "
410  << matef->GetIsotopeList().size() << G4endl;
411  G4cout << " Number of G4tgrElement's: "
412  << matef->GetElementList().size() << G4endl;
413  G4cout << " Number of G4tgrMaterial's: "
414  << matef->GetMaterialList().size() << G4endl;
415 
417  G4cout << " Number of G4tgrRotationMatrix's: "
418  << rotmf->GetRotMatList().size() << G4endl;
419 
420 
421  //---------- Dump detail list of objects of each class
422  DumpVolumeTree();
423 
424  matef->DumpIsotopeList();
425  matef->DumpElementList();
426  matef->DumpMaterialList();
427  rotmf->DumpRotmList();
428 }