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

Cloud2DTranslator.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 Cloud2DTranslator
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 "Cloud2DTranslator.h"
00031 #include "AIDA/ICloud2D.h"
00032 #include "AIDA_Dev/IDevCloud2D.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::Cloud2DTranslator::Cloud2DTranslator(const AIDA::ICloud2D * 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::Cloud2DTranslator::Cloud2DTranslator(const DataXML::DataObject * xmlObject) : 
00046   m_element(*xmlObject)
00047 {
00048 }
00049 
00050 
00051 Anaphe::AIDA_XMLStore::Cloud2DTranslator::~Cloud2DTranslator() 
00052 {  // no op
00053 }
00054 
00055 Anaphe::AIDA_XMLStore::Cloud2DTranslator::Cloud2DTranslator(const Anaphe::AIDA_XMLStore::Cloud2DTranslator &)  
00056 {
00057 }
00058 
00059 Anaphe::AIDA_XMLStore::Cloud2DTranslator & Anaphe::AIDA_XMLStore::Cloud2DTranslator::operator = (const Anaphe::AIDA_XMLStore::Cloud2DTranslator &rhs) 
00060 {
00061    if (this == &rhs) return *this;  // time saving self-test
00062 
00063    return *this;
00064 }
00065 
00066 bool Anaphe::AIDA_XMLStore::Cloud2DTranslator::toXML() 
00067 { 
00068   // write name and title
00069   appendObjectHeader(m_element,"cloud2d",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::IDevCloud2D* dev_cloud = 
00073     dynamic_cast< AIDA::Dev::IDevCloud2D* >( const_cast<AIDA::ICloud2D * > (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->lowerEdgeX())); 
00079   m_element.setAttribute("upperEdgeX", toString(m_cloud->upperEdgeX())); 
00080   m_element.setAttribute("lowerEdgeY", toString(m_cloud->lowerEdgeY())); 
00081   m_element.setAttribute("upperEdgeY", toString(m_cloud->upperEdgeY())); 
00082   
00083   appendAnnotation(m_element,m_cloud->annotation()); 
00084 
00085   if (!setData () ) return false;
00086   return true;
00087 
00088 }
00089 
00090 
00091 bool Anaphe::AIDA_XMLStore::Cloud2DTranslator::setData()
00092 { 
00093   // write data element and append to the dataobject
00094 
00095   DataXML::DataObject dataElement;
00096   dataElement.setName("entries1d");
00097   const int dim = 1;
00098   const int n = m_cloud->entries(); 
00099   for (int i = 0; i < n; ++i) 
00100     appendCloudEntry(dataElement, dim,
00101                      m_cloud->valueX(i), m_cloud->valueY(i), 0,m_cloud->weight(i));
00102 
00103   m_element.appendChild(dataElement);
00104   return true;
00105 }
00106 
00108 
00109 AIDA::Dev::IDevCloud2D * Anaphe::AIDA_XMLStore::Cloud2DTranslator::createFromXML(AIDA::Dev::IDevHistogramFactory& factory)
00110 { 
00111   // read header 
00112   std::string title,options = emptyString;
00113   getObjectHeader(m_element,m_name,title,m_path,options); 
00114   int nMax = -1; 
00115   toValue(m_element.getAttributeValue("maxEntries"), nMax);
00116 
00117 
00118   // read annotation
00119   AnnotationData annoData; 
00120   getAnnotation(m_element,annoData); 
00121 
00122   // Now I can create the cloud 
00123 
00124   AIDA::Dev::IDevCloud2D * cloud  = 
00125     factory.createCloud2D( title, nMax,options );
00126 
00127   if (!cloud) { 
00128     std::cerr << " AIDA_XMLStore::Cloud2DTranslator - Cannot create Cloud2D " << std::endl; 
00129     return 0; 
00130   }
00131 
00132   //no need to  get statistics since for AIDA 
00133 
00134   // set annotation
00135   AIDA::IAnnotation & anno = cloud->annotation(); 
00136   setAnnotation(&anno,annoData); 
00137 
00138   // get the data 
00139  
00140   const DataXML::DataObject * dataElement = m_element.getChild("entries2d");
00141   if (!dataElement) return cloud; 
00142   for (std::vector<DataXML::DataObject>::const_iterator entryElement = dataElement->children().begin(); entryElement != dataElement->children().end(); ++entryElement) {  
00143     if (entryElement->name() == "entry2d") { 
00144       double xval,yval,zval = 0;    
00145       double weight = 1; 
00146       getCloudEntryData(*entryElement,1,xval,yval,zval,weight);
00147       // fill the cloud with the contents 
00148       cloud->fill(xval,yval,weight); 
00149     }
00150   }
00151 
00152   return cloud; 
00153 }
00154 

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