ATLAS Offline Software
Loading...
Searching...
No Matches
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
19#include "AthLinks/ElementLink.h"
22#include "StoreGateExample_ClassDEF.h" /*the CLIDs for the containers*/
23
24#include <vector>
25
26
28
30{
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
49StatusCode 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
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
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
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
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;
118 for (const MapElemLink& l : *vectorHandle) {
120 ("VectorMapLinks::linked element: key " << l.index()
121 << " - value " << (*l)
122 << " - stored as " << l);
123 }
124
125 return StatusCode::SUCCESS;
126}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_INFO(x,...)
Helpers for checking error return status codes and reporting errors.
An STL vector of pointers that by default owns its pointed-to elements.
Testing reentrant algorithms.
A standard conforming forward iterator over items in StoreGate.
Handle class for reading from StoreGate.
SG::ReadHandleKey< std::vector< ElementLink< MapStringFloat > > > m_linkVectorKey
SG::ReadHandleKey< std::vector< float > > m_vFloatKey
SG::ReadHandleKey< std::list< ElementLink< std::vector< float > > > > m_pLinkListKey
SG::ReadHandleKey< DataVector< MyContObj > > m_cobjKey
virtual StatusCode execute(const EventContext &ctx) const override final
SG::ReadHandleKeyArray< MyDataObj > m_dobjKeyArray
virtual StatusCode initialize() override final
SG::ReadHandleKey< MyDataObj > m_nonexistingKey
SG::ReadHandleKey< TestDataObject > m_testObjectKey
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfo
virtual bool isValid() override final
Can the handle be successfully dereferenced?
static void hideErrorLocus(bool flag=true)
If set to true, hide the source file and line number in the output.
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())