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::stringStringVec
 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< ContainerSectionContainerSections
 Definition of container sections to handle merged files. More...
 
typedef std::map< std::string, ContainerSectionsMergeSections
 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, std::shared_ptr< RootConnectionSetup > setup)
 Standard constructor. More...
 
 ~RootDataConnection () override=default
 Standard destructor. More...
 
TFile * file () const
 Direct access to TFile structure. More...
 
bool isConnected () const override
 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...
 
StatusCode connectRead () override
 Open data stream in read mode. More...
 
StatusCode connectWrite (IoType typ) override
 Open data stream in write mode. More...
 
StatusCode disconnect () override
 Release data stream and release implementation dependent resources. More...
 
StatusCode read (void *const, size_t) override
 Read root byte buffer from input stream. More...
 
StatusCode write (const void *, int) override
 Write root byte buffer to output stream. More...
 
long long int seek (long long int, int) override
 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::stringgetDb (int which) const
 Access database/file name from saved index. More...
 
const std::stringgetCont (int which) const
 Access container name from saved index. More...
 
const std::stringgetLink (int which) const
 Access link name from saved index. More...
 
- Public Member Functions inherited from Gaudi::IDataConnection
 IDataConnection (const IInterface *own, std::string nam)
 Standard constructor. More...
 
virtual ~IDataConnection ()=default
 Standard destructor. More...
 
const std::stringname () const
 Connection name. More...
 
void setFID (std::string fid)
 Set file ID. More...
 
const std::stringfid () const
 Access file id. More...
 
const std::stringpfn () const
 Access physical file name. More...
 
void setPFN (std::string fn)
 Set physical file name. More...
 
int 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

std::unique_ptr< Toolm_tool
 

Protected Member Functions

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

Protected Attributes

std::shared_ptr< RootConnectionSetupm_setup
 Reference to the setup structure. More...
 
std::unique_ptr< TTreePerfStats > m_statistics
 I/O read statistics from TTree. More...
 
std::unique_ptr< TFile > m_file
 Reference to ROOT file. More...
 
TTree * m_refs = nullptr
 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 = 0
 Age counter. More...
 
const IInterfacem_owner = nullptr
 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 92 of file RootDataConnection.h.

Member Typedef Documentation

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

Client set.

Definition at line 143 of file RootDataConnection.h.

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

Definition of container sections to handle merged files.

Definition at line 137 of file RootDataConnection.h.

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

Link sections definition.

Definition at line 141 of file RootDataConnection.h.

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

Definition of database section to handle merged files.

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

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

Definition of tree sections.

Definition at line 135 of file RootDataConnection.h.

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

Type definition for string maps.

Definition at line 131 of file RootDataConnection.h.

Member Enumeration Documentation

anonymous enum
Enumerator
ROOT_READ_ERROR 
ROOT_OPEN_ERROR 

Definition at line 95 of file RootDataConnection.h.

Constructor & Destructor Documentation

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

Standard constructor.

Definition at line 140 of file RootDataConnection.cpp.

141  : IDataConnection(owner,fname), m_setup(std::move(setup))
142 { // 01234567890123456789012345678901234567890
143  // Check if FID: A82A3BD8-7ECB-DC11-8DC0-000423D950B0
144  if ( fname.length() == 36 && fname[8]=='-'&&fname[13]=='-'&&fname[18]=='-'&&fname[23]=='-' ) {
145  m_name = "FID:"+fname;
146  }
147  m_age = 0;
148  m_file.reset();
149  addClient(owner);
150 }
void addClient(const IInterface *client)
Add new client to this data source.
int m_age
Age counter.
std::string m_name
Connection name/identifier.
IDataConnection(const IInterface *own, std::string nam)
Standard constructor.
T reset(T...args)
T move(T...args)
const IInterface * owner() const
Owner instance.
std::shared_ptr< RootConnectionSetup > m_setup
Reference to the setup structure.
std::unique_ptr< TFile > m_file
Reference to ROOT file.
Gaudi::RootDataConnection::~RootDataConnection ( )
overridedefault

