The Gaudi Framework  v30r4 (9b837755)
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  class TTH
36  {
37  public:
38  template <typename INPUT>
39  TTH( INPUT* i ) : m_c( dynamic_cast<CLASS*>( i ) )
40  {
41  }
42  template <typename INPUT>
43  bool CopyH( INPUT& i )
44  {
45  if ( m_c ) {
46  m_c->Copy( i );
47  }
48  return m_c != nullptr;
49  }
50 
51  private:
52  CLASS* m_c = nullptr;
53  };
54 
55  public:
57  StatusCode createObj( IOpaqueAddress* pAddr, DataObject*& refpObj ) override
58  {
59  refpObj = DataObjFactory::create( objType() ).release();
60  RootObjAddress* r = dynamic_cast<RootObjAddress*>( pAddr );
61  Q* h = dynamic_cast<Q*>( refpObj );
62  if ( r && h ) {
63  // Need to flip representation .... clumsy for the time being, because
64  // THXY constructor has no "generic" copy constructor
65  auto s = dynamic_cast<S*>( r->tObj() );
66  if ( s ) {
67  auto a = dynamic_cast<TArray*>( s );
68  if ( a ) {
69  auto p = std::make_unique<T>();
70  auto ok = TTH<S>( s ).CopyH( *p );
71  if ( ok ) {
72  p->Set( a->GetSize() );
73  p->Reset();
74  p->Add( s );
75  h->adoptRepresentation( p.release() );
76  return StatusCode::SUCCESS;
77  }
78  }
79  }
80  }
81  return error( "Cannot create histogram - invalid address." );
82  }
84  StatusCode updateObj( IOpaqueAddress* /* pAddr */, DataObject* /* pObj */ ) override { return StatusCode::SUCCESS; }
86  TObject* createPersistent( DataObject* pObj ) override
87  {
88  auto h = dynamic_cast<Q*>( pObj );
89  if ( h ) {
90  auto r = dynamic_cast<T*>( h->representation() );
91  if ( r ) {
92  auto a = dynamic_cast<TArray*>( r );
93  if ( a ) {
94  auto c = std::make_unique<T>();
95  auto ok = TTH<S>( r ).CopyH( *c );
96  if ( ok ) {
97  c->Set( a->GetSize() );
98  c->Reset();
99  c->Add( r );
100  c->SetName( pObj->registry()->name().c_str() + 1 );
101  return c.release();
102  }
103  }
104  }
105  }
106  error( "Histogram object is invalid!" );
107  return nullptr;
108  }
110  static const CLID& classID();
112  RHistogramCnv( ISvcLocator* svc ) : RConverter( classID(), svc ) {}
113  };
114 } // namespace RootHistCnv
115 #endif // ROOTHISTCNV_RHISTOGRAMCNV_H
Root Converter.
Definition: RConverter.h:33
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:86
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:84
StatusCode createObj(IOpaqueAddress *pAddr, DataObject *&refpObj) override
Create the transient representation of an object.
Definition: RHistogramCnv.h:57