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 160 of file RootDataConnection.cpp.

161  : IDataConnection(owner,fname), m_setup(setup), m_statistics(0), m_tool(0)
162 { // 01234567890123456789012345678901234567890
163  // Check if FID: A82A3BD8-7ECB-DC11-8DC0-000423D950B0
164  if ( fname.length() == 36 && fname[8]=='-'&&fname[13]=='-'&&fname[18]=='-'&&fname[23]=='-' ) {
165  m_name = "FID:"+fname;
166  }
167  m_setup->addRef();
168  m_age = 0;
169  m_file = 0;
170  m_refs = 0;
171  addClient(owner);
172 }
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 175 of file RootDataConnection.cpp.

175  {
176  m_setup->release();
177  releasePtr(m_tool);
178 }
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 181 of file RootDataConnection.cpp.

181  {
182  m_clients.insert(client);
183 }
Clients m_clients
Client list.
void RootDataConnection::badWriteError ( const std::string &  msg) const

Error handler when bad write statements occur.

Definition at line 199 of file RootDataConnection.cpp.

199  {
200  msgSvc() << MSG::ERROR << "File:" << fid() << "Failed action:" << msg << endmsg;
201 }
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:243
StatusCode RootDataConnection::connectRead ( )
virtual

Open data stream in read mode.

Connect the file in READ mode.

Implements Gaudi::IDataConnection.

Definition at line 241 of file RootDataConnection.cpp.

241  {
242  m_file = TFile::Open(m_pfn.c_str());
243  if ( m_file && !m_file->IsZombie() ) {
245  msgSvc() << MSG::DEBUG << "Opened file " << m_pfn << " in mode READ. [" << m_fid << "]" << endmsg << MSG::DEBUG;
246  if ( msgSvc().isActive() ) m_file->ls();
247  msgSvc() << MSG::VERBOSE;
248  if ( msgSvc().isActive() ) m_file->Print();
249  if ( makeTool() ) {
250  sc = m_tool->readRefs();
251  sc.ignore();
252  if ( sc.getCode() == ROOT_READ_ERROR ) {
253  IIncidentSvc* inc = m_setup->incidentSvc();
254  if ( inc ) {
256  }
257  }
258  }
259  if ( sc.isSuccess() ) {
260  bool need_fid = m_fid == m_pfn;
261  string fid = m_fid;
262  m_mergeFIDs.clear();
263  for(size_t i=0, n=m_params.size(); i<n; ++i) {
264  if ( m_params[i].first == "FID" ) {
265  m_mergeFIDs.push_back(m_params[i].second);
266  if ( m_params[i].second != m_fid ) {
267  msgSvc() << MSG::DEBUG << "Check FID param:" << m_params[i].second << endmsg;
268  //if ( m_fid == m_pfn ) {
269  m_fid = m_params[i].second;
270  //}
271  }
272  }
273  }
274  if ( !need_fid && fid != m_fid ) {
275  msgSvc() << MSG::ERROR << "FID mismatch:" << fid << "(Catalog) != " << m_fid << "(file)" << endmsg
276  << "for PFN:" << m_pfn << endmsg;
277  return StatusCode::FAILURE;
278  }
279  msgSvc() << MSG::DEBUG << "Using FID " << m_fid << " from params table...." << endmsg
280  << "for PFN:" << m_pfn << endmsg;
281  return sc;
282  }
283  }
284  else if ( m_file ) {
285  deletePtr(m_file);
286  }
287  return StatusCode::FAILURE;
288 }
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:243
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 291 of file RootDataConnection.cpp.

