Presentation is loading. Please wait.

Presentation is loading. Please wait.

Athena StoreGate Tutorial: May 30, 2002 1 Objectives Learn how to access data objects using StoreGate How to record/retrieve by TYPE Optionally using keys.

Similar presentations


Presentation on theme: "Athena StoreGate Tutorial: May 30, 2002 1 Objectives Learn how to access data objects using StoreGate How to record/retrieve by TYPE Optionally using keys."— Presentation transcript:

1 Athena StoreGate Tutorial: May 30, 2002 1 Objectives Learn how to access data objects using StoreGate How to record/retrieve by TYPE Optionally using keys Retrieving of all data objects of a given type How to use Data Links Persistable relationships

2 Athena StoreGate Tutorial: May 30, 2002 2 Why StoreGate? To manage Data Objects life-time SG manages data objects memory (owns them) SG interacts with the Event Store to write/read data objects from disk/tape To access Data Objects Type-Centric Naming service Give me the TrackCollection called “MyTracks” Navigation Persistable references (DataLinks) History Give me the TrackCollection made by MyRecoAlgorithm How was this TrackCollection made?

3 Athena StoreGate Tutorial: May 30, 2002 3 Transient Event Store CaloRec e  Collection ClusterCollection TrackCollection D D D DigitCollectionDigits Converter PersistencyOn-demandaccess H H H H H Reconstruction / Data Flow Converter Persistency OutputStream AthenaAlgorithmsClusters iPatRec Clusters xKalman Tracks, Clusters egammaRec key-Akey-B DataLinks (illustration only)

4 Athena StoreGate Tutorial: May 30, 2002 4 Basics: Recording an Object Providing a Key: StatusCode sc = m_storeGate  record(TrkColl, TrkCollKey); where : TrkColl is a pointer to your TrackCollection (a DataObject) TrkCollKey is an identifier for your data object also specified in your jobOptions in a similar way. It can be a simple string like: “MyTrackCollection” Keyless: StatusCode sc = m_storeGate  record(TrkColl); Locking an Object StatusCode sc = m_storeGate  setConst(TrkColl);

5 Athena StoreGate Tutorial: May 30, 2002 5 Basics: Retrieving an Object Specifying a Key: const DataHandle TrkColl; sc = m_storeGate  retrieve( TrkColl, TrkCollKey); We create an instance of the DataHandle (TrkColl) and pass it to the retrieve method. It is returned to you and can be used as a pointer (to be precise as an STL forward iterator): TrkColl  some_method_in_TrackCollection(); Retrieving the Default instance: const DataHandle defaultTrkColl; sc = m_storeGate  retrieve( defaultTrkColl);

6 Athena StoreGate Tutorial: May 30, 2002 6 Basics: Retrieving all Data Objects of Given Type If you have several TrackCollection instances in SG and you wish to retrieve ALL of them, this is what you do: DataHandle dbegin, dend; sc = m_storegate  retrieve(dbegin, dend); for (; dbegin != dend; ++ dbegin) // loop over TrackCollections { dbegin  method_in_trackCollection(); TrackCollection::iterator iter dbegin  begin(); for (; iter != dbegin  end(); ++iter) // loop over TrackObjects { (*iter)  TrackPT(); // call some method in Track }

