Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4tgbVolumeMgr.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: G4tgbVolumeMgr.cc 66872 2013-01-15 01:25:57Z japost $
28 //
29 //
30 // class G4tgbVolumeMgr
31 
32 // History:
33 // - Created. P.Arce, CIEMAT (November 2007)
34 // -------------------------------------------------------------------------
35 
36 #include "G4tgbVolumeMgr.hh"
37 
38 #include "G4SystemOfUnits.hh"
39 #include "G4tgbVolume.hh"
40 #include "G4tgbMaterialMgr.hh"
42 
43 #include "G4tgrVolumeMgr.hh"
44 #include "G4tgrFileReader.hh"
45 #include "G4tgrUtils.hh"
46 
47 #include "G4VSolid.hh"
48 #include "G4PhysicalVolumeStore.hh"
49 #include "G4ReflectionFactory.hh"
50 #include "G4tgrMessenger.hh"
51 #include "G4tgbDetectorBuilder.hh"
52 
53 G4ThreadLocal G4tgbVolumeMgr* G4tgbVolumeMgr::theInstance = 0;
54 
55 //---------------------------------------------------------------------
57 {
59  // NOTE: problems building matrices with not enough figures,
60  // like :ROTM RR30 0.866025 0.5 0. -0.5 0.866025 0. 0. 0 -1
61  theDetectorBuilder = new G4tgbDetectorBuilder();
62 }
63 
64 
65 //---------------------------------------------------------------------
67 {
68  delete theDetectorBuilder;
69  delete theInstance;
70 }
71 
72 
73 //---------------------------------------------------------------------
75 {
76  if( !theInstance )
77  {
78  theInstance = new G4tgbVolumeMgr();
79  }
80  return theInstance;
81 }
82 
83 
84 //---------------------------------------------------------------------
86 {
88 }
89 
90 
91 //---------------------------------------------------------------------
93 {
94  const G4tgrVolume* tgrVoltop = theDetectorBuilder->ReadDetector();
95  return theDetectorBuilder->ConstructDetector(tgrVoltop);
96 }
97 
98 
99 //---------------------------------------------------------------------
101 {
102  theVolumeList.insert( G4mssvol::value_type( vol->GetName(),
103  const_cast<G4tgbVolume*>(vol) ) );
104 }
105 
106 
107 //---------------------------------------------------------------------
109 {
110  theSolids.insert( G4mmssol::value_type( solid->GetName(),
111  const_cast<G4VSolid*>(solid) ) );
112 }
113 
114 
115 //---------------------------------------------------------------------
117 {
118  theLVs.insert( G4mmslv::value_type( lv->GetName(),
119  const_cast<G4LogicalVolume*>(lv) ) );
120 
121 #ifdef G4VERBOSE
123  {
124  G4cout << " G4tgbVolumeMgr::RegisterMe() - Logical volume registered: "
125  << lv->GetName() << G4endl;
126  }
127 #endif
128 }
129 
130 //---------------------------------------------------------------------
132 {
133  thePVs.insert( G4mmspv::value_type( pv->GetName(),
134  const_cast<G4VPhysicalVolume*>(pv) ) );
135 }
136 
137 
138 //---------------------------------------------------------------------
140  const G4LogicalVolume* parentLV )
141 {
142  theLVInvTree[const_cast<G4LogicalVolume*>(logvol)] =
143  const_cast<G4LogicalVolume*>(parentLV);
144  theLVTree[const_cast<G4LogicalVolume*>(parentLV)] =
145  const_cast<G4LogicalVolume*>(logvol);
146 }
147 
148 //---------------------------------------------------------------------
150 {
151  //--------- Loop G4tgbVolume's and create a G4tgbVolume for each DetUnit
152  G4mapsvol::iterator cite;
154  for(cite = vollist.begin(); cite != vollist.end(); cite++)
155  {
156  G4tgrVolume* tgrvol = const_cast<G4tgrVolume*>( (*cite).second );
157  G4tgbVolume* svol = new G4tgbVolume( tgrvol );
158  RegisterMe( svol );
159  }
160 }
161 
162 
163 //---------------------------------------------------------------------
165 {
166  G4mssvol::const_iterator cite = theVolumeList.find( volname );
167  if( cite == theVolumeList.end() )
168  {
169  G4String ErrMessage = "G4tgbVolume not found: " + volname + " !";
170  G4Exception("G4tgbVolumeMgr::FindVolume()", "InvalidSetup",
171  FatalException, ErrMessage);
172  }
173  return (*cite).second;
174 }
175 
176 
177 //---------------------------------------------------------------------
179 {
180 #ifdef G4VERBOSE
182  {
183  G4cout << " G4tgbVolumeMgr::FindG4Solid() - " << name << G4endl;
184  }
185 #endif
186 
187  G4VSolid* oldSolid = 0;
188  std::pair<G4mmssol::iterator, G4mmssol::iterator> mmssdi;
189  mmssdi = theSolids.equal_range( name );
190 
191  if( mmssdi.first != mmssdi.second ) { // check there is a solid found
192  G4mmssol::const_iterator mmsscite = mmssdi.first;
193 
194 #ifdef G4VERBOSE
196  {
197  G4cout << " G4tgbVolumeMgr::FindG4Solid() - Solid finding "
198  << name << G4endl;
199  }
200 #endif
201  /*
202  G4VSolid overwrites the operator== comparing the addresses
203  => this cannot be used !!
204  Then just compare solids by name =>> POSP tag cannot be used
205  for the moment ...
206  if( solid == *( (*mmsscite).second ) )
207  {
208  oldSolid = (*mmsscite).second;
209  break;
210  }
211  until we write operator== for each solid type, we take a solid
212  with the same name (therefore we will not allow two solids with
213  equal name and different parameters (POSP) )
214  */
215  oldSolid = (*mmsscite).second;
216 #ifdef G4VERBOSE
218  {
219  G4cout << " G4tgbVolumeMgr::FindG4Solid() - Solid already found "
220  << name << G4endl;
221  }
222 #endif
223  }
224 
225 #ifdef G4VERBOSE
227  {
228  G4cout << " G4tgbVolumeMgr::FindG4Solid() - Old solid: "
229  << oldSolid << G4endl;
230  }
231 #endif
232 
233  return oldSolid;
234 }
235 
236 
237 //---------------------------------------------------------------------
240 {
241  G4mmslv::const_iterator mscite = theLVs.find( name );
242  if( mscite == theLVs.end() )
243  {
244  if( exists )
245  {
246  G4String ErrMessage = "Logical volume name " + name + " not found !";
247  G4Exception("G4tgbVolumeMgr::FindG4LogVol()", "InvalidSetup",
248  FatalException, ErrMessage);
249  }
250  return 0;
251  }
252  else
253  {
254  return (*mscite).second;
255  }
256 }
257 
258 //---------------------------------------------------------------------
261 {
262  G4mmspv::const_iterator mscite = thePVs.find( name );
263  if( mscite == thePVs.end() )
264  {
265  if( exists )
266  {
267  G4String ErrMessage = "Physical volume name " + name + " not found !";
268  G4Exception("G4tgbVolumeMgr::FindG4PhysVol()", "InvalidSetup",
269  FatalException, ErrMessage);
270  }
271  return 0;
272  }
273  else
274  {
275  return (*mscite).second;
276  }
277 }
278 
279 
280 //---------------------------------------------------------------------
282 {
283  G4LogicalVolume* lv = GetTopLogVol();
284  G4VPhysicalVolume* pv = ( *(thePVs.find( lv->GetName() )) ).second;
285 
286 #ifdef G4VERBOSE
288  {
289  G4cout << " G4tgbVolumeMgr::GetTopPhysVol() - pv: "
290  << pv->GetName() << G4endl;
291  }
292 #endif
293 
294  return pv;
295 }
296 
297 
298 //---------------------------------------------------------------------
300 {
301  //----------- Start from any G4LogicalVolume, because if you go upwards
302  // you will always end at the top
303 #ifdef G4VERBOSE
305  {
306  G4cout << " G4tgbVolumeMgr::GetTopLogVol theLVInvTresize "
307  << theLVInvTree.size() << G4endl;
308  }
309 #endif
310  if( theLVInvTree.size() == 0 )
311  {
312  G4Exception("G4tgbVolumeMgr::GetTopLogVol()", "InvalidSetup",
313  FatalException, "theLVInvTree has no elements.");
314  }
315  G4LogicalVolume* lv = (*(theLVInvTree.begin())).second;
316 
317  //------- if first element is the top LV, its parent is 0
318  if( lv == 0 )
319  {
320  lv = (*(theLVInvTree.begin())).first;
321  }
322  else
323  {
324  while( (*(theLVInvTree.find( lv ))).second != 0)
325  {
326  //---------- get parent of first position
327  lv = (*(theLVInvTree.find( lv ))).second;
328 #ifdef G4VERBOSE
330  {
331  G4cout << " G4tgbVolumeMgr::GetTopPhysVol: lv "
332  << lv->GetName() << G4endl;
333  }
334 #endif
335  }
336  }
337 
338  return lv;
339 }
340 
341 
342 //---------------------------------------------------------------------
344 {
345 /*
346  G4PhysicalVolumeStore* pvs = G4PhysicalVolumeStore::GetInstance();
347  std::vector<G4VPhysicalVolume*>::iterator cite;
348  for( cite = pvs->begin(); cite != pvs->end(); cite++ )
349  {
350  thePVTree[ *cite ] = (*cite)->GetMother();
351  thePVInvTree[ (*cite)->GetMother() ] = *cite;
352  }
353 */
354 }
355 
356 
357 //---------------------------------------------------------------------
359 {
360  //---------- Dump number of objects of each class
361  G4cout << " @@@@@@@@@@@@@ Dumping Geant4 geometry objects Summary " << G4endl;
362  G4cout << " @@@ Geometry built inside world volume: "
363  << GetTopPhysVol()->GetName() << G4endl;
364  G4cout << " Number of G4VSolid's: " << theSolids.size() << G4endl;
365  G4cout << " Number of G4LogicalVolume's: " << theLVs.size() << G4endl;
366  G4cout << " Number of G4VPhysicalVolume's: " << thePVs.size() << G4endl;
367 
369  G4cout << " Number of G4Isotope's: "
370  << mateMgr->GetG4IsotopeList().size() << G4endl;
371  G4cout << " Number of G4Element's: "
372  << mateMgr->GetG4ElementList().size() << G4endl;
373  G4cout << " Number of G4Material's: "
374  << mateMgr->GetG4MaterialList().size() << G4endl;
375 
377  G4cout << " Number of G4RotationMatrix's: "
378  << rotmMgr->GetG4RotMatList().size() << G4endl;
379 
380  //---------- Dump list of objects of each class
381  DumpG4SolidList();
384 }
385 
386 
387 //---------------------------------------------------------------------
389 {
390  G4mmssol::const_iterator cite;
391  for( cite = theSolids.begin(); cite != theSolids.end(); cite++)
392  {
393  G4cout << "G4SOLID: " << (*cite).second->GetName()
394  << " of type " << (*cite).second->GetEntityType() << G4endl;
395  }
396 }
397 
398 
399 //---------------------------------------------------------------------
401 {
402  G4cout << " @@@@@@@@@@@@@ DUMPING G4LogicalVolume's Tree " << G4endl;
403 
405 
406  DumpG4LogVolLeaf(lv, 0);
407 }
408 
409 
410 //---------------------------------------------------------------------
412  unsigned int leafDepth)
413 {
414  for( size_t ii=0; ii < leafDepth; ii++ )
415  {
416  G4cout << " ";
417  }
418  G4cout << " LV:(" << leafDepth << ")" << lv->GetName() << G4endl;
419 
420  //---------- construct the children of this volume
421  // G4LogicalVolume* lvnc = const_cast<G4LogicalVolume*>(lv);
422  // std::pair<G4mlvlv::iterator, G4mlvlv::iterator> children
423  // = theLVTree.equal_range( lvnc );
424  //
425  // G4mlvlv::iterator cite;
426 
427  leafDepth++;
428  // for( cite = children.first; cite != children.second; cite++ )
429  // {
430  // DumpG4LVLeaf( (*cite)->second, leafDepth );
431  // }
432 }
433 
434 
435 
436 //---------------------------------------------------------------------
438 {
439  G4cout << " @@@@@@@@@@@@@ DUMPING G4PhysicalVolume's Tree " << G4endl;
440 
442 
443  DumpG4PhysVolLeaf(pv, 0);
444 }
445 
446 
447 //---------------------------------------------------------------------
449  unsigned int leafDepth)
450 {
451  for( size_t ii=0; ii < leafDepth; ii++ )
452  {
453  G4cout << " ";
454  }
455  G4cout << " PV:(" << leafDepth << ")" << pv->GetName() << G4endl;
456 
457  //---------- construct the children of this PV
458  // G4VPhysicalVolume* pvnc = const_cast<G4VPhysicalVolume*>(pv);
459  // std::pair<G4mpvpv::iterator, G4mpvpv::iterator> children
460  // = thePVTree.equal_range( pvnc );
461  //
462  // G4mpvpv::iterator cite;
463 
464  leafDepth++;
465  // for( cite = children.first; cite != children.second; cite++ )
466  // {
467  // DumpG4PVLeaf( (*cite)->second, leafDepth );
468  // }
469 }
G4String GetName() const
G4VSolid * FindG4Solid(const G4String &name)
const XML_Char * name
Definition: expat.h:151
static constexpr double mm
Definition: G4SIunits.hh:115
void DumpG4PhysVolLeaf(const G4VPhysicalVolume *pv, unsigned int leafDepth)
const G4msg4mate GetG4MaterialList() const
void SetScalePrecision(G4double scaleValue)
static G4tgbRotationMatrixMgr * GetInstance()
const G4msg4rotm & GetG4RotMatList() const
const G4String & GetName() const
Definition: G4tgbVolume.hh:108
static constexpr double second
Definition: G4SIunits.hh:157
const G4msg4elem GetG4ElementList() const
#define G4ThreadLocal
Definition: tls.hh:89
virtual const G4tgrVolume * ReadDetector()
static G4ReflectionFactory * Instance()
static G4tgrFileReader * GetInstance()
G4VPhysicalVolume * FindG4PhysVol(const G4String &theName, const G4bool bExists=0)
G4GLOB_DLL std::ostream G4cout
const G4String & GetName() const
static G4int GetVerboseLevel()
bool G4bool
Definition: G4Types.hh:79
static G4tgrVolumeMgr * GetInstance()
virtual G4VPhysicalVolume * ConstructDetector(const G4tgrVolume *tgrVoltop)
void AddTextFile(const G4String &fname)
G4VPhysicalVolume * ReadAndConstructDetector()
const G4msg4isot GetG4IsotopeList() const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
std::map< G4String, G4tgrVolume * > G4mapsvol
G4VPhysicalVolume * GetTopPhysVol()
void RegisterMe(const G4tgbVolume *vol)
void DumpG4PhysVolTree()
const G4mapsvol & GetVolumeMap()
void RegisterChildParentLVs(const G4LogicalVolume *logvol, const G4LogicalVolume *parentLV)
G4tgbVolume * FindVolume(const G4String &volname)
G4LogicalVolume * GetTopLogVol()
void AddTextFile(const G4String &fname)
#define G4endl
Definition: G4ios.hh:61
void DumpG4LogVolLeaf(const G4LogicalVolume *lv, unsigned int leafDepth)
string fname
Definition: test.py:308
const G4String & GetName() const
static G4tgbVolumeMgr * GetInstance()
static G4tgbMaterialMgr * GetInstance()
G4LogicalVolume * FindG4LogVol(const G4String &theName, const G4bool bExists=0)