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