ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
AthenaExamples
AthExStoreGateExample
src
ReadDataReentrant.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
10
11
12
#undef NDEBUG
13
#include "
ReadDataReentrant.h
"
14
15
#include "
AthExStoreGateExample/MyDataObj.h
"
16
#include "
AthContainers/DataVector.h
"
17
#include "
AthenaKernel/DefaultKey.h
"
18
#include "
AthenaKernel/errorcheck.h
"
19
#include "AthLinks/ElementLink.h"
20
#include "
StoreGate/SGIterator.h
"
21
#include "
StoreGate/ReadHandle.h
"
22
#include "
StoreGateExample_ClassDEF.h
"
/*the CLIDs for the containers*/
23
24
#include <vector>
25
26
28
29
StatusCode
ReadDataReentrant::initialize
()
30
{
31
errorcheck::ReportMessage::hideErrorLocus
();
32
33
ATH_MSG_INFO
(
"in initialize()"
);
34
35
ATH_CHECK
(
m_cobjKey
.initialize() );
36
ATH_CHECK
(
m_vFloatKey
.initialize() );
37
ATH_CHECK
(
m_pLinkListKey
.initialize() );
38
ATH_CHECK
(
m_linkVectorKey
.initialize() );
39
ATH_CHECK
(
m_testObjectKey
.initialize() );
40
ATH_CHECK
(
m_eventInfo
.initialize() );
41
ATH_CHECK
(
m_dobjKeyArray
.initialize() );
42
ATH_CHECK
(
m_nonexistingKey
.initialize() );
43
44
return
StatusCode::SUCCESS;
45
}
46
47
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
48
49
StatusCode
ReadDataReentrant::execute
(
const
EventContext& ctx)
const
50
{
51
52
ATH_MSG_INFO
(
"in execute()"
);
53
55
// Part 1: retrieving individual objects from SG
56
//
57
58
SG::ReadHandle<TestDataObject>
testobj (
m_testObjectKey
, ctx);
59
if
(testobj->val() != 10) std::abort();
60
61
// Reading the array of handles.
62
std::vector<SG::ReadHandle<MyDataObj> > vh =
m_dobjKeyArray
.makeHandles (ctx);
63
for
(
size_t
i = 0; i < vh.size(); i++) {
64
assert (vh[i]->val() ==
static_cast<
int
>
(100+i));
65
}
66
67
69
// Get the default listof MyContObj, print out its contents
70
71
//the CLID of list<MyContObj> must be defined using the CLASSDEF
72
//macros. See StoreGateExample_ClassDEF.h for a few examples
73
//If no CLID is defined StoreGate assumes the object is (convertible to a)
74
//DataObject. If this is not the case an error message is issued:
75
//uncomment below to see how your compiler catches an undefined CLID
76
//ERROR p_SGevent->retrieve(errorH);
77
78
SG::ReadHandle<DataVector<MyContObj>
> list (
m_cobjKey
, ctx);
79
for
(
const
MyContObj
* obj : *list) {
80
float
time = obj->time();
81
int
ID = obj->id();
82
83
ATH_MSG_INFO
(
"Time: {} ID: {}"
, time, ID);
84
}
85
87
// Get the std::vector, print out its contents
88
89
SG::ReadHandle<std::vector<float>
> pVec (
m_vFloatKey
, ctx);
90
for
(
unsigned
int
it=0; it<pVec->size(); it++) {
91
ATH_MSG_INFO
(
"pVec [{}] = {}"
, it, (*pVec)[it]);
92
}
93
95
// test if an object is not in the store
96
SG::ReadHandle<MyDataObj>
nonexisting (
m_nonexistingKey
, ctx);
97
if
(nonexisting.
isValid
()) {
98
ATH_MSG_ERROR
(
"event store claims it contains MyDataObj with {}"
,
m_nonexistingKey
);
99
return
StatusCode::FAILURE;
100
}
else
{
101
ATH_MSG_INFO
(
"event store does not contain MyDataObj with {}"
,
m_nonexistingKey
);
102
}
103
105
// Part 2: retrieving DataLinks
106
107
// Get the list of links, print out its contents
108
109
typedef
ElementLink<std::vector<float>
> VecElemLink;
110
auto
pList =
SG::makeHandle
(
m_pLinkListKey
, ctx);
111
for
(
const
VecElemLink& l : *pList) {
112
ATH_MSG_INFO
(
"ListVecLinks::linked element {}"
, *l);
113
}
114
115
// Get the vector of links, print out its contents
116
typedef
ElementLink<MapStringFloat>
MapElemLink;
117
SG::ReadHandle<std::vector<MapElemLink>
> vectorHandle (
m_linkVectorKey
, ctx);
118
for
(
const
MapElemLink& l : *vectorHandle) {
119
ATH_MSG_INFO
120
(
"VectorMapLinks::linked element: key "
<< l.index()
121
<<
" - value "
<< (*l)
122
<<
" - stored as "
<< l);
123
}
124
125
return
StatusCode::SUCCESS;
126
}
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x,...)
Definition
AthMsgStreamMacros.h:47
ATH_MSG_INFO
#define ATH_MSG_INFO(x,...)
Definition
AthMsgStreamMacros.h:45
errorcheck.h
Helpers for checking error return status codes and reporting errors.
DataVector.h
An STL vector of pointers that by default owns its pointed-to elements.
DefaultKey.h
MyDataObj.h
ReadDataReentrant.h
Testing reentrant algorithms.
SGIterator.h
A standard conforming forward iterator over items in StoreGate.
StoreGateExample_ClassDEF.h
ReadHandle.h
Handle class for reading from StoreGate.
ElementLink
ElementLink implementation for ROOT usage.
Definition
A/AthLinks/ElementLink.h:40
MyContObj
Definition
MyContObj.h:11
ReadDataReentrant::m_linkVectorKey
SG::ReadHandleKey< std::vector< ElementLink< MapStringFloat > > > m_linkVectorKey
Definition
ReadDataReentrant.h:40
ReadDataReentrant::m_vFloatKey
SG::ReadHandleKey< std::vector< float > > m_vFloatKey
Definition
ReadDataReentrant.h:38
ReadDataReentrant::m_pLinkListKey
SG::ReadHandleKey< std::list< ElementLink< std::vector< float > > > > m_pLinkListKey
Definition
ReadDataReentrant.h:39
ReadDataReentrant::m_cobjKey
SG::ReadHandleKey< DataVector< MyContObj > > m_cobjKey
Definition
ReadDataReentrant.h:37
ReadDataReentrant::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Definition
ReadDataReentrant.cxx:49
ReadDataReentrant::m_dobjKeyArray
SG::ReadHandleKeyArray< MyDataObj > m_dobjKeyArray
Definition
ReadDataReentrant.h:43
ReadDataReentrant::initialize
virtual StatusCode initialize() override final
Definition
ReadDataReentrant.cxx:29
ReadDataReentrant::m_nonexistingKey
SG::ReadHandleKey< MyDataObj > m_nonexistingKey
Definition
ReadDataReentrant.h:44
ReadDataReentrant::m_testObjectKey
SG::ReadHandleKey< TestDataObject > m_testObjectKey
Definition
ReadDataReentrant.h:41
ReadDataReentrant::m_eventInfo
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfo
Definition
ReadDataReentrant.h:42
SG::ReadHandle
Definition
StoreGate/StoreGate/ReadHandle.h:66
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
errorcheck::ReportMessage::hideErrorLocus
static void hideErrorLocus(bool flag=true)
If set to true, hide the source file and line number in the output.
Definition
errorcheck.cxx:197
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition
ReadCondHandle.h:268
Generated on
for ATLAS Offline Software by
1.17.0