G4tgrMaterialFactory.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: G4tgrMaterialFactory.cc 69803 2013-05-15 15:24:50Z gcosmo $
00028 //
00029 //
00030 // class G4tgrMaterialFactory
00031 
00032 // History:
00033 // - Created.                                 P.Arce, CIEMAT (November 2007)
00034 // -------------------------------------------------------------------------
00035 
00036 #include "G4tgrMaterialFactory.hh"
00037 #include "G4tgrUtils.hh"
00038 #include "G4tgrElementSimple.hh"
00039 #include "G4tgrElementFromIsotopes.hh"
00040 #include "G4tgrMaterialSimple.hh"
00041 #include "G4tgrMaterialMixture.hh"
00042 #include "G4tgrFileReader.hh"
00043 #include "G4tgrMessenger.hh"
00044 
00045 
00046 G4tgrMaterialFactory* G4tgrMaterialFactory::theInstance = 0;
00047 
00048 
00049 //-------------------------------------------------------------
00050 G4tgrMaterialFactory::G4tgrMaterialFactory()
00051 {
00052 }
00053 
00054 
00055 //-------------------------------------------------------------
00056 G4tgrMaterialFactory* G4tgrMaterialFactory::GetInstance()
00057 {
00058   if( !theInstance )
00059   {
00060     theInstance = new G4tgrMaterialFactory;
00061   }
00062   return theInstance;
00063 }
00064 
00065 
00066 //-------------------------------------------------------------
00067 G4tgrMaterialFactory::~G4tgrMaterialFactory()
00068 {
00069   G4mstgrisot::iterator isotcite;
00070   for( isotcite = theG4tgrIsotopes.begin();
00071        isotcite != theG4tgrIsotopes.end(); isotcite++)
00072   {
00073     delete (*isotcite).second;
00074   }
00075   theG4tgrIsotopes.clear();
00076 
00077   G4mstgrelem::iterator elemcite;
00078   for( elemcite = theG4tgrElements.begin();
00079        elemcite != theG4tgrElements.end(); elemcite++)
00080   {
00081     delete (*elemcite).second;
00082   }
00083   theG4tgrElements.clear();
00084 
00085   G4mstgrmate::iterator matcite;
00086   for( matcite = theG4tgrMaterials.begin();
00087        matcite != theG4tgrMaterials.end(); matcite++)
00088   {
00089     delete (*matcite).second;
00090   }
00091   theG4tgrMaterials.clear();
00092   delete theInstance;
00093 }
00094 
00095 
00096 //-------------------------------------------------------------
00097 G4tgrIsotope*
00098 G4tgrMaterialFactory::AddIsotope( const std::vector<G4String>& wl )
00099 {
00100   //---------- Look if isotope exists
00101   if( FindIsotope( G4tgrUtils::GetString(wl[1]) ) != 0 )
00102   {
00103     ErrorAlreadyExists("isotope", wl );
00104   }
00105   
00106   G4tgrIsotope* isot = new G4tgrIsotope( wl );
00107   theG4tgrIsotopes[isot->GetName()] = isot;
00108 
00109   return isot;
00110 }
00111 
00112 //-------------------------------------------------------------
00113 G4tgrElementSimple*
00114 G4tgrMaterialFactory::AddElementSimple( const std::vector<G4String>& wl )
00115 {
00116   //---------- Look if element exists
00117   if( FindElement( G4tgrUtils::GetString(wl[1]) ) != 0 )
00118   {
00119     ErrorAlreadyExists("element", wl );
00120   }
00121   
00122   G4tgrElementSimple* elem = new G4tgrElementSimple( wl );
00123   theG4tgrElements[elem->GetName()] = elem;
00124 
00125   return elem;
00126 }
00127 
00128 
00129 //-------------------------------------------------------------
00130 G4tgrElementFromIsotopes*
00131 G4tgrMaterialFactory::AddElementFromIsotopes( const std::vector<G4String>& wl )
00132 {
00133   //---------- Look if element exists
00134   if( FindElement( G4tgrUtils::GetString(wl[1]) ) != 0 )
00135   {
00136     ErrorAlreadyExists("element", wl );
00137   }
00138   
00139   G4tgrElementFromIsotopes* elem = new G4tgrElementFromIsotopes( wl );
00140   theG4tgrElements[elem->GetName()] = elem;
00141 
00142   return elem;
00143 }
00144 
00145 
00146 //-------------------------------------------------------------
00147 G4tgrMaterialSimple*
00148 G4tgrMaterialFactory::AddMaterialSimple( const std::vector<G4String>& wl )
00149 {
00150 #ifdef G4VERBOSE
00151   if( G4tgrMessenger::GetVerboseLevel() >= 2 )
00152   {
00153     G4cout << " G4tgrMaterialFactory::AddMaterialSimple" << wl[1] << G4endl;
00154   }
00155 #endif
00156 
00157   //---------- Look if material exists
00158   if( FindMaterial( G4tgrUtils::GetString(wl[1]) ) != 0 )
00159   {
00160     ErrorAlreadyExists("material simple", wl );
00161   }
00162 
00163   G4tgrMaterialSimple* mate = new G4tgrMaterialSimple("MaterialSimple", wl );
00164 
00165   //---------- register this material
00166   theG4tgrMaterials[ mate->GetName() ] = mate;
00167   
00168   return mate;
00169 }
00170 
00171 
00172 //-------------------------------------------------------------
00173 G4tgrMaterialMixture*
00174 G4tgrMaterialFactory::AddMaterialMixture( const std::vector<G4String>& wl,
00175                                           const G4String& mixtType )
00176 {
00177 #ifdef G4VERBOSE
00178   if( G4tgrMessenger::GetVerboseLevel() >= 2 )
00179   {
00180     G4cout << " G4tgrMaterialFactory::AddMaterialMixture " << wl[1] << G4endl;
00181   }
00182 #endif
00183 
00184   //---------- Look if material already exists
00185   if( FindMaterial( G4tgrUtils::GetString(wl[1]) ) != 0 )
00186   {
00187     ErrorAlreadyExists("material mixture", wl );
00188   }
00189 
00190   G4tgrMaterialMixture* mate; 
00191   mate = new G4tgrMaterialMixture( mixtType, wl );
00192   
00193   //---------- register this material
00194   theG4tgrMaterials[ mate->GetName() ] = mate;
00195   
00196   return mate;
00197 }
00198 
00199 
00200 //-------------------------------------------------------------
00201 G4tgrIsotope* G4tgrMaterialFactory::FindIsotope(const G4String & name) const 
00202 {
00203 #ifdef G4VERBOSE
00204   if( G4tgrMessenger::GetVerboseLevel() >= 3 )
00205   {
00206      G4cout << " G4tgrMaterialFactory::FindIsotope() - " << name << G4endl;
00207   }
00208 #endif
00209 
00210   G4mstgrisot::const_iterator cite;
00211   cite = theG4tgrIsotopes.find( name ); 
00212   if( cite == theG4tgrIsotopes.end() )
00213   {
00214     return 0;
00215   }
00216   else
00217   {
00218 #ifdef G4VERBOSE
00219     if( G4tgrMessenger::GetVerboseLevel() >= 3 )
00220     {
00221       G4cout << " G4tgrIsotope found: "
00222              << ( (*cite).second )->GetName() << G4endl;
00223     }
00224 #endif
00225     return (*cite).second;
00226   }
00227 }
00228 
00229 
00230 //-------------------------------------------------------------
00231 G4tgrElement* G4tgrMaterialFactory::FindElement(const G4String & name) const 
00232 {
00233 #ifdef G4VERBOSE
00234   if( G4tgrMessenger::GetVerboseLevel() >= 3 )
00235   {
00236     G4cout << " G4tgrMaterialFactory::FindElement() - " << name << G4endl;
00237   }
00238 #endif
00239   G4mstgrelem::const_iterator cite;
00240   cite = theG4tgrElements.find( name ); 
00241   if( cite == theG4tgrElements.end() )
00242   {
00243     return 0;
00244   }
00245   else
00246   {
00247 #ifdef G4VERBOSE
00248     if( G4tgrMessenger::GetVerboseLevel() >= 3 )
00249     {
00250       DumpElementList();
00251       G4cout << " G4tgrElement found: "
00252              << ( (*cite).second )->GetName() << G4endl;
00253     }
00254 #endif
00255     return (*cite).second;
00256   }
00257 }
00258 
00259 
00260 //-------------------------------------------------------------
00261 G4tgrMaterial* G4tgrMaterialFactory::FindMaterial(const G4String & name) const 
00262 {
00263 #ifdef G4VERBOSE
00264   if( G4tgrMessenger::GetVerboseLevel() >= 3 )
00265   {
00266     G4cout << " G4tgrMaterialFactory::FindMaterial() - " << name << G4endl;
00267   }
00268 #endif
00269   G4mstgrmate::const_iterator cite;
00270   cite = theG4tgrMaterials.find( name );
00271   if( cite == theG4tgrMaterials.end() )
00272   {
00273     return 0;
00274   }
00275   else
00276   {
00277     return (*cite).second;
00278   }
00279 }
00280 
00281 
00282 //-------------------------------------------------------------
00283 void G4tgrMaterialFactory::DumpIsotopeList() const
00284 {
00285   G4cout << " @@@@@@@@@@@@@@@@ DUMPING G4tgrIsotope's List " << G4endl;
00286   G4mstgrisot::const_iterator cite;
00287   for(cite = theG4tgrIsotopes.begin(); cite != theG4tgrIsotopes.end(); cite++)
00288   {
00289     G4cout << " ISOT: " << (*cite).second->GetName() << G4endl;
00290   }
00291 }
00292 
00293 
00294 //-------------------------------------------------------------
00295 void G4tgrMaterialFactory::DumpElementList() const 
00296 {
00297   G4cout << " @@@@@@@@@@@@@@@@ DUMPING G4tgrElement's List " << G4endl;
00298   G4mstgrelem::const_iterator cite;
00299   for(cite = theG4tgrElements.begin(); cite != theG4tgrElements.end(); cite++)
00300   {
00301     G4cout << " ELEM: " << (*cite).second->GetName() << G4endl;
00302   }
00303 }
00304 
00305 
00306 //-------------------------------------------------------------
00307 void G4tgrMaterialFactory::DumpMaterialList() const
00308 {
00309   G4cout << " @@@@@@@@@@@@@@@@ DUMPING G4tgrMaterial's List " << G4endl;
00310   G4mstgrmate::const_iterator cite;
00311   for(cite = theG4tgrMaterials.begin(); cite != theG4tgrMaterials.end(); cite++)
00312   {
00313     G4tgrMaterial* mate = (*cite).second;
00314     G4cout << " MATE: " << mate->GetName() << " Type: " << mate->GetType() 
00315            << " NoComponents= " << mate->GetNumberOfComponents() << G4endl;
00316   }
00317 }
00318  
00319 
00320 //-------------------------------------------------------------
00321 void G4tgrMaterialFactory::
00322 ErrorAlreadyExists(const G4String& object,
00323                    const std::vector<G4String>& wl, const G4bool bNoRepeating )
00324 {
00325   G4String msg = object + G4String(" repeated");
00326   if( bNoRepeating )
00327   {
00328     G4tgrUtils::DumpVS( wl, (G4String("!!!! EXITING: ") + msg).c_str() );
00329     G4Exception("G4tgrMaterialFactory", "FatalError",
00330                 FatalException, "Aborting...");
00331   }
00332   else
00333   {
00334 #ifdef G4VERBOSE
00335     if( G4tgrMessenger::GetVerboseLevel() >= 1 )
00336     {
00337       G4tgrUtils::DumpVS( wl, (G4String("!! WARNING: ") + msg).c_str() ); 
00338     }
00339 #endif
00340   }
00341 }

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