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 TupleTranslator 00024 // 00025 // Created by: moneta at Thu Sep 12 10:41:06 2002 00026 // 00027 // Last update: Thu Sep 12 10:41:06 2002 00028 // 00029 00030 /* 00031 * class containing methods to transfrom a 1D Cloud to and from XML 00032 * using DataXML library. 00033 * When translating to XML the class it is constructed using 00034 * AIDA Tuple plus name and path and creates a DataXML::DataObject. 00035 * The DataObject is filled with all histogram information when the 00036 * toXML() methos is called, and the data object is returned using the 00037 * dataObject() method. 00038 * Transforming from XML, the class is constructed using a 00039 * DataXML::DataObject in the constructor and method createFromXML 00040 * takes an AIDA::Dev::IDevCloudFactory to create the corresponding 00041 * AIDA Cloud 00042 * The helper methods used to transfrom to/from XML are in the base class 00043 * Translator since are used also by the other AIDA objects. 00044 * 00045 */ 00046 00047 #ifndef TUPLETRANSLATOR 00048 #define TUPLETRANSLATOR 1 00049 00050 #include "Translator.h" 00051 #include <string> 00052 00053 #include "DataXML/DataObject.h" 00054 00055 namespace AIDA { 00056 class ITuple; 00057 namespace Dev { 00058 class IDevTuple; 00059 class IDevTupleFactory; 00060 } 00061 } 00062 00063 namespace Anaphe { 00064 namespace AIDA_XMLStore { 00065 00066 00067 class TupleTranslator : public Translator { 00068 00069 public: 00070 // constructor for writing 00071 TupleTranslator(AIDA::ITuple * tuple, const std::string & name, const std::string & path ); 00072 // constructor for reading 00073 TupleTranslator(const DataXML::DataObject * element); 00074 00075 virtual ~TupleTranslator(); 00076 00077 private: 00078 // usually copying is non trivial, so we make this unaccessible 00079 TupleTranslator(const TupleTranslator &); 00080 TupleTranslator & operator = (const TupleTranslator &); 00081 00082 public: 00083 00084 00085 DataXML::DataObject & dataObject() { return m_element; } 00086 const AIDA::ITuple * histo() { return m_tuple; } 00087 const std::string & name() { return m_name; } 00088 const std::string & path() { return m_path; } 00089 00091 bool toXML(); 00093 AIDA::Dev::IDevTuple * createFromXML(AIDA::Dev::IDevTupleFactory& factory); 00094 00095 protected: 00096 00097 00098 00099 00100 00101 private: 00102 00103 // private methods 00104 bool setData(); 00105 bool setHeader(); 00106 void appendRow(DataXML::DataObject & parElement, AIDA::ITuple * tuple); 00107 00108 template <class T> 00109 bool appendTupleEntry(DataXML::DataObject & dataElement, T value); 00110 00111 00113 00115 DataXML::DataObject m_element; 00117 AIDA::ITuple * m_tuple; 00119 std::string m_name; 00121 std::string m_path; 00122 }; 00123 00124 00125 00126 } // end of namespace Anaphe::AIDA_XMLStore 00127 } 00128 00129 #endif /* TUPLETRANSLATOR */