ATLAS Offline Software
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 
13 #undef NDEBUG
14 #include "ReadDataReentrant.h"
15 
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 
31 {
33 
34  ATH_MSG_INFO ("in initialize()");
35 
42  ATH_CHECK( m_dobjKeyArray.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 
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) {
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 }
StoreGateExample_ClassDEF.h
ReadDataReentrant::m_pLinkListKey
SG::ReadHandleKey< std::list< ElementLink< std::vector< float > > > > m_pLinkListKey
Definition: ReadDataReentrant.h:39
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
ID
std::vector< Identifier > ID
Definition: CalibHitIDCheck.h:24
ReadDataReentrant::m_eventInfo
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfo
Definition: ReadDataReentrant.h:42
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
ReadDataReentrant::m_dobjKeyArray
SG::ReadHandleKeyArray< MyDataObj > m_dobjKeyArray
Definition: ReadDataReentrant.h:43
skel.it
it
Definition: skel.GENtoEVGEN.py:407
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:157
SGIterator.h
A standard conforming forward iterator over items in StoreGate.
TestDataObject::val
void val(int i)
Definition: MyDataObj.h:39
ReadDataReentrant::m_vFloatKey
SG::ReadHandleKey< std::vector< float > > m_vFloatKey
Definition: ReadDataReentrant.h:38
ReadDataReentrant::m_linkVectorKey
SG::ReadHandleKey< std::vector< ElementLink< MapStringFloat > > > m_linkVectorKey
Definition: ReadDataReentrant.h:40
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:274
ReadDataReentrant::m_cobjKey
SG::ReadHandleKey< DataVector< MyContObj > > m_cobjKey
Definition: ReadDataReentrant.h:37
ReadDataReentrant.h
Testing reentrant algorithms.
ReadDataReentrant::initialize
virtual StatusCode initialize() override final
Definition: ReadDataReentrant.cxx:30
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
MyContObj
Definition: MyContObj.h:11
lumiFormat.i
int i
Definition: lumiFormat.py:85
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
MyDataObj.h
ReadDataReentrant::m_nonexistingKey
SG::ReadHandleKey< MyDataObj > m_nonexistingKey
Definition: ReadDataReentrant.h:44
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
errorcheck.h
Helpers for checking error return status codes and reporting errors.
ReadDataReentrant::m_testObjectKey
SG::ReadHandleKey< TestDataObject > m_testObjectKey
Definition: ReadDataReentrant.h:41
DataVector.h
An STL vector of pointers that by default owns its pointed-to elements.
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
ReadHandle.h
Handle class for reading from StoreGate.
DefaultKey.h
python.PyAthena.obj
obj
Definition: PyAthena.py:132
ReadDataReentrant::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Definition: ReadDataReentrant.cxx:50