00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
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
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
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
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
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
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
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
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 }