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

Cloud1DTranslator.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 Cloud1DTranslator
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 #include "Cloud1DTranslator.h"
00031 #include "AIDA/ICloud1D.h"
00032 #include "AIDA_Dev/IDevCloud1D.h"
00033 #include "AIDA_Dev/IDevHistogramFactory.h"
00034 
00035 #include "DataXML/DataObject.h"
00036 
00037 static const std::string emptyString = "";
00038 
00040 Anaphe::AIDA_XMLStore::Cloud1DTranslator::Cloud1DTranslator(const AIDA::ICloud1D * cloud, const std::string & name, const std::string & path ) : 
00041   m_cloud(cloud), m_name(name), m_path(path)
00042 {
00043 }
00045 Anaphe::AIDA_XMLStore::Cloud1DTranslator::Cloud1DTranslator(const DataXML::DataObject * xmlObject) : 
00046   m_element(*xmlObject)
00047 {
00048 }
00049 
00050 
00051 Anaphe::AIDA_XMLStore::Cloud1DTranslator::~Cloud1DTranslator() 
00052 {  // no op
00053 }
00054 
00055 Anaphe::AIDA_XMLStore::Cloud1DTranslator::Cloud1DTranslator(const Anaphe::AIDA_XMLStore::Cloud1DTranslator &)  
00056 {
00057 }
00058 
00059 Anaphe::AIDA_XMLStore::Cloud1DTranslator & Anaphe::AIDA_XMLStore::Cloud1DTranslator::operator = (const Anaphe::AIDA_XMLStore::Cloud1DTranslator &rhs) 
00060 {
00061    if (this == &rhs) return *this;  // time saving self-test
00062 
00063    return *this;
00064 }
00065 
00066 bool Anaphe::AIDA_XMLStore::Cloud1DTranslator::toXML() 
00067 { 
00068   // write name and title
00069   appendObjectHeader(m_element,"cloud1d",m_name,m_cloud->title(),m_path); 
00070   // extra stuff for clouds (maxentries + lower/upper edge
00071   // for max entries a dev 
00072   AIDA::Dev::IDevCloud1D* dev_cloud = 
00073     dynamic_cast< AIDA::Dev::IDevCloud1D* >( const_cast<AIDA::ICloud1D * > (m_cloud ));
00074   
00075   if ( !dev_cloud ) return false;     
00076   m_element.setAttribute("maxEntries", toString(static_cast<int>(dev_cloud->cacheSize() ))); 
00077   // lower and uppper edges                                              
00078   m_element.setAttribute("lowerEdgeX", toString(m_cloud->lowerEdge())); 
00079   m_element.setAttribute("upperEdgeX", toString(m_cloud->upperEdge())); 
00080   
00081   appendAnnotation(m_element,m_cloud->annotation()); 
00082 
00083   if (!setData () ) return false;
00084   return true;
00085 
00086 }
00087 
00088 
00089 bool Anaphe::AIDA_XMLStore::Cloud1DTranslator::setData()
00090 { 
00091   // write data element and append to the dataobject
00092 
00093   DataXML::DataObject dataElement;
00094   dataElement.setName("entries1d");
00095   const int dim = 1;
00096   const int n = m_cloud->entries(); 
00097   for (int i = 0; i < n; ++i) 
00098     appendCloudEntry(dataElement, dim,
00099                      m_cloud->value(i), 0, 0,m_cloud->weight(i));
00100 
00101   m_element.appendChild(dataElement);
00102   return true;
00103 }
00104 
00106 
00107 AIDA::Dev::IDevCloud1D * Anaphe::AIDA_XMLStore::Cloud1DTranslator::createFromXML(AIDA::Dev::IDevHistogramFactory& factory)
00108 { 
00109   // read header 
00110   std::string title,options = emptyString;
00111   getObjectHeader(m_element,m_name,title,m_path,options); 
00112   int nMax = -1; 
00113   toValue(m_element.getAttributeValue("maxEntries"), nMax);
00114 
00115 
00116   // read annotation
00117   AnnotationData annoData; 
00118   getAnnotation(m_element,annoData); 
00119 
00120   // Now I can create the cloud 
00121 
00122   AIDA::Dev::IDevCloud1D * cloud  = 
00123     factory.createCloud1D( title, nMax,options );
00124 
00125   if (!cloud) { 
00126     std::cerr << " AIDA_XMLStore::Cloud1DTranslator - Cannot create Cloud1D " << std::endl; 
00127     return 0; 
00128   }
00129 
00130   //no need to  get statistics since for AIDA 
00131 
00132   // set annotation
00133   AIDA::IAnnotation & anno = cloud->annotation(); 
00134   setAnnotation(&anno,annoData); 
00135 
00136   // get the data 
00137  
00138   const DataXML::DataObject * dataElement = m_element.getChild("entries1d");
00139   if (!dataElement) return cloud; 
00140   //int i = 0; 
00141   //cout << " Number of elements " << dataElement->children().size() << endl; 
00142   for (std::vector<DataXML::DataObject>::const_iterator entryElement = dataElement->children().begin(); entryElement != dataElement->children().end(); ++entryElement) {  
00143     // need to check on the name to eliminate white spaces
00144     if (entryElement->name() == "entry1d") { 
00145       double xval,yval,zval = 0;    
00146       double weight = 1; 
00147       getCloudEntryData(*entryElement,1,xval,yval,zval,weight);
00148       // fill the cloud with the contents 
00149       //cout << " entry " << entryElement->name() << " " << i << " x " << xval << " w " << weight << endl; 
00150       cloud->fill(xval,weight); 
00151       //i++;
00152     }
00153   }
00154 
00155   //  std::cout << " cloud entries = " << cloud->entries() << endl; 
00156 
00157   return cloud; 
00158 }

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