ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
StoreGate
StoreGate
ReadMetaHandle.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_READMETAHANDLE_H
6
#define STOREGATE_READMETAHANDLE_H
7
8
#include "
AthenaKernel/getMessageSvc.h
"
9
#include "
AthenaKernel/MetaCont.h
"
10
#include "
AthenaKernel/ExtendedEventContext.h
"
11
12
#include "
StoreGate/ReadHandle.h
"
13
#include "
StoreGate/ReadMetaHandleKey.h
"
14
#include "
CxxUtils/AthUnlikelyMacros.h
"
15
16
#include "GaudiKernel/DataHandle.h"
17
#include "GaudiKernel/DataObjID.h"
18
#include "GaudiKernel/EventContext.h"
19
#include "GaudiKernel/ThreadLocalContext.h"
20
21
#include <string>
22
#include <stdexcept>
23
24
namespace
SG
{
25
26
template
<
typename
T>
27
class
ReadMetaHandle
{
28
29
public
:
30
typedef
T*
pointer_type
;
// FIXME: better handling of
31
typedef
const
T*
const_pointer_type
;
// qualified T type ?
32
typedef
T&
reference_type
;
33
typedef
const
T&
const_reference_type
;
34
35
public
:
36
ReadMetaHandle
(
const
SG::ReadMetaHandleKey<T>
& key);
37
ReadMetaHandle
(
const
SG::ReadMetaHandleKey<T>
& key
38
,
const
EventContext& ctx);
39
40
ReadMetaHandle
(
SG::ReadMetaHandleKey<T>
&& key) =
delete
;
// Not allowed from a temporary.
41
ReadMetaHandle
(
SG::ReadMetaHandleKey<T>
&& key,
42
const
EventContext& ctx) =
delete
;
// Not allowed from a temporary.
43
44
~ReadMetaHandle
() {};
45
46
const_pointer_type
retrieve
();
47
const_pointer_type
retrieve
(
const
SG::SourceID
& t);
48
49
const_pointer_type
operator->
() {
return
retrieve
(); }
50
const_pointer_type
operator*
() {
return
retrieve
(); }
51
52
bool
isValid
();
53
54
private
:
55
56
bool
initMetaHandle
();
57
58
SG::SourceID
m_sid
;
59
const
MetaCont<T>
*
m_cont
{
nullptr
};
60
T*
m_ent
{
nullptr
};
61
62
const
SG::ReadMetaHandleKey<T>
&
m_hkey
;
63
};
64
65
66
//------------------------------------------------------------------------
67
68
template
<
typename
T>
69
ReadMetaHandle<T>::ReadMetaHandle
(
const
SG::ReadMetaHandleKey<T>
& key)
70
:
ReadMetaHandle
(key,
Gaudi
::Hive::currentContext())
71
{
72
}
73
74
//------------------------------------------------------------------------
75
76
template
<
typename
T>
77
ReadMetaHandle<T>::ReadMetaHandle
(
const
SG::ReadMetaHandleKey<T>
& key
78
,
const
EventContext& ctx)
79
:
m_sid
(
Atlas
::getExtendedEventContext(ctx).proxy()->sourceID() )
80
,
m_cont
( key.getContainer() )
81
,
m_hkey
(key)
82
{
83
MsgStream
msg
(
Athena::getMessageSvc
(),
"ReadMetaHandle"
);
84
if
(
ATH_UNLIKELY
(!
m_hkey
.isInit())) {
85
msg
<< MSG::ERROR
86
<<
"ReadMetaHandleKey "
<< key.objKey() <<
" was not initialized"
87
<<
endmsg
;
88
throw
std::runtime_error(
"ReadMetaHandle: ReadMetaHandleKey was not initialized"
);
89
}
90
91
if
(
ATH_UNLIKELY
(
m_cont
== 0)) {
92
// Try to retrieve it
93
MetaContBase
* cb{
nullptr
};
94
if
(
m_hkey
.getStore()->retrieve(cb,
m_hkey
.key()).isFailure()) {
95
msg
<< MSG::ERROR
96
<<
"can't retrieve "
<<
m_hkey
.fullKey()
97
<<
" via base class"
<<
endmsg
;
98
throw
std::runtime_error(
"ReadCondHandle: ptr to CondCont<T> is zero"
);
99
}
100
else
{
101
m_cont
=
dynamic_cast<
MetaCont<T>
*
>
(cb);
102
if
(!
m_cont
) {
103
msg
<< MSG::ERROR
104
<<
"can't dcast MetaContBase to "
<<
m_hkey
.fullKey()
105
<<
endmsg
;
106
throw
std::runtime_error(
"ReadMetaHandle: ptr to MetaCont<T> is zero"
);
107
}
108
}
109
}
110
}
111
112
//------------------------------------------------------------------------
113
114
template
<
typename
T>
115
bool
116
ReadMetaHandle<T>::initMetaHandle
()
117
{
118
119
if
(
m_ent
)
return
true
;
120
121
// Initialize sid from dbKey found at ReadMetaHandleKey initialize
122
// m_sid = m_hkey.dbKey(); ???? Do I need this ????
123
124
if
(
ATH_UNLIKELY
(!
m_cont
->find(
m_sid
,
m_ent
)) ) {
125
std::ostringstream ost;
126
m_cont
->list(ost);
127
MsgStream
msg
(
Athena::getMessageSvc
(),
"ReadMetaHandle"
);
128
msg
<< MSG::ERROR
129
<<
"ReadMetaHandle:: could not find current SourceID "
130
<<
m_sid
<<
" for key "
<<
m_hkey
.objKey() <<
"\n"
131
<< ost.str() <<
endmsg
;
132
m_ent
=
nullptr
;
133
return
false
;
134
}
135
136
return
true
;
137
}
138
139
//------------------------------------------------------------------------
140
141
template
<
typename
T>
142
const
T*
143
ReadMetaHandle<T>::retrieve
()
144
{
145
146
if
(
m_ent
== 0) {
147
if
(!
initMetaHandle
()) {
148
return
nullptr
;
149
}
150
}
151
152
return
m_ent
;
153
}
154
155
//------------------------------------------------------------------------
156
157
template
<
typename
T>
158
const
T*
159
ReadMetaHandle<T>::retrieve
(
const
SG::SourceID
& sid)
160
{
161
if
(sid ==
m_sid
) {
162
return
retrieve
();
163
}
164
165
pointer_type
obj(0);
166
if
(! (
m_cont
->find(sid, obj) ) ) {
167
std::ostringstream ost;
168
m_cont
->list(ost);
169
MsgStream
msg
(
Athena::getMessageSvc
(),
"ReadMetaHandle"
);
170
msg
<< MSG::ERROR
171
<<
"ReadMetaHandle::retrieve() could not find SourceID "
172
<< sid <<
" for key "
<<
m_hkey
.objKey() <<
"\n"
173
<< ost.str()
174
<<
endmsg
;
175
return
nullptr
;
176
}
177
178
return
obj;
179
}
180
181
//---------------------------------------------------------------------------
182
183
template
<
typename
T>
184
bool
185
ReadMetaHandle<T>::isValid
() {
186
187
return
initMetaHandle
();
188
}
189
190
}
191
192
#endif
193
endmsg
#define endmsg
Definition
AnalysisConfig_Ntuple.cxx:54
AthUnlikelyMacros.h
ATH_UNLIKELY
#define ATH_UNLIKELY(x)
Definition
AthUnlikelyMacros.h:17
ExtendedEventContext.h
MetaCont.h
ReadMetaHandleKey.h
ReadHandle.h
Handle class for reading from StoreGate.
MetaContBase
Definition
MetaCont.h:24
MetaCont
Definition
MetaCont.h:48
SG::ReadMetaHandleKey
Definition
ReadMetaHandleKey.h:18
SG::ReadMetaHandle::ReadMetaHandle
ReadMetaHandle(const SG::ReadMetaHandleKey< T > &key)
Definition
ReadMetaHandle.h:69
SG::ReadMetaHandle::operator*
const_pointer_type operator*()
Definition
ReadMetaHandle.h:50
SG::ReadMetaHandle::m_hkey
const SG::ReadMetaHandleKey< T > & m_hkey
Definition
ReadMetaHandle.h:62
SG::ReadMetaHandle::ReadMetaHandle
ReadMetaHandle(SG::ReadMetaHandleKey< T > &&key)=delete
SG::ReadMetaHandle::pointer_type
T * pointer_type
Definition
ReadMetaHandle.h:30
SG::ReadMetaHandle::m_ent
T * m_ent
Definition
ReadMetaHandle.h:60
SG::ReadMetaHandle::const_reference_type
const T & const_reference_type
Definition
ReadMetaHandle.h:33
SG::ReadMetaHandle::const_pointer_type
const T * const_pointer_type
Definition
ReadMetaHandle.h:31
SG::ReadMetaHandle::reference_type
T & reference_type
Definition
ReadMetaHandle.h:32
SG::ReadMetaHandle::initMetaHandle
bool initMetaHandle()
Definition
ReadMetaHandle.h:116
SG::ReadMetaHandle::ReadMetaHandle
ReadMetaHandle(SG::ReadMetaHandleKey< T > &&key, const EventContext &ctx)=delete
SG::ReadMetaHandle::~ReadMetaHandle
~ReadMetaHandle()
Definition
ReadMetaHandle.h:44
SG::ReadMetaHandle::m_cont
const MetaCont< T > * m_cont
Definition
ReadMetaHandle.h:59
SG::ReadMetaHandle::m_sid
SG::SourceID m_sid
Definition
ReadMetaHandle.h:58
SG::ReadMetaHandle::operator->
const_pointer_type operator->()
Definition
ReadMetaHandle.h:49
SG::ReadMetaHandle::isValid
bool isValid()
Definition
ReadMetaHandle.h:185
SG::ReadMetaHandle::retrieve
const_pointer_type retrieve()
Definition
ReadMetaHandle.h:143
getMessageSvc.h
singleton-like access to IMessageSvc via open function and helper
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition
getMessageSvc.cxx:20
Atlas
Definition
ExtendedEventContext.h:21
Gaudi
=============================================================================
Definition
CaloGPUClusterAndCellDataMonitorOptions.h:273
SG
Forward declaration.
Definition
CaloCellPacker_400_500.h:32
SG::SourceID
std::string SourceID
Definition
AthenaKernel/AthenaKernel/SourceID.h:25
msg
MsgStream & msg
Definition
testRead.cxx:32
Generated on
for ATLAS Offline Software by
1.17.0