Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/persistency/gdml/src/G4GDMLReadMaterials.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /persistency/gdml/src/G4GDMLReadMaterials.cc (Version 11.3.0) and /persistency/gdml/src/G4GDMLReadMaterials.cc (Version 9.6.p3)


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