291  {
292  int compress = RootConnectionSetup::compression();
293  msgSvc() << MSG::DEBUG;
294  switch(typ) {
295  case CREATE:
296  resetAge();
297  m_file = TFile::Open(m_pfn.c_str(),"CREATE","Root event data",compress);
298  m_refs = new TTree("Refs","Root reference data");
299  msgSvc() << "Opened file " << m_pfn << " in mode CREATE. [" << m_fid << "]" << endmsg;
300  m_params.push_back(make_pair("PFN",m_pfn));
301  if ( m_fid != m_pfn ) {
302  m_params.push_back(make_pair("FID",m_fid));
303  }
304  makeTool();
305  break;
306  case RECREATE:
307  resetAge();
308  m_file = TFile::Open(m_pfn.c_str(),"RECREATE","Root event data",compress);
309  msgSvc() << "Opened file " << m_pfn << " in mode RECREATE. [" << m_fid << "]" << endmsg;
310  m_refs = new TTree("Refs","Root reference data");
311  m_params.push_back(make_pair("PFN",m_pfn));
312  if ( m_fid != m_pfn ) {
313  m_params.push_back(make_pair("FID",m_fid));
314  }
315  makeTool();
316  break;
317  case UPDATE:
318  resetAge();
319  m_file = TFile::Open(m_pfn.c_str(),"UPDATE","Root event data",compress);
320  msgSvc() << "Opened file " << m_pfn << " in mode UPDATE. [" << m_fid << "]" << endmsg;
321  if ( m_file && !m_file->IsZombie() ) {
322  if ( makeTool() ) {
324  sc.ignore();
325  if ( sc.getCode() == ROOT_READ_ERROR ) {
326  IIncidentSvc* inc = m_setup->incidentSvc();
327  if ( inc ) {
329  }
330  }
331  return sc;
332  }
333  TDirectory::TContext ctxt(m_file);
334  m_refs = new TTree("Refs","Root reference data");
335  makeTool();
336  return StatusCode::SUCCESS;
337  }
338  break;
339  default:
340  m_refs = 0;
341  m_file = 0;
342  return StatusCode::FAILURE;
343  }
345 }
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:243
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 348 of file RootDataConnection.cpp.

348  {
349  if ( m_file ) {
350  if ( !m_file->IsZombie() ) {
351  if ( m_file->IsWritable() ) {
352  msgSvc() << MSG::DEBUG;
353  TDirectory::TContext ctxt(m_file);
354  if ( m_refs ) {
355  if ( !m_tool->saveRefs().isSuccess() ) badWriteError("Saving References");
356  if ( m_refs->Write() < 0 ) badWriteError("Write Reference branch");
357  }
358  for(Sections::iterator i=m_sections.begin(); i!= m_sections.end();++i) {
359  if ( (*i).second ) {
360  if ( (*i).second->Write() < 0 ) badWriteError("Write section:"+(*i).first);
361  msgSvc() << "Disconnect section " << (*i).first << " " << (*i).second->GetName() << endmsg;
362  }
363  }
364  m_sections.clear();
365  }
366  msgSvc() << MSG::DEBUG;
367  if ( msgSvc().isActive() ) m_file->ls();
368  msgSvc() << MSG::VERBOSE;
369  if ( msgSvc().isActive() ) m_file->Print();
370  m_file->Close();
371  }
372  msgSvc() << MSG::DEBUG << "Disconnected file " << m_pfn << " " << m_file->GetName() << endmsg;
373  deletePtr(m_file);
374  releasePtr(m_tool);
375  }
376  return StatusCode::SUCCESS;
377 }
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:243
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 487 of file RootDataConnection.cpp.

487  {
488  return s_empty;
489 }
void RootDataConnection::enableStatistics ( const std::string &  section)

Enable TTreePerStats.

Definition at line 214 of file RootDataConnection.cpp.

214  {
215  if ( 0 == m_statistics ) {
216  TTree* t=getSection(section,false);
217  if ( t ) {
218  m_statistics = new TTreePerfStats((section+"_ioperf").c_str(),t);
219  return;
220  }
221  msgSvc() << MSG::WARNING << "Failed to enable perfstats for tree:" << section << endmsg;
222  return;
223  }
224  msgSvc() << MSG::INFO << "Perfstats are ALREADY ENABLED." << endmsg;
225 }
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:243
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 478 of file RootDataConnection.cpp.

478  {
479  if ( (which>=0) && (size_t(which)<m_dbs.size()) ) {
480  if ( *(m_dbs.begin()+which) == s_local ) return m_fid;
481  return *(m_dbs.begin()+which);
482  }
483  return s_empty;
484 }
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 602 of file RootDataConnection.cpp.

602  {
603  //size_t idx = cont.find('/',1);
604  //string container = cont[0]=='/' ? cont.substr(1,idx==string::npos?idx:idx-1) : cont;
605  MergeSections::const_iterator i=m_mergeSects.find(container);
606  if ( i != m_mergeSects.end() ) {
607  size_t cnt = 0;
608  const ContainerSections& s = (*i).second;
609  for(ContainerSections::const_iterator j=s.begin(); j != s.end(); ++j,++cnt) {
610  const ContainerSection& c = *j;
611  if ( entry >= c.start && entry < (c.start+c.length) ) {
612  if ( m_linkSects.size() > cnt ) {
613  if ( msgSvc().isActive() ) {
614  msgSvc() << MSG::VERBOSE << "MergeSection for:" << container
615  << " [" << entry << "]" << endmsg
616  << "FID:" << m_fid << " -> PFN:" << m_pfn << endmsg;
617  }
618  return make_pair(&(m_linkSects[cnt]), &c);
619  }
620  }
621  }
622  }
623  msgSvc() << MSG::DEBUG << "Return INVALID MergeSection for:" << container
624  << " [" << entry << "]" << endmsg
625  << "FID:" << m_fid << " -> PFN:" << m_pfn << endmsg;
626  return make_pair((const RootRef*)0,(const ContainerSection*)0);
627 }
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:127
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:243
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 380 of file RootDataConnection.cpp.

