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 7 Accessing data Version/Issue: 2.0.0<br />

The first four methods are for retrieving a pointer to an object that is already in the store. How the<br />

object got into the store, whether it has been read in from a persistent store or added to the store by an<br />

algorithm, is irrelevant.<br />

The find and retrieve methods come in two versions: one version uses a full path name as an<br />

object identifier, the other takes a pointer to a previously retrieved object and the name of the object to<br />

look for below that node in the tree.<br />

Additionally the find and retrieve methods differ in one important respect: the find method will<br />

look in the store to see if the object is present (i.e. in memory) and if it is not will return a null pointer.<br />

The retrieve method, however, will attempt to load the object from a persistent store (database or<br />

file) if it is not found in memory. Only if it is not found in the persistent data store will the method<br />

return a null pointer (and a bad status code of course).<br />

7.3 Using data objects<br />

Whatever the concrete type of the object you have retrieved from the store the pointer which you have<br />

is a pointer to a DataObject, so before you can do anything useful with that object you must cast it to<br />

the correct type, for example:<br />

1: typedef ObjectVector MyTrackVector;<br />

2: DataObject *pObject;<br />

3:<br />

4: StatusCode sc = eventSvc()->retrieveObject(“/Event/MyTracks”,pObject);<br />

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

6: return sc;<br />

7:<br />

8: MyTrackVector *tv = 0;<br />

9: try {<br />

10: tv = dynamic_cast (pObject);<br />

11: } catch(...) {<br />

12: // Print out an error message and return<br />

13: }<br />

14: // tv may now be manipulated.<br />

The typedef on line 1 is just to save typing: in what follows we will use the two syntaxes<br />

interchangeably. After the dynamic_cast on line 10 all of the methods of the MyTrackVector<br />

class become available. If the object which is returned from the store does not match the type to which<br />

you try to cast it, an exception will be thrown. If you do not catch this exception it will be caught by the<br />

algorithm base class, and the program will stop, probably with an obscure message. A more elegant<br />

way to retrieve the data involves the use of Smart Pointers - this is discussed in section 7.8<br />

As mentioned earlier a certain amount of run-time investigation may be done into what data is available<br />

in the store. For example, suppose that we have various sets of testbeam data and each data set was<br />

taken with a different number of detectors. If the raw data is saved on a per-detector basis the number of<br />

page 45

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

Saved successfully!

Ooh no, something went wrong!