| The Gaudi Framework v32r1 (f65d50dc)

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 "GaudiKernel/DataObject.h"
6 #include "GaudiKernel/HistogramBase.h"
7 #include "GaudiKernel/IOpaqueAddress.h"
8 #include "GaudiKernel/IRegistry.h"
9 #include "GaudiKernel/ObjectFactory.h"
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
RootHistCnv::RConverter
Root Converter.
Definition: RConverter.h:31
RootHistCnv::RHistogramCnv::RHistogramCnv
RHistogramCnv(ISvcLocator *svc)
Standard constructor.
Definition: RHistogramCnv.h:102
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
gaudirun.c
c
Definition: gaudirun.py:487
DataObject::registry
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:72
RootHistCnv::RootObjAddress::tObj
virtual TObject * tObj() const
Retrieve TObject* ptr.
Definition: RootObjAddress.h:81
RootHistCnv::RHistogramCnv::TTH::TTH
TTH(INPUT *i)
Definition: RHistogramCnv.h:36
RootHistCnv::RHistogramCnv::createPersistent
TObject * createPersistent(DataObject *pObj) override
Create the persistent representation of the histogram object.
Definition: RHistogramCnv.h:77
RootHistCnv::RHistogramCnv::TTH
Definition: RHistogramCnv.h:33
ObjectFactory.h
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
IRegistry::name
virtual const name_type & name() const =0
Name of the directory (or key)
RootHistCnv::RootObjAddress
Definition: RootObjAddress.h:11
RConverter.h
RootHistCnv::RHistogramCnv::classID
static const CLID & classID()
Inquire class type.
Definition: RHistogramCnv.cpp:8
RootHistCnv::RHistogramCnv::TTH::CopyH
bool CopyH(INPUT &i)
Definition: RHistogramCnv.h:38
HistogramBase.h
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
SmartIF.h
RootHistCnv::RHistogramCnv
Generic converter to save/read AIDA_ROOT histograms using ROOT.
Definition: RHistogramCnv.h:31
RootHistCnv
Definition: DirectoryCnv.h:17
IRegistry.h
CLID
unsigned int CLID
Class ID definition.
Definition: ClassID.h:8
IOpaqueAddress.h
DataObject::release
virtual unsigned long release()
release reference to object
Definition: DataObject.cpp:46
RootObjAddress.h
RootHistCnv::RConverter::error
StatusCode error(const std::string &msg)
Definition: RConverter.cpp:329
std::string::c_str
T c_str(T... args)
gaudirun.s
string s
Definition: gaudirun.py:316
IOpaqueAddress
Opaque address interface definition.
Definition: IOpaqueAddress.h:23
DataObject
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
RootHistCnv::RHistogramCnv::updateObj
StatusCode updateObj(IOpaqueAddress *, DataObject *) override
Update the transient object from the other representation.
Definition: RHistogramCnv.h:75
RootHistCnv::RHistogramCnv::createObj
StatusCode createObj(IOpaqueAddress *pAddr, DataObject *&refpObj) override
Create the transient representation of an object.
Definition: RHistogramCnv.h:49
Converter::objType
const CLID & objType() const override
Retrieve the class type of objects the converter produces.
Definition: Converter.cpp:13
DataObject.h
RootHistCnv::RHistogramCnv::TTH::m_c
CLASS * m_c
Definition: RHistogramCnv.h:44