Standard destructor.

Member Function Documentation

void RootDataConnection::addClient ( const IInterface client)

Add new client to this data source.

Definition at line 153 of file RootDataConnection.cpp.

153  {
154  m_clients.insert(client);
155 }
Clients m_clients
Client list.
T insert(T...args)
void RootDataConnection::badWriteError ( const std::string msg) const

Error handler when bad write statements occur.

Definition at line 171 of file RootDataConnection.cpp.

171  {
172  msgSvc() << MSG::ERROR << "File:" << fid() << "Failed action:" << msg << endmsg;
173 }
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 ( )
overridevirtual

Open data stream in read mode.

Connect the file in READ mode.

Implements Gaudi::IDataConnection.

Definition at line 214 of file RootDataConnection.cpp.

214  {
215  m_file.reset( TFile::Open(m_pfn.c_str()) );
216  if ( !m_file || m_file->IsZombie() ) {
217  m_file.reset();
218  return StatusCode::FAILURE;
219  }
221  msgSvc() << MSG::DEBUG << "Opened file " << m_pfn << " in mode READ. [" << m_fid << "]" << endmsg << MSG::DEBUG;
222  if ( msgSvc().isActive() ) m_file->ls();
223  msgSvc() << MSG::VERBOSE;
224  if ( msgSvc().isActive() ) m_file->Print();
225  if ( makeTool() ) {
226  sc = m_tool->readRefs();
227  sc.ignore();
228 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,33,0)
229  if ( sc.getCode() == ROOT_READ_ERROR ) {
230  IIncidentSvc* inc = m_setup->incidentSvc();
231  if ( inc ) {
232  inc->fireIncident(Incident(pfn(),IncidentType::CorruptedInputFile));
233  }
234  }
235 #endif
236  }
237  if ( !sc.isSuccess() ) return sc;
238  bool need_fid = m_fid == m_pfn;
239  string fid = m_fid;
240  m_mergeFIDs.clear();
241  for(auto & elem : m_params) {
242  if ( elem.first == "FID" ) {
243  m_mergeFIDs.push_back(elem.second);
244  if ( elem.second != m_fid ) {
245  msgSvc() << MSG::DEBUG << "Check FID param:" << elem.second << endmsg;
246  //if ( m_fid == m_pfn ) {
247  m_fid = elem.second;
248  //}
249  }
250  }
251  }
252  if ( !need_fid && fid != m_fid ) {
253  msgSvc() << MSG::ERROR << "FID mismatch:" << fid << "(Catalog) != " << m_fid << "(file)" << endmsg
254  << "for PFN:" << m_pfn << endmsg;
255  return StatusCode::FAILURE;
256  }
257  msgSvc() << MSG::DEBUG << "Using FID " << m_fid << " from params table...." << endmsg
258  << "for PFN:" << m_pfn << endmsg;
259  return sc;
260 }
const std::string & fid() const
Access file id.
std::unique_ptr< Tool > m_tool
unsigned long getCode() const
Get the status code by value.
Definition: StatusCode.h:93
std::string m_fid
File ID of the connection.
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
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.
T push_back(T...args)
virtual void fireIncident(const Incident &incident)=0
Fire an Incident.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
T reset(T...args)
T clear(T...args)
Tool * makeTool()
Create file access tool to encapsulate POOL compatibiliy.
std::shared_ptr< RootConnectionSetup > m_setup
Reference to the setup structure.
T c_str(T...args)
Base class for all Incidents (computing events).
Definition: Incident.h:17
MsgStream & msgSvc() const
Allow access to printer service.
std::unique_ptr< TFile > m_file
Reference to ROOT file.
void ignore() const
Definition: StatusCode.h:108
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
The interface implemented by the IncidentSvc service.
Definition: IIncidentSvc.h:21
StatusCode RootDataConnection::connectWrite ( IoType  typ)
overridevirtual

Open data stream in write mode.

Implements Gaudi::IDataConnection.

Definition at line 263 of file RootDataConnection.cpp.

