Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

Translator.h

Go to the documentation of this file.
00001  /**********************************************************************
00002   *                                                                    *
00003   * Copyright (c) 2002 Lorenzo Moneta, CERN/IT                       *
00004   *                   <Lorenzo.Moneta.cern.ch>                       *
00005   *                                                                    *
00006   * This library is free software; you can redistribute it and/or      *
00007   * modify it under the terms of the GNU Lesser General Public         *
00008   * License as published by the Free Software Foundation; either       *
00009   * version 2.1 of the License, or (at your option) any later version. *
00010   *                                                                    *
00011   * This library is distributed in the hope that it will be useful,    *
00012   * but WITHOUT ANY WARRANTY; without even the implied warranty of     *
00013   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   *
00014   * Lesser General Public License for more details.                    *
00015   *                                                                    *
00016   * You should have received a copy of the GNU Lesser General Public   *
00017   * License along with this library (see file COPYING); if not, write  *
00018   * to the Free Software Foundation, Inc., 59 Temple Place, Suite      *
00019   * 330, Boston, MA 02111-1307 USA, or contact the author.             *
00020   *                                                                    *
00021   **********************************************************************/
00022 
00023 // Header file for class Translator
00024 // 
00025 // Created by: moneta  at Fri Sep 13 10:43:55 2002
00026 // 
00027 // Last update: Fri Sep 13 10:43:55 2002
00028 // 
00029 
00030 /*   Helper class containing methods using by the various types to 
00031  *    transform into and from XML
00032  *   It uses of the DataXML package
00033  */
00034  
00035 #ifndef TRANSLATOR
00036 #define TRANSLATOR 1
00037 
00038 #include <string>
00039 #include <vector>
00040 
00041 #ifdef OLDSTREAMS
00042 # include <strstream>
00043 # define ostringstream ostrstream
00044 # define istringstream istrstream
00045 #else
00046 # include <sstream>
00047 #endif
00048 
00049 
00050 
00051 namespace DataXML { 
00052    class DataObject; 
00053  }
00054 
00055 namespace AIDA { 
00056    class IAxis; 
00057    class IAnnotation;
00058 }
00059 
00060 
00061 namespace Anaphe { 
00062    namespace AIDA_XMLStore { 
00063 
00064 class Translator {
00065 
00066 public: 
00067   Translator(); 
00068   virtual ~Translator();
00069 
00070 private:
00071 // usually copying is non trivial, so we make this unaccessible
00072   Translator(const Translator &); 
00073   Translator & operator = (const Translator &); 
00074 
00075 public: 
00076 
00077   typedef std::vector<DataXML::DataObject>::const_iterator ElementIterator;
00078 
00079 protected: 
00080 
00081   // helper methods to be used by the specific translators 
00082 
00083   bool appendAidaHeader(DataXML::DataObject & aidaElement); 
00084 
00085   bool appendObjectHeader(DataXML::DataObject & objElement, 
00086                           const std::string & elementName, 
00087                           const std::string & name, 
00088                           const std::string & title = "", 
00089                           const std::string & path = "", 
00090                           const std::string & options = "");
00091 
00092   bool appendAnnotation(DataXML::DataObject & objElement,
00093                         const AIDA::IAnnotation& anno); 
00094 
00095   bool appendAxis(DataXML::DataObject & objElement, 
00096                   const std::string& axisName, 
00097                   const AIDA::IAxis& axis);
00098 
00099   bool appendStatistics(DataXML::DataObject & statisticsElement, 
00100                         const std::string& axisName, 
00101                         double mean, double rms, double skew = 0);
00102 
00103   bool appendHisto1DBinData(DataXML::DataObject & dataElement,  
00104                             int xbin, int entries, double height, double error, 
00105                             double wMean = 0, double rms = 0, 
00106                             double wRms = 0,  double error2= 0 );
00107 
00108   bool appendHisto2DBinData(DataXML::DataObject & dataElement,  
00109                             int xbin, int ybin , int entries, 
00110                             double height, double error, 
00111                             double wMeanX = 0, double wMeanY=0, double rms = 0);
00112 
00113   bool appendHisto3DBinData(DataXML::DataObject & dataElement,  
00114                             int xbin, int ybin , int zbin, int entries, 
00115                             double height, double error, 
00116                             double wMeanX = 0, double wMeanY=0, double wMeanZ=0,  double rms = 0 );
00117 
00118   bool appendCloudEntry(DataXML::DataObject & dataElement,  int dimension, 
00119                         double xval, double yval, double zval, double weight); 
00120 
00121   bool appendDataPointMeasurement(DataXML::DataObject & dataElement, 
00122                                   double value, double eminus, double eplus); 
00123 
00125 
00126   void getObjectHeader(const DataXML::DataObject & objElement, std::string & name, 
00127                   std::string & title, std::string & path, std::string & options); 
00128 
00129   typedef std::vector<std::pair<std::string, std::pair<std::string, bool> > > AnnotationData;
00130  
00132 
00133   void getAnnotation(const DataXML::DataObject & obj,AnnotationData & annoData);
00135   void setAnnotation(AIDA::IAnnotation * anno, const AnnotationData & annoData); 
00136 
00137   void getAxis(const DataXML::DataObject & objElement, const std::string& axisName, 
00138           int& nBins, double& low, double& high, std::vector<double> & edges);
00139 
00140   void getStatistics(const DataXML::DataObject & statisticsElement, 
00141                 const std::string& axisName, 
00142                 double & mean, double & rms, double & skew);
00143 
00144   
00145   void getHisto1DBinData(const DataXML::DataObject &  binElement, int & xbin, int & entries, double & height, double & error, double & wMean, double & wRms, double & error2, double & rms);
00146 
00147   void getHisto2DBinData(const DataXML::DataObject &  binElement, int & xbin, int & ybin, int & entries, double & height, double & error, double & wMeanX, double & wMeanY, double & wRmsX, double & wRmsY, double & error2, double & rms);
00148 
00149   void getHisto3DBinData(const DataXML::DataObject &  binElement, int & xbin, int & ybin, int & zbin, int & entries, double & height, double & error, double & wMeanX, double & wMeanY, double & wMeanZ, double & wRmsX, double & wRmsY, double & wRmsZ, double & error2, double & rms);
00150 
00151   void getCloudEntryData(const DataXML::DataObject & entryElement, 
00152                          const int dim, double & xval, double & yval, 
00153                          double & zval, double & weight );
00154 
00155   void getDataPointMeasurement(const DataXML::DataObject & dataElement, 
00156                                double & value, double & eminus, double & eplus); 
00157   // other helper methods
00158   template<class FP>
00159   std::string toString(FP v) const;
00160   std::string toString(int i) const;
00161 
00162   template<class T>
00163   bool toValue(std::string s, T& val);
00164 
00165   // static members available to all subclasses 
00166 
00167   static const int SCI_PRECISION;
00168   static const std::string XML_VERSION; 
00169   static const std::string ENCODING_TYPE; 
00170   static const std::string PACKAGE; 
00171   static const std::string PACKAGE_VERSION; 
00172 
00173 
00174 private: 
00175 
00176   // private helper methods 
00177 
00178   std::string  binNumToString(int bn);
00179   int stringToBinNum(const std::string & bin); 
00180   
00181 
00182 }; 
00183 
00184    }      // end of namespace Anaphe::AIDA_XMLStore
00185 }
00186 
00187 
00190 
00191 template<class FP>
00192 std::string Anaphe::AIDA_XMLStore::Translator::toString(FP number) const
00193 {
00194   // generic method for floating point types
00195   std::ostringstream buf;
00196   buf.setf(std::ios::scientific);
00197   buf.precision(Anaphe::AIDA_XMLStore::Translator::SCI_PRECISION);
00198   buf << number;
00199 #ifndef BADENDS
00200   buf << std::ends;
00201 #endif
00202   std::string ret = buf.str();
00203   return ret;
00204 }
00205 
00206 
00207 
00208 
00209 #endif /* TRANSLATOR */

Generated on Tue Nov 19 12:32:57 2002 for AIDA_XMLStore by doxygen1.2.16