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

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

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