ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
AthenaKernel
AthenaKernel
StorableConversions.h
Go to the documentation of this file.
1
// This file's extension implies that it's C, but it's really -*- C++ -*-.
2
3
/*
4
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
5
*/
6
7
#ifndef ATHENAKERNEL_STORABLECONVERSIONS_H
8
# define ATHENAKERNEL_STORABLECONVERSIONS_H
13
14
#include "
AthenaKernel/DataBucket.h
"
15
#include "
AthenaKernel/DataBucketTraitFwd.h
"
16
#include "
AthenaKernel/ClassID_traits.h
"
17
#include "GaudiKernel/DataObject.h"
18
19
#include <memory>
20
#include <type_traits>
21
#include <typeinfo>
22
23
24
namespace
SG
{
25
26
// put a dobj pointer in a bucket as appropriate
27
template
<
typename
T>
28
DataObject*
asStorable
(T* pObject);
29
30
// get a dobj pointer from a bucket as appropriate
31
template
<
typename
T>
32
bool
fromStorable
(DataObject* pDObj, T*& pTrans,
bool
quiet
=
false
,
33
IRegisterTransient
* irt = 0,
34
bool
isConst =
true
);
35
36
template
<
typename
T>
37
T*
Storable_cast
(DataObject* pDObj,
bool
quiet
=
true
,
38
IRegisterTransient
* irt = 0,
39
bool
isConst =
true
) {
40
T* result;
41
return
fromStorable
(pDObj, result,
quiet
, irt, isConst) ? result : 0;
42
}
43
44
58
void
*
fromStorable
(DataObject* pDObj,
CLID
clid,
59
const
std::type_info* tinfo =
nullptr
,
60
bool
quiet
=
false
,
61
IRegisterTransient* irt = 0,
62
bool
isConst =
true
);
63
64
78
void
*
Storable_cast
(DataObject* pDObj,
CLID
clid,
79
const
std::type_info* tinfo =
nullptr
,
80
bool
quiet
=
false
,
81
IRegisterTransient* irt = 0,
82
bool
isConst =
true
);
83
}
84
86
// implementation details
87
88
89
namespace
SG
{
90
91
128
template
<
class
T
,
class
U
/* = T*/
>
129
struct
DataBucketTrait
130
{
131
// The first base of @c T (or @c SG::NoBase).
132
using
base1
= SG::BaseType_t<typename SG::Bases<T>::bases::Base1>;
133
134
// Test to see if it's valid.
135
static
constexpr
bool
has_base
= std::is_same_v<base1, SG::NoBase>;
136
137
// This is what we'll return in the default (no base) case.
138
using
deflt
= std::type_identity<SG::DataBucket<U> >;
139
140
// This is what we use to recursively check the base
141
using
recurse
=
DataBucketTrait<base1, U>
;
142
143
// Calculate the output.
144
using
type
=
typename
std::conditional_t<has_base, deflt, recurse>::type;
145
147
static
void
init
() {}
148
};
149
150
151
// put a dobj pointer in a bucket as appropriate
152
template
<
typename
T>
153
DataObject*
asStorable
(T* pObject) {
154
typedef
typename
DataBucketTrait<T>::type
bucket_t;
155
return
new
bucket_t (pObject);
156
}
157
158
template
<
typename
T>
159
DataObject*
asStorable
(std::unique_ptr<T> pObject) {
160
typedef
typename
std::remove_const<T>::type T_nc;
161
typedef
typename
DataBucketTrait<T_nc>::type
bucket_t;
162
return
new
bucket_t (std::move(pObject));
163
}
164
165
// get a dobj pointer from a bucket as appropriate
166
//the DataObject must be a DataBucket<DATA>*.
167
168
template
<
typename
T>
169
bool
fromStorable
(DataObject* pDObj, T*& pTrans,
170
bool
quiet
,
171
IRegisterTransient
* irt,
172
bool
isConst
/*= true*/
)
173
{
174
typedef
typename
std::remove_const<T>::type T_nc;
175
DataBucketTrait<T_nc>::init
();
176
177
pTrans =
static_cast<
T*
>
(
fromStorable
(pDObj,
ClassID_traits<T_nc>::ID
(),
178
&
typeid
(T_nc),
179
quiet
, irt, isConst));
180
return
pTrans !=
nullptr
;
181
}
182
183
}
184
185
#endif
// ATHENAKERNEL_STORABLECONVERSIONS_H
ClassID_traits.h
a traits class that associates a CLID to a type T It also detects whether T inherits from Gaudi DataO...
DataBucketTraitFwd.h
DataBucket.h
CLID
uint32_t CLID
The Class ID type.
Definition
Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
quiet
bool quiet
Definition
TrigGlobEffCorrValidation.cxx:190
SG::IRegisterTransient
Interface for registering a transient object in t2p map.
Definition
IRegisterTransient.h:28
SG
Forward declaration.
Definition
CaloCellPacker_400_500.h:32
SG::Storable_cast
T * Storable_cast(DataObject *pDObj, bool quiet=true, IRegisterTransient *irt=0, bool isConst=true)
Definition
StorableConversions.h:37
SG::fromStorable
bool fromStorable(DataObject *pDObj, T *&pTrans, bool quiet=false, IRegisterTransient *irt=0, bool isConst=true)
Definition
StorableConversions.h:169
SG::asStorable
DataObject * asStorable(SG::DataObjectSharedPtr< T > pObject)
Definition
DataObjectSharedPtr.h:31
TSU::T
unsigned long long T
Definition
L1TopoDataTypes.h:36
ClassID_traits::ID
static constexpr CLID ID()
Definition
Control/AthenaKernel/AthenaKernel/ClassID_traits.h:44
SG::DataBucketTrait
Metafunction to find the proper DataBucket class for T.
Definition
StorableConversions.h:130
SG::DataBucketTrait::init
static void init()
Initialization hook. A no-op by default.
Definition
StorableConversions.h:147
SG::DataBucketTrait::base1
SG::BaseType_t< typename SG::Bases< T >::bases::Base1 > base1
Definition
StorableConversions.h:132
SG::DataBucketTrait< base1, U >::type
typename std::conditional_t< has_base, deflt, recurse >::type type
Definition
StorableConversions.h:144
SG::DataBucketTrait< base1, U >::has_base
static constexpr bool has_base
Definition
StorableConversions.h:135
SG::DataBucketTrait::deflt
std::type_identity< SG::DataBucket< U > > deflt
Definition
StorableConversions.h:138
SG::DataBucketTrait::recurse
DataBucketTrait< base1, U > recurse
Definition
StorableConversions.h:141
Generated on
for ATLAS Offline Software by
1.17.0