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