ATLAS Offline Software
Loading...
Searching...
No Matches
ReadData Class Reference

Example of a legacy Algorithm in single-threaded athena. More...

#include <ReadData.h>

Inheritance diagram for ReadData:
Collaboration diagram for ReadData:

Public Member Functions

virtual StatusCode initialize () override
virtual StatusCode execute () override
 AthAlgorithm (const std::string &name, ISvcLocator *pSvcLocator)
 Constructor with parameters:
virtual StatusCode sysInitialize () override
 Override sysInitialize.
virtual const DataObjIDColl & extraOutputDeps () const override
 Return the list of extra output dependencies.
ServiceHandle< StoreGateSvc > & evtStore ()
 The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
const ServiceHandle< StoreGateSvc > & detStore () const
 The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
virtual StatusCode sysStart () override
 Handle START transition.
virtual std::vector< Gaudi::DataHandle * > inputHandles () const override
 Return this algorithm's input handles.
virtual std::vector< Gaudi::DataHandle * > outputHandles () const override
 Return this algorithm's output handles.
Gaudi::Details::PropertyBase & declareProperty (Gaudi::Property< T, V, H > &t)
void updateVHKA (Gaudi::Details::PropertyBase &)
MsgStream & msg () const
bool msgLvl (const MSG::Level lvl) const

Protected Member Functions

void renounceArray (SG::VarHandleKeyArray &handlesArray)
 remove all handles from I/O resolution
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce (T &h)
void extraDeps_update_handler (Gaudi::Details::PropertyBase &ExtraDeps)
 Add StoreName to extra input/output deps as needed.

Private Types

typedef ServiceHandle< StoreGateSvcStoreGateSvc_t

Private Member Functions

Gaudi::Details::PropertyBase & declareGaudiProperty (Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyType &)
 specialization for handling Gaudi::Property<SG::VarHandleKey>

Private Attributes

Gaudi::Property< std::string > m_DataProducer {this, "DataProducer", ""}
SG::ReadHandle< MyDataObjm_dobj3
SG::ReadHandleKey< xAOD::EventInfom_eventInfo {this, "EvtInfo", "EventInfo", "EventInfo name"}
DataObjIDColl m_extendedExtraObjects
StoreGateSvc_t m_evtStore
 Pointer to StoreGate (event store by default)
StoreGateSvc_t m_detStore
 Pointer to StoreGate (detector store by default)
std::vector< SG::VarHandleKeyArray * > m_vhka
bool m_varHandleArraysDeclared

Detailed Description

Example of a legacy Algorithm in single-threaded athena.

IMPORTANT: This is no longer recommended. See ReadDataReentrant instead.

Definition at line 23 of file Control/AthenaExamples/AthExStoreGateExample/src/ReadData.h.

Member Typedef Documentation

◆ StoreGateSvc_t

typedef ServiceHandle<StoreGateSvc> AthCommonDataStore< AthCommonMsg< Algorithm > >::StoreGateSvc_t
privateinherited

Definition at line 388 of file AthCommonDataStore.h.

Member Function Documentation

◆ AthAlgorithm()

AthAlgorithm::AthAlgorithm ( const std::string & name,
ISvcLocator * pSvcLocator )

Constructor with parameters:

Definition at line 51 of file AthAlgorithm.cxx.

25 :
27{
28 // Set up to run AthAlgorithmDHUpdate in sysInitialize before
29 // merging dependency lists. This extends the output dependency
30 // list with any symlinks implied by inheritance relations.
31 m_updateDataHandles =
32 std::make_unique<AthenaBaseComps::AthAlgorithmDHUpdate>
34 std::move (m_updateDataHandles));
35}
DataObjIDColl m_extendedExtraObjects
AthCommonDataStore(const std::string &name, T... args)

◆ declareGaudiProperty()

Gaudi::Details::PropertyBase & AthCommonDataStore< AthCommonMsg< Algorithm > >::declareGaudiProperty ( Gaudi::Property< T, V, H > & hndl,
const SG::VarHandleKeyType &  )
inlineprivateinherited

