All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Gaudi::RootDataConnection Class Reference

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

#include <GaudiRootCnv/RootDataConnection.h>

Inheritance diagram for Gaudi::RootDataConnection:
Collaboration diagram for Gaudi::RootDataConnection:

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

enum  { ROOT_READ_ERROR = 0x2, ROOT_OPEN_ERROR = 0x4 }
 
typedef std::vector< std::string > StringVec
 Type definition for string maps. More...
 
typedef std::vector< std::pair
< std::string, std::string > > 
ParamMap
 Type definition for the parameter map. More...
 
typedef std::map< std::string,
TTree * > 
Sections
 Definition of tree sections. More...
 
typedef std::vector
< ContainerSection
ContainerSections
 Definition of container sections to handle merged files. More...
 
typedef std::map< std::string,
ContainerSections
MergeSections
 Definition of database section to handle merged files. More...
 
typedef std::vector< RootRefLinkSections
 Link sections definition. More...
 
typedef std::set< const
IInterface * > 
Clients
 Client set. More...
 
- Public Types inherited from Gaudi::IDataConnection
enum  IoType { READ =1<<1, UPDATE =1<<2, CREATE =1<<3, RECREATE =(1<<4)+(1<<3) }
 I/O Connection types. More...
 
enum  IoStatus { BAD_DATA_CONNECTION =4 }
 Status Code on bad file connection. More...
 

Public Member Functions

MsgStreammsgSvc () const
 Allow access to printer service. More...
 
ToolmakeTool ()
 Create file access tool to encapsulate POOL compatibiliy. More...
 
 RootDataConnection (const IInterface *own, const std::string &nam, RootConnectionSetup *setup)
 Standard constructor. More...
 
virtual ~RootDataConnection ()
 Standard destructor. More...
 
TFile * file () const
 Direct access to TFile structure. More...
 
virtual bool isConnected () const
 Check if connected to data source. More...
 
bool isWritable () const
 Is the file writable? More...
 
Tooltool () const
 Access tool. More...
 
const MergeSectionsmergeSections () const
 Access merged data section inventory. More...
 
const StringVecmergeFIDs () const
 Access merged FIDs. More...
 
void addClient (const IInterface *client)
 Add new client to this data source. More...
 
size_t removeClient (const IInterface *client)
 Remove client from this data source. More...
 
bool lookupClient (const IInterface *client) const
 Lookup client for this data source. More...
 
void badWriteError (const std::string &msg) const
 Error handler when bad write statements occur. More...
 
std::pair< const RootRef
*, const ContainerSection * > 
getMergeSection (const std::string &container, int entry) const
 Access link section for single container and entry. More...
 
void enableStatistics (const std::string &section)
 Enable TTreePerStats. More...
 
void saveStatistics (const std::string &statisticsFile)
 Save TTree access statistics if required. More...
 
int loadObj (const std::string &section, const std::string &cnt, unsigned long entry, DataObject *&pObj)
 Load object. More...
 
int loadRefs (const std::string &section, const std::string &cnt, unsigned long entry, RootObjectRefs &refs)
 Load references object. More...
 
std::pair< int, unsigned long > saveObj (const std::string &section, const std::string &cnt, TClass *cl, DataObject *pObj, int buff_siz, int split_lvl, bool fill_missing=false)
 Save object of a given class to section and container. More...
 
std::pair< int, unsigned long > save (const std::string &section, const std::string &cnt, TClass *cl, void *pObj, int buff_siz, int split_lvl, bool fill_missing=false)
 Save object of a given class to section and container. More...
 
virtual StatusCode connectRead ()
 Open data stream in read mode. More...
 
virtual StatusCode connectWrite (IoType typ)
 Open data stream in write mode. More...
 
virtual StatusCode disconnect ()
 Release data stream and release implementation dependent resources. More...
 
virtual StatusCode read (void *const, size_t)
 Read root byte buffer from input stream. More...
 
virtual StatusCode write (const void *, int)
 Write root byte buffer to output stream. More...
 
virtual long long int seek (long long int, int)
 Seek on the file described by ioDesc. Arguments as in ::seek() More...
 
TTree * getSection (const std::string &sect, bool create=false)
 Access TTree section from section name. The section is created if required. More...
 
TBranch * getBranch (const std::string &section, const std::string &branch_name)
 Access data branch by name: Get existing branch in read only mode. More...
 
TBranch * getBranch (const std::string &section, const std::string &branch_name, TClass *cl, void *ptr, int buff_siz, int split_lvl)
 Access data branch by name: Get existing branch in write mode. More...
 
void makeRef (IRegistry *pA, RootRef &ref)
 Create reference object from registry entry. More...
 
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. More...
 
int makeLink (const std::string &p)
 Convert path string to path index. More...
 
const std::string & getDb (int which) const
 Access database/file name from saved index. More...
 
const std::string & getCont (int which) const
 Access container name from saved index. More...
 
const std::string & getLink (int which) const
 Access link name from saved index. More...
 
- Public Member Functions inherited from Gaudi::IDataConnection
 IDataConnection (const IInterface *own, const std::string &nam)
 Standard constructor. More...
 
virtual ~IDataConnection ()
 Standard destructor. More...
 
const std::string & name () const
 Connection name. More...
 
void setFID (const std::string &fid)
 Set file ID. More...
 
const std::string & fid () const
 Access file id. More...
 
const std::string & pfn () const
 Access physical file name. More...
 
void setPFN (const std::string &fn)
 Set physical file name. More...
 