7 Athena StoreGate Tutorial: May 30, 2002 7 Store Access Policy An object in SG may be modified until it is setConst Access to a const Data Object: const DataHandle trackHandle; sc = m_storegate  retrieve( trackHandle, key ); Only const methods in the Data Object are accessible! class Track { void set_pT(float pT) { m_pT = pT; } // NO ACCESS float get_pT const { return m_pT; } // ACCESS OK … } Must use const-iterators to iterate over TrackCollection If you do not specify const, this will force a check. If the data object you are accessing is ‘const’, then an error is returned if accessing it in a non-const way.

8 Athena StoreGate Tutorial: May 30, 2002 8 Hands On: Exercise In the ADL exercise, you have created a LArCell and a CaloCell data class (in Example1 and Example2 package) You will find two algorithms: WriteData and ReadData in tutAlg package The purpose of WriteData Algorithm is to record objects (LArCell) in StoreGate. The purpose of ReadData Algorithm is to retrieve the objects (LArCell) recorded by WriteData algorithm.

9 Athena StoreGate Tutorial: May 30, 2002 9 HandOn: Exercise The header files in ReadData and WriteData are already setup correctly. The #includes in WriteData.cxx and ReadData.cxx are also setup correctly. The properties from jobOptions file are also retrieved using declareProperty in the initialize method. Check this and the jobOptions file in the run area. The objects LArCell has also been created for you. Your job is to: get the pointer to StoreGateSvc in both algorithms record the LArCell objects in WriteData and check error status Retrieve the objects in ReadData in different ways, check error and print data content of these objects

10 Athena StoreGate Tutorial: May 30, 2002 10 Hands On: Accessing StoreGate StoreGateSvc is the Gaudi service that allows to record and retrieve data objects. Obtain the pointer to the StoreGateSvc: In the initialize method of both your algorithms: StatusCode sc = service(“StoreGateSvc”, m_storeGate); m_storeGate should be declared as a private data member of type StoreGateSvc* This is already done in the header file. Check it. This caches m_storeGate and you do not have to call the serviceLocator to retrieve the pointer to StoreGateSvc every event in your execute method. Check the StatusCode and print error if failure

11 Athena StoreGate Tutorial: May 30, 2002 11 Hands On: Record Data Objects (contd.) Fill in SGWriteData::execute :: There are two LArCell objects already created for you. Record the LArCell by data type with a key = (property from jobOptions) StatusCode sc = m_storeGate  record(pdobj, m_DataObj1Name); where pdObj is the pointer to the LArCell object. m_DataObj1Name is the key name defined in jobOptions and retrieved using the property service in the initialize method. Record each of the LArCell objects with a different key.

12 Athena StoreGate Tutorial: May 30, 2002 12 Hands On: Retrieve Data Objects (contd.) Fill in ReadData::execute You need to : Create a “const” DataHandle and pass it to the retrieve method Using same key! const DataHandle dobj; StatusCode sc = m_storeGate->retrieve(dobj, m_DataObj1Name); On return, dobj can be used as a pointer to the LArCell object Print the LArCell data using message service: dobj_->print(); will print the cell data on your screen

13 Athena StoreGate Tutorial: May 30, 2002 13 Hands On: Retrieve Data Objects (contd.) Retrieve all the LArCell object in the Store (note that you recorded two of them with different keys): const DataHandle d1, d2; StatusCode sc = m_storeGate->retrieve(d1,d2); Now you have all the LArCell objects. Iterate over them and dump the content: for (; d1 != d2; d1++) { log print() << endreq; }

14 Athena StoreGate Tutorial: May 30, 2002 14 Hands On: build ReadData and WriteData From TestRelease/ /cmt cmt broadcast gmake cd to the run area Where the jobOption files are In your jobOptions file, you need: Declare a string key for each LArCell data object in SG, e.g., WriteData.DataObj1Name = “MyData” ReadData.DataObj1Name = “MyData” And similarily for the second LArCell data object Run athena and make sure that print outs are what you expect.

15 Athena StoreGate Tutorial: May 30, 2002 15 StoreGate : PART II You will now be working with the package tutAlg2. LArCell objects have already been created for you. Your job is to : Create a LArCellCollection and push the LArCell objects into the collection. record a collection of LArCell objects in WriteData.cxx Retrieve a Collection of LArCell objects in ReadData.cxx Iterate over the collection of these objects and call the print method for each of these objects.

16 Athena StoreGate Tutorial: May 30, 2002 16 Part III: Data Links Allow to establish a persistable inter objects relationship A Track holding pointers to a set of associated hits. A link can be to a single object/collection DataLink m_objLink; DataLink m_collectionLink; in a list/vector (SequenceLink), a map (MapLink) or a set (SetLink) or non-STL container like HepMC Or an element in a list/vector (SequenceLink), a map (MapLink) or a set (SetLink) or non-STL container like HepMC SequenceLink >::type m_contLink; The data link can be used as though it was a pointer to the data object or to the element. To get to the ‘real’ object/element one has to dereference the link *m_objLink *m_contLink Collections must not be modified after a DataLink to an element in the collection has been established.

17 Athena StoreGate Tutorial: May 30, 2002 17 Creating a DataLink Example: Link to a data object m_objLink.toStorableObject(dobj); Link to a contained object std::vector * pVect; SequenceLink >::type seqLink; seqLink.toContainedElement(*pVect, pElement); time consuming index search A faster way: seqLink.toIndexedElement(*pv, index); index = 0 for first element, 1 for second element, … Not in 3.0.0: use StoreGate-02-00-16

18 Athena StoreGate Tutorial: May 30, 2002 18 Hands On: LinkObj class In LinkObj.h: Insert as data members a DataLink to a MyDataObj and a SequenceLink to a MyElement in the vector created in part 2 Implement LinkObj methods using m_objLink.toStorableObject(dobj); m_contLink.toContainedElement(coll, cobj); Or better m_contLink.toIndexedElement(coll, index); Implement a LinkObj extractor (operator <<) that invokes the linked-to object extractors. For the SequenceLink also print the index value ost << “ link to MyElement[“ << rhs.m_contLink.index()”] :” << *rhs.m_contLink;

19 Athena StoreGate Tutorial: May 30, 2002 19 Hands On: using LinkObj In both algorithms include #include "StoreGate/DataLink.h" #include "StoreGate/tools/STLlinks.h” #include “Tutorial_ClassDef.h In SGWrite (Part 3): Instantiate a LinkObj Establish the data links in LinkObj to MyDataObj and an element within vector. In SGRead (Part 3): Retrieve the LinkObj and verify that it has worked. log << MSG::INFO << "retrieved default LinkObj:\n" << *linkObj << endreq;

20 Athena StoreGate Tutorial: May 30, 2002 20 Hands On: ClassDEFs Take a look at Tutorial_ClassDEF.h It contains the CLASS_DEF macros for the “external” data object your package uses (typically the STL containers) In this case we have (omitting namespaces) CLASS_DEF(vector<MyElement, 9903, 1) “9903” is the famous CLID “1” is the version number (currently ignored by SG) More examples are in../src/StoreGateExample_ClassDEF.h


Download ppt "Athena StoreGate Tutorial: May 30, 2002 1 Objectives Learn how to access data objects using StoreGate How to record/retrieve by TYPE Optionally using keys."

Similar presentations


Ads by Google