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

DataPointSetTranslator.cpp

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 // Implementation file for class DataPointSetTranslator
00024 // 
00025 // Created by: moneta  at Mon Sep 23 09:54:17 2002
00026 // 
00027 // Last update: Mon Sep 23 09:54:17 2002
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 {  // no op
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;  // time saving self-test
00063 
00064    return *this;
00065 }
00066 
00067 bool Anaphe::AIDA_XMLStore::DataPointSetTranslator::toXML() 
00068 { 
00069   // write name and title
00070   appendObjectHeader(m_element,"dataPointSet",m_name,m_dataset->title(),m_path); 
00071   // for datapointset dimensions are needed...
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   // loop on all data point in the set 
00085   for (int i = 0; i < m_dataset->size(); ++i) { 
00086     // write data element and append to the dataobject
00087     DataXML::DataObject dataElement;
00088     dataElement.setName("dataPoint");
00089     // get the point 
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       // write data element and app; ++i) 
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   // read header 
00108   std::string title, options;
00109   getObjectHeader(m_element,m_name,title,m_path,options); 
00110   // get dimensions of the points 
00111   int dimension = 0; 
00112   toValue(m_element.getAttributeValue("dimension"), dimension);
00113 
00114   // read annotation
00115   AnnotationData annoData; 
00116   getAnnotation(m_element,annoData); 
00117 
00118   // Now I can create the data point set  
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   // set annotation
00128   AIDA::IAnnotation & anno = dpSet->annotation(); 
00129   setAnnotation(&anno,annoData); 
00130  
00131   // loop on the data points in the set   
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       // add point to the set 
00136       dpSet->addPoint(); 
00137       AIDA::IDataPoint* point = dpSet->point( iPoint );
00138       iPoint++;
00139       // loop on measurements
00140       int dim = 0; 
00141       // check if dimension in file is not different than what is written
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           // set new values 
00154           measurement->setValue(value); 
00155           measurement->setErrorPlus(eplus); 
00156           measurement->setErrorMinus(eminus); 
00157           dim++; 
00158         }         
00159       }
00160     }
00161   }
00162   return dpSet; 
00163 }
00164 

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