void ageFile ()
 Increase age of I/O source. More...
 
void resetAge ()
 Reset age. More...
 
int age () const
 Access age counter. More...
 
const IInterfaceowner () const
 Owner instance. More...
 

Public Attributes

class
Gaudi::RootDataConnection::Tool
m_tool
 

Protected Member Functions

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

Protected Attributes

RootConnectionSetupm_setup
 Reference to the setup structure. More...
 
TTreePerfStats * m_statistics
 I/O read statistics from TTree. More...
 
TFile * m_file
 Reference to ROOT file. More...
 
TTree * m_refs
 Pointer to the reference tree. More...
 
Sections m_sections
 Tree sections in TFile. More...
 
StringVec m_dbs
 Map containing external database file names (fids) More...
 
StringVec m_conts
 Map containing external container names. More...
 
StringVec m_links
 Map containing internal links names. More...
 
StringVec m_mergeFIDs
 Map containing merge FIDs. More...
 
ParamMap m_params
 Parameter map for file parameters. More...
 
MergeSections m_mergeSects
 Database section map for merged files. More...
 
LinkSections m_linkSects
 Database link sections. More...
 
Clients m_clients
 Client list. More...
 
std::string m_empty
 Buffer for empty string reference. More...
 
- Protected Attributes inherited from Gaudi::IDataConnection
std::string m_name
 Connection name/identifier. More...
 
std::string m_fid
 File ID of the connection. More...
 
std::string m_pfn
 Physical file name of the connection. More...
 
int m_age
 Age counter. More...
 
const IInterfacem_owner
 Owner pointer. More...
 

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 99 of file RootDataConnection.h.

Member Typedef Documentation

typedef std::set<const IInterface*> Gaudi::RootDataConnection::Clients

Client set.

Definition at line 150 of file RootDataConnection.h.

typedef std::vector<ContainerSection> Gaudi::RootDataConnection::ContainerSections

Definition of container sections to handle merged files.

Definition at line 144 of file RootDataConnection.h.

typedef std::vector<RootRef> Gaudi::RootDataConnection::LinkSections

Link sections definition.

Definition at line 148 of file RootDataConnection.h.

typedef std::map<std::string,ContainerSections> Gaudi::RootDataConnection::MergeSections

Definition of database section to handle merged files.

Definition at line 146 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 140 of file RootDataConnection.h.

typedef std::map<std::string,TTree*> Gaudi::RootDataConnection::Sections

Definition of tree sections.

Definition at line 142 of file RootDataConnection.h.

typedef std::vector<std::string> Gaudi::RootDataConnection::StringVec

Type definition for string maps.

Definition at line 138 of file RootDataConnection.h.

Member Enumeration Documentation

anonymous enum
Enumerator
ROOT_READ_ERROR 
ROOT_OPEN_ERROR 

Definition at line 102 of file RootDataConnection.h.

Constructor & Destructor Documentation

RootDataConnection::RootDataConnection ( const IInterface own,
const std::string &  nam,
RootConnectionSetup setup 
)

Standard constructor.

Definition at line 168 of file RootDataConnection.cpp.

169  : IDataConnection(owner,fname), m_setup(setup), m_statistics(0), m_tool(0)
170 { // 01234567890123456789012345678901234567890
171  // Check if FID: A82A3BD8-7ECB-DC11-8DC0-000423D950B0
172  if ( fname.length() == 36 && fname[8]=='-'&&fname[13]=='-'&&fname[18]=='-'&&fname[23]=='-' ) {
173  m_name = "FID:"+fname;
174  }
175  m_setup->addRef();
176  m_age = 0;
177  m_file = 0;
178  m_refs = 0;
179  addClient(owner);
180 }
void addClient(const IInterface *client)
Add new client to this data source.
void addRef()
Increase reference count.
int m_age
Age counter.
std::string m_name
Connection name/identifier.
TFile * m_file
Reference to ROOT file.
class Gaudi::RootDataConnection::Tool * m_tool
TTreePerfStats * m_statistics
I/O read statistics from TTree.
const IInterface * owner() const
Owner instance.
IDataConnection(const IInterface *own, const std::string &nam)
Standard constructor.
RootConnectionSetup * m_setup
Reference to the setup structure.
TTree * m_refs
Pointer to the reference tree.
RootDataConnection::~RootDataConnection ( )
virtual

Standard destructor.

Definition at line 183 of file RootDataConnection.cpp.

183  {
184  m_setup->release();
185  releasePtr(m_tool);
186 }
void release()
Decrease reference count.
class Gaudi::RootDataConnection::Tool * m_tool
RootConnectionSetup * m_setup
Reference to the setup structure.

Member Function Documentation

void RootDataConnection::addClient ( const IInterface client)

Add new client to this data source.

Definition at line 189 of file RootDataConnection.cpp.

189  {
190  m_clients.insert(client);
191 }
Clients m_clients
Client list.
void RootDataConnection::badWriteError ( const std::string &  msg) const

Error handler when bad write statements occur.

Definition at line 207 of file RootDataConnection.cpp.

207  {
208  msgSvc() << MSG::ERROR << "File:" << fid() << "Failed action:" << msg << endmsg;
209 }
const std::string & fid() const
Access file id.
MsgStream & msgSvc() const
Allow access to printer service.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
StatusCode RootDataConnection::connectRead ( )
virtual

Open data stream in read mode.

Connect the file in READ mode.

Implements Gaudi::IDataConnection.