specialization for handling Gaudi::Property<SG::VarHandleKey>

Definition at line 156 of file AthCommonDataStore.h.

158 {
160 hndl.value(),
161 hndl.documentation());
162
163 }
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)

◆ declareProperty()

Gaudi::Details::PropertyBase & AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty ( Gaudi::Property< T, V, H > & t)
inlineinherited

Definition at line 145 of file AthCommonDataStore.h.

145 {
146 typedef typename SG::HandleClassifier<T>::type htype;
148 }
Gaudi::Details::PropertyBase & declareGaudiProperty(Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyType &)
specialization for handling Gaudi::Property<SG::VarHandleKey>

◆ detStore()

const ServiceHandle< StoreGateSvc > & AthCommonDataStore< AthCommonMsg< Algorithm > >::detStore ( ) const
inlineinherited

The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 95 of file AthCommonDataStore.h.

◆ evtStore()

ServiceHandle< StoreGateSvc > & AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore ( )
inlineinherited

The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 85 of file AthCommonDataStore.h.

◆ execute()

StatusCode ReadData::execute ( )
overridevirtual

Definition at line 43 of file Control/AthenaExamples/AthExStoreGateExample/src/ReadData.cxx.

43 {
44
45 ATH_MSG_INFO ("in execute()");
46
48 // Get a specific MyDataObj by providing its key
49 // (in this case the name of the algo which recorded it)
50
51 ATH_MSG_INFO ("Get the MyDataObj recorded by " << m_DataProducer.value());
52
53 //this time we set a *non-const* pointer. *If* we get back a valid
54 //pointer we'll be able to modify the content of the underlying transient obj
55 MyDataObj* dobj3 = nullptr;
56 //Most objects recorded to the SG may not be retrieved
57 //using a non-const handle, unless the original producer of the object
58 //allowed for later modifications invoking StoreGateSvc::record with
59 //the last "allowMods" optional argument = true
60
61 // We retrieve our MyDataObj, using m_DataProducer as our key
63 dobj3->val(4); // should be able to do this
64
65 // Also check retrieving it as a const object via ReadHandle.
66 assert (m_dobj3->val() == 4);
67
68 //not every type can be used as a key.
69 //These requirements are checked at compile time in the record method
70 //using StoreGate/constraints/KeyConcept.h
71 //uncomment to see how the key concept is checked by the compiler
72 // p_SGevent->retrieve(dobj3, 1.0);
73 //concept checking does not work using egcs 1.1 (gcc 2.91)
74 //(but you still get a compiler error message...)
75
77 // iii) Get all recorded instances of MyDataObj, print out their contents
78
79 // (a SG::ConstIterator is an iterator class that we also use to defer
80 // and control the access to the persistent object)
81 SG::ConstIterator<MyDataObj> iMyD;
82 SG::ConstIterator<MyDataObj> eMyD;
83
84 ATH_CHECK (evtStore()->retrieve(iMyD, eMyD));
85
86 // while(iMyD != eMyD) {
87 // ATH_MSG_INFO ((*iMyD).val());
88 // ++iMyD;
89 // }
90 ATH_MSG_WARNING ("FIXME loop of ConstIterator bombs");
91
92
93
95 // Get the default listof MyContObj, print out its contents
96
97 //the CLID of list<MyContObj> must be defined using the CLASSDEF
98 //macros. See StoreGateExample_ClassDEF.h for a few examples
99 //If no CLID is defined StoreGate assumes the object is (convertible to a)
100 //DataObject. If this is not the case an error message is issued:
101 //uncomment below to see how your compiler catches an undefined CLID
102 //ERROR p_SGevent->retrieve(errorH);
103
105
106 //now let's try again with a const pointer
107 const DataVector<MyContObj>* list = nullptr;
108
109 ATH_CHECK (evtStore()->retrieve(list));
110 ATH_MSG_INFO ("Retrieved DataVector of MyContObj using a const pointer");
111
112 for (const MyContObj* obj : *list) {
113 float time = obj->time();
114 int ID = obj->id();
115
116 ATH_MSG_INFO ("Time: " << time << " ID: " << ID);
117 }
118
120 // Get the std::vector, print out its contents
121
122 const std::vector<float>* pVec = nullptr;
123
124 ATH_CHECK (evtStore()->retrieve(pVec));
125 for (unsigned int it=0; it<pVec->size(); it++) {
126 ATH_MSG_INFO ("pVec [" << it << "] = " << (*pVec)[it]);
127 }
128
129 // test if an object is not in the store
130 if (evtStore()->contains<MyDataObj>("FunnyNonExistingKey")) {
132 ("event store claims it contains MyDataObj with FunnyNonExistingKey");
133 return( StatusCode::FAILURE);
134 } else {
136 ("event store does not contain MyDataObj with FunnyNonExistingKey");
137 }
138
139
140
142 // Part 2: retrieving DataLinks
143
144 // Get the list of links, print out its contents
145
146 typedef ElementLink<std::vector<float> > VecElemLink;
147 const std::list<VecElemLink>* pList = nullptr;
148
149 ATH_CHECK (evtStore()->retrieve(pList));
150 ATH_MSG_INFO ("Retrieved list of links");
151
152 std::list<VecElemLink>::const_iterator itL= pList->begin();
153 std::list<VecElemLink>::const_iterator endL= pList->end();
154
155 while(itL != endL) {
156 ATH_MSG_INFO ("ListVecLinks::linked element " << **itL);
157 ++itL;
158 }
159
160 // Get the vector of links, print out its contents
161
162 typedef ElementLink<MapStringFloat> MapElemLink;
163 const std::vector<MapElemLink>* vectorHandle = nullptr;
164
165 ATH_CHECK (evtStore()->retrieve(vectorHandle));
166 ATH_MSG_INFO ("Retrieved vector of links");
167
168 std::vector<MapElemLink>::const_iterator itV= vectorHandle->begin();
169 std::vector<MapElemLink>::const_iterator endV= vectorHandle->end();
170 while(itV != endV) {
172 ("VectorMapLinks::linked element: key " << itV->index()
173 << " - value " << (**itV)
174 << " - stored as " << *itV);
175 ++itV;
176 }
177
178 //try to "read back" a link
179 // istrstream istr("due 0");
180 // MapElemLink toBeRead;
181 // istr >> toBeRead;
182 // if (!toBeRead.isValid()) {
183 // log << MSG::ERROR
184 // << "Could not read back MapElement"
185 // << endmsg;
186 // return( StatusCode::FAILURE);
187 // } else {
188 // log << MSG::INFO << "MapElement read back: key " << toBeRead->first
189 // << " value " << toBeRead->second <<endmsg;
190 // }
191
193 // Part 3: symbolic links and derived types
194 // Get all objects as its base class
195
196 SG::ConstIterator<BaseClass> it2;
197 SG::ConstIterator<BaseClass> iEnd2;
198
199 ATH_CHECK (evtStore()->retrieve(it2, iEnd2));
200
201 // not much we can do with an empty base class,
202 // so print the path of its persistable companion (the DataBucket)
203 ATH_MSG_INFO (" retrieve as BaseClass, print its address: ");
204 while(it2 != iEnd2) {
205 ATH_MSG_INFO (&*it2);
206 ++it2;
207 }
208
210 // Part 4: Get the event header, print out event and run number
211
212 SG::ReadHandle<xAOD::EventInfo> eventInfo(m_eventInfo);
213 if(eventInfo.isValid()) {
214 int event = eventInfo->eventNumber();
215 int run = eventInfo->runNumber();
216 ATH_MSG_INFO (" EventInfo : "
217 << " event: " << event
218 << " run: " << run);
219 }
220 else
221 {
222 ATH_MSG_ERROR (" Unable to retrieve EventInfo from StoreGate ");
223 return StatusCode::SUCCESS;
224 }
225
226 return StatusCode::SUCCESS;
227}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
std::vector< Identifier > ID
DataModel_detail::const_iterator< DataVector > const_iterator
Standard const_iterator.
Definition DataVector.h:838
void val(int i)
Definition MyDataObj.h:24
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfo
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:114
time(flags, cells_name, *args, **kw)
list(name, path='/')
Definition histSizes.py:38
retrieve(aClass, aKey=None)
Definition PyKernel.py:110

