00001
00012
00013 #ifdef _MSC_VER
00014 #include "msdevstudio/MSconfig.h"
00015 #endif
00016
00017 #include "NTupleProjectorXML.h"
00018
00019 #include "XmlController.h"
00020 #include "XmlDocument.h"
00021 #include "XmlElement.h"
00022
00023 #include "datasrcs/TupleCut.h"
00024 #include "pattern/string_convert.h"
00025 #include "projectors/NTupleProjector.h"
00026
00027 #include <cassert>
00028
00029 using std::list;
00030 using std::string;
00031 using std::vector;
00032
00033 using namespace hippodraw;
00034
00035 NTupleProjectorXML::NTupleProjectorXML ( XmlController * controller )
00036 : BaseXML ( "NTupleProjector", controller )
00037 {
00038 }
00039
00040 void
00041 NTupleProjectorXML::
00042 createChildren ( XmlElement & tag,
00043 const NTupleProjector & projector )
00044 {
00045 const vector < const TupleCut * > & cutlist = projector.getCutList ();
00046 if ( cutlist.empty() ) return;
00047
00048 #ifdef ITERATOR_MEMBER_DEFECT
00049 std::
00050 #endif
00051 vector < const TupleCut * >::const_iterator first = cutlist.begin();
00052 for ( ; first != cutlist.end(); ++first ) {
00053 const TupleCut * cut = *first;
00054 const void * addr = reinterpret_cast < const void * > ( cut );
00055 int ref = m_controller -> getId ( addr );
00056 XmlElement * element
00057 = XmlController::m_xml_doc->createElement ( "TupleCutRef" );
00058 element->setAttribute ( "ref", ref );
00059 tag.appendChild ( *element );
00060 delete element;
00061 }
00062
00063 }
00064
00065 XmlElement *
00066 NTupleProjectorXML::createElement ( const NTupleProjector & projector )
00067 {
00068 XmlElement * tag = BaseXML::createElement ();
00069 const void * addr = reinterpret_cast < const void * > ( & projector );
00070 int id = m_controller -> getId ( addr );
00071 setId ( *tag, id );
00072
00073 const DataSource * ntuple = projector.getNTuple ();
00074
00075 XmlElement * element = m_controller->addDataSource ( ntuple );
00076
00077 int ref = element->getID ();
00078 tag->setAttribute ( "ref", ref );
00079
00080 const vector < string > & bindings = projector.getAxisBindings();
00081 unsigned int size = bindings.size();
00082
00083 for ( unsigned int i = 0; i < size; i++ ) {
00084 string name ( "Axis" );
00085 name += String::convert ( i );
00086 const string & label = bindings[i];
00087 tag -> setAttribute ( name, label );
00088 }
00089
00090 createChildren ( *tag, projector );
00091
00092 return tag;
00093 }
00094
00095 int NTupleProjectorXML::getNTupleReference ( const XmlElement * element ) const
00096 {
00097 int ref;
00098 bool ok = element->attribute ( "ref", ref );
00099 if ( ! ok ) return 0;
00100
00101 return ref;
00102 }
00103
00104 void
00105 NTupleProjectorXML::
00106 getBindings ( const XmlElement * element,
00107 std::vector < std::string > & bindings ) const
00108 {
00109 bindings.clear();
00110
00111 for ( int i = 0; ; i++ ) {
00112 string label;
00113 string name ( "Axis" );
00114 name += String::convert ( i );
00115 bool ok = element -> attribute ( name, label );
00116 if ( ! ok ) break;
00117
00118 bindings.push_back ( label );
00119 }
00120
00121 }