Definition at line 249 of file RootDataConnection.cpp.

249  {
250  m_file = TFile::Open(m_pfn.c_str());
251  if ( m_file && !m_file->IsZombie() ) {
253  msgSvc() << MSG::DEBUG << "Opened file " << m_pfn << " in mode READ. [" << m_fid << "]" << endmsg << MSG::DEBUG;
254  if ( msgSvc().isActive() ) m_file->ls();
255  msgSvc() << MSG::VERBOSE;
256  if ( msgSvc().isActive() ) m_file->Print();
257  if ( makeTool() ) {
258  sc = m_tool->readRefs();
259  sc.ignore();
260 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,33,0)
261  if ( sc.getCode() == ROOT_READ_ERROR ) {
262  IIncidentSvc* inc = m_setup->incidentSvc();
263  if ( inc ) {
265  }
266  }
267 #endif
268  }
269  if ( sc.isSuccess() ) {
270  bool need_fid = m_fid == m_pfn;
271  string fid = m_fid;
272  m_mergeFIDs.clear();
273  for(size_t i=0, n=m_params.size(); i<n; ++i) {
274  if ( m_params[i].first == "FID" ) {
275  m_mergeFIDs.push_back(m_params[i].second);
276  if ( m_params[i].second != m_fid ) {
277  msgSvc() << MSG::DEBUG << "Check FID param:" << m_params[i].second << endmsg;
278  //if ( m_fid == m_pfn ) {
279  m_fid = m_params[i].second;
280  //}
281  }
282  }
283  }
284  if ( !need_fid && fid != m_fid ) {
285  msgSvc() << MSG::ERROR << "FID mismatch:" << fid << "(Catalog) != " << m_fid << "(file)" << endmsg
286  << "for PFN:" << m_pfn << endmsg;
287  return StatusCode::FAILURE;
288  }
289  msgSvc() << MSG::DEBUG << "Using FID " << m_fid << " from params table...." << endmsg
290  << "for PFN:" << m_pfn << endmsg;
291  return sc;
292  }
293  }
294  else if ( m_file ) {
295  deletePtr(m_file);
296  }
297  return StatusCode::FAILURE;
298 }
const std::string & fid() const
Access file id.
unsigned long getCode() const
Get the status code by value.
Definition: StatusCode.h:79
std::string m_fid
File ID of the connection.
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:62
TFile * m_file
Reference to ROOT file.
const std::string & pfn() const
Access physical file name.
ParamMap m_params
Parameter map for file parameters.
StringVec m_mergeFIDs
Map containing merge FIDs.
std::string m_pfn
Physical file name of the connection.
virtual void fireIncident(const Incident &incident)=0
Fire an Incident.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
class Gaudi::RootDataConnection::Tool * m_tool
Tool * makeTool()
Create file access tool to encapsulate POOL compatibiliy.
IIncidentSvc * incidentSvc() const
Retrieve incident service.
virtual StatusCode readRefs()=0
Read references section when opening data file.
Base class for all Incidents (computing events).
Definition: Incident.h:16
MsgStream & msgSvc() const
Allow access to printer service.
RootConnectionSetup * m_setup
Reference to the setup structure.
void ignore() const
Definition: StatusCode.h:94
list i
Definition: ana.py:128
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
const std::string CorruptedInputFile
the input file has shown a corruption
Definition: Incident.h:81
The interface implemented by the IncidentSvc service.
Definition: IIncidentSvc.h:22
StatusCode RootDataConnection::connectWrite ( IoType  typ)
virtual

Open data stream in write mode.

Implements Gaudi::IDataConnection.

Definition at line 301 of file RootDataConnection.cpp.

301  {
302  int compress = RootConnectionSetup::compression();
303  msgSvc() << MSG::DEBUG;
304  switch(typ) {
305  case CREATE:
306  resetAge();
307  m_file = TFile::Open(m_pfn.c_str(),"CREATE","Root event data",compress);
308  m_refs = new TTree("Refs","Root reference data");
309  msgSvc() << "Opened file " << m_pfn << " in mode CREATE. [" << m_fid << "]" << endmsg;
310  m_params.push_back(make_pair("PFN",m_pfn));
311  if ( m_fid != m_pfn ) {
312  m_params.push_back(make_pair("FID",m_fid));
313  }
314  makeTool();
315  break;
316  case RECREATE:
317  resetAge();
318  m_file = TFile::Open(m_pfn.c_str(),"RECREATE","Root event data",compress);
319  msgSvc() << "Opened file " << m_pfn << " in mode RECREATE. [" << m_fid << "]" << endmsg;
320  m_refs = new TTree("Refs","Root reference data");
321  m_params.push_back(make_pair("PFN",m_pfn));
322  if ( m_fid != m_pfn ) {
323  m_params.push_back(make_pair("FID",m_fid));
324  }
325  makeTool();
326  break;
327  case UPDATE:
328  resetAge();
329  m_file = TFile::Open(m_pfn.c_str(),"UPDATE","Root event data",compress);
330  msgSvc() << "Opened file " << m_pfn << " in mode UPDATE. [" << m_fid << "]" << endmsg;
331  if ( m_file && !m_file->IsZombie() ) {
332  if ( makeTool() ) {
334  sc.ignore();
335  if ( sc.getCode() == ROOT_READ_ERROR ) {
336 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,33,0)
337  IIncidentSvc* inc = m_setup->incidentSvc();
338  if ( inc ) {
340  }
341 #endif
342  }
343  return sc;
344  }
345  TDirectory::TContext ctxt(m_file);
346  m_refs = new TTree("Refs","Root reference data");
347  makeTool();
348  return StatusCode::SUCCESS;
349  }
350  break;
351  default:
352  m_refs = 0;
353  m_file = 0;
354  return StatusCode::FAILURE;
355  }
357 }
unsigned long getCode() const
Get the status code by value.
Definition: StatusCode.h:79
std::string m_fid
File ID of the connection.
TFile * m_file
Reference to ROOT file.
static int compression()
Access to global compression level.
const std::string & pfn() const
Access physical file name.
ParamMap m_params
Parameter map for file parameters.
std::string m_pfn
Physical file name of the connection.
virtual void fireIncident(const Incident &incident)=0
Fire an Incident.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
class Gaudi::RootDataConnection::Tool * m_tool
Tool * makeTool()
Create file access tool to encapsulate POOL compatibiliy.
IIncidentSvc * incidentSvc() const
Retrieve incident service.
virtual StatusCode readRefs()=0
Read references section when opening data file.
void resetAge()
Reset age.
Base class for all Incidents (computing events).
Definition: Incident.h:16
MsgStream & msgSvc() const
Allow access to printer service.
RootConnectionSetup * m_setup
Reference to the setup structure.
void ignore() const
Definition: StatusCode.h:94
TTree * m_refs
Pointer to the reference tree.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
const std::string CorruptedInputFile
the input file has shown a corruption
Definition: Incident.h:81
The interface implemented by the IncidentSvc service.
Definition: IIncidentSvc.h:22
StatusCode RootDataConnection::disconnect ( )
virtual

