source: trunk/source/persistency/gdml/src/G4GDMLReadMaterials.cc @ 1347

Last change on this file since 1347 was 1347, checked in by garnier, 14 years ago

geant4 tag 9.4

File size: 23.3 KB
Line 
1//
2// ********************************************************************
3// * License and Disclaimer                                           *
4// *                                                                  *
5// * The  Geant4 software  is  copyright of the Copyright Holders  of *
6// * the Geant4 Collaboration.  It is provided  under  the terms  and *
7// * conditions of the Geant4 Software License,  included in the file *
8// * LICENSE and available at  http://cern.ch/geant4/license .  These *
9// * include a list of copyright holders.                             *
10// *                                                                  *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work  make  any representation or  warranty, express or implied, *
14// * regarding  this  software system or assume any liability for its *
15// * use.  Please see the license in the file  LICENSE  and URL above *
16// * for the full disclaimer and the limitation of liability.         *
17// *                                                                  *
18// * This  code  implementation is the result of  the  scientific and *
19// * technical work of the GEANT4 collaboration.                      *
20// * By using,  copying,  modifying or  distributing the software (or *
21// * any work based  on the software)  you  agree  to acknowledge its *
22// * use  in  resulting  scientific  publications,  and indicate your *
23// * acceptance of all terms of the Geant4 Software license.          *
24// ********************************************************************
25//
26//
27// $Id: G4GDMLReadMaterials.cc,v 1.21 2010/10/14 16:19:40 gcosmo Exp $
28// GEANT4 tag $ Name:$
29//
30// class G4GDMLReadMaterials Implementation
31//
32// Original author: Zoltan Torzsok, November 2007
33//
34// --------------------------------------------------------------------
35
36#include "G4GDMLReadMaterials.hh"
37
38#include "G4Element.hh"
39#include "G4Isotope.hh"
40#include "G4Material.hh"
41#include "G4NistManager.hh"
42
43G4GDMLReadMaterials::G4GDMLReadMaterials() : G4GDMLReadDefine()
44{
45}
46
47G4GDMLReadMaterials::~G4GDMLReadMaterials()
48{
49}
50
51G4double
52G4GDMLReadMaterials::AtomRead(const xercesc::DOMElement* const atomElement)
53{
54   G4double value = 0.0;
55   G4double unit = g/mole;
56
57   const xercesc::DOMNamedNodeMap* const attributes
58         = atomElement->getAttributes();
59   XMLSize_t attributeCount = attributes->getLength();
60
61   for (XMLSize_t attribute_index=0;
62        attribute_index<attributeCount; attribute_index++)
63   {
64      xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
65
66      if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
67      { continue; }
68
69      const xercesc::DOMAttr* const attribute
70            = dynamic_cast<xercesc::DOMAttr*>(attribute_node);   
71      if (!attribute)
72      {
73        G4Exception("G4GDMLReadMaterials::AtomRead()", "InvalidRead",
74                    FatalException, "No attribute found!");
75        return value;
76      }
77      const G4String attName = Transcode(attribute->getName());
78      const G4String attValue = Transcode(attribute->getValue());
79
80      if (attName=="value") { value = eval.Evaluate(attValue); } else
81      if (attName=="unit")  { unit = eval.Evaluate(attValue); }
82   }
83
84   return value*unit;
85}
86
87G4int G4GDMLReadMaterials::
88CompositeRead(const xercesc::DOMElement* const compositeElement,G4String& ref)
89{
90   G4int n = 0;
91
92   const xercesc::DOMNamedNodeMap* const attributes
93         = compositeElement->getAttributes();
94   XMLSize_t attributeCount = attributes->getLength();
95
96   for (XMLSize_t attribute_index=0;
97        attribute_index<attributeCount; attribute_index++)
98   {
99      xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
100
101      if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
102      { continue; }
103
104      const xercesc::DOMAttr* const attribute
105            = dynamic_cast<xercesc::DOMAttr*>(attribute_node);   
106      if (!attribute)
107      {
108        G4Exception("G4GDMLReadMaterials::CompositeRead()", "InvalidRead",
109                    FatalException, "No attribute found!");
110        return n;
111      }
112      const G4String attName = Transcode(attribute->getName());
113      const G4String attValue = Transcode(attribute->getValue());
114
115      if (attName=="n")  { n = eval.EvaluateInteger(attValue); } else
116      if (attName=="ref") { ref = attValue; }
117   }
118
119   return n;
120}
121
122G4double G4GDMLReadMaterials::DRead(const xercesc::DOMElement* const DElement)
123{
124   G4double value = 0.0;
125   G4double unit = g/cm3;
126
127   const xercesc::DOMNamedNodeMap* const attributes
128         = DElement->getAttributes();
129   XMLSize_t attributeCount = attributes->getLength();
130
131   for (XMLSize_t attribute_index=0;
132        attribute_index<attributeCount; attribute_index++)
133   {
134      xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
135
136      if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
137      { continue; }
138
139      const xercesc::DOMAttr* const attribute
140            = dynamic_cast<xercesc::DOMAttr*>(attribute_node);   
141      if (!attribute)
142      {
143        G4Exception("G4GDMLReadMaterials::DRead()", "InvalidRead",
144                    FatalException, "No attribute found!");
145        return value;
146      }
147      const G4String attName = Transcode(attribute->getName());
148      const G4String attValue = Transcode(attribute->getValue());
149
150      if (attName=="value") { value = eval.Evaluate(attValue); } else
151      if (attName=="unit")  { unit = eval.Evaluate(attValue); }
152   }
153
154   return value*unit;
155}
156
157G4double G4GDMLReadMaterials::PRead(const xercesc::DOMElement* const PElement)
158{
159   G4double value = STP_Pressure;
160   G4double unit = pascal;
161
162   const xercesc::DOMNamedNodeMap* const attributes = PElement->getAttributes();
163   XMLSize_t attributeCount = attributes->getLength();
164
165   for (XMLSize_t attribute_index=0;
166        attribute_index<attributeCount; attribute_index++)
167   {
168      xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
169
170      if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
171      { continue; }
172
173      const xercesc::DOMAttr* const attribute
174            = dynamic_cast<xercesc::DOMAttr*>(attribute_node);   
175      if (!attribute)
176      {
177        G4Exception("G4GDMLReadMaterials::PRead()", "InvalidRead",
178                    FatalException, "No attribute found!");
179        return value;
180      }
181      const G4String attName = Transcode(attribute->getName());
182      const G4String attValue = Transcode(attribute->getValue());
183
184      if (attName=="value") { value = eval.Evaluate(attValue); } else
185      if (attName=="unit")  { unit = eval.Evaluate(attValue); }
186   }
187
188   return value*unit;
189}
190
191G4double G4GDMLReadMaterials::TRead(const xercesc::DOMElement* const TElement)
192{
193   G4double value = STP_Temperature;
194   G4double unit = kelvin;
195
196   const xercesc::DOMNamedNodeMap* const attributes = TElement->getAttributes();
197   XMLSize_t attributeCount = attributes->getLength();
198
199   for (XMLSize_t attribute_index=0;
200        attribute_index<attributeCount; attribute_index++)
201   {
202      xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
203
204      if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
205      { continue; }
206
207      const xercesc::DOMAttr* const attribute
208            = dynamic_cast<xercesc::DOMAttr*>(attribute_node);   
209      if (!attribute)
210      {
211        G4Exception("G4GDMLReadMaterials::TRead()", "InvalidRead",
212                    FatalException, "No attribute found!");
213        return value;
214      }
215      const G4String attName = Transcode(attribute->getName());
216      const G4String attValue = Transcode(attribute->getValue());
217
218      if (attName=="value") { value = eval.Evaluate(attValue); } else
219      if (attName=="unit")  { unit = eval.Evaluate(attValue); }
220   }
221
222   return value*unit;
223}
224
225void G4GDMLReadMaterials::
226ElementRead(const xercesc::DOMElement* const elementElement) 
227{
228   G4String name;
229   G4String formula;
230   G4double a = 0.0;
231   G4double Z = 0.0;
232
233   const xercesc::DOMNamedNodeMap* const attributes
234         = elementElement->getAttributes();
235   XMLSize_t attributeCount = attributes->getLength();
236
237   for (XMLSize_t attribute_index=0;
238        attribute_index<attributeCount; attribute_index++)
239   {
240      xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
241
242      if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
243      { continue; }
244
245      const xercesc::DOMAttr* const attribute
246            = dynamic_cast<xercesc::DOMAttr*>(attribute_node);   
247      if (!attribute)
248      {
249        G4Exception("G4GDMLReadMaterials::ElementRead()", "InvalidRead",
250                    FatalException, "No attribute found!");
251        return;
252      }
253      const G4String attName = Transcode(attribute->getName());
254      const G4String attValue = Transcode(attribute->getValue());
255
256      if (attName=="name") { name = GenerateName(attValue); } else
257      if (attName=="formula") { formula = attValue; } else
258      if (attName=="Z") { Z = eval.Evaluate(attValue); }
259   }
260
261   G4int nComponents = 0;
262
263   for (xercesc::DOMNode* iter = elementElement->getFirstChild();
264        iter != 0; iter = iter->getNextSibling())
265   {
266      if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; }
267
268      const xercesc::DOMElement* const child
269            = dynamic_cast<xercesc::DOMElement*>(iter);
270      if (!child)
271      {
272        G4Exception("G4GDMLReadMaterials::ElementRead()", "InvalidRead",
273                    FatalException, "No child found!");
274        return;
275      }
276      const G4String tag = Transcode(child->getTagName());
277
278      if (tag=="atom") { a = AtomRead(child); }  else
279      if (tag=="fraction") { nComponents++; }
280   }
281
282   if (nComponents>0)
283   {
284     MixtureRead(elementElement,
285                 new G4Element(Strip(name),formula,nComponents));
286   }
287   else
288   {
289     new G4Element(Strip(name),formula,Z,a);
290   }
291}
292
293G4double G4GDMLReadMaterials::
294FractionRead(const xercesc::DOMElement* const fractionElement, G4String& ref)
295{
296   G4double n = 0.0;
297
298   const xercesc::DOMNamedNodeMap* const attributes
299         = fractionElement->getAttributes();
300   XMLSize_t attributeCount = attributes->getLength();
301
302   for (XMLSize_t attribute_index=0;
303        attribute_index<attributeCount; attribute_index++)
304   {
305      xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
306
307      if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
308      { continue; }
309
310      const xercesc::DOMAttr* const attribute
311            = dynamic_cast<xercesc::DOMAttr*>(attribute_node);   
312      if (!attribute)
313      {
314        G4Exception("G4GDMLReadMaterials::FractionRead()", "InvalidRead",
315                    FatalException, "No attribute found!");
316        return n;
317      }
318      const G4String attName = Transcode(attribute->getName());
319      const G4String attValue = Transcode(attribute->getValue());
320
321      if (attName=="n")   { n = eval.Evaluate(attValue); } else
322      if (attName=="ref") { ref = attValue; }
323   }
324
325   return n;
326}
327
328void G4GDMLReadMaterials::
329IsotopeRead(const xercesc::DOMElement* const isotopeElement)
330{
331   G4String name;
332   G4int Z = 0;
333   G4int N = 0;
334   G4double a = 0.0;
335
336   const xercesc::DOMNamedNodeMap* const attributes
337         = isotopeElement->getAttributes();
338   XMLSize_t attributeCount = attributes->getLength();
339
340   for (XMLSize_t attribute_index=0;
341        attribute_index<attributeCount;attribute_index++)
342   {
343      xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
344
345      if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
346      { continue; }
347
348      const xercesc::DOMAttr* const attribute
349            = dynamic_cast<xercesc::DOMAttr*>(attribute_node);   
350      if (!attribute)
351      {
352        G4Exception("G4GDMLReadMaterials::IsotopeRead()", "InvalidRead",
353                    FatalException, "No attribute found!");
354        return;
355      }
356      const G4String attName = Transcode(attribute->getName());
357      const G4String attValue = Transcode(attribute->getValue());
358
359      if (attName=="name") { name = GenerateName(attValue); } else
360      if (attName=="Z") { Z = eval.EvaluateInteger(attValue); } else
361      if (attName=="N") { N = eval.EvaluateInteger(attValue); }
362   }
363
364   for (xercesc::DOMNode* iter = isotopeElement->getFirstChild();
365        iter != 0; iter = iter->getNextSibling())
366   {
367      if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; }
368
369      const xercesc::DOMElement* const child
370            = dynamic_cast<xercesc::DOMElement*>(iter);
371      if (!child)
372      {
373        G4Exception("G4GDMLReadMaterials::IsotopeRead()", "InvalidRead",
374                    FatalException, "No child found!");
375        return;
376      }
377      const G4String tag = Transcode(child->getTagName());
378
379      if (tag=="atom")  { a = AtomRead(child); }
380   }
381
382   new G4Isotope(Strip(name),Z,N,a);
383}
384
385void G4GDMLReadMaterials::
386MaterialRead(const xercesc::DOMElement* const materialElement)
387{
388   G4String name;
389   G4double Z = 0.0;
390   G4double a = 0.0;
391   G4double D = 0.0;
392   G4State state = kStateUndefined;
393   G4double T = STP_Temperature;
394   G4double P = STP_Pressure;
395
396   const xercesc::DOMNamedNodeMap* const attributes
397         = materialElement->getAttributes();
398   XMLSize_t attributeCount = attributes->getLength();
399
400   for (XMLSize_t attribute_index=0;
401        attribute_index<attributeCount; attribute_index++)
402   {
403      xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
404
405      if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
406      { continue; }
407
408      const xercesc::DOMAttr* const attribute
409            = dynamic_cast<xercesc::DOMAttr*>(attribute_node);   
410      if (!attribute)
411      {
412        G4Exception("G4GDMLReadMaterials::MaterialRead()", "InvalidRead",
413                    FatalException, "No attribute found!");
414        return;
415      }
416      const G4String attName = Transcode(attribute->getName());
417      const G4String attValue = Transcode(attribute->getValue());
418
419      if (attName=="name") { name = GenerateName(attValue); } else
420      if (attName=="Z") { Z = eval.Evaluate(attValue); } else
421      if (attName=="state")
422      {
423         if (attValue=="solid")  { state = kStateSolid;  } else
424         if (attValue=="liquid") { state = kStateLiquid; } else
425         if (attValue=="gas")    { state = kStateGas; }
426      }
427   }
428
429   size_t nComponents = 0;
430
431   for (xercesc::DOMNode* iter = materialElement->getFirstChild();
432        iter != 0; iter = iter->getNextSibling())
433   {
434      if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; }
435
436      const xercesc::DOMElement* const child
437            = dynamic_cast<xercesc::DOMElement*>(iter);
438      if (!child)
439      {
440        G4Exception("G4GDMLReadMaterials::MaterialRead()", "InvalidRead",
441                    FatalException, "No child found!");
442        return;
443      }
444      const G4String tag = Transcode(child->getTagName());
445
446      if (tag=="atom") { a = AtomRead(child); } else
447      if (tag=="Dref") { D = GetQuantity(GenerateName(RefRead(child))); } else
448      if (tag=="Pref") { P = GetQuantity(GenerateName(RefRead(child))); } else
449      if (tag=="Tref") { T = GetQuantity(GenerateName(RefRead(child))); } else
450      if (tag=="D") { D = DRead(child); } else
451      if (tag=="P") { P = PRead(child); } else
452      if (tag=="T") { T = TRead(child); } else
453      if (tag=="fraction" || tag=="composite")  { nComponents++; }
454   }
455
456   G4Material* material =  0;
457
458   if (nComponents==0)
459   {
460     material = new G4Material(Strip(name),Z,a,D,state,T,P);
461   }
462   else
463   {
464     material = new G4Material(Strip(name),D,nComponents,state,T,P);
465     MixtureRead(materialElement, material);
466   }
467
468   for (xercesc::DOMNode* iter = materialElement->getFirstChild();
469        iter != 0; iter = iter->getNextSibling())
470   {
471      if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; }
472
473      const xercesc::DOMElement* const child
474            = dynamic_cast<xercesc::DOMElement*>(iter);
475      if (!child)
476      {
477        G4Exception("G4GDMLReadMaterials::MaterialRead()", "InvalidRead",
478                    FatalException, "No child found!");
479        return;
480      }
481      const G4String tag = Transcode(child->getTagName());
482
483      if (tag=="property") { PropertyRead(child,material); }
484   }
485}
486
487void G4GDMLReadMaterials::
488MixtureRead(const xercesc::DOMElement *const mixtureElement, G4Element *element)
489{
490   for (xercesc::DOMNode* iter = mixtureElement->getFirstChild();
491        iter != 0; iter = iter->getNextSibling())
492   {
493      if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; }
494
495      const xercesc::DOMElement* const child
496            = dynamic_cast<xercesc::DOMElement*>(iter);
497      if (!child)
498      {
499        G4Exception("G4GDMLReadMaterials::MixtureRead()", "InvalidRead",
500                    FatalException, "No child found!");
501        return;
502      }
503      const G4String tag = Transcode(child->getTagName());
504
505      if (tag=="fraction")
506      {
507         G4String ref;
508         G4double n = FractionRead(child,ref);
509         element->AddIsotope(GetIsotope(GenerateName(ref,true)),n);
510      }
511   }
512}
513
514void G4GDMLReadMaterials::
515MixtureRead(const xercesc::DOMElement *const mixtureElement,
516            G4Material *material)
517{
518   for (xercesc::DOMNode* iter = mixtureElement->getFirstChild();
519        iter != 0; iter = iter->getNextSibling())
520   {
521      if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; }
522
523      const xercesc::DOMElement* const child
524            = dynamic_cast<xercesc::DOMElement*>(iter);
525      if (!child)
526      {
527        G4Exception("G4GDMLReadMaterials::MixtureRead()", "InvalidRead",
528                    FatalException, "No child found!");
529        return;
530      }
531      const G4String tag = Transcode(child->getTagName());
532
533      if (tag=="fraction")
534      {
535         G4String ref;
536         G4double n = FractionRead(child,ref);
537         
538         G4Material *materialPtr = GetMaterial(GenerateName(ref,true), false);
539         G4Element *elementPtr = GetElement(GenerateName(ref,true), false);
540
541         if (materialPtr != 0) { material->AddMaterial(materialPtr,n); } else
542         if (elementPtr != 0)  { material->AddElement(elementPtr,n); }
543
544         if ((materialPtr == 0) && (elementPtr == 0))
545         {
546            G4String error_msg = "Referenced material/element '"
547                               + GenerateName(ref,true) + "' was not found!";
548            G4Exception("G4GDMLReadMaterials::MixtureRead()", "InvalidSetup",
549                        FatalException, error_msg);   
550         }
551      } 
552      else if (tag=="composite")
553      {
554         G4String ref;
555         G4int n = CompositeRead(child,ref);
556
557         G4Element *elementPtr = GetElement(GenerateName(ref,true));
558         material->AddElement(elementPtr,n);
559      }
560   }
561}
562
563void G4GDMLReadMaterials::
564PropertyRead(const xercesc::DOMElement* const propertyElement,
565             G4Material* material)
566{
567   G4String name;
568   G4String ref;
569   G4GDMLMatrix matrix;
570
571   const xercesc::DOMNamedNodeMap* const attributes
572         = propertyElement->getAttributes();
573   XMLSize_t attributeCount = attributes->getLength();
574
575   for (XMLSize_t attribute_index=0;
576        attribute_index<attributeCount; attribute_index++)
577   {
578      xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
579
580      if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
581      { continue; }
582
583      const xercesc::DOMAttr* const attribute
584            = dynamic_cast<xercesc::DOMAttr*>(attribute_node);   
585      if (!attribute)
586      {
587        G4Exception("G4GDMLReadMaterials::PropertyRead()", "InvalidRead",
588                    FatalException, "No attribute found!");
589        return;
590      }
591      const G4String attName = Transcode(attribute->getName());
592      const G4String attValue = Transcode(attribute->getValue());
593
594      if (attName=="name") { name = GenerateName(attValue); } else
595      if (attName=="ref")  { matrix = GetMatrix(ref=attValue); }
596   }
597
598   if (matrix.GetCols() != 2)
599   {
600     G4String error_msg = "Referenced matrix '" + ref
601            + "' should have \n two columns as a property table for material: "
602            + material->GetName();
603     G4Exception("G4GDMLReadMaterials::PropertyRead()", "InvalidRead",
604                 FatalException, error_msg);
605   }
606   if (matrix.GetRows() == 0) { return; }
607
608   G4MaterialPropertiesTable* matprop=material->GetMaterialPropertiesTable();
609   if (!matprop)
610   {
611     matprop = new G4MaterialPropertiesTable();
612     material->SetMaterialPropertiesTable(matprop);
613   }
614   if (matrix.GetCols() == 1)  // constant property assumed
615   {
616     matprop->AddConstProperty(Strip(name), matrix.Get(0,0));
617   }
618   else  // build the material properties vector
619   {
620     G4MaterialPropertyVector* propvect = new G4MaterialPropertyVector(0,0,0);
621     for (size_t i=0; i<matrix.GetRows(); i++)
622     {
623       propvect->AddElement(matrix.Get(i,0),matrix.Get(i,1));
624     }
625     matprop->AddProperty(Strip(name),propvect);
626   }
627}
628
629void G4GDMLReadMaterials::
630MaterialsRead(const xercesc::DOMElement* const materialsElement)
631{
632   G4cout << "G4GDML: Reading materials..." << G4endl;
633
634   for (xercesc::DOMNode* iter = materialsElement->getFirstChild();
635        iter != 0; iter = iter->getNextSibling())
636   {
637      if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; }
638
639      const xercesc::DOMElement* const child
640            = dynamic_cast<xercesc::DOMElement*>(iter);
641      if (!child)
642      {
643        G4Exception("G4GDMLReadMaterials::MaterialsRead()", "InvalidRead",
644                    FatalException, "No child found!");
645        return;
646      }
647      const G4String tag = Transcode(child->getTagName());
648     
649      if (tag=="define")   { DefineRead(child);  }  else 
650      if (tag=="element")  { ElementRead(child); }  else 
651      if (tag=="isotope")  { IsotopeRead(child); }  else 
652      if (tag=="material") { MaterialRead(child); }
653      else
654      {
655        G4String error_msg = "Unknown tag in materials: " + tag;
656        G4Exception("G4GDMLReadMaterials::MaterialsRead()", "InvalidSetup",
657                    FatalException, error_msg);
658      }
659   }
660}
661
662G4Element* G4GDMLReadMaterials::
663GetElement(const G4String& ref, G4bool verbose) const
664{
665   G4Element* elementPtr = G4Element::GetElement(ref,false);
666
667   if (!elementPtr)
668   {
669     elementPtr = G4NistManager::Instance()->FindOrBuildElement(ref);
670   }
671
672   if (verbose && !elementPtr)
673   {
674     G4String error_msg = "Referenced element '" + ref + "' was not found!";
675     G4Exception("G4GDMLReadMaterials::GetElement()", "InvalidRead",
676                 FatalException, error_msg);
677   }
678
679   return elementPtr;
680}
681
682G4Isotope* G4GDMLReadMaterials::GetIsotope(const G4String& ref,
683                                           G4bool verbose) const
684{
685   G4Isotope* isotopePtr = G4Isotope::GetIsotope(ref,false);
686
687   if (verbose && !isotopePtr)
688   {
689     G4String error_msg = "Referenced isotope '" + ref + "' was not found!";
690     G4Exception("G4GDMLReadMaterials::GetIsotope()", "InvalidRead",
691                 FatalException, error_msg);
692   }
693
694   return isotopePtr;
695}
696
697G4Material* G4GDMLReadMaterials::GetMaterial(const G4String& ref,
698                                             G4bool verbose) const
699{
700   G4Material *materialPtr = G4Material::GetMaterial(ref,false);
701
702   if (!materialPtr)
703   {
704     materialPtr = G4NistManager::Instance()->FindOrBuildMaterial(ref);
705   }
706
707   if (verbose && !materialPtr)
708   {
709     G4String error_msg = "Referenced material '" + ref + "' was not found!";
710     G4Exception("G4GDMLReadMaterials::GetMaterial()", "InvalidRead",
711                 FatalException, error_msg);
712   }
713
714   return materialPtr;
715}
Note: See TracBrowser for help on using the repository browser.