The Gaudi Framework  v30r3 (a5ef0a68)
RHistogramCnv.h
Go to the documentation of this file.
1 #ifndef ROOTHISTCNV_RHISTOGRAMCNV_H
2 #define ROOTHISTCNV_RHISTOGRAMCNV_H 1
3 
4 // Include files
10 #include "GaudiKernel/SmartIF.h"
11 #include "RConverter.h"
12 #include "RootObjAddress.h"
13 #include "TArray.h"
14 #include <memory>
15 
16 namespace RootHistCnv
17 {
18 
31  template <typename T, typename S, typename Q>
32  class RHistogramCnv : public RConverter
33  {
34  template <typename CLASS>
35  struct TTH : public CLASS {
36  void CopyH( TObject& o ) { CLASS::Copy( o ); }
37  };
38 
39  public:
41  StatusCode createObj( IOpaqueAddress* pAddr, DataObject*& refpObj ) override
42  {
43  refpObj = DataObjFactory::create( objType() ).release();
44  RootObjAddress* r = dynamic_cast<RootObjAddress*>( pAddr );
45  Q* h = dynamic_cast<Q*>( refpObj );
46  if ( r && h ) {
47  // Need to flip representation .... clumsy for the time being, because
48  // THXY constructor has no "generic" copy constructor
49  auto p = std::make_unique<T>();
50  S* s = dynamic_cast<S*>( r->tObj() );
51  if ( s && p.get() ) {
52  TTH<S>* casted = (TTH<S>*)s;
53  TArray* a = dynamic_cast<TArray*>( s );
54  casted->CopyH( *p );
55  if ( 0 != a ) {
56  p->Set( a->GetSize() );
57  p->Reset();
58  p->Add( s );
59  h->adoptRepresentation( p.release() );
60  return StatusCode::SUCCESS;
61  }
62  }
63  }
64  return error( "Cannot create histogram - invalid address." );
65  }
67  StatusCode updateObj( IOpaqueAddress* /* pAddr */, DataObject* /* pObj */ ) override { return StatusCode::SUCCESS; }
69  TObject* createPersistent( DataObject* pObj ) override
70  {
71  Q* h = dynamic_cast<Q*>( pObj );
72  if ( 0 != h ) {
73  T* r = dynamic_cast<T*>( h->representation() );
74  if ( r ) {
75  T* c = new T();
76  TArray* a = dynamic_cast<TArray*>( r );
77  ( (TTH<S>*)r )->CopyH( *c );
78  if ( 0 != a ) {
79  c->Set( a->GetSize() );
80  c->Reset();
81  c->Add( r );
82  c->SetName( pObj->registry()->name().c_str() + 1 );
83  return c;
84  }
85  }
86  }
87  error( "Histogram object is invalid!" );
88  return 0;
89  }
91  static const CLID& classID();
93  RHistogramCnv( ISvcLocator* svc ) : RConverter( classID(), svc ) {}
94  };
95 } // namespace RootHistCnv
96 #endif // ROOTHISTCNV_RHISTOGRAMCNV_H
Root Converter.
Definition: RConverter.h:33
RHistogramCnv(ISvcLocator *svc)
Standard constructor.
Definition: RHistogramCnv.h:93
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:13
TObject * createPersistent(DataObject *pObj) override
Create the persistent representation of the histogram object.
Definition: RHistogramCnv.h:69
virtual const name_type & name() const =0
Name of the directory (or key)
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:73
static const CLID & classID()
Inquire class type.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
virtual TObject * tObj() const
Retrieve TObject* ptr.
Generic converter to save/read AIDA_ROOT histograms using ROOT.
Definition: RHistogramCnv.h:32
unsigned int CLID
Class ID definition.
Definition: ClassID.h:8
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
virtual unsigned long release()
release reference to object
Definition: DataObject.cpp:51
StatusCode error(const std::string &msg)
Definition: RConverter.cpp:337
T c_str(T...args)
string s
Definition: gaudirun.py:253
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:67
StatusCode createObj(IOpaqueAddress *pAddr, DataObject *&refpObj) override
Create the transient representation of an object.
Definition: RHistogramCnv.h:41