Release data stream and release implementation dependent resources.

Implements Gaudi::IDataConnection.

Definition at line 360 of file RootDataConnection.cpp.

360  {
361  if ( m_file ) {
362  if ( !m_file->IsZombie() ) {
363  if ( m_file->IsWritable() ) {
364  msgSvc() << MSG::DEBUG;
365  TDirectory::TContext ctxt(m_file);
366  if ( m_refs ) {
367  if ( !m_tool->saveRefs().isSuccess() ) badWriteError("Saving References");
368  if ( m_refs->Write() < 0 ) badWriteError("Write Reference branch");
369  }
370  for(Sections::iterator i=m_sections.begin(); i!= m_sections.end();++i) {
371  if ( (*i).second ) {
372  if ( (*i).second->Write() < 0 ) badWriteError("Write section:"+(*i).first);
373  msgSvc() << "Disconnect section " << (*i).first << " " << (*i).second->GetName() << endmsg;
374  }
375  }
376  m_sections.clear();
377  }
378  msgSvc() << MSG::DEBUG;
379  if ( msgSvc().isActive() ) m_file->ls();
380  msgSvc() << MSG::VERBOSE;
381  if ( msgSvc().isActive() ) m_file->Print();
382  m_file->Close();
383  }
384  msgSvc() << MSG::DEBUG << "Disconnected file " << m_pfn << " " << m_file->GetName() << endmsg;
385  deletePtr(m_file);
386  releasePtr(m_tool);
387  }
388  return StatusCode::SUCCESS;
389 }
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:62
virtual StatusCode saveRefs()=0
Save references section when closing data file.
TFile * m_file
Reference to ROOT file.
std::string m_pfn
Physical file name of the connection.
Sections m_sections
Tree sections in TFile.
class Gaudi::RootDataConnection::Tool * m_tool
MsgStream & msgSvc() const
Allow access to printer service.
list i
Definition: ana.py:128
TTree * m_refs
Pointer to the reference tree.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
void badWriteError(const std::string &msg) const
Error handler when bad write statements occur.
CSTR RootDataConnection::empty ( ) const
protected

Empty string reference.

Definition at line 499 of file RootDataConnection.cpp.

499  {
500  return s_empty;
501 }
void RootDataConnection::enableStatistics ( const std::string &  section)

Enable TTreePerStats.

Definition at line 222 of file RootDataConnection.cpp.

222  {
223  if ( 0 == m_statistics ) {
224  TTree* t=getSection(section,false);
225  if ( t ) {
226  m_statistics = new TTreePerfStats((section+"_ioperf").c_str(),t);
227  return;
228  }
229  msgSvc() << MSG::WARNING << "Failed to enable perfstats for tree:" << section << endmsg;
230  return;
231  }
232  msgSvc() << MSG::INFO << "Perfstats are ALREADY ENABLED." << endmsg;
233 }
TTree * getSection(const std::string &sect, bool create=false)
Access TTree section from section name. The section is created if required.
TTreePerfStats * m_statistics
I/O read statistics from TTree.
MsgStream & msgSvc() const
Allow access to printer service.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
TFile* Gaudi::RootDataConnection::file ( ) const
inline

Direct access to TFile structure.

Definition at line 255 of file RootDataConnection.h.

255 { return m_file; }
TFile * m_file
Reference to ROOT 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 315 of file RootDataConnection.h.

316  { return m_tool->getBranch(section,branch_name); }
class Gaudi::RootDataConnection::Tool * m_tool
virtual TBranch * getBranch(const std::string &section, const std::string &n)=0
Access data branch by name: Get existing branch in read only mode.
TBranch* Gaudi::RootDataConnection::getBranch ( const std::string &  section,
const std::string &  branch_name,
TClass *  cl,
void *  ptr,
int  buff_siz,
int  split_lvl 
)

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 332 of file RootDataConnection.h.

