GEAR  1.9.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Friends Pages
ConstantBFieldXML.cc
1 #include "gearxml/ConstantBFieldXML.h"
2 
3 #include "gearxml/XMLHandlerMgr.h"
4 #include "gearxml/GearParametersXML.h"
5 
6 #include "gearxml/tinyxml.h"
7 #include "gearimpl/ConstantBField.h"
8 // #include "gear/LayerLayout.h"
9 #include "gear/GearMgr.h"
10 
11 
12 namespace gear {
13 
14 
16 
17  const ConstantBField* param = dynamic_cast<const ConstantBField*> ( &parameters );
18 
19  if( param == 0 ) {
20 
21  throw Exception( "ConstantBFieldXML::toXML given parmeters not of correct type. "
22  "needs to be gear::ConstantBField." );
23  }
24 
25  TiXmlElement field("BField");
26 
27  field.SetAttribute("type","ConstantBField") ;
28 
29  Vector3D b = param->at( Vector3D( 0.,0.,0. ) ) ;
30 
31  field.SetDoubleAttribute("x", b.x() ) ;
32  field.SetDoubleAttribute("y", b.y() ) ;
33  field.SetDoubleAttribute("z", b.z() ) ;
34 
35  // Write all other parameters
36  GearParametersXML::getXMLForParameters( &field , param ) ;
37 
38  return field ;
39  }
40 
41  GearParameters* ConstantBFieldXML::fromXML( const TiXmlElement* xmlElement, GearMgr* gearMgr) const {
42 
43  double bx = atof( getXMLAttribute( xmlElement , "x" ) .c_str() ) ;
44  double by = atof( getXMLAttribute( xmlElement , "y" ) .c_str() ) ;
45  double bz = atof( getXMLAttribute( xmlElement , "z" ) .c_str() ) ;
46 
47  ConstantBField* bfield = new ConstantBField( Vector3D( bx, by, bz) ) ;
48 
49  // now we can read the generic parameters
50  GearParametersXML::setParametersFromXML( xmlElement, bfield ) ;
51 
52 
53  //--------- add to proper section in GearMgr ----
54  if( gearMgr != 0 ) {
55 
56  gearMgr->setBField( bfield ) ;
57 
58  }
59 
60  return bfield ;
61  }
62 
63 
64 
65 } // namespace
virtual GearParameters * fromXML(const TiXmlElement *xmlElement, GearMgr *gearMgr=0) const
Creates the appropriate GearParameters subclass from the given XML element (node) ...
virtual void setBField(BField *bField)=0
Set the BField.
Base exception class for GEAR - all other exceptions extend this.
Definition: GEAR.h:41
static void setParametersFromXML(const TiXmlElement *xmlElement, GearParametersImpl *gearParams)
Static helper function that can be used by other subclass handlers to read parameters.
Abstract interface for a set of parameters that can be used to describe the geometrical properties of...
Simple three dimensional vector providing the components for cartesian, cylindrical and spherical coo...
Definition: Vector3D.h:18
static void getXMLForParameters(TiXmlElement *xmlElement, const GearParameters *gearParams)
Static helper function that can be used by other subclass handlers to create XML for parameters...
double x() const
Cartesian x coordinate.
Definition: Vector3D.h:56
double y() const
Cartesian y coordinate.
Definition: Vector3D.h:59
double z()
Cartesian cartesian z coordinate.
Definition: Vector3D.h:62
std::string getXMLAttribute(const TiXmlNode *node, const std::string &name)
Helper method used for parsing XML.
Global B field map implementation with constant field.
The element is a container class.
Definition: tinyxml.h:827
void SetDoubleAttribute(const char *name, double value)
Sets an attribute of name to a given value.
Definition: tinyxml.cc:738
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 Vector3D at(Vector3D) const
Returns the B field vector in Tesla at given point.
virtual TiXmlElement toXML(const GearParameters &parameters) const
Creates an XML node for the given parameters.