The Gaudi Framework
master (9f3f8895)
Toggle main menu visibility
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
"
16
#include <
GaudiKernel/DataObject.h
>
17
#include <
GaudiKernel/HistogramBase.h
>
18
#include <
GaudiKernel/IOpaqueAddress.h
>
19
#include <
GaudiKernel/IRegistry.h
>
20
#include <
GaudiKernel/ObjectFactory.h
>
21
#include <
GaudiKernel/SmartIF.h
>
22
#include <TArray.h>
23
#include <memory>
24
25
namespace
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() );
76
return
StatusCode::SUCCESS
;
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
();
111
RHistogramCnv
(
ISvcLocator
* svc ) :
RConverter
(
classID
(), svc ) {}
112
};
113
}
// namespace RootHistCnv
CLID
unsigned int CLID
Class ID definition.
Definition
ClassID.h:16
DataObject.h
HistogramBase.h
IOpaqueAddress.h
IRegistry.h
ObjectFactory.h
RConverter.h
RootObjAddress.h
SmartIF.h
Converter::objType
const CLID & objType() const override
Retrieve the class type of objects the converter produces.
Definition
Converter.cpp:22
DataObject
A DataObject is the base class of any identifiable object on any data store.
Definition
DataObject.h:37
DataObject::registry
IRegistry * registry() const
Get pointer to Registry.
Definition
DataObject.h:79
DataObject::release
virtual unsigned long release()
release reference to object
Definition
DataObject.cpp:56
IOpaqueAddress
Opaque address interface definition.
Definition
IOpaqueAddress.h:28
IRegistry::name
virtual const name_type & name() const =0
Name of the directory (or key).
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition
ISvcLocator.h:42
RootHistCnv::RConverter::RConverter
RConverter(const CLID &clid, ISvcLocator *svc)
Standard constructor.
Definition
RConverter.h:64
RootHistCnv::RConverter::error
StatusCode error(const std::string &msg)
Definition
RConverter.cpp:339
RootHistCnv::RHistogramCnv::TTH::m_c
CLASS * m_c
Definition
RHistogramCnv.h:53
RootHistCnv::RHistogramCnv::TTH::CopyH
bool CopyH(INPUT &i)
Definition
RHistogramCnv.h:47
RootHistCnv::RHistogramCnv::TTH::TTH
TTH(INPUT *i)
Definition
RHistogramCnv.h:45
RootHistCnv::RHistogramCnv::createObj
StatusCode createObj(IOpaqueAddress *pAddr, DataObject *&refpObj) override
Create the transient representation of an object.
Definition
RHistogramCnv.h:58
RootHistCnv::RHistogramCnv::classID
static const CLID & classID()
Inquire class type.
RootHistCnv::RHistogramCnv::RHistogramCnv
RHistogramCnv(ISvcLocator *svc)
Standard constructor.
Definition
RHistogramCnv.h:111
RootHistCnv::RHistogramCnv::createPersistent
TObject * createPersistent(DataObject *pObj) override
Create the persistent representation of the histogram object.
Definition
RHistogramCnv.h:86
RootHistCnv::RHistogramCnv::updateObj
StatusCode updateObj(IOpaqueAddress *, DataObject *) override
Update the transient object from the other representation.
Definition
RHistogramCnv.h:84
RootHistCnv::RootObjAddress
Definition
RootObjAddress.h:20
RootHistCnv::RootObjAddress::tObj
virtual TObject * tObj() const
Retrieve TObject* ptr.
Definition
RootObjAddress.h:90
StatusCode
This class is used for returning status codes from appropriate routines.
Definition
StatusCode.h:64
StatusCode::ignore
void ignore() const
Allow discarding a StatusCode without warning.
Definition
StatusCode.h:128
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition
StatusCode.h:99
RootHistCnv
Definition
DirectoryCnv.h:26
RootHistCnv
src
RHistogramCnv.h
Generated on
for The Gaudi Framework by
1.17.0