333  { return (which>=0)&&(size_t(which)<m_conts.size()) ? *(m_conts.begin()+which) : empty(); }
StringVec m_conts
Map containing external container names.
const std::string & empty() const
Empty string reference.
def which
Locates an executable in the executables path ($PATH) and returns the full path to it...
Definition: GaudiTest.py:289
CSTR RootDataConnection::getDb ( int  which) const

Access database/file name from saved index.

Definition at line 490 of file RootDataConnection.cpp.

490  {
491  if ( (which>=0) && (size_t(which)<m_dbs.size()) ) {
492  if ( *(m_dbs.begin()+which) == s_local ) return m_fid;
493  return *(m_dbs.begin()+which);
494  }
495  return s_empty;
496 }
std::string m_fid
File ID of the connection.
def which
Locates an executable in the executables path ($PATH) and returns the full path to it...
Definition: GaudiTest.py:289
StringVec m_dbs
Map containing external database file names (fids)
const std::string& Gaudi::RootDataConnection::getLink ( int  which) const
inline

Access link name from saved index.

Definition at line 336 of file RootDataConnection.h.

337  { return (which>=0)&&(size_t(which)<m_links.size()) ? *(m_links.begin()+which) : empty(); }
StringVec m_links
Map containing internal links names.
const std::string & empty() const
Empty string reference.
def which
Locates an executable in the executables path ($PATH) and returns the full path to it...
Definition: GaudiTest.py:289
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 618 of file RootDataConnection.cpp.

618  {
619  //size_t idx = cont.find('/',1);
620  //string container = cont[0]=='/' ? cont.substr(1,idx==string::npos?idx:idx-1) : cont;
621  MergeSections::const_iterator i=m_mergeSects.find(container);
622  if ( i != m_mergeSects.end() ) {
623  size_t cnt = 0;
624  const ContainerSections& s = (*i).second;
625  for(ContainerSections::const_iterator j=s.begin(); j != s.end(); ++j,++cnt) {
626  const ContainerSection& c = *j;
627  if ( entry >= c.start && entry < (c.start+c.length) ) {
628  if ( m_linkSects.size() > cnt ) {
629  if ( msgSvc().isActive() ) {
630  msgSvc() << MSG::VERBOSE << "MergeSection for:" << container
631  << " [" << entry << "]" << endmsg
632  << "FID:" << m_fid << " -> PFN:" << m_pfn << endmsg;
633  }
634  return make_pair(&(m_linkSects[cnt]), &c);
635  }
636  }
637  }
638  }
639  msgSvc() << MSG::DEBUG << "Return INVALID MergeSection for:" << container
640  << " [" << entry << "]" << endmsg
641  << "FID:" << m_fid << " -> PFN:" << m_pfn << endmsg;
642  return make_pair((const RootRef*)0,(const ContainerSection*)0);
643 }
MergeSections m_mergeSects
Database section map for merged files.
std::vector< ContainerSection > ContainerSections
Definition of container sections to handle merged files.
std::string m_fid
File ID of the connection.
tuple c
Definition: gaudirun.py:341
bool isActive() const
Accessor: is MsgStream active.
Definition: MsgStream.h:128
std::string m_pfn
Physical file name of the connection.
Persistent reference object.
Definition: RootRefs.h:31
LinkSections m_linkSects
Database link sections.
MsgStream & msgSvc() const
Allow access to printer service.
string s
Definition: gaudirun.py:210
list i
Definition: ana.py:128
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
TTree * RootDataConnection::getSection ( const std::string &  sect,
bool  create = false 
)

Access TTree section from section name. The section is created if required.

Definition at line 392 of file RootDataConnection.cpp.

