GEAR  1.9.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Friends Pages
RectangularPadRowLayoutXML.cc
1 #include "gearxml/RectangularPadRowLayoutXML.h"
2 
3 #include "gearxml/XMLHandler.h"
4 
5 #include "gearxml/tinyxml.h"
6 #include "gearimpl/RectangularPadRowLayout.h"
7 #include "gear/GearMgr.h"
8 
9 namespace gear {
10 
11 
13 
14  // Check if type is RectangularPadRowLayout
15 
16  const RectangularPadRowLayout* rectangularPadLayout=dynamic_cast<const RectangularPadRowLayout*>(layout);
17 
18  if (rectangularPadLayout==NULL) {
19 
20  throw ParseException("RectangularPadRowLayoutXML::toXML wrong type !");
21  }
22 
23  // append data to PadRowLayout2D
24  TiXmlElement padRowLayout2DXML("PadRowLayout2D");
25 
26  padRowLayout2DXML.SetAttribute("type","RectangularPadRowLayout");
27 
28  padRowLayout2DXML.SetDoubleAttribute( "xMin", rectangularPadLayout->getPlaneExtent()[0] );
29  padRowLayout2DXML.SetDoubleAttribute( "xMax", rectangularPadLayout->getPlaneExtent()[1] );
30  padRowLayout2DXML.SetDoubleAttribute( "yMin", rectangularPadLayout->getPlaneExtent()[2] );
31 
32  int repeatRowCount = rectangularPadLayout->getRepeatRowCount() ;
33 
34  if( repeatRowCount > 1 )
35  padRowLayout2DXML.SetDoubleAttribute( "RepeatRows", repeatRowCount );
36 
37 
38  const std::vector<unsigned>& rowNumbers = rectangularPadLayout->equalRowNumbers() ;
39  int theRow = 0 ;
40 
41  int rowNum = rowNumbers.size() ;
42 
43  if( repeatRowCount > 1 )
44  rowNum /= repeatRowCount ;
45 
46 
47 
48  for(int i=0 ; i< rowNum ; ++i){
49 
50  TiXmlElement rowElement("row");
51 
52  const RectangularPadRowLayout::Row& row = rectangularPadLayout->rows()[ theRow ] ;
53 
54  int nRow = rowNumbers[i] ;
55 
56  if( nRow > 1 )
57  rowElement.SetAttribute("repeat", nRow) ;
58 
59  rowElement.SetAttribute("nPad", row.NPad ) ;
60 
61  rowElement.SetDoubleAttribute("padWidth" , row.PadWidth ) ;
62  rowElement.SetDoubleAttribute("padHeight" , row.PadHeight ) ;
63  rowElement.SetDoubleAttribute("rowHeight" , row.Height ) ;
64  rowElement.SetDoubleAttribute("leftOffset" , row.LeftOffset ) ;
65  rowElement.SetDoubleAttribute("rightOffset" , row.RightOffset ) ;
66 
67  padRowLayout2DXML.InsertEndChild( rowElement ) ;
68 
69  theRow += nRow ;
70  }
71 
72  return padRowLayout2DXML ;
73  }
74 
75 
77 
78 
79  double xMin = atof( getXMLAttribute( xmlElement , "xMin" ) .c_str() ) ;
80  double xMax = atof( getXMLAttribute( xmlElement , "xMax" ) .c_str() ) ;
81  double yMin = atof( getXMLAttribute( xmlElement , "yMin" ) .c_str() ) ;
82 
83  int repeatRowCount = atoi( getOptionalXMLAttribute( xmlElement , "repeatRows" , "1" ) .c_str() ) ;
84 
85  RectangularPadRowLayout* padRowLayout = new RectangularPadRowLayout( xMin, xMax, yMin ) ;
86 
87  // ----- rows ------------
88  int rowId = 0 ;
89 
90  const TiXmlNode* row = 0 ;
91  while( ( row = xmlElement->IterateChildren( "row", row ) ) != 0 ){
92 
93  int nRow = atoi( getOptionalXMLAttribute( row , "repeat" , "1" ) .c_str() ) ;
94 
95  int nPad = atoi( getXMLAttribute( row , "nPad" ) .c_str() ) ;
96 
97  double padWidth = atof( getXMLAttribute( row , "padWidth" ) .c_str() ) ;
98  double padHeight = atof( getXMLAttribute( row , "padHeight" ) .c_str() ) ;
99 
100  double rowHeight = atof( getOptionalXMLAttribute( row , "rowHeight" , "0.0" ).c_str() ) ;
101  double leftOffset = atof( getOptionalXMLAttribute( row , "leftOffset" , "0.0" ).c_str() ) ;
102  double rightOffset = atof( getOptionalXMLAttribute( row , "rightOffset", "0.0" ).c_str() ) ;
103 
104  padRowLayout->addRow( nRow, nPad, padWidth, padHeight, rowHeight, leftOffset, rightOffset ) ;
105 
106  rowId+= nRow ;
107  }
108 
109  padRowLayout->repeatRows( repeatRowCount ) ;
110 
111  return padRowLayout ;
112  }
113 
114 }
115 
int getRepeatRowCount() const
Returns the number number for which a given row pattern has been repaeted.
virtual PadRowLayout2D * fromXML(const TiXmlElement *xmlElement) const
Creates the appropriate PadRowLayout2D subclass from the given XML element (node) ...
const std::vector< Row > & rows() const
Helper method with all row data.
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 TiXmlElement toXML(const PadRowLayout2D *layout) const
Creates an XML node for the given PadRowLayout2D.
const std::vector< unsigned > & equalRowNumbers() const
Helper method to identify equal row numbers in this layout (as they have been added).
The parent class for everything in the Document Object Model.
Definition: tinyxml.h:370
virtual void addRow(int nRow, int nPad, double padWidth, double padHeight, double rowHeight=0.0, double leftOffset=0.0, double rightOffset=0.0)
Add nRow rows with the given parameters.
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
virtual const std::vector< double > & getPlaneExtent() const
Extent of the sensitive plane - [xmin,xmax,ymin,ymax] CARTESIAN or [rmin,rmax,phimin,phimax] POLAR.
virtual void repeatRows(unsigned count)
Repeat the current rows &#39;count&#39; times - this allows to easily repeat a pattern of several rows...
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 rectangular row based layout where all pads in a given row are...
Internal helper class for RectangularPadRowLayout.