All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RHistogramCnv.h
Go to the documentation of this file.
1 // $Id: RHistogramCnv.h,v 1.4 2007/01/08 17:16:02 mato Exp $
2 #ifndef ROOTHISTCNV_RHISTOGRAMCNV_H
3 #define ROOTHISTCNV_RHISTOGRAMCNV_H 1
4 
5 // Include files
6 #include "RConverter.h"
7 #include "GaudiKernel/SmartIF.h"
13 #include "RootObjAddress.h"
14 #include "TArray.h"
15 #include <memory>
16 
17 namespace RootHistCnv {
18 
31  template<typename T,typename S,typename Q> class RHistogramCnv : public RConverter {
32  template <typename CLASS> struct TTH : public CLASS {
33  void CopyH(TObject& o) { CLASS::Copy(o); }
34  };
35  public:
37  virtual StatusCode createObj(IOpaqueAddress* pAddr, DataObject*& refpObj) {
38  refpObj = DataObjFactory::create(objType());
39  RootObjAddress *r = dynamic_cast<RootObjAddress*>(pAddr);
40  Q* h = dynamic_cast<Q*>(refpObj);
41  if ( r && h ) {
42  // Need to flip representation .... clumsy for the time being, because
43  // THXY constructor has no "generic" copy constructor
44  std::auto_ptr<T> p(new T());
45  S *s = dynamic_cast<S*>(r->tObj());
46  if ( s && p.get() ) {
47  TTH<S>* casted = (TTH<S>*)s;
48  TArray* a = dynamic_cast<TArray*>(s);
49  casted->CopyH(*p);
50  if ( 0 != a ) {
51  p->Set(a->GetSize());
52  p->Reset();
53  p->Add(s);
54  h->adoptRepresentation(p.release());
55  return StatusCode::SUCCESS;
56  }
57  }
58  }
59  return error("Cannot create histogram - invalid address.");
60  }
62  virtual StatusCode updateObj(IOpaqueAddress* /* pAddr */, DataObject* /* pObj */) {
63  return StatusCode::SUCCESS;
64  }
66  virtual TObject* createPersistent(DataObject* pObj) {
67  Q* h = dynamic_cast<Q*>(pObj);
68  if ( 0 != h ) {
69  T *r = dynamic_cast<T*>(h->representation());
70  if ( r ) {
71  T* c = new T();
72  TArray* a = dynamic_cast<TArray*>(r);
73  ((TTH<S>*)r)->CopyH(*c);
74  if ( 0 != a ) {
75  c->Set(a->GetSize());
76  c->Reset();
77  c->Add(r);
78  c->SetName(pObj->registry()->name().c_str()+1);
79  return c;
80  }
81  }
82  }
83  error("Histogram object is invalid!");
84  return 0;
85  }
87  static const CLID& classID();
90  virtual ~RHistogramCnv() {}
91  };
92 } // namespace RootHistCnv
93 #endif // ROOTHISTCNV_RHISTOGRAMCNV_H
virtual StatusCode updateObj(IOpaqueAddress *, DataObject *)
Update the transient object from the other representation.
Definition: RHistogramCnv.h:62
Root Converter.
Definition: RConverter.h:34
RHistogramCnv(ISvcLocator *svc)
Standard constructor.
Definition: RHistogramCnv.h:89
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:26
virtual StatusCode createObj(IOpaqueAddress *pAddr, DataObject *&refpObj)
Create the transient representation of an object.
Definition: RHistogramCnv.h:37
tuple c
Definition: gaudirun.py:341
virtual const name_type & name() const =0
Name of the directory (or key)
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:69
static const CLID & classID()
Inquire class type.
virtual const CLID & objType() const
Retrieve the class type of objects the converter produces.
Definition: Converter.cpp:16
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
virtual TObject * tObj() const
Retrieve TObject* ptr.
Generic converter to save/read AIDA_ROOT histograms using ROOT.
Definition: RHistogramCnv.h:31
unsigned int CLID
Class ID definition.
Definition: ClassID.h:9
virtual TObject * createPersistent(DataObject *pObj)
Create the persistent representation of the histogram object.
Definition: RHistogramCnv.h:66
StatusCode error(const std::string &msg)
Definition: RConverter.cpp:386
string s
Definition: gaudirun.py:210
Opaque address interface definition.
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:31