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