DataRepXML.cxx
Go to the documentation of this file.
1 
12 // for truncation warning
13 #ifdef _MSC_VER
14 #include "msdevstudio/MSconfig.h"
15 #endif
16 
17 #include "DataRepXML.h"
18 
19 #include "BinningProjectorXML.h"
20 #include "NTupleProjectorXML.h"
21 #include "FunctionProjectorXML.h"
22 #include "MapMatrixProjectorXML.h"
23 #include "PointRepXML.h"
24 #include "XmlController.h"
25 #include "XmlDocument.h"
26 #include "XmlElement.h"
27 
30 
32 #include "datareps/FunctionRep.h"
33 #include "datareps/TextDataRep.h"
34 
35 #include "datasrcs/DataSource.h"
36 #include "plotters/PlotterBase.h"
37 
41 
42 #include "reps/RepBase.h"
43 
44 #include <cassert>
45 
46 using std::string;
47 using std::vector;
48 
49 
50 using namespace hippodraw;
51 
53  : BaseXML ( "DataRep", controller ),
54  m_contours ( "contours" )
55 {
56  m_pointrep = new PointRepXML ( controller );
57  m_nTupleProjector = new NTupleProjectorXML ( controller );
58  m_binningProjectorXML = new BinningProjectorXML ( controller );
59  m_functionProjector = new FunctionProjectorXML ( controller );
61 }
62 
65 {
66  delete m_pointrep;
67  delete m_nTupleProjector;
68  delete m_binningProjectorXML;
69  delete m_functionProjector;
71 }
72 
74 {
76 
77  const void * addr = reinterpret_cast < const void * > ( & rep );
78  int id = m_controller -> getId ( addr );
79 
80  setId ( *tag, id );
81  tag->setAttribute ( m_type, rep.name() );
82 
83  createChildren ( *tag, rep );
84 
85  return tag;
86 }
87 
88 
90  const NTupleProjector * projector )
91 {
92  NTupleProjectorXML * qt_projector
93  = dynamic_cast < NTupleProjectorXML * > ( m_nTupleProjector );
94  XmlElement * element = qt_projector->createElement ( *projector );
95 
96  tag.appendChild ( *element );
97  delete element;
98 }
99 
100 void
102 createChildren ( XmlElement & tag, const BinningProjector * projector )
103 {
104  XmlElement * element
105  = m_binningProjectorXML -> createElement ( *projector );
106  tag.appendChild ( *element );
107  delete element;
108 }
109 
110 void
112 createChildren ( XmlElement & tag, const MapMatrixProjector * projector )
113 {
114  XmlElement * element
115  = m_mapMatrixProjectorXML -> createElement ( *projector );
116  tag.appendChild ( *element );
117  delete element;
118 }
119 
121  const FunctionProjector * projector )
122 {
123  FunctionProjectorXML * qt_projector
124  = dynamic_cast < FunctionProjectorXML * > ( m_functionProjector );
125  XmlElement * element = qt_projector->createElement ( *projector );
126 
127  tag.appendChild ( *element );
128  delete element;
129 }
130 
132  const hippodraw::DataRep & rep )
133 {
134  RepBase * pointrep = rep.getRepresentation ();
135  XmlElement * element = m_pointrep->createElement ( *pointrep );
136 
137  tag.appendChild ( *element );
138  delete element;
139 
140  ProjectorBase * projbase = rep.getProjector ();
141 
142  if ( rep.hasNTupleBindings () )
143  {
144  const NTupleProjector * projector
145  = dynamic_cast < const NTupleProjector * > ( projbase );
146  createChildren ( tag, projector );
147  }
148 
149  const BinningProjector * binProjector
150  = dynamic_cast < const BinningProjector * > ( projbase );
151  if ( binProjector != 0 )
152  {
153  createChildren ( tag, binProjector );
154  }
155 
156  const FunctionProjector * functionProjector
157  = dynamic_cast < const FunctionProjector * > ( projbase );
158  if ( functionProjector != 0 )
159  {
160  createFunctionTargetChild ( tag, rep );
161  createChildren ( tag, functionProjector );
162  }
163 
164  const MapMatrixProjector * mapMatrixProjector
165  = dynamic_cast < const MapMatrixProjector * > ( projbase );
166  if ( mapMatrixProjector != 0 ) {
167  createChildren ( tag, mapMatrixProjector );
168  }
169 
170 }
171 
172 void DataRepXML::
174  const hippodraw::DataRep & rep )
175 {
176  const FunctionRep & frep = dynamic_cast < const FunctionRep & > ( rep );
177  hippodraw::DataRep * target = frep.getTarget ();
178  const void * addr = reinterpret_cast < const void * > ( target );
179  int id = m_controller -> getId ( addr );
180  XmlElement * element
181  = XmlController::m_xml_doc->createElement ( "FunctionTarget" );
182  element->setAttribute ( "id", id );
183  tag.appendChild ( *element );
184  delete element;
185 }
186 
189 createDataRep ( const XmlElement * element )
190 {
191  DataRep * rep = 0;
192 
193  string type;
194  bool ok = element -> attribute ( m_type, type );
195  assert ( ok );
196 
197  if ( type == "Z Plot" ) {
198  type = "Image"; // name has changed.
199  }
200 
202  try {
203  rep = controller -> createDataRep ( type );
204  }
205  catch ( const DataRepException & ) {
206  // do nothing
207  }
208 
209  return rep;
210 }
211 
212 DataRep *
214 createDataRep ( const XmlElement * element, const XmlElement * ntp_element )
215 {
216  string type;
217  bool ok = element->attribute ( m_type, type );
218  assert ( ok );
219 
220  int ref = m_nTupleProjector->getNTupleReference ( ntp_element );
221  const DataSource * ntuple = m_controller->getDataSource ( ref );
222  assert ( ntuple != 0 );
223 
224  vector < string > bindings;
225  m_nTupleProjector->getBindings ( ntp_element, bindings );
226 
228  DataRep * rep
229  = controller->createDataRep ( type, ntuple, bindings );
230 
231  return rep;
232 }
233 
236 DataRep *
239 {
240  TextDataRep * rep = new TextDataRep ();
241 
242  return rep;
243 }
244 
246 {
247  DataRep * rep = 0;
248 
249  const XmlElement * element
250  = m_nTupleProjector->getNode ( dr_element );
251 
252  if ( element != 0 ) { // bound to ntuple
253  rep = createDataRep ( dr_element, element );
254  ProjectorBase * projector = rep->getProjector ();
255  m_binningProjectorXML->getObject ( dr_element, projector );
256  }
257 
258  element = m_mapMatrixProjectorXML -> getNode ( dr_element );
259  if ( element != 0 ) {
260  ProjectorBase * projector = rep -> getProjector ();
261  m_mapMatrixProjectorXML -> setAttributes ( element, projector );
262  }
263 
264  element = m_functionProjector->getNode ( dr_element );
265  if ( element != 0 ) {
266  XmlElement * targetelement = dr_element->getNode ( "FunctionTarget" );
267  assert ( targetelement );
268  int id = targetelement->getID ();
269  DataRep * target = m_controller->getDataRep ( id );
270  assert ( target );
271  rep = m_functionProjector -> createFunctionRep ( element, target );
272  }
273 
274  if ( element == 0 ) { // not any of above
275  const XmlElement * element
276  = m_nTupleProjector->getNode ( dr_element );
277  if ( element == 0 ) {
278  rep = createDataRep ( dr_element );
279  if ( rep != 0 ) {
280  ProjectorBase * projector = rep -> getProjector ();
281  m_binningProjectorXML -> getObject ( dr_element, projector );
282  m_binningProjectorXML -> setBins ( dr_element, projector );
283  }
284  }
285  }
286 
287  string type;
288  bool ok = dr_element->attribute ( m_type, type );
289  assert ( ok );
290 
291  if ( type == "TextDataRep" ) {
292  rep = getTextRepObject ( dr_element );
293  }
294 
295  if ( rep == 0 ) return 0;
296 
297  const XmlElement * pr_element = m_pointrep->getNode ( dr_element );
298  assert ( pr_element );
299  RepBase * pr = m_pointrep->createObject ( pr_element );
300  rep->setPointRep ( pr );
301 
302  return rep;
303 }
XmlElement * createElement()
Creates a new element node.
Definition: BaseXML.cxx:43
The BinningProjector is an abstract class provides most of the functionality for a projector that doe...
virtual XmlElement * createElement(const std::string &tagName)=0
Creates a new DOM element wrapper object and returns a pointer to it.
NTupleProjectorXML * m_nTupleProjector
The NTupleProjectorXML instance used by this class.
Definition: DataRepXML.h:55
virtual bool attribute(const std::string &name, bool &value) const =0
Sets value to the attribute name&#39;s value.
FunctionProjectorXML class interface.
hippodraw::DataRepXML class interface
const std::string & name() const
Returns the name of the display.
Definition: DataRep.cxx:72
BinningProjectorXML * m_binningProjectorXML
the BinningProjectorXML instance used by this class.
Definition: DataRepXML.h:58
PointRepXML class interface.
virtual void setPointRep(RepBase *pointrep)
Sets the representation of the data points.
Definition: DataRep.cxx:217
XmlDocument class interface.
hippodraw::DataRep * createDataRep(const XmlElement *element)
Creates and returns a DataRep object that does not have NTuple bindings.
Definition: DataRepXML.cxx:189
XmlController class interface.
FunctionProjectorXML * m_functionProjector
The FunctionProjectorXML instance used by this class.
Definition: DataRepXML.h:61
hippodraw::FunctionController class interface
hippodraw::TextDataRep class interface
hippodraw::BinningProjector class interface
XmlElement * createElement(const RepBase &rep)
Returns a newly created XML element for the RepBase object.
Definition: PointRepXML.cxx:56
MapMatrixProjectorXML * m_mapMatrixProjectorXML
The MapMatrixProjectorXML instance used by this class.
Definition: DataRepXML.h:65
const XmlElement * getNode(const XmlElement *element) const
Returns the single child node of element of the type that can be handled by this object.
Definition: BaseXML.cxx:53
An NTupleProjector is a projector that projects data from an DataSource object.
A pure virtual base class of XML element wrapper.
Definition: XmlElement.h:30
PointRepXML * m_pointrep
The PointRepXML instance used by this class.
Definition: DataRepXML.h:52
A derived class of DataRep which is a base class for displaying a function.
Definition: FunctionRep.h:34
An class XML doing serialization and deserialization of derived classes of BinningProjector.
An class XML doing serialization and de-serialization of derived classes of MapMatrixProjector.
RepBase * createObject(const XmlElement *element)
Creates an object derived from RepBase from information in the XmlElement.
Definition: PointRepXML.cxx:97
return rep
Definition: Inspector.cxx:3843
virtual XmlElement * getNode(const std::string &tagName) const =0
Returns the single direct child element node with name tagName.
hippodraw::DataRep * getTextRepObject(const XmlElement *)
Creates and returns a DataRep object that is a TextDataRep.
Definition: DataRepXML.cxx:238
virtual int getID() const =0
Returns the ID of the element, if it has one.
hippodraw::MapMatrixProjector class interface
DataRep * createDataRep(const std::string &name)
Creates a new DataRep object of class name.
A singleton class that is does XML serialization and de-serialization of derived classes of RepBase...
Definition: PointRepXML.h:30
DataRep * getTarget() const
Returns the DataRep object upon which the function is applied.
void setId(XmlElement &tag, int id)
Sets the unique identification of the object.
Definition: BaseXML.cxx:64
hippodraw::FunctionRep class interface
hippodraw::DataSource class interface.
hippodraw::DataRep * createObject(const XmlElement *element)
Returns a newly created object based on the XmlElement.
Definition: DataRepXML.cxx:245
bool ok
Definition: CanvasView.cxx:163
PyArray_TYPES type(numeric::array arr)
Definition: num_util.cpp:249
The base class for data representations.
Definition: DataRep.h:68
virtual void appendChild(const XmlNode &child)=0
Appends a child element to the element.
DataRepController class interface.
XmlElement * createElement(const FunctionProjector &projector)
Returns a newly created XmlElement with its attributes set for projector.
DataRepXML(XmlController *)
A constructor taking an XML Controller as argument.
Definition: DataRepXML.cxx:52
const DataSource * getDataSource(int ref_id)
Returns pointer to data source from the xml reference ID.
A derived class of NTupleProjector that maps 1 DataSource column to a Y axis of two dimensional proje...
A singleton class that is the interface between GUI and the DataRep.
An class XML doing serialization and deserialization of derived classes of NTupleProjector.
virtual bool hasNTupleBindings() const
Returns true if the DataRep&#39;s projector can bind to DataSource.
Definition: DataRep.cxx:95
hippodraw::RepBase class interface
XmlController * m_controller
The singleton XML controller object.
Definition: BaseXML.h:60
XmlElement class interface.
void getObject(const XmlElement *parent, ProjectorBase *projector)
Sets the binning attributes of the projector from child nodes of the parent XML element.
The base class for the Projector hierarchy.
Definition: ProjectorBase.h:56
static DataRepController * instance()
Returns the pointer to the singleton instance.
BinningProjectorXML class interface.
static XmlDocument * m_xml_doc
The current document being generated or read.
const std::string m_type
The attribute name for the type of object.
Definition: BaseXML.h:54
hippodraw::FunctionProjector class interface
An class XML doing serialization and deserialization of derived classes of FunctionProjector.
An xception class that is thrown when attempting to bind a DataRep to a NTuple with a column name tha...
void createFunctionTargetChild(XmlElement &tag, const hippodraw::DataRep &rep)
Creates the child element for the function target.
Definition: DataRepXML.cxx:173
A base class of XML element controllers.
Definition: BaseXML.h:35
XmlElement * createElement(const NTupleProjector &projector)
Returns a newly created XML element with its attributes set.
DataRep * getDataRep(int ref)
Returns a pointer to the DataRep from the xml reference Id.
MapMatrixProjectorXML class interface.
void getBindings(const XmlElement *element, std::vector< std::string > &bindings) const
Retreives the bindings to the HiNTuple from the element&#39;s data by clearing the list then filling it...
A base class that is the interface between GUI and the XML serialization and deserialization.
Definition: XmlController.h:53
~DataRepXML()
The destructor.
Definition: DataRepXML.cxx:64
hippodraw::NTupleProjectorXML class interface
virtual ProjectorBase * getProjector() const
Returns the Projector object controlling the data.
Definition: DataRep.cxx:138
Displays data in textual representation.
Definition: TextDataRep.h:32
int getNTupleReference(const XmlElement *element) const
Retrieves the reference to the DataSource from the XML elements&#39;s data.
void createChildren(XmlElement &tag, const hippodraw::DataRep &rep)
Creates the children elements of this element.
Definition: DataRepXML.cxx:131
The base class for the point representation hierarchy.
Definition: RepBase.h:45
RepBase * getRepresentation() const
Returns the representation used to draw the data points.
Definition: DataRep.cxx:234
hippodraw::PlotterBase class interface.
virtual void setAttribute(const std::string &name, bool value)=0
Sets attribute named name to the int value value.
A projector that plots one function.
Base class for DataSource.
Definition: DataSource.h:55

Generated for HippoDraw Class Library by doxygen