Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

NTupleProjectorXML.cxx

Go to the documentation of this file.
00001 
00012 #ifdef HAVE_CONFIG_H
00013 #include "config.h"
00014 #endif
00015 
00016 // for truncation warning
00017 #ifdef _MSC_VER
00018 #include "msdevstudio/MSconfig.h"
00019 #endif
00020 
00021 #include "NTupleProjectorXML.h"
00022 
00023 #include "XmlController.h"
00024 #include "XmlDocument.h"
00025 #include "XmlElement.h"
00026 
00027 #include "datasrcs/TupleCut.h"
00028 #include "projectors/NTupleProjector.h"
00029 
00030 #ifdef SSTREAM_DEFECT
00031 #include <strstream>
00032 using std::ostrstream;
00033 #else
00034 #include <sstream>
00035 using std::ostringstream;
00036 #endif
00037 
00038 #include <cassert>
00039 
00040 using std::list;
00041 using std::string;
00042 using std::vector;
00043 
00044 NTupleProjectorXML::NTupleProjectorXML ( XmlController * controller )
00045   : BaseXML ( "NTupleProjector", controller )
00046 {
00047 }
00048 
00049 void
00050 NTupleProjectorXML::
00051 createChildren ( XmlElement & tag, 
00052                  const NTupleProjector & projector )
00053 {
00054   const vector < const TupleCut * > & cutlist = projector.getCutList ();
00055   if ( cutlist.empty() ) return;
00056 
00057 #ifdef ITERATOR_MEMBER_DEFECT
00058   std:: 
00059 #endif
00060   vector < const TupleCut * >::const_iterator first = cutlist.begin();
00061   for ( ; first != cutlist.end(); ++first ) {
00062     const TupleCut * cut = *first;
00063     const void * addr = reinterpret_cast < const void * > ( cut );
00064     int ref = m_controller -> getId ( addr );
00065     XmlElement * element 
00066       = XmlController::m_xml_doc->createElement ( "TupleCutRef" );
00067     element->setAttribute ( "ref", ref );
00068     tag.appendChild ( *element );
00069   }
00070 
00071 }
00072 
00073 XmlElement * 
00074 NTupleProjectorXML::createElement ( const NTupleProjector & projector )
00075 {
00076   XmlElement * tag = BaseXML::createElement (); // in base class
00077   const void * addr = reinterpret_cast < const void * > ( & projector );
00078   int id = m_controller -> getId ( addr );
00079   setId ( *tag, id );
00080 
00081   const DataSource * ntuple = projector.getNTuple ();
00082 
00083   XmlElement * element = m_controller->addDataSource ( ntuple );
00084 
00085   int ref = element->getID ();
00086   tag->setAttribute ( "ref", ref );
00087 
00088   const vector < string > & bindings = projector.getAxisBindings();
00089   unsigned int size = bindings.size();
00090 
00091   for ( unsigned int i = 0; i < size; i++ ) {
00092 #ifdef SSTREAM_DEFECT
00093     ostrstream name;
00094 #else
00095     ostringstream name;
00096 #endif
00097     name << "Axis" << i << std::ends;
00098     const string & label = bindings[i];
00099 
00100     tag->setAttribute ( name.str(), label );
00101   }
00102 
00103   createChildren ( *tag, projector );
00104 
00105   return tag;
00106 }
00107 
00108 int NTupleProjectorXML::getNTupleReference ( const XmlElement * element ) const
00109 {
00110   int ref;
00111   bool ok = element->attribute ( "ref", ref );
00112   if ( ! ok ) return 0;
00113 
00114   return ref;
00115 }
00116 
00117 void 
00118 NTupleProjectorXML::
00119 getBindings ( const XmlElement * element, 
00120               std::vector < std::string > & bindings ) const
00121 {
00122   bindings.clear();
00123 
00124   for ( int i = 0; ; i++ ) {
00125 #ifdef SSTREAM_DEFECT
00126     ostrstream name;
00127 #else
00128     ostringstream name;
00129 #endif
00130     name << "Axis" << i << std::ends;
00131     string label;
00132     bool ok = element->attribute ( name.str(), label );
00133     if ( ! ok ) break;
00134 
00135     bindings.push_back ( label );
00136   }
00137 
00138 }
00139 
00140 void 
00141 NTupleProjectorXML::
00142 addCuts ( const XmlElement * element, NTupleProjector * projector )
00143 {
00144   list < XmlElement * > nodelist;
00145   element->fillNodeList ( "TupleCutRef", nodelist );
00146   if ( nodelist.empty () ) return;
00147 
00148 #ifdef ITERATOR_MEMBER_DEFECT
00149   std::
00150 #endif
00151   list < XmlElement * >::const_iterator first = nodelist.begin();
00152   for ( ; first != nodelist.end (); ++first ) {
00153     XmlElement * node = *first;
00154     int ref = 0;
00155     bool ok = node->attribute ( "ref", ref );
00156     assert ( ok );
00157     const TupleCut * cut = m_controller->getTupleCut ( ref );
00158     projector->addCut ( cut );
00159     cut = m_controller -> getTupleCut ( -ref );
00160     if ( cut != 0 ) {
00161       projector->addCut ( cut );
00162     }
00163   }
00164 }

Generated for HippoDraw-1.14.8.5 by doxygen 1.4.3