Gaudi Framework, version v23r0

Home   Generated: Mon Jan 30 2012
Classes | Public Types | Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Friends

Gaudi::RootDataConnection Class Reference

Concrete implementation of the IDataConnection interface to access ROOT files. More...

#include <GaudiRootCnv/RootDataConnection.h>

Inheritance diagram for Gaudi::RootDataConnection:
Inheritance graph
[legend]
Collaboration diagram for Gaudi::RootDataConnection:
Collaboration graph
[legend]

List of all members.

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::stringStringVec
 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< RootRefLinkSections
 Link sections definition.
typedef std::set< const
IInterface * > 
Clients
 Client set.

Public Member Functions

MsgStreammsgSvc () const
 Allow access to printer service.
ToolmakeTool ()
 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?
Tooltool () const
 Access tool.
const MergeSectionsmergeSections () const
 Access merged data section inventory.
const StringVecmergeFIDs () 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 &section)
 Enable TTreePerStats.
void saveStatistics (const std::string &statisticsFile)
 Save TTree access statistics if required.
int loadObj (const std::string &section, const std::string &cnt, unsigned long entry, DataObject *&pObj)
 Load object.
int loadRefs (const std::string &section, const std::string &cnt, unsigned long entry, RootObjectRefs &refs)
 Load references object.
std::pair< int, unsigned long > 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.
std::pair< int, unsigned long > 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.
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 &sect, bool create=false)
 Access TTree section from section name. The section is created if required.
TBranch * getBranch (const std::string &section, const std::string &branch_name)
 Access data branch by name: Get existing branch in read only mode.
TBranch * 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.
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::stringgetDb (int which) const
 Access database/file name from saved index.
const std::stringgetCont (int which) const
 Access container name from saved index.
const std::stringgetLink (int which) const
 Access link name from saved index.

Public Attributes

class
Gaudi::RootDataConnection::Tool * 
m_tool

Protected Member Functions

const std::stringempty () const
 Empty string reference.
StatusCode saveRefs ()
 Internal helper to save/update reference tables.

Protected Attributes

RootConnectionSetupm_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

Detailed Description

Concrete implementation of the IDataConnection interface to access ROOT files.

Author:
M.Frank
Version:
1.0
Date:
20/12/2009

Definition at line 89 of file RootDataConnection.h.


Member Typedef Documentation

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.


Constructor & Destructor Documentation

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.

                                          {
  m_setup->release();
  releasePtr(m_tool);
}

Member Function Documentation

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]

Empty string reference.

Definition at line 412 of file RootDataConnection.cpp.

                                     { 
  return s_empty;
}
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]

Access container name from saved index.

Definition at line 310 of file RootDataConnection.h.

      { return (which>=0)&&(size_t(which)<m_conts.size()) ? *(m_conts.begin()+which) : empty();    }
CSTR RootDataConnection::getDb ( int  which ) const

Access database/file name from saved index.

Definition at line 403 of file RootDataConnection.cpp.

                                              {
  if ( (which>=0) && (size_t(which)<m_dbs.size()) )  {
    if ( *(m_dbs.begin()+which) == s_local ) return m_fid;
    return *(m_dbs.begin()+which);
  }
  return s_empty;
}
const std::string& Gaudi::RootDataConnection::getLink ( int  which ) const [inline]

Access link name from saved index.

Definition at line 314 of file RootDataConnection.h.

      { return (which>=0)&&(size_t(which)<m_links.size()) ? *(m_links.begin()+which) : empty();    }
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.

{  return m_file != 0 && m_file->IsWritable(); }
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.

                                                                      {
  Clients::const_iterator i=m_clients.find(client);
  return i != m_clients.end();
}
int Gaudi::RootDataConnection::makeLink ( const std::string p )

Convert path string to path index.

void RootDataConnection::makeRef ( IRegistry pA,
RootRef ref 
)

Create reference object from registry entry.

Definition at line 529 of file RootDataConnection.cpp.

                                                            {
  IOpaqueAddress* pA = pR->address();
  makeRef(pR->name(),pA->clID(),pA->svcType(),pA->par()[0],pA->par()[1],-1,ref);
}
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.

                                                       {
  releasePtr(m_tool);
  if ( !m_refs ) m_refs = (TTree*)m_file->Get("Refs");
  if ( m_refs )
    m_tool = new RootTool(this);
#ifdef __POOL_COMPATIBILITY
  else if ( m_file->Get("##Links") != 0 )
    m_tool = new PoolTool(this);
#endif
  return m_tool;
}
const StringVec& Gaudi::RootDataConnection::mergeFIDs (  ) const [inline]

Access merged FIDs.

Definition at line 245 of file RootDataConnection.h.

{  return m_mergeFIDs;                         }
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 )

Remove client from this data source.

Definition at line 136 of file RootDataConnection.cpp.

                                                                {
  Clients::iterator i=m_clients.find(client);
  if ( i != m_clients.end() ) m_clients.erase(i);
  return m_clients.size();
}
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]

Access tool.

Definition at line 241 of file RootDataConnection.h.

{  return m_tool;                              }
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; }

Friends And Related Function Documentation

friend class Tool [friend]

Definition at line 222 of file RootDataConnection.h.


Member Data Documentation

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

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Mon Jan 30 2012 13:53:31 for Gaudi Framework, version v23r0 by Doxygen version 1.7.2 written by Dimitri van Heesch, © 1997-2004