263  {
264  int compress = RootConnectionSetup::compression();
265  msgSvc() << MSG::DEBUG;
266  switch(typ) {
267  case CREATE:
268  resetAge();
269  m_file.reset(TFile::Open(m_pfn.c_str(),"CREATE","Root event data",compress));
270  m_refs = new TTree("Refs","Root reference data");
271  msgSvc() << "Opened file " << m_pfn << " in mode CREATE. [" << m_fid << "]" << endmsg;
272  m_params.emplace_back("PFN",m_pfn);
273  if ( m_fid != m_pfn ) {
274  m_params.emplace_back("FID",m_fid);
275  }
276  makeTool();
277  break;
278  case RECREATE:
279  resetAge();
280  m_file.reset(TFile::Open(m_pfn.c_str(),"RECREATE","Root event data",compress));
281  msgSvc() << "Opened file " << m_pfn << " in mode RECREATE. [" << m_fid << "]" << endmsg;
282  m_refs = new TTree("Refs","Root reference data");
283  m_params.emplace_back("PFN",m_pfn);
284  if ( m_fid != m_pfn ) {
285  m_params.emplace_back("FID",m_fid);
286  }
287  makeTool();
288  break;
289  case UPDATE:
290  resetAge();
291  m_file.reset(TFile::Open(m_pfn.c_str(),"UPDATE","Root event data",compress));
292  msgSvc() << "Opened file " << m_pfn << " in mode UPDATE. [" << m_fid << "]" << endmsg;
293  if ( m_file && !m_file->IsZombie() ) {
294  if ( makeTool() ) {
295  StatusCode sc = m_tool->readRefs();
296  sc.ignore();
297  if ( sc.getCode() == ROOT_READ_ERROR ) {
298 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,33,0)
299  IIncidentSvc* inc = m_setup->incidentSvc();
300  if ( inc ) {
301  inc->fireIncident(Incident(pfn(),IncidentType::CorruptedInputFile));
302  }
303 #endif
304  }
305  return sc;
306  }
307  TDirectory::TContext ctxt(m_file.get());
308  m_refs = new TTree("Refs","Root reference data");
309  makeTool();
310  return StatusCode::SUCCESS;
311  }
312  break;
313  default:
314  m_refs = nullptr;
315  m_file.reset();
316  return StatusCode::FAILURE;
317  }
319 }
std::unique_ptr< Tool > m_tool
unsigned long getCode() const
Get the status code by value.
Definition: StatusCode.h:93
std::string m_fid
File ID of the connection.
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:26
T reset(T...args)
Tool * makeTool()
Create file access tool to encapsulate POOL compatibiliy.
T get(T...args)
std::shared_ptr< RootConnectionSetup > m_setup
Reference to the setup structure.
void resetAge()
Reset age.
T c_str(T...args)
Base class for all Incidents (computing events).
Definition: Incident.h:17
MsgStream & msgSvc() const
Allow access to printer service.
std::unique_ptr< TFile > m_file
Reference to ROOT file.
void ignore() const
Definition: StatusCode.h:108
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
The interface implemented by the IncidentSvc service.
Definition: IIncidentSvc.h:21
T emplace_back(T...args)
StatusCode RootDataConnection::disconnect ( )
overridevirtual

Release data stream and release implementation dependent resources.

Implements Gaudi::IDataConnection.

Definition at line 322 of file RootDataConnection.cpp.

