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 // G4GDMLReadMaterials implementation << 27 // 26 // 28 // Author: Zoltan Torzsok, November 2007 << 27 // $Id: G4GDMLReadMaterials.cc,v 1.21 2010-10-14 16:19:40 gcosmo Exp $ >> 28 // GEANT4 tag $ Name:$ >> 29 // >> 30 // class G4GDMLReadMaterials Implementation >> 31 // >> 32 // Original author: Zoltan Torzsok, November 2007 >> 33 // 29 // ------------------------------------------- 34 // -------------------------------------------------------------------- 30 35 31 #include "G4GDMLReadMaterials.hh" 36 #include "G4GDMLReadMaterials.hh" 32 37 33 #include "G4PhysicalConstants.hh" << 34 #include "G4SystemOfUnits.hh" << 35 #include "G4UnitsTable.hh" << 36 #include "G4Element.hh" 38 #include "G4Element.hh" 37 #include "G4Isotope.hh" 39 #include "G4Isotope.hh" 38 #include "G4Material.hh" 40 #include "G4Material.hh" 39 #include "G4NistManager.hh" 41 #include "G4NistManager.hh" 40 42 41 // ------------------------------------------- << 43 G4GDMLReadMaterials::G4GDMLReadMaterials() : G4GDMLReadDefine() 42 G4GDMLReadMaterials::G4GDMLReadMaterials() << 43 : G4GDMLReadDefine() << 44 { 44 { 45 } 45 } 46 46 47 // ------------------------------------------- << 48 G4GDMLReadMaterials::~G4GDMLReadMaterials() 47 G4GDMLReadMaterials::~G4GDMLReadMaterials() 49 { 48 { 50 } 49 } 51 50 52 // ------------------------------------------- << 51 G4double 53 G4double G4GDMLReadMaterials::AtomRead( << 52 G4GDMLReadMaterials::AtomRead(const xercesc::DOMElement* const atomElement) 54 const xercesc::DOMElement* const atomElement << 55 { 53 { 56 G4double value = 0.0; << 54 G4double value = 0.0; 57 G4double unit = g / mole; << 55 G4double unit = g/mole; 58 56 59 const xercesc::DOMNamedNodeMap* const attrib << 57 const xercesc::DOMNamedNodeMap* const attributes 60 atomElement->getAttributes(); << 58 = atomElement->getAttributes(); 61 XMLSize_t attributeCount = attributes->getLe << 59 XMLSize_t attributeCount = attributes->getLength(); 62 << 60 63 for(XMLSize_t attribute_index = 0; attribute << 61 for (XMLSize_t attribute_index=0; 64 ++attribute_index) << 62 attribute_index<attributeCount; attribute_index++) 65 { << 63 { 66 xercesc::DOMNode* attribute_node = attribu << 64 xercesc::DOMNode* attribute_node = attributes->item(attribute_index); 67 << 65 68 if(attribute_node->getNodeType() != xerces << 66 if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE) 69 { << 67 { continue; } 70 continue; << 68 71 } << 69 const xercesc::DOMAttr* const attribute 72 << 70 = dynamic_cast<xercesc::DOMAttr*>(attribute_node); 73 const xercesc::DOMAttr* const attribute = << 71 if (!attribute) 74 dynamic_cast<xercesc::DOMAttr*>(attribut << 75 if(attribute == nullptr) << 76 { << 77 G4Exception("G4GDMLReadMaterials::AtomRe << 78 FatalException, "No attribut << 79 return value; << 80 } << 81 const G4String attName = Transcode(attrib << 82 const G4String attValue = Transcode(attrib << 83 << 84 if(attName == "value") << 85 { << 86 value = eval.Evaluate(attValue); << 87 } << 88 else if(attName == "unit") << 89 { << 90 unit = G4UnitDefinition::GetValueOf(attV << 91 if(G4UnitDefinition::GetCategory(attValu << 92 { 72 { 93 G4Exception("G4GDMLReadMaterials::Atom 73 G4Exception("G4GDMLReadMaterials::AtomRead()", "InvalidRead", 94 FatalException, "Invalid u << 74 FatalException, "No attribute found!"); >> 75 return value; 95 } 76 } 96 } << 77 const G4String attName = Transcode(attribute->getName()); 97 } << 78 const G4String attValue = Transcode(attribute->getValue()); 98 79 99 return value * unit; << 80 if (attName=="value") { value = eval.Evaluate(attValue); } else >> 81 if (attName=="unit") { unit = eval.Evaluate(attValue); } >> 82 } >> 83 >> 84 return value*unit; 100 } 85 } 101 86 102 // ------------------------------------------- << 87 G4int G4GDMLReadMaterials:: 103 G4int G4GDMLReadMaterials::CompositeRead( << 88 CompositeRead(const xercesc::DOMElement* const compositeElement,G4String& ref) 104 const xercesc::DOMElement* const compositeEl << 105 { 89 { 106 G4int n = 0; << 90 G4int n = 0; 107 91 108 const xercesc::DOMNamedNodeMap* const attrib << 92 const xercesc::DOMNamedNodeMap* const attributes 109 compositeElement->getAttributes(); << 93 = compositeElement->getAttributes(); 110 XMLSize_t attributeCount = attributes->getLe << 94 XMLSize_t attributeCount = attributes->getLength(); 111 << 112 for(XMLSize_t attribute_index = 0; attribute << 113 ++attribute_index) << 114 { << 115 xercesc::DOMNode* attribute_node = attribu << 116 << 117 if(attribute_node->getNodeType() != xerces << 118 { << 119 continue; << 120 } << 121 << 122 const xercesc::DOMAttr* const attribute = << 123 dynamic_cast<xercesc::DOMAttr*>(attribut << 124 if(attribute == nullptr) << 125 { << 126 G4Exception("G4GDMLReadMaterials::Compos << 127 FatalException, "No attribut << 128 return n; << 129 } << 130 const G4String attName = Transcode(attrib << 131 const G4String attValue = Transcode(attrib << 132 << 133 if(attName == "n") << 134 { << 135 n = eval.EvaluateInteger(attValue); << 136 } << 137 else if(attName == "ref") << 138 { << 139 ref = attValue; << 140 } << 141 } << 142 95 143 return n; << 96 for (XMLSize_t attribute_index=0; >> 97 attribute_index<attributeCount; attribute_index++) >> 98 { >> 99 xercesc::DOMNode* attribute_node = attributes->item(attribute_index); >> 100 >> 101 if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE) >> 102 { continue; } >> 103 >> 104 const xercesc::DOMAttr* const attribute >> 105 = dynamic_cast<xercesc::DOMAttr*>(attribute_node); >> 106 if (!attribute) >> 107 { >> 108 G4Exception("G4GDMLReadMaterials::CompositeRead()", "InvalidRead", >> 109 FatalException, "No attribute found!"); >> 110 return n; >> 111 } >> 112 const G4String attName = Transcode(attribute->getName()); >> 113 const G4String attValue = Transcode(attribute->getValue()); >> 114 >> 115 if (attName=="n") { n = eval.EvaluateInteger(attValue); } else >> 116 if (attName=="ref") { ref = attValue; } >> 117 } >> 118 >> 119 return n; 144 } 120 } 145 121 146 // ------------------------------------------- << 147 G4double G4GDMLReadMaterials::DRead(const xerc 122 G4double G4GDMLReadMaterials::DRead(const xercesc::DOMElement* const DElement) 148 { 123 { 149 G4double value = 0.0; << 124 G4double value = 0.0; 150 G4double unit = g / cm3; << 125 G4double unit = g/cm3; 151 126 152 const xercesc::DOMNamedNodeMap* const attrib << 127 const xercesc::DOMNamedNodeMap* const attributes 153 XMLSize_t attributeCount << 128 = DElement->getAttributes(); 154 << 129 XMLSize_t attributeCount = attributes->getLength(); 155 for(XMLSize_t attribute_index = 0; attribute << 130 156 ++attribute_index) << 131 for (XMLSize_t attribute_index=0; 157 { << 132 attribute_index<attributeCount; attribute_index++) 158 xercesc::DOMNode* attribute_node = attribu << 133 { 159 << 134 xercesc::DOMNode* attribute_node = attributes->item(attribute_index); 160 if(attribute_node->getNodeType() != xerces << 135 161 { << 136 if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE) 162 continue; << 137 { continue; } 163 } << 138 164 << 139 const xercesc::DOMAttr* const attribute 165 const xercesc::DOMAttr* const attribute = << 140 = dynamic_cast<xercesc::DOMAttr*>(attribute_node); 166 dynamic_cast<xercesc::DOMAttr*>(attribut << 141 if (!attribute) 167 if(attribute == nullptr) << 168 { << 169 G4Exception("G4GDMLReadMaterials::DRead( << 170 "No attribute found!"); << 171 return value; << 172 } << 173 const G4String attName = Transcode(attrib << 174 const G4String attValue = Transcode(attrib << 175 << 176 if(attName == "value") << 177 { << 178 value = eval.Evaluate(attValue); << 179 } << 180 else if(attName == "unit") << 181 { << 182 unit = G4UnitDefinition::GetValueOf(attV << 183 if(G4UnitDefinition::GetCategory(attValu << 184 { 142 { 185 G4Exception("G4GDMLReadMaterials::DRea 143 G4Exception("G4GDMLReadMaterials::DRead()", "InvalidRead", 186 FatalException, "Invalid u << 144 FatalException, "No attribute found!"); >> 145 return value; 187 } 146 } 188 } << 147 const G4String attName = Transcode(attribute->getName()); 189 } << 148 const G4String attValue = Transcode(attribute->getValue()); >> 149 >> 150 if (attName=="value") { value = eval.Evaluate(attValue); } else >> 151 if (attName=="unit") { unit = eval.Evaluate(attValue); } >> 152 } 190 153 191 return value * unit; << 154 return value*unit; 192 } 155 } 193 156 194 // ------------------------------------------- << 195 G4double G4GDMLReadMaterials::PRead(const xerc 157 G4double G4GDMLReadMaterials::PRead(const xercesc::DOMElement* const PElement) 196 { 158 { 197 G4double value = STP_Pressure; << 159 G4double value = STP_Pressure; 198 G4double unit = hep_pascal; << 160 G4double unit = pascal; 199 161 200 const xercesc::DOMNamedNodeMap* const attrib << 162 const xercesc::DOMNamedNodeMap* const attributes = PElement->getAttributes(); 201 XMLSize_t attributeCount << 163 XMLSize_t attributeCount = attributes->getLength(); 202 164 203 for(XMLSize_t attribute_index = 0; attribute << 165 for (XMLSize_t attribute_index=0; 204 ++attribute_index) << 166 attribute_index<attributeCount; attribute_index++) 205 { << 167 { 206 xercesc::DOMNode* attribute_node = attribu << 168 xercesc::DOMNode* attribute_node = attributes->item(attribute_index); 207 << 169 208 if(attribute_node->getNodeType() != xerces << 170 if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE) 209 { << 171 { continue; } 210 continue; << 172 211 } << 173 const xercesc::DOMAttr* const attribute 212 << 174 = dynamic_cast<xercesc::DOMAttr*>(attribute_node); 213 const xercesc::DOMAttr* const attribute = << 175 if (!attribute) 214 dynamic_cast<xercesc::DOMAttr*>(attribut << 215 if(attribute == nullptr) << 216 { << 217 G4Exception("G4GDMLReadMaterials::PRead( << 218 "No attribute found!"); << 219 return value; << 220 } << 221 const G4String attName = Transcode(attrib << 222 const G4String attValue = Transcode(attrib << 223 << 224 if(attName == "value") << 225 { << 226 value = eval.Evaluate(attValue); << 227 } << 228 else if(attName == "unit") << 229 { << 230 unit = G4UnitDefinition::GetValueOf(attV << 231 if(G4UnitDefinition::GetCategory(attValu << 232 { 176 { 233 G4Exception("G4GDMLReadMaterials::PRea 177 G4Exception("G4GDMLReadMaterials::PRead()", "InvalidRead", 234 FatalException, "Invalid u << 178 FatalException, "No attribute found!"); >> 179 return value; 235 } 180 } 236 } << 181 const G4String attName = Transcode(attribute->getName()); 237 } << 182 const G4String attValue = Transcode(attribute->getValue()); >> 183 >> 184 if (attName=="value") { value = eval.Evaluate(attValue); } else >> 185 if (attName=="unit") { unit = eval.Evaluate(attValue); } >> 186 } 238 187 239 return value * unit; << 188 return value*unit; 240 } 189 } 241 190 242 // ------------------------------------------- << 243 G4double G4GDMLReadMaterials::TRead(const xerc 191 G4double G4GDMLReadMaterials::TRead(const xercesc::DOMElement* const TElement) 244 { 192 { 245 G4double value = NTP_Temperature; << 193 G4double value = STP_Temperature; 246 G4double unit = kelvin; << 194 G4double unit = kelvin; 247 195 248 const xercesc::DOMNamedNodeMap* const attrib << 196 const xercesc::DOMNamedNodeMap* const attributes = TElement->getAttributes(); 249 XMLSize_t attributeCount << 197 XMLSize_t attributeCount = attributes->getLength(); 250 198 251 for(XMLSize_t attribute_index = 0; attribute << 199 for (XMLSize_t attribute_index=0; 252 ++attribute_index) << 200 attribute_index<attributeCount; attribute_index++) 253 { << 201 { 254 xercesc::DOMNode* attribute_node = attribu << 202 xercesc::DOMNode* attribute_node = attributes->item(attribute_index); 255 << 203 256 if(attribute_node->getNodeType() != xerces << 204 if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE) 257 { << 205 { continue; } 258 continue; << 206 259 } << 207 const xercesc::DOMAttr* const attribute 260 << 208 = dynamic_cast<xercesc::DOMAttr*>(attribute_node); 261 const xercesc::DOMAttr* const attribute = << 209 if (!attribute) 262 dynamic_cast<xercesc::DOMAttr*>(attribut << 263 if(attribute == nullptr) << 264 { << 265 G4Exception("G4GDMLReadMaterials::TRead( << 266 "No attribute found!"); << 267 return value; << 268 } << 269 const G4String attName = Transcode(attrib << 270 const G4String attValue = Transcode(attrib << 271 << 272 if(attName == "value") << 273 { << 274 value = eval.Evaluate(attValue); << 275 } << 276 else if(attName == "unit") << 277 { << 278 unit = G4UnitDefinition::GetValueOf(attV << 279 if(G4UnitDefinition::GetCategory(attValu << 280 { 210 { 281 G4Exception("G4GDMLReadMaterials::TRea 211 G4Exception("G4GDMLReadMaterials::TRead()", "InvalidRead", 282 FatalException, "Invalid u << 212 FatalException, "No attribute found!"); >> 213 return value; 283 } 214 } 284 } << 215 const G4String attName = Transcode(attribute->getName()); 285 } << 216 const G4String attValue = Transcode(attribute->getValue()); >> 217 >> 218 if (attName=="value") { value = eval.Evaluate(attValue); } else >> 219 if (attName=="unit") { unit = eval.Evaluate(attValue); } >> 220 } 286 221 287 return value * unit; << 222 return value*unit; 288 } 223 } 289 224 290 // ------------------------------------------- << 225 void G4GDMLReadMaterials:: 291 G4double G4GDMLReadMaterials::MEERead(const xe << 226 ElementRead(const xercesc::DOMElement* const elementElement) 292 { 227 { 293 G4double value = -1; << 228 G4String name; 294 G4double unit = eV; << 229 G4String formula; >> 230 G4double a = 0.0; >> 231 G4double Z = 0.0; 295 232 296 const xercesc::DOMNamedNodeMap* const attrib << 233 const xercesc::DOMNamedNodeMap* const attributes 297 XMLSize_t attributeCount << 234 = elementElement->getAttributes(); >> 235 XMLSize_t attributeCount = attributes->getLength(); 298 236 299 for(XMLSize_t attribute_index = 0; attribute << 237 for (XMLSize_t attribute_index=0; 300 ++attribute_index) << 238 attribute_index<attributeCount; attribute_index++) 301 { << 239 { 302 xercesc::DOMNode* attribute_node = attribu << 240 xercesc::DOMNode* attribute_node = attributes->item(attribute_index); 303 << 241 304 if(attribute_node->getNodeType() != xerces << 242 if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE) 305 { << 243 { continue; } 306 continue; << 244 307 } << 245 const xercesc::DOMAttr* const attribute 308 << 246 = dynamic_cast<xercesc::DOMAttr*>(attribute_node); 309 const xercesc::DOMAttr* const attribute = << 247 if (!attribute) 310 dynamic_cast<xercesc::DOMAttr*>(attribut << 311 if(attribute == nullptr) << 312 { << 313 G4Exception("G4GDMLReadMaterials::MEERea << 314 FatalException, "No attribut << 315 return value; << 316 } << 317 const G4String attName = Transcode(attrib << 318 const G4String attValue = Transcode(attrib << 319 << 320 if(attName == "value") << 321 { << 322 value = eval.Evaluate(attValue); << 323 } << 324 else if(attName == "unit") << 325 { << 326 unit = G4UnitDefinition::GetValueOf(attV << 327 if(G4UnitDefinition::GetCategory(attValu << 328 { 248 { 329 G4Exception("G4GDMLReadMaterials::MEER << 249 G4Exception("G4GDMLReadMaterials::ElementRead()", "InvalidRead", 330 FatalException, "Invalid u << 250 FatalException, "No attribute found!"); >> 251 return; 331 } 252 } 332 } << 253 const G4String attName = Transcode(attribute->getName()); 333 } << 254 const G4String attValue = Transcode(attribute->getValue()); 334 255 335 return value * unit; << 256 if (attName=="name") { name = GenerateName(attValue); } else 336 } << 257 if (attName=="formula") { formula = attValue; } else >> 258 if (attName=="Z") { Z = eval.Evaluate(attValue); } >> 259 } 337 260 338 // ------------------------------------------- << 261 G4int nComponents = 0; 339 void G4GDMLReadMaterials::ElementRead( << 340 const xercesc::DOMElement* const elementElem << 341 { << 342 G4String name; << 343 G4String formula; << 344 G4double a = 0.0; << 345 G4double Z = 0.0; << 346 << 347 const xercesc::DOMNamedNodeMap* const attrib << 348 elementElement->getAttributes(); << 349 XMLSize_t attributeCount = attributes->getLe << 350 << 351 for(XMLSize_t attribute_index = 0; attribute << 352 ++attribute_index) << 353 { << 354 xercesc::DOMNode* attribute_node = attribu << 355 << 356 if(attribute_node->getNodeType() != xerces << 357 { << 358 continue; << 359 } << 360 << 361 const xercesc::DOMAttr* const attribute = << 362 dynamic_cast<xercesc::DOMAttr*>(attribut << 363 if(attribute == nullptr) << 364 { << 365 G4Exception("G4GDMLReadMaterials::Elemen << 366 FatalException, "No attribut << 367 return; << 368 } << 369 const G4String attName = Transcode(attrib << 370 const G4String attValue = Transcode(attrib << 371 << 372 if(attName == "name") << 373 { << 374 name = GenerateName(attValue); << 375 } << 376 else if(attName == "formula") << 377 { << 378 formula = attValue; << 379 } << 380 else if(attName == "Z") << 381 { << 382 Z = eval.Evaluate(attValue); << 383 } << 384 } << 385 << 386 G4int nComponents = 0; << 387 << 388 for(xercesc::DOMNode* iter = elementElement- << 389 iter = iter->getNextSi << 390 { << 391 if(iter->getNodeType() != xercesc::DOMNode << 392 { << 393 continue; << 394 } << 395 << 396 const xercesc::DOMElement* const child = << 397 dynamic_cast<xercesc::DOMElement*>(iter) << 398 if(child == nullptr) << 399 { << 400 G4Exception("G4GDMLReadMaterials::Elemen << 401 FatalException, "No child fo << 402 return; << 403 } << 404 const G4String tag = Transcode(child->getT << 405 << 406 if(tag == "atom") << 407 { << 408 a = AtomRead(child); << 409 } << 410 else if(tag == "fraction") << 411 { << 412 nComponents++; << 413 } << 414 } << 415 << 416 if(nComponents > 0) << 417 { << 418 MixtureRead(elementElement, << 419 new G4Element(Strip(name), for << 420 } << 421 else << 422 { << 423 new G4Element(Strip(name), formula, Z, a); << 424 } << 425 } << 426 262 427 // ------------------------------------------- << 263 for (xercesc::DOMNode* iter = elementElement->getFirstChild(); 428 G4double G4GDMLReadMaterials::FractionRead( << 264 iter != 0; iter = iter->getNextSibling()) 429 const xercesc::DOMElement* const fractionEle << 265 { 430 { << 266 if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; } 431 G4double n = 0.0; << 267 >> 268 const xercesc::DOMElement* const child >> 269 = dynamic_cast<xercesc::DOMElement*>(iter); >> 270 if (!child) >> 271 { >> 272 G4Exception("G4GDMLReadMaterials::ElementRead()", "InvalidRead", >> 273 FatalException, "No child found!"); >> 274 return; >> 275 } >> 276 const G4String tag = Transcode(child->getTagName()); 432 277 433 const xercesc::DOMNamedNodeMap* const attrib << 278 if (tag=="atom") { a = AtomRead(child); } else 434 fractionElement->getAttributes(); << 279 if (tag=="fraction") { nComponents++; } 435 XMLSize_t attributeCount = attributes->getLe << 280 } 436 << 437 for(XMLSize_t attribute_index = 0; attribute << 438 ++attribute_index) << 439 { << 440 xercesc::DOMNode* attribute_node = attribu << 441 << 442 if(attribute_node->getNodeType() != xerces << 443 { << 444 continue; << 445 } << 446 << 447 const xercesc::DOMAttr* const attribute = << 448 dynamic_cast<xercesc::DOMAttr*>(attribut << 449 if(attribute == nullptr) << 450 { << 451 G4Exception("G4GDMLReadMaterials::Fracti << 452 FatalException, "No attribut << 453 return n; << 454 } << 455 const G4String attName = Transcode(attrib << 456 const G4String attValue = Transcode(attrib << 457 << 458 if(attName == "n") << 459 { << 460 n = eval.Evaluate(attValue); << 461 } << 462 else if(attName == "ref") << 463 { << 464 ref = attValue; << 465 } << 466 } << 467 281 468 return n; << 282 if (nComponents>0) >> 283 { >> 284 MixtureRead(elementElement, >> 285 new G4Element(Strip(name),formula,nComponents)); >> 286 } >> 287 else >> 288 { >> 289 new G4Element(Strip(name),formula,Z,a); >> 290 } 469 } 291 } 470 292 471 // ------------------------------------------- << 293 G4double G4GDMLReadMaterials:: 472 void G4GDMLReadMaterials::IsotopeRead( << 294 FractionRead(const xercesc::DOMElement* const fractionElement, G4String& ref) 473 const xercesc::DOMElement* const isotopeElem << 474 { 295 { 475 G4String name; << 296 G4double n = 0.0; 476 G4int Z = 0; << 297 477 G4int N = 0; << 298 const xercesc::DOMNamedNodeMap* const attributes 478 G4double a = 0.0; << 299 = fractionElement->getAttributes(); 479 << 300 XMLSize_t attributeCount = attributes->getLength(); 480 const xercesc::DOMNamedNodeMap* const attrib << 301 481 isotopeElement->getAttributes(); << 302 for (XMLSize_t attribute_index=0; 482 XMLSize_t attributeCount = attributes->getLe << 303 attribute_index<attributeCount; attribute_index++) 483 << 304 { 484 for(XMLSize_t attribute_index = 0; attribute << 305 xercesc::DOMNode* attribute_node = attributes->item(attribute_index); 485 ++attribute_index) << 486 { << 487 xercesc::DOMNode* attribute_node = attribu << 488 << 489 if(attribute_node->getNodeType() != xerces << 490 { << 491 continue; << 492 } << 493 << 494 const xercesc::DOMAttr* const attribute = << 495 dynamic_cast<xercesc::DOMAttr*>(attribut << 496 if(attribute == nullptr) << 497 { << 498 G4Exception("G4GDMLReadMaterials::Isotop << 499 FatalException, "No attribut << 500 return; << 501 } << 502 const G4String attName = Transcode(attrib << 503 const G4String attValue = Transcode(attrib << 504 << 505 if(attName == "name") << 506 { << 507 name = GenerateName(attValue); << 508 } << 509 else if(attName == "Z") << 510 { << 511 Z = eval.EvaluateInteger(attValue); << 512 } << 513 else if(attName == "N") << 514 { << 515 N = eval.EvaluateInteger(attValue); << 516 } << 517 } << 518 << 519 for(xercesc::DOMNode* iter = isotopeElement- << 520 iter = iter->getNextSi << 521 { << 522 if(iter->getNodeType() != xercesc::DOMNode << 523 { << 524 continue; << 525 } << 526 << 527 const xercesc::DOMElement* const child = << 528 dynamic_cast<xercesc::DOMElement*>(iter) << 529 if(child == nullptr) << 530 { << 531 G4Exception("G4GDMLReadMaterials::Isotop << 532 FatalException, "No child fo << 533 return; << 534 } << 535 const G4String tag = Transcode(child->getT << 536 << 537 if(tag == "atom") << 538 { << 539 a = AtomRead(child); << 540 } << 541 } << 542 306 543 new G4Isotope(Strip(name), Z, N, a); << 307 if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE) >> 308 { continue; } >> 309 >> 310 const xercesc::DOMAttr* const attribute >> 311 = dynamic_cast<xercesc::DOMAttr*>(attribute_node); >> 312 if (!attribute) >> 313 { >> 314 G4Exception("G4GDMLReadMaterials::FractionRead()", "InvalidRead", >> 315 FatalException, "No attribute found!"); >> 316 return n; >> 317 } >> 318 const G4String attName = Transcode(attribute->getName()); >> 319 const G4String attValue = Transcode(attribute->getValue()); >> 320 >> 321 if (attName=="n") { n = eval.Evaluate(attValue); } else >> 322 if (attName=="ref") { ref = attValue; } >> 323 } >> 324 >> 325 return n; 544 } 326 } 545 327 546 // ------------------------------------------- << 328 void G4GDMLReadMaterials:: 547 void G4GDMLReadMaterials::MaterialRead( << 329 IsotopeRead(const xercesc::DOMElement* const isotopeElement) 548 const xercesc::DOMElement* const materialEle << 549 { 330 { 550 G4String name; << 331 G4String name; 551 G4double Z = 0.0; << 332 G4int Z = 0; 552 G4double a = 0.0; << 333 G4int N = 0; 553 G4double D = 0.0; << 334 G4double a = 0.0; 554 G4State state = kStateUndefined; << 335 555 G4double T = NTP_Temperature; << 336 const xercesc::DOMNamedNodeMap* const attributes 556 G4double P = STP_Pressure; << 337 = isotopeElement->getAttributes(); 557 G4double MEE = -1.0; << 338 XMLSize_t attributeCount = attributes->getLength(); 558 << 339 559 const xercesc::DOMNamedNodeMap* const attrib << 340 for (XMLSize_t attribute_index=0; 560 materialElement->getAttributes(); << 341 attribute_index<attributeCount;attribute_index++) 561 XMLSize_t attributeCount = attributes->getLe << 342 { 562 << 343 xercesc::DOMNode* attribute_node = attributes->item(attribute_index); 563 for(XMLSize_t attribute_index = 0; attribute << 344 564 ++attribute_index) << 345 if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE) 565 { << 346 { continue; } 566 xercesc::DOMNode* attribute_node = attribu << 347 567 << 348 const xercesc::DOMAttr* const attribute 568 if(attribute_node->getNodeType() != xerces << 349 = dynamic_cast<xercesc::DOMAttr*>(attribute_node); 569 { << 350 if (!attribute) 570 continue; << 351 { 571 } << 352 G4Exception("G4GDMLReadMaterials::IsotopeRead()", "InvalidRead", 572 << 353 FatalException, "No attribute found!"); 573 const xercesc::DOMAttr* const attribute = << 354 return; 574 dynamic_cast<xercesc::DOMAttr*>(attribut << 355 } 575 if(attribute == nullptr) << 356 const G4String attName = Transcode(attribute->getName()); 576 { << 357 const G4String attValue = Transcode(attribute->getValue()); 577 G4Exception("G4GDMLReadMaterials::Materi << 358 578 FatalException, "No attribut << 359 if (attName=="name") { name = GenerateName(attValue); } else 579 return; << 360 if (attName=="Z") { Z = eval.EvaluateInteger(attValue); } else 580 } << 361 if (attName=="N") { N = eval.EvaluateInteger(attValue); } 581 const G4String attName = Transcode(attrib << 362 } 582 const G4String attValue = Transcode(attrib << 363 583 << 364 for (xercesc::DOMNode* iter = isotopeElement->getFirstChild(); 584 if(attName == "name") << 365 iter != 0; iter = iter->getNextSibling()) 585 { << 366 { 586 name = GenerateName(attValue); << 367 if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; } 587 } << 368 588 else if(attName == "Z") << 369 const xercesc::DOMElement* const child 589 { << 370 = dynamic_cast<xercesc::DOMElement*>(iter); 590 Z = eval.Evaluate(attValue); << 371 if (!child) 591 } << 372 { 592 else if(attName == "state") << 373 G4Exception("G4GDMLReadMaterials::IsotopeRead()", "InvalidRead", 593 { << 374 FatalException, "No child found!"); 594 if(attValue == "solid") << 375 return; 595 { << 376 } 596 state = kStateSolid; << 377 const G4String tag = Transcode(child->getTagName()); 597 } << 378 598 else if(attValue == "liquid") << 379 if (tag=="atom") { a = AtomRead(child); } 599 { << 380 } 600 state = kStateLiquid; << 381 601 } << 382 new G4Isotope(Strip(name),Z,N,a); 602 else if(attValue == "gas") << 603 { << 604 state = kStateGas; << 605 } << 606 } << 607 } << 608 << 609 std::size_t nComponents = 0; << 610 << 611 for(xercesc::DOMNode* iter = materialElement << 612 iter != nullptr; iter << 613 { << 614 if(iter->getNodeType() != xercesc::DOMNode << 615 { << 616 continue; << 617 } << 618 << 619 const xercesc::DOMElement* const child = << 620 dynamic_cast<xercesc::DOMElement*>(iter) << 621 if(child == nullptr) << 622 { << 623 G4Exception("G4GDMLReadMaterials::Materi << 624 FatalException, "No child fo << 625 return; << 626 } << 627 const G4String tag = Transcode(child->getT << 628 << 629 if(tag == "atom") << 630 { << 631 a = AtomRead(child); << 632 } << 633 else if(tag == "Dref") << 634 { << 635 D = GetQuantity(GenerateName(RefRead(chi << 636 } << 637 else if(tag == "Pref") << 638 { << 639 P = GetQuantity(GenerateName(RefRead(chi << 640 } << 641 else if(tag == "Tref") << 642 { << 643 T = GetQuantity(GenerateName(RefRead(chi << 644 } << 645 else if(tag == "MEEref") << 646 { << 647 MEE = GetQuantity(GenerateName(RefRead(c << 648 } << 649 else if(tag == "D") << 650 { << 651 D = DRead(child); << 652 } << 653 else if(tag == "P") << 654 { << 655 P = PRead(child); << 656 } << 657 else if(tag == "T") << 658 { << 659 T = TRead(child); << 660 } << 661 else if(tag == "MEE") << 662 { << 663 MEE = MEERead(child); << 664 } << 665 else if(tag == "fraction" || tag == "compo << 666 { << 667 nComponents++; << 668 } << 669 } << 670 << 671 G4Material* material = nullptr; << 672 << 673 if(nComponents == 0) << 674 { << 675 material = new G4Material(Strip(name), Z, << 676 } << 677 else << 678 { << 679 material = new G4Material(Strip(name), D, << 680 MixtureRead(materialElement, material); << 681 } << 682 if(MEE != -1) // ionisation potential (mean << 683 { << 684 material->GetIonisation()->SetMeanExcitati << 685 } << 686 << 687 for(xercesc::DOMNode* iter = materialElement << 688 iter != nullptr; iter << 689 { << 690 if(iter->getNodeType() != xercesc::DOMNode << 691 { << 692 continue; << 693 } << 694 << 695 const xercesc::DOMElement* const child = << 696 dynamic_cast<xercesc::DOMElement*>(iter) << 697 if(child == nullptr) << 698 { << 699 G4Exception("G4GDMLReadMaterials::Materi << 700 FatalException, "No child fo << 701 return; << 702 } << 703 const G4String tag = Transcode(child->getT << 704 << 705 if(tag == "property") << 706 { << 707 PropertyRead(child, material); << 708 } << 709 } << 710 } 383 } 711 384 712 // ------------------------------------------- << 385 void G4GDMLReadMaterials:: 713 void G4GDMLReadMaterials::MixtureRead( << 386 MaterialRead(const xercesc::DOMElement* const materialElement) 714 const xercesc::DOMElement* const mixtureElem << 715 { 387 { 716 for(xercesc::DOMNode* iter = mixtureElement- << 388 G4String name; 717 iter = iter->getNextSi << 389 G4double Z = 0.0; 718 { << 390 G4double a = 0.0; 719 if(iter->getNodeType() != xercesc::DOMNode << 391 G4double D = 0.0; 720 { << 392 G4State state = kStateUndefined; 721 continue; << 393 G4double T = STP_Temperature; 722 } << 394 G4double P = STP_Pressure; 723 << 395 724 const xercesc::DOMElement* const child = << 396 const xercesc::DOMNamedNodeMap* const attributes 725 dynamic_cast<xercesc::DOMElement*>(iter) << 397 = materialElement->getAttributes(); 726 if(child == nullptr) << 398 XMLSize_t attributeCount = attributes->getLength(); 727 { << 399 728 G4Exception("G4GDMLReadMaterials::Mixtur << 400 for (XMLSize_t attribute_index=0; 729 FatalException, "No child fo << 401 attribute_index<attributeCount; attribute_index++) 730 return; << 402 { 731 } << 403 xercesc::DOMNode* attribute_node = attributes->item(attribute_index); 732 const G4String tag = Transcode(child->getT << 404 733 << 405 if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE) 734 if(tag == "fraction") << 406 { continue; } 735 { << 407 736 G4String ref; << 408 const xercesc::DOMAttr* const attribute 737 G4double n = FractionRead(child, ref); << 409 = dynamic_cast<xercesc::DOMAttr*>(attribute_node); 738 element->AddIsotope(GetIsotope(GenerateN << 410 if (!attribute) 739 } << 411 { 740 } << 412 G4Exception("G4GDMLReadMaterials::MaterialRead()", "InvalidRead", >> 413 FatalException, "No attribute found!"); >> 414 return; >> 415 } >> 416 const G4String attName = Transcode(attribute->getName()); >> 417 const G4String attValue = Transcode(attribute->getValue()); >> 418 >> 419 if (attName=="name") { name = GenerateName(attValue); } else >> 420 if (attName=="Z") { Z = eval.Evaluate(attValue); } else >> 421 if (attName=="state") >> 422 { >> 423 if (attValue=="solid") { state = kStateSolid; } else >> 424 if (attValue=="liquid") { state = kStateLiquid; } else >> 425 if (attValue=="gas") { state = kStateGas; } >> 426 } >> 427 } >> 428 >> 429 size_t nComponents = 0; >> 430 >> 431 for (xercesc::DOMNode* iter = materialElement->getFirstChild(); >> 432 iter != 0; iter = iter->getNextSibling()) >> 433 { >> 434 if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; } >> 435 >> 436 const xercesc::DOMElement* const child >> 437 = dynamic_cast<xercesc::DOMElement*>(iter); >> 438 if (!child) >> 439 { >> 440 G4Exception("G4GDMLReadMaterials::MaterialRead()", "InvalidRead", >> 441 FatalException, "No child found!"); >> 442 return; >> 443 } >> 444 const G4String tag = Transcode(child->getTagName()); >> 445 >> 446 if (tag=="atom") { a = AtomRead(child); } else >> 447 if (tag=="Dref") { D = GetQuantity(GenerateName(RefRead(child))); } else >> 448 if (tag=="Pref") { P = GetQuantity(GenerateName(RefRead(child))); } else >> 449 if (tag=="Tref") { T = GetQuantity(GenerateName(RefRead(child))); } else >> 450 if (tag=="D") { D = DRead(child); } else >> 451 if (tag=="P") { P = PRead(child); } else >> 452 if (tag=="T") { T = TRead(child); } else >> 453 if (tag=="fraction" || tag=="composite") { nComponents++; } >> 454 } >> 455 >> 456 G4Material* material = 0; >> 457 >> 458 if (nComponents==0) >> 459 { >> 460 material = new G4Material(Strip(name),Z,a,D,state,T,P); >> 461 } >> 462 else >> 463 { >> 464 material = new G4Material(Strip(name),D,nComponents,state,T,P); >> 465 MixtureRead(materialElement, material); >> 466 } >> 467 >> 468 for (xercesc::DOMNode* iter = materialElement->getFirstChild(); >> 469 iter != 0; iter = iter->getNextSibling()) >> 470 { >> 471 if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; } >> 472 >> 473 const xercesc::DOMElement* const child >> 474 = dynamic_cast<xercesc::DOMElement*>(iter); >> 475 if (!child) >> 476 { >> 477 G4Exception("G4GDMLReadMaterials::MaterialRead()", "InvalidRead", >> 478 FatalException, "No child found!"); >> 479 return; >> 480 } >> 481 const G4String tag = Transcode(child->getTagName()); >> 482 >> 483 if (tag=="property") { PropertyRead(child,material); } >> 484 } 741 } 485 } 742 486 743 // ------------------------------------------- << 487 void G4GDMLReadMaterials:: 744 void G4GDMLReadMaterials::MixtureRead( << 488 MixtureRead(const xercesc::DOMElement *const mixtureElement, G4Element *element) 745 const xercesc::DOMElement* const mixtureElem << 746 { 489 { 747 for(xercesc::DOMNode* iter = mixtureElement- << 490 for (xercesc::DOMNode* iter = mixtureElement->getFirstChild(); 748 iter = iter->getNextSi << 491 iter != 0; iter = iter->getNextSibling()) 749 { << 492 { 750 if(iter->getNodeType() != xercesc::DOMNode << 493 if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; } 751 { << 752 continue; << 753 } << 754 494 755 const xercesc::DOMElement* const child = << 495 const xercesc::DOMElement* const child 756 dynamic_cast<xercesc::DOMElement*>(iter) << 496 = dynamic_cast<xercesc::DOMElement*>(iter); 757 if(child == nullptr) << 497 if (!child) 758 { << 498 { 759 G4Exception("G4GDMLReadMaterials::Mixtur << 499 G4Exception("G4GDMLReadMaterials::MixtureRead()", "InvalidRead", 760 FatalException, "No child fo << 500 FatalException, "No child found!"); 761 return; << 501 return; 762 } << 502 } 763 const G4String tag = Transcode(child->getT << 503 const G4String tag = Transcode(child->getTagName()); 764 504 765 if(tag == "fraction") << 505 if (tag=="fraction") 766 { << 506 { 767 G4String ref; << 507 G4String ref; 768 G4double n = FractionRead(child, ref); << 508 G4double n = FractionRead(child,ref); >> 509 element->AddIsotope(GetIsotope(GenerateName(ref,true)),n); >> 510 } >> 511 } >> 512 } 769 513 770 G4Material* materialPtr = GetMaterial(Ge << 514 void G4GDMLReadMaterials:: 771 G4Element* elementPtr = GetElement(Gen << 515 MixtureRead(const xercesc::DOMElement *const mixtureElement, >> 516 G4Material *material) >> 517 { >> 518 for (xercesc::DOMNode* iter = mixtureElement->getFirstChild(); >> 519 iter != 0; iter = iter->getNextSibling()) >> 520 { >> 521 if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; } 772 522 773 if(elementPtr != nullptr) << 523 const xercesc::DOMElement* const child >> 524 = dynamic_cast<xercesc::DOMElement*>(iter); >> 525 if (!child) 774 { 526 { 775 material->AddElement(elementPtr, n); << 527 G4Exception("G4GDMLReadMaterials::MixtureRead()", "InvalidRead", >> 528 FatalException, "No child found!"); >> 529 return; 776 } 530 } 777 else if(materialPtr != nullptr) << 531 const G4String tag = Transcode(child->getTagName()); >> 532 >> 533 if (tag=="fraction") 778 { 534 { 779 material->AddMaterial(materialPtr, n); << 535 G4String ref; 780 } << 536 G4double n = FractionRead(child,ref); >> 537 >> 538 G4Material *materialPtr = GetMaterial(GenerateName(ref,true), false); >> 539 G4Element *elementPtr = GetElement(GenerateName(ref,true), false); 781 540 782 if((materialPtr == nullptr) && (elementP << 541 if (materialPtr != 0) { material->AddMaterial(materialPtr,n); } else >> 542 if (elementPtr != 0) { material->AddElement(elementPtr,n); } >> 543 >> 544 if ((materialPtr == 0) && (elementPtr == 0)) >> 545 { >> 546 G4String error_msg = "Referenced material/element '" >> 547 + GenerateName(ref,true) + "' was not found!"; >> 548 G4Exception("G4GDMLReadMaterials::MixtureRead()", "InvalidSetup", >> 549 FatalException, error_msg); >> 550 } >> 551 } >> 552 else if (tag=="composite") 783 { 553 { 784 G4String error_msg = "Referenced mater << 554 G4String ref; 785 GenerateName(ref, << 555 G4int n = CompositeRead(child,ref); 786 G4Exception("G4GDMLReadMaterials::Mixt << 556 787 FatalException, error_msg) << 557 G4Element *elementPtr = GetElement(GenerateName(ref,true)); >> 558 material->AddElement(elementPtr,n); 788 } 559 } 789 } << 560 } 790 else if(tag == "composite") << 791 { << 792 G4String ref; << 793 G4int n = CompositeRead(child, ref); << 794 << 795 G4Element* elementPtr = GetElement(Gener << 796 material->AddElement(elementPtr, n); << 797 } << 798 } << 799 } 561 } 800 562 801 // ------------------------------------------- << 563 void G4GDMLReadMaterials:: 802 void G4GDMLReadMaterials::PropertyRead( << 564 PropertyRead(const xercesc::DOMElement* const propertyElement, 803 const xercesc::DOMElement* const propertyEle << 565 G4Material* material) 804 { 566 { 805 G4String name; << 567 G4String name; 806 G4String ref; << 568 G4String ref; 807 G4GDMLMatrix matrix; << 569 G4GDMLMatrix matrix; 808 << 570 809 const xercesc::DOMNamedNodeMap* const attrib << 571 const xercesc::DOMNamedNodeMap* const attributes 810 propertyElement->getAttributes(); << 572 = propertyElement->getAttributes(); 811 XMLSize_t attributeCount = attributes->getLe << 573 XMLSize_t attributeCount = attributes->getLength(); 812 << 574 813 for(XMLSize_t attribute_index = 0; attribute << 575 for (XMLSize_t attribute_index=0; 814 ++attribute_index) << 576 attribute_index<attributeCount; attribute_index++) 815 { << 577 { 816 xercesc::DOMNode* attribute_node = attribu << 578 xercesc::DOMNode* attribute_node = attributes->item(attribute_index); 817 << 579 818 if(attribute_node->getNodeType() != xerces << 580 if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE) 819 { << 581 { continue; } 820 continue; << 582 821 } << 583 const xercesc::DOMAttr* const attribute 822 << 584 = dynamic_cast<xercesc::DOMAttr*>(attribute_node); 823 const xercesc::DOMAttr* const attribute = << 585 if (!attribute) 824 dynamic_cast<xercesc::DOMAttr*>(attribut << 586 { 825 if(attribute == nullptr) << 587 G4Exception("G4GDMLReadMaterials::PropertyRead()", "InvalidRead", 826 { << 588 FatalException, "No attribute found!"); 827 G4Exception("G4GDMLReadMaterials::Proper << 589 return; 828 FatalException, "No attribut << 590 } 829 return; << 591 const G4String attName = Transcode(attribute->getName()); 830 } << 592 const G4String attValue = Transcode(attribute->getValue()); 831 const G4String attName = Transcode(attrib << 593 832 const G4String attValue = Transcode(attrib << 594 if (attName=="name") { name = GenerateName(attValue); } else 833 << 595 if (attName=="ref") { matrix = GetMatrix(ref=attValue); } 834 if(attName == "name") << 596 } 835 { << 597 836 name = GenerateName(attValue); << 598 if (matrix.GetCols() != 2) 837 } << 599 { 838 else if(attName == "ref") << 600 G4String error_msg = "Referenced matrix '" + ref 839 { << 601 + "' should have \n two columns as a property table for material: " 840 matrix = GetMatrix(ref = attValue); << 602 + material->GetName(); 841 } << 603 G4Exception("G4GDMLReadMaterials::PropertyRead()", "InvalidRead", 842 } << 604 FatalException, error_msg); 843 << 605 } 844 /* << 606 if (matrix.GetRows() == 0) { return; } 845 if (matrix.GetCols() != 2) << 607 846 { << 608 G4MaterialPropertiesTable* matprop=material->GetMaterialPropertiesTable(); 847 G4String error_msg = "Referenced matrix '" << 609 if (!matprop) 848 + "' should have \n two columns as << 610 { 849 + material->GetName(); << 611 matprop = new G4MaterialPropertiesTable(); 850 G4Exception("G4GDMLReadMaterials::Property << 612 material->SetMaterialPropertiesTable(matprop); 851 FatalException, error_msg); << 613 } 852 } << 614 if (matrix.GetCols() == 1) // constant property assumed 853 */ << 615 { 854 << 616 matprop->AddConstProperty(Strip(name), matrix.Get(0,0)); 855 if(matrix.GetRows() == 0) << 617 } 856 { << 618 else // build the material properties vector 857 return; << 619 { 858 } << 620 G4MaterialPropertyVector* propvect = new G4MaterialPropertyVector(0,0,0); 859 << 621 for (size_t i=0; i<matrix.GetRows(); i++) 860 G4MaterialPropertiesTable* matprop = materia << 622 { 861 if(matprop == nullptr) << 623 propvect->AddElement(matrix.Get(i,0),matrix.Get(i,1)); 862 { << 624 } 863 matprop = new G4MaterialPropertiesTable(); << 625 matprop->AddProperty(Strip(name),propvect); 864 material->SetMaterialPropertiesTable(matpr << 626 } 865 } << 866 if(matrix.GetCols() == 1) // constant prope << 867 { << 868 matprop->AddConstProperty(Strip(name), mat << 869 } << 870 else // build the material properties vecto << 871 { << 872 G4MaterialPropertyVector* propvect = new G << 873 for(std::size_t i = 0; i < matrix.GetRows( << 874 { << 875 propvect->InsertValues(matrix.Get(i, 0), << 876 } << 877 matprop->AddProperty(Strip(name), propvect << 878 } << 879 } 627 } 880 628 881 // ------------------------------------------- << 629 void G4GDMLReadMaterials:: 882 void G4GDMLReadMaterials::MaterialsRead( << 630 MaterialsRead(const xercesc::DOMElement* const materialsElement) 883 const xercesc::DOMElement* const materialsEl << 884 { 631 { 885 #ifdef G4VERBOSE << 632 G4cout << "G4GDML: Reading materials..." << G4endl; 886 G4cout << "G4GDML: Reading materials..." << << 633 887 #endif << 634 for (xercesc::DOMNode* iter = materialsElement->getFirstChild(); 888 for(xercesc::DOMNode* iter = materialsElemen << 635 iter != 0; iter = iter->getNextSibling()) 889 iter != nullptr; iter << 636 { 890 { << 637 if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; } 891 if(iter->getNodeType() != xercesc::DOMNode << 638 892 { << 639 const xercesc::DOMElement* const child 893 continue; << 640 = dynamic_cast<xercesc::DOMElement*>(iter); 894 } << 641 if (!child) 895 << 642 { 896 const xercesc::DOMElement* const child = << 643 G4Exception("G4GDMLReadMaterials::MaterialsRead()", "InvalidRead", 897 dynamic_cast<xercesc::DOMElement*>(iter) << 644 FatalException, "No child found!"); 898 if(child == nullptr) << 645 return; 899 { << 646 } 900 G4Exception("G4GDMLReadMaterials::Materi << 647 const G4String tag = Transcode(child->getTagName()); 901 FatalException, "No child fo << 648 902 return; << 649 if (tag=="define") { DefineRead(child); } else 903 } << 650 if (tag=="element") { ElementRead(child); } else 904 const G4String tag = Transcode(child->getT << 651 if (tag=="isotope") { IsotopeRead(child); } else 905 << 652 if (tag=="material") { MaterialRead(child); } 906 if(tag == "define") << 653 else 907 { << 654 { 908 DefineRead(child); << 655 G4String error_msg = "Unknown tag in materials: " + tag; 909 } << 656 G4Exception("G4GDMLReadMaterials::MaterialsRead()", "InvalidSetup", 910 else if(tag == "element") << 657 FatalException, error_msg); 911 { << 658 } 912 ElementRead(child); << 659 } 913 } << 914 else if(tag == "isotope") << 915 { << 916 IsotopeRead(child); << 917 } << 918 else if(tag == "material") << 919 { << 920 MaterialRead(child); << 921 } << 922 else << 923 { << 924 G4String error_msg = "Unknown tag in mat << 925 G4Exception("G4GDMLReadMaterials::Materi << 926 FatalException, error_msg); << 927 } << 928 } << 929 } 660 } 930 661 931 // ------------------------------------------- << 662 G4Element* G4GDMLReadMaterials:: 932 G4Element* G4GDMLReadMaterials::GetElement(con << 663 GetElement(const G4String& ref, G4bool verbose) const 933 G4b << 934 { 664 { 935 G4Element* elementPtr = G4Element::GetElemen << 665 G4Element* elementPtr = G4Element::GetElement(ref,false); 936 666 937 if(elementPtr == nullptr) << 667 if (!elementPtr) 938 { << 668 { 939 elementPtr = G4NistManager::Instance()->Fi << 669 elementPtr = G4NistManager::Instance()->FindOrBuildElement(ref); 940 } << 670 } 941 << 942 if(verbose && elementPtr == nullptr) << 943 { << 944 G4String error_msg = "Referenced element ' << 945 G4Exception("G4GDMLReadMaterials::GetEleme << 946 FatalException, error_msg); << 947 } << 948 671 949 return elementPtr; << 672 if (verbose && !elementPtr) >> 673 { >> 674 G4String error_msg = "Referenced element '" + ref + "' was not found!"; >> 675 G4Exception("G4GDMLReadMaterials::GetElement()", "InvalidRead", >> 676 FatalException, error_msg); >> 677 } >> 678 >> 679 return elementPtr; 950 } 680 } 951 681 952 // ------------------------------------------- << 953 G4Isotope* G4GDMLReadMaterials::GetIsotope(con 682 G4Isotope* G4GDMLReadMaterials::GetIsotope(const G4String& ref, 954 G4b 683 G4bool verbose) const 955 { 684 { 956 G4Isotope* isotopePtr = G4Isotope::GetIsotop << 685 G4Isotope* isotopePtr = G4Isotope::GetIsotope(ref,false); 957 686 958 if(verbose && isotopePtr == nullptr) << 687 if (verbose && !isotopePtr) 959 { << 688 { 960 G4String error_msg = "Referenced isotope ' << 689 G4String error_msg = "Referenced isotope '" + ref + "' was not found!"; 961 G4Exception("G4GDMLReadMaterials::GetIsoto << 690 G4Exception("G4GDMLReadMaterials::GetIsotope()", "InvalidRead", 962 FatalException, error_msg); << 691 FatalException, error_msg); 963 } << 692 } 964 693 965 return isotopePtr; << 694 return isotopePtr; 966 } 695 } 967 696 968 // ------------------------------------------- << 969 G4Material* G4GDMLReadMaterials::GetMaterial(c 697 G4Material* G4GDMLReadMaterials::GetMaterial(const G4String& ref, 970 G 698 G4bool verbose) const 971 { 699 { 972 G4Material* materialPtr = G4Material::GetMat << 700 G4Material *materialPtr = G4Material::GetMaterial(ref,false); 973 701 974 if(materialPtr == nullptr) << 702 if (!materialPtr) 975 { << 703 { 976 materialPtr = G4NistManager::Instance()->F << 704 materialPtr = G4NistManager::Instance()->FindOrBuildMaterial(ref); 977 } << 705 } 978 << 706 979 if(verbose && materialPtr == nullptr) << 707 if (verbose && !materialPtr) 980 { << 708 { 981 G4String error_msg = "Referenced material << 709 G4String error_msg = "Referenced material '" + ref + "' was not found!"; 982 G4Exception("G4GDMLReadMaterials::GetMater << 710 G4Exception("G4GDMLReadMaterials::GetMaterial()", "InvalidRead", 983 FatalException, error_msg); << 711 FatalException, error_msg); 984 } << 712 } 985 713 986 return materialPtr; << 714 return materialPtr; 987 } 715 } 988 716