Gaudi Framework, version v22r2

Home   Generated: Tue May 10 2011

P2D.cpp

Go to the documentation of this file.
00001 #ifdef __ICC
00002 // disable icc remark #2259: non-pointer conversion from "X" to "Y" may lose significant bits
00003 //   TODO: To be removed, since it comes from ROOT TMathBase.h
00004 #pragma warning(disable:2259)
00005 #endif
00006 #ifdef WIN32
00007 // Disable warning
00008 //   warning C4996: 'sprintf': This function or variable may be unsafe.
00009 // coming from TString.h
00010 #pragma warning(disable:4996)
00011 #endif
00012 #include "GaudiKernel/DataObject.h"
00013 #include "GaudiKernel/ObjectFactory.h"
00014 #include "GaudiPI.h"
00015 #include "Generic2D.h"
00016 #include "TProfile2D.h"
00017 #include "TH2D.h"
00018 
00019 namespace Gaudi {
00020 
00027   class GAUDI_API Profile2D : public DataObject, public Generic2D<AIDA::IProfile2D,TProfile2D>   {
00028   public:
00030     Profile2D() {
00031       m_classType = "IProfile2D";
00032       m_rep = new TProfile2D();
00033       m_rep->SetErrorOption("s");
00034       m_rep->SetDirectory(0);
00035       m_sumEntries = 0;
00036     }
00038     Profile2D(TProfile2D* rep);
00040     virtual ~Profile2D()  {}
00042     bool fill(double x,double y,double z,double weight)  {
00043       m_rep->Fill(x,y,z,weight);
00044       return true;
00045     }
00047     virtual const CLID& clID() const { return Gaudi::Profile2D::classID(); }
00048     static const CLID& classID()     { return CLID_ProfileH2; }
00049   };
00050 }
00051 
00052 namespace Gaudi {
00053   template <>
00054   void* Generic2D<AIDA::IProfile2D,TProfile2D>::cast(const std::string& className) const  {
00055     if (className == "AIDA::IProfile2D")
00056       return const_cast<AIDA::IProfile2D*>((AIDA::IProfile2D*)this);
00057     else if (className == "AIDA::IProfile")
00058       return const_cast<AIDA::IProfile*>((AIDA::IProfile*)this);
00059     else if (className == "AIDA::IBaseHistogram")
00060       return const_cast<AIDA::IBaseHistogram*>((AIDA::IBaseHistogram*)this);
00061     return 0;
00062   }
00063 
00064   template <>
00065   int  Generic2D<AIDA::IProfile2D,TProfile2D>::binEntries(int idX, int idY) const  {
00066     int rBin = m_rep->GetBin(rIndexX(idX),rIndexY(idY));
00067     return int(m_rep->GetBinEntries(rBin)+0.5);
00068   }
00069 
00070   template <>
00071   void Generic2D<AIDA::IProfile2D,TProfile2D>::adoptRepresentation(TObject* rep) {
00072     TProfile2D* imp = dynamic_cast<TProfile2D*>(rep);
00073     if ( imp )  {
00074       if ( m_rep ) delete m_rep;
00075       m_rep = imp;
00076       m_xAxis.initialize(m_rep->GetXaxis(),true);
00077       m_yAxis.initialize(m_rep->GetYaxis(),true);
00078       setTitle(m_rep->GetTitle());
00079       return;
00080     }
00081     throw std::runtime_error("Cannot adopt native histogram representation.");
00082   }
00083 }
00084 
00085 std::pair<DataObject*,AIDA::IProfile2D*> Gaudi::createProf2D(const std::string& title, const Edges& eX, const Edges& eY, double /* zlow */ , double /* zup */) {
00086   // Not implemented in ROOT! Can only use TProfile2D with no z-limits
00087   Profile2D* p = new Profile2D(new TProfile2D(title.c_str(),title.c_str(),eX.size()-1,&eX.front(), eY.size()-1,&eY.front()/*,zlow,zup */));
00088   return std::pair<DataObject*,AIDA::IProfile2D*>(p,p);
00089 }
00090 
00091 std::pair<DataObject*,AIDA::IProfile2D*>
00092 Gaudi::createProf2D(const std::string& title,int binsX,double xlow,double xup,int binsY,double ylow,double yup,double zlow,double zup) {
00093   Profile2D* p = new Profile2D(new TProfile2D(title.c_str(),title.c_str(),binsX,xlow,xup,binsY,ylow,yup,zlow,zup));
00094   return std::pair<DataObject*,AIDA::IProfile2D*>(p,p);
00095 }
00096 
00097 std::pair<DataObject*,AIDA::IProfile2D*> Gaudi::createProf2D(const AIDA::IProfile2D& hist)  {
00098   TProfile2D *h = getRepresentation<AIDA::IProfile2D,TProfile2D>(hist);
00099   Profile2D *n = h ? new Profile2D(new TProfile2D(*h)) : 0;
00100   return std::pair<DataObject*,AIDA::IProfile2D*>(n,n);
00101 }
00102 
00103 Gaudi::Profile2D::Profile2D(TProfile2D* rep)    {
00104   m_rep = 0;
00105   m_classType = "IProfile2D";
00106   rep->SetDirectory(0);
00107   adoptRepresentation(rep);
00108   m_sumEntries = 0;
00109 }
00110 
00111 typedef Gaudi::Profile2D P2D;
00112 DECLARE_DATAOBJECT_FACTORY(P2D)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Tue May 10 2011 18:53:59 for Gaudi Framework, version v22r2 by Doxygen version 1.7.2 written by Dimitri van Heesch, © 1997-2004