The Gaudi Framework  master (181af51f)
Loading...
Searching...
No Matches
RHistogramCnv.h
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2025 CERN for the benefit of the LHCb and ATLAS collaborations *
3* *
4* This software is distributed under the terms of the Apache version 2 licence, *
5* copied verbatim in the file "LICENSE". *
6* *
7* In applying this licence, CERN does not waive the privileges and immunities *
8* granted to it by virtue of its status as an Intergovernmental Organization *
9* or submit itself to any jurisdiction. *
10\***********************************************************************************/
11#pragma once
12
13// Include files
14#include "RConverter.h"
15#include "RootObjAddress.h"
21#include <GaudiKernel/SmartIF.h>
22#include <TArray.h>
23#include <memory>
24
25namespace RootHistCnv {
26
39 template <typename T, typename S, typename Q>
40 class RHistogramCnv : public RConverter {
41 template <typename CLASS>
42 class TTH {
43 public:
44 template <typename INPUT>
45 TTH( INPUT* i ) : m_c( dynamic_cast<CLASS*>( i ) ) {}
46 template <typename INPUT>
47 bool CopyH( INPUT& i ) {
48 if ( m_c ) { m_c->Copy( i ); }
49 return m_c != nullptr;
50 }
51
52 private:
53 CLASS* m_c = nullptr;
54 };
55
56 public:
58 StatusCode createObj( IOpaqueAddress* pAddr, DataObject*& refpObj ) override {
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() );
77 }
78 }
79 }
80 }
81 return error( "Cannot create histogram - invalid address." );
82 }
83
84 StatusCode updateObj( IOpaqueAddress* /* pAddr */, DataObject* /* pObj */ ) override { return StatusCode::SUCCESS; }
86 TObject* createPersistent( DataObject* pObj ) override {
87 auto h = dynamic_cast<Q*>( pObj );
88 if ( h ) {
89 auto r = dynamic_cast<T*>( h->representation() );
90 if ( r ) {
91 auto a = dynamic_cast<TArray*>( r );
92 if ( a ) {
93 auto c = std::make_unique<T>();
94 auto ok = TTH<S>( r ).CopyH( *c );
95 if ( ok ) {
96 c->Set( a->GetSize() );
97 c->Reset();
98 c->Add( r );
99 c->SetName( pObj->registry()->name().c_str() + 1 );
100 return c.release();
101 }
102 }
103 }
104 }
105 error( "Histogram object is invalid!" ).ignore();
106 return nullptr;
107 }
108
109 static const CLID& classID();
112 };
113} // namespace RootHistCnv
unsigned int CLID
Class ID definition.
Definition ClassID.h:16
const CLID & objType() const override
Retrieve the class type of objects the converter produces.
Definition Converter.cpp:22
A DataObject is the base class of any identifiable object on any data store.
Definition DataObject.h:37
IRegistry * registry() const
Get pointer to Registry.
Definition DataObject.h:79
virtual unsigned long release()
release reference to object
Opaque address interface definition.
virtual const name_type & name() const =0
Name of the directory (or key)
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition ISvcLocator.h:42
RConverter(const CLID &clid, ISvcLocator *svc)
Standard constructor.
Definition RConverter.h:64
StatusCode error(const std::string &msg)
StatusCode createObj(IOpaqueAddress *pAddr, DataObject *&refpObj) override
Create the transient representation of an object.
static const CLID & classID()
Inquire class type.
RHistogramCnv(ISvcLocator *svc)
Standard constructor.
TObject * createPersistent(DataObject *pObj) override
Create the persistent representation of the histogram object.
StatusCode updateObj(IOpaqueAddress *, DataObject *) override
Update the transient object from the other representation.
virtual TObject * tObj() const
Retrieve TObject* ptr.
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
Definition StatusCode.h:139
constexpr static const auto SUCCESS
Definition StatusCode.h:99