Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
30  template <typename T, typename S, typename Q>
31  class RHistogramCnv : public RConverter {
32  template <typename CLASS>
33  class TTH {
34  public:
35  template <typename INPUT>
36  TTH( INPUT* i ) : m_c( dynamic_cast<CLASS*>( i ) ) {}
37  template <typename INPUT>
38  bool CopyH( INPUT& i ) {
39  if ( m_c ) { m_c->Copy( i ); }
40  return m_c != nullptr;
41  }
42 
43  private:
44  CLASS* m_c = nullptr;
45  };
46 
47  public:
49  StatusCode createObj( IOpaqueAddress* pAddr, DataObject*& refpObj ) override {
50  refpObj = DataObjFactory::create( objType() ).release();
51  RootObjAddress* r = dynamic_cast<RootObjAddress*>( pAddr );
52  Q* h = dynamic_cast<Q*>( refpObj );
53  if ( r && h ) {
54  // Need to flip representation .... clumsy for the time being, because
55  // THXY constructor has no "generic" copy constructor
56  auto s = dynamic_cast<S*>( r->tObj() );
57  if ( s ) {
58  auto a = dynamic_cast<TArray*>( s );
59  if ( a ) {
60  auto p = std::make_unique<T>();
61  auto ok = TTH<S>( s ).CopyH( *p );
62  if ( ok ) {
63  p->Set( a->GetSize() );
64  p->Reset();
65  p->Add( s );
66  h->adoptRepresentation( p.release() );
67  return StatusCode::SUCCESS;
68  }
69  }
70  }
71  }
72  return error( "Cannot create histogram - invalid address." );
73  }
75  StatusCode updateObj( IOpaqueAddress* /* pAddr */, DataObject* /* pObj */ ) override { return StatusCode::SUCCESS; }
77  TObject* createPersistent( DataObject* pObj ) override {
78  auto h = dynamic_cast<Q*>( pObj );
79  if ( h ) {
80  auto r = dynamic_cast<T*>( h->representation() );
81  if ( r ) {
82  auto a = dynamic_cast<TArray*>( r );
83  if ( a ) {
84  auto c = std::make_unique<T>();
85  auto ok = TTH<S>( r ).CopyH( *c );
86  if ( ok ) {
87  c->Set( a->GetSize() );
88  c->Reset();
89  c->Add( r );
90  c->SetName( pObj->registry()->name().c_str() + 1 );
91  return c.release();
92  }
93  }
94  }
95  }
96  error( "Histogram object is invalid!" );
97  return nullptr;
98  }
100  static const CLID& classID();
102  RHistogramCnv( ISvcLocator* svc ) : RConverter( classID(), svc ) {}
103  };
104 } // namespace RootHistCnv
105 #endif // ROOTHISTCNV_RHISTOGRAMCNV_H
Root Converter.
Definition: RConverter.h:31
RHistogramCnv(ISvcLocator *svc)
Standard constructor.
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:77
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
virtual const name_type & name() const =0
Name of the directory (or key)
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:72
static const CLID & classID()
Inquire class type.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
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:8
virtual unsigned long release()
release reference to object
Definition: DataObject.cpp:46
StatusCode error(const std::string &msg)
Definition: RConverter.cpp:329
T c_str(T...args)
string s
Definition: gaudirun.py:312
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:75
StatusCode createObj(IOpaqueAddress *pAddr, DataObject *&refpObj) override
Create the transient representation of an object.
Definition: RHistogramCnv.h:49