392  {
393  TTree* t = m_sections[section];
394  if ( !t ) {
395  t = (TTree*)m_file->Get(section.c_str());
396  if ( !t && create ) {
397  TDirectory::TContext ctxt(m_file);
398  t = new TTree(section.c_str(),"Root data for Gaudi");
399  }
400  if ( t ) {
401  int cacheSize = m_setup->cacheSize;
402  if ( create ) {
403  //t->SetAutoFlush(100);
404  }
405  if ( section == m_setup->loadSection && cacheSize>-2 ) {
406  MsgStream& msg = msgSvc();
407  int learnEntries = m_setup->learnEntries;
408  t->SetCacheSize(cacheSize);
409  t->SetCacheLearnEntries(learnEntries);
410  msg << MSG::DEBUG;
411  if ( create ) {
412  msg << "Tree:" << section << "Setting up tree cache:" << cacheSize << endmsg;
413  }
414  else {
415  const StringVec& vB = m_setup->vetoBranches;
416  const StringVec& cB = m_setup->cacheBranches;
417  msg << "Tree:" << section << " Setting up tree cache:" << cacheSize << " Add all branches." << endmsg;
418  msg << "Tree:" << section << " Learn for " << learnEntries << " entries." << endmsg;
419 
420  if ( cB.size()==0 && vB.size()== 0 ) {
421  msg << "Adding (default) all branches to tree cache." << endmsg;
422  t->AddBranchToCache("*",kTRUE);
423  }
424  if ( cB.size()==1 && cB[0]=="*" ) {
425  msg << "Adding all branches to tree cache according to option \"CacheBranches\"." << endmsg;
426  t->AddBranchToCache("*",kTRUE);
427  }
428  else {
429  StringVec::const_iterator i;
430  for(TIter it(t->GetListOfBranches()); it.Next(); ) {
431  const char* n = ((TNamed*)(*it))->GetName();
432  bool add = false, veto = false;
433  for(i=cB.begin(); i != cB.end();++i) {
434  if ( !match_wild(n,(*i).c_str()) ) continue;
435  add = true;
436  break;
437  }
438  for(i=vB.begin(); !add && i!=vB.end();++i) {
439  if ( !match_wild(n,(*i).c_str()) ) continue;
440  veto = true;
441  break;
442  }
443  if ( add && !veto ) {
444  msg << "Add " << n << " to branch cache." << endmsg;
445  t->AddBranchToCache(n,kTRUE);
446  }
447  else {
448  msg << "Do not cache branch " << n << endmsg;
449  }
450  }
451  }
452  }
453  }
454  m_sections[section] = t;
455  }
456  }
457  return t;
458 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
TFile * m_file
Reference to ROOT file.
std::vector< std::string > StringVec
Type definition for string maps.
int cacheSize
RootCnvSvc Property: Root data cache size.
std::string loadSection
RootCnvSvc Property: Root data cache size.
int learnEntries
RootCnvSvc Property: ROOT cache learn entries.
Sections m_sections
Tree sections in TFile.
StringVec cacheBranches
Vector of strings with branches to be cached for input files.
StringVec vetoBranches
Vector of strings with branches to NOT be cached for input files.
MsgStream & msgSvc() const
Allow access to printer service.
RootConnectionSetup * m_setup
Reference to the setup structure.
list i
Definition: ana.py:128
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
virtual bool Gaudi::RootDataConnection::isConnected ( ) const
inlinevirtual

Check if connected to data source.

Implements Gaudi::IDataConnection.

Definition at line 257 of file RootDataConnection.h.

257 { return m_file != 0; }
TFile * m_file
Reference to ROOT file.
bool Gaudi::RootDataConnection::isWritable ( ) const
inline

Is the file writable?

Definition at line 259 of file RootDataConnection.h.

259 { return m_file != 0 && m_file->IsWritable(); }
TFile * m_file
Reference to ROOT file.
int RootDataConnection::loadObj ( const std::string &  section,
const std::string &  cnt,
unsigned long  entry,
DataObject *&  pObj 
)

Load object.

Definition at line 541 of file RootDataConnection.cpp.

541  {
542  TBranch* b = getBranch(section,cnt);
543  if ( b ) {
544  TClass* cl = gROOT->GetClass(b->GetClassName(),kTRUE);
545  if ( cl ) {
546  int nb = -1;
547  pObj = (DataObject*)cl->New();
548  {
549  DataObjectPush push(pObj);
550  b->SetAddress(&pObj);
551  if ( section == m_setup->loadSection ) {
552  TTree* t = b->GetTree();
553  if ( Long64_t(entry) != t->GetReadEntry() ) {
554  t->LoadTree(Long64_t(entry));
555  }
556  }
557  nb = b->GetEntry(entry);
558  msgSvc() << MSG::VERBOSE;
559  if ( msgSvc().isActive() ) {
560  msgSvc() << "Load [" << entry << "] --> " << section
561  << ":" << cnt << " " << nb << " bytes."
562  << endmsg;
563  }
564  if ( nb < 0 ) { // This is definitely an error...ROOT says if reads fail, -1 is issued.
565 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,33,0)
566  IIncidentSvc* inc = m_setup->incidentSvc();
567  if ( inc ) {
569  }
570 #endif
571  }
572  else if ( nb == 0 && pObj->clID() == CLID_DataObject) {
573  TFile* f = b->GetFile();
574  int vsn = f->GetVersion();
575  if ( vsn < 52400 ) {
576  // For Gaudi v21r5 (ROOT 5.24.00b) DataObject::m_version was not written!
577  // Still this call be well be successful.
578  nb = 1;
579  }
580  else if ( vsn>1000000 && (vsn%1000000)<52400 ) {
581  // dto. Some POOL files have for unknown reasons a version
582  // not according to ROOT standards. Hack this explicitly.
583  nb = 1;
584  }
585  }
586  if ( nb < 0 ) {
587  delete pObj;
588  pObj = 0;
589  }
590  }
591  return nb;
592  }
593  }
594  return -1;
595 }
const std::string & pfn() const
Access physical file name.
std::string loadSection
RootCnvSvc Property: Root data cache size.
virtual void fireIncident(const Incident &incident)=0
Fire an Incident.
virtual const CLID & clID() const
Retrieve reference to class definition structure.
Definition: DataObject.cpp:58
TBranch * getBranch(const std::string &section, const std::string &branch_name)
Access data branch by name: Get existing branch in read only mode.
IIncidentSvc * incidentSvc() const
Retrieve incident service.
Base class for all Incidents (computing events).
Definition: Incident.h:16
MsgStream & msgSvc() const
Allow access to printer service.
RootConnectionSetup * m_setup
Reference to the setup structure.
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:31
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
const std::string CorruptedInputFile
the input file has shown a corruption
Definition: Incident.h:81
The interface implemented by the IncidentSvc service.
Definition: IIncidentSvc.h:22
int RootDataConnection::loadRefs ( const std::string &  section,
const std::string &  cnt,
unsigned long  entry,
RootObjectRefs refs 
)

Load references object.

Definition at line 598 of file RootDataConnection.cpp.

