| # Gaudi Framework, version v21r10p1 |

Home |  | Generated: 29 Jul 2010

# RHistogramCnv.h

Go to the documentation of this file.

    00001 // $Id: RHistogramCnv.h,v 1.4 2007/01/08 17:16:02 mato Exp $
    00002 #ifndef ROOTHISTCNV_RHISTOGRAMCNV_H
    00003 #define ROOTHISTCNV_RHISTOGRAMCNV_H 1
    00004
    00005 // Include files
    00006 #include "RConverter.h"
    00007 #include "GaudiKernel/SmartIF.h"
    00008 #include "GaudiKernel/DataObject.h"
    00009 #include "GaudiKernel/IRegistry.h"
    00010 #include "GaudiKernel/IOpaqueAddress.h"
    00011 #include "GaudiKernel/HistogramBase.h"
    00012 #include "RootObjAddress.h"
    00013 #include "TArray.h"
    00014 #include <memory>
    00015
    00016 namespace RootHistCnv {
    00017
    00030   template<typename T,typename S,typename Q> class RHistogramCnv : public RConverter {
    00031     template <typename CLASS> struct TTH : public CLASS {
    00032       void CopyH(TObject& o) { CLASS::Copy(o); }
    00033     };
    00034   public:
    00036     virtual StatusCode createObj(IOpaqueAddress* pAddr, DataObject*& refpObj) {
    00037       refpObj = ROOT::Reflex::PluginService::CreateWithId<DataObject*>(objType());
    00038       RootObjAddress *r = dynamic_cast<RootObjAddress*>(pAddr);
    00039       Q* h = dynamic_cast<Q*>(refpObj);
    00040       if ( r && h )   {
    00041         // Need to flip representation .... clumsy for the time being, because
    00042         // THXY constructor has no "generic" copy constructor
    00043         std::auto_ptr<T> p(new T());
    00044         S *s = dynamic_cast<S*>(r->tObj());
    00045         if ( s && p.get() )  {
    00046           TTH<S>* casted = (TTH<S>*)s;
    00047           TArray* a = dynamic_cast<TArray*>(s);
    00048           casted->CopyH(*p);
    00049           if ( 0 != a )  {
    00050             p->Set(a->GetSize());
    00051             p->Reset();
    00052             p->Add(s);
    00053             h->adoptRepresentation(p.release());
    00054             return StatusCode::SUCCESS;
    00055           }
    00056         }
    00057       }
    00058       return error("Cannot create histogram - invalid address.");
    00059     }
    00061     virtual StatusCode updateObj(IOpaqueAddress* /* pAddr */, DataObject* /* pObj */)  {
    00062       return StatusCode::SUCCESS;
    00063     }
    00065     virtual TObject* createPersistent(DataObject* pObj)   {
    00066       Q* h = dynamic_cast<Q*>(pObj);
    00067       if ( 0 != h ) {
    00068         T *r = dynamic_cast<T*>(h->representation());
    00069         if ( r )   {
    00070           T* c = new T();
    00071           TArray* a = dynamic_cast<TArray*>(r);
    00072           ((TTH<S>*)r)->CopyH(*c);
    00073           if ( 0 != a )  {
    00074             c->Set(a->GetSize());
    00075             c->Reset();
    00076             c->Add(r);
    00077             c->SetName(pObj->registry()->name().c_str()+1);
    00078             return c;
    00079           }
    00080         }
    00081       }
    00082       error("Histogram object is invalid!");
    00083       return 0;
    00084     }
    00086     static const CLID& classID();
    00088     RHistogramCnv(ISvcLocator* svc) : RConverter(classID(), svc) {}
    00089     virtual ~RHistogramCnv() {}
    00090   };
    00091 }       // namespace RootHistCnv
    00092 #endif  // ROOTHISTCNV_RHISTOGRAMCNV_H