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-2025 CERN for the benefit of the ATLAS collaboration
3
*/
4
11
12
13
#undef NDEBUG
14
#include "
ReadDataReentrant.h
"
15
16
#include "
AthExStoreGateExample/MyDataObj.h
"
17
#include "
AthContainers/DataVector.h
"
18
#include "
AthenaKernel/DefaultKey.h
"
19
#include "
AthenaKernel/errorcheck.h
"
20
#include "AthLinks/ElementLink.h"
21
#include "
StoreGate/SGIterator.h
"
22
#include "
StoreGate/ReadHandle.h
"
23
#include "
StoreGateExample_ClassDEF.h
"
/*the CLIDs for the containers*/
24
25
#include <vector>
26
27
29
30
StatusCode
ReadDataReentrant::initialize
()
31
{
32
errorcheck::ReportMessage::hideErrorLocus
();
33
34
ATH_MSG_INFO
(
"in initialize()"
);
35
36
ATH_CHECK
(
m_cobjKey
.initialize() );
37
ATH_CHECK
(
m_vFloatKey
.initialize() );
38
ATH_CHECK
(
m_pLinkListKey
.initialize() );
39
ATH_CHECK
(
m_linkVectorKey
.initialize() );
40
ATH_CHECK
(
m_testObjectKey
.initialize() );
41
ATH_CHECK
(
m_eventInfo
.initialize() );
42
ATH_CHECK
(
m_dobjKeyArray
.initialize() );
43
ATH_CHECK
(
m_nonexistingKey
.initialize() );
44
45
return
StatusCode::SUCCESS;
46
}
47
48
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
49
50
StatusCode
ReadDataReentrant::execute
(
const
EventContext& ctx)
const
51
{
52
53
ATH_MSG_INFO
(
"in execute()"
);
54
56
// Part 1: retrieving individual objects from SG
57
//
58
59
SG::ReadHandle<TestDataObject>
testobj (
m_testObjectKey
, ctx);
60
if
(testobj->val() != 10) std::abort();
61
62
// Reading the array of handles.
63
std::vector<SG::ReadHandle<MyDataObj> > vh =
m_dobjKeyArray
.makeHandles (ctx);
64
for
(
size_t
i = 0; i < vh.size(); i++) {
65
assert (vh[i]->val() ==
static_cast<
int
>
(100+i));
66
}
67
68
70
// Get the default listof MyContObj, print out its contents
71
72
//the CLID of list<MyContObj> must be defined using the CLASSDEF
73
//macros. See StoreGateExample_ClassDEF.h for a few examples
74
//If no CLID is defined StoreGate assumes the object is (convertible to a)
75
//DataObject. If this is not the case an error message is issued:
76
//uncomment below to see how your compiler catches an undefined CLID
77
//ERROR p_SGevent->retrieve(errorH);
78
79
SG::ReadHandle<DataVector<MyContObj>
> list (
m_cobjKey
, ctx);
80
for
(
const
MyContObj
* obj : *list) {
81
float
time = obj->time();
82
int
ID = obj->id();
83
84
ATH_MSG_INFO
(
"Time: "
<< time <<
" ID: "
<< ID);
85
}
86
88
// Get the std::vector, print out its contents
89
90
SG::ReadHandle<std::vector<float>
> pVec (
m_vFloatKey
, ctx);
91
for
(
unsigned
int
it=0; it<pVec->size(); it++) {
92
ATH_MSG_INFO
(
"pVec ["
<< it <<
"] = "
<< (*pVec)[it]);
93
}
94
96
// test if an object is not in the store
97
SG::ReadHandle<MyDataObj>
nonexisting (
m_nonexistingKey
, ctx);
98
if
(nonexisting.
isValid
()) {
99
ATH_MSG_ERROR
(
"event store claims it contains MyDataObj with "
<<
m_nonexistingKey
);
100
return
StatusCode::FAILURE;
101
}
else
{
102
ATH_MSG_INFO
(
"event store does not contain MyDataObj with "
<<
m_nonexistingKey
);
103
}
104
106
// Part 2: retrieving DataLinks
107
108
// Get the list of links, print out its contents
109
110
typedef
ElementLink<std::vector<float>
> VecElemLink;
111
auto
pList =
SG::makeHandle
(
m_pLinkListKey
, ctx);
112
for
(
const
VecElemLink& l : *pList) {
113
ATH_MSG_INFO
(
"ListVecLinks::linked element "
<< *l);
114
}
115
116
// Get the vector of links, print out its contents
117
typedef
ElementLink<MapStringFloat>
MapElemLink;
118
SG::ReadHandle<std::vector<MapElemLink>
> vectorHandle (
m_linkVectorKey
, ctx);
119
for
(
const
MapElemLink& l : *vectorHandle) {
120
ATH_MSG_INFO
121
(
"VectorMapLinks::linked element: key "
<< l.index()
122
<<
" - value "
<< (*l)
123
<<
" - stored as "
<< l);
124
}
125
126
return
StatusCode::SUCCESS;
127
}
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:33
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
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:50
ReadDataReentrant::m_dobjKeyArray
SG::ReadHandleKeyArray< MyDataObj > m_dobjKeyArray
Definition
ReadDataReentrant.h:43
ReadDataReentrant::initialize
virtual StatusCode initialize() override final
Definition
ReadDataReentrant.cxx:30
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:67
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:269
Generated on
for ATLAS Offline Software by
1.17.0