600 {
601  int nbytes = m_tool->loadRefs(section,cnt,entry,refs);
602 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,33,0)
603  if ( nbytes < 0 ) {
604  // This is definitely an error:
605  // -- Either branch not preesent at all or
606  // -- ROOT I/O error, which issues -1
607  IIncidentSvc* inc = m_setup->incidentSvc();
608  if ( inc ) {
610  }
611  }
612 #endif
613  return nbytes;
614 }
virtual int loadRefs(const std::string &section, const std::string &cnt, unsigned long entry, RootObjectRefs &refs)=0
Load references object.
const std::string & pfn() const
Access physical file name.
virtual void fireIncident(const Incident &incident)=0
Fire an Incident.
class Gaudi::RootDataConnection::Tool * m_tool
IIncidentSvc * incidentSvc() const
Retrieve incident service.
Base class for all Incidents (computing events).
Definition: Incident.h:16
RootConnectionSetup * m_setup
Reference to the setup structure.
const std::string CorruptedInputFile
the input file has shown a corruption
Definition: Incident.h:81
The interface implemented by the IncidentSvc service.
Definition: IIncidentSvc.h:22
bool RootDataConnection::lookupClient ( const IInterface client) const

Lookup client for this data source.

Definition at line 201 of file RootDataConnection.cpp.

201  {
202  Clients::const_iterator i=m_clients.find(client);
203  return i != m_clients.end();
204 }
Clients m_clients
Client list.
list i
Definition: ana.py:128
int RootDataConnection::makeLink ( const std::string &  p)

Convert path string to path index.

Definition at line 479 of file RootDataConnection.cpp.

479  {
480  int cnt = 0;
481  StringVec::iterator ip;
482  for(ip=m_links.begin();ip!=m_links.end();++ip,++cnt) {
483  if( (*ip) == p ) return cnt;
484  }
485  m_links.push_back(p);
486  return m_links.size()-1;
487 }
StringVec m_links
Map containing internal links names.
void RootDataConnection::makeRef ( IRegistry pA,
RootRef ref 
)

Create reference object from registry entry.

Definition at line 646 of file RootDataConnection.cpp.

646  {
647  IOpaqueAddress* pA = pR->address();
648  makeRef(pR->name(),pA->clID(),pA->svcType(),pA->par()[0],pA->par()[1],-1,ref);
649 }
virtual const std::string * par() const =0
Retrieve String parameters.
virtual long svcType() const =0
Retrieve service type.
virtual const CLID & clID() const =0
Retrieve class information from link.
void makeRef(IRegistry *pA, RootRef &ref)
Create reference object from registry entry.
virtual IOpaqueAddress * address() const =0
Retrieve opaque storage address.
Opaque address interface definition.
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 236 of file RootDataConnection.cpp.

236  {
237  releasePtr(m_tool);
238  if ( !m_refs ) m_refs = (TTree*)m_file->Get("Refs");
239  if ( m_refs )
240  m_tool = new RootTool(this);
241 #ifdef __POOL_COMPATIBILITY
242  else if ( m_file->Get("##Links") != 0 )
243  m_tool = new PoolTool(this);
244 #endif
245  return m_tool;
246 }
TFile * m_file
Reference to ROOT file.
Description:
Definition: RootTool.h:15
class Gaudi::RootDataConnection::Tool * m_tool
TTree * m_refs
Pointer to the reference tree.
const StringVec& Gaudi::RootDataConnection::mergeFIDs ( ) const
inline

Access merged FIDs.

Definition at line 265 of file RootDataConnection.h.

265 { return m_mergeFIDs; }
StringVec m_mergeFIDs
Map containing merge FIDs.
const MergeSections& Gaudi::RootDataConnection::mergeSections ( ) const
inline

Access merged data section inventory.

Definition at line 263 of file RootDataConnection.h.

263 { return m_mergeSects; }
MergeSections m_mergeSects
Database section map for merged files.
MsgStream& Gaudi::RootDataConnection::msgSvc ( ) const
inline

Allow access to printer service.

Definition at line 153 of file RootDataConnection.h.

153 { return m_setup->msgSvc(); }
MsgStream & msgSvc() const
Retrieve message service.
RootConnectionSetup * m_setup
Reference to the setup structure.
virtual StatusCode Gaudi::RootDataConnection::read ( void *  const,
size_t   
)
inlinevirtual

Read root byte buffer from input stream.

Implements Gaudi::IDataConnection.

Definition at line 305 of file RootDataConnection.h.

size_t RootDataConnection::removeClient ( const IInterface client)

Remove client from this data source.

Definition at line 194 of file RootDataConnection.cpp.

194  {
195  Clients::iterator i=m_clients.find(client);
196  if ( i != m_clients.end() ) m_clients.erase(i);
197  return m_clients.size();
198 }
Clients m_clients
Client list.
list i
Definition: ana.py:128
pair< int, unsigned long > RootDataConnection::save ( const std::string &  section,
const std::string &  cnt,
TClass *  cl,
void *  pObj,
int  buff_siz,
int  split_lvl,
bool  fill_missing = false 
)

Save object of a given class to section and container.

Definition at line 512 of file RootDataConnection.cpp.