380  {
381  TTree* t = m_sections[section];
382  if ( !t ) {
383  t = (TTree*)m_file->Get(section.c_str());
384  if ( !t && create ) {
385  TDirectory::TContext ctxt(m_file);
386  t = new TTree(section.c_str(),"Root data for Gaudi");
387  }
388  if ( t ) {
389  int cacheSize = m_setup->cacheSize;
390  if ( create ) {
391  //t->SetAutoFlush(100);
392  }
393  if ( section == m_setup->loadSection && cacheSize>-2 ) {
394  MsgStream& msg = msgSvc();
395  int learnEntries = m_setup->learnEntries;
396  t->SetCacheSize(cacheSize);
397  t->SetCacheLearnEntries(learnEntries);
398  msg << MSG::DEBUG;
399  if ( create ) {
400  msg << "Tree:" << section << "Setting up tree cache:" << cacheSize << endmsg;
401  }
402  else {
403  const StringVec& vB = m_setup->vetoBranches;
404  const StringVec& cB = m_setup->cacheBranches;
405  msg << "Tree:" << section << " Setting up tree cache:" << cacheSize << " Add all branches." << endmsg;
406  msg << "Tree:" << section << " Learn for " << learnEntries << " entries." << endmsg;
407 
408  if ( cB.size()==0 && vB.size()== 0 ) {
409  msg << "Adding (default) all branches to tree cache." << endmsg;
410  t->AddBranchToCache("*",kTRUE);
411  }
412  if ( cB.size()==1 && cB[0]=="*" ) {
413  msg << "Adding all branches to tree cache according to option \"CacheBranches\"." << endmsg;
414  t->AddBranchToCache("*",kTRUE);
415  }
416  else {
417  StringVec::const_iterator i;
418  for(TIter it(t->GetListOfBranches()); it.Next(); ) {
419  const char* n = ((TNamed*)(*it))->GetName();
420  bool add = false, veto = false;
421  for(i=cB.begin(); i != cB.end();++i) {
422  if ( !match_wild(n,(*i).c_str()) ) continue;
423  add = true;
424  break;
425  }
426  for(i=vB.begin(); !add && i!=vB.end();++i) {
427  if ( !match_wild(n,(*i).c_str()) ) continue;
428  veto = true;
429  break;
430  }
431  if ( add && !veto ) {
432  msg << "Add " << n << " to branch cache." << endmsg;
433  t->AddBranchToCache(n,kTRUE);
434  }
435  else {
436  msg << "Do not cache branch " << n << endmsg;
437  }
438  }
439  }
440  }
441  }
442  m_sections[section] = t;
443  }
444  }
445  return t;
446 }
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:243
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 529 of file RootDataConnection.cpp.

529  {
530  TBranch* b = getBranch(section,cnt);
531  if ( b ) {
532  TClass* cl = gROOT->GetClass(b->GetClassName(),kTRUE);
533  if ( cl ) {
534  int nb = -1;
535  pObj = (DataObject*)cl->New();
536  {
537  DataObjectPush push(pObj);
538  b->SetAddress(&pObj);
539  if ( section == m_setup->loadSection ) {
540  TTree* t = b->GetTree();
541  if ( Long64_t(entry) != t->GetReadEntry() ) {
542  t->LoadTree(Long64_t(entry));
543  }
544  }
545  nb = b->GetEntry(entry);
546  msgSvc() << MSG::VERBOSE;
547  if ( msgSvc().isActive() ) {
548  msgSvc() << "Load [" << entry << "] --> " << section
549  << ":" << cnt << " " << nb << " bytes."
550  << endmsg;
551  }
552  if ( nb < 0 ) { // This is definitely an error...ROOT says if reads fail, -1 is issued.
553  IIncidentSvc* inc = m_setup->incidentSvc();
554  if ( inc ) {
556  }
557  }
558  else if ( nb == 0 && pObj->clID() == CLID_DataObject) {
559  TFile* f = b->GetFile();
560  int vsn = f->GetVersion();
561  if ( vsn < 52400 ) {
562  // For Gaudi v21r5 (ROOT 5.24.00b) DataObject::m_version was not written!
563  // Still this call be well be successful.
564  nb = 1;
565  }
566  else if ( vsn>1000000 && (vsn%1000000)<52400 ) {
567  // dto. Some POOL files have for unknown reasons a version
568  // not according to ROOT standards. Hack this explicitly.
569  nb = 1;
570  }
571  }
572  if ( nb < 0 ) {
573  delete pObj;
574  pObj = 0;
575  }
576  }
577  return nb;
578  }
579  }
580  return -1;
581 }
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:243
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 584 of file RootDataConnection.cpp.