◆ extraDeps_update_handler()

void AthCommonDataStore< AthCommonMsg< Algorithm > >::extraDeps_update_handler ( Gaudi::Details::PropertyBase & ExtraDeps)
protectedinherited

Add StoreName to extra input/output deps as needed.

use the logic of the VarHandleKey to parse the DataObjID keys supplied via the ExtraInputs and ExtraOuputs Properties to add the StoreName if it's not explicitly given

◆ extraOutputDeps()

const DataObjIDColl & AthAlgorithm::extraOutputDeps ( ) const
overridevirtualinherited

Return the list of extra output dependencies.

This list is extended to include symlinks implied by inheritance relations.

Definition at line 50 of file AthAlgorithm.cxx.

51{
52 // If we didn't find any symlinks to add, just return the collection
53 // from the base class. Otherwise, return the extended collection.
54 if (!m_extendedExtraObjects.empty()) {
56 }
57 return Algorithm::extraOutputDeps();
58}

◆ initialize()

StatusCode ReadData::initialize ( )
overridevirtual

Definition at line 23 of file Control/AthenaExamples/AthExStoreGateExample/src/ReadData.cxx.

23 {
24
25 ATH_MSG_INFO ("in initialize()");
26
27 // Print out the location of the data objects
28 ATH_MSG_INFO ("Data Object producer: " << m_DataProducer.value());
29
30 //locate the StoreGateSvc and initialize our local ptr
32
34 ATH_CHECK( m_dobj3.initialize() );
35
36 ATH_CHECK( m_eventInfo.initialize() );
37
38 return StatusCode::SUCCESS;
39}

