Commit 8cb50fc3 authored by Marco Clemencic's avatar Marco Clemencic
Browse files

Imported RootCnv from LHCb.

IN PROGRESS - issue GAUDI-1: Split GaudiSvc in smaller libraries
https://sftjira.cern.ch/browse/GAUDI-1

From: Marco Clemencic <marco.clemencic@cern.ch>


git-svn-id: svn+ssh://svn.cern.ch/reps/gaudi/Gaudi/branches/GAUDI/GAUDI_newpack@6729 53ecefc3-a64d-0410-9bdf-b8581fa3287e
parent 3a6afdec
......@@ -30,6 +30,7 @@ use GaudiUtils v3r14
use GaudiPartProp v1r0
# Technology-specific Persistency packages
use RootCnv *
use RootHistCnv v10r7
use GaudiPython v11r1
......
// $Id: RootAddress.h,v 1.8 2010-09-17 09:40:02 frankb Exp $
//====================================================================
// RootAddress.h
//--------------------------------------------------------------------
//
// Author : M.Frank
//====================================================================
// $Header: /afs/cern.ch/project/cvs/reps/lhcb/Online/RootCnv/src/RootAddress.h,v 1.8 2010-09-17 09:40:02 frankb Exp $
#ifndef GAUDIROOTCNV_ROOTADDRESS_H
#define GAUDIROOTCNV_ROOTADDRESS_H
// Framework include files
#include "GaudiKernel/GenericAddress.h"
#include "TTreeFormula.h"
// Forward declaration
class TTree;
class TTreeFormula;
/*
* Gaudi namespace declaration
*/
namespace Gaudi {
// Forward declarations
class RootDataConnection;
/** @class RootAddress RootAddress.h GaudiRoot/RootAddress.h
*
* Description:
*
* Definition of a transient link which is capable of locating
* an object in the persistent storage.
*
* @author M.Frank
* @version 1.0
*/
class GAUDI_API RootAddress : virtual public GenericAddress {
public:
/// Pointer to ROOT select statement (filled for N-tuples only)
TTreeFormula* select;
/// Pointer to ROOT TTree (filled for N-tuples only)
TTree* section;
public:
/// Full constructor
RootAddress( long svc,
const CLID& clid,
const std::string& p1="",
const std::string& p2="",
unsigned long ip1=0,
unsigned long ip2=0)
: GenericAddress(svc,clid,p1,p2,ip1,ip2), select(0), section(0) { }
/// Standard Destructor
virtual ~RootAddress() { if ( select ) delete select; select = 0; }
};
}
#endif // GAUDIROOTCNV_ROOTADDRESS_H
// $Id: RootCnvSvc.h,v 1.7 2010-09-14 06:01:12 frankb Exp $
//====================================================================
// RootCnvSvc definition
//--------------------------------------------------------------------
//
// Author : M.Frank
//====================================================================
#ifndef GAUDIROOTCNV_GAUDIROOTCNVSVC_H
#define GAUDIROOTCNV_GAUDIROOTCNVSVC_H
// $Header: /afs/cern.ch/project/cvs/reps/lhcb/Online/RootCnv/src/RootCnvSvc.h,v 1.7 2010-09-14 06:01:12 frankb Exp $
// Framework include files
#include "GaudiKernel/ConversionSvc.h"
#include "GaudiKernel/DataObject.h"
#include "GaudiKernel/ClassID.h"
// C++ include files
#include <set>
// Forward declarations
class IDataManagerSvc;
class IIncidentSvc;
class TClass;
/*
* Gaudi namespace declaration
*/
namespace Gaudi {
// Forward declarations
class IIODataManager;
class IDataConnection;
class RootDataConnection;
class RootConnectionSetup;
/** @class RootCnvSvc RootCnvSvc.h src/RootCnvSvc.h
*
* Description:
*
* RootCnvSvc class implementation definition.
*
* @author Markus Frank
* @version 1.0
* @date 20/12/2009
*/
class GAUDI_API RootCnvSvc : public ConversionSvc {
protected:
/// Reference to the I/O data manager
Gaudi::IIODataManager* m_ioMgr;
/// Reference to incident service
IIncidentSvc* m_incidentSvc;
/// On writing: reference to active output stream
Gaudi::RootDataConnection* m_current;
/// TClass pointer to reference class
TClass* m_classRefs;
/// TClass pointer to DataObject class
TClass* m_classDO;
/// Setup structure (ref-counted) and passed to data connections
RootConnectionSetup* m_setup;
/// Property: ROOT section name
std::string m_currSection;
/// Property: Flag to enable incidents on FILE_OPEN
bool m_incidentEnabled;
/// Property: Share files ? If set to YES, files will not be closed on finalize
std::string m_shareFiles;
/// Property: Records name to fire incident for file records
std::string m_recordName;
/// Property: Enable TTree IOperfStats if not empty; otherwise perf stat file name
std::string m_ioPerfStats;
/// Set with bad files/tables
std::set<std::string> m_badFiles;
/// Message streamer
MsgStream* m_log;
/// Helper: Get TClass for a given DataObject pointer
TClass* getClass(DataObject* pObject);
/// Helper: Use message streamer
MsgStream& log() const { return *m_log; }
public:
/// Standard constructor
RootCnvSvc(const std::string& name, ISvcLocator* svc);
/// Standard destructor
virtual ~RootCnvSvc();
/// Update state of the service
virtual StatusCode updateServiceState(IOpaqueAddress* /* pAddress */)
{ return StatusCode::SUCCESS; }
/** Standard way to print errors. after the printout an exception is thrown.
* @param msg [IN] Message string to be printed.
*
* @return Status code returning failure.
*/
StatusCode error(const std::string& msg);
/** Connect the output file to the service with open mode.
* @param dataset String containig file name
* @param mode String containig opening mode
*
* @return Status code indicating success or failure.
*/
StatusCode connectDatabase(const std::string& dataset, int mode, RootDataConnection** con);
public:
/// Access default section (Tree) name
//const std::string& section() const { return m_section; }
/// ConversionSvc overload: initialize Db service
virtual StatusCode initialize();
/// ConversionSvc overload: Finalize Db service
virtual StatusCode finalize();
/// ConversionSvc overload: Create new Converter using factory
virtual IConverter* createConverter(long typ,
const CLID& wanted,
const ICnvFactory* fac);
/// ConversionSvc overload: Load the class (dictionary) for the converter
virtual void loadConverter(DataObject* pObj);
/** Connect the output file to the service with open mode.
* @param outputFile String containig output file
* @param openMode String containig opening mode of the output file
*
* @return Status code indicating success or failure.
*/
virtual StatusCode connectOutput(const std::string& outputFile,
const std::string& openMode);
/** Connect the output file to the service.
* @param outputFile String containig output file
*
* @return Status code indicating success or failure.
*/
virtual StatusCode connectOutput(const std::string& outputFile);
/** Commit pending output.
* @param outputFile String containig output file
* @param do_commit if true commit the output and flush
* eventually pending items to the database
* if false, discard pending buffers.
* Note: The possibility to commit or rollback
* depends on the database technology used!
*
* @return Status code indicating success or failure.
*/
virtual StatusCode commitOutput(const std::string& outputFile,
bool do_commit);
/** Disconnect from an existing data stream.
* @param dbName String containing name of the database
*
* @return Status code indicating success or failure.
*/
virtual StatusCode disconnect(const std::string& dbName);
/** IAddressCreator implementation: Address creation.
* Create an address using the link infotmation together with
* the triple (database name/container name/object name).
*
* @param refLink Reference to abstract link information
* @param dbName Database name
* @param containerName Object container name
* @param refpAddress Opaque address information to retrieve object
*
* @return StatusCode indicating SUCCESS or failure
*/
virtual StatusCode createAddress( long svc_type,
const CLID& clid,
const std::string* par,
const unsigned long* ip,
IOpaqueAddress*& refpAddress);
/** IAddressCreator implementation: Creates an address in string form to object form
* @param svc_type Technology identifier encapsulated
* in this address.
* @param clid Class identifier of the DataObject
* represented by the opaque address
* @param address Input address.
* @param refpAddress Output address in string form.
* @return Status code indicating success or failure.
*/
virtual StatusCode createAddress( long svc_type,
const CLID& clid,
const std::string& refAddress,
IOpaqueAddress*& refpAddress) {
return this->ConversionSvc::createAddress(svc_type,clid,refAddress,refpAddress);
}
/** Insert null marker for not existent transient object
*
* @param path [IN] Path to the (null-)object
*
* @return Status code indicating success or failure.
*/
virtual StatusCode createNullRep(const std::string& path);
/** Insert null marker for not existent transient object
*
* @param path [IN] Path to the (null-)object
*
* @return Status code indicating success or failure.
*/
virtual StatusCode createNullRef(const std::string& path);
/** Convert the transient object to the requested persistent representation.
*
* @param pObj [IN] Pointer to data object
* @param refpAddr [OUT] Location to store pointer to object address.
*
* @return Status code indicating success or failure.
*/
virtual StatusCode i__createRep(DataObject* pObj, IOpaqueAddress*& refpAddr);
/** Resolve the references of the converted object.
*
* @param pAddr [IN] Pointer to object address.
* @param pObj [IN] Pointer to data object
*
* @return Status code indicating success or failure.
*/
virtual StatusCode i__fillRepRefs(IOpaqueAddress* pAddr,DataObject* pObj);
/** Create transient object from persistent data
*
* @param pAddr [IN] Pointer to object address.
* @param refpObj [OUT] Location to pointer to store data object
*
* @return Status code indicating success or failure.
*/
virtual StatusCode i__createObj(IOpaqueAddress* pAddr, DataObject*& refpObj);
/** Resolve the references of the created transient object.
*
* @param pAddr [IN] Pointer to object address.
* @param pObj [IN] Pointer to data object
*
* @return Status code indicating success or failure.
*/
virtual StatusCode i__fillObjRefs(IOpaqueAddress* pAddr, DataObject* pObj);
};
}
#endif // GAUDIROOTCNV_GAUDIROOTCNVSVC_H
// $Id: RootConverter.h,v 1.5 2010-08-24 14:03:03 frankb Exp $
//====================================================================
// RootConverter class definition
//
// Author : M.Frank
//====================================================================
#ifndef GAUDIROOTCNV_ROOTCONVERTER_H
#define GAUDIROOTCNV_ROOTCONVERTER_H
// Framework include files
#include "GaudiKernel/Converter.h"
#include "RootCnv/RootCnvSvc.h"
/*
* Gaudi namespace declaration
*/
namespace Gaudi {
/** @class RootConverter RootConverter.h Root/RootConverter.h
*
* Description:
* Definition of the ROOT data converter.
* The generic data converter provides the infrastructure
* of all data converters. All actions are delegated to
* the corresponding conversion service.
*
* For a detailed description of the overridden function see the the
* base class.
*
* @author M.Frank
* @version 1.0
*/
class GAUDI_API RootConverter : public Converter {
protected:
/// Conversion service needed for proper operation to forward requests
RootCnvSvc* m_dbMgr;
public:
/** Initializing Constructor
* @param typ [IN] Concrete storage type of the converter
* @param clid [IN] Class identifier of the object
* @param svc [IN] Pointer to service locator object
*
* @return Reference to RootConverter object
*/
RootConverter(long typ, const CLID& clid, ISvcLocator* svc, RootCnvSvc* mgr)
: Converter(typ, clid, svc), m_dbMgr(mgr) {}
/// Standard Destructor
virtual ~RootConverter() {}
/// Retrieve the class type of the data store the converter uses.
virtual long repSvcType() const { return i_repSvcType(); }
/** Converter overrides: Create transient object from persistent data
*
* @param pAddr [IN] Pointer to object address.
* @param refpObj [OUT] Location to pointer to store data object
*
* @return Status code indicating success or failure.
*/
virtual StatusCode createObj(IOpaqueAddress* pAddr, DataObject*& refpObj)
{ return m_dbMgr->i__createObj(pAddr, refpObj); }
/** Resolve the references of the created transient object.
*
* @param pAddr [IN] Pointer to object address.
* @param pObj [IN] Pointer to data object
*
* @return Status code indicating success or failure.
*/
virtual StatusCode fillObjRefs(IOpaqueAddress* pAddr, DataObject* pObj)
{ return m_dbMgr->i__fillObjRefs(pAddr, pObj); }
/** Converter overrides: Convert the transient object to the
* requested representation.
*
* @param pObj [IN] Pointer to data object
* @param refpAddr [OUT] Location to store pointer to object address.
*
* @return Status code indicating success or failure.
*/
virtual StatusCode createRep(DataObject* pObj, IOpaqueAddress*& refpAddr)
{ return m_dbMgr->i__createRep(pObj, refpAddr); }
/** Resolve the references of the created transient object.
*
* @param pAddr [IN] Pointer to object address.
* @param pObj [IN] Pointer to data object
*
* @return Status code indicating success or failure.
*/
virtual StatusCode fillRepRefs(IOpaqueAddress* pAddr, DataObject* pObj)
{ return m_dbMgr->i__fillRepRefs(pAddr, pObj); }
};
}
#endif // GAUDIROOTCNV_ROOTCONVERTER_H
// $Id: RootDataConnection.h,v 1.9 2010-09-17 09:00:12 frankb Exp $
#ifndef GAUDIROOT_ROOTDATACONNECTION_H
#define GAUDIROOT_ROOTDATACONNECTION_H
// Framework include files
#include "GaudiKernel/ClassID.h"
#include "GaudiUtils/IIODataManager.h"
#include <string>
#include <vector>
#include <map>
#include <set>
#include "TFile.h"
#include "RootCnv/RootRefs.h"
// Forward declarations
class TTree;
class TClass;
class TBranch;
class TTreePerfStats;
class MsgStream;
class IRegistry;
class DataObject;
/*
* Gaudi namespace declaration
*/
namespace Gaudi {
/** @class RootConnectionSet RootDataConnection.h GaudiRootCnv/RootDataConnection.h
*
* Class describing the setup parameters of a ROOT data connection.
* The parameters are filled by the conversion service (using properties)
* and is then passed to all data connections served by this service.
*
* @author M.Frank
* @version 1.0
* @date 20/12/2009
*/
class GAUDI_API RootConnectionSetup {
public:
/// Type definition for string maps
typedef std::vector<std::string> StringVec;
protected:
/// Standard destructor
virtual ~RootConnectionSetup();
/// Object refrfence count
int refCount;
/// Reference to message service
MsgStream* m_msgSvc;
public:
/// Vector of strings with branches to be cached for input files
StringVec cacheBranches;
/// Vector of strings with branches to NOT be cached for input files
StringVec vetoBranches;
/// RootCnvSvc Property: Root data cache size
std::string loadSection;
/// RootCnvSvc Property: Root data cache size
int cacheSize;
/// RootCnvSvc Property: ROOT cache learn entries
int learnEntries;
/// RootCnvSvc Property: AutoFlush parameter for ROOT TTree (Number of events between auto flushes)
int autoFlush;
/// RootCnvSvc Property: Basket optimization parameter for ROOT TTree (total basket size)
int basketSize;
/// Standard constructor
RootConnectionSetup();
/// Increase reference count
void addRef();
/// Decrease reference count
void release();
/// Set message service reference
void setMessageSvc(MsgStream* m);
/// Retrieve message service
MsgStream& msgSvc() const { return *m_msgSvc; }
};
/** @class RootDataConnection RootDataConnection.h GaudiRootCnv/RootDataConnection.h
*
* Concrete implementation of the IDataConnection interface to access ROOT files.
*
* @author M.Frank
* @version 1.0
* @date 20/12/2009
*/
class GAUDI_API RootDataConnection : virtual public Gaudi::IDataConnection {
public:
/** @class ContainerSection RootDataConnection.h GaudiRootCnv/RootDataConnection.h
*
* Internal helper class, which described a TBranch section in a ROOT file.
* TBranch sections (ie. an intervall of events) are used to describe
* files using the ROOT fast merge mechanism.
*
* @author M.Frank
* @version 1.0
* @date 20/12/2009
*/
struct ContainerSection {
/// Default constructor
ContainerSection() : start(-1), length(0) {}
/// Initializing constructor
ContainerSection(int s, int l) : start(s), length(l) {}
/// Copy constructor
ContainerSection(const ContainerSection& s) : start(s.start), length(s.length) {}
/// Assignment operator to copy objects
ContainerSection& operator=(const ContainerSection& s) { start=s.start;length=s.length; return *this;}
/// The start entry of the section
int start;
/// The length of the section
int length;
};
/// Type definition for string maps
typedef std::vector<std::string> StringVec;
/// Type definition for the parameter map
typedef std::vector<std::pair<std::string,std::string> > ParamMap;
/// Definition of tree sections
typedef std::map<std::string,TTree*> Sections;
/// Definition of container sections to handle merged files
typedef std::vector<ContainerSection> ContainerSections;
/// Definition of database section to handle merged files
typedef std::map<std::string,ContainerSections> MergeSections;
/// Link sections definition
typedef std::vector<RootRef> LinkSections;
/// Client set
typedef std::set<const IInterface*> Clients;
/// Allow access to printer service
MsgStream& msgSvc() const { return m_setup->msgSvc(); }
protected:
/// Reference to the setup structure
RootConnectionSetup* m_setup;
/// I/O read statistics from TTree
TTreePerfStats* m_statistics;
/// Reference to ROOT file
TFile* m_file;
/// Pointer to the reference tree
TTree *m_refs;
/// Tree sections in TFile
Sections m_sections;
/// Map containing external database file names (fids)
StringVec m_dbs;
/// Map containing external container names
StringVec m_conts;
/// Map containing internal links names
StringVec m_links;
/// Map containing merge FIDs
StringVec m_mergeFIDs;
/// Parameter map for file parameters
ParamMap m_params;
/// Database section map for merged files
MergeSections m_mergeSects;
/// Database link sections
LinkSections m_linkSects;
/// Client list
Clients m_clients;
/// Buffer for empty string reference
std::string m_empty;
/// Empty string reference
const std::string& empty() const;
/// Internal helper to save/update reference tables
StatusCode saveRefs();
public:
/** @class Tool RootDataConnection.h src/RootDataConnection.h
*
* Helper class to facilitate an abstraction layer for reading
* POOL style files with this package.
* YES: This class obsoletes POOL.
*
* @author M.Frank
* @version 1.0
*/
class Tool {
protected:
typedef RootDataConnection::StringVec StringVec;
typedef RootDataConnection::ParamMap ParamMap;
typedef RootDataConnection::Sections Sections;
typedef RootDataConnection::MergeSections MergeSections;
typedef RootDataConnection::LinkSections LinkSections;
typedef RootDataConnection::ContainerSection ContainerSection;
typedef RootDataConnection::ContainerSections ContainerSections;
/// Pointer to containing data connection object
RootDataConnection* c;
public:
TTree* refs() const { return c->m_refs; }
StringVec& dbs() const { return c->m_dbs; }