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 #include "Profile1DTranslator.h"
00031 #include "AIDA/IProfile1D.h"
00032 #include "AIDA_Dev/IDevProfile1D.h"
00033 #include "AIDA_Dev/IDevHistogramFactory.h"
00034 #include "AIDA/IAxis.h"
00035
00036 #include "DataXML/DataObject.h"
00037
00038 static const std::string emptyString = "";
00039
00041 Anaphe::AIDA_XMLStore::Profile1DTranslator::Profile1DTranslator(const AIDA::IProfile1D * histo, const std::string & name, const std::string & path ) :
00042 m_histo(histo), m_name(name), m_path(path)
00043 {
00044 }
00046 Anaphe::AIDA_XMLStore::Profile1DTranslator::Profile1DTranslator(const DataXML::DataObject * xmlObject) :
00047 m_element(*xmlObject)
00048 {
00049 }
00050
00051
00052 Anaphe::AIDA_XMLStore::Profile1DTranslator::~Profile1DTranslator()
00053 {
00054 }
00055
00056 Anaphe::AIDA_XMLStore::Profile1DTranslator::Profile1DTranslator(const Anaphe::AIDA_XMLStore::Profile1DTranslator &)
00057 {
00058 }
00059
00060 Anaphe::AIDA_XMLStore::Profile1DTranslator & Anaphe::AIDA_XMLStore::Profile1DTranslator::operator = (const Anaphe::AIDA_XMLStore::Profile1DTranslator &rhs)
00061 {
00062 if (this == &rhs) return *this;
00063
00064 return *this;
00065 }
00066
00067 bool Anaphe::AIDA_XMLStore::Profile1DTranslator::toXML()
00068 {
00069
00070 appendObjectHeader(m_element,"profile1d",m_name,m_histo->title(),m_path);
00071
00072 appendAnnotation(m_element,m_histo->annotation());
00073
00074 if (!setAxes() ) return false;
00075 if (!setStatistics() ) return false;
00076 if (!setData () ) return false;
00077 return true;
00078
00079 }
00080
00081 bool Anaphe::AIDA_XMLStore::Profile1DTranslator::setAxes()
00082 {
00083 appendAxis (m_element, "x", m_histo->axis());
00084 return true;
00085 }
00086
00087
00090
00091 bool Anaphe::AIDA_XMLStore::Profile1DTranslator::setStatistics()
00092 {
00093 DataXML::DataObject allStatisticsElement;
00094 allStatisticsElement.setName("statistics");
00095 allStatisticsElement.setAttribute("entries", toString(m_histo->entries()));
00096
00097
00098 appendStatistics(allStatisticsElement, "x", m_histo->mean(), m_histo->rms());
00099 m_element.appendChild(allStatisticsElement);
00100 return true;
00101 }
00102
00103
00104 bool Anaphe::AIDA_XMLStore::Profile1DTranslator::setData()
00105 {
00106
00107
00108 DataXML::DataObject dataElement;
00109 dataElement.setName("data1d");
00110 const int nbx = (m_histo->axis()).bins();
00111 for (int i = -2; i < nbx; ++i) {
00112 int entries = m_histo->binEntries(i);
00113 double height = m_histo->binHeight (i);
00114 double error = m_histo->binError (i);
00115 double binMean = m_histo->binMean (i);
00116 double rms = m_histo->binRms (i);
00117
00118 appendHisto1DBinData(dataElement, i, entries, height, error, binMean, rms );
00119 }
00120 m_element.appendChild(dataElement);
00121 return true;
00122 }
00123
00125
00126 AIDA::Dev::IDevProfile1D * Anaphe::AIDA_XMLStore::Profile1DTranslator::createFromXML(AIDA::Dev::IDevHistogramFactory& factory)
00127 {
00128
00129 std::string title, options;
00130 getObjectHeader(m_element,m_name,title,m_path,options);
00131
00132
00133 AnnotationData annoData;
00134 getAnnotation(m_element,annoData);
00135
00136
00137 int numberOfBins = 0;
00138 double lowerEdge = 0;
00139 double upperEdge = 0;
00140 std::vector<double> edges;
00141 getAxis(m_element,"x",numberOfBins,lowerEdge,upperEdge,edges);
00142
00143
00144
00145
00146 AIDA::Dev::IDevProfile1D * h = 0;
00147 if (edges.empty())
00148
00149 h = factory.createProfile1D( title, numberOfBins, lowerEdge, upperEdge );
00150 else
00151
00152 h = factory.createProfile1D( title, edges, emptyString );
00153
00154
00155
00156
00157 AIDA::IAnnotation & anno = h->annotation();
00158 setAnnotation(&anno,annoData);
00159
00160
00161
00162 const DataXML::DataObject * dataElement = m_element.getChild("data1d");
00163 if (!dataElement) return h;
00164 for (std::vector<DataXML::DataObject>::const_iterator binElement = dataElement->children().begin(); binElement != dataElement->children().end(); ++binElement) {
00165 if (binElement->name() == "bin1d") {
00166 int xbin = -999;
00167 int entries = 0;
00168 double height, error, wMean, wRms, error2, rms = 0;
00169 getHisto1DBinData(*binElement,xbin,entries,height,error,wMean,wRms,error2, rms);
00170
00171
00172 h->setBinContents(xbin,entries, height, error, rms, wMean);
00173 }
00174 }
00175
00176 return h;
00177 }