512  {
513  split_lvl = 0;
514  TBranch* b = getBranch(section, cnt, cl, (void*)(pObj ? &pObj : 0),buff_siz,split_lvl);
515  if ( b ) {
516  Long64_t evt = b->GetEntries();
517  //msgSvc() << MSG::DEBUG << cnt.c_str() << " Obj:" << (void*)pObj
518  // << " Split:" << split_lvl << " Buffer size:" << buff_siz << endl;
519  if ( fill_missing ) {
520  Long64_t num, nevt = b->GetTree()->GetEntries();
521  if ( nevt > evt ) {
522  b->SetAddress(0);
523  num = nevt - evt;
524  while( num > 0 ) { b->Fill(); --num; }
525  msgSvc() << MSG::DEBUG << "Added " << long(nevt-evt)
526  << " / Tree: " << nevt << " / Branch: " << b->GetEntries()+1
527  << " NULL entries to:" << cnt << endmsg;
528  evt = b->GetEntries();
529  }
530  }
531  b->SetAddress(&pObj);
532  return make_pair(b->Fill(),(unsigned long)evt);
533  }
534  else if ( 0 != pObj ) {
535  msgSvc() << MSG::ERROR << "Failed to access branch " << m_name << "/" << cnt << endmsg;
536  }
537  return make_pair(-1,~0);
538 }
std::string m_name
Connection name/identifier.
TBranch * getBranch(const std::string &section, const std::string &branch_name)
Access data branch by name: Get existing branch in read only mode.
list nevt
Definition: ana.py:134
MsgStream & msgSvc() const
Allow access to printer service.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
pair< int, unsigned long > RootDataConnection::saveObj ( const std::string &  section,
const std::string &  cnt,
TClass *  cl,
DataObject pObj,
int  buff_siz,
int  split_lvl,
bool  fill_missing = false 
)

Save object of a given class to section and container.

Definition at line 505 of file RootDataConnection.cpp.

505  {
506  DataObjectPush push(pObj);
507  return save(section,cnt,cl,pObj,buff_siz,split_lvl,fill);
508 }
GAUDI_API void fill(AIDA::IHistogram1D *histo, const double value, const double weight=1.0)
simple function to fill AIDA::IHistogram1D objects
Definition: Fill.cpp:37
std::pair< int, unsigned long > save(const std::string &section, const std::string &cnt, TClass *cl, void *pObj, int buff_siz, int split_lvl, 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 RootDataConnection::saveStatistics ( const std::string &  statisticsFile)

Save TTree access statistics if required.

Definition at line 212 of file RootDataConnection.cpp.

212  {
213  if ( m_statistics ) {
214  m_statistics->Print();
215  if ( !statisticsFile.empty() )
216  m_statistics->SaveAs(statisticsFile.c_str());
217  deletePtr(m_statistics);
218  }
219 }
TTreePerfStats * m_statistics
I/O read statistics from TTree.
virtual long long int Gaudi::RootDataConnection::seek ( long long int  ,
int   
)
inlinevirtual

Seek on the file described by ioDesc. Arguments as in ::seek()

Implements Gaudi::IDataConnection.

Definition at line 309 of file RootDataConnection.h.

309 { return -1; }
Tool* Gaudi::RootDataConnection::tool ( ) const
inline

Access tool.

Definition at line 261 of file RootDataConnection.h.

261 { return m_tool; }
class Gaudi::RootDataConnection::Tool * m_tool
virtual StatusCode Gaudi::RootDataConnection::write ( const void *  ,
int   
)
inlinevirtual

Write root byte buffer to output stream.

Implements Gaudi::IDataConnection.

Definition at line 307 of file RootDataConnection.h.

Friends And Related Function Documentation

friend class Tool
friend

Definition at line 242 of file RootDataConnection.h.

Member Data Documentation

Clients Gaudi::RootDataConnection::m_clients
protected

Client list.

Definition at line 182 of file RootDataConnection.h.

StringVec Gaudi::RootDataConnection::m_conts
protected

Map containing external container names.

Definition at line 170 of file RootDataConnection.h.

StringVec Gaudi::RootDataConnection::m_dbs
protected

Map containing external database file names (fids)

Definition at line 168 of file RootDataConnection.h.

std::string Gaudi::RootDataConnection::m_empty
protected

Buffer for empty string reference.

Definition at line 184 of file RootDataConnection.h.

TFile* Gaudi::RootDataConnection::m_file
protected

Reference to ROOT file.

Definition at line 162 of file RootDataConnection.h.

StringVec Gaudi::RootDataConnection::m_links
protected

Map containing internal links names.

Definition at line 172 of file RootDataConnection.h.

LinkSections Gaudi::RootDataConnection::m_linkSects
protected

Database link sections.

Definition at line 180 of file RootDataConnection.h.

StringVec Gaudi::RootDataConnection::m_mergeFIDs
protected

Map containing merge FIDs.

Definition at line 174 of file RootDataConnection.h.

MergeSections Gaudi::RootDataConnection::m_mergeSects
protected

Database section map for merged files.

Definition at line 178 of file RootDataConnection.h.

ParamMap Gaudi::RootDataConnection::m_params
protected

Parameter map for file parameters.

Definition at line 176 of file RootDataConnection.h.

TTree* Gaudi::RootDataConnection::m_refs
protected

Pointer to the reference tree.

Definition at line 164 of file RootDataConnection.h.

Sections Gaudi::RootDataConnection::m_sections
protected

Tree sections in TFile.

Definition at line 166 of file RootDataConnection.h.

RootConnectionSetup* Gaudi::RootDataConnection::m_setup
protected

Reference to the setup structure.

Definition at line 158 of file RootDataConnection.h.

TTreePerfStats* Gaudi::RootDataConnection::m_statistics
protected

I/O read statistics from TTree.

Definition at line 160 of file RootDataConnection.h.

class Gaudi::RootDataConnection::Tool * Gaudi::RootDataConnection::m_tool

The documentation for this class was generated from the following files: