Anaphe Home Page Reference Documentation

Main Page     Namespaces     Classes     Source Code    

Translator.h

Go to the documentation of this file.
00001 #ifndef TRANSLATOR_H
00002 #define TRANSLATOR_H
00003 
00004 // -*- C++ -*-
00005 
00006 //
00007 // (c) CERN, Geneva
00008 //
00009 
00010 //
00011 // Class for translating AIDA-compliant XML into a generic histo data container 
00012 // (the HistoParametersXD classes), or writing out XML from an (interface) histogram.
00013 // Interface depends only on AIDA interface classes IHistogramXD and the
00014 // HistoParametersXD classes (part of this package)
00015 // Implementation depends on the DataXML package (which, in turn, uses expat).
00016 //
00017 // The WHOLE of the XML document is read in one go. The stream must supply 
00018 // the <aida> tag, the </aida> tag, and everything in between.
00019 //
00020 // Max 20/12/01
00021 //
00022 
00023 
00024 
00025 
00026 // a kludge
00027 #ifdef AIDA_STD
00028 # undef AIDA_STD
00029 #endif
00030 #ifdef AIDA_NOT_USE_STD
00031 # define AIDA_STD
00032 #else
00033 # define AIDA_STD std
00034 #endif
00035 
00036 
00037 
00038 
00039 #include <vector>
00040 #include <string>
00041 #include <iostream>
00042 #include "Interfaces/IHistogram1D.h"
00043 #include "Interfaces/IHistogram2D.h"
00044 #include "Interfaces/IHistogram3D.h"
00045 #include "DataXML/XMLStream.h"
00046 #include "DataXML/DataObject.h"
00047 #include "HistoParameters/HistoParameters.h"
00048 
00049 
00050 
00051 
00052 namespace Anaphe {
00053 
00054 
00055 
00056 
00057 class Translator
00058 {
00059 public:
00064   Translator(void);
00065   Translator(const Translator&);
00066   ~Translator(void);
00067   const Translator& operator=(const Translator&);
00068 
00069 public:
00071   void noWarnings(const bool& = true);
00073   bool setInputStream(AIDA_STD::istream&);
00074   bool setOutputStream(AIDA_STD::ostream&);
00077   bool read(HistoParameters1D&);
00078   bool read(HistoParameters2D&);
00079   bool read(HistoParameters3D&);
00081   bool write(const IHistogram1D&);
00082   bool write(const IHistogram2D&);
00083   bool write(const IHistogram3D&);
00085   void flush(void);
00086 
00087 private:
00088   typedef AIDA_STD::vector<DataXML::DataObject>::const_iterator ElementCIterator;
00089   typedef AIDA_STD::vector<DataXML::DataObject>::iterator       ElementIterator;
00090 
00091 private:
00092   // XML writing stuff:
00093   template<class HistoType> 
00094   bool             genericWrite(const HistoType&);
00095   void             removeOTree(void);
00096   bool             createNewOTree(void);
00097   void             appendHistoTypeElement(const ElementIterator&);
00098   bool             writeHistoElement(const IHistogram1D&, const ElementIterator& histoElement);
00099   bool             writeHistoElement(const IHistogram2D&, const ElementIterator& histoElement);
00100   bool             writeHistoElement(const IHistogram3D&, const ElementIterator& histoElement);
00101   template<class HistoType>
00102   bool             appendHisto(const HistoType&, const ElementIterator& parent);
00103   void             setTitle(const IHistogram&, const ElementIterator& histoElement);
00104   bool             setAxes(const IHistogram1D&, const ElementIterator& histoElement);
00105   bool             setAxes(const IHistogram2D&, const ElementIterator& histoElement);
00106   bool             setAxes(const IHistogram3D&, const ElementIterator& histoElement);
00107   bool             appendAxis(const ElementIterator& histoElement,
00108                               const AIDA_STD::string& axisName, const IAxis& axis);
00109   bool             variableBins(const IAxis&) const;
00110   bool             setStats(const IHistogram1D& h, const ElementIterator& histoElement);
00111   bool             setStats(const IHistogram2D& h, const ElementIterator& histoElement);
00112   bool             setStats(const IHistogram3D& h, const ElementIterator& histoElement);
00113   bool             appendStat(const ElementIterator& statisticsElement, 
00114                               const AIDA_STD::string& axisName,
00115                               const double& mean, const double& rms);
00116   bool             setData(const IHistogram1D& h, const ElementIterator& histoElement);
00117   bool             setData(const IHistogram2D& h, const ElementIterator& histoElement);
00118   bool             setData(const IHistogram3D& h, const ElementIterator& histoElement);
00119   void             appendDataPoint(const int& dim, const ElementIterator& parent,
00120                                    const int& xbin, const int& ybin, const int& zbin,
00121                                    const int& entries, const double& height, 
00122                                    const double& error);
00123   int              binConversion(const int& i, const bool& histoMetric) const;
00124   void             addBinNumberAttribute(const ElementIterator&, const AIDA_STD::string& attName,
00125                                          const int& bn);
00126   bool             significantlyDifferent(const double&, const double&) const;
00127   void             writeHeader(AIDA_STD::ostream&) const;
00128   void             writeFooter(AIDA_STD::ostream&) const;
00129   void             noOutputStreamError(void) const;
00130   // XML reading stuff:
00131   void             removeITree(void);
00132   bool             createNewITree(AIDA_STD::istream& s);
00133   void             resetIterators(void);
00134   int              dimensionality(const ElementCIterator& histoElement) const;
00135   bool             readHistoElement(const ElementCIterator& histoElement, HistoParameters1D& hp);
00136   bool             readHistoElement(const ElementCIterator& histoelement, HistoParameters2D& hp);
00137   bool             readHistoElement(const ElementCIterator& histoelement, HistoParameters3D& hp);
00138   void             getTitle(const ElementCIterator& histoelement, HistoParameters& hp) const;
00139   void             getXAxis(const ElementCIterator& histoElement, HistoParameters1D& hp) const;
00140   void             getXAndYAxes(const ElementCIterator& histoElement, HistoParameters2D& hp) const;
00141   void             getXYAndZAxes(const ElementCIterator& histoElement, HistoParameters3D& hp) const;
00142   void             getAxis(const ElementCIterator& histoElement, const AIDA_STD::string& axisName,
00143                         int& nb, double& lo, double& hi, HistoParameters::VecDouble& edges) const;
00144   void             getStatistics(const ElementCIterator& histoElement, HistoParameters1D& hp) const;
00145   void             getStatistics(const ElementCIterator& histoElement, HistoParameters2D& hp) const;
00146   void             getStatistics(const ElementCIterator& histoElement, HistoParameters3D& hp) const;
00147   void             getNumberOfEntries(const ElementCIterator& histoElement, int& nev) const;
00148   void             getStatistic(const ElementCIterator& histoElement, 
00149                                 const AIDA_STD::string& axisName,
00150                                 double& mean, double& rms, double& skew) const;
00151   void             getData(const ElementCIterator& histoElement, HistoParameters1D& hp) const;
00152   void             getData(const ElementCIterator& histoElement, HistoParameters2D& hp) const;
00153   void             getData(const ElementCIterator& histoElement, HistoParameters3D& hp) const;
00154   void             fillBin(const ElementCIterator& binElement, HistoParameters::BinInfo& bin) const;
00155   bool             goodParameters(const HistoParameters1D& parameters) const;
00156   bool             goodParameters(const HistoParameters2D& parameters) const;
00157   bool             goodParameters(const HistoParameters3D& parameters) const;
00158   int              binNumber(const AIDA_STD::string& s) const;
00159   int              binNumber(const ElementCIterator& binElement) const;
00160   int              xBinNumber(const ElementCIterator& binElement) const;
00161   int              yBinNumber(const ElementCIterator& binElement) const;
00162   int              zBinNumber(const ElementCIterator& binElement) const;
00163   double           binHeight(const ElementCIterator& binElement) const;
00164   double           binError(const ElementCIterator& binElement) const;
00165   double           binError2(const ElementCIterator& binElement) const;
00166   int              binEntries(const ElementCIterator& binElement) const;
00167   bool             consistentBin(const int& binNumber, 
00168                                  const HistoParameters1D& hp) const;
00169   bool             consistentBin(const int& binNumberX, const int& binNumberY, 
00170                                  const HistoParameters2D& hp) const;
00171   bool             consistentBin(const int& binNumberX, const int& binNumberY, const int& binNumberZ,
00172                                  const HistoParameters3D& hp) const;
00173   void             resizeMatrix(HistoParameters::VecData&,
00174                                 const int& xdim) const;
00175   void             resizeMatrix(HistoParameters::VecVecData&,
00176                                 const int& xdim, const int& ydim) const;
00177   void             resizeMatrix(HistoParameters::VecVecVecData&,
00178                                 const int& xdim, const int& ydim, const int& zdim) const;
00179   void             convertBinNumber(int& i, const int& nbins) const;
00180   ElementCIterator getChild(const ElementCIterator& parent, 
00181                             const AIDA_STD::string& childName) const;
00182   void             getBinEdges(const ElementCIterator&, HistoParameters::VecDouble&,
00183                                const double& low, const double& high) const;
00184   void             badInputStreamError(void) const;
00185   void             wrongDocTypeError(void) const;
00186   void             missingElementError(const AIDA_STD::string& elementName) const;
00187   void             nonsenseBinError(void) const;
00188   void             badNBError(void) const;
00189   // General helpers
00190   template<class FPType> 
00191   AIDA_STD::string toString(const FPType&) const;
00192   AIDA_STD::string toString(const int&) const;
00193   int              stringToInt(const AIDA_STD::string& str) const;
00194   void             errorMessage(const AIDA_STD::string& msg) const;
00195 
00196 private:
00197   /* porting to Solaris7: UNDERFLOW and OVERFLOW #defined in math.h 
00198    * added prefix constant_ 
00199    * /kuba/
00200    */
00201   static const int              constant_UNDERFLOW;
00202   static const int              constant_OVERFLOW;
00203   static const int              RUBBISH;
00204   static const double           ROUNDOFF_TOLERANCE;
00205   static const int              SCI_PRECISION;
00206   static const AIDA_STD::string XML_VERSION;
00207   static const AIDA_STD::string ENCODING_TYPE;
00208   bool                          silent;
00209   DataXML::InputXMLStream*      iXmlStream;
00210   const DataXML::DataObject*    iRootElement;
00211   ElementCIterator              iHisto1DIt;
00212   ElementCIterator              iHisto2DIt;
00213   ElementCIterator              iHisto3DIt;
00214   AIDA_STD::ostream*            oStream;
00215   DataXML::DataObject*          oRootElement;
00216 
00217 };
00218 
00219 
00220 
00221 
00222 } // end of Anaphe namespace
00223 
00224 
00225 
00226 #endif // TRANSLATOR_H


Anaphe documentation generated by Doxygen (www.doxygen.org)