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