322  {
323  if ( m_file ) {
324  if ( !m_file->IsZombie() ) {
325  if ( m_file->IsWritable() ) {
326  msgSvc() << MSG::DEBUG;
327  TDirectory::TContext ctxt(m_file.get());
328  if ( m_refs ) {
329  if ( !m_tool->saveRefs().isSuccess() ) badWriteError("Saving References");
330  if ( m_refs->Write() < 0 ) badWriteError("Write Reference branch");
331  }
332  for( auto& i : m_sections ) {
333  if ( i.second ) {
334  if ( i.second->Write() < 0 ) badWriteError("Write section:"+i.first);
335  msgSvc() << "Disconnect section " << i.first << " " << i.second->GetName() << endmsg;
336  }
337  }
338  m_sections.clear();
339  }
340  msgSvc() << MSG::DEBUG;
341  if ( msgSvc().isActive() ) m_file->ls();
342  msgSvc() << MSG::VERBOSE;
343  if ( msgSvc().isActive() ) m_file->Print();
344  m_file->Close();
345  }
346  msgSvc() << MSG::DEBUG << "Disconnected file " << m_pfn << " " << m_file->GetName() << endmsg;
347  m_file.reset();
348  m_tool.reset();
349  }
350  return StatusCode::SUCCESS;
351 }
std::unique_ptr< Tool > m_tool
std::string m_pfn
Physical file name of the connection.
void clear(STATE_TYPE _i=std::ios_base::failbit)
Definition: MsgStream.h:222
Sections m_sections
Tree sections in TFile.
T reset(T...args)
T get(T...args)
MsgStream & msgSvc() const
Allow access to printer service.
std::unique_ptr< TFile > m_file
Reference to ROOT file.
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 456 of file RootDataConnection.cpp.

456  {
457  return s_empty;
458 }
void RootDataConnection::enableStatistics ( const std::string section)

Enable TTreePerStats.

Definition at line 186 of file RootDataConnection.cpp.

186  {
187  if ( m_statistics ) {
188  TTree* t=getSection(section,false);
189  if ( t ) {
190  m_statistics.reset( new TTreePerfStats((section+"_ioperf").c_str(),t) );
191  return;
192  }
193  msgSvc() << MSG::WARNING << "Failed to enable perfstats for tree:" << section << endmsg;
194  return;
195  }
196  msgSvc() << MSG::INFO << "Perfstats are ALREADY ENABLED." << endmsg;
197 }
std::unique_ptr< TTreePerfStats > m_statistics
I/O read statistics from TTree.
TTree * getSection(const std::string &sect, bool create=false)
Access TTree section from section name. The section is created if required.
T reset(T...args)
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 247 of file RootDataConnection.h.

247 { return m_file.get(); }
T get(T...args)
std::unique_ptr< 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 307 of file RootDataConnection.h.

308  { return m_tool->getBranch(section,branch_name); }
std::unique_ptr< Tool > m_tool
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 324 of file RootDataConnection.h.

