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 #include <iostream>
00032 #include <fstream>
00033 #include <string>
00034 #include <vector>
00035
00036 #include "AIDA/IConstants.h"
00037
00038 #include "StoreTranslator.h"
00039 #include "Histo1DTranslator.h"
00040 #include "Histo2DTranslator.h"
00041 #include "Histo3DTranslator.h"
00042 #include "Profile1DTranslator.h"
00043 #include "Profile2DTranslator.h"
00044 #include "Cloud1DTranslator.h"
00045 #include "Cloud2DTranslator.h"
00046 #include "Cloud3DTranslator.h"
00047 #include "DataPointSetTranslator.h"
00048 #include "FunctionTranslator.h"
00049 #include "TupleTranslator.h"
00050 #include "DataXML/DataObject.h"
00051 #include "DataXML/XMLStream.h"
00052
00054 Anaphe::AIDA_XMLStore::StoreTranslator::StoreTranslator( std::istream & stream )
00055 {
00056 m_inputStream = new DataXML::InputXMLStream(stream);
00057 }
00058
00059
00060 Anaphe::AIDA_XMLStore::StoreTranslator::StoreTranslator( std::ostream & stream )
00061 {
00062 m_outputStream = new DataXML::OutputXMLStream(stream);
00063
00064 appendAidaHeader(m_element);
00065 }
00066
00067 Anaphe::AIDA_XMLStore::StoreTranslator::~StoreTranslator()
00068 {
00069 if (!m_outputStream) delete m_outputStream;
00070 if (!m_inputStream) delete m_inputStream;
00071 }
00072
00073 Anaphe::AIDA_XMLStore::StoreTranslator::StoreTranslator(const Anaphe::AIDA_XMLStore::StoreTranslator &)
00074 {
00075 }
00076
00077 Anaphe::AIDA_XMLStore::StoreTranslator & Anaphe::AIDA_XMLStore::StoreTranslator::operator = (const Anaphe::AIDA_XMLStore::StoreTranslator &rhs)
00078 {
00079 if (this == &rhs) return *this;
00080
00081 return *this;
00082 }
00083
00085
00086 bool Anaphe::AIDA_XMLStore::StoreTranslator::write()
00087 {
00088
00089 writeFileHeader(m_outputStream->getDefaultStream());
00090 return m_outputStream->write(m_element);
00091
00092 }
00093
00095
00096 bool Anaphe::AIDA_XMLStore::StoreTranslator::read(DataXML::DataObject & aidaElement)
00097 {
00098
00099
00100 m_element = m_inputStream->read();
00101 if (m_element.name() == "aida") {
00102
00103 aidaElement = m_element;
00104 return true;
00105 }
00106 return false;
00107 }
00108
00109
00110
00111
00112 bool Anaphe::AIDA_XMLStore::StoreTranslator::append(const AIDA::IHistogram1D & h,
00113 const std::string& name,
00114 const std::string& path )
00115 {
00116 Anaphe::AIDA_XMLStore::Histo1DTranslator t(&h,name,path);
00117 t.toXML();
00118 m_element.appendChild(t.dataObject());
00119 return true;
00120 }
00121
00122 bool Anaphe::AIDA_XMLStore::StoreTranslator::append(const AIDA::IHistogram2D & h,
00123 const std::string& name,
00124 const std::string& path )
00125 {
00126 Anaphe::AIDA_XMLStore::Histo2DTranslator t(&h,name,path);
00127 t.toXML();
00128 m_element.appendChild(t.dataObject());
00129 return true;
00130 }
00131
00132 bool Anaphe::AIDA_XMLStore::StoreTranslator::append(const AIDA::IHistogram3D & h,
00133 const std::string& name,
00134 const std::string& path )
00135 {
00136 Anaphe::AIDA_XMLStore::Histo3DTranslator t(&h,name,path);
00137 t.toXML();
00138 m_element.appendChild(t.dataObject());
00139 return true;
00140 }
00141
00142
00143
00144 bool Anaphe::AIDA_XMLStore::StoreTranslator::append(const AIDA::ICloud1D & c,
00145 const std::string& name,
00146 const std::string& path )
00147
00148 {
00149 Anaphe::AIDA_XMLStore::Cloud1DTranslator t(&c,name,path);
00150 t.toXML();
00151 m_element.appendChild(t.dataObject());
00152 return true;
00153 }
00154
00155
00156
00157 bool Anaphe::AIDA_XMLStore::StoreTranslator::append(const AIDA::ICloud2D & c,
00158 const std::string& name,
00159 const std::string& path )
00160
00161 {
00162 Anaphe::AIDA_XMLStore::Cloud2DTranslator t(&c,name,path);
00163 t.toXML();
00164 m_element.appendChild(t.dataObject());
00165 return true;
00166 }
00167
00168
00169
00170 bool Anaphe::AIDA_XMLStore::StoreTranslator::append(const AIDA::ICloud3D & c,
00171 const std::string& name,
00172 const std::string& path )
00173
00174 {
00175 Anaphe::AIDA_XMLStore::Cloud3DTranslator t(&c,name,path);
00176 t.toXML();
00177 m_element.appendChild(t.dataObject());
00178 return true;
00179 }
00180
00181
00182
00183 bool Anaphe::AIDA_XMLStore::StoreTranslator::append(const AIDA::IProfile1D & h,
00184 const std::string& name,
00185 const std::string& path )
00186
00187 {
00188 Anaphe::AIDA_XMLStore::Profile1DTranslator t(&h,name,path);
00189 t.toXML();
00190 m_element.appendChild(t.dataObject());
00191 return true;
00192 }
00193
00194 bool Anaphe::AIDA_XMLStore::StoreTranslator::append(const AIDA::IProfile2D & h,
00195 const std::string& name,
00196 const std::string& path )
00197
00198 {
00199 Anaphe::AIDA_XMLStore::Profile2DTranslator t(&h,name,path);
00200 t.toXML();
00201 m_element.appendChild(t.dataObject());
00202 return true;
00203 }
00204
00205
00206
00207 bool Anaphe::AIDA_XMLStore::StoreTranslator::append(const AIDA::IDataPointSet & dps,
00208 const std::string& name,
00209 const std::string& path )
00210
00211 {
00212
00213 Anaphe::AIDA_XMLStore::DataPointSetTranslator t(&dps,name,path);
00214 t.toXML();
00215 m_element.appendChild(t.dataObject());
00216 return true;
00217 }
00218
00219 bool Anaphe::AIDA_XMLStore::StoreTranslator::append(const AIDA::IFunction & f,
00220 const std::string& name,
00221 const std::string& path )
00222
00223 {
00224 Anaphe::AIDA_XMLStore::FunctionTranslator t(&f,name,path);
00225 t.toXML();
00226 m_element.appendChild(t.dataObject());
00227 return true;
00228 }
00229
00230 bool Anaphe::AIDA_XMLStore::StoreTranslator::append(AIDA::ITuple & nt,
00231 const std::string& name,
00232 const std::string& path )
00233
00234 {
00235 Anaphe::AIDA_XMLStore::TupleTranslator t(&nt,name,path);
00236 t.toXML();
00237 m_element.appendChild(t.dataObject());
00238 return true;
00239 }
00240
00241
00242
00244
00245 void Anaphe::AIDA_XMLStore::StoreTranslator::writeFileHeader(std::ostream& stream) const
00246 {
00247
00248 stream << "<?xml"
00249 << " "
00250 << "version=\"" << Anaphe::AIDA_XMLStore::Translator::XML_VERSION << "\""
00251 << " "
00252 << "encoding=\"" << Anaphe::AIDA_XMLStore::Translator::ENCODING_TYPE << "\""
00253 << "?>"
00254 << std::endl;
00255 stream << "<!"
00256 << "DOCTYPE"
00257 << " " << "aida" << " "
00258 << "SYSTEM"
00259 << " " << "\"http://aida.freehep.org/schemas/" << std::string(VERSION) << "/aida.dtd\"" << " "
00260 << ">"
00261 << std::endl;
00262 }
00263