586 {
587  int nbytes = m_tool->loadRefs(section,cnt,entry,refs);
588  if ( nbytes < 0 ) {
589  // This is definitely an error:
590  // -- Either branch not preesent at all or
591  // -- ROOT I/O error, which issues -1
592  IIncidentSvc* inc = m_setup->incidentSvc();
593  if ( inc ) {
595  }
596  }
597  return nbytes;
598 }
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 193 of file RootDataConnection.cpp.

193  {
194  Clients::const_iterator i=m_clients.find(client);
195  return i != m_clients.end();
196 }
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 467 of file RootDataConnection.cpp.

467  {
468  int cnt = 0;
469  StringVec::iterator ip;
470  for(ip=m_links.begin();ip!=m_links.end();++ip,++cnt) {
471  if( (*ip) == p ) return cnt;
472  }
473  m_links.push_back(p);
474  return m_links.size()-1;
475 }
StringVec m_links
Map containing internal links names.
void RootDataConnection::makeRef ( IRegistry pA,
RootRef ref 
)

Create reference object from registry entry.

Definition at line 630 of file RootDataConnection.cpp.

630  {
631  IOpaqueAddress* pA = pR->address();
632  makeRef(pR->name(),pA->clID(),pA->svcType(),pA->par()[0],pA->par()[1],-1,ref);
633 }
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 228 of file RootDataConnection.cpp.

228  {
229  releasePtr(m_tool);
230  if ( !m_refs ) m_refs = (TTree*)m_file->Get("Refs");
231  if ( m_refs )
232  m_tool = new RootTool(this);
233 #ifdef __POOL_COMPATIBILITY
234  else if ( m_file->Get("##Links") != 0 )
235  m_tool = new PoolTool(this);
236 #endif
237  return m_tool;
238 }
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 186 of file RootDataConnection.cpp.

186  {
187  Clients::iterator i=m_clients.find(client);
188  if ( i != m_clients.end() ) m_clients.erase(i);
189  return m_clients.size();
190 }
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 500 of file RootDataConnection.cpp.

500  {
501  split_lvl = 0;
502  TBranch* b = getBranch(section, cnt, cl, (void*)(pObj ? &pObj : 0),buff_siz,split_lvl);
503  if ( b ) {
504  Long64_t evt = b->GetEntries();
505  //msgSvc() << MSG::DEBUG << cnt.c_str() << " Obj:" << (void*)pObj
506  // << " Split:" << split_lvl << " Buffer size:" << buff_siz << endl;
507  if ( fill_missing ) {
508  Long64_t num, nevt = b->GetTree()->GetEntries();
509  if ( nevt > evt ) {
510  b->SetAddress(0);
511  num = nevt - evt;
512  while( num > 0 ) { b->Fill(); --num; }
513  msgSvc() << MSG::DEBUG << "Added " << long(nevt-evt)
514  << " / Tree: " << nevt << " / Branch: " << b->GetEntries()+1
515  << " NULL entries to:" << cnt << endmsg;
516  evt = b->GetEntries();
517  }
518  }
519  b->SetAddress(&pObj);
520  return make_pair(b->Fill(),(unsigned long)evt);
521  }
522  else if ( 0 != pObj ) {
523  msgSvc() << MSG::ERROR << "Failed to access branch " << m_name << "/" << cnt << endmsg;
524  }
525  return make_pair(-1,~0);
526 }
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:243
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 493 of file RootDataConnection.cpp.

493  {
494  DataObjectPush push(pObj);
495  return save(section,cnt,cl,pObj,buff_siz,split_lvl,fill);
496 }
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 204 of file RootDataConnection.cpp.

204  {
205  if ( m_statistics ) {
206  m_statistics->Print();
207  if ( !statisticsFile.empty() )
208  m_statistics->SaveAs(statisticsFile.c_str());
209  deletePtr(m_statistics);
210  }
211 }
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: