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