00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
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
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
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
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
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
00177
00178 std::string binNumToString(int bn);
00179 int stringToBinNum(const std::string & bin);
00180
00181
00182 };
00183
00184 }
00185 }
00186
00187
00190
00191 template<class FP>
00192 std::string Anaphe::AIDA_XMLStore::Translator::toString(FP number) const
00193 {
00194
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