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