ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
StoreGate
StoreGate
ReadCondHandle.h
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#ifndef STOREGATE_READCONDHANDLE_H
6
#define STOREGATE_READCONDHANDLE_H 1
7
8
#include "
AthenaKernel/CondCont.h
"
9
#include "
AthenaKernel/ExtendedEventContext.h
"
10
11
#include "
StoreGate/ReadHandle.h
"
12
#include "
StoreGate/ReadCondHandleKey.h
"
13
#include "
StoreGate/exceptions.h
"
14
15
#include "GaudiKernel/DataObjID.h"
16
#include "GaudiKernel/EventIDBase.h"
17
#include "GaudiKernel/EventContext.h"
18
#include "GaudiKernel/ThreadLocalContext.h"
19
20
#include <string>
21
#include <stdexcept>
22
#include <any>
23
24
25
namespace
SG
{
26
27
34
void
ReadCondHandleNotFound
(
const
CondContBase& cc,
35
const
EventIDBase& eid,
36
const
std::string& key);
37
38
template
<
typename
T>
39
class
ReadCondHandle
{
40
41
public
:
42
typedef
T*
pointer_type
;
// FIXME: better handling of
43
typedef
const
T*
const_pointer_type
;
// qualified T type ?
44
typedef
T&
reference_type
;
45
typedef
const
T&
const_reference_type
;
46
47
public
:
48
ReadCondHandle
(
const
SG::ReadCondHandleKey<T>
&
key
);
49
ReadCondHandle
(
const
SG::ReadCondHandleKey<T>
&
key
,
50
const
EventContext& ctx);
51
52
ReadCondHandle
(
SG::ReadCondHandleKey<T>
&&
key
) =
delete
;
// Not allowed from a temporary.
53
ReadCondHandle
(
SG::ReadCondHandleKey<T>
&&
key
,
54
const
EventContext& ctx) =
delete
;
// Not allowed from a temporary.
55
56
~ReadCondHandle
() {};
57
58
const
std::string&
key
()
const
{
return
m_hkey
.key(); }
59
const
DataObjID&
fullKey
()
const
{
return
m_hkey
.fullKey(); }
60
61
const_pointer_type
retrieve
();
62
const_pointer_type
retrieve
(
const
EventIDBase& t);
63
64
const_pointer_type
operator->
() {
return
retrieve
(); }
65
const_pointer_type
operator*
() {
return
retrieve
(); }
66
const_pointer_type
cptr
() {
return
retrieve
(); }
67
68
69
bool
isValid
();
70
bool
isValid
(
const
EventIDBase& t)
const
;
71
72
bool
range
(EventIDRange&
r
);
73
bool
range
(
const
EventIDBase& t, EventIDRange&
r
)
const
;
74
const
EventIDRange&
getRange
();
75
76
CondCont<T>
*
getCC
() {
return
m_cc
; }
77
78
private
:
79
80
bool
initCondHandle
();
81
82
EventIDBase
m_eid
;
83
CondCont<T>
*
m_cc
{
nullptr
};
84
const
T*
m_obj
{
nullptr
};
85
const
EventIDRange*
m_range
{
nullptr
};
86
87
const
SG::ReadCondHandleKey<T>
&
m_hkey
;
88
};
89
90
91
//---------------------------------------------------------------------------
92
93
template
<
typename
T>
94
ReadCondHandle<T>::ReadCondHandle
(
const
SG::ReadCondHandleKey<T>
&
key
):
95
ReadCondHandle
(
key
,
Gaudi
::Hive::currentContext())
96
{
97
// cppcheck-suppress missingReturn; false positive
98
}
99
100
//---------------------------------------------------------------------------
101
102
template
<
typename
T>
103
ReadCondHandle<T>::ReadCondHandle
(
const
SG::ReadCondHandleKey<T>
&
key
,
104
const
EventContext& ctx):
105
m_eid
( ctx.eventID() ),
106
m_cc
(
key
.
getCC
() ),
107
m_hkey
(
key
)
108
{
109
try
{
110
EventIDBase::number_type conditionsRun =
111
Atlas::getExtendedEventContext
(ctx).
conditionsRun
();
112
if
(conditionsRun != EventIDBase::UNDEFNUM) {
113
m_eid
.set_run_number (conditionsRun);
114
}
115
}
116
catch
(
const
std::bad_any_cast& e) {
117
throw
SG::ExcBadContext
(ctx,
key
.objKey());
118
}
119
120
if
(!
key
.isInit()) [[
unlikely
]] {
121
throw SG::ExcUninitKey (key.clid(), key.key(), key.storeHandle().name(),
122
""
,
"ReadCond"
);
123
}
124
125
if
(
m_cc
== 0) [[
unlikely
]] {
126
// try to retrieve it
127
CondContBase
*cb(
nullptr
);
128
if
(
m_hkey
.getCS()->retrieve(cb,
m_hkey
.key()).isFailure()) {
129
throw
SG::ExcNoCondCont
(
m_hkey
.fullKey().key(),
"Can't retrieve."
);
130
}
else
{
131
m_cc
=
dynamic_cast<
CondCont<T>
*
>
(cb);
132
if
(
m_cc
== 0) {
133
throw
SG::ExcNoCondCont
(
m_hkey
.fullKey().key(),
"Can't dcast CondContBase."
);
134
}
135
}
136
}
137
}
138
139
//---------------------------------------------------------------------------
140
141
template
<
typename
T>
142
bool
143
ReadCondHandle<T>::initCondHandle
() {
144
145
if
(
m_obj
!= 0)
return
true
;
146
147
if
(!
m_cc
->find(
m_eid
,
m_obj
, &
m_range
)) [[
unlikely
]] {
148
ReadCondHandleNotFound
(*
m_cc
,
m_eid
,
m_hkey
.objKey());
149
m_obj
=
nullptr
;
150
return
false
;
151
}
152
153
return
true
;
154
}
155
156
//---------------------------------------------------------------------------
157
158
template
<
typename
T>
159
const
T*
160
ReadCondHandle<T>::retrieve
() {
161
162
if
(
m_obj
== 0) {
163
if
(!
initCondHandle
()) {
164
// std::ostringstream ost;
165
// m_cc->list(ost);
166
// MsgStream msg(Athena::getMessageSvc(), "ReadCondHandle");
167
// msg << MSG::ERROR
168
// << "ReadCondHandle::retrieve() could not find EventTime "
169
// << m_eid << " for key " << objKey() << "\n"
170
// << ost.str()
171
// << endmsg;
172
return
nullptr
;
173
}
174
}
175
176
return
m_obj
;
177
}
178
179
//---------------------------------------------------------------------------
180
181
template
<
typename
T>
182
const
T*
183
ReadCondHandle<T>::retrieve
(
const
EventIDBase& eid) {
184
if
(eid ==
m_eid
) {
185
return
retrieve
();
186
}
187
188
// pointer_type obj(0);
189
const_pointer_type
cobj(0);
190
if
(! (
m_cc
->find(eid, cobj) ) ) {
191
ReadCondHandleNotFound
(*
m_cc
, eid,
m_hkey
.objKey());
192
return
nullptr
;
193
}
194
195
// const_pointer_type cobj = const_cast<const_pointer_type>( obj );
196
197
return
cobj;
198
}
199
200
//---------------------------------------------------------------------------
201
202
template
<
typename
T>
203
bool
204
ReadCondHandle<T>::isValid
() {
205
206
return
initCondHandle
();
207
}
208
209
//---------------------------------------------------------------------------
210
211
template
<
typename
T>
212
bool
213
ReadCondHandle<T>::isValid
(
const
EventIDBase& t)
const
{
214
215
return
(
m_cc
->valid(t));
216
}
217
218
//---------------------------------------------------------------------------
219
220
template
<
typename
T>
221
bool
222
ReadCondHandle<T>::range
(EventIDRange&
r
) {
223
224
if
(
m_obj
== 0) {
225
if
(!
initCondHandle
()) {
226
return
false
;
227
}
228
}
229
230
if
(
m_range
) {
231
r
= *
m_range
;
232
return
true
;
233
}
234
235
return
false
;
236
}
237
238
template
<
typename
T>
239
const
EventIDRange&
240
ReadCondHandle<T>::getRange
() {
241
242
if
(
m_obj
== 0) {
243
if
(!
initCondHandle
()) {
244
throw
SG::ExcBadReadCondHandleInit
();
245
}
246
}
247
248
if
(!
m_range
) {
249
throw
SG::ExcNoRange
();
250
}
251
return
*
m_range
;
252
253
}
254
255
256
//---------------------------------------------------------------------------
257
258
template
<
typename
T>
259
bool
260
ReadCondHandle<T>::range
(
const
EventIDBase& eid, EventIDRange&
r
)
const
{
261
262
return
(
m_cc
->range(eid,
r
) );
263
}
264
265
266
// helper methods to create a read cond handle from the corresponding key.
267
template
<
class
T>
268
SG::ReadCondHandle<T>
makeHandle
(
const
SG::ReadCondHandleKey<T>
&key,
269
const
EventContext& ctx = Gaudi::Hive::currentContext()) {
270
return
SG::ReadCondHandle<T>
(key, ctx);
271
}
272
280
template
<
class
T>
281
const
T*
get
(
const
ReadCondHandleKey<T>
& key,
282
const
EventContext& ctx)
283
{
284
if
(key.key().empty())
return
nullptr
;
285
try
{
286
ReadCondHandle<T>
h
(key, ctx);
287
return
h
.cptr();
288
}
289
catch
(
SG::ExcNoCondCont
&) {
290
return
nullptr
;
291
}
292
}
293
294
303
template
<
class
T>
304
StatusCode
get
(
const
T*& ptr,
305
const
ReadCondHandleKey<T>
& key,
306
const
EventContext& ctx)
307
{
308
ptr =
get
(key, ctx);
309
return
(ptr || key.empty()) ? StatusCode::SUCCESS : StatusCode::FAILURE;
310
}
311
312
}
313
314
#endif
315
CondCont.h
Hold mappings of ranges to condition objects.
exceptions.h
Exceptions that can be thrown from StoreGate.
ExtendedEventContext.h
ReadCondHandleKey.h
if
if(pathvar)
Definition
SealSharedLib.cxx:168
ReadHandle.h
Handle class for reading from StoreGate.
h
Header file for AthHistogramAlgorithm.
Atlas::ExtendedEventContext::conditionsRun
EventIDBase::number_type conditionsRun() const
Definition
ExtendedEventContext.h:38
CondContBase
Base class for all conditions containers.
Definition
CondCont.h:140
CondCont
Hold mapping of ranges to condition objects.
Definition
CondCont.h:889
SG::ExcBadContext
Exception — Bad EventContext extension while building ReadCondHandle.
Definition
Control/StoreGate/StoreGate/exceptions.h:312
SG::ExcBadReadCondHandleInit
Exception — ReadCondHandle didn't initialize in getRange().
Definition
Control/StoreGate/StoreGate/exceptions.h:346
SG::ExcNoCondCont
Exception — Can't retrieve CondCont from ReadCondHandle.
Definition
Control/StoreGate/StoreGate/exceptions.h:330
SG::ExcNoRange
Exception — Range not set in ReadCondHandle::getRange().
Definition
Control/StoreGate/StoreGate/exceptions.h:360
SG::ReadCondHandleKey
Definition
ReadCondHandleKey.h:21
SG::ReadCondHandle
Definition
ReadCondHandle.h:39
SG::ReadCondHandle::m_obj
const T * m_obj
Definition
ReadCondHandle.h:84
SG::ReadCondHandle::operator->
const_pointer_type operator->()
Definition
ReadCondHandle.h:64
SG::ReadCondHandle::m_eid
EventIDBase m_eid
Definition
ReadCondHandle.h:82
SG::ReadCondHandle::operator*
const_pointer_type operator*()
Definition
ReadCondHandle.h:65
SG::ReadCondHandle::reference_type
T & reference_type
Definition
ReadCondHandle.h:44
SG::ReadCondHandle::ReadCondHandle
ReadCondHandle(const SG::ReadCondHandleKey< T > &key)
Definition
ReadCondHandle.h:94
SG::ReadCondHandle::retrieve
const_pointer_type retrieve()
Definition
ReadCondHandle.h:160
SG::ReadCondHandle::pointer_type
T * pointer_type
Definition
ReadCondHandle.h:42
SG::ReadCondHandle::range
bool range(EventIDRange &r)
Definition
ReadCondHandle.h:222
SG::ReadCondHandle::m_range
const EventIDRange * m_range
Definition
ReadCondHandle.h:85
SG::ReadCondHandle::m_hkey
const SG::ReadCondHandleKey< T > & m_hkey
Definition
ReadCondHandle.h:87
SG::ReadCondHandle< PixelCablingCondData >::key
const std::string & key() const
Definition
ReadCondHandle.h:58
SG::ReadCondHandle::isValid
bool isValid()
Definition
ReadCondHandle.h:204
SG::ReadCondHandle::getCC
CondCont< T > * getCC()
Definition
ReadCondHandle.h:76
SG::ReadCondHandle::ReadCondHandle
ReadCondHandle(SG::ReadCondHandleKey< T > &&key)=delete
SG::ReadCondHandle::fullKey
const DataObjID & fullKey() const
Definition
ReadCondHandle.h:59
SG::ReadCondHandle::~ReadCondHandle
~ReadCondHandle()
Definition
ReadCondHandle.h:56
SG::ReadCondHandle::const_reference_type
const T & const_reference_type
Definition
ReadCondHandle.h:45
SG::ReadCondHandle::m_cc
CondCont< T > * m_cc
Definition
ReadCondHandle.h:83
SG::ReadCondHandle::const_pointer_type
const T * const_pointer_type
Definition
ReadCondHandle.h:43
SG::ReadCondHandle::ReadCondHandle
ReadCondHandle(SG::ReadCondHandleKey< T > &&key, const EventContext &ctx)=delete
SG::ReadCondHandle::getRange
const EventIDRange & getRange()
Definition
ReadCondHandle.h:240
SG::ReadCondHandle::initCondHandle
bool initCondHandle()
Definition
ReadCondHandle.h:143
SG::ReadCondHandle::cptr
const_pointer_type cptr()
Definition
ReadCondHandle.h:66
r
int r
Definition
globals.cxx:22
Atlas::getExtendedEventContext
const ExtendedEventContext & getExtendedEventContext(const EventContext &ctx)
Retrieve an extended context from a context object.
Definition
ExtendedEventContext.cxx:32
Gaudi
=============================================================================
Definition
CaloGPUClusterAndCellDataMonitorOptions.h:273
SG
Forward declaration.
Definition
CaloCellPacker_400_500.h:32
SG::ReadCondHandleNotFound
void ReadCondHandleNotFound(const CondContBase &cc, const EventIDBase &eid, const std::string &key)
Report a conditions container lookup failure.
Definition
ReadCondHandle.cxx:23
SG::get
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
Definition
ReadCondHandle.h:281
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition
ReadCondHandle.h:268
unlikely
#define unlikely(x)
Definition
pythonic_coracool.cxx:9
Generated on
for ATLAS Offline Software by
1.17.0