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 "DataPointSetTranslator.h"
00031 #include "AIDA/IMeasurement.h"
00032 #include "AIDA/IDataPoint.h"
00033 #include "AIDA/IDataPointSet.h"
00034 #include "AIDA_Dev/IDevDataPointSet.h"
00035 #include "AIDA_Dev/IDevDataPointSetFactory.h"
00036 #include "DataXML/DataObject.h"
00037
00038 static const std::string emptyString = "";
00039
00041 Anaphe::AIDA_XMLStore::DataPointSetTranslator::DataPointSetTranslator(const AIDA::IDataPointSet * dataSet, const std::string & name, const std::string & path ) :
00042 m_dataset(dataSet), m_name(name), m_path(path)
00043 {
00044 }
00046 Anaphe::AIDA_XMLStore::DataPointSetTranslator::DataPointSetTranslator(const DataXML::DataObject * xmlObject) :
00047 m_element(*xmlObject)
00048 {
00049 }
00050
00051
00052 Anaphe::AIDA_XMLStore::DataPointSetTranslator::~DataPointSetTranslator()
00053 {
00054 }
00055
00056 Anaphe::AIDA_XMLStore::DataPointSetTranslator::DataPointSetTranslator(const Anaphe::AIDA_XMLStore::DataPointSetTranslator &)
00057 {
00058 }
00059
00060 Anaphe::AIDA_XMLStore::DataPointSetTranslator & Anaphe::AIDA_XMLStore::DataPointSetTranslator::operator = (const Anaphe::AIDA_XMLStore::DataPointSetTranslator &rhs)
00061 {
00062 if (this == &rhs) return *this;
00063
00064 return *this;
00065 }
00066
00067 bool Anaphe::AIDA_XMLStore::DataPointSetTranslator::toXML()
00068 {
00069
00070 appendObjectHeader(m_element,"dataPointSet",m_name,m_dataset->title(),m_path);
00071
00072 m_element.setAttribute("dimension", toString(m_dataset->dimension()));
00073
00074 appendAnnotation(m_element,m_dataset->annotation());
00075
00076 if (!setData () ) return false;
00077 return true;
00078
00079 }
00080
00081
00082 bool Anaphe::AIDA_XMLStore::DataPointSetTranslator::setData()
00083 {
00084
00085 for (int i = 0; i < m_dataset->size(); ++i) {
00086
00087 DataXML::DataObject dataElement;
00088 dataElement.setName("dataPoint");
00089
00090 const AIDA::IDataPoint * point = m_dataset->point(i);
00091
00092 for (int j = 0; j < point->dimension(); ++j) {
00093 const AIDA::IMeasurement* m = point->coordinate( j );
00094
00095 appendDataPointMeasurement(dataElement,m->value(),
00096 m->errorPlus(),m->errorMinus() );
00097 }
00098 m_element.appendChild(dataElement);
00099 }
00100 return true;
00101 }
00102
00104
00105 AIDA::Dev::IDevDataPointSet * Anaphe::AIDA_XMLStore::DataPointSetTranslator::createFromXML(AIDA::Dev::IDevDataPointSetFactory& factory)
00106 {
00107
00108 std::string title, options;
00109 getObjectHeader(m_element,m_name,title,m_path,options);
00110
00111 int dimension = 0;
00112 toValue(m_element.getAttributeValue("dimension"), dimension);
00113
00114
00115 AnnotationData annoData;
00116 getAnnotation(m_element,annoData);
00117
00118
00119
00120 AIDA::Dev::IDevDataPointSet * dpSet = 0;
00121
00122 if (title.empty())
00123 dpSet = factory.create( dimension );
00124 else
00125 dpSet = factory.create( title, dimension );
00126
00127
00128 AIDA::IAnnotation & anno = dpSet->annotation();
00129 setAnnotation(&anno,annoData);
00130
00131
00132 int iPoint = 0;
00133 for (std::vector<DataXML::DataObject>::const_iterator dpElement = m_element.children().begin(); dpElement != m_element.children().end(); ++dpElement) {
00134 if (dpElement->name() == "dataPoint") {
00135
00136 dpSet->addPoint();
00137 AIDA::IDataPoint* point = dpSet->point( iPoint );
00138 iPoint++;
00139
00140 int dim = 0;
00141
00142 int n = dpElement->children().size();
00143 if (n != dpSet->dimension() ) {
00144 std::cerr << "DataPointSetTranslator:: Invalid dataPoint dimension in XML file " << std::endl;
00145 return 0;
00146 }
00147 for (std::vector<DataXML::DataObject>::const_iterator m = dpElement->children().begin(); m != dpElement->children().end(); ++m) {
00148 if (m->name() == "measurement") {
00149 if (dim >= dpSet->dimension() ) return 0;
00150 AIDA::IMeasurement* measurement = point->coordinate( dim );
00151 double value,eplus,eminus = 0;
00152 getDataPointMeasurement(*m,value,eplus,eminus);
00153
00154 measurement->setValue(value);
00155 measurement->setErrorPlus(eplus);
00156 measurement->setErrorMinus(eminus);
00157 dim++;
00158 }
00159 }
00160 }
00161 }
00162 return dpSet;
00163 }
00164