Gaudi Framework, version v23r0 |
Home | Generated: Mon Jan 30 2012 |
Concrete implementation of the IDataConnection interface to access ROOT files. More...
#include <GaudiRootCnv/RootDataConnection.h>
Classes | |
class | ContainerSection |
Internal helper class, which described a TBranch section in a ROOT file. More... | |
class | Tool |
Helper class to facilitate an abstraction layer for reading POOL style files with this package. More... | |
Public Types | |
typedef std::vector< std::string > | StringVec |
Type definition for string maps. | |
typedef std::vector< std::pair < std::string, std::string > > | ParamMap |
Type definition for the parameter map. | |
typedef std::map< std::string, TTree * > | Sections |
Definition of tree sections. | |
typedef std::vector < ContainerSection > | ContainerSections |
Definition of container sections to handle merged files. | |
typedef std::map< std::string, ContainerSections > | MergeSections |
Definition of database section to handle merged files. | |
typedef std::vector< RootRef > | LinkSections |
Link sections definition. | |
typedef std::set< const IInterface * > | Clients |
Client set. | |
Public Member Functions | |
MsgStream & | msgSvc () const |
Allow access to printer service. | |
Tool * | makeTool () |
Create file access tool to encapsulate POOL compatibiliy. | |
RootDataConnection (const IInterface *own, const std::string &nam, RootConnectionSetup *setup) | |
Standard constructor. | |
virtual | ~RootDataConnection () |
Standard destructor. | |
TFile * | file () const |
Direct access to TFile structure. | |
virtual bool | isConnected () const |
Check if connected to data source. | |
bool | isWritable () const |
Is the file writable? | |
Tool * | tool () const |
Access tool. | |
const MergeSections & | mergeSections () const |
Access merged data section inventory. | |
const StringVec & | mergeFIDs () const |
Access merged FIDs. | |
void | addClient (const IInterface *client) |
Add new client to this data source. | |
size_t | removeClient (const IInterface *client) |
Remove client from this data source. | |
bool | lookupClient (const IInterface *client) const |
Lookup client for this data source. | |
std::pair< const RootRef *, const ContainerSection * > | getMergeSection (const std::string &container, int entry) const |
Access link section for single container and entry. | |
void | enableStatistics (const std::string §ion) |
Enable TTreePerStats. | |
void | saveStatistics (const std::string &statisticsFile) |
Save TTree access statistics if required. | |
int | loadObj (const std::string §ion, const std::string &cnt, unsigned long entry, DataObject *&pObj) |
Load object. | |
int | loadRefs (const std::string §ion, const std::string &cnt, unsigned long entry, RootObjectRefs &refs) |
Load references object. | |
std::pair< int, unsigned long > | saveObj (const std::string §ion, const std::string &cnt, TClass *cl, DataObject *pObj, bool fill_missing=false) |
Save object of a given class to section and container. | |
std::pair< int, unsigned long > | save (const std::string §ion, const std::string &cnt, TClass *cl, void *pObj, bool fill_missing=false) |
Save object of a given class to section and container. | |
virtual StatusCode | connectRead () |
Open data stream in read mode. | |
virtual StatusCode | connectWrite (IoType typ) |
Open data stream in write mode. | |
virtual StatusCode | disconnect () |
Release data stream and release implementation dependent resources. | |
virtual StatusCode | read (void *const, size_t) |
Read root byte buffer from input stream. | |
virtual StatusCode | write (const void *, int) |
Write root byte buffer to output stream. | |
virtual long long int | seek (long long int, int) |
Seek on the file described by ioDesc. Arguments as in seek() | |
TTree * | getSection (const std::string §, bool create=false) |
Access TTree section from section name. The section is created if required. | |
TBranch * | getBranch (const std::string §ion, const std::string &branch_name) |
Access data branch by name: Get existing branch in read only mode. | |
TBranch * | getBranch (const std::string §ion, const std::string &branch_name, TClass *cl, void *ptr) |
Access data branch by name: Get existing branch in write mode. | |
void | makeRef (IRegistry *pA, RootRef &ref) |
Create reference object from registry entry. | |
void | makeRef (const std::string &name, long clid, int tech, const std::string &db, const std::string &cnt, int entry, RootRef &ref) |
Create reference object from values. | |
int | makeLink (const std::string &p) |
Convert path string to path index. | |
const std::string & | getDb (int which) const |
Access database/file name from saved index. | |
const std::string & | getCont (int which) const |
Access container name from saved index. | |
const std::string & | getLink (int which) const |
Access link name from saved index. | |
Public Attributes | |
class Gaudi::RootDataConnection::Tool * | m_tool |
Protected Member Functions | |
const std::string & | empty () const |
Empty string reference. | |
StatusCode | saveRefs () |
Internal helper to save/update reference tables. | |
Protected Attributes | |
RootConnectionSetup * | m_setup |
Reference to the setup structure. | |
TTreePerfStats * | m_statistics |
I/O read statistics from TTree. | |
TFile * | m_file |
Reference to ROOT file. | |
TTree * | m_refs |
Pointer to the reference tree. | |
Sections | m_sections |
Tree sections in TFile. | |
StringVec | m_dbs |
Map containing external database file names (fids) | |
StringVec | m_conts |
Map containing external container names. | |
StringVec | m_links |
Map containing internal links names. | |
StringVec | m_mergeFIDs |
Map containing merge FIDs. | |
ParamMap | m_params |
Parameter map for file parameters. | |
MergeSections | m_mergeSects |
Database section map for merged files. | |
LinkSections | m_linkSects |
Database link sections. | |
Clients | m_clients |
Client list. | |
std::string | m_empty |
Buffer for empty string reference. | |
Friends | |
class | Tool |
Concrete implementation of the IDataConnection interface to access ROOT files.
Definition at line 89 of file RootDataConnection.h.
typedef std::set<const IInterface*> Gaudi::RootDataConnection::Clients |
Client set.
Definition at line 130 of file RootDataConnection.h.
typedef std::vector<ContainerSection> Gaudi::RootDataConnection::ContainerSections |
Definition of container sections to handle merged files.
Definition at line 124 of file RootDataConnection.h.
typedef std::vector<RootRef> Gaudi::RootDataConnection::LinkSections |
Link sections definition.
Definition at line 128 of file RootDataConnection.h.
typedef std::map<std::string,ContainerSections> Gaudi::RootDataConnection::MergeSections |
Definition of database section to handle merged files.
Definition at line 126 of file RootDataConnection.h.
typedef std::vector<std::pair<std::string,std::string> > Gaudi::RootDataConnection::ParamMap |
Type definition for the parameter map.
Definition at line 120 of file RootDataConnection.h.
typedef std::map<std::string,TTree*> Gaudi::RootDataConnection::Sections |
Definition of tree sections.
Definition at line 122 of file RootDataConnection.h.
typedef std::vector<std::string> Gaudi::RootDataConnection::StringVec |
Type definition for string maps.
Definition at line 118 of file RootDataConnection.h.
Gaudi::RootDataConnection::RootDataConnection | ( | const IInterface * | own, |
const std::string & | nam, | ||
RootConnectionSetup * | setup | ||
) |
Standard constructor.
RootDataConnection::~RootDataConnection | ( | ) | [virtual] |
Standard destructor.
Definition at line 125 of file RootDataConnection.cpp.
void RootDataConnection::addClient | ( | const IInterface * | client ) |
Add new client to this data source.
Definition at line 131 of file RootDataConnection.cpp.
{ m_clients.insert(client); }
StatusCode RootDataConnection::connectRead | ( | ) | [virtual] |
Open data stream in read mode.
Implements Gaudi::IDataConnection.
Definition at line 186 of file RootDataConnection.cpp.
{ m_file = TFile::Open(m_pfn.c_str()); if ( m_file && !m_file->IsZombie() ) { StatusCode sc = StatusCode::FAILURE; msgSvc() << MSG::DEBUG << "Opened file " << m_pfn << " in mode READ. [" << m_fid << "]" << endmsg << MSG::DEBUG; if ( msgSvc().isActive() ) m_file->ls(); msgSvc() << MSG::VERBOSE; if ( msgSvc().isActive() ) m_file->Print(); if ( makeTool() ) sc = m_tool->readRefs(); if ( sc.isSuccess() ) { bool need_fid = m_fid == m_pfn; string fid = m_fid; m_mergeFIDs.clear(); for(size_t i=0, n=m_params.size(); i<n; ++i) { if ( m_params[i].first == "FID" ) { m_mergeFIDs.push_back(m_params[i].second); if ( m_params[i].second != m_fid ) { msgSvc() << MSG::DEBUG << "Check FID param:" << m_params[i].second << endmsg; //if ( m_fid == m_pfn ) { m_fid = m_params[i].second; //} } } } if ( !need_fid && fid != m_fid ) { msgSvc() << MSG::ERROR << "FID mismatch:" << fid << "(Catalog) != " << m_fid << "(file)" << endmsg << "for PFN:" << m_pfn << endmsg; return StatusCode::FAILURE; } msgSvc() << MSG::DEBUG << "Using FID " << m_fid << " from params table...." << endmsg << "for PFN:" << m_pfn << endmsg; return sc; } } else if ( m_file ) { deletePtr(m_file); } return StatusCode::FAILURE; }
StatusCode RootDataConnection::connectWrite | ( | IoType | typ ) | [virtual] |
Open data stream in write mode.
Implements Gaudi::IDataConnection.
Definition at line 227 of file RootDataConnection.cpp.
{ msgSvc() << MSG::DEBUG; switch(typ) { case CREATE: resetAge(); m_file = TFile::Open(m_pfn.c_str(),"CREATE","Root event data"); m_refs = new TTree("Refs","Root reference data"); msgSvc() << "Opened file " << m_pfn << " in mode CREATE. [" << m_fid << "]" << endmsg; m_params.push_back(make_pair("PFN",m_pfn)); if ( m_fid != m_pfn ) { m_params.push_back(make_pair("FID",m_fid)); } makeTool(); break; case RECREATE: resetAge(); m_file = TFile::Open(m_pfn.c_str(),"RECREATE","Root event data"); msgSvc() << "Opened file " << m_pfn << " in mode RECREATE. [" << m_fid << "]" << endmsg; m_refs = new TTree("Refs","Root reference data"); m_params.push_back(make_pair("PFN",m_pfn)); if ( m_fid != m_pfn ) { m_params.push_back(make_pair("FID",m_fid)); } makeTool(); break; case UPDATE: resetAge(); m_file = TFile::Open(m_pfn.c_str(),"UPDATE","Root event data"); msgSvc() << "Opened file " << m_pfn << " in mode UPDATE. [" << m_fid << "]" << endmsg; if ( m_file && !m_file->IsZombie() ) { if ( makeTool() ) return m_tool->readRefs(); TDirectory::TContext ctxt(m_file); m_refs = new TTree("Refs","Root reference data"); makeTool(); return StatusCode::SUCCESS; } break; default: m_refs = 0; m_file = 0; return StatusCode::FAILURE; } return 0==m_file ? StatusCode::FAILURE : StatusCode::SUCCESS; }
StatusCode RootDataConnection::disconnect | ( | ) | [virtual] |
Release data stream and release implementation dependent resources.
Implements Gaudi::IDataConnection.
Definition at line 273 of file RootDataConnection.cpp.
{ if ( m_file ) { if ( !m_file->IsZombie() ) { if ( m_file->IsWritable() ) { msgSvc() << MSG::DEBUG; TDirectory::TContext ctxt(m_file); if ( m_refs ) { m_tool->saveRefs().ignore(); m_refs->Write(); } for(Sections::iterator i=m_sections.begin(); i!= m_sections.end();++i) { if ( (*i).second ) { (*i).second->Write(); msgSvc() << "Disconnect section " << (*i).first << " " << (*i).second->GetName() << endmsg; } } m_sections.clear(); } msgSvc() << MSG::DEBUG; if ( msgSvc().isActive() ) m_file->ls(); msgSvc() << MSG::VERBOSE; if ( msgSvc().isActive() ) m_file->Print(); m_file->Close(); } msgSvc() << MSG::DEBUG << "Disconnected file " << m_pfn << " " << m_file->GetName() << endmsg; deletePtr(m_file); releasePtr(m_tool); } return StatusCode::SUCCESS; }
CSTR RootDataConnection::empty | ( | void | ) | const [protected] |
void Gaudi::RootDataConnection::enableStatistics | ( | const std::string & | section ) |
Enable TTreePerStats.
TFile* Gaudi::RootDataConnection::file | ( | ) | const [inline] |
Direct access to TFile structure.
Definition at line 235 of file RootDataConnection.h.
{ return m_file; }
TBranch* Gaudi::RootDataConnection::getBranch | ( | const std::string & | section, |
const std::string & | branch_name | ||
) | [inline] |
Access data branch by name: Get existing branch in read only mode.
Definition at line 293 of file RootDataConnection.h.
{ return m_tool->getBranch(section,branch_name); }
TBranch* Gaudi::RootDataConnection::getBranch | ( | const std::string & | section, |
const std::string & | branch_name, | ||
TClass * | cl, | ||
void * | ptr | ||
) |
Access data branch by name: Get existing branch in write mode.
const std::string& Gaudi::RootDataConnection::getCont | ( | int | which ) | const [inline] |
CSTR RootDataConnection::getDb | ( | int | which ) | const |
const std::string& Gaudi::RootDataConnection::getLink | ( | int | which ) | const [inline] |
pair< const RootRef *, const RootDataConnection::ContainerSection * > RootDataConnection::getMergeSection | ( | const std::string & | container, |
int | entry | ||
) | const |
Access link section for single container and entry.
Definition at line 501 of file RootDataConnection.cpp.
{ //size_t idx = cont.find('/',1); //string container = cont[0]=='/' ? cont.substr(1,idx==string::npos?idx:idx-1) : cont; MergeSections::const_iterator i=m_mergeSects.find(container); if ( i != m_mergeSects.end() ) { size_t cnt = 0; const ContainerSections& s = (*i).second; for(ContainerSections::const_iterator j=s.begin(); j != s.end(); ++j,++cnt) { const ContainerSection& c = *j; if ( entry >= c.start && entry < (c.start+c.length) ) { if ( m_linkSects.size() > cnt ) { if ( msgSvc().isActive() ) { msgSvc() << MSG::VERBOSE << "MergeSection for:" << container << " [" << entry << "]" << endmsg << "FID:" << m_fid << " -> PFN:" << m_pfn << endmsg; } return make_pair(&(m_linkSects[cnt]), &c); } } } } msgSvc() << MSG::DEBUG << "Return INVALID MergeSection for:" << container << " [" << entry << "]" << endmsg << "FID:" << m_fid << " -> PFN:" << m_pfn << endmsg; return make_pair((const RootRef*)0,(const ContainerSection*)0); }
TTree* Gaudi::RootDataConnection::getSection | ( | const std::string & | sect, |
bool | create = false |
||
) |
Access TTree section from section name. The section is created if required.
virtual bool Gaudi::RootDataConnection::isConnected | ( | ) | const [inline, virtual] |
Check if connected to data source.
Implements Gaudi::IDataConnection.
Definition at line 237 of file RootDataConnection.h.
{ return m_file != 0; }
bool Gaudi::RootDataConnection::isWritable | ( | ) | const [inline] |
Is the file writable?
Definition at line 239 of file RootDataConnection.h.
int Gaudi::RootDataConnection::loadObj | ( | const std::string & | section, |
const std::string & | cnt, | ||
unsigned long | entry, | ||
DataObject *& | pObj | ||
) |
Load object.
int Gaudi::RootDataConnection::loadRefs | ( | const std::string & | section, |
const std::string & | cnt, | ||
unsigned long | entry, | ||
RootObjectRefs & | refs | ||
) | [inline] |
Load references object.
Definition at line 267 of file RootDataConnection.h.
{ return m_tool->loadRefs(section,cnt,entry,refs); }
bool RootDataConnection::lookupClient | ( | const IInterface * | client ) | const |
Lookup client for this data source.
Definition at line 143 of file RootDataConnection.cpp.
int Gaudi::RootDataConnection::makeLink | ( | const std::string & | p ) |
Convert path string to path index.
Create reference object from registry entry.
Definition at line 529 of file RootDataConnection.cpp.
void Gaudi::RootDataConnection::makeRef | ( | const std::string & | name, |
long | clid, | ||
int | tech, | ||
const std::string & | db, | ||
const std::string & | cnt, | ||
int | entry, | ||
RootRef & | ref | ||
) |
Create reference object from values.
RootDataConnection::Tool * RootDataConnection::makeTool | ( | ) |
Create file access tool to encapsulate POOL compatibiliy.
Definition at line 173 of file RootDataConnection.cpp.
const StringVec& Gaudi::RootDataConnection::mergeFIDs | ( | ) | const [inline] |
const MergeSections& Gaudi::RootDataConnection::mergeSections | ( | ) | const [inline] |
Access merged data section inventory.
Definition at line 243 of file RootDataConnection.h.
{ return m_mergeSects; }
MsgStream& Gaudi::RootDataConnection::msgSvc | ( | ) | const [inline] |
Allow access to printer service.
Definition at line 133 of file RootDataConnection.h.
{ return m_setup->msgSvc(); }
virtual StatusCode Gaudi::RootDataConnection::read | ( | void * | const, |
size_t | |||
) | [inline, virtual] |
Read root byte buffer from input stream.
Implements Gaudi::IDataConnection.
Definition at line 283 of file RootDataConnection.h.
{ return StatusCode::FAILURE; }
size_t RootDataConnection::removeClient | ( | const IInterface * | client ) |
std::pair<int,unsigned long> Gaudi::RootDataConnection::save | ( | const std::string & | section, |
const std::string & | cnt, | ||
TClass * | cl, | ||
void * | pObj, | ||
bool | fill_missing = false |
||
) |
Save object of a given class to section and container.
std::pair<int,unsigned long> Gaudi::RootDataConnection::saveObj | ( | const std::string & | section, |
const std::string & | cnt, | ||
TClass * | cl, | ||
DataObject * | pObj, | ||
bool | fill_missing = false |
||
) |
Save object of a given class to section and container.
StatusCode Gaudi::RootDataConnection::saveRefs | ( | ) | [protected] |
Internal helper to save/update reference tables.
void Gaudi::RootDataConnection::saveStatistics | ( | const std::string & | statisticsFile ) |
Save TTree access statistics if required.
virtual long long int Gaudi::RootDataConnection::seek | ( | long long int | , |
int | |||
) | [inline, virtual] |
Seek on the file described by ioDesc. Arguments as in seek()
Implements Gaudi::IDataConnection.
Definition at line 287 of file RootDataConnection.h.
{ return -1; }
Tool* Gaudi::RootDataConnection::tool | ( | ) | const [inline] |
virtual StatusCode Gaudi::RootDataConnection::write | ( | const void * | , |
int | |||
) | [inline, virtual] |
Write root byte buffer to output stream.
Implements Gaudi::IDataConnection.
Definition at line 285 of file RootDataConnection.h.
{ return StatusCode::FAILURE; }
friend class Tool [friend] |
Definition at line 222 of file RootDataConnection.h.
Clients Gaudi::RootDataConnection::m_clients [protected] |
Client list.
Definition at line 162 of file RootDataConnection.h.
StringVec Gaudi::RootDataConnection::m_conts [protected] |
Map containing external container names.
Definition at line 150 of file RootDataConnection.h.
StringVec Gaudi::RootDataConnection::m_dbs [protected] |
Map containing external database file names (fids)
Definition at line 148 of file RootDataConnection.h.
std::string Gaudi::RootDataConnection::m_empty [protected] |
Buffer for empty string reference.
Definition at line 164 of file RootDataConnection.h.
TFile* Gaudi::RootDataConnection::m_file [protected] |
Reference to ROOT file.
Definition at line 142 of file RootDataConnection.h.
StringVec Gaudi::RootDataConnection::m_links [protected] |
Map containing internal links names.
Definition at line 152 of file RootDataConnection.h.
LinkSections Gaudi::RootDataConnection::m_linkSects [protected] |
Database link sections.
Definition at line 160 of file RootDataConnection.h.
StringVec Gaudi::RootDataConnection::m_mergeFIDs [protected] |
Map containing merge FIDs.
Definition at line 154 of file RootDataConnection.h.
MergeSections Gaudi::RootDataConnection::m_mergeSects [protected] |
Database section map for merged files.
Definition at line 158 of file RootDataConnection.h.
ParamMap Gaudi::RootDataConnection::m_params [protected] |
Parameter map for file parameters.
Definition at line 156 of file RootDataConnection.h.
TTree* Gaudi::RootDataConnection::m_refs [protected] |
Pointer to the reference tree.
Definition at line 144 of file RootDataConnection.h.
Sections Gaudi::RootDataConnection::m_sections [protected] |
Tree sections in TFile.
Definition at line 146 of file RootDataConnection.h.
RootConnectionSetup* Gaudi::RootDataConnection::m_setup [protected] |
Reference to the setup structure.
Definition at line 138 of file RootDataConnection.h.
TTreePerfStats* Gaudi::RootDataConnection::m_statistics [protected] |
I/O read statistics from TTree.
Definition at line 140 of file RootDataConnection.h.
class Gaudi::RootDataConnection::Tool * Gaudi::RootDataConnection::m_tool |