GEAR  1.9.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Friends Pages
VersatileDiskRowLayoutXML.cc
1 #include "gearxml/VersatileDiskRowLayoutXML.h"
2 
3 #include "gearxml/XMLHandler.h"
4 // #include "gearxml/GearParametersXML.h"
5 
6 #include "gearxml/tinyxml.h"
7 #include "gearimpl/VersatileDiskRowLayout.h"
8 #include "gear/GearMgr.h"
9 
10 // #include <vector>
11 // #include <algorithm>
12 // #include <sstream>
13 
14 namespace gear {
15 
16 
18 
19  // Check if type is VersatileDiskRowLayout
20 
21  const VersatileDiskRowLayout* padLayout=dynamic_cast<const VersatileDiskRowLayout*>(layout);
22 
23  if (padLayout==NULL) {
24 
25  throw ParseException("VersatileDiskRowLayoutXML::toXML wrong type !");
26  }
27 
28  // append data to PadRowLayout2D
29  TiXmlElement padRowLayout2DXML("PadRowLayout2D");
30 
31  padRowLayout2DXML.SetAttribute("type","VersatileDiskRowLayout");
32 
33  padRowLayout2DXML.SetDoubleAttribute("rMin",(padLayout->getPlaneExtent())[0]);
34 
35  for (std::vector<VersatileDiskRowLayout::Row>::const_iterator rowIter = padLayout->rows().begin();
36  rowIter < padLayout->rows().end(); rowIter ++)
37  {
38  TiXmlElement rowElement("row");
39 
40  rowElement.SetAttribute("nPad", rowIter->getNPads() ) ;
41  rowElement.SetDoubleAttribute("padPitch", rowIter->getPadPitch() ) ;
42  rowElement.SetDoubleAttribute("padPitch", rowIter->getPadPitch() ) ;
43  rowElement.SetDoubleAttribute("rowHeight", rowIter->getRowHeight() ) ;
44  rowElement.SetDoubleAttribute("padWidth", rowIter->getPadWidth() ) ;
45  rowElement.SetDoubleAttribute("padHeight", rowIter->getPadHeight() ) ;
46  rowElement.SetDoubleAttribute("offset", rowIter->getOffset() ) ;
47 
48  padRowLayout2DXML.InsertEndChild( rowElement ) ;
49  }
50 
51  return padRowLayout2DXML ;
52  }
53 
54 
56 
57  double rMin = atof( getXMLAttribute( xmlLayout , "rMin" ) .c_str() ) ;
58 
59  VersatileDiskRowLayout * padLayout = new VersatileDiskRowLayout( rMin );
60 
61  const TiXmlNode* xmlRow = 0 ;
62  while( ( xmlRow = xmlLayout->IterateChildren( "row", xmlRow ) ) != 0 ){
63 
64  int nPad = atoi( getXMLAttribute( xmlRow , "nPad" ) .c_str() ) ;
65  double padPitch = atof( getXMLAttribute( xmlRow, "padPitch" ) .c_str() ) ;
66  double rowHeight = atof( getXMLAttribute( xmlRow , "rowHeight" ) .c_str() ) ;
67 
68  double padWidth = atof( getOptionalXMLAttribute( xmlRow , "padWidtht" , "0.0" ).c_str() ) ;
69  double padHeight = atof( getOptionalXMLAttribute( xmlRow , "padHeight" , "0.0" ).c_str() ) ;
70  double offset = atof( getOptionalXMLAttribute( xmlRow , "offset" , "0.0" ).c_str() ) ;
71  int repeat = atoi( getOptionalXMLAttribute( xmlRow , "repeat" , "1" ).c_str() ) ;
72 
73  padLayout->addRow( nPad, padPitch, rowHeight, offset, padWidth, padHeight, repeat );
74  }
75 
76  return padLayout;
77  }
78 
79 }
80 
Abstract description of a planar subdetector with pads (cells) that are positioned in rows (circular ...
std::string getOptionalXMLAttribute(const TiXmlNode *node, const std::string &name, const std::string &defaultValue)
Helper method used for parsing XML.
virtual PadRowLayout2D * fromXML(const TiXmlElement *xmlElement) const
Creates the appropriate PadRowLayout2D subclass from the given XML element (node) ...
virtual const std::vector< double > & getPlaneExtent() const
Extent of the sensitive plane - [xmin,xmax,ymin,ymax] CARTESIAN or [rmin,rmax,phimin,phimax] POLAR.
const std::vector< Row > & rows() const
Get access to the individual rows.
virtual TiXmlElement toXML(const PadRowLayout2D *layout) const
Creates an XML node for the given PadRowLayout2D.
virtual void addRow(int nPads, double padPitch, double rowHeight, double offset=0., double padWidth=0., double padHeight=0., int repeat=1)
Add &#39;repeat&#39; rows with the given parameters.
The parent class for everything in the Document Object Model.
Definition: tinyxml.h:370
ParseException used for parse errors, e.g.
Definition: GEAR.h:65
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
TiXmlNode * InsertEndChild(const TiXmlNode &addThis)
Add a new node related to this.
Definition: tinyxml.cc:218
void SetDoubleAttribute(const char *name, double value)
Sets an attribute of name to a given value.
Definition: tinyxml.cc:738
const TiXmlNode * IterateChildren(const TiXmlNode *previous) const
An alternate way to walk the children of a node.
Definition: tinyxml.cc:376
void SetAttribute(const char *name, const char *value)
Sets an attribute of name to a given value.
Definition: tinyxml.cc:746
Implementation of PadRowLayout2D for a wedge shaped module.