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

BinsBaseXML.cxx

Go to the documentation of this file.
00001 
00012 // for truncation warning
00013 #ifdef _MSC_VER
00014 #include "msdevstudio/MSconfig.h"
00015 #endif
00016 
00017 #include "BinsBaseXML.h"
00018 
00019 #include "BinnerAxisXML.h"
00020 #include "XmlElement.h"
00021 
00022 #include "binners/BinsBase.h"
00023 #include "binners/BinsFactory.h"
00024 
00025 #include <cassert>
00026 
00027 using namespace hippodraw;
00028 
00029 using std::list;
00030 using std::string;
00031 
00032 BinsBaseXML::BinsBaseXML ( XmlController * controller )
00033   : BaseXML ( "BinsBase", controller ),
00034     m_axis ( "axis" )
00035 {
00036   m_binnerXML = new BinnerAxisXML ( controller );
00037 }
00038 
00039 XmlElement * 
00040 BinsBaseXML::
00041 createElement ( const BinsBase & bins )
00042 {
00043   XmlElement * tag = BaseXML::createElement ();
00044   const string & type = bins.name();
00045   tag->setAttribute ( m_type, type );
00046 
00047   createChildren ( *tag, bins );
00048 
00049   return tag;
00050 }
00051 
00052 
00053 void
00054 BinsBaseXML::
00055 createChildren ( XmlElement & tag, const BinsBase & bins )
00056 {
00057   const BinnerAxis * binner = bins.getBinnerOn ( Axes::X );
00058   XmlElement * element = m_binnerXML->createElement ( *binner );
00059   string axis ( "X" );
00060   element->setAttribute ( m_axis, axis );
00061   tag.appendChild ( *element );
00062 
00063   int number = bins.getNumberOfAxes ();
00064   if ( number < 2 ) return;
00065 
00066   binner = bins.getBinnerOn ( Axes::Y );
00067   element = m_binnerXML->createElement ( *binner );
00068   axis = "Y";
00069   element->setAttribute ( m_axis, axis );
00070   tag.appendChild ( *element );
00071 }
00072 
00073 void
00074 BinsBaseXML::
00075 createNTuple ( XmlElement & tag, const BinsBase & bins )
00076 {
00077 
00078 }
00079 
00080 BinsBase * 
00081 BinsBaseXML::
00082 createObject ( const XmlElement * binsbase )
00083 {
00084   string type;
00085   bool ok = binsbase->attribute ( m_type, type );
00086   assert ( ok );
00087 
00088   BinsFactory * factory = BinsFactory::instance ();
00089   BinsBase * bins = factory->create ( type );
00090 
00091   list < XmlElement * > nodelist;
00092   m_binnerXML->fillNodeList ( binsbase, nodelist );
00093 
00094   list < XmlElement * > :: const_iterator first = nodelist.begin();
00095   while ( first != nodelist.end() ) {
00096     XmlElement * element = *first++;
00097     BinnerAxis * binner = m_binnerXML->createObject ( element );
00098     string axis;
00099     bool ok = element->attribute ( m_axis, axis );
00100     assert ( ok );
00101 
00102     Axes::Type type = axis == "X" ? Axes::X : Axes::Y;
00103     bins->setBinnerOn ( binner, type );
00104   }
00105 
00106   return bins;
00107 }

Generated for HippoDraw-1.14.8.5 by doxygen 1.4.3