Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // G4tgbMaterialMgr implementation << 27 // 26 // 28 // Author: P.Arce, CIEMAT (November 2007) << 27 // $Id: G4tgbMaterialMgr.cc 66872 2013-01-15 01:25:57Z japost $ 29 // ------------------------------------------- << 28 // >> 29 // >> 30 // class G4tgbMaterialMgr >> 31 >> 32 // History: >> 33 // - Created. P.Arce, CIEMAT (November 2007) >> 34 // ------------------------------------------------------------------------- 30 35 31 #include "G4tgbMaterialMgr.hh" 36 #include "G4tgbMaterialMgr.hh" 32 #include "G4tgbMaterialMixtureByWeight.hh" 37 #include "G4tgbMaterialMixtureByWeight.hh" 33 #include "G4tgbMaterialMixtureByVolume.hh" 38 #include "G4tgbMaterialMixtureByVolume.hh" 34 #include "G4tgbMaterialMixtureByNoAtoms.hh" 39 #include "G4tgbMaterialMixtureByNoAtoms.hh" 35 #include "G4tgbMaterialSimple.hh" 40 #include "G4tgbMaterialSimple.hh" 36 41 37 #include "G4tgrMaterialFactory.hh" 42 #include "G4tgrMaterialFactory.hh" 38 #include "G4tgrMaterialSimple.hh" 43 #include "G4tgrMaterialSimple.hh" 39 #include "G4tgrMaterialMixture.hh" 44 #include "G4tgrMaterialMixture.hh" 40 #include "G4tgrUtils.hh" 45 #include "G4tgrUtils.hh" 41 #include "G4tgrMessenger.hh" 46 #include "G4tgrMessenger.hh" 42 #include "G4NistManager.hh" 47 #include "G4NistManager.hh" 43 48 44 G4ThreadLocal G4tgbMaterialMgr* G4tgbMaterialM << 45 49 46 // ------------------------------------------- << 50 G4ThreadLocal G4tgbMaterialMgr* G4tgbMaterialMgr::theInstance = 0; >> 51 >> 52 >> 53 // ------------------------------------------------------------------------- 47 G4tgbMaterialMgr::G4tgbMaterialMgr() 54 G4tgbMaterialMgr::G4tgbMaterialMgr() 48 { 55 { 49 } 56 } 50 57 51 // ------------------------------------------- << 58 >> 59 // ------------------------------------------------------------------------- 52 G4tgbMaterialMgr* G4tgbMaterialMgr::GetInstanc 60 G4tgbMaterialMgr* G4tgbMaterialMgr::GetInstance() 53 { 61 { 54 if(theInstance == nullptr) << 62 if( !theInstance ) 55 { 63 { 56 theInstance = new G4tgbMaterialMgr; 64 theInstance = new G4tgbMaterialMgr; 57 theInstance->CopyIsotopes(); 65 theInstance->CopyIsotopes(); 58 theInstance->CopyElements(); 66 theInstance->CopyElements(); 59 theInstance->CopyMaterials(); 67 theInstance->CopyMaterials(); 60 } 68 } 61 return theInstance; 69 return theInstance; 62 } 70 } 63 71 64 // ------------------------------------------- << 72 >> 73 // ------------------------------------------------------------------------- 65 G4tgbMaterialMgr::~G4tgbMaterialMgr() 74 G4tgbMaterialMgr::~G4tgbMaterialMgr() 66 { 75 { 67 for(auto isotcite = theG4tgbIsotopes.cbegin( << 76 G4mstgbisot::const_iterator isotcite; 68 isotcite != theG4tgbIsotopes.cend() << 77 for( isotcite = theG4tgbIsotopes.begin(); >> 78 isotcite != theG4tgbIsotopes.end(); isotcite++) 69 { 79 { 70 delete(*isotcite).second; << 80 delete (*isotcite).second; 71 } 81 } 72 theG4tgbIsotopes.clear(); 82 theG4tgbIsotopes.clear(); 73 83 74 for(auto elemcite = theG4tgbElements.cbegin( << 84 G4mstgbelem::const_iterator elemcite; 75 elemcite != theG4tgbElements.cend() << 85 for( elemcite = theG4tgbElements.begin(); >> 86 elemcite != theG4tgbElements.end(); elemcite++) 76 { 87 { 77 delete(*elemcite).second; << 88 delete (*elemcite).second; 78 } 89 } 79 theG4tgbElements.clear(); 90 theG4tgbElements.clear(); 80 91 81 for(auto matcite = theG4tgbMaterials.cbegin( << 92 G4mstgbmate::const_iterator matcite; 82 matcite != theG4tgbMaterials.cend() << 93 for( matcite = theG4tgbMaterials.begin(); >> 94 matcite != theG4tgbMaterials.end(); matcite++) 83 { 95 { 84 delete(*matcite).second; << 96 delete (*matcite).second; 85 } 97 } 86 theG4tgbMaterials.clear(); 98 theG4tgbMaterials.clear(); 87 99 88 delete theInstance; 100 delete theInstance; 89 } 101 } 90 102 91 // ------------------------------------------- << 103 >> 104 // ------------------------------------------------------------------------- 92 void G4tgbMaterialMgr::CopyIsotopes() 105 void G4tgbMaterialMgr::CopyIsotopes() 93 { 106 { 94 const G4mstgrisot tgrIsots = << 107 const G4mstgrisot tgrIsots 95 G4tgrMaterialFactory::GetInstance()->GetIs << 108 = G4tgrMaterialFactory::GetInstance()->GetIsotopeList(); 96 for(auto cite = tgrIsots.cbegin(); cite != t << 109 G4mstgrisot::const_iterator cite; >> 110 for( cite = tgrIsots.begin(); cite != tgrIsots.end(); cite++ ) 97 { 111 { 98 G4tgrIsotope* tgr = (*cite) << 112 G4tgrIsotope* tgr = (*cite).second; 99 G4tgbIsotope* tgb = new G4t << 113 G4tgbIsotope* tgb = new G4tgbIsotope( tgr ); 100 theG4tgbIsotopes[tgb->GetName()] = tgb; 114 theG4tgbIsotopes[tgb->GetName()] = tgb; 101 } 115 } 102 } 116 } 103 117 104 // ------------------------------------------- << 118 >> 119 // ------------------------------------------------------------------------- 105 void G4tgbMaterialMgr::CopyElements() 120 void G4tgbMaterialMgr::CopyElements() 106 { 121 { 107 const G4mstgrelem tgrElems = << 122 const G4mstgrelem tgrElems 108 G4tgrMaterialFactory::GetInstance()->GetEl << 123 = G4tgrMaterialFactory::GetInstance()->GetElementList(); 109 for(auto cite = tgrElems.cbegin(); cite != t << 124 G4mstgrelem::const_iterator cite; >> 125 for( cite = tgrElems.begin(); cite != tgrElems.end(); cite++ ) 110 { 126 { 111 G4tgrElement* tgr = (*cite) << 127 G4tgrElement* tgr = (*cite).second; 112 G4tgbElement* tgb = new G4t << 128 G4tgbElement* tgb = new G4tgbElement( tgr ); 113 theG4tgbElements[tgb->GetName()] = tgb; 129 theG4tgbElements[tgb->GetName()] = tgb; 114 } 130 } 115 } 131 } 116 132 117 // ------------------------------------------- << 133 >> 134 // ------------------------------------------------------------------------- 118 void G4tgbMaterialMgr::CopyMaterials() 135 void G4tgbMaterialMgr::CopyMaterials() 119 { 136 { 120 const G4mstgrmate tgrMates = << 137 const G4mstgrmate tgrMates 121 G4tgrMaterialFactory::GetInstance()->GetMa << 138 = G4tgrMaterialFactory::GetInstance()->GetMaterialList(); 122 for(auto cite = tgrMates.cbegin(); cite != t << 139 G4mstgrmate::const_iterator cite; >> 140 for( cite = tgrMates.begin(); cite != tgrMates.end(); cite++ ) 123 { 141 { 124 G4tgrMaterial* tgr = (*cite).second; 142 G4tgrMaterial* tgr = (*cite).second; 125 G4tgbMaterial* tgb = nullptr; << 143 G4tgbMaterial* tgb = 0; 126 if(tgr->GetType() == "MaterialSimple") << 144 if( tgr->GetType() == "MaterialSimple" ) { 127 { << 145 tgb = new G4tgbMaterialSimple( tgr ); 128 tgb = new G4tgbMaterialSimple(tgr); << 146 } else if( tgr->GetType() == "MaterialMixtureByWeight" ) { 129 } << 147 tgb = new G4tgbMaterialMixtureByWeight( tgr ); 130 else if(tgr->GetType() == "MaterialMixture << 148 } else if( tgr->GetType() == "MaterialMixtureByNoAtoms" ) { 131 { << 149 tgb = new G4tgbMaterialMixtureByNoAtoms( tgr ); 132 tgb = new G4tgbMaterialMixtureByWeight(t << 150 } else if( tgr->GetType() == "MaterialMixtureByVolume" ) { 133 } << 151 tgb = new G4tgbMaterialMixtureByVolume( tgr ); 134 else if(tgr->GetType() == "MaterialMixture << 152 } else { 135 { << 136 tgb = new G4tgbMaterialMixtureByNoAtoms( << 137 } << 138 else if(tgr->GetType() == "MaterialMixture << 139 { << 140 tgb = new G4tgbMaterialMixtureByVolume(t << 141 } << 142 else << 143 { << 144 return; 153 return; 145 } 154 } 146 theG4tgbMaterials[tgb->GetName()] = tgb; 155 theG4tgbMaterials[tgb->GetName()] = tgb; 147 } 156 } 148 } 157 } 149 158 150 // ------------------------------------------- << 159 151 G4Isotope* G4tgbMaterialMgr::FindOrBuildG4Isot << 160 // ------------------------------------------------------------------------- >> 161 G4Isotope* G4tgbMaterialMgr::FindOrBuildG4Isotope(const G4String & name) 152 { 162 { 153 G4Isotope* g4isot = FindBuiltG4Isotope(name) << 163 G4Isotope* g4isot = FindBuiltG4Isotope( name ); 154 if(g4isot == nullptr) << 164 if( g4isot == 0 ) 155 { 165 { 156 G4tgbIsotope* tgbisot = FindG4tgbIsotope(n << 166 G4tgbIsotope* tgbisot = FindG4tgbIsotope( name ); 157 // FindG4tgbIsotope never returns nullptr, << 167 // FindG4tgbIsotope never returns 0, otherwise if not found, crashes 158 g4isot = tgbisot->BuildG4Isotope(); 168 g4isot = tgbisot->BuildG4Isotope(); 159 // Register it 169 // Register it 160 G4String isotname = g4isot->GetName( << 170 G4String isotname = g4isot->GetName(); 161 theG4Isotopes[isotname] = g4isot; 171 theG4Isotopes[isotname] = g4isot; 162 } 172 } 163 else 173 else 164 { << 174 { 165 #ifdef G4VERBOSE 175 #ifdef G4VERBOSE 166 if(G4tgrMessenger::GetVerboseLevel() >= 1) << 176 if( G4tgrMessenger::GetVerboseLevel() >= 1 ) 167 { 177 { 168 G4cout << " G4tgbMaterialMgr::FindOrBuil 178 G4cout << " G4tgbMaterialMgr::FindOrBuildG4Isotope() -" 169 << " G4Isotope already built: " < 179 << " G4Isotope already built: " << g4isot->GetName() << G4endl; 170 } 180 } 171 #endif 181 #endif 172 } 182 } 173 183 174 #ifdef G4VERBOSE 184 #ifdef G4VERBOSE 175 if(G4tgrMessenger::GetVerboseLevel() >= 2) << 185 if( G4tgrMessenger::GetVerboseLevel() >= 2 ) 176 { 186 { 177 G4cout << " G4tgbMaterialMgr::FindOrBuildG << 187 G4cout << " G4tgbMaterialMgr::FindOrBuildG4Isotope() - Isotope: " 178 << G4endl; << 188 << name << G4endl; 179 } 189 } 180 #endif 190 #endif 181 return g4isot; 191 return g4isot; 182 } << 192 } 183 193 184 // ------------------------------------------- << 185 G4Isotope* G4tgbMaterialMgr::FindBuiltG4Isotop << 186 { << 187 G4Isotope* g4isot = nullptr; << 188 194 189 G4msg4isot::const_iterator cite = theG4Isoto << 195 // ------------------------------------------------------------------------- 190 if(cite != theG4Isotopes.cend()) << 196 G4Isotope* G4tgbMaterialMgr::FindBuiltG4Isotope(const G4String & name) const >> 197 { >> 198 G4Isotope* g4isot = 0; >> 199 >> 200 G4msg4isot::const_iterator cite = theG4Isotopes.find( name ); >> 201 if( cite != theG4Isotopes.end() ) 191 { 202 { 192 g4isot = (*cite).second; 203 g4isot = (*cite).second; 193 #ifdef G4VERBOSE 204 #ifdef G4VERBOSE 194 if(G4tgrMessenger::GetVerboseLevel() >= 2) << 205 if( G4tgrMessenger::GetVerboseLevel() >= 2 ) 195 { << 206 { 196 G4cout << " G4tgbMaterialMgr::FindBuiltG << 207 G4cout << " G4tgbMaterialMgr::FindBuiltG4Isotope() - Isotope: " 197 << " = " << g4isot << G4endl; << 208 << name << " = " << g4isot << G4endl; 198 } << 209 } 199 #endif 210 #endif 200 } << 211 >> 212 } 201 213 202 return g4isot; 214 return g4isot; 203 } 215 } 204 216 205 // ------------------------------------------- << 217 206 G4tgbIsotope* G4tgbMaterialMgr::FindG4tgbIsoto << 218 // ------------------------------------------------------------------------- 207 << 219 G4tgbIsotope* G4tgbMaterialMgr::FindG4tgbIsotope(const G4String & name, >> 220 G4bool bMustExist ) const 208 { 221 { 209 G4tgbIsotope* isot = nullptr; << 222 G4tgbIsotope* isot = 0; 210 223 211 G4mstgbisot::const_iterator cite = theG4tgbI << 224 G4mstgbisot::const_iterator cite = theG4tgbIsotopes.find( name ); 212 if(cite != theG4tgbIsotopes.cend()) << 225 if( cite != theG4tgbIsotopes.end() ) 213 { 226 { 214 #ifdef G4VERBOSE 227 #ifdef G4VERBOSE 215 if(G4tgrMessenger::GetVerboseLevel() >= 2) << 228 if( G4tgrMessenger::GetVerboseLevel() >= 2 ) 216 { 229 { 217 G4cout << " G4tgbMaterialMgr::FindG4tgbI 230 G4cout << " G4tgbMaterialMgr::FindG4tgbIsotope() -" 218 << " G4tgbIsotope found: " << ((* << 231 << " G4tgbIsotope found: " << ( (*cite).second )->GetName() 219 << G4endl; 232 << G4endl; 220 } 233 } 221 #endif 234 #endif 222 isot = (*cite).second; 235 isot = (*cite).second; 223 } 236 } 224 if((isot == nullptr) && bMustExist) << 237 if( (isot == 0) && bMustExist ) 225 { 238 { 226 G4String ErrMessage = "Isotope " + name + 239 G4String ErrMessage = "Isotope " + name + " not found !"; 227 G4Exception("G4tgbMaterialMgr::FindG4tgbIs << 240 G4Exception("G4tgbMaterialMgr::FindG4tgbIsotope()", 228 FatalException, ErrMessage); << 241 "InvalidSetup", FatalException, ErrMessage); 229 } 242 } 230 243 231 return isot; 244 return isot; 232 } 245 } 233 246 234 // ------------------------------------------- << 247 235 G4Element* G4tgbMaterialMgr::FindOrBuildG4Elem << 248 // ------------------------------------------------------------------------- 236 << 249 G4Element* G4tgbMaterialMgr::FindOrBuildG4Element(const G4String & name, >> 250 G4bool bMustExist ) 237 { 251 { 238 G4Element* g4elem = FindBuiltG4Element(name) << 252 G4Element* g4elem = FindBuiltG4Element( name ); 239 if(g4elem == nullptr) << 253 if( g4elem == 0 ) 240 { 254 { 241 G4tgbElement* tgbelem = FindG4tgbElement(n << 255 G4tgbElement* tgbelem = FindG4tgbElement( name, false ); 242 if(tgbelem == nullptr) << 256 if( tgbelem == 0) 243 { 257 { 244 // If FindG4tgbElement returns nullptr, << 258 // If FindG4tgbElement returns 0, look for a G4NISTElement 245 G4cout << " G4NistManager::Instance()-> 259 G4cout << " G4NistManager::Instance()->FindOrBuildElement( " << G4endl; 246 g4elem = G4NistManager::Instance()->Find 260 g4elem = G4NistManager::Instance()->FindOrBuildElement(name); 247 } 261 } 248 else 262 else 249 { 263 { 250 if(tgbelem->GetType() == "ElementSimple" << 264 if( tgbelem->GetType() == "ElementSimple" ) 251 { 265 { 252 g4elem = tgbelem->BuildG4ElementSimple 266 g4elem = tgbelem->BuildG4ElementSimple(); 253 } 267 } 254 else if(tgbelem->GetType() == "ElementFr << 268 else if( tgbelem->GetType() == "ElementFromIsotopes" ) 255 { 269 { 256 g4elem = tgbelem->BuildG4ElementFromIs 270 g4elem = tgbelem->BuildG4ElementFromIsotopes(); 257 } 271 } 258 else 272 else 259 { 273 { 260 G4String ErrMessage = << 274 G4String ErrMessage = "Element type " + tgbelem->GetType() 261 "Element type " + tgbelem->GetType() << 275 + " does not exist !"; 262 G4Exception("G4tgbMaterialMgr::GetG4El << 276 G4Exception("G4tgbMaterialMgr::GetG4Element()", 263 FatalException, ErrMessage << 277 "InvalidSetup", FatalException, ErrMessage); 264 } 278 } 265 } 279 } 266 // Register it 280 // Register it 267 if((g4elem != nullptr)) << 281 if( (g4elem != 0) ) 268 { 282 { 269 theG4Elements[g4elem->GetName()] = g4ele 283 theG4Elements[g4elem->GetName()] = g4elem; 270 #ifdef G4VERBOSE 284 #ifdef G4VERBOSE 271 if(G4tgrMessenger::GetVerboseLevel() >= << 285 if( G4tgrMessenger::GetVerboseLevel() >= 2 ) 272 { << 286 { 273 G4cout << " G4tgbMaterialMgr::FindOrBu << 287 G4cout << " G4tgbMaterialMgr::FindOrBuildG4Element() - Element: " 274 << name << G4endl; << 288 << name << G4endl; 275 } << 289 } 276 #endif 290 #endif 277 } 291 } 278 else 292 else 279 { 293 { 280 if(bMustExist) << 294 if( bMustExist ) 281 { 295 { 282 G4String ErrMessage = "Element " + nam 296 G4String ErrMessage = "Element " + name + " not found !"; 283 G4Exception("G4tgbMaterialMgr::FindOrB << 297 G4Exception("G4tgbMaterialMgr::FindOrBuildG4Element()", 284 FatalException, ErrMessage << 298 "InvalidSetup", FatalException, ErrMessage); 285 } 299 } 286 #ifdef G4VERBOSE 300 #ifdef G4VERBOSE 287 if(G4tgrMessenger::GetVerboseLevel() >= << 301 if( G4tgrMessenger::GetVerboseLevel() >= 2 ) 288 { 302 { 289 G4cout << " G4tgbMaterialMgr::FindOrBu 303 G4cout << " G4tgbMaterialMgr::FindOrBuildG4Element() - Element: " 290 << name << " not found " << G4 304 << name << " not found " << G4endl; 291 } 305 } 292 #endif 306 #endif 293 } 307 } 294 } 308 } 295 else 309 else 296 { << 310 { 297 #ifdef G4VERBOSE 311 #ifdef G4VERBOSE 298 if(G4tgrMessenger::GetVerboseLevel() >= 1) << 312 if( G4tgrMessenger::GetVerboseLevel() >= 1 ) 299 { 313 { 300 G4cout << " G4tgbMaterialMgr::GetG4Eleme 314 G4cout << " G4tgbMaterialMgr::GetG4Element() -" 301 << " G4Element already built: " < << 315 << " G4Element already built: " << g4elem->GetName() << G4endl; 302 } 316 } 303 #endif 317 #endif 304 } 318 } 305 319 306 return g4elem; 320 return g4elem; 307 } << 321 } 308 322 309 // ------------------------------------------- << 310 G4Element* G4tgbMaterialMgr::FindBuiltG4Elemen << 311 { << 312 G4Element* g4elem = nullptr; << 313 323 314 G4msg4elem::const_iterator cite = theG4Eleme << 324 // ------------------------------------------------------------------------- 315 if(cite != theG4Elements.cend()) << 325 G4Element* G4tgbMaterialMgr::FindBuiltG4Element(const G4String & name) const >> 326 { >> 327 G4Element* g4elem = 0; >> 328 >> 329 G4msg4elem::const_iterator cite = theG4Elements.find( name ); >> 330 if( cite != theG4Elements.end() ) 316 { 331 { 317 g4elem = (*cite).second; 332 g4elem = (*cite).second; 318 #ifdef G4VERBOSE 333 #ifdef G4VERBOSE 319 if(G4tgrMessenger::GetVerboseLevel() >= 2) << 334 if( G4tgrMessenger::GetVerboseLevel() >= 2 ) 320 { 335 { 321 G4cout << " G4tgbMaterialMgr::FindBuiltG << 336 G4cout << " G4tgbMaterialMgr::FindBuiltG4Element() - Element: " 322 << " = " << g4elem << G4endl; << 337 << name << " = " << g4elem << G4endl; 323 } 338 } 324 #endif 339 #endif 325 } << 340 } 326 341 327 return g4elem; 342 return g4elem; 328 } 343 } 329 344 330 // ------------------------------------------- << 345 331 G4tgbElement* G4tgbMaterialMgr::FindG4tgbEleme << 346 // ------------------------------------------------------------------------- 332 << 347 G4tgbElement* G4tgbMaterialMgr::FindG4tgbElement(const G4String & name, >> 348 G4bool bMustExist ) const 333 { 349 { 334 G4tgbElement* elem = nullptr; << 350 G4tgbElement* elem = 0; 335 351 336 G4mstgbelem::const_iterator cite = theG4tgbE << 352 G4mstgbelem::const_iterator cite = theG4tgbElements.find( name ); 337 if(cite != theG4tgbElements.cend()) << 353 if( cite != theG4tgbElements.end() ) 338 { 354 { 339 #ifdef G4VERBOSE 355 #ifdef G4VERBOSE 340 if(G4tgrMessenger::GetVerboseLevel() >= 2) << 356 if( G4tgrMessenger::GetVerboseLevel() >= 2 ) 341 { 357 { 342 G4cout << " G4tgbMaterialMgr::FindG4tgbE 358 G4cout << " G4tgbMaterialMgr::FindG4tgbElement() -" 343 << " G4tgbElement found: " << ((* << 359 << " G4tgbElement found: " << ( (*cite).second )->GetName() 344 << G4endl; 360 << G4endl; 345 } 361 } 346 #endif 362 #endif 347 elem = (*cite).second; 363 elem = (*cite).second; 348 } 364 } 349 if((elem == nullptr) && bMustExist) << 365 if( (elem == 0) && bMustExist ) 350 { 366 { 351 G4String ErrMessage = "Element " + name + 367 G4String ErrMessage = "Element " + name + " not found !"; 352 G4Exception("G4tgbMaterialMgr::FindG4tgbEl << 368 G4Exception("G4tgbMaterialMgr::FindG4tgbElement()", 353 FatalException, ErrMessage); << 369 "InvalidSetup", FatalException, ErrMessage); 354 } 370 } 355 371 356 return elem; 372 return elem; 357 } 373 } 358 374 359 // ------------------------------------------- << 375 360 G4Material* G4tgbMaterialMgr::FindOrBuildG4Mat << 376 // ------------------------------------------------------------------------- 361 << 377 G4Material* G4tgbMaterialMgr::FindOrBuildG4Material(const G4String & name, >> 378 G4bool bMustExist ) 362 { 379 { 363 G4Material* g4mate = FindBuiltG4Material(nam << 380 G4Material* g4mate = FindBuiltG4Material( name ); 364 if(g4mate == nullptr) << 381 if( g4mate == 0) 365 { 382 { 366 G4tgbMaterial* tgbmate = FindG4tgbMaterial << 383 G4tgbMaterial* tgbmate = FindG4tgbMaterial( name, false ); 367 << 384 368 if(tgbmate == nullptr) << 385 if( tgbmate == 0) 369 { 386 { 370 // if FindG4tgbMaterial() returns 0, loo 387 // if FindG4tgbMaterial() returns 0, look for a G4NISTMaterial 371 g4mate = G4NistManager::Instance()->Find 388 g4mate = G4NistManager::Instance()->FindOrBuildMaterial(name); 372 } 389 } 373 else 390 else 374 { 391 { 375 g4mate = tgbmate->BuildG4Material(); 392 g4mate = tgbmate->BuildG4Material(); 376 393 377 if(tgbmate->GetTgrMate()->GetIonisationM << 394 if( tgbmate->GetTgrMate()->GetIonisationMeanExcitationEnergy() != -1. ) 378 { 395 { 379 g4mate->GetIonisation()->SetMeanExcita << 396 g4mate->GetIonisation()->SetMeanExcitationEnergy(tgbmate-> 380 tgbmate->GetTgrMate()->GetIonisation << 397 GetTgrMate()->GetIonisationMeanExcitationEnergy()); 381 } 398 } 382 } 399 } 383 400 384 // Register it 401 // Register it 385 if(g4mate != nullptr) << 402 if( g4mate != 0 ) 386 { 403 { 387 theG4Materials[g4mate->GetName()] = g4ma 404 theG4Materials[g4mate->GetName()] = g4mate; 388 #ifdef G4VERBOSE 405 #ifdef G4VERBOSE 389 if(G4tgrMessenger::GetVerboseLevel() >= << 406 if( G4tgrMessenger::GetVerboseLevel() >= 2 ) 390 { 407 { 391 G4cout << " G4tgbMaterialMgr::FindOrBu 408 G4cout << " G4tgbMaterialMgr::FindOrBuildG4Material() - Material: " 392 << name << G4endl; 409 << name << G4endl; 393 } 410 } 394 #endif 411 #endif 395 } 412 } 396 else 413 else 397 { 414 { 398 if(bMustExist) << 415 if( bMustExist ) 399 { 416 { 400 G4String ErrMessage = "Material " + na 417 G4String ErrMessage = "Material " + name + " not found !"; 401 G4Exception("G4tgbMaterialMgr::FindOrB << 418 G4Exception("G4tgbMaterialMgr::FindOrBuildG4Material()", 402 FatalException, ErrMessage << 419 "InvalidSetup", FatalException, ErrMessage); 403 } << 420 } 404 #ifdef G4VERBOSE 421 #ifdef G4VERBOSE 405 if(G4tgrMessenger::GetVerboseLevel() >= << 422 if( G4tgrMessenger::GetVerboseLevel() >= 2 ) 406 { 423 { 407 G4cout << " G4tgbMaterialMgr::FindOrBu 424 G4cout << " G4tgbMaterialMgr::FindOrBuildG4Material() - Element: " 408 << name << " not found " << G4 425 << name << " not found " << G4endl; 409 } 426 } 410 #endif 427 #endif 411 } 428 } 412 } 429 } 413 else 430 else 414 { << 431 { 415 #ifdef G4VERBOSE 432 #ifdef G4VERBOSE 416 if(G4tgrMessenger::GetVerboseLevel() >= 1) << 433 if( G4tgrMessenger::GetVerboseLevel() >= 1 ) 417 { 434 { 418 G4cout << " G4tgbMaterialMgr::FindOrBuil 435 G4cout << " G4tgbMaterialMgr::FindOrBuildG4Material() -" 419 << " G4Material already built: " 436 << " G4Material already built: " << g4mate->GetName() << G4endl; 420 } 437 } 421 #endif 438 #endif 422 } 439 } 423 440 424 return g4mate; 441 return g4mate; 425 } 442 } 426 443 427 // ------------------------------------------- << 444 428 G4Material* G4tgbMaterialMgr::FindBuiltG4Mater << 445 // ------------------------------------------------------------------------- >> 446 G4Material* G4tgbMaterialMgr::FindBuiltG4Material(const G4String & name) const 429 { 447 { 430 G4Material* g4mate = nullptr; << 448 G4Material* g4mate = 0; 431 //---------- look for an existing G4Material 449 //---------- look for an existing G4Material 432 G4msg4mate::const_iterator cite = theG4Mater << 450 G4msg4mate::const_iterator cite = theG4Materials.find( name ); 433 if(cite != theG4Materials.cend()) << 451 if( cite != theG4Materials.end() ) 434 { 452 { 435 g4mate = (*cite).second; 453 g4mate = (*cite).second; 436 #ifdef G4VERBOSE 454 #ifdef G4VERBOSE 437 if(G4tgrMessenger::GetVerboseLevel() >= 2) << 455 if( G4tgrMessenger::GetVerboseLevel() >= 2 ) 438 { 456 { 439 G4cout << " G4tgbMaterialMgr::FindBuiltG << 457 G4cout << " G4tgbMaterialMgr::FindBuiltG4Material() - Material: " 440 << " = " << g4mate << G4endl; << 458 << name << " = " << g4mate << G4endl; 441 } 459 } 442 #endif 460 #endif 443 } 461 } 444 462 445 return g4mate; 463 return g4mate; 446 } 464 } 447 465 >> 466 448 // ------------------------------------------- 467 // ------------------------------------------------------------------------- 449 G4tgbMaterial* G4tgbMaterialMgr::FindG4tgbMate << 468 G4tgbMaterial* G4tgbMaterialMgr::FindG4tgbMaterial(const G4String & name, 450 << 469 G4bool bMustExist ) const 451 { 470 { 452 G4tgbMaterial* mate = nullptr; << 471 G4tgbMaterial* mate = 0; 453 G4mstgbmate::const_iterator cite = theG4tgbM << 472 G4mstgbmate::const_iterator cite = theG4tgbMaterials.find( name ); 454 if(cite != theG4tgbMaterials.cend()) << 473 if( cite != theG4tgbMaterials.end() ) 455 { 474 { 456 mate = (*cite).second; 475 mate = (*cite).second; 457 #ifdef G4VERBOSE 476 #ifdef G4VERBOSE 458 if(G4tgrMessenger::GetVerboseLevel() >= 2) << 477 if( G4tgrMessenger::GetVerboseLevel() >= 2 ) 459 { 478 { 460 G4cout << " G4tgbMaterialMgr::FindG4tgbM 479 G4cout << " G4tgbMaterialMgr::FindG4tgbMaterial() -" 461 << " G4tgbMaterial found: " << (( << 480 << " G4tgbMaterial found: " << ( (*cite).second )->GetName() 462 << " type " << ((*cite).second)-> << 481 << " type " << ( (*cite).second )->GetName() << G4endl; 463 } 482 } 464 #endif 483 #endif 465 } 484 } 466 485 467 if((mate == nullptr) && bMustExist) << 486 if( (mate == 0) && bMustExist ) 468 { 487 { 469 G4String ErrMessage = "Material " + name + 488 G4String ErrMessage = "Material " + name + " not found !"; 470 G4Exception("G4tgbMaterialMgr::FindG4tgbMa << 489 G4Exception("G4tgbMaterialMgr::FindG4tgbMaterial()", 471 FatalException, ErrMessage); << 490 "InvalidSetup", FatalException, ErrMessage); 472 } 491 } 473 492 474 return mate; 493 return mate; 475 } 494 } 476 495