325  { 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.
T size(T...args)
T begin(T...args)
def which(executable)
Definition: BaseTest.py:547
CSTR RootDataConnection::getDb ( int  which) const

Access database/file name from saved index.

Definition at line 447 of file RootDataConnection.cpp.

447  {
448  if ( (which>=0) && (size_t(which)<m_dbs.size()) ) {
449  if ( *(m_dbs.begin()+which) == s_local ) return m_fid;
450  return *(m_dbs.begin()+which);
451  }
452  return s_empty;
453 }
std::string m_fid
File ID of the connection.
T size(T...args)
T begin(T...args)
def which(executable)
Definition: BaseTest.py:547
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 328 of file RootDataConnection.h.

329  { 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.
T size(T...args)
T begin(T...args)
def which(executable)
Definition: BaseTest.py:547
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 575 of file RootDataConnection.cpp.

575  {
576  //size_t idx = cont.find('/',1);
577  //string container = cont[0]=='/' ? cont.substr(1,idx==string::npos?idx:idx-1) : cont;
578  auto i=m_mergeSects.find(container);
579  if ( i != m_mergeSects.end() ) {
580  size_t cnt = 0;
581  const ContainerSections& s = (*i).second;
582  for(auto j=s.cbegin(); j != s.cend(); ++j,++cnt) {
583  const ContainerSection& c = *j;
584  if ( entry >= c.start && entry < (c.start+c.length) ) {
585  if ( m_linkSects.size() > cnt ) {
586  if ( msgSvc().isActive() ) {
587  msgSvc() << MSG::VERBOSE << "MergeSection for:" << container
588  << " [" << entry << "]" << endmsg
589  << "FID:" << m_fid << " -> PFN:" << m_pfn << endmsg;
590  }
591  return { &(m_linkSects[cnt]), &c };
592  }
593  }
594  }
595  }
596  msgSvc() << MSG::DEBUG << "Return INVALID MergeSection for:" << container
597  << " [" << entry << "]" << endmsg
598  << "FID:" << m_fid << " -> PFN:" << m_pfn << endmsg;
599  return { nullptr, nullptr };
600 }
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:391
bool isActive() const
Accessor: is MsgStream active.
Definition: MsgStream.h:128
T end(T...args)
std::string m_pfn
Physical file name of the connection.
T find(T...args)
T size(T...args)
LinkSections m_linkSects
Database link sections.
MsgStream & msgSvc() const
Allow access to printer service.
string s
Definition: gaudirun.py:245
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 354 of file RootDataConnection.cpp.

354  {
355  TTree* t = m_sections[section];
356  if ( !t ) {
357  t = (TTree*)m_file->Get(section.c_str());
358  if ( !t && create ) {
359  TDirectory::TContext ctxt(m_file.get());
360  t = new TTree(section.c_str(),"Root data for Gaudi");
361  }
362  if ( t ) {
363  int cacheSize = m_setup->cacheSize;
364  if ( create ) {
365  //t->SetAutoFlush(100);
366  }
367  if ( section == m_setup->loadSection && cacheSize>-2 ) {
368  MsgStream& msg = msgSvc();
369  int learnEntries = m_setup->learnEntries;
370  t->SetCacheSize(cacheSize);
371  t->SetCacheLearnEntries(learnEntries);
372  msg << MSG::DEBUG;
373  if ( create ) {
374  msg << "Tree:" << section << "Setting up tree cache:" << cacheSize << endmsg;
375  }
376  else {
377  const StringVec& vB = m_setup->vetoBranches;
378  const StringVec& cB = m_setup->cacheBranches;
379  msg << "Tree:" << section << " Setting up tree cache:" << cacheSize << " Add all branches." << endmsg;
380  msg << "Tree:" << section << " Learn for " << learnEntries << " entries." << endmsg;
381 
382  if ( cB.empty() && vB.empty()) {
383  msg << "Adding (default) all branches to tree cache." << endmsg;
384  t->AddBranchToCache("*",kTRUE);
385  }
386  if ( cB.size()==1 && cB[0]=="*" ) {
387  msg << "Adding all branches to tree cache according to option \"CacheBranches\"." << endmsg;
388  t->AddBranchToCache("*",kTRUE);
389  }
390  else {
391  for(TIter it(t->GetListOfBranches()); it.Next(); ) {
392  const char* n = ((TNamed*)(*it))->GetName();
393  bool add = false, veto = false;
394  for(const auto& i : cB ) {
395  if ( !match_wild(n,(i).c_str()) ) continue;
396  add = true;
397  break;
398  }
399  for(auto i=vB.cbegin(); !add && i!=vB.cend();++i) {
400  if ( !match_wild(n,(*i).c_str()) ) continue;
401  veto = true;
402  break;
403  }
404  if ( add && !veto ) {
405  msg << "Add " << n << " to branch cache." << endmsg;
406  t->AddBranchToCache(n,kTRUE);
407  }
408  else {
409  msg << "Do not cache branch " << n << endmsg;
410  }
411  }
412  }
413  }
414  }
415  m_sections[section] = t;
416  }
417  }
418  return t;
419 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
T cend(T...args)
std::vector< std::string > StringVec
Type definition for string maps.
Sections m_sections
Tree sections in TFile.
T get(T...args)
std::shared_ptr< RootConnectionSetup > m_setup
Reference to the setup structure.
T cbegin(T...args)
MsgStream & msgSvc() const
Allow access to printer service.
std::unique_ptr< TFile > m_file
Reference to ROOT file.
list i
Definition: ana.py:128
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
bool Gaudi::RootDataConnection::isConnected ( ) const
inlineoverridevirtual

Check if connected to data source.

Implements Gaudi::IDataConnection.

Definition at line 249 of file RootDataConnection.h.

249 { return bool(m_file); }
std::unique_ptr< TFile > m_file
Reference to ROOT file.
bool Gaudi::RootDataConnection::isWritable ( ) const
inline

Is the file writable?

Definition at line 251 of file RootDataConnection.h.

251 { return m_file && m_file->IsWritable(); }
std::unique_ptr< 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 498 of file RootDataConnection.cpp.

498  {
499  TBranch* b = getBranch(section,cnt);
500  if ( b ) {
501  TClass* cl = gROOT->GetClass(b->GetClassName(),kTRUE);
502  if ( cl ) {
503  int nb = -1;
504  pObj = (DataObject*)cl->New();
505  {
506  DataObjectPush push(pObj);
507  b->SetAddress(&pObj);
508  if ( section == m_setup->loadSection ) {
509  TTree* t = b->GetTree();
510  if ( Long64_t(entry) != t->GetReadEntry() ) {
511  t->LoadTree(Long64_t(entry));
512  }
513  }
514  nb = b->GetEntry(entry);
515  msgSvc() << MSG::VERBOSE;
516  if ( msgSvc().isActive() ) {
517  msgSvc() << "Load [" << entry << "] --> " << section
518  << ":" << cnt << " " << nb << " bytes."
519  << endmsg;
520  }
521  if ( nb < 0 ) { // This is definitely an error...ROOT says if reads fail, -1 is issued.
522 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,33,0)
523  IIncidentSvc* inc = m_setup->incidentSvc();
524  if ( inc ) {
525  inc->fireIncident(Incident(pfn(),IncidentType::CorruptedInputFile));
526  }
527 #endif
528  }
529  else if ( nb == 0 && pObj->clID() == CLID_DataObject) {
530  TFile* f = b->GetFile();
531  int vsn = f->GetVersion();
532  if ( vsn < 52400 ) {
533  // For Gaudi v21r5 (ROOT 5.24.00b) DataObject::m_version was not written!
534  // Still this call be well be successful.
535  nb = 1;
536  }
537  else if ( vsn>1000000 && (vsn%1000000)<52400 ) {
538  // dto. Some POOL files have for unknown reasons a version
539  // not according to ROOT standards. Hack this explicitly.
540  nb = 1;
541  }
542  }
543  if ( nb < 0 ) {
544  delete pObj;
545  pObj = nullptr;
546  }
547  }
548  return nb;
549  }
550  }
551  return -1;
552 }
const std::string & pfn() const
Access physical file name.
virtual void fireIncident(const Incident &incident)=0
Fire an Incident.
virtual const CLID & clID() const
Retrieve reference to class definition structure.
Definition: DataObject.cpp:68
TBranch * getBranch(const std::string &section, const std::string &branch_name)
Access data branch by name: Get existing branch in read only mode.
std::shared_ptr< RootConnectionSetup > m_setup
Reference to the setup structure.
Base class for all Incidents (computing events).
Definition: Incident.h:17
MsgStream & msgSvc() const
Allow access to printer service.
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
The interface implemented by the IncidentSvc service.
Definition: IIncidentSvc.h:21
int RootDataConnection::loadRefs ( const std::string section,
const std::string cnt,
unsigned long  entry,
RootObjectRefs refs 
)

Load references object.

Definition at line 555 of file RootDataConnection.cpp.

557 {
558  int nbytes = m_tool->loadRefs(section,cnt,entry,refs);
559 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,33,0)
560  if ( nbytes < 0 ) {
561  // This is definitely an error:
562  // -- Either branch not preesent at all or
563  // -- ROOT I/O error, which issues -1
564  IIncidentSvc* inc = m_setup->incidentSvc();
565  if ( inc ) {
566  inc->fireIncident(Incident(pfn(),IncidentType::CorruptedInputFile));
567  }
568  }
569 #endif
570  return nbytes;
571 }
std::unique_ptr< Tool > m_tool
const std::string & pfn() const
Access physical file name.
virtual void fireIncident(const Incident &incident)=0
Fire an Incident.
std::shared_ptr< RootConnectionSetup > m_setup
Reference to the setup structure.
Base class for all Incidents (computing events).
Definition: Incident.h:17
The interface implemented by the IncidentSvc service.
Definition: IIncidentSvc.h:21
bool RootDataConnection::lookupClient ( const IInterface client) const

Lookup client for this data source.

Definition at line 165 of file RootDataConnection.cpp.

165  {
166  auto i=m_clients.find(client);
167  return i != m_clients.end();
168 }
Clients m_clients
Client list.
T end(T...args)
T find(T...args)
list i
Definition: ana.py:128
int RootDataConnection::makeLink ( const std::string p)

Convert path string to path index.

Definition at line 439 of file RootDataConnection.cpp.

439  {
441  if (ip!=std::end(m_links)) return std::distance(std::begin(m_links),ip);
442  m_links.push_back(p);
443  return m_links.size()-1;
444 }
T distance(T...args)
T end(T...args)
StringVec m_links
Map containing internal links names.
T push_back(T...args)
T find(T...args)
T size(T...args)
T begin(T...args)
void RootDataConnection::makeRef ( IRegistry pA,
RootRef ref 
)

Create reference object from registry entry.

Definition at line 603 of file RootDataConnection.cpp.

603  {
604  IOpaqueAddress* pA = pR->address();
605  makeRef(pR->name(),pA->clID(),pA->svcType(),pA->par()[0],pA->par()[1],-1,ref);
606 }
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 200 of file RootDataConnection.cpp.

200  {
201  if ( !m_refs ) m_refs = (TTree*)m_file->Get("Refs");
202  if ( m_refs )
203  m_tool.reset( new RootTool(this) );
204 #ifdef __POOL_COMPATIBILITY
205  else if ( m_file->Get("##Links") != nullptr )
206  m_tool.reset(new PoolTool(this));
207 #endif
208  else
209  m_tool.reset();
210  return m_tool.get();
211 }
std::unique_ptr< Tool > m_tool
Description:
Definition: RootTool.h:16
std::unique_ptr< TFile > m_file
Reference to ROOT file.
TTree * m_refs
Pointer to the reference tree.
const StringVec& Gaudi::RootDataConnection::mergeFIDs ( ) const
inline

Access merged FIDs.

Definition at line 257 of file RootDataConnection.h.

257 { 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 255 of file RootDataConnection.h.

255 { 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 146 of file RootDataConnection.h.

146 { return m_setup->msgSvc(); }
std::shared_ptr< RootConnectionSetup > m_setup
Reference to the setup structure.
StatusCode Gaudi::RootDataConnection::read ( void *  const,
size_t   
)
inlineoverridevirtual

Read root byte buffer from input stream.

Implements Gaudi::IDataConnection.

Definition at line 297 of file RootDataConnection.h.

size_t RootDataConnection::removeClient ( const IInterface client)

Remove client from this data source.

Definition at line 158 of file RootDataConnection.cpp.

158  {
159  auto i=m_clients.find(client);
160  if ( i != m_clients.end() ) m_clients.erase(i);
161  return m_clients.size();
162 }
Clients m_clients
Client list.
T end(T...args)
T erase(T...args)
T find(T...args)
T size(T...args)
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 469 of file RootDataConnection.cpp.

469  {
470  split_lvl = 0;
471  TBranch* b = getBranch(section, cnt, cl, pObj ? &pObj : nullptr, buff_siz, split_lvl);
472  if ( b ) {
473  Long64_t evt = b->GetEntries();
474  //msgSvc() << MSG::DEBUG << cnt.c_str() << " Obj:" << (void*)pObj
475  // << " Split:" << split_lvl << " Buffer size:" << buff_siz << endl;
476  if ( fill_missing ) {
477  Long64_t num, nevt = b->GetTree()->GetEntries();
478  if ( nevt > evt ) {
479  b->SetAddress(nullptr);
480  num = nevt - evt;
481  while( num > 0 ) { b->Fill(); --num; }
482  msgSvc() << MSG::DEBUG << "Added " << long(nevt-evt)
483  << " / Tree: " << nevt << " / Branch: " << b->GetEntries()+1
484  << " NULL entries to:" << cnt << endmsg;
485  evt = b->GetEntries();
486  }
487  }
488  b->SetAddress(&pObj);
489  return {b->Fill(),evt};
490  }
491  if ( pObj ) {
492  msgSvc() << MSG::ERROR << "Failed to access branch " << m_name << "/" << cnt << endmsg;
493  }
494  return {-1,~0};
495 }
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 462 of file RootDataConnection.cpp.

462  {
463  DataObjectPush push(pObj);
464  return save(section,cnt,cl,pObj,buff_siz,split_lvl,fill);
465 }
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:36
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 176 of file RootDataConnection.cpp.

176  {
177  if ( m_statistics ) {
178  m_statistics->Print();
179  if ( !statisticsFile.empty() )
180  m_statistics->SaveAs(statisticsFile.c_str());
182  }
183 }
T empty(T...args)
std::unique_ptr< TTreePerfStats > m_statistics
I/O read statistics from TTree.
T reset(T...args)
T c_str(T...args)
long long int Gaudi::RootDataConnection::seek ( long long int  ,
int   
)
inlineoverridevirtual

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

Implements Gaudi::IDataConnection.

Definition at line 301 of file RootDataConnection.h.

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

Access tool.

Definition at line 253 of file RootDataConnection.h.

253 { return m_tool.get(); }
std::unique_ptr< Tool > m_tool
StatusCode Gaudi::RootDataConnection::write ( const void *  ,
int   
)
inlineoverridevirtual

Write root byte buffer to output stream.

Implements Gaudi::IDataConnection.

Definition at line 299 of file RootDataConnection.h.

Friends And Related Function Documentation

friend class Tool
friend

Definition at line 234 of file RootDataConnection.h.

Member Data Documentation

Clients Gaudi::RootDataConnection::m_clients
protected

Client list.

Definition at line 175 of file RootDataConnection.h.

StringVec Gaudi::RootDataConnection::m_conts
protected

Map containing external container names.

Definition at line 163 of file RootDataConnection.h.

StringVec Gaudi::RootDataConnection::m_dbs
protected

Map containing external database file names (fids)

Definition at line 161 of file RootDataConnection.h.

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

Buffer for empty string reference.

Definition at line 177 of file RootDataConnection.h.

std::unique_ptr<TFile> Gaudi::RootDataConnection::m_file
protected

Reference to ROOT file.

Definition at line 155 of file RootDataConnection.h.

StringVec Gaudi::RootDataConnection::m_links
protected

Map containing internal links names.

Definition at line 165 of file RootDataConnection.h.

LinkSections Gaudi::RootDataConnection::m_linkSects
protected

Database link sections.

Definition at line 173 of file RootDataConnection.h.

StringVec Gaudi::RootDataConnection::m_mergeFIDs
protected

Map containing merge FIDs.

Definition at line 167 of file RootDataConnection.h.

MergeSections Gaudi::RootDataConnection::m_mergeSects
protected

Database section map for merged files.

Definition at line 171 of file RootDataConnection.h.

ParamMap Gaudi::RootDataConnection::m_params
protected

Parameter map for file parameters.

Definition at line 169 of file RootDataConnection.h.

TTree* Gaudi::RootDataConnection::m_refs = nullptr
protected

Pointer to the reference tree.

Definition at line 157 of file RootDataConnection.h.

Sections Gaudi::RootDataConnection::m_sections
protected

Tree sections in TFile.

Definition at line 159 of file RootDataConnection.h.

std::shared_ptr<RootConnectionSetup> Gaudi::RootDataConnection::m_setup
protected

Reference to the setup structure.

Definition at line 151 of file RootDataConnection.h.

std::unique_ptr<TTreePerfStats> Gaudi::RootDataConnection::m_statistics
protected

I/O read statistics from TTree.

Definition at line 153 of file RootDataConnection.h.

std::unique_ptr<Tool> Gaudi::RootDataConnection::m_tool

Definition at line 233 of file RootDataConnection.h.


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