Geant4 Cross Reference |
1 // 1 2 // ******************************************* 3 // * License and Disclaimer 4 // * 5 // * The Geant4 software is copyright of th 6 // * the Geant4 Collaboration. It is provided 7 // * conditions of the Geant4 Software License 8 // * LICENSE and available at http://cern.ch/ 9 // * include a list of copyright holders. 10 // * 11 // * Neither the authors of this software syst 12 // * institutes,nor the agencies providing fin 13 // * work make any representation or warran 14 // * regarding this software system or assum 15 // * use. Please see the license in the file 16 // * for the full disclaimer and the limitatio 17 // * 18 // * This code implementation is the result 19 // * technical work of the GEANT4 collaboratio 20 // * By using, copying, modifying or distri 21 // * any work based on the software) you ag 22 // * use in resulting scientific publicati 23 // * acceptance of all terms of the Geant4 Sof 24 // ******************************************* 25 // 26 // G4tgrMaterialFactory implementation 27 // 28 // Author: P.Arce, CIEMAT (November 2007) 29 // ------------------------------------------- 30 31 #include "G4tgrMaterialFactory.hh" 32 #include "G4tgrUtils.hh" 33 #include "G4tgrElementSimple.hh" 34 #include "G4tgrElementFromIsotopes.hh" 35 #include "G4tgrMaterialSimple.hh" 36 #include "G4tgrMaterialMixture.hh" 37 #include "G4tgrFileReader.hh" 38 #include "G4tgrMessenger.hh" 39 40 G4ThreadLocal G4tgrMaterialFactory* G4tgrMater 41 42 // ------------------------------------------- 43 G4tgrMaterialFactory::G4tgrMaterialFactory() 44 { 45 } 46 47 // ------------------------------------------- 48 G4tgrMaterialFactory* G4tgrMaterialFactory::Ge 49 { 50 if(theInstance == nullptr) 51 { 52 theInstance = new G4tgrMaterialFactory; 53 } 54 return theInstance; 55 } 56 57 // ------------------------------------------- 58 G4tgrMaterialFactory::~G4tgrMaterialFactory() 59 { 60 for(auto isotcite = theG4tgrIsotopes.cbegin( 61 isotcite != theG4tgrIsotopes.cend() 62 { 63 delete(*isotcite).second; 64 } 65 theG4tgrIsotopes.clear(); 66 67 for(auto elemcite = theG4tgrElements.cbegin( 68 elemcite != theG4tgrElements.cend() 69 { 70 delete(*elemcite).second; 71 } 72 theG4tgrElements.clear(); 73 74 for(auto matcite = theG4tgrMaterials.cbegin( 75 matcite != theG4tgrMaterials.cend() 76 { 77 delete(*matcite).second; 78 } 79 theG4tgrMaterials.clear(); 80 delete theInstance; 81 } 82 83 // ------------------------------------------- 84 G4tgrIsotope* G4tgrMaterialFactory::AddIsotope 85 { 86 //---------- Look if isotope exists 87 if(FindIsotope(G4tgrUtils::GetString(wl[1])) 88 { 89 ErrorAlreadyExists("isotope", wl); 90 } 91 92 G4tgrIsotope* isot = new G4tgrIsotope(wl); 93 theG4tgrIsotopes[isot->GetName()] = isot; 94 95 return isot; 96 } 97 98 // ------------------------------------------- 99 G4tgrElementSimple* 100 G4tgrMaterialFactory::AddElementSimple(const s 101 { 102 //---------- Look if element exists 103 if(FindElement(G4tgrUtils::GetString(wl[1])) 104 { 105 ErrorAlreadyExists("element", wl); 106 } 107 108 G4tgrElementSimple* elem = new G4tgrElementS 109 theG4tgrElements[elem->GetName()] = elem; 110 111 return elem; 112 } 113 114 // ------------------------------------------- 115 G4tgrElementFromIsotopes* 116 G4tgrMaterialFactory::AddElementFromIsotopes(c 117 { 118 //---------- Look if element exists 119 if(FindElement(G4tgrUtils::GetString(wl[1])) 120 { 121 ErrorAlreadyExists("element", wl); 122 } 123 124 G4tgrElementFromIsotopes* elem = new G4tgrEl 125 theG4tgrElements[elem->GetName()] = elem; 126 127 return elem; 128 } 129 130 // ------------------------------------------- 131 G4tgrMaterialSimple* 132 G4tgrMaterialFactory::AddMaterialSimple(const 133 { 134 #ifdef G4VERBOSE 135 if(G4tgrMessenger::GetVerboseLevel() >= 2) 136 { 137 G4cout << " G4tgrMaterialFactory::AddMater 138 } 139 #endif 140 141 //---------- Look if material exists 142 if(FindMaterial(G4tgrUtils::GetString(wl[1]) 143 { 144 ErrorAlreadyExists("material simple", wl); 145 } 146 147 G4tgrMaterialSimple* mate = new G4tgrMateria 148 149 //---------- register this material 150 theG4tgrMaterials[mate->GetName()] = mate; 151 152 return mate; 153 } 154 155 // ------------------------------------------- 156 G4tgrMaterialMixture* 157 G4tgrMaterialFactory::AddMaterialMixture(const 158 const 159 { 160 #ifdef G4VERBOSE 161 if(G4tgrMessenger::GetVerboseLevel() >= 2) 162 { 163 G4cout << " G4tgrMaterialFactory::AddMater 164 } 165 #endif 166 167 //---------- Look if material already exists 168 if(FindMaterial(G4tgrUtils::GetString(wl[1]) 169 { 170 ErrorAlreadyExists("material mixture", wl) 171 } 172 173 G4tgrMaterialMixture* mate; 174 mate = new G4tgrMaterialMixture(mixtType, wl 175 176 //---------- register this material 177 theG4tgrMaterials[mate->GetName()] = mate; 178 179 return mate; 180 } 181 182 // ------------------------------------------- 183 G4tgrIsotope* G4tgrMaterialFactory::FindIsotop 184 { 185 #ifdef G4VERBOSE 186 if(G4tgrMessenger::GetVerboseLevel() >= 3) 187 { 188 G4cout << " G4tgrMaterialFactory::FindIsot 189 } 190 #endif 191 192 G4mstgrisot::const_iterator cite; 193 cite = theG4tgrIsotopes.find(name); 194 if(cite == theG4tgrIsotopes.cend()) 195 { 196 return nullptr; 197 } 198 else 199 { 200 #ifdef G4VERBOSE 201 if(G4tgrMessenger::GetVerboseLevel() >= 3) 202 { 203 G4cout << " G4tgrIsotope found: " << ((* 204 << G4endl; 205 } 206 #endif 207 return (*cite).second; 208 } 209 } 210 211 // ------------------------------------------- 212 G4tgrElement* G4tgrMaterialFactory::FindElemen 213 { 214 #ifdef G4VERBOSE 215 if(G4tgrMessenger::GetVerboseLevel() >= 3) 216 { 217 G4cout << " G4tgrMaterialFactory::FindElem 218 } 219 #endif 220 G4mstgrelem::const_iterator cite; 221 cite = theG4tgrElements.find(name); 222 if(cite == theG4tgrElements.cend()) 223 { 224 return nullptr; 225 } 226 else 227 { 228 #ifdef G4VERBOSE 229 if(G4tgrMessenger::GetVerboseLevel() >= 3) 230 { 231 DumpElementList(); 232 G4cout << " G4tgrElement found: " << ((* 233 << G4endl; 234 } 235 #endif 236 return (*cite).second; 237 } 238 } 239 240 // ------------------------------------------- 241 G4tgrMaterial* G4tgrMaterialFactory::FindMater 242 { 243 #ifdef G4VERBOSE 244 if(G4tgrMessenger::GetVerboseLevel() >= 3) 245 { 246 G4cout << " G4tgrMaterialFactory::FindMate 247 } 248 #endif 249 G4mstgrmate::const_iterator cite; 250 cite = theG4tgrMaterials.find(name); 251 if(cite == theG4tgrMaterials.cend()) 252 { 253 return nullptr; 254 } 255 else 256 { 257 return (*cite).second; 258 } 259 } 260 261 // ------------------------------------------- 262 void G4tgrMaterialFactory::DumpIsotopeList() c 263 { 264 G4cout << " @@@@@@@@@@@@@@@@ DUMPING G4tgrIs 265 for(auto cite = theG4tgrIsotopes.cbegin(); 266 cite != theG4tgrIsotopes.cend(); ++ 267 { 268 G4cout << " ISOT: " << (*cite).second->Get 269 } 270 } 271 272 // ------------------------------------------- 273 void G4tgrMaterialFactory::DumpElementList() c 274 { 275 G4cout << " @@@@@@@@@@@@@@@@ DUMPING G4tgrEl 276 for(auto cite = theG4tgrElements.cbegin(); 277 cite != theG4tgrElements.cend(); ++ 278 { 279 G4cout << " ELEM: " << (*cite).second->Get 280 } 281 } 282 283 // ------------------------------------------- 284 void G4tgrMaterialFactory::DumpMaterialList() 285 { 286 G4cout << " @@@@@@@@@@@@@@@@ DUMPING G4tgrMa 287 for(auto cite = theG4tgrMaterials.cbegin(); 288 cite != theG4tgrMaterials.cend(); + 289 { 290 G4tgrMaterial* mate = (*cite).second; 291 G4cout << " MATE: " << mate->GetName() << 292 << " NoComponents= " << mate->GetNu 293 } 294 } 295 296 // ------------------------------------------- 297 void G4tgrMaterialFactory::ErrorAlreadyExists( 298 299 300 { 301 G4String msg = object + G4String(" repeated" 302 if(bNoRepeating) 303 { 304 G4tgrUtils::DumpVS(wl, (G4String("!!!! EXI 305 G4Exception("G4tgrMaterialFactory", "Fatal 306 "Aborting..."); 307 } 308 else 309 { 310 #ifdef G4VERBOSE 311 if(G4tgrMessenger::GetVerboseLevel() >= 1) 312 { 313 G4tgrUtils::DumpVS(wl, (G4String("!! WAR 314 } 315 #endif 316 } 317 } 318