TupleCutXML.cxx
Go to the documentation of this file.
1 
12 // for iterator member defect
13 #ifdef _MSC_VER
14 #include "msdevstudio/MSconfig.h"
15 #endif
16 
17 #include "TupleCutXML.h"
18 
19 #include "XmlController.h"
20 #include "XmlDocument.h"
21 #include "XmlElement.h"
22 
23 #include "datasrcs//TupleCut.h"
24 
25 #include <cassert>
26 
27 using namespace hippodraw;
28 
30  : BaseXML ( "TupleCut", controller ),
31  m_low ( "low" ),
32  m_high ( "high" ),
33  m_invert ( "invert" ),
34  m_column ( "column" ),
35  m_dim ( "dimension" ),
36  m_axis ( "axis" )
37 {
38 }
39 
40 XmlElement *
42 createElement ( unsigned int i, const TupleCut & cut )
43 {
45 
46  const void * addr = reinterpret_cast < const void * > ( & cut );
47  int id = m_controller -> getId ( addr );
48  setId ( *tag, id );
49 
50  tag -> setAttribute ( m_dim, -1 ); // to flag not obsolete TupleCut
51  XmlElement * element
52  = XmlController::m_xml_doc -> createElement ( "TupleCutAxis" );
53  element -> setAttribute ( m_axis, i );
54 
55  int tmp = cut.getInversion () ? 1 : 0;
56  element -> setAttribute ( m_invert, tmp );
57 
58  const Range & range = cut.getRange ();
59  element -> setAttribute ( m_low, range.low() );
60  element -> setAttribute ( m_high, range.high() );
61 
62  int col = cut.getColumn ( );
63  element -> setAttribute ( m_column, col );
64 
65  tag -> appendChild ( *element );
66  delete element;
67 
68  return tag;
69 }
70 
72 {
73  TupleCut * cut = 0; // will create one of correct dim in function below
74  setAttributes ( cut, &tag );
75 
76  return cut;
77 }
78 
81 void
85  const XmlElement * element ) const
86 {
87  int value;
88  bool ok = element->attribute ( m_invert, value );
89  if ( ok && ( value == 1 ) ) cut -> setInversion( true );
90 
91  double low = 0.0;
92  ok = element->attribute( m_low, low );
93  double high = 0.0;
94  ok = element->attribute( m_high, high );
95 
96  Range range ( low, high );
97 
98  cut->setRange( range );
99 
100  int col = -2;
101  ok = element->attribute ( m_column, col );
102  cut->setColumn( col );
103 }
104 
105 bool
107 hasMultiDimTupleCut ( const XmlElement * element ) const
108 {
109  bool yes = true;
110  int dim;
111  bool ok = element -> attribute ( m_dim, dim );
112  if ( ok && dim < 0 ) yes = false;
113 
114  return yes;
115 }
116 
117 void
119 getObjects ( const XmlElement * element, std::vector <TupleCut * > & cuts )
120 {
121  int dim;
122  bool ok = element -> attribute ( m_dim, dim );
123  if ( ! ok ) { // very old documents forgot the Y axis
124  TupleCut * cut = new TupleCut ();
125  setAxisAttributes ( cut, Axes::X, element );
126  cuts.push_back ( cut );
127  }
128  else { // multidemension style
129  XmlElement::NodeList_t nodelist;
130  element -> fillNodeList ( "TupleCutAxis", nodelist );
131  assert ( nodelist.empty () == false );
132  XmlElement::NodeList_t::const_iterator first = nodelist.begin();
133 
134  while ( first != nodelist.end() ) {
135  XmlElement * node = *first++;
136  int axis;
137  bool ok = node -> attribute ( m_axis, axis );
138  assert ( ok );
139  Axes::Type axis_t = axis == 0 ? Axes::X : Axes::Y;
140  TupleCut * cut = new TupleCut ();
141  setAxisAttributes ( cut, axis_t, node );
142  cuts.push_back ( cut );
143  }
144  }
145 }
146 
148  const XmlElement * element ) const
149 {
150  int dim;
151  bool ok = element->attribute ( m_dim, dim );
152 
153  if ( ! ok ) { // older documents forgot Y axis
154  cut = new TupleCut ();
155  setAxisAttributes ( cut, Axes::X, element );
156  }
157  else { // new style
158  cut = new TupleCut ( );
159  XmlElement::NodeList_t nodelist;
160  element -> fillNodeList ( "TupleCutAxis", nodelist );
161  assert ( nodelist.empty () == false );
162  XmlElement::NodeList_t::const_iterator first = nodelist.begin();
163 
164  while ( first != nodelist.end() ) {
165  XmlElement * node = *first++;
166  int axis;
167  bool ok = node -> attribute ( m_axis, axis );
168  assert ( ok );
169  Axes::Type axis_t = axis == 0 ? Axes::X : Axes::Y;
170  setAxisAttributes ( cut, axis_t, node );
171  }
172  }
173 }
XmlElement * createElement()
Creates a new element node.
Definition: BaseXML.cxx:43
unsigned int i
double high() const
Returns the maximum of the range object.
Definition: Range.cxx:100
virtual bool attribute(const std::string &name, bool &value) const =0
Sets value to the attribute name&#39;s value.
TupleCutXML class interface.
XmlDocument class interface.
void setRange(const Range &range)
Sets the range of the cut.
Definition: TupleCut.cxx:77
XmlController class interface.
void setAttributes(TupleCut *&cut, const XmlElement *element) const
Sets the attributes of the TupleCut object plotter from the information in the XmlElement element...
std::string m_column
The column index attribute name.
Definition: TupleCutXML.h:50
TupleCut * getObject(const XmlElement &tag) const
Creates an TupleCut object and sets its properties from the XmlElement.
Definition: TupleCutXML.cxx:71
A pure virtual base class of XML element wrapper.
Definition: XmlElement.h:30
void fillNodeList(const XmlElement *element, std::list< XmlElement * > &nodelist)
Fills the nodelist with immediate child nodes of element with nodes that can be handled by this objec...
Definition: BaseXML.cxx:58
The class expresses a cut on a DataSource, i.e.
Definition: TupleCut.h:43
return yes
Definition: CanvasView.cxx:883
void setId(XmlElement &tag, int id)
Sets the unique identification of the object.
Definition: BaseXML.cxx:64
void getObjects(const XmlElement *element, std::vector< TupleCut * > &cuts)
Creates TupleCut objects from old style multidimensional TupleCut.
bool ok
Definition: CanvasView.cxx:163
unsigned int getColumn() const
Returns the column index used in the DataSource.
Definition: TupleCut.cxx:70
std::list< XmlElement * > NodeList_t
The type of container used to store XmlElement nodes.
Definition: XmlElement.h:47
std::string m_invert
The inversion attribute name.
Definition: TupleCutXML.h:47
bool hasMultiDimTupleCut(const XmlElement *element) const
Returns true if element contains old style NTuple, i.e.
XmlController * m_controller
The singleton XML controller object.
Definition: BaseXML.h:60
XmlElement class interface.
std::string m_low
The low end of Range attribute name.
Definition: TupleCutXML.h:41
void setAxisAttributes(TupleCut *cut, hippodraw::Axes::Type axis, const XmlElement *element) const
Sets the attributes for each axis of the TupleCut.
Definition: TupleCutXML.cxx:83
hippodraw::TupleCut class interface
static XmlDocument * m_xml_doc
The current document being generated or read.
std::string m_dim
The number of dimension attribute name.
Definition: TupleCutXML.h:58
std::string m_axis
The axis attribute name.
Definition: TupleCutXML.h:62
A base class of XML element controllers.
Definition: BaseXML.h:35
double low() const
Returns the minimum of the range object.
Definition: Range.cxx:87
TupleCutXML(const TupleCutXML &)
A private copy constructor in order to avoid copying.
const Range & getRange() const
Returns a reference to the range for each dimension.
Definition: TupleCut.cxx:84
Expresses a range of values.
Definition: Range.h:33
std::string m_high
The high end of Range attribute name.
Definition: TupleCutXML.h:44
A base class that is the interface between GUI and the XML serialization and deserialization.
Definition: XmlController.h:53
bool getInversion() const
Returns the state of the inversion for the axis.
Definition: TupleCut.cxx:98
Type
Axes constants.
Definition: AxesType.h:31
void setColumn(unsigned int col)
Sets the column in the DataSource to be used.
Definition: TupleCut.cxx:63

Generated for HippoDraw Class Library by doxygen