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

Histo3DTranslator.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 Histo3DTranslator
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 "Histo3DTranslator.h"
00031 #include "AIDA/IHistogram3D.h"
00032 #include "AIDA_Dev/IDevHistogram3D.h"
00033 #include "AIDA_Dev/IDevHistogramFactory.h"
00034 #include "AIDA/IAxis.h"
00035 
00036 #include "DataXML/DataObject.h"
00037 
00038 static const std::string emptyString = "";
00039 
00041 Anaphe::AIDA_XMLStore::Histo3DTranslator::Histo3DTranslator(const AIDA::IHistogram3D * histo, const std::string & name, const std::string & path ) : 
00042   m_histo(histo), m_name(name), m_path(path)
00043 {
00044 }
00046 Anaphe::AIDA_XMLStore::Histo3DTranslator::Histo3DTranslator(const DataXML::DataObject * xmlObject) : 
00047   m_element(*xmlObject)
00048 {
00049 }
00050 
00051 
00052 Anaphe::AIDA_XMLStore::Histo3DTranslator::~Histo3DTranslator() 
00053 {  // no op
00054 }
00055 
00056 Anaphe::AIDA_XMLStore::Histo3DTranslator::Histo3DTranslator(const Anaphe::AIDA_XMLStore::Histo3DTranslator &)  
00057 {
00058 }
00059 
00060 Anaphe::AIDA_XMLStore::Histo3DTranslator & Anaphe::AIDA_XMLStore::Histo3DTranslator::operator = (const Anaphe::AIDA_XMLStore::Histo3DTranslator &rhs) 
00061 {
00062    if (this == &rhs) return *this;  // time saving self-test
00063 
00064    return *this;
00065 }
00066 
00067 bool Anaphe::AIDA_XMLStore::Histo3DTranslator::toXML() 
00068 { 
00069   // write name and title
00070   appendObjectHeader(m_element,"histogram3d",m_name,m_histo->title(),m_path); 
00071 
00072   appendAnnotation(m_element,m_histo->annotation()); 
00073   if (!setAxes() ) return false;
00074   if (!setStatistics() ) return false;
00075   if (!setData () ) return false;
00076   return true;
00077 
00078 }
00079 
00080 bool Anaphe::AIDA_XMLStore::Histo3DTranslator::setAxes()
00081 { 
00082   appendAxis (m_element, "x", m_histo->xAxis());
00083   appendAxis (m_element, "y", m_histo->yAxis());
00084   appendAxis (m_element, "z", m_histo->zAxis());
00085   return true;
00086 }
00087 
00088 
00091 
00092 bool Anaphe::AIDA_XMLStore::Histo3DTranslator::setStatistics()
00093 { 
00094   DataXML::DataObject allStatisticsElement;
00095   allStatisticsElement.setName("statistics");
00096   allStatisticsElement.setAttribute("entries", toString(m_histo->entries()));
00097 
00098   // append the statistics info
00099   appendStatistics(allStatisticsElement, "x", m_histo->meanX(), m_histo->rmsX());
00100   appendStatistics(allStatisticsElement, "y", m_histo->meanY(), m_histo->rmsY());
00101   appendStatistics(allStatisticsElement, "z", m_histo->meanZ(), m_histo->rmsZ());
00102   m_element.appendChild(allStatisticsElement);
00103   return true;
00104 }
00105 
00106 
00107 bool Anaphe::AIDA_XMLStore::Histo3DTranslator::setData()
00108 { 
00109   // write data element and append to the dataobject
00110 
00111   DataXML::DataObject dataElement;
00112   dataElement.setName("data2d");
00113   const int nbx = (m_histo->xAxis()).bins();
00114   const int nby = (m_histo->yAxis()).bins();
00115   const int nbz = (m_histo->zAxis()).bins();
00116   for (int i = -2; i < nbx; ++i) {
00117     for (int j = -2; j < nby; ++j ) { 
00118       for (int k = -2; k < nbz; ++j ) { 
00119         int    entries = m_histo->binEntries(i,j,k);
00120         double height  = m_histo->binHeight (i,j,k);
00121         double error   = m_histo->binError  (i,j,k);
00122         double binMeanX = m_histo->binMeanX   (i,j,k);
00123         double binMeanY = m_histo->binMeanY   (i,j,k);
00124         double binMeanZ = m_histo->binMeanZ   (i,j,k);
00125         appendHisto3DBinData(dataElement, i, j, k, entries, height, error, binMeanX, binMeanY, binMeanZ);
00126       }
00127     }
00128   }
00129   m_element.appendChild(dataElement);
00130   return true;
00131 }
00132 
00134 
00135 AIDA::Dev::IDevHistogram3D * Anaphe::AIDA_XMLStore::Histo3DTranslator::createFromXML(AIDA::Dev::IDevHistogramFactory& factory)
00136 { 
00137   // read header 
00138   std::string title, options;
00139   getObjectHeader(m_element,m_name,title,m_path,options); 
00140 
00141   // read annotation
00142   AnnotationData annoData; 
00143   getAnnotation(m_element,annoData); 
00144 
00145   // read axis
00146   int numberOfBinsX = 0;
00147   double lowerEdgeX = 0;
00148   double upperEdgeX = 0;
00149   std::vector<double> edgesX; 
00150   getAxis(m_element,"x",numberOfBinsX,lowerEdgeX,upperEdgeX,edgesX); 
00151   int numberOfBinsY = 0;
00152   double lowerEdgeY = 0;
00153   double upperEdgeY = 0;
00154   std::vector<double> edgesY; 
00155   getAxis(m_element,"y",numberOfBinsY,lowerEdgeY,upperEdgeY,edgesY); 
00156   int numberOfBinsZ = 0;
00157   double lowerEdgeZ = 0;
00158   double upperEdgeZ = 0;
00159   std::vector<double> edgesZ; 
00160   getAxis(m_element,"z",numberOfBinsZ,lowerEdgeZ,upperEdgeZ,edgesZ); 
00161 
00162 
00163   // Now I can create the histogram 
00164 
00165   AIDA::Dev::IDevHistogram3D * h = 0; 
00166   if (edgesX.empty() )  
00167     // equal bins histograms
00168     h = factory.createHistogram3D( title, numberOfBinsX, lowerEdgeX, upperEdgeX, numberOfBinsY, lowerEdgeY, upperEdgeY, numberOfBinsZ, lowerEdgeZ, upperEdgeZ );
00169   else   
00170     // variable bins histograms 
00171     h = factory.createHistogram3D( title, edgesX, edgesY, edgesZ, emptyString );
00172 
00173   //read statistics (rms is needed since no binRMs is stored) 
00174   double rmsX,rmsY,rmsZ = 0; 
00175   const DataXML::DataObject * statElement = m_element.getChild("statistics");
00176   if (statElement) { 
00177     double mean,skew = 0; // not used 
00178     getStatistics(*statElement,"x",mean,rmsX,skew); 
00179     getStatistics(*statElement,"y",mean,rmsY,skew); 
00180     getStatistics(*statElement,"z",mean,rmsZ,skew); 
00181   }
00182 
00183   // set annotation
00184   AIDA::IAnnotation & anno = h->annotation(); 
00185   setAnnotation(&anno,annoData); 
00186 
00187   // get the data 
00188  
00189   const DataXML::DataObject * dataElement = m_element.getChild("data3d");
00190   if (dataElement) { 
00191     for (std::vector<DataXML::DataObject>::const_iterator binElement = dataElement->children().begin(); binElement != dataElement->children().end(); ++binElement) {  
00192       if (binElement->name() == "bin3d") { 
00193         int xbin,ybin, zbin = -999;    // just a number which is not used 
00194         int entries = 0;
00195         // get info (not all is used..) 
00196         double height, error, wMeanX, wMeanY, wMeanZ, wRmsX, wRmsY, wRmsZ, error2, rms = 0; 
00197         getHisto3DBinData(*binElement,xbin,ybin,zbin,entries,height,error,wMeanX,wMeanY,wMeanZ,wRmsX,wRmsY,wRmsZ, error2, rms); 
00198         // fill the histogram with the bin contents 
00199         // (assume that binMean(centre) is defined) 
00200         h->setBinContents(xbin,ybin,zbin,entries, height, error, wMeanX, wMeanY,wMeanZ); 
00201       }
00202     }
00203   }
00204   h->setRms(rmsX,rmsY,rmsZ);
00205 
00206   return h; 
00207 }

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