GEAR  1.9.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Friends Pages
SimpleMaterialXML.cc
1 #include "gearxml/SimpleMaterialXML.h"
2 
3 #include "gear/GearMgr.h"
4 #include "gearimpl/SimpleMaterialImpl.h"
5 
6 #include "gearxml/tinyxml.h"
7 #include "gearxml/XMLHandler.h"
8 
9 #include <string>
10 #include <sstream>
11 
12 namespace gear {
13 
15 
16  //std::cout << "SimpleMaterial::toXML called" << std::endl ; //debug
17 
18  TiXmlElement matElem("material") ;
19 
20  matElem.SetAttribute( "name", material.getName() ) ;
21  matElem.SetDoubleAttribute( "A", material.getA() ) ;
22  matElem.SetDoubleAttribute( "Z", material.getZ() ) ;
23  matElem.SetDoubleAttribute( "density", material.getDensity() ) ;
24  matElem.SetDoubleAttribute( "radLength", material.getRadLength() ) ;
25  matElem.SetDoubleAttribute( "intLength", material.getIntLength() ) ;
26 
27  return matElem ;
28  }
29 
30 
31 
32  SimpleMaterial* SimpleMaterialXML::fromXML( const TiXmlElement* xmlElement, GearMgr* gearMgr) const {
33 
34 
35 
36  std::string name = getXMLAttribute( xmlElement , "name" ) ;
37 
38 
39  //std::cout << " SimpleMaterialXML::fromXML( " << name << " ... ) " << std::endl ;
40 
41  std::stringstream ss ;
42  double dummy ;
43 
44  ss << getXMLAttribute( xmlElement , "A" ) ; ss >> dummy ; ss.clear() ;
45  double A = dummy ;
46 
47  ss << getXMLAttribute( xmlElement , "Z" ) ; ss >> dummy ; ss.clear() ;
48  double Z = dummy ;
49 
50  ss << getXMLAttribute( xmlElement , "density" ) ; ss >> dummy ; ss.clear() ;
51  double d = dummy ;
52 
53  ss << getXMLAttribute( xmlElement , "radLength" ) ; ss >> dummy ; ss.clear() ;
54  double rL = dummy ;
55 
56  ss << getXMLAttribute( xmlElement , "intLength" ) ; ss >> dummy ; ss.clear() ;
57  double iL = dummy ;
58 
59  SimpleMaterialImpl* sm = new SimpleMaterialImpl( name , A , Z , d , rL , iL ) ;
60 
61  //--------- add to proper section in GearMgr ----
62  if( gearMgr != 0 ) {
63 
64  gearMgr->registerSimpleMaterial( sm ) ;
65  }
66 
67  return sm ;
68 
69  } // fromXML
70 
71 } // namespace
72 
73 
virtual double getA() const =0
The mass number of the (averaged) material.
Abstract interface for a simple material description tjhat hold s the following properties: A...
virtual double getIntLength() const =0
Interaction length of material in mm.
virtual double getRadLength() const =0
Radiation length of material in mm.
virtual void registerSimpleMaterial(const SimpleMaterial *material)=0
Register the SimpleMaterial with SimpleMaterial::getName() - throws Exception if a material of the gi...
virtual const std::string & getName() const =0
The material name.
std::string getXMLAttribute(const TiXmlNode *node, const std::string &name)
Helper method used for parsing XML.
The element is a container class.
Definition: tinyxml.h:827
virtual SimpleMaterial * fromXML(const TiXmlElement *xmlElement, GearMgr *gearMgr=0) const
Creates a SimpleMaterial from the XML element (node)
virtual double getZ() const =0
The atomic number of the (averaged) material.
void SetDoubleAttribute(const char *name, double value)
Sets an attribute of name to a given value.
Definition: tinyxml.cc:738
virtual TiXmlElement toXML(const SimpleMaterial &material) const
Creates an XML node for the given material.
Abstract interface for a manager class that returns the Gear classes for the relevant subdetectors...
Definition: GearMgr.h:36
void SetAttribute(const char *name, const char *value)
Sets an attribute of name to a given value.
Definition: tinyxml.cc:746
virtual double getDensity() const =0
Density in kg/m^3.
Implementation of gear::SimpleMaterial.