23.05.2014 Views

Athena Developer Guide

Athena Developer Guide

Athena Developer Guide

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Athena</strong><br />

Chapter 8 StoreGate - the event data access model Version/Issue: 2.0.0<br />

Typically MyDataObj will be a collection containing several objects. You may iterate over these<br />

Contained Objects using the code shown in Listing 8.10:<br />

Listing 8.10 Iterate over Contained Objects<br />

MyDataObj::iterator first = dhandle->begin();<br />

MyDataObj::iterator last = dhandle->end();<br />

for (; first != last; ++first)<br />

{<br />

(*first)->use_me();<br />

}<br />

where (*first) is the pointer to the Contained Object; use_me() is a method in this Contained Object<br />

and ++first iterates over the Contained Objects.<br />

8.6.2 Retrieving a keyed DataObject<br />

In the WriteData example, three MyDataObj were recorded in the TDS, but only one with a key. The<br />

key was a string key containing “MyDataObjName”. Here we will show how to retrieve that<br />

DataObject. Note that since no other MyDataObj can be registered with a key “MyDataObjName”, you<br />

will retrieve at most one object. Note further that this is not necessarily the last DataObject of this type<br />

recorded in the TDS.<br />

Listing 8.11 Retrieve a keyed DataObject<br />

std::string keystring = "MyDataObjName";<br />

DataHandle dhandle; //non-const access required. May fail!!!<br />

StatusCode sc = storeGateSvc()->retrieve(dhandle,keystring);<br />

if (sc.isFailure())<br />

{<br />

log

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!