ATLAS Offline Software
Loading...
Searching...
No Matches
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
20#include "AthLinks/ElementLink.h"
23#include "StoreGateExample_ClassDEF.h" /*the CLIDs for the containers*/
24
25#include <vector>
26
27
29
31{
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
50StatusCode 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
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
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
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
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;
119 for (const MapElemLink& l : *vectorHandle) {
121 ("VectorMapLinks::linked element: key " << l.index()
122 << " - value " << (*l)
123 << " - stored as " << l);
124 }
125
126 return StatusCode::SUCCESS;
127}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
std::vector< Identifier > ID
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())