| 1 | //
|
|---|
| 2 | // ********************************************************************
|
|---|
| 3 | // * License and Disclaimer *
|
|---|
| 4 | // * *
|
|---|
| 5 | // * The Geant4 software is copyright of the Copyright Holders of *
|
|---|
| 6 | // * the Geant4 Collaboration. It is provided under the terms and *
|
|---|
| 7 | // * conditions of the Geant4 Software License, included in the file *
|
|---|
| 8 | // * LICENSE and available at http://cern.ch/geant4/license . These *
|
|---|
| 9 | // * include a list of copyright holders. *
|
|---|
| 10 | // * *
|
|---|
| 11 | // * Neither the authors of this software system, nor their employing *
|
|---|
| 12 | // * institutes,nor the agencies providing financial support for this *
|
|---|
| 13 | // * work make any representation or warranty, express or implied, *
|
|---|
| 14 | // * regarding this software system or assume any liability for its *
|
|---|
| 15 | // * use. Please see the license in the file LICENSE and URL above *
|
|---|
| 16 | // * for the full disclaimer and the limitation of liability. *
|
|---|
| 17 | // * *
|
|---|
| 18 | // * This code implementation is the result of the scientific and *
|
|---|
| 19 | // * technical work of the GEANT4 collaboration. *
|
|---|
| 20 | // * By using, copying, modifying or distributing the software (or *
|
|---|
| 21 | // * any work based on the software) you agree to acknowledge its *
|
|---|
| 22 | // * use in resulting scientific publications, and indicate your *
|
|---|
| 23 | // * acceptance of all terms of the Geant4 Software license. *
|
|---|
| 24 | // ********************************************************************
|
|---|
| 25 | //
|
|---|
| 26 | //
|
|---|
| 27 | // $Id: G4GDMLMaterials.cc,v 1.12 2007/11/30 15:20:00 gcosmo Exp $
|
|---|
| 28 | // GEANT4 tag $ Name:$
|
|---|
| 29 | //
|
|---|
| 30 | // class G4GDMLMaterials Implementation
|
|---|
| 31 | //
|
|---|
| 32 | // Original author: Zoltan Torzsok, November 2007
|
|---|
| 33 | //
|
|---|
| 34 | // --------------------------------------------------------------------
|
|---|
| 35 |
|
|---|
| 36 | #include "G4GDMLMaterials.hh"
|
|---|
| 37 |
|
|---|
| 38 | G4double G4GDMLMaterials::atomRead(const xercesc::DOMElement* const element) {
|
|---|
| 39 |
|
|---|
| 40 | G4String value;
|
|---|
| 41 | G4String unit("g/mole");
|
|---|
| 42 |
|
|---|
| 43 | const xercesc::DOMNamedNodeMap* const attributes = element->getAttributes();
|
|---|
| 44 | XMLSize_t attributeCount = attributes->getLength();
|
|---|
| 45 |
|
|---|
| 46 | for (XMLSize_t attribute_index=0;attribute_index<attributeCount;attribute_index++) {
|
|---|
| 47 |
|
|---|
| 48 | xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
|
|---|
| 49 |
|
|---|
| 50 | if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE) continue;
|
|---|
| 51 |
|
|---|
| 52 | const xercesc::DOMAttr* const attribute = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
|
|---|
| 53 |
|
|---|
| 54 | const G4String attribute_name = xercesc::XMLString::transcode(attribute->getName());
|
|---|
| 55 | const G4String attribute_value = xercesc::XMLString::transcode(attribute->getValue());
|
|---|
| 56 |
|
|---|
| 57 | if (attribute_name=="value") value = attribute_value; else
|
|---|
| 58 | if (attribute_name=="unit") unit = attribute_value;
|
|---|
| 59 | }
|
|---|
| 60 |
|
|---|
| 61 | return eval.Evaluate(value)*eval.Evaluate(unit);
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | G4double G4GDMLMaterials::DRead(const xercesc::DOMElement* const element) {
|
|---|
| 65 |
|
|---|
| 66 | G4String value;
|
|---|
| 67 | G4String unit("g/cm3");
|
|---|
| 68 |
|
|---|
| 69 | const xercesc::DOMNamedNodeMap* const attributes = element->getAttributes();
|
|---|
| 70 | XMLSize_t attributeCount = attributes->getLength();
|
|---|
| 71 |
|
|---|
| 72 | for (XMLSize_t attribute_index=0;attribute_index<attributeCount;attribute_index++) {
|
|---|
| 73 |
|
|---|
| 74 | xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
|
|---|
| 75 |
|
|---|
| 76 | if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE) continue;
|
|---|
| 77 |
|
|---|
| 78 | const xercesc::DOMAttr* const attribute = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
|
|---|
| 79 |
|
|---|
| 80 | const G4String attribute_name = xercesc::XMLString::transcode(attribute->getName());
|
|---|
| 81 | const G4String attribute_value = xercesc::XMLString::transcode(attribute->getValue());
|
|---|
| 82 |
|
|---|
| 83 | if (attribute_name=="value") value = attribute_value; else
|
|---|
| 84 | if (attribute_name=="unit") unit = attribute_value;
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | return eval.Evaluate(value)*eval.Evaluate(unit);
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | void G4GDMLMaterials::elementRead(const xercesc::DOMElement* const element) {
|
|---|
| 91 |
|
|---|
| 92 | G4String name;
|
|---|
| 93 | G4String formula;
|
|---|
| 94 | G4String Z;
|
|---|
| 95 |
|
|---|
| 96 | const xercesc::DOMNamedNodeMap* const attributes = element->getAttributes();
|
|---|
| 97 | XMLSize_t attributeCount = attributes->getLength();
|
|---|
| 98 |
|
|---|
| 99 | for (XMLSize_t attribute_index=0;attribute_index<attributeCount;attribute_index++) {
|
|---|
| 100 |
|
|---|
| 101 | xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
|
|---|
| 102 |
|
|---|
| 103 | if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE) continue;
|
|---|
| 104 |
|
|---|
| 105 | const xercesc::DOMAttr* const attribute = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
|
|---|
| 106 |
|
|---|
| 107 | const G4String attribute_name = xercesc::XMLString::transcode(attribute->getName());
|
|---|
| 108 | const G4String attribute_value = xercesc::XMLString::transcode(attribute->getValue());
|
|---|
| 109 |
|
|---|
| 110 | if (attribute_name=="name") name = attribute_value; else
|
|---|
| 111 | if (attribute_name=="formula") formula = attribute_value; else
|
|---|
| 112 | if (attribute_name=="Z") Z = attribute_value;
|
|---|
| 113 | }
|
|---|
| 114 |
|
|---|
| 115 | G4double _Z = eval.Evaluate(Z);
|
|---|
| 116 | G4double _a = 0;
|
|---|
| 117 |
|
|---|
| 118 | G4int nComponents = 0;
|
|---|
| 119 |
|
|---|
| 120 | for (xercesc::DOMNode* iter = element->getFirstChild();iter != 0;iter = iter->getNextSibling()) {
|
|---|
| 121 |
|
|---|
| 122 | if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) continue;
|
|---|
| 123 |
|
|---|
| 124 | const xercesc::DOMElement* const child = dynamic_cast<xercesc::DOMElement*>(iter);
|
|---|
| 125 |
|
|---|
| 126 | const G4String tag = xercesc::XMLString::transcode(child->getTagName());
|
|---|
| 127 |
|
|---|
| 128 | if (tag=="atom") _a = atomRead(child); else
|
|---|
| 129 | if (tag=="fraction") nComponents++; else
|
|---|
| 130 | G4Exception("GDML: Unknown tag in element: "+tag);
|
|---|
| 131 | }
|
|---|
| 132 |
|
|---|
| 133 | if (nComponents>0) mixtureRead(element,new G4Element(GenerateName(name),formula,nComponents));
|
|---|
| 134 | else new G4Element(GenerateName(name),formula,_Z,_a);
|
|---|
| 135 | }
|
|---|
| 136 |
|
|---|
| 137 | G4double G4GDMLMaterials::fractionRead(const xercesc::DOMElement* const element,G4String& ref) {
|
|---|
| 138 |
|
|---|
| 139 | G4String n;
|
|---|
| 140 |
|
|---|
| 141 | const xercesc::DOMNamedNodeMap* const attributes = element->getAttributes();
|
|---|
| 142 | XMLSize_t attributeCount = attributes->getLength();
|
|---|
| 143 |
|
|---|
| 144 | for (XMLSize_t attribute_index=0;attribute_index<attributeCount;attribute_index++) {
|
|---|
| 145 |
|
|---|
| 146 | xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
|
|---|
| 147 |
|
|---|
| 148 | if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE) continue;
|
|---|
| 149 |
|
|---|
| 150 | const xercesc::DOMAttr* const attribute = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
|
|---|
| 151 |
|
|---|
| 152 | const G4String attribute_name = xercesc::XMLString::transcode(attribute->getName());
|
|---|
| 153 | const G4String attribute_value = xercesc::XMLString::transcode(attribute->getValue());
|
|---|
| 154 |
|
|---|
| 155 | if (attribute_name=="n") n = attribute_value; else
|
|---|
| 156 | if (attribute_name=="ref") ref = attribute_value;
|
|---|
| 157 | }
|
|---|
| 158 |
|
|---|
| 159 | return eval.Evaluate(n);
|
|---|
| 160 | }
|
|---|
| 161 |
|
|---|
| 162 | void G4GDMLMaterials::isotopeRead(const xercesc::DOMElement* const element) {
|
|---|
| 163 |
|
|---|
| 164 | G4String name;
|
|---|
| 165 | G4String Z;
|
|---|
| 166 | G4String N;
|
|---|
| 167 |
|
|---|
| 168 | const xercesc::DOMNamedNodeMap* const attributes = element->getAttributes();
|
|---|
| 169 | XMLSize_t attributeCount = attributes->getLength();
|
|---|
| 170 |
|
|---|
| 171 | for (XMLSize_t attribute_index=0;attribute_index<attributeCount;attribute_index++) {
|
|---|
| 172 |
|
|---|
| 173 | xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
|
|---|
| 174 |
|
|---|
| 175 | if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE) continue;
|
|---|
| 176 |
|
|---|
| 177 | const xercesc::DOMAttr* const attribute = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
|
|---|
| 178 |
|
|---|
| 179 | const G4String attribute_name = xercesc::XMLString::transcode(attribute->getName());
|
|---|
| 180 | const G4String attribute_value = xercesc::XMLString::transcode(attribute->getValue());
|
|---|
| 181 |
|
|---|
| 182 | if (attribute_name=="name") name = attribute_value; else
|
|---|
| 183 | if (attribute_name=="Z") Z = attribute_value; else
|
|---|
| 184 | if (attribute_name=="N") N = attribute_value;
|
|---|
| 185 | }
|
|---|
| 186 |
|
|---|
| 187 | G4double __Z = eval.Evaluate(Z);
|
|---|
| 188 | G4double __N = eval.Evaluate(N);
|
|---|
| 189 | G4double __a = 0;
|
|---|
| 190 |
|
|---|
| 191 | for (xercesc::DOMNode* iter = element->getFirstChild();iter != 0;iter = iter->getNextSibling()) {
|
|---|
| 192 |
|
|---|
| 193 | if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) continue;
|
|---|
| 194 |
|
|---|
| 195 | const xercesc::DOMElement* const child = dynamic_cast<xercesc::DOMElement*>(iter);
|
|---|
| 196 |
|
|---|
| 197 | const G4String tag = xercesc::XMLString::transcode(child->getTagName());
|
|---|
| 198 |
|
|---|
| 199 | if (tag=="atom") __a = atomRead(child);
|
|---|
| 200 | }
|
|---|
| 201 |
|
|---|
| 202 | new G4Isotope(GenerateName(name),(G4int)__Z,(G4int)__N,__a);
|
|---|
| 203 | }
|
|---|
| 204 |
|
|---|
| 205 | void G4GDMLMaterials::materialRead(const xercesc::DOMElement* const element) {
|
|---|
| 206 |
|
|---|
| 207 | G4String name;
|
|---|
| 208 | G4String Z;
|
|---|
| 209 |
|
|---|
| 210 | const xercesc::DOMNamedNodeMap* const attributes = element->getAttributes();
|
|---|
| 211 | XMLSize_t attributeCount = attributes->getLength();
|
|---|
| 212 |
|
|---|
| 213 | for (XMLSize_t attribute_index=0;attribute_index<attributeCount;attribute_index++) {
|
|---|
| 214 |
|
|---|
| 215 | xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
|
|---|
| 216 |
|
|---|
| 217 | if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE) continue;
|
|---|
| 218 |
|
|---|
| 219 | const xercesc::DOMAttr* const attribute = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
|
|---|
| 220 |
|
|---|
| 221 | const G4String attribute_name = xercesc::XMLString::transcode(attribute->getName());
|
|---|
| 222 | const G4String attribute_value = xercesc::XMLString::transcode(attribute->getValue());
|
|---|
| 223 |
|
|---|
| 224 | if (attribute_name=="name") name = attribute_value; else
|
|---|
| 225 | if (attribute_name=="Z") Z = attribute_value;
|
|---|
| 226 | }
|
|---|
| 227 |
|
|---|
| 228 | G4double _Z = eval.Evaluate(Z);
|
|---|
| 229 | G4double _D = 0.0;
|
|---|
| 230 | G4double _a = 0.0;
|
|---|
| 231 |
|
|---|
| 232 | G4int nComponents = 0;
|
|---|
| 233 |
|
|---|
| 234 | for (xercesc::DOMNode* iter = element->getFirstChild();iter != 0;iter = iter->getNextSibling()) {
|
|---|
| 235 |
|
|---|
| 236 | if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) continue;
|
|---|
| 237 |
|
|---|
| 238 | const xercesc::DOMElement* const child = dynamic_cast<xercesc::DOMElement*>(iter);
|
|---|
| 239 |
|
|---|
| 240 | const G4String tag = xercesc::XMLString::transcode(child->getTagName());
|
|---|
| 241 |
|
|---|
| 242 | if (tag=="D") _D = DRead(child); else
|
|---|
| 243 | if (tag=="atom") _a = atomRead(child); else
|
|---|
| 244 | if (tag=="fraction") nComponents++; else
|
|---|
| 245 | G4Exception("GDML: Unknown tag in material: "+tag);
|
|---|
| 246 | }
|
|---|
| 247 |
|
|---|
| 248 | if (nComponents>0) mixtureRead(element,new G4Material(GenerateName(name),_D,nComponents));
|
|---|
| 249 | else new G4Material(GenerateName(name),_Z,_a,_D);
|
|---|
| 250 | }
|
|---|
| 251 |
|
|---|
| 252 | void G4GDMLMaterials::mixtureRead(const xercesc::DOMElement *const element,G4Element *ele) {
|
|---|
| 253 |
|
|---|
| 254 | for (xercesc::DOMNode* iter = element->getFirstChild();iter != 0;iter = iter->getNextSibling()) {
|
|---|
| 255 |
|
|---|
| 256 | if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) continue;
|
|---|
| 257 |
|
|---|
| 258 | const xercesc::DOMElement* const child = dynamic_cast<xercesc::DOMElement*>(iter);
|
|---|
| 259 |
|
|---|
| 260 | const G4String tag = xercesc::XMLString::transcode(child->getTagName());
|
|---|
| 261 |
|
|---|
| 262 | if (tag=="fraction") {
|
|---|
| 263 |
|
|---|
| 264 | G4String ref;
|
|---|
| 265 | G4double _n = fractionRead(child,ref);
|
|---|
| 266 |
|
|---|
| 267 | ele->AddIsotope(getIsotope(GenerateName(ref)),_n);
|
|---|
| 268 | } else G4Exception("GDML: Unknown tag in mixture element: "+tag);
|
|---|
| 269 | }
|
|---|
| 270 | }
|
|---|
| 271 |
|
|---|
| 272 | void G4GDMLMaterials::mixtureRead(const xercesc::DOMElement *const element,G4Material *material) {
|
|---|
| 273 |
|
|---|
| 274 | for (xercesc::DOMNode* iter = element->getFirstChild();iter != 0;iter = iter->getNextSibling()) {
|
|---|
| 275 |
|
|---|
| 276 | if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) continue;
|
|---|
| 277 |
|
|---|
| 278 | const xercesc::DOMElement* const child = dynamic_cast<xercesc::DOMElement*>(iter);
|
|---|
| 279 |
|
|---|
| 280 | const G4String tag = xercesc::XMLString::transcode(child->getTagName());
|
|---|
| 281 |
|
|---|
| 282 | if (tag=="D") { /*already processed*/ } else
|
|---|
| 283 | if (tag=="fraction") {
|
|---|
| 284 |
|
|---|
| 285 | G4String ref;
|
|---|
| 286 | G4double _n = fractionRead(child,ref);
|
|---|
| 287 |
|
|---|
| 288 | G4Material *materialPtr = G4Material::GetMaterial(GenerateName(ref),false);
|
|---|
| 289 | G4Element *elementPtr = G4Element::GetElement(GenerateName(ref),false);
|
|---|
| 290 |
|
|---|
| 291 | if (materialPtr != 0) material->AddMaterial(materialPtr,_n); else
|
|---|
| 292 | if (elementPtr != 0) material->AddElement(elementPtr,_n);
|
|---|
| 293 |
|
|---|
| 294 | if ((materialPtr == 0) && (elementPtr == 0)) G4Exception("GDML: Referenced material/element '"+GenerateName(ref)+"' was not found!");
|
|---|
| 295 | } else G4Exception("GDML: Unknown tag in mixture material: "+tag);
|
|---|
| 296 | }
|
|---|
| 297 | }
|
|---|
| 298 |
|
|---|
| 299 | void G4GDMLMaterials::materialsRead(const xercesc::DOMElement* const element) {
|
|---|
| 300 |
|
|---|
| 301 | for (xercesc::DOMNode* iter = element->getFirstChild();iter != 0;iter = iter->getNextSibling()) {
|
|---|
| 302 |
|
|---|
| 303 | if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) continue;
|
|---|
| 304 |
|
|---|
| 305 | const xercesc::DOMElement* const child = dynamic_cast<xercesc::DOMElement*>(iter);
|
|---|
| 306 |
|
|---|
| 307 | const G4String tag = xercesc::XMLString::transcode(child->getTagName());
|
|---|
| 308 |
|
|---|
| 309 | if (tag=="element") elementRead(child); else
|
|---|
| 310 | if (tag=="isotope") isotopeRead(child); else
|
|---|
| 311 | if (tag=="material") materialRead(child); else
|
|---|
| 312 | G4Exception("GDML: Unknown tag in materials: "+tag);
|
|---|
| 313 | }
|
|---|
| 314 | }
|
|---|
| 315 |
|
|---|
| 316 | G4Isotope* G4GDMLMaterials::getIsotope(const G4String& ref) const {
|
|---|
| 317 |
|
|---|
| 318 | G4Isotope* isotopePtr = G4Isotope::GetIsotope(ref,false);
|
|---|
| 319 |
|
|---|
| 320 | if (!isotopePtr) G4Exception("GDML: Referenced isotope '"+ref+"' was not found!");
|
|---|
| 321 |
|
|---|
| 322 | return isotopePtr;
|
|---|
| 323 | }
|
|---|
| 324 |
|
|---|
| 325 | G4Material* G4GDMLMaterials::getMaterial(const G4String& ref) const {
|
|---|
| 326 |
|
|---|
| 327 | G4Material *materialPtr = G4Material::GetMaterial(ref,false);
|
|---|
| 328 |
|
|---|
| 329 | if (!materialPtr) G4Exception("GDML: Referenced material '"+ref+"' was not found!");
|
|---|
| 330 |
|
|---|
| 331 | return materialPtr;
|
|---|
| 332 | }
|
|---|