G4tgbMaterialMgr.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: G4tgbMaterialMgr.cc 69803 2013-05-15 15:24:50Z gcosmo $
00028 //
00029 //
00030 // class G4tgbMaterialMgr
00031 
00032 // History:
00033 // - Created.                                 P.Arce, CIEMAT (November 2007)
00034 // -------------------------------------------------------------------------
00035 
00036 #include "G4tgbMaterialMgr.hh"
00037 #include "G4tgbMaterialMixtureByWeight.hh"
00038 #include "G4tgbMaterialMixtureByVolume.hh"
00039 #include "G4tgbMaterialMixtureByNoAtoms.hh"
00040 #include "G4tgbMaterialSimple.hh"
00041 
00042 #include "G4tgrMaterialFactory.hh"
00043 #include "G4tgrMaterialSimple.hh"
00044 #include "G4tgrMaterialMixture.hh"
00045 #include "G4tgrUtils.hh"
00046 #include "G4tgrMessenger.hh"
00047 #include "G4NistManager.hh"
00048 
00049 
00050 G4tgbMaterialMgr* G4tgbMaterialMgr::theInstance = 0;
00051 
00052 
00053 // -------------------------------------------------------------------------
00054 G4tgbMaterialMgr::G4tgbMaterialMgr()
00055 {
00056 }
00057 
00058 
00059 // -------------------------------------------------------------------------
00060 G4tgbMaterialMgr* G4tgbMaterialMgr::GetInstance()
00061 {
00062   if( !theInstance )
00063   {
00064     theInstance = new G4tgbMaterialMgr;
00065     theInstance->CopyIsotopes();
00066     theInstance->CopyElements();
00067     theInstance->CopyMaterials();
00068   }
00069   return theInstance;
00070 }
00071 
00072 
00073 // -------------------------------------------------------------------------
00074 G4tgbMaterialMgr::~G4tgbMaterialMgr()
00075 {
00076   G4mstgbisot::const_iterator isotcite;
00077   for( isotcite = theG4tgbIsotopes.begin();
00078        isotcite != theG4tgbIsotopes.end(); isotcite++)
00079   {
00080     delete (*isotcite).second;
00081   }
00082   theG4tgbIsotopes.clear();
00083 
00084   G4mstgbelem::const_iterator elemcite;
00085   for( elemcite = theG4tgbElements.begin();
00086        elemcite != theG4tgbElements.end(); elemcite++)
00087   {
00088     delete (*elemcite).second;
00089   }
00090   theG4tgbElements.clear();
00091 
00092   G4mstgbmate::const_iterator matcite;
00093   for( matcite = theG4tgbMaterials.begin();
00094        matcite != theG4tgbMaterials.end(); matcite++)
00095   {
00096     delete (*matcite).second;
00097   }
00098   theG4tgbMaterials.clear();
00099 
00100   delete theInstance;
00101 }
00102 
00103 
00104 // -------------------------------------------------------------------------
00105 void G4tgbMaterialMgr::CopyIsotopes()
00106 {
00107   const G4mstgrisot tgrIsots
00108         = G4tgrMaterialFactory::GetInstance()->GetIsotopeList();
00109   G4mstgrisot::const_iterator cite;
00110   for( cite = tgrIsots.begin(); cite != tgrIsots.end(); cite++ )
00111   {
00112     G4tgrIsotope* tgr = (*cite).second;
00113     G4tgbIsotope* tgb = new G4tgbIsotope( tgr );
00114     theG4tgbIsotopes[tgb->GetName()] = tgb;
00115   }
00116 }
00117 
00118 
00119 // -------------------------------------------------------------------------
00120 void G4tgbMaterialMgr::CopyElements()
00121 {
00122   const G4mstgrelem tgrElems
00123         = G4tgrMaterialFactory::GetInstance()->GetElementList();
00124   G4mstgrelem::const_iterator cite;
00125   for( cite = tgrElems.begin(); cite != tgrElems.end(); cite++ )
00126   {
00127     G4tgrElement* tgr = (*cite).second;
00128     G4tgbElement* tgb = new G4tgbElement( tgr );
00129     theG4tgbElements[tgb->GetName()] = tgb;
00130   }
00131 }
00132 
00133 
00134 // -------------------------------------------------------------------------
00135 void G4tgbMaterialMgr::CopyMaterials()
00136 {
00137   const G4mstgrmate tgrMates
00138         = G4tgrMaterialFactory::GetInstance()->GetMaterialList();
00139   G4mstgrmate::const_iterator cite;
00140   for( cite = tgrMates.begin(); cite != tgrMates.end(); cite++ )
00141   {
00142     G4tgrMaterial* tgr = (*cite).second;
00143     G4tgbMaterial* tgb = 0;
00144     if( tgr->GetType() == "MaterialSimple" ) {
00145       tgb = new G4tgbMaterialSimple( tgr );
00146     } else if( tgr->GetType() == "MaterialMixtureByWeight" ) {
00147       tgb = new G4tgbMaterialMixtureByWeight( tgr );
00148     } else if( tgr->GetType() == "MaterialMixtureByNoAtoms" ) {
00149       tgb = new G4tgbMaterialMixtureByNoAtoms( tgr );
00150     } else if( tgr->GetType() == "MaterialMixtureByVolume" ) {
00151       tgb = new G4tgbMaterialMixtureByVolume( tgr );
00152     } else {
00153       return;
00154     }
00155     theG4tgbMaterials[tgb->GetName()] = tgb;
00156   }
00157 }
00158 
00159 
00160 // -------------------------------------------------------------------------
00161 G4Isotope* G4tgbMaterialMgr::FindOrBuildG4Isotope(const G4String & name) 
00162 {
00163   G4Isotope* g4isot = FindBuiltG4Isotope( name );
00164   if( g4isot == 0 )
00165   {
00166     G4tgbIsotope* tgbisot = FindG4tgbIsotope( name );
00167     // FindG4tgbIsotope never returns 0, otherwise if not found, crashes
00168     g4isot = tgbisot->BuildG4Isotope();
00169     // Register it
00170     G4String isotname = g4isot->GetName();
00171     theG4Isotopes[isotname] = g4isot;
00172   }
00173   else
00174   { 
00175 #ifdef G4VERBOSE
00176     if( G4tgrMessenger::GetVerboseLevel() >= 1 )
00177     {
00178       G4cout << " G4tgbMaterialMgr::FindOrBuildG4Isotope() -"
00179              << " G4Isotope already built: " << g4isot->GetName() << G4endl;
00180     }
00181 #endif
00182   }
00183 
00184 #ifdef G4VERBOSE
00185   if( G4tgrMessenger::GetVerboseLevel() >= 2 )
00186   {
00187     G4cout << " G4tgbMaterialMgr::FindOrBuildG4Isotope() - Isotope: "
00188            << name << G4endl;
00189   }
00190 #endif
00191   return g4isot;
00192 } 
00193 
00194 
00195 // -------------------------------------------------------------------------
00196 G4Isotope* G4tgbMaterialMgr::FindBuiltG4Isotope(const G4String & name) const 
00197 {
00198   G4Isotope* g4isot = 0;
00199  
00200   G4msg4isot::const_iterator cite = theG4Isotopes.find( name );
00201   if( cite != theG4Isotopes.end() )
00202   {
00203     g4isot = (*cite).second;
00204 #ifdef G4VERBOSE
00205     if( G4tgrMessenger::GetVerboseLevel() >= 2 )
00206       {
00207         G4cout << " G4tgbMaterialMgr::FindBuiltG4Isotope() - Isotope: "
00208                << name << " = " << g4isot << G4endl;
00209       }
00210 #endif
00211 
00212   } 
00213 
00214   return g4isot;
00215 }
00216 
00217 
00218 // -------------------------------------------------------------------------
00219 G4tgbIsotope* G4tgbMaterialMgr::FindG4tgbIsotope(const G4String & name,
00220                                                        G4bool bMustExist ) const 
00221 {
00222   G4tgbIsotope* isot = 0;
00223 
00224   G4mstgbisot::const_iterator cite = theG4tgbIsotopes.find( name ); 
00225   if( cite != theG4tgbIsotopes.end() )
00226   {
00227 #ifdef G4VERBOSE
00228     if( G4tgrMessenger::GetVerboseLevel() >= 2 )
00229     {
00230       G4cout << " G4tgbMaterialMgr::FindG4tgbIsotope() -"
00231              << " G4tgbIsotope found: " << ( (*cite).second )->GetName()
00232              << G4endl;
00233     }
00234 #endif
00235     isot = (*cite).second;
00236   }
00237   if( (isot == 0) && bMustExist )
00238   {
00239     G4String ErrMessage = "Isotope " + name + " not found !";
00240     G4Exception("G4tgbMaterialMgr::FindG4tgbIsotope()",
00241                 "InvalidSetup", FatalException, ErrMessage);
00242   }
00243 
00244   return isot;
00245 }
00246 
00247 
00248 // -------------------------------------------------------------------------
00249 G4Element* G4tgbMaterialMgr::FindOrBuildG4Element(const G4String & name,
00250                                                   G4bool bMustExist ) 
00251 {
00252   G4Element* g4elem = FindBuiltG4Element( name );
00253   if( g4elem == 0 )
00254   {
00255     G4tgbElement* tgbelem = FindG4tgbElement( name, false );
00256     if( tgbelem == 0)
00257     {
00258       // If FindG4tgbElement returns 0, look for a G4NISTElement
00259       G4cout << "  G4NistManager::Instance()->FindOrBuildElement( " << G4endl;
00260       g4elem = G4NistManager::Instance()->FindOrBuildElement(name);
00261     }
00262     else
00263     {
00264       if( tgbelem->GetType() == "ElementSimple" )
00265       {
00266         g4elem = tgbelem->BuildG4ElementSimple();
00267       }
00268       else if( tgbelem->GetType() == "ElementFromIsotopes" )
00269       {
00270         g4elem = tgbelem->BuildG4ElementFromIsotopes();
00271       }
00272       else
00273       {
00274         G4String ErrMessage = "Element type " + tgbelem->GetType()
00275           + " does not exist !";
00276         G4Exception("G4tgbMaterialMgr::GetG4Element()",
00277                     "InvalidSetup", FatalException, ErrMessage);
00278       }
00279     }
00280     // Register it
00281     if( (g4elem != 0) )
00282     {
00283       theG4Elements[g4elem->GetName()] = g4elem;
00284 #ifdef G4VERBOSE
00285       if( G4tgrMessenger::GetVerboseLevel() >= 2 )
00286         {
00287           G4cout << " G4tgbMaterialMgr::FindOrBuildG4Element() - Element: "
00288                  << name << G4endl;
00289         }
00290 #endif
00291     }
00292     else
00293     {
00294       if( bMustExist )
00295       {
00296         G4String ErrMessage = "Element " + name + " not found !";
00297         G4Exception("G4tgbMaterialMgr::FindOrBuildG4Element()",
00298                     "InvalidSetup", FatalException, ErrMessage);
00299       }
00300 #ifdef G4VERBOSE
00301       if( G4tgrMessenger::GetVerboseLevel() >= 2 )
00302       {
00303         G4cout << " G4tgbMaterialMgr::FindOrBuildG4Element() - Element: "
00304                << name << " not found  " << G4endl;
00305       }
00306 #endif
00307     }
00308   }
00309   else
00310   { 
00311 #ifdef G4VERBOSE
00312     if( G4tgrMessenger::GetVerboseLevel() >= 1 )
00313     {
00314       G4cout << " G4tgbMaterialMgr::GetG4Element() -"
00315              << " G4Element already built: " << g4elem->GetName() << G4endl; 
00316     }
00317 #endif
00318   }
00319 
00320   return g4elem;
00321 } 
00322 
00323 
00324 // -------------------------------------------------------------------------
00325 G4Element* G4tgbMaterialMgr::FindBuiltG4Element(const G4String & name) const 
00326 {
00327   G4Element* g4elem = 0;
00328  
00329   G4msg4elem::const_iterator cite = theG4Elements.find( name );
00330   if( cite != theG4Elements.end() )
00331   {
00332     g4elem = (*cite).second;
00333 #ifdef G4VERBOSE
00334     if( G4tgrMessenger::GetVerboseLevel() >= 2 )
00335     {
00336       G4cout << " G4tgbMaterialMgr::FindBuiltG4Element() - Element: "
00337              << name << " = " << g4elem << G4endl;
00338     }
00339 #endif
00340   } 
00341 
00342   return g4elem;
00343 }
00344 
00345 
00346 // -------------------------------------------------------------------------
00347 G4tgbElement* G4tgbMaterialMgr::FindG4tgbElement(const G4String & name,
00348                                                        G4bool bMustExist ) const
00349 {
00350   G4tgbElement* elem = 0;
00351 
00352   G4mstgbelem::const_iterator cite = theG4tgbElements.find( name ); 
00353   if( cite != theG4tgbElements.end() )
00354   {
00355 #ifdef G4VERBOSE
00356     if( G4tgrMessenger::GetVerboseLevel() >= 2 )
00357     {
00358       G4cout << " G4tgbMaterialMgr::FindG4tgbElement() -"
00359              << " G4tgbElement found: " << ( (*cite).second )->GetName()
00360              << G4endl;
00361     }
00362 #endif
00363     elem = (*cite).second;
00364   }
00365   if( (elem == 0) && bMustExist )
00366   {
00367     G4String ErrMessage = "Element " + name + "  not found !";
00368     G4Exception("G4tgbMaterialMgr::FindG4tgbElement()",
00369                 "InvalidSetup", FatalException, ErrMessage);
00370   }
00371 
00372   return elem;
00373 }
00374 
00375 
00376 // -------------------------------------------------------------------------
00377 G4Material* G4tgbMaterialMgr::FindOrBuildG4Material(const G4String & name,
00378                                                     G4bool bMustExist )  
00379 {
00380   G4Material* g4mate = FindBuiltG4Material( name );
00381   if( g4mate == 0)
00382   {
00383     G4tgbMaterial* tgbmate = FindG4tgbMaterial( name, false );
00384    
00385     if( tgbmate == 0)
00386     {
00387       // if FindG4tgbMaterial() returns 0, look for a G4NISTMaterial
00388       g4mate = G4NistManager::Instance()->FindOrBuildMaterial(name);
00389     }
00390     else
00391     {
00392       g4mate = tgbmate->BuildG4Material();
00393 
00394       if( tgbmate->GetTgrMate()->GetIonisationMeanExcitationEnergy() != -1. )
00395       {
00396         g4mate->GetIonisation()->SetMeanExcitationEnergy(tgbmate->
00397                 GetTgrMate()->GetIonisationMeanExcitationEnergy());
00398       }
00399     }
00400 
00401     // Register it
00402     if( g4mate != 0 )
00403     {
00404       theG4Materials[g4mate->GetName()] = g4mate;
00405 #ifdef G4VERBOSE
00406       if( G4tgrMessenger::GetVerboseLevel() >= 2 )
00407       {
00408         G4cout << " G4tgbMaterialMgr::FindOrBuildG4Material() - Material: "
00409                << name << G4endl;
00410       }
00411 #endif
00412     }
00413     else
00414     {
00415       if( bMustExist )
00416       {
00417         G4String ErrMessage = "Material " + name + "  not found !";
00418         G4Exception("G4tgbMaterialMgr::FindOrBuildG4Material()",
00419                     "InvalidSetup", FatalException, ErrMessage);
00420       }  
00421 #ifdef G4VERBOSE
00422       if( G4tgrMessenger::GetVerboseLevel() >= 2 )
00423       {
00424         G4cout << " G4tgbMaterialMgr::FindOrBuildG4Material() - Element: "
00425                << name << " not found  " << G4endl;
00426       }
00427 #endif
00428     }
00429   }
00430   else
00431   { 
00432 #ifdef G4VERBOSE
00433     if( G4tgrMessenger::GetVerboseLevel() >= 1 )
00434     {
00435       G4cout << " G4tgbMaterialMgr::FindOrBuildG4Material() -"
00436              << " G4Material already built: " << g4mate->GetName() << G4endl;
00437     }
00438 #endif
00439   }
00440 
00441   return g4mate;
00442 }
00443 
00444 
00445 // -------------------------------------------------------------------------
00446 G4Material* G4tgbMaterialMgr::FindBuiltG4Material(const G4String & name) const 
00447 {
00448   G4Material* g4mate = 0;
00449   //---------- look for an existing G4Material
00450   G4msg4mate::const_iterator cite = theG4Materials.find( name );
00451   if( cite != theG4Materials.end() )
00452   {
00453     g4mate = (*cite).second;
00454 #ifdef G4VERBOSE
00455     if( G4tgrMessenger::GetVerboseLevel() >= 2 )
00456     {
00457       G4cout << " G4tgbMaterialMgr::FindBuiltG4Material() - Material: "
00458              << name << " = " << g4mate << G4endl;
00459     }
00460 #endif
00461   }
00462 
00463   return g4mate;
00464 }
00465 
00466 
00467 // -------------------------------------------------------------------------
00468 G4tgbMaterial* G4tgbMaterialMgr::FindG4tgbMaterial(const G4String & name,
00469                                                    G4bool bMustExist ) const 
00470 {
00471   G4tgbMaterial* mate = 0;
00472   G4mstgbmate::const_iterator cite = theG4tgbMaterials.find( name );
00473   if( cite != theG4tgbMaterials.end() )
00474   {
00475     mate = (*cite).second;
00476 #ifdef G4VERBOSE
00477     if( G4tgrMessenger::GetVerboseLevel() >= 2 )
00478     {
00479       G4cout << " G4tgbMaterialMgr::FindG4tgbMaterial() -"
00480              << " G4tgbMaterial found: " << ( (*cite).second )->GetName()
00481              << " type " << ( (*cite).second )->GetName() << G4endl;
00482     }
00483 #endif
00484   }
00485 
00486   if( (mate == 0) && bMustExist )
00487   {
00488     G4String ErrMessage = "Material " + name + "  not found !";
00489     G4Exception("G4tgbMaterialMgr::FindG4tgbMaterial()",
00490                 "InvalidSetup", FatalException, ErrMessage);
00491   }
00492 
00493   return mate;
00494 }

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