NTupleProjectorXML.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 "NTupleProjectorXML.h"
18 
19 #include "XmlController.h"
20 #include "XmlDocument.h"
21 #include "XmlElement.h"
22 
23 #include "datasrcs/TupleCut.h"
24 #include "pattern/string_convert.h"
26 
27 #include <cassert>
28 
29 using std::list;
30 using std::string;
31 using std::vector;
32 
33 using namespace hippodraw;
34 
36  : BaseXML ( "NTupleProjector", controller )
37 {
38 }
39 
40 void
43  const NTupleProjector & projector )
44 {
45  const vector < const TupleCut * > & cutlist = projector.getCutList ();
46  if ( cutlist.empty() ) return;
47 
48 #ifdef ITERATOR_MEMBER_DEFECT
49  std::
50 #endif
51  vector < const TupleCut * >::const_iterator first = cutlist.begin();
52  for ( ; first != cutlist.end(); ++first ) {
53  const TupleCut * cut = *first;
54  const void * addr = reinterpret_cast < const void * > ( cut );
55  int ref = m_controller -> getId ( addr );
56  XmlElement * element
57  = XmlController::m_xml_doc->createElement ( "TupleCutRef" );
58  element->setAttribute ( "ref", ref );
59  tag.appendChild ( *element );
60  delete element;
61  }
62 
63 }
64 
65 XmlElement *
67 {
68  XmlElement * tag = BaseXML::createElement (); // in base class
69  const void * addr = reinterpret_cast < const void * > ( & projector );
70  int id = m_controller -> getId ( addr );
71  setId ( *tag, id );
72 
73  const DataSource * ntuple = projector.getNTuple ();
74 
75  XmlElement * element = m_controller->addDataSource ( ntuple );
76 
77  int ref = element->getID ();
78  tag->setAttribute ( "ref", ref );
79 
80  const vector < string > & bindings = projector.getAxisBindings();
81  unsigned int size = bindings.size();
82 
83  for ( unsigned int i = 0; i < size; i++ ) {
84  string name ( "Axis" );
85  name += String::convert ( i );
86  const string & label = bindings[i];
87  tag -> setAttribute ( name, label );
88  }
89 
90  createChildren ( *tag, projector );
91 
92  return tag;
93 }
94 
96 {
97  int ref;
98  bool ok = element->attribute ( "ref", ref );
99  if ( ! ok ) return 0;
100 
101  return ref;
102 }
103 
104 void
106 getBindings ( const XmlElement * element,
107  std::vector < std::string > & bindings ) const
108 {
109  bindings.clear();
110 
111  for ( int i = 0; ; i++ ) {
112  string label;
113  string name ( "Axis" );
114  name += String::convert ( i );
115  bool ok = element -> attribute ( name, label );
116  if ( ! ok ) break;
117 
118  bindings.push_back ( label );
119  }
120 
121 }
XmlElement * createElement()
Creates a new element node.
Definition: BaseXML.cxx:43
unsigned int i
virtual const DataSource * getNTuple() const
Returns the DataSource used by the projector.
virtual XmlElement * createElement(const std::string &tagName)=0
Creates a new DOM element wrapper object and returns a pointer to it.
virtual bool attribute(const std::string &name, bool &value) const =0
Sets value to the attribute name&#39;s value.
void createChildren(XmlElement &tag, const NTupleProjector &proj)
Creates child elements of the element.
XmlDocument class interface.
XmlController class interface.
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
The class expresses a cut on a DataSource, i.e.
Definition: TupleCut.h:43
virtual int getID() const =0
Returns the ID of the element, if it has one.
The namespace for conversion to string.
void setId(XmlElement &tag, int id)
Sets the unique identification of the object.
Definition: BaseXML.cxx:64
bool ok
Definition: CanvasView.cxx:163
virtual void appendChild(const XmlNode &child)=0
Appends a child element to the element.
intp size(numeric::array arr)
Definition: num_util.cpp:296
string convert(int i)
Converts an integer to a string.
NTupleProjectorXML(const NTupleProjectorXML &)
A private copy constructor in order to avoid copying.
XmlController * m_controller
The singleton XML controller object.
Definition: BaseXML.h:60
const std::vector< const TupleCut * > & getCutList() const
Returns the list of TupleCut objects used by this projector.
XmlElement class interface.
hippodraw::TupleCut class interface
static XmlDocument * m_xml_doc
The current document being generated or read.
A base class of XML element controllers.
Definition: BaseXML.h:35
virtual XmlElement * addDataSource(const DataSource *ntuple)
Adds the DataSource to the document if it doesn&#39;t already exist.
virtual const std::vector< std::string > & getAxisBindings() const
Returns the current axis bindings.
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
hippodraw::NTupleProjectorXML class interface
int getNTupleReference(const XmlElement *element) const
Retrieves the reference to the DataSource from the XML elements&#39;s data.
hippodraw::NTupleProjector class interface
virtual void setAttribute(const std::string &name, bool value)=0
Sets attribute named name to the int value value.
Base class for DataSource.
Definition: DataSource.h:55

Generated for HippoDraw Class Library by doxygen