Making TDS objects and Converters |
This purpose of this document is to describe the procedure for creating a new TDS (Transient Data Store) object and the matching Gaudi converter. The full Gaudi manual is also available here.
Creating a TDS object is a straight forward procedure. For an object to live in the TDS it must inherit from either of the Gaudi classes DataObject or ContainedObject.
How do I choose between the two?
- DataObject is meant for the case when you have only one object of this type in the TDS.
- Contained object is meant for the case when you want several of these objects all wrapped up in a STL style container.
To write the class start with either of these examples TDSDataObject.h or TDSContainedObject.h. Add your own data members and what ever access methods you would like. The serialize methods allow the classes to to pass into and out of the Gaudi Persistent Data Store(PDS).
There are several modifications that will need to be made outside of the class. First, a spot will need to be defined for the object in the GLAST Event Model.
- Start by adding: const "CLID_TDSDataObject = appropritenumber" to EventModel.cpp
- Have a look EventModel.h. If you wanted to add a class called TDSDataObject to the MC branch of the TDS you you would add the line:
- _EXTERN_ std::string TDSDataObject;
to the MC namespace
- Now add the line
- EventModel::MC::TDSDataObject = EventModel::MC::Event + "/TDSDataObject";
to EventModel.cpp. This defines a variable name that can be used to specify the TDS path for a particular object.
Start by taking the examples MyCnv.h MyCnv.cxx. Also have a look at the currently implemented converters in GlastSvc as examples.
One can make a request of the TDS either by making a call to retrieveObject or by using a SmartPointer. Either way, the behavior is the same. When you ask for a TDS object via a SmartPointer thusly
- SmartDataPtr<TDSDataObject> myVar(eventSvc(), "/Event/MC/TDSDataObject");
The TDS checks to see if there is such an object in the TDS in the place you designated. If the object is already available in the TDS - it is passed back to the caller. If the object is not currently available, the object's converter is called to create the object. The converter's createObject() method is called, which handles the creation of the object and filling it with appropriate data.
Technicalities related to converters:
Once you have a converter you will need to add a macro call in GlastSvc_load. Once again with the example, you will need to add the line
DECLARE_CONVERTER( MyCnv );
to make sure that the converter is linked into the GlastSvc DLL.
Please have a look at the userAlg package as example of how to write an algorithm. This is the simplest thing to do in Gaudi. Three methods must be implemented in all Gaudi algorithms, initialize() execute() and Finalize().
Algorithms can create and add DataObjects to the TDS. This is done via a call to the registerObject method
DataSvc::registerObject(const std::string& fullPath, DataObject* pObject);
Example: dataSvc()-> registerObject("/Event/MC/TDSDataObject/", myObject)
Once you have a TDS object and what you think should be a working converter you can test it out by adding some code to the built in test program in GlastSvc. You will need to add what ever testing code you want to CreateEvent.cpp under the test project you get with GlastSvc. The usual procedure for testing a newly created TDS object is to load if from the TDS and then check the data members.
Ian Gable 2002-03-20 14:32:48 -0800