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 // G4tgrMaterialFactory implementation << 27 // 26 // 28 // Author: P.Arce, CIEMAT (November 2007) << 27 // $Id$ 29 // ------------------------------------------- << 28 // >> 29 // >> 30 // class G4tgrMaterialFactory >> 31 >> 32 // History: >> 33 // - Created. P.Arce, CIEMAT (November 2007) >> 34 // ------------------------------------------------------------------------- 30 35 31 #include "G4tgrMaterialFactory.hh" 36 #include "G4tgrMaterialFactory.hh" 32 #include "G4tgrUtils.hh" 37 #include "G4tgrUtils.hh" 33 #include "G4tgrElementSimple.hh" 38 #include "G4tgrElementSimple.hh" 34 #include "G4tgrElementFromIsotopes.hh" 39 #include "G4tgrElementFromIsotopes.hh" 35 #include "G4tgrMaterialSimple.hh" 40 #include "G4tgrMaterialSimple.hh" 36 #include "G4tgrMaterialMixture.hh" 41 #include "G4tgrMaterialMixture.hh" 37 #include "G4tgrFileReader.hh" 42 #include "G4tgrFileReader.hh" 38 #include "G4tgrMessenger.hh" 43 #include "G4tgrMessenger.hh" 39 44 40 G4ThreadLocal G4tgrMaterialFactory* G4tgrMater << 41 45 42 // ------------------------------------------- << 46 G4tgrMaterialFactory* G4tgrMaterialFactory::theInstance = 0; >> 47 >> 48 >> 49 //------------------------------------------------------------- 43 G4tgrMaterialFactory::G4tgrMaterialFactory() 50 G4tgrMaterialFactory::G4tgrMaterialFactory() 44 { 51 { 45 } 52 } 46 53 47 // ------------------------------------------- << 54 >> 55 //------------------------------------------------------------- 48 G4tgrMaterialFactory* G4tgrMaterialFactory::Ge 56 G4tgrMaterialFactory* G4tgrMaterialFactory::GetInstance() 49 { 57 { 50 if(theInstance == nullptr) << 58 if( !theInstance ) 51 { 59 { 52 theInstance = new G4tgrMaterialFactory; 60 theInstance = new G4tgrMaterialFactory; 53 } 61 } 54 return theInstance; 62 return theInstance; 55 } 63 } 56 64 57 // ------------------------------------------- << 65 >> 66 //------------------------------------------------------------- 58 G4tgrMaterialFactory::~G4tgrMaterialFactory() 67 G4tgrMaterialFactory::~G4tgrMaterialFactory() 59 { 68 { 60 for(auto isotcite = theG4tgrIsotopes.cbegin( << 69 G4mstgrisot::iterator isotcite; 61 isotcite != theG4tgrIsotopes.cend() << 70 for( isotcite = theG4tgrIsotopes.begin(); >> 71 isotcite != theG4tgrIsotopes.end(); isotcite++) 62 { 72 { 63 delete(*isotcite).second; << 73 delete (*isotcite).second; 64 } 74 } 65 theG4tgrIsotopes.clear(); 75 theG4tgrIsotopes.clear(); 66 76 67 for(auto elemcite = theG4tgrElements.cbegin( << 77 G4mstgrelem::iterator elemcite; 68 elemcite != theG4tgrElements.cend() << 78 for( elemcite = theG4tgrElements.begin(); >> 79 elemcite != theG4tgrElements.end(); elemcite++) 69 { 80 { 70 delete(*elemcite).second; << 81 delete (*elemcite).second; 71 } 82 } 72 theG4tgrElements.clear(); 83 theG4tgrElements.clear(); 73 84 74 for(auto matcite = theG4tgrMaterials.cbegin( << 85 G4mstgrmate::iterator matcite; 75 matcite != theG4tgrMaterials.cend() << 86 for( matcite = theG4tgrMaterials.begin(); >> 87 matcite != theG4tgrMaterials.end(); matcite++) 76 { 88 { 77 delete(*matcite).second; << 89 delete (*matcite).second; 78 } 90 } 79 theG4tgrMaterials.clear(); 91 theG4tgrMaterials.clear(); 80 delete theInstance; 92 delete theInstance; 81 } 93 } 82 94 83 // ------------------------------------------- << 95 84 G4tgrIsotope* G4tgrMaterialFactory::AddIsotope << 96 //------------------------------------------------------------- >> 97 G4tgrIsotope* >> 98 G4tgrMaterialFactory::AddIsotope( const std::vector<G4String>& wl ) 85 { 99 { 86 //---------- Look if isotope exists 100 //---------- Look if isotope exists 87 if(FindIsotope(G4tgrUtils::GetString(wl[1])) << 101 if( FindIsotope( G4tgrUtils::GetString(wl[1]) ) != 0 ) 88 { 102 { 89 ErrorAlreadyExists("isotope", wl); << 103 ErrorAlreadyExists("isotope", wl ); 90 } 104 } 91 << 105 92 G4tgrIsotope* isot = new G4tgrIsotope(wl); << 106 G4tgrIsotope* isot = new G4tgrIsotope( wl ); 93 theG4tgrIsotopes[isot->GetName()] = isot; 107 theG4tgrIsotopes[isot->GetName()] = isot; 94 108 95 return isot; 109 return isot; 96 } 110 } 97 111 98 // ------------------------------------------- << 112 //------------------------------------------------------------- 99 G4tgrElementSimple* 113 G4tgrElementSimple* 100 G4tgrMaterialFactory::AddElementSimple(const s << 114 G4tgrMaterialFactory::AddElementSimple( const std::vector<G4String>& wl ) 101 { 115 { 102 //---------- Look if element exists 116 //---------- Look if element exists 103 if(FindElement(G4tgrUtils::GetString(wl[1])) << 117 if( FindElement( G4tgrUtils::GetString(wl[1]) ) != 0 ) 104 { 118 { 105 ErrorAlreadyExists("element", wl); << 119 ErrorAlreadyExists("element", wl ); 106 } 120 } 107 << 121 108 G4tgrElementSimple* elem = new G4tgrElementS << 122 G4tgrElementSimple* elem = new G4tgrElementSimple( wl ); 109 theG4tgrElements[elem->GetName()] = elem; 123 theG4tgrElements[elem->GetName()] = elem; 110 124 111 return elem; 125 return elem; 112 } 126 } 113 127 114 // ------------------------------------------- << 128 >> 129 //------------------------------------------------------------- 115 G4tgrElementFromIsotopes* 130 G4tgrElementFromIsotopes* 116 G4tgrMaterialFactory::AddElementFromIsotopes(c << 131 G4tgrMaterialFactory::AddElementFromIsotopes( const std::vector<G4String>& wl ) 117 { 132 { 118 //---------- Look if element exists 133 //---------- Look if element exists 119 if(FindElement(G4tgrUtils::GetString(wl[1])) << 134 if( FindElement( G4tgrUtils::GetString(wl[1]) ) != 0 ) 120 { 135 { 121 ErrorAlreadyExists("element", wl); << 136 ErrorAlreadyExists("element", wl ); 122 } 137 } 123 << 138 124 G4tgrElementFromIsotopes* elem = new G4tgrEl << 139 G4tgrElementFromIsotopes* elem = new G4tgrElementFromIsotopes( wl ); 125 theG4tgrElements[elem->GetName()] = elem; 140 theG4tgrElements[elem->GetName()] = elem; 126 141 127 return elem; 142 return elem; 128 } 143 } 129 144 130 // ------------------------------------------- << 145 >> 146 //------------------------------------------------------------- 131 G4tgrMaterialSimple* 147 G4tgrMaterialSimple* 132 G4tgrMaterialFactory::AddMaterialSimple(const << 148 G4tgrMaterialFactory::AddMaterialSimple( const std::vector<G4String>& wl ) 133 { 149 { 134 #ifdef G4VERBOSE 150 #ifdef G4VERBOSE 135 if(G4tgrMessenger::GetVerboseLevel() >= 2) << 151 if( G4tgrMessenger::GetVerboseLevel() >= 2 ) 136 { 152 { 137 G4cout << " G4tgrMaterialFactory::AddMater 153 G4cout << " G4tgrMaterialFactory::AddMaterialSimple" << wl[1] << G4endl; 138 } 154 } 139 #endif 155 #endif 140 156 141 //---------- Look if material exists 157 //---------- Look if material exists 142 if(FindMaterial(G4tgrUtils::GetString(wl[1]) << 158 if( FindMaterial( G4tgrUtils::GetString(wl[1]) ) != 0 ) 143 { 159 { 144 ErrorAlreadyExists("material simple", wl); << 160 ErrorAlreadyExists("material simple", wl ); 145 } 161 } 146 162 147 G4tgrMaterialSimple* mate = new G4tgrMateria << 163 G4tgrMaterialSimple* mate = new G4tgrMaterialSimple("MaterialSimple", wl ); 148 164 149 //---------- register this material 165 //---------- register this material 150 theG4tgrMaterials[mate->GetName()] = mate; << 166 theG4tgrMaterials[ mate->GetName() ] = mate; 151 << 167 152 return mate; 168 return mate; 153 } 169 } 154 170 155 // ------------------------------------------- << 171 >> 172 //------------------------------------------------------------- 156 G4tgrMaterialMixture* 173 G4tgrMaterialMixture* 157 G4tgrMaterialFactory::AddMaterialMixture(const << 174 G4tgrMaterialFactory::AddMaterialMixture( const std::vector<G4String>& wl, 158 const << 175 const G4String& mixtType ) 159 { 176 { 160 #ifdef G4VERBOSE 177 #ifdef G4VERBOSE 161 if(G4tgrMessenger::GetVerboseLevel() >= 2) << 178 if( G4tgrMessenger::GetVerboseLevel() >= 2 ) 162 { 179 { 163 G4cout << " G4tgrMaterialFactory::AddMater 180 G4cout << " G4tgrMaterialFactory::AddMaterialMixture " << wl[1] << G4endl; 164 } 181 } 165 #endif 182 #endif 166 183 167 //---------- Look if material already exists 184 //---------- Look if material already exists 168 if(FindMaterial(G4tgrUtils::GetString(wl[1]) << 185 if( FindMaterial( G4tgrUtils::GetString(wl[1]) ) != 0 ) 169 { 186 { 170 ErrorAlreadyExists("material mixture", wl) << 187 ErrorAlreadyExists("material mixture", wl ); 171 } 188 } 172 189 173 G4tgrMaterialMixture* mate; << 190 G4tgrMaterialMixture* mate; 174 mate = new G4tgrMaterialMixture(mixtType, wl << 191 mate = new G4tgrMaterialMixture( mixtType, wl ); 175 << 192 176 //---------- register this material 193 //---------- register this material 177 theG4tgrMaterials[mate->GetName()] = mate; << 194 theG4tgrMaterials[ mate->GetName() ] = mate; 178 << 195 179 return mate; 196 return mate; 180 } 197 } 181 198 182 // ------------------------------------------- << 199 183 G4tgrIsotope* G4tgrMaterialFactory::FindIsotop << 200 //------------------------------------------------------------- >> 201 G4tgrIsotope* G4tgrMaterialFactory::FindIsotope(const G4String & name) const 184 { 202 { 185 #ifdef G4VERBOSE 203 #ifdef G4VERBOSE 186 if(G4tgrMessenger::GetVerboseLevel() >= 3) << 204 if( G4tgrMessenger::GetVerboseLevel() >= 3 ) 187 { 205 { 188 G4cout << " G4tgrMaterialFactory::FindIsot << 206 G4cout << " G4tgrMaterialFactory::FindIsotope() - " << name << G4endl; 189 } 207 } 190 #endif 208 #endif 191 209 192 G4mstgrisot::const_iterator cite; 210 G4mstgrisot::const_iterator cite; 193 cite = theG4tgrIsotopes.find(name); << 211 cite = theG4tgrIsotopes.find( name ); 194 if(cite == theG4tgrIsotopes.cend()) << 212 if( cite == theG4tgrIsotopes.end() ) 195 { 213 { 196 return nullptr; << 214 return 0; 197 } 215 } 198 else 216 else 199 { 217 { 200 #ifdef G4VERBOSE 218 #ifdef G4VERBOSE 201 if(G4tgrMessenger::GetVerboseLevel() >= 3) << 219 if( G4tgrMessenger::GetVerboseLevel() >= 3 ) 202 { 220 { 203 G4cout << " G4tgrIsotope found: " << ((* << 221 G4cout << " G4tgrIsotope found: " 204 << G4endl; << 222 << ( (*cite).second )->GetName() << G4endl; 205 } 223 } 206 #endif 224 #endif 207 return (*cite).second; 225 return (*cite).second; 208 } 226 } 209 } 227 } 210 228 211 // ------------------------------------------- << 229 212 G4tgrElement* G4tgrMaterialFactory::FindElemen << 230 //------------------------------------------------------------- >> 231 G4tgrElement* G4tgrMaterialFactory::FindElement(const G4String & name) const 213 { 232 { 214 #ifdef G4VERBOSE 233 #ifdef G4VERBOSE 215 if(G4tgrMessenger::GetVerboseLevel() >= 3) << 234 if( G4tgrMessenger::GetVerboseLevel() >= 3 ) 216 { 235 { 217 G4cout << " G4tgrMaterialFactory::FindElem 236 G4cout << " G4tgrMaterialFactory::FindElement() - " << name << G4endl; 218 } 237 } 219 #endif 238 #endif 220 G4mstgrelem::const_iterator cite; 239 G4mstgrelem::const_iterator cite; 221 cite = theG4tgrElements.find(name); << 240 cite = theG4tgrElements.find( name ); 222 if(cite == theG4tgrElements.cend()) << 241 if( cite == theG4tgrElements.end() ) 223 { 242 { 224 return nullptr; << 243 return 0; 225 } 244 } 226 else 245 else 227 { 246 { 228 #ifdef G4VERBOSE 247 #ifdef G4VERBOSE 229 if(G4tgrMessenger::GetVerboseLevel() >= 3) << 248 if( G4tgrMessenger::GetVerboseLevel() >= 3 ) 230 { 249 { 231 DumpElementList(); 250 DumpElementList(); 232 G4cout << " G4tgrElement found: " << ((* << 251 G4cout << " G4tgrElement found: " 233 << G4endl; << 252 << ( (*cite).second )->GetName() << G4endl; 234 } 253 } 235 #endif 254 #endif 236 return (*cite).second; 255 return (*cite).second; 237 } 256 } 238 } 257 } 239 258 240 // ------------------------------------------- << 259 241 G4tgrMaterial* G4tgrMaterialFactory::FindMater << 260 //------------------------------------------------------------- >> 261 G4tgrMaterial* G4tgrMaterialFactory::FindMaterial(const G4String & name) const 242 { 262 { 243 #ifdef G4VERBOSE 263 #ifdef G4VERBOSE 244 if(G4tgrMessenger::GetVerboseLevel() >= 3) << 264 if( G4tgrMessenger::GetVerboseLevel() >= 3 ) 245 { 265 { 246 G4cout << " G4tgrMaterialFactory::FindMate 266 G4cout << " G4tgrMaterialFactory::FindMaterial() - " << name << G4endl; 247 } 267 } 248 #endif 268 #endif 249 G4mstgrmate::const_iterator cite; 269 G4mstgrmate::const_iterator cite; 250 cite = theG4tgrMaterials.find(name); << 270 cite = theG4tgrMaterials.find( name ); 251 if(cite == theG4tgrMaterials.cend()) << 271 if( cite == theG4tgrMaterials.end() ) 252 { 272 { 253 return nullptr; << 273 return 0; 254 } 274 } 255 else 275 else 256 { 276 { 257 return (*cite).second; 277 return (*cite).second; 258 } 278 } 259 } 279 } 260 280 261 // ------------------------------------------- << 281 >> 282 //------------------------------------------------------------- 262 void G4tgrMaterialFactory::DumpIsotopeList() c 283 void G4tgrMaterialFactory::DumpIsotopeList() const 263 { 284 { 264 G4cout << " @@@@@@@@@@@@@@@@ DUMPING G4tgrIs 285 G4cout << " @@@@@@@@@@@@@@@@ DUMPING G4tgrIsotope's List " << G4endl; 265 for(auto cite = theG4tgrIsotopes.cbegin(); << 286 G4mstgrisot::const_iterator cite; 266 cite != theG4tgrIsotopes.cend(); ++ << 287 for(cite = theG4tgrIsotopes.begin(); cite != theG4tgrIsotopes.end(); cite++) 267 { 288 { 268 G4cout << " ISOT: " << (*cite).second->Get 289 G4cout << " ISOT: " << (*cite).second->GetName() << G4endl; 269 } 290 } 270 } 291 } 271 292 272 // ------------------------------------------- << 293 273 void G4tgrMaterialFactory::DumpElementList() c << 294 //------------------------------------------------------------- >> 295 void G4tgrMaterialFactory::DumpElementList() const 274 { 296 { 275 G4cout << " @@@@@@@@@@@@@@@@ DUMPING G4tgrEl 297 G4cout << " @@@@@@@@@@@@@@@@ DUMPING G4tgrElement's List " << G4endl; 276 for(auto cite = theG4tgrElements.cbegin(); << 298 G4mstgrelem::const_iterator cite; 277 cite != theG4tgrElements.cend(); ++ << 299 for(cite = theG4tgrElements.begin(); cite != theG4tgrElements.end(); cite++) 278 { 300 { 279 G4cout << " ELEM: " << (*cite).second->Get 301 G4cout << " ELEM: " << (*cite).second->GetName() << G4endl; 280 } 302 } 281 } 303 } 282 304 283 // ------------------------------------------- << 305 >> 306 //------------------------------------------------------------- 284 void G4tgrMaterialFactory::DumpMaterialList() 307 void G4tgrMaterialFactory::DumpMaterialList() const 285 { 308 { 286 G4cout << " @@@@@@@@@@@@@@@@ DUMPING G4tgrMa 309 G4cout << " @@@@@@@@@@@@@@@@ DUMPING G4tgrMaterial's List " << G4endl; 287 for(auto cite = theG4tgrMaterials.cbegin(); << 310 G4mstgrmate::const_iterator cite; 288 cite != theG4tgrMaterials.cend(); + << 311 for(cite = theG4tgrMaterials.begin(); cite != theG4tgrMaterials.end(); cite++) 289 { 312 { 290 G4tgrMaterial* mate = (*cite).second; 313 G4tgrMaterial* mate = (*cite).second; 291 G4cout << " MATE: " << mate->GetName() << << 314 G4cout << " MATE: " << mate->GetName() << " Type: " << mate->GetType() 292 << " NoComponents= " << mate->GetNu 315 << " NoComponents= " << mate->GetNumberOfComponents() << G4endl; 293 } 316 } 294 } 317 } >> 318 295 319 296 // ------------------------------------------- << 320 //------------------------------------------------------------- 297 void G4tgrMaterialFactory::ErrorAlreadyExists( << 321 void G4tgrMaterialFactory:: 298 << 322 ErrorAlreadyExists(const G4String& object, 299 << 323 const std::vector<G4String>& wl, const G4bool bNoRepeating ) 300 { 324 { 301 G4String msg = object + G4String(" repeated" 325 G4String msg = object + G4String(" repeated"); 302 if(bNoRepeating) << 326 if( bNoRepeating ) 303 { 327 { 304 G4tgrUtils::DumpVS(wl, (G4String("!!!! EXI << 328 G4tgrUtils::DumpVS( wl, (G4String("!!!! EXITING: ") + msg).c_str() ); 305 G4Exception("G4tgrMaterialFactory", "Fatal << 329 G4Exception("G4tgrMaterialFactory", "FatalError", 306 "Aborting..."); << 330 FatalException, "Aborting..."); 307 } 331 } 308 else 332 else 309 { 333 { 310 #ifdef G4VERBOSE 334 #ifdef G4VERBOSE 311 if(G4tgrMessenger::GetVerboseLevel() >= 1) << 335 if( G4tgrMessenger::GetVerboseLevel() >= 1 ) 312 { 336 { 313 G4tgrUtils::DumpVS(wl, (G4String("!! WAR << 337 G4tgrUtils::DumpVS( wl, (G4String("!! WARNING: ") + msg).c_str() ); 314 } 338 } 315 #endif 339 #endif 316 } 340 } 317 } 341 } 318 342