◆ inputHandles()

virtual std::vector< Gaudi::DataHandle * > AthCommonDataStore< AthCommonMsg< Algorithm > >::inputHandles ( ) const
overridevirtualinherited

Return this algorithm's input handles.

We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.

◆ msg()

MsgStream & AthCommonMsg< Algorithm >::msg ( ) const
inlineinherited

Definition at line 24 of file AthCommonMsg.h.

24 {
25 return this->msgStream();
26 }

◆ msgLvl()

bool AthCommonMsg< Algorithm >::msgLvl ( const MSG::Level lvl) const
inlineinherited

Definition at line 30 of file AthCommonMsg.h.

30 {
31 return this->msgLevel(lvl);
32 }

◆ outputHandles()

virtual std::vector< Gaudi::DataHandle * > AthCommonDataStore< AthCommonMsg< Algorithm > >::outputHandles ( ) const
overridevirtualinherited

Return this algorithm's output handles.

We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.

◆ renounce()

std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > AthCommonDataStore< AthCommonMsg< Algorithm > >::renounce ( T & h)
inlineprotectedinherited

Definition at line 380 of file AthCommonDataStore.h.

381 {
382 h.renounce();
384 }
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce(T &h)

◆ renounceArray()

void AthCommonDataStore< AthCommonMsg< Algorithm > >::renounceArray ( SG::VarHandleKeyArray & handlesArray)
inlineprotectedinherited

remove all handles from I/O resolution

Definition at line 364 of file AthCommonDataStore.h.

364 {
366 }

◆ sysInitialize()

StatusCode AthAlgorithm::sysInitialize ( )
overridevirtualinherited

Override sysInitialize.

Override sysInitialize from the base class.

Loop through all output handles, and if they're WriteCondHandles, automatically register them and this Algorithm with the CondSvc

Scan through all outputHandles, and if they're WriteCondHandles, register them with the CondSvc

Reimplemented from AthCommonDataStore< AthCommonMsg< Algorithm > >.

Reimplemented in AthAnalysisAlgorithm, AthFilterAlgorithm, AthHistogramAlgorithm, and PyAthena::Alg.

Definition at line 66 of file AthAlgorithm.cxx.

66 {
68
69 if (sc.isFailure()) {
70 return sc;
71 }
72 ServiceHandle<ICondSvc> cs("CondSvc",name());
73 for (auto h : outputHandles()) {
74 if (h->isCondition() && h->mode() == Gaudi::DataHandle::Writer) {
75 // do this inside the loop so we don't create the CondSvc until needed
76 if ( cs.retrieve().isFailure() ) {
77 ATH_MSG_WARNING("no CondSvc found: won't autoreg WriteCondHandles");
78 return StatusCode::SUCCESS;
79 }
80 if (cs->regHandle(this,*h).isFailure()) {
81 sc = StatusCode::FAILURE;
82 ATH_MSG_ERROR("unable to register WriteCondHandle " << h->fullKey()
83 << " with CondSvc");
84 }
85 }
86 }
87 return sc;
88}
static Double_t sc
virtual StatusCode sysInitialize() override
Override sysInitialize.
virtual std::vector< Gaudi::DataHandle * > outputHandles() const override
::StatusCode StatusCode
StatusCode definition for legacy code.

◆ sysStart()

virtual StatusCode AthCommonDataStore< AthCommonMsg< Algorithm > >::sysStart ( )
overridevirtualinherited

Handle START transition.

We override this in order to make sure that conditions handle keys can cache a pointer to the conditions container.

◆ updateVHKA()

void AthCommonDataStore< AthCommonMsg< Algorithm > >::updateVHKA ( Gaudi::Details::PropertyBase & )
inlineinherited

Definition at line 308 of file AthCommonDataStore.h.

308 {
309 // debug() << "updateVHKA for property " << p.name() << " " << p.toString()
310 // << " size: " << m_vhka.size() << endmsg;
311 for (auto &a : m_vhka) {
313 for (auto k : keys) {
314 k->setOwner(this);
315 }
316 }
317 }
std::vector< SG::VarHandleKeyArray * > m_vhka

Member Data Documentation

◆ m_DataProducer

Gaudi::Property<std::string> ReadData::m_DataProducer {this, "DataProducer", ""}
private

Definition at line 32 of file Control/AthenaExamples/AthExStoreGateExample/src/ReadData.h.

32{this, "DataProducer", ""};

◆ m_detStore

StoreGateSvc_t AthCommonDataStore< AthCommonMsg< Algorithm > >::m_detStore
privateinherited

Pointer to StoreGate (detector store by default)

Definition at line 393 of file AthCommonDataStore.h.

◆ m_dobj3

SG::ReadHandle<MyDataObj> ReadData::m_dobj3
private

◆ m_eventInfo

SG::ReadHandleKey<xAOD::EventInfo> ReadData::m_eventInfo {this, "EvtInfo", "EventInfo", "EventInfo name"}
private

Definition at line 34 of file Control/AthenaExamples/AthExStoreGateExample/src/ReadData.h.

34{this, "EvtInfo", "EventInfo", "EventInfo name"};

◆ m_evtStore

StoreGateSvc_t AthCommonDataStore< AthCommonMsg< Algorithm > >::m_evtStore
privateinherited

Pointer to StoreGate (event store by default)

Definition at line 390 of file AthCommonDataStore.h.

◆ m_extendedExtraObjects

DataObjIDColl AthAlgorithm::m_extendedExtraObjects
privateinherited

Definition at line 79 of file AthAlgorithm.h.

◆ m_varHandleArraysDeclared

bool AthCommonDataStore< AthCommonMsg< Algorithm > >::m_varHandleArraysDeclared
privateinherited

Definition at line 399 of file AthCommonDataStore.h.

◆ m_vhka

std::vector<SG::VarHandleKeyArray*> AthCommonDataStore< AthCommonMsg< Algorithm > >::m_vhka
privateinherited

Definition at line 398 of file AthCommonDataStore.h.


The documentation for this class was generated from the following files: