Using the Persistent Data Store

Purpose:

We use the Persistent Data Store (PDS) to save and retrieve data for later use.  This page explains how to setup a Gaudi job options file to store data into or read data from a Root file (our chosen format for persistent data) - and how to setup a new DataObject to be available for storage into a persistent form.

Setting up the Job Options:

Parameters to create a Root output file:

// Create an instance of DbEventCnvSvc - named RootDbEvtCnvSvc, (this name can be anything you want - just be consistent!)

ApplicationMgr.ExtSvc = { "DbEventCnvSvc/RootDbEvtCnvSvc" }; 

ApplicationMgr.DLLs = { "RootDb" };  // tell Gaudi to load the RootDb Dll

// Define name for output writer - again you can provide any name you want here
ApplicationMgr.OutStream = { "RootDst" };

// Add Root as a potential persistency converter service
EventPersistencySvc.CnvServices = {"RootDbEvtCnvSvc"};

// RootEvtCnvSvc uses DbType in Gaudi v6 - not in Gaudi v5!
RootDbEvtCnvSvc.DbType = "ROOT";

// Setup options for Root output
// The value #9999 denotes how many directory levels below to go
RootDst.ItemList = {"/Event#9999"};
// name of output file - whatever you want
RootDst.Output = "DATAFILE='output.root' TYP='ROOT'";

Job Option Parameters to read from a Root file:

// Add an instance of the DbEventCnvSvc named RootDbEvtCnvSvc
ApplicationMgr.ExtSvc = { "DbEvtSelector/EventSelector", "DbEventCnvSvc/RootDbEvtCnvSvc" };

// List of DLLs
ApplicationMgr.DLLs = { "GlastSvc", "RootDb", "GlastEventFactories"};

// Input root file
EventSelector.Input = "FILE output.root";

// Persistency service setup:
// Add Root as a potential persistency converter service
EventPersistencySvc.CnvServices = {"RootDbEvtCnvSvc"};

// RootEvtCnvSvc setup for Gaudi v6
RootDbEvtCnvSvc.DbType = "ROOT";

EventSelector.CnvService = "RootDbEvtCnvSvc";

// Number of events to be processed
ApplicationMgr.EvtMax = 20;

What is going on behind the scenes

Gaudi provides a package, DbCnv, that is an interface to various persistency mechanisms, including Root.  We have our own package called GlastDb that utilizes the libraries available in DbCnv.  One of those libraries in DbCnv is RootDb which is used to write and read from Root within Gaudi.  Loading of the library is accomplished by updating the job options file for your particular application.

GlastDb also contains some Glast specific code that allows the data in TDS to be written to or read from a Root file. A small amount of code is required for each type of data that we desire to make available for Root I/O.  

How to setup a new DataObject to be available for Persistent storage

Each class that we desire to make available for Root I/O must implement 2 versions of a method called serialize.  The serialize method streams the bits associated with our class into a buffer.  Here is an example:

inline StreamBuffer& myType::serialize( StreamBuffer& s ) const {
ContainedObject::serialize(s);
return s << m_data1 << m_data2;
}

inline StreamBuffer& myType::serialize( StreamBuffer& s ) {
ContainedObject::serialize(s);
return s >> m_data1 >> m_data2;
}

Now the DataObject is prepared to for persistent storage. Next the appropriate converter must be setup.  The Root specific converters are defined by a macro.  There are 2 types of macros provided by Gaudi:  one for collections of objects, and another for objects that are not collections:  _ImplementContainerConverters( myType ) and  _ImplementConverter( myType )