G4tgbVolumeMgr.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id: G4tgbVolumeMgr.cc 69803 2013-05-15 15:24:50Z gcosmo $
00028 //
00029 //
00030 // class G4tgbVolumeMgr
00031 
00032 // History:
00033 // - Created.                                 P.Arce, CIEMAT (November 2007)
00034 // -------------------------------------------------------------------------
00035 
00036 #include "G4tgbVolumeMgr.hh"
00037 
00038 #include "G4SystemOfUnits.hh"
00039 #include "G4tgbVolume.hh"
00040 #include "G4tgbMaterialMgr.hh"
00041 #include "G4tgbRotationMatrixMgr.hh"
00042 
00043 #include "G4tgrVolumeMgr.hh"
00044 #include "G4tgrFileReader.hh"
00045 #include "G4tgrUtils.hh"
00046 
00047 #include "G4VSolid.hh"
00048 #include "G4PhysicalVolumeStore.hh"
00049 #include "G4ReflectionFactory.hh"
00050 #include "G4tgrMessenger.hh"
00051 #include "G4tgbDetectorBuilder.hh"
00052 
00053 G4tgbVolumeMgr* G4tgbVolumeMgr::theInstance = 0;
00054 
00055 //---------------------------------------------------------------------
00056 G4tgbVolumeMgr::G4tgbVolumeMgr() 
00057 {
00058   G4ReflectionFactory::Instance()->SetScalePrecision(1.E-6*mm);
00059     // NOTE: problems building matrices with not enough figures,
00060     // like  :ROTM RR30 0.866025 0.5 0. -0.5 0.866025 0. 0. 0 -1
00061   theDetectorBuilder = new G4tgbDetectorBuilder();
00062 }
00063 
00064 
00065 //---------------------------------------------------------------------
00066 G4tgbVolumeMgr::~G4tgbVolumeMgr()
00067 {
00068   delete theDetectorBuilder;
00069   delete theInstance;
00070 }
00071 
00072 
00073 //---------------------------------------------------------------------
00074 G4tgbVolumeMgr* G4tgbVolumeMgr::GetInstance()
00075 {
00076   if( !theInstance )
00077   {
00078     theInstance = new G4tgbVolumeMgr();
00079   }
00080   return theInstance;
00081 }
00082 
00083 
00084 //---------------------------------------------------------------------
00085 void G4tgbVolumeMgr::AddTextFile( const G4String& fname ) 
00086 {
00087   G4tgrFileReader::GetInstance()->AddTextFile( fname );
00088 }
00089 
00090 
00091 //---------------------------------------------------------------------
00092 G4VPhysicalVolume* G4tgbVolumeMgr::ReadAndConstructDetector()
00093 {
00094   const G4tgrVolume* tgrVoltop = theDetectorBuilder->ReadDetector();
00095   return theDetectorBuilder->ConstructDetector(tgrVoltop);
00096 }
00097 
00098 
00099 //---------------------------------------------------------------------
00100 void G4tgbVolumeMgr::RegisterMe( const G4tgbVolume* vol )
00101 {
00102   theVolumeList.insert( G4mssvol::value_type( vol->GetName(),
00103                         const_cast<G4tgbVolume*>(vol) ) );
00104 }
00105 
00106 
00107 //---------------------------------------------------------------------
00108 void G4tgbVolumeMgr::RegisterMe( const G4VSolid* solid )
00109 {
00110   theSolids.insert( G4mmssol::value_type( solid->GetName(),
00111                     const_cast<G4VSolid*>(solid) ) );
00112 }
00113 
00114 
00115 //---------------------------------------------------------------------
00116 void G4tgbVolumeMgr::RegisterMe( const G4LogicalVolume* lv )
00117 {
00118   theLVs.insert( G4mmslv::value_type( lv->GetName(),
00119                  const_cast<G4LogicalVolume*>(lv) ) );
00120 
00121 #ifdef G4VERBOSE
00122   if( G4tgrMessenger::GetVerboseLevel() >= 2 )
00123   {
00124     G4cout << " G4tgbVolumeMgr::RegisterMe() - Logical volume registered: "
00125            << lv->GetName() << G4endl; 
00126   }
00127 #endif
00128 }
00129 
00130 //---------------------------------------------------------------------
00131 void G4tgbVolumeMgr::RegisterMe( const G4VPhysicalVolume* pv )
00132 {
00133   thePVs.insert( G4mmspv::value_type( pv->GetName(),
00134                  const_cast<G4VPhysicalVolume*>(pv) ) );
00135 }
00136 
00137 
00138 //---------------------------------------------------------------------
00139 void G4tgbVolumeMgr::RegisterChildParentLVs( const G4LogicalVolume* logvol,
00140                                              const G4LogicalVolume* parentLV )
00141 {
00142   theLVInvTree[const_cast<G4LogicalVolume*>(logvol)] =
00143     const_cast<G4LogicalVolume*>(parentLV);
00144   theLVTree[const_cast<G4LogicalVolume*>(parentLV)] =
00145     const_cast<G4LogicalVolume*>(logvol);
00146 }
00147 
00148 //---------------------------------------------------------------------
00149 void G4tgbVolumeMgr::CopyVolumes()
00150 {
00151   //--------- Loop G4tgbVolume's and create a G4tgbVolume for each DetUnit
00152   G4mapsvol::iterator cite;
00153   G4mapsvol vollist = G4tgrVolumeMgr::GetInstance()->GetVolumeMap();
00154   for(cite = vollist.begin(); cite != vollist.end(); cite++)
00155   {
00156     G4tgrVolume* tgrvol = const_cast<G4tgrVolume*>( (*cite).second );
00157     G4tgbVolume* svol = new G4tgbVolume( tgrvol );
00158     RegisterMe( svol );
00159   }
00160 }
00161 
00162 
00163 //---------------------------------------------------------------------
00164 G4tgbVolume* G4tgbVolumeMgr::FindVolume( const G4String& volname)
00165 {
00166   G4mssvol::const_iterator cite = theVolumeList.find( volname );
00167   if( cite == theVolumeList.end() )
00168   {
00169     G4String ErrMessage = "G4tgbVolume not found: " + volname + " !";
00170     G4Exception("G4tgbVolumeMgr::FindVolume()", "InvalidSetup",
00171                 FatalException, ErrMessage);
00172   }
00173   return (*cite).second;
00174 }
00175 
00176 
00177 //---------------------------------------------------------------------
00178 G4VSolid* G4tgbVolumeMgr::FindG4Solid( const G4String& name )
00179 {
00180 #ifdef G4VERBOSE
00181   if( G4tgrMessenger::GetVerboseLevel() >= 2 )
00182   {
00183     G4cout << " G4tgbVolumeMgr::FindG4Solid() - " << name << G4endl;
00184   }
00185 #endif
00186 
00187   G4VSolid* oldSolid = 0;
00188   std::pair<G4mmssol::iterator, G4mmssol::iterator> mmssdi;
00189   mmssdi = theSolids.equal_range( name );
00190 
00191   if( mmssdi.first != mmssdi.second ) { // check there is a solid found
00192     G4mmssol::const_iterator mmsscite = mmssdi.first;
00193 
00194 #ifdef G4VERBOSE
00195     if( G4tgrMessenger::GetVerboseLevel() >= 2 )
00196     {
00197       G4cout << " G4tgbVolumeMgr::FindG4Solid() - Solid finding "
00198              << name << G4endl; 
00199     }
00200 #endif
00201     /*
00202        G4VSolid overwrites the operator== comparing the addresses
00203        => this cannot be used !!
00204        Then just compare solids by name =>> POSP tag cannot be used
00205        for the moment ...
00206          if( solid == *( (*mmsscite).second ) )
00207          {
00208            oldSolid = (*mmsscite).second;
00209            break;
00210          }
00211        until we write operator== for each solid type, we take a solid
00212        with the same name (therefore we will not allow two solids with
00213        equal name and different parameters (POSP) )
00214     */
00215     oldSolid = (*mmsscite).second;
00216 #ifdef G4VERBOSE
00217     if( G4tgrMessenger::GetVerboseLevel() >= 1 )
00218     {
00219       G4cout << " G4tgbVolumeMgr::FindG4Solid() - Solid already found "
00220              << name << G4endl; 
00221     }
00222 #endif
00223   }
00224  
00225 #ifdef G4VERBOSE
00226   if( G4tgrMessenger::GetVerboseLevel() >= 2 )
00227   {
00228       G4cout << " G4tgbVolumeMgr::FindG4Solid() - Old solid: "
00229              << oldSolid << G4endl;
00230   }
00231 #endif
00232 
00233   return oldSolid;
00234 }
00235 
00236 
00237 //---------------------------------------------------------------------
00238 G4LogicalVolume*
00239 G4tgbVolumeMgr::FindG4LogVol( const G4String& name, const G4bool exists )
00240 {
00241   G4mmslv::const_iterator mscite = theLVs.find( name );
00242   if( mscite == theLVs.end() )
00243   {
00244     if( exists )
00245     {
00246       G4String ErrMessage = "Logical volume name " + name + " not found !";
00247       G4Exception("G4tgbVolumeMgr::FindG4LogVol()", "InvalidSetup",
00248                   FatalException, ErrMessage);
00249     }
00250     return 0;
00251   }
00252   else
00253   {
00254     return (*mscite).second;
00255   }
00256 }
00257 
00258 //---------------------------------------------------------------------
00259 G4VPhysicalVolume*
00260 G4tgbVolumeMgr::FindG4PhysVol( const G4String& name, const G4bool exists )
00261 {
00262   G4mmspv::const_iterator mscite = thePVs.find( name );
00263   if( mscite == thePVs.end() )
00264   {
00265     if( exists )
00266     {
00267       G4String ErrMessage = "Physical volume name " + name + " not found !";
00268       G4Exception("G4tgbVolumeMgr::FindG4PhysVol()", "InvalidSetup",
00269                   FatalException, ErrMessage);
00270     }
00271     return 0;
00272   }
00273   else
00274   {
00275     return (*mscite).second;
00276   }
00277 }
00278 
00279 
00280 //---------------------------------------------------------------------
00281 G4VPhysicalVolume* G4tgbVolumeMgr::GetTopPhysVol()
00282 {
00283   G4LogicalVolume* lv = GetTopLogVol(); 
00284   G4VPhysicalVolume* pv = ( *(thePVs.find( lv->GetName() )) ).second;
00285 
00286 #ifdef G4VERBOSE
00287   if( G4tgrMessenger::GetVerboseLevel() >= 2 )
00288   {
00289     G4cout << " G4tgbVolumeMgr::GetTopPhysVol() - pv: "
00290            << pv->GetName() << G4endl;
00291   }
00292 #endif
00293 
00294   return pv;
00295 }
00296 
00297 
00298 //---------------------------------------------------------------------
00299 G4LogicalVolume* G4tgbVolumeMgr::GetTopLogVol()
00300 {
00301   //----------- Start from any G4LogicalVolume, because if you go upwards
00302   //            you will always end at the top  
00303 #ifdef G4VERBOSE
00304   if( G4tgrMessenger::GetVerboseLevel() >= 2 )
00305   {
00306     G4cout << " G4tgbVolumeMgr::GetTopLogVol theLVInvTresize "
00307            << theLVInvTree.size() << G4endl;
00308   }
00309 #endif
00310   if(  theLVInvTree.size() == 0 ) 
00311   { 
00312     G4Exception("G4tgbVolumeMgr::GetTopLogVol()", "InvalidSetup",
00313                 FatalException, "theLVInvTree has no elements.");
00314   }
00315   G4LogicalVolume* lv = (*(theLVInvTree.begin())).second;
00316 
00317   //------- if first element is the top LV, its parent is 0
00318   if( lv == 0 ) 
00319   {
00320     lv = (*(theLVInvTree.begin())).first;
00321   } 
00322   else 
00323   {
00324     while( (*(theLVInvTree.find( lv ))).second != 0) 
00325     {
00326       //---------- get parent of first position
00327       lv = (*(theLVInvTree.find( lv ))).second;
00328 #ifdef G4VERBOSE
00329       if( G4tgrMessenger::GetVerboseLevel() >= 2 )
00330       {
00331         G4cout << " G4tgbVolumeMgr::GetTopPhysVol: lv "
00332                << lv->GetName() << G4endl;
00333       }
00334 #endif
00335     }
00336   }
00337   
00338   return lv;
00339 }
00340 
00341   
00342 //---------------------------------------------------------------------
00343 void G4tgbVolumeMgr::BuildPhysVolTree()
00344 {
00345 /*
00346   G4PhysicalVolumeStore* pvs = G4PhysicalVolumeStore::GetInstance();
00347   std::vector<G4VPhysicalVolume*>::iterator cite;
00348   for( cite = pvs->begin(); cite != pvs->end(); cite++ )
00349   {
00350     thePVTree[ *cite ] = (*cite)->GetMother();
00351     thePVInvTree[ (*cite)->GetMother() ] = *cite;
00352   }
00353 */
00354 }
00355  
00356 
00357 //---------------------------------------------------------------------
00358 void G4tgbVolumeMgr::DumpSummary()
00359 {
00360   //---------- Dump number of objects of each class
00361   G4cout << " @@@@@@@@@@@@@ Dumping Geant4 geometry objects Summary " << G4endl;
00362   G4cout << " @@@ Geometry built inside world volume: "
00363          << GetTopPhysVol()->GetName() << G4endl;
00364   G4cout << " Number of G4VSolid's: " << theSolids.size() << G4endl;
00365   G4cout << " Number of G4LogicalVolume's: " << theLVs.size() << G4endl;
00366   G4cout << " Number of G4VPhysicalVolume's: " << thePVs.size() << G4endl;
00367 
00368   G4tgbMaterialMgr* mateMgr = G4tgbMaterialMgr::GetInstance();
00369   G4cout << " Number of G4Isotope's: "
00370          << mateMgr->GetG4IsotopeList().size() << G4endl;
00371   G4cout << " Number of G4Element's: "
00372          << mateMgr->GetG4ElementList().size() << G4endl;
00373   G4cout << " Number of G4Material's: "
00374          << mateMgr->GetG4MaterialList().size() << G4endl;
00375 
00376   G4tgbRotationMatrixMgr* rotmMgr = G4tgbRotationMatrixMgr::GetInstance();
00377   G4cout << " Number of G4RotationMatrix's: "
00378          << rotmMgr->GetG4RotMatList().size() << G4endl;
00379 
00380   //---------- Dump list of objects of each class
00381   DumpG4SolidList();
00382   DumpG4LogVolTree();
00383   DumpG4PhysVolTree();
00384 }
00385 
00386 
00387 //---------------------------------------------------------------------
00388 void G4tgbVolumeMgr::DumpG4SolidList()
00389 {
00390   G4mmssol::const_iterator cite;
00391   for( cite = theSolids.begin(); cite != theSolids.end(); cite++)
00392   {
00393     G4cout << "G4SOLID: " << (*cite).second->GetName()
00394            << " of type " << (*cite).second->GetEntityType() << G4endl;
00395   }
00396 } 
00397 
00398 
00399 //---------------------------------------------------------------------
00400 void G4tgbVolumeMgr::DumpG4LogVolTree()
00401 {
00402   G4cout << " @@@@@@@@@@@@@ DUMPING G4LogicalVolume's Tree  " << G4endl;
00403   
00404   G4LogicalVolume* lv = GetTopLogVol();
00405   
00406   DumpG4LogVolLeaf(lv, 0);
00407 }
00408 
00409 
00410 //---------------------------------------------------------------------
00411 void G4tgbVolumeMgr::DumpG4LogVolLeaf( const G4LogicalVolume* lv,
00412                                        unsigned int leafDepth)
00413 {
00414   for( size_t ii=0; ii < leafDepth; ii++ )
00415   {
00416     G4cout << "  ";
00417   }
00418   G4cout << " LV:(" << leafDepth << ")" << lv->GetName() << G4endl;
00419   
00420   //---------- construct the children of this volume
00421   // G4LogicalVolume* lvnc = const_cast<G4LogicalVolume*>(lv);
00422   // std::pair<G4mlvlv::iterator, G4mlvlv::iterator> children
00423   //   = theLVTree.equal_range( lvnc );
00424   //
00425   // G4mlvlv::iterator cite; 
00426   
00427   leafDepth++;
00428   // for( cite = children.first; cite != children.second; cite++ )
00429   // {
00430   //  DumpG4LVLeaf( (*cite)->second, leafDepth );
00431   // } 
00432 }
00433 
00434 
00435 
00436 //---------------------------------------------------------------------
00437 void G4tgbVolumeMgr::DumpG4PhysVolTree()
00438 {
00439   G4cout << " @@@@@@@@@@@@@ DUMPING G4PhysicalVolume's Tree  " << G4endl;
00440 
00441   G4VPhysicalVolume* pv = GetTopPhysVol();
00442 
00443   DumpG4PhysVolLeaf(pv, 0);
00444 }
00445 
00446 
00447 //---------------------------------------------------------------------
00448 void G4tgbVolumeMgr::DumpG4PhysVolLeaf( const G4VPhysicalVolume* pv,
00449                                         unsigned int leafDepth)
00450 {
00451   for( size_t ii=0; ii < leafDepth; ii++ )
00452   {
00453     G4cout << "  ";
00454   }
00455   G4cout << " PV:(" << leafDepth << ")" << pv->GetName() << G4endl;
00456 
00457   //---------- construct the children of this PV
00458   // G4VPhysicalVolume* pvnc = const_cast<G4VPhysicalVolume*>(pv);
00459   // std::pair<G4mpvpv::iterator, G4mpvpv::iterator> children
00460   //  = thePVTree.equal_range( pvnc );
00461   //
00462   // G4mpvpv::iterator cite; 
00463 
00464   leafDepth++;
00465   // for( cite = children.first; cite != children.second; cite++ )
00466   // {
00467   //  DumpG4PVLeaf( (*cite)->second, leafDepth );
00468   // }
00469 }

Generated on Mon May 27 17:49:58 2013 for Geant4 by  doxygen 1.4.7