The Gaudi Framework  v36r7 (7f57a304)
Gaudi::RootDataConnection Class Reference

#include <GaudiRootCnv/RootDataConnection.h>

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

Classes

class  ContainerSection
 
class  Tool
 

Public Types

enum  Status : StatusCode::code_t { Status::ROOT_READ_ERROR = 0x2, Status::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 *, std::less<> > Sections
 Definition of tree sections. More...
 
typedef std::vector< ContainerSectionContainerSections
 Definition of container sections to handle merged files. More...
 
typedef std::map< std::string, ContainerSections, std::less<> > 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, std::string_view nam, std::shared_ptr< RootConnectionSetup > setup)
 Standard constructor. 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 (std::string_view msg) const
 Error handler when bad write statements occur. More...
 
std::pair< const RootRef *, const ContainerSection * > getMergeSection (std::string_view container, int entry) const
 Access link section for single container and entry. More...
 
void enableStatistics (std::string_view section)
 Enable TTreePerStats. More...
 
void saveStatistics (std::string_view statisticsFile)
 Save TTree access statistics if required. More...
 
int loadObj (std::string_view section, std::string_view cnt, unsigned long entry, DataObject *&pObj)
 Load object. More...
 
int loadRefs (std::string_view section, std::string_view cnt, unsigned long entry, RootObjectRefs &refs)
 Load references object. More...
 
std::pair< int, unsigned long > saveObj (std::string_view section, std::string_view 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 (std::string_view section, std::string_view 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 (std::string_view sect, bool create=false)
 Access TTree section from section name. The section is created if required. More...
 
TBranch * getBranch (std::string_view section, std::string_view branch_name)
 Access data branch by name: Get existing branch in read only mode. More...
 
TBranch * getBranch (std::string_view section, std::string_view 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 (const IRegistry &pA, RootRef &ref)
 Create reference object from registry entry. More...
 
void makeRef (std::string_view name, long clid, int tech, std::string_view db, std::string_view cnt, int entry, RootRef &ref)
 Create reference object from values. More...
 
int makeLink (std::string_view 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 103 of file RootDataConnection.h.

Member Typedef Documentation

◆ Clients

Client set.

Definition at line 151 of file RootDataConnection.h.

◆ ContainerSections

Definition of container sections to handle merged files.

Definition at line 145 of file RootDataConnection.h.

◆ LinkSections

Link sections definition.

Definition at line 149 of file RootDataConnection.h.

◆ MergeSections

Definition of database section to handle merged files.

Definition at line 147 of file RootDataConnection.h.

◆ ParamMap

Type definition for the parameter map.

Definition at line 141 of file RootDataConnection.h.

◆ Sections

Definition of tree sections.

Definition at line 143 of file RootDataConnection.h.

◆ StringVec

Type definition for string maps.

Definition at line 139 of file RootDataConnection.h.

Member Enumeration Documentation

◆ Status

Enumerator
ROOT_READ_ERROR 
ROOT_OPEN_ERROR 

Definition at line 105 of file RootDataConnection.h.

105 : StatusCode::code_t { ROOT_READ_ERROR = 0x2, ROOT_OPEN_ERROR = 0x4 };

Constructor & Destructor Documentation

◆ RootDataConnection()

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

Standard constructor.

Definition at line 169 of file RootDataConnection.cpp.

171  : IDataConnection( owner, std::string{ fname } )
172  , m_setup( std::move( setup ) ) { // 01234567890123456789012345678901234567890
173  // Check if FID: A82A3BD8-7ECB-DC11-8DC0-000423D950B0
174  if ( fname.size() == 36 && fname[8] == '-' && fname[13] == '-' && fname[18] == '-' && fname[23] == '-' ) {
175  m_name = "FID:";
176  m_name.append( fname.data(), fname.size() );
177  }
178  m_age = 0;
179  m_file.reset();
180  addClient( owner );
181 }

Member Function Documentation

◆ addClient()

void RootDataConnection::addClient ( const IInterface client)

Add new client to this data source.

Definition at line 184 of file RootDataConnection.cpp.

184 { m_clients.insert( client ); }

◆ badWriteError()

void RootDataConnection::badWriteError ( std::string_view  msg) const

Error handler when bad write statements occur.

Definition at line 200 of file RootDataConnection.cpp.

200  {
201  msgSvc() << MSG::ERROR << "File:" << fid() << "Failed action:" << msg << endmsg;
202 }

◆ connectRead()

StatusCode RootDataConnection::connectRead ( )
overridevirtual

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.reset( TFile::Open( m_pfn.c_str() ) );
243  if ( !m_file || m_file->IsZombie() ) {
244  m_file.reset();
245  return StatusCode::FAILURE;
246  }
248  msgSvc() << MSG::DEBUG << "Opened file " << m_pfn << " in mode READ. [" << m_fid << "]" << endmsg << MSG::DEBUG;
249  if ( msgSvc().isActive() ) m_file->ls();
250  msgSvc() << MSG::VERBOSE;
251  if ( msgSvc().isActive() ) m_file->Print();
252  if ( makeTool() ) {
253  sc = m_tool->readRefs();
254  sc.ignore();
255 #if ROOT_VERSION_CODE >= ROOT_VERSION( 5, 33, 0 )
256  if ( sc == Status::ROOT_READ_ERROR ) {
257  IIncidentSvc* inc = m_setup->incidentSvc();
258  if ( inc ) { inc->fireIncident( Incident( pfn(), IncidentType::CorruptedInputFile ) ); }
259  }
260 #endif
261  }
262  if ( !sc.isSuccess() ) return sc;
263  bool need_fid = m_fid == m_pfn;
264  string fid = m_fid;
265  m_mergeFIDs.clear();
266  for ( auto& elem : m_params ) {
267  if ( elem.first == "FID" ) {
268  m_mergeFIDs.push_back( elem.second );
269  if ( elem.second != m_fid ) {
270  msgSvc() << MSG::DEBUG << "Check FID param:" << elem.second << endmsg;
271  // if ( m_fid == m_pfn ) {
272  m_fid = elem.second;
273  //}
274  }
275  }
276  }
277  if ( !need_fid && fid != m_fid ) {
278  msgSvc() << MSG::ERROR << "FID mismatch:" << fid << "(Catalog) != " << m_fid << "(file)" << endmsg
279  << "for PFN:" << m_pfn << endmsg;
280  return StatusCode::FAILURE;
281  }
282  msgSvc() << MSG::DEBUG << "Using FID " << m_fid << " from params table...." << endmsg << "for PFN:" << m_pfn
283  << endmsg;
284  return sc;
285 }

◆ connectWrite()

StatusCode RootDataConnection::connectWrite ( IoType  typ)
overridevirtual

Open data stream in write mode.

Implements Gaudi::IDataConnection.

Definition at line 288 of file RootDataConnection.cpp.

288  {
289  int compress = RootConnectionSetup::compression();
290  msgSvc() << MSG::DEBUG;
291  switch ( typ ) {
292  case CREATE:
293  resetAge();
294  m_file.reset( TFile::Open( m_pfn.c_str(), "CREATE", "Root event data", compress ) );
295  m_refs = new TTree( "Refs", "Root reference data" );
296  msgSvc() << "Opened file " << m_pfn << " in mode CREATE. [" << m_fid << "]" << endmsg;
297  m_params.emplace_back( "PFN", m_pfn );
298  if ( m_fid != m_pfn ) { m_params.emplace_back( "FID", m_fid ); }
299  makeTool();
300  break;
301  case RECREATE:
302  resetAge();
303  m_file.reset( TFile::Open( m_pfn.c_str(), "RECREATE", "Root event data", compress ) );
304  msgSvc() << "Opened file " << m_pfn << " in mode RECREATE. [" << m_fid << "]" << endmsg;
305  m_refs = new TTree( "Refs", "Root reference data" );
306  m_params.emplace_back( "PFN", m_pfn );
307  if ( m_fid != m_pfn ) { m_params.emplace_back( "FID", m_fid ); }
308  makeTool();
309  break;
310  case UPDATE:
311  resetAge();
312  m_file.reset( TFile::Open( m_pfn.c_str(), "UPDATE", "Root event data", compress ) );
313  msgSvc() << "Opened file " << m_pfn << " in mode UPDATE. [" << m_fid << "]" << endmsg;
314  if ( m_file && !m_file->IsZombie() ) {
315  if ( makeTool() ) {
316  StatusCode sc = m_tool->readRefs();
317  sc.ignore();
318  if ( sc == Status::ROOT_READ_ERROR ) {
319 #if ROOT_VERSION_CODE >= ROOT_VERSION( 5, 33, 0 )
320  IIncidentSvc* inc = m_setup->incidentSvc();
321  if ( inc ) { inc->fireIncident( Incident( pfn(), IncidentType::CorruptedInputFile ) ); }
322 #endif
323  }
324  return sc;
325  }
326  TDirectory::TContext ctxt( m_file.get() );
327  m_refs = new TTree( "Refs", "Root reference data" );
328  makeTool();
329  return StatusCode::SUCCESS;
330  }
331  break;
332  default:
333  m_refs = nullptr;
334  m_file.reset();
335  return StatusCode::FAILURE;
336  }
338 }

◆ disconnect()

StatusCode RootDataConnection::disconnect ( )
overridevirtual

Release data stream and release implementation dependent resources.

Implements Gaudi::IDataConnection.

Definition at line 341 of file RootDataConnection.cpp.

341  {
342  if ( m_file ) {
343  if ( !m_file->IsZombie() ) {
344  if ( m_file->IsWritable() ) {
345  msgSvc() << MSG::DEBUG;
346  TDirectory::TContext ctxt( m_file.get() );
347  if ( m_refs ) {
348  if ( !m_tool->saveRefs().isSuccess() ) badWriteError( "Saving References" );
349  if ( m_refs->Write() < 0 ) badWriteError( "Write Reference branch" );
350  }
351  for ( auto& i : m_sections ) {
352  if ( i.second ) {
353  if ( i.second->Write() < 0 ) badWriteError( "Write section:" + i.first );
354  msgSvc() << "Disconnect section " << i.first << " " << i.second->GetName() << endmsg;
355  }
356  }
357  m_sections.clear();
358  }
359  msgSvc() << MSG::DEBUG;
360  if ( msgSvc().isActive() ) m_file->ls();
361  msgSvc() << MSG::VERBOSE;
362  if ( msgSvc().isActive() ) m_file->Print();
363  m_file->Close();
364  }
365  msgSvc() << MSG::DEBUG << "Disconnected file " << m_pfn << " " << m_file->GetName() << endmsg;
366  m_file.reset();
367  m_tool.reset();
368  }
369  return StatusCode::SUCCESS;
370 }

◆ empty()

CSTR RootDataConnection::empty ( ) const
protected

Empty string reference.

Definition at line 473 of file RootDataConnection.cpp.

473 { return s_empty; }

◆ enableStatistics()

void RootDataConnection::enableStatistics ( std::string_view  section)

Enable TTreePerStats.

Definition at line 214 of file RootDataConnection.cpp.

214  {
215  if ( m_statistics ) {
216  TTree* t = getSection( section, false );
217  if ( t ) {
218  m_statistics.reset( new TTreePerfStats( ( std::string{ 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 }

◆ file()

TFile* Gaudi::RootDataConnection::file ( ) const
inline

Direct access to TFile structure.

Definition at line 253 of file RootDataConnection.h.

253 { return m_file.get(); }

◆ getBranch() [1/2]

TBranch* Gaudi::RootDataConnection::getBranch ( std::string_view  section,
std::string_view  branch_name 
)
inline

Access data branch by name: Get existing branch in read only mode.

Definition at line 313 of file RootDataConnection.h.

313  {
314  return m_tool->getBranch( section, branch_name );
315  }

◆ getBranch() [2/2]

TBranch * RootDataConnection::getBranch ( std::string_view  section,
std::string_view  branch_name,
TClass *  cl,
void *  ptr,
int  buff_siz,
int  split_lvl 
)

Access data branch by name: Get existing branch in write mode.

Definition at line 439 of file RootDataConnection.cpp.

440  {
441  string n = std::string{ branch_name };
443  begin( n ), end( n ), []( const char c ) { return !isalnum( c ); }, '_' );
444  n += ".";
445  TTree* t = getSection( section, true );
446  TBranch* b = t->GetBranch( n.c_str() );
447  if ( !b && cl && m_file->IsWritable() ) {
448  b = t->Branch( n.c_str(), cl->GetName(), (void*)( ptr ? &ptr : nullptr ), buff_siz, split_lvl );
449  }
450  if ( !b ) b = t->GetBranch( std::string{ branch_name }.c_str() );
451  if ( b ) b->SetAutoDelete( kFALSE );
452  return b;
453 }

◆ getCont()

const std::string& Gaudi::RootDataConnection::getCont ( int  which) const
inline

Access container name from saved index.

Definition at line 333 of file RootDataConnection.h.

333  {
334  return ( which >= 0 ) && ( size_t( which ) < m_conts.size() ) ? *( m_conts.begin() + which ) : empty();
335  }

◆ getDb()

CSTR RootDataConnection::getDb ( int  which) const

Access database/file name from saved index.

Definition at line 464 of file RootDataConnection.cpp.

464  {
465  if ( ( which >= 0 ) && ( size_t( which ) < m_dbs.size() ) ) {
466  if ( *( m_dbs.begin() + which ) == s_local ) return m_fid;
467  return *( m_dbs.begin() + which );
468  }
469  return s_empty;
470 }

◆ getLink()

const std::string& Gaudi::RootDataConnection::getLink ( int  which) const
inline

Access link name from saved index.

Definition at line 338 of file RootDataConnection.h.

338  {
339  return ( which >= 0 ) && ( size_t( which ) < m_links.size() ) ? *( m_links.begin() + which ) : empty();
340  }

◆ getMergeSection()

pair< const RootRef *, const RootDataConnection::ContainerSection * > RootDataConnection::getMergeSection ( std::string_view  container,
int  entry 
) const

Access link section for single container and entry.

Definition at line 580 of file RootDataConnection.cpp.

580  {
581  // size_t idx = cont.find('/',1);
582  // string container = cont[0]=='/' ? cont.substr(1,idx==string::npos?idx:idx-1) : cont;
583  auto i = m_mergeSects.find( container );
584  if ( i != m_mergeSects.end() ) {
585  size_t cnt = 0;
586  const ContainerSections& s = ( *i ).second;
587  for ( auto j = s.cbegin(); j != s.cend(); ++j, ++cnt ) {
588  const ContainerSection& c = *j;
589  if ( entry >= c.start && entry < ( c.start + c.length ) ) {
590  if ( m_linkSects.size() > cnt ) {
591  if ( msgSvc().isActive() ) {
592  msgSvc() << MSG::VERBOSE << "MergeSection for:" << container << " [" << entry << "]" << endmsg
593  << "FID:" << m_fid << " -> PFN:" << m_pfn << endmsg;
594  }
595  return { &( m_linkSects[cnt] ), &c };
596  }
597  }
598  }
599  }
600  msgSvc() << MSG::DEBUG << "Return INVALID MergeSection for:" << container << " [" << entry << "]" << endmsg
601  << "FID:" << m_fid << " -> PFN:" << m_pfn << endmsg;
602  return { nullptr, nullptr };
603 }

◆ getSection()

TTree * RootDataConnection::getSection ( std::string_view  sect,
bool  create = false 
)

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

Definition at line 373 of file RootDataConnection.cpp.

373  {
374  auto it = m_sections.find( section );
375  TTree* t = ( it != m_sections.end() ? it->second : nullptr );
376  if ( !t ) {
377  t = (TTree*)m_file->Get( std::string{ section }.c_str() );
378  if ( !t && create ) {
379  TDirectory::TContext ctxt( m_file.get() );
380  t = new TTree( std::string{ section }.c_str(), "Root data for Gaudi" );
381  }
382  if ( t ) {
383  int cacheSize = m_setup->cacheSize;
384  if ( create ) {
385  // t->SetAutoFlush(100);
386  }
387  if ( section == m_setup->loadSection && cacheSize > -2 ) {
388  MsgStream& msg = msgSvc();
389  int learnEntries = m_setup->learnEntries;
390  t->SetCacheSize( cacheSize );
391  t->SetCacheLearnEntries( learnEntries );
392  msg << MSG::DEBUG;
393  if ( create ) {
394  msg << "Tree:" << section << "Setting up tree cache:" << cacheSize << endmsg;
395  } else {
396  const StringVec& vB = m_setup->vetoBranches;
397  const StringVec& cB = m_setup->cacheBranches;
398  msg << "Tree:" << section << " Setting up tree cache:" << cacheSize << " Add all branches." << endmsg;
399  msg << "Tree:" << section << " Learn for " << learnEntries << " entries." << endmsg;
400 
401  if ( cB.empty() && vB.empty() ) {
402  msg << "Adding (default) all branches to tree cache." << endmsg;
403  t->AddBranchToCache( "*", kTRUE );
404  }
405  if ( cB.size() == 1 && cB[0] == "*" ) {
406  msg << "Adding all branches to tree cache according to option \"CacheBranches\"." << endmsg;
407  t->AddBranchToCache( "*", kTRUE );
408  } else {
409  for ( TIter it( t->GetListOfBranches() ); it.Next(); ) {
410  const char* n = ( (TNamed*)( *it ) )->GetName();
411  bool add = false, veto = false;
412  for ( const auto& i : cB ) {
413  if ( !match_wild( n, ( i ).c_str() ) ) continue;
414  add = true;
415  break;
416  }
417  for ( auto i = vB.cbegin(); !add && i != vB.cend(); ++i ) {
418  if ( !match_wild( n, ( *i ).c_str() ) ) continue;
419  veto = true;
420  break;
421  }
422  if ( add && !veto ) {
423  msg << "Add " << n << " to branch cache." << endmsg;
424  t->AddBranchToCache( n, kTRUE );
425  } else {
426  msg << "Do not cache branch " << n << endmsg;
427  }
428  }
429  }
430  }
431  }
432  m_sections[std::string{ section }] = t;
433  }
434  }
435  return t;
436 }

◆ isConnected()

bool Gaudi::RootDataConnection::isConnected ( ) const
inlineoverridevirtual

Check if connected to data source.

Implements Gaudi::IDataConnection.

Definition at line 255 of file RootDataConnection.h.

255 { return bool( m_file ); }

◆ isWritable()

bool Gaudi::RootDataConnection::isWritable ( ) const
inline

Is the file writable?

Definition at line 257 of file RootDataConnection.h.

257 { return m_file && m_file->IsWritable(); }

◆ loadObj()

int RootDataConnection::loadObj ( std::string_view  section,
std::string_view  cnt,
unsigned long  entry,
DataObject *&  pObj 
)

Load object.

Definition at line 513 of file RootDataConnection.cpp.

514  {
515  TBranch* b = getBranch( section, cnt );
516  if ( b ) {
517  TClass* cl = gROOT->GetClass( b->GetClassName(), kTRUE );
518  if ( cl ) {
519  int nb = -1;
520  pObj = (DataObject*)cl->New();
521  {
522  DataObjectPush push( pObj );
523  b->SetAddress( &pObj );
524  if ( section == m_setup->loadSection ) {
525  TTree* t = b->GetTree();
526  if ( Long64_t( entry ) != t->GetReadEntry() ) { t->LoadTree( Long64_t( entry ) ); }
527  }
528  nb = b->GetEntry( entry );
529  msgSvc() << MSG::VERBOSE;
530  if ( msgSvc().isActive() ) {
531  msgSvc() << "Load [" << entry << "] --> " << section << ":" << cnt << " " << nb << " bytes." << endmsg;
532  }
533  if ( nb < 0 ) { // This is definitely an error...ROOT says if reads fail, -1 is issued.
534 #if ROOT_VERSION_CODE >= ROOT_VERSION( 5, 33, 0 )
535  IIncidentSvc* inc = m_setup->incidentSvc();
536  if ( inc ) { inc->fireIncident( Incident( pfn(), IncidentType::CorruptedInputFile ) ); }
537 #endif
538  } else if ( nb == 0 && pObj->clID() == CLID_DataObject ) {
539  TFile* f = b->GetFile();
540  int vsn = f->GetVersion();
541  if ( vsn < 52400 ) {
542  // For Gaudi v21r5 (ROOT 5.24.00b) DataObject::m_version was not written!
543  // Still this call be well be successful.
544  nb = 1;
545  } else if ( vsn > 1000000 && ( vsn % 1000000 ) < 52400 ) {
546  // dto. Some POOL files have for unknown reasons a version
547  // not according to ROOT standards. Hack this explicitly.
548  nb = 1;
549  }
550  }
551  if ( nb < 0 ) {
552  delete pObj;
553  pObj = nullptr;
554  }
555  }
556  return nb;
557  }
558  }
559  return -1;
560 }

◆ loadRefs()

int RootDataConnection::loadRefs ( std::string_view  section,
std::string_view  cnt,
unsigned long  entry,
RootObjectRefs refs 
)

Load references object.

Definition at line 563 of file RootDataConnection.cpp.

564  {
565  int nbytes = m_tool->loadRefs( section, cnt, entry, refs );
566 #if ROOT_VERSION_CODE >= ROOT_VERSION( 5, 33, 0 )
567  if ( nbytes < 0 ) {
568  // This is definitely an error:
569  // -- Either branch not preesent at all or
570  // -- ROOT I/O error, which issues -1
571  IIncidentSvc* inc = m_setup->incidentSvc();
572  if ( inc ) { inc->fireIncident( Incident( pfn(), IncidentType::CorruptedInputFile ) ); }
573  }
574 #endif
575  return nbytes;
576 }

◆ lookupClient()

bool RootDataConnection::lookupClient ( const IInterface client) const

Lookup client for this data source.

Definition at line 194 of file RootDataConnection.cpp.

194  {
195  auto i = m_clients.find( client );
196  return i != m_clients.end();
197 }

◆ makeLink()

int RootDataConnection::makeLink ( std::string_view  p)

Convert path string to path index.

Definition at line 456 of file RootDataConnection.cpp.

456  {
457  auto ip = std::find( std::begin( m_links ), std::end( m_links ), p );
458  if ( ip != std::end( m_links ) ) return std::distance( std::begin( m_links ), ip );
459  m_links.push_back( std::string{ p } );
460  return m_links.size() - 1;
461 }

◆ makeRef() [1/2]

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

Create reference object from registry entry.

Definition at line 606 of file RootDataConnection.cpp.

606  {
607  IOpaqueAddress* pA = pR.address();
608  makeRef( pR.name(), pA->clID(), pA->svcType(), pA->par()[0], pA->par()[1], -1, ref );
609 }

◆ makeRef() [2/2]

void RootDataConnection::makeRef ( std::string_view  name,
long  clid,
int  tech,
std::string_view  db,
std::string_view  cnt,
int  entry,
RootRef ref 
)

Create reference object from values.

Definition at line 612 of file RootDataConnection.cpp.

613  {
614  auto db = ( dbase == m_fid ? std::string_view{ s_local } : dbase );
615  ref.entry = entry;
616 
617  int cdb = -1;
618  if ( !db.empty() ) {
619  auto idb = std::find_if( m_dbs.begin(), m_dbs.end(), [&]( const std::string& i ) { return i == db; } );
620  cdb = std::distance( m_dbs.begin(), idb );
621  if ( idb == m_dbs.end() ) m_dbs.push_back( std::string{ db } );
622  }
623 
624  int ccnt = -1;
625  if ( !cnt.empty() ) {
626  auto icnt = std::find_if( m_conts.begin(), m_conts.end(), [&]( const std::string& i ) { return i == cnt; } );
627  ccnt = std::distance( m_conts.begin(), icnt );
628  if ( icnt == m_conts.end() ) m_conts.push_back( std::string{ cnt } );
629  }
630 
631  int clnk = -1;
632  if ( !name.empty() ) {
633  auto ilnk = std::find_if( m_links.begin(), m_links.end(), [&]( const std::string& i ) { return i == name; } );
634  clnk = std::distance( m_links.begin(), ilnk );
635  if ( ilnk == m_links.end() ) m_links.push_back( std::string{ name } );
636  }
637 
638  ref.dbase = cdb;
639  ref.container = ccnt;
640  ref.link = clnk;
641  ref.clid = clid;
642  ref.svc = tech;
643  if ( ref.svc == POOL_ROOT_StorageType || ref.svc == POOL_ROOTKEY_StorageType ||
644  ref.svc == POOL_ROOTTREE_StorageType ) {
645  ref.svc = ROOT_StorageType;
646  }
647 }

◆ makeTool()

RootDataConnection::Tool * RootDataConnection::makeTool ( )

Create file access tool to encapsulate POOL compatibiliy.

Definition at line 228 of file RootDataConnection.cpp.

228  {
229  if ( !m_refs ) m_refs = (TTree*)m_file->Get( "Refs" );
230  if ( m_refs ) m_tool.reset( new RootTool( this ) );
231 #ifdef __POOL_COMPATIBILITY
232  else if ( m_file->Get( "##Links" ) != nullptr )
233  m_tool.reset( new PoolTool( this ) );
234 #endif
235  else
236  m_tool.reset();
237  return m_tool.get();
238 }

◆ mergeFIDs()

const StringVec& Gaudi::RootDataConnection::mergeFIDs ( ) const
inline

Access merged FIDs.

Definition at line 263 of file RootDataConnection.h.

263 { return m_mergeFIDs; }

◆ mergeSections()

const MergeSections& Gaudi::RootDataConnection::mergeSections ( ) const
inline

Access merged data section inventory.

Definition at line 261 of file RootDataConnection.h.

261 { return m_mergeSects; }

◆ msgSvc()

MsgStream& Gaudi::RootDataConnection::msgSvc ( ) const
inline

Allow access to printer service.

Definition at line 154 of file RootDataConnection.h.

154 { return m_setup->msgSvc(); }

◆ read()

StatusCode Gaudi::RootDataConnection::read ( void * const  ,
size_t   
)
inlineoverridevirtual

Read root byte buffer from input stream.

Implements Gaudi::IDataConnection.

Definition at line 303 of file RootDataConnection.h.

303 { return StatusCode::FAILURE; }

◆ removeClient()

size_t RootDataConnection::removeClient ( const IInterface client)

Remove client from this data source.

Definition at line 187 of file RootDataConnection.cpp.

187  {
188  auto i = m_clients.find( client );
189  if ( i != m_clients.end() ) m_clients.erase( i );
190  return m_clients.size();
191 }

◆ save()

pair< int, unsigned long > RootDataConnection::save ( std::string_view  section,
std::string_view  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 483 of file RootDataConnection.cpp.

484  {
485  split_lvl = 0;
486  TBranch* b = getBranch( section, cnt, cl, pObj ? &pObj : nullptr, buff_siz, split_lvl );
487  if ( b ) {
488  Long64_t evt = b->GetEntries();
489  // msgSvc() << MSG::DEBUG << cnt.c_str() << " Obj:" << (void*)pObj
490  // << " Split:" << split_lvl << " Buffer size:" << buff_siz << endl;
491  if ( fill_missing ) {
492  Long64_t num, nevt = b->GetTree()->GetEntries();
493  if ( nevt > evt ) {
494  b->SetAddress( nullptr );
495  num = nevt - evt;
496  while ( num > 0 ) {
497  b->Fill();
498  --num;
499  }
500  msgSvc() << MSG::DEBUG << "Added " << long( nevt - evt ) << " / Tree: " << nevt
501  << " / Branch: " << b->GetEntries() + 1 << " NULL entries to:" << cnt << endmsg;
502  evt = b->GetEntries();
503  }
504  }
505  b->SetAddress( &pObj );
506  return { b->Fill(), evt };
507  }
508  if ( pObj ) { msgSvc() << MSG::ERROR << "Failed to access branch " << m_name << "/" << cnt << endmsg; }
509  return { -1, ~0 };
510 }

◆ saveObj()

pair< int, unsigned long > RootDataConnection::saveObj ( std::string_view  section,
std::string_view  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 476 of file RootDataConnection.cpp.

477  {
478  DataObjectPush push( pObj );
479  return save( section, cnt, cl, pObj, buff_siz, split_lvl, fill );
480 }

◆ saveRefs()

StatusCode Gaudi::RootDataConnection::saveRefs ( )
protected

Internal helper to save/update reference tables.

◆ saveStatistics()

void RootDataConnection::saveStatistics ( std::string_view  statisticsFile)

Save TTree access statistics if required.

Definition at line 205 of file RootDataConnection.cpp.

205  {
206  if ( m_statistics ) {
207  m_statistics->Print();
208  if ( !statisticsFile.empty() ) m_statistics->SaveAs( std::string{ statisticsFile }.c_str() );
210  }
211 }

◆ seek()

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

307 { return -1; }

◆ tool()

Tool* Gaudi::RootDataConnection::tool ( ) const
inline

Access tool.

Definition at line 259 of file RootDataConnection.h.

259 { return m_tool.get(); }

◆ write()

StatusCode Gaudi::RootDataConnection::write ( const void *  ,
int   
)
inlineoverridevirtual

Write root byte buffer to output stream.

Implements Gaudi::IDataConnection.

Definition at line 305 of file RootDataConnection.h.

305 { return StatusCode::FAILURE; }

Friends And Related Function Documentation

◆ Tool

friend class Tool
friend

Definition at line 243 of file RootDataConnection.h.

Member Data Documentation

◆ m_clients

Clients Gaudi::RootDataConnection::m_clients
protected

Client list.

Definition at line 182 of file RootDataConnection.h.

◆ m_conts

StringVec Gaudi::RootDataConnection::m_conts
protected

Map containing external container names.

Definition at line 170 of file RootDataConnection.h.

◆ m_dbs

StringVec Gaudi::RootDataConnection::m_dbs
protected

Map containing external database file names (fids)

Definition at line 168 of file RootDataConnection.h.

◆ m_empty

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

Buffer for empty string reference.

Definition at line 184 of file RootDataConnection.h.

◆ m_file

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

Reference to ROOT file.

Definition at line 162 of file RootDataConnection.h.

◆ m_links

StringVec Gaudi::RootDataConnection::m_links
protected

Map containing internal links names.

Definition at line 172 of file RootDataConnection.h.

◆ m_linkSects

LinkSections Gaudi::RootDataConnection::m_linkSects
protected

Database link sections.

Definition at line 180 of file RootDataConnection.h.

◆ m_mergeFIDs

StringVec Gaudi::RootDataConnection::m_mergeFIDs
protected

Map containing merge FIDs.

Definition at line 174 of file RootDataConnection.h.

◆ m_mergeSects

MergeSections Gaudi::RootDataConnection::m_mergeSects
protected

Database section map for merged files.

Definition at line 178 of file RootDataConnection.h.

◆ m_params

ParamMap Gaudi::RootDataConnection::m_params
protected

Parameter map for file parameters.

Definition at line 176 of file RootDataConnection.h.

◆ m_refs

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

Pointer to the reference tree.

Definition at line 164 of file RootDataConnection.h.

◆ m_sections

Sections Gaudi::RootDataConnection::m_sections
protected

Tree sections in TFile.

Definition at line 166 of file RootDataConnection.h.

◆ m_setup

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

Reference to the setup structure.

Definition at line 158 of file RootDataConnection.h.

◆ m_statistics

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

I/O read statistics from TTree.

Definition at line 160 of file RootDataConnection.h.

◆ m_tool

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

Definition at line 242 of file RootDataConnection.h.


The documentation for this class was generated from the following files:
IOTest.evt
evt
Definition: IOTest.py:110
Gaudi::RootDataConnection::save
std::pair< int, unsigned long > save(std::string_view section, std::string_view 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: RootDataConnection.cpp:483
MSG::DEBUG
@ DEBUG
Definition: IMessageSvc.h:25
Gaudi::IDataConnection::name
const std::string & name() const
Connection name.
Definition: IIODataManager.h:59
std::string
STL class.
Gaudi::RootDataConnection::m_clients
Clients m_clients
Client list.
Definition: RootDataConnection.h:182
IOpaqueAddress::par
virtual const std::string * par() const =0
Retrieve String parameters.
Gaudi::RootTool
Definition: RootTool.h:26
std::move
T move(T... args)
Gaudi::ContainerSection
Definition: merge.C:33
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:314
MSG::INFO
@ INFO
Definition: IMessageSvc.h:25
Gaudi::RootDataConnection::badWriteError
void badWriteError(std::string_view msg) const
Error handler when bad write statements occur.
Definition: RootDataConnection.cpp:200
Properties.long
long
(c) Copyright 1998-2020 CERN for the benefit of the LHCb and ATLAS collaborations # # This software i...
Definition: Properties.py:15
gaudirun.s
string s
Definition: gaudirun.py:346
IOpaqueAddress
Definition: IOpaqueAddress.h:33
std::map::find
T find(T... args)
std::vector::size
T size(T... args)
IOpaqueAddress::svcType
virtual long svcType() const =0
Retrieve service type.
Gaudi::IDataConnection::RECREATE
@ RECREATE
Definition: IIODataManager.h:49
Gaudi::IDataConnection::resetAge
void resetAge()
Reset age.
Definition: IIODataManager.h:71
GaudiMP.FdsRegistry.msg
msg
Definition: FdsRegistry.py:19
Gaudi::RootDataConnection::m_file
std::unique_ptr< TFile > m_file
Reference to ROOT file.
Definition: RootDataConnection.h:162
std::unique_ptr::get
T get(T... args)
std::distance
T distance(T... args)
MSG::WARNING
@ WARNING
Definition: IMessageSvc.h:25
Gaudi::RootDataConnection::m_params
ParamMap m_params
Parameter map for file parameters.
Definition: RootDataConnection.h:176
std::isalnum
T isalnum(T... args)
gaudirun.c
c
Definition: gaudirun.py:525
StatusCode::code_t
unsigned long code_t
type of StatusCode value
Definition: StatusCode.h:67
std::unique_ptr::reset
T reset(T... args)
IIncidentSvc::fireIncident
virtual void fireIncident(const Incident &incident)=0
Fire an Incident.
Gaudi::RootDataConnection::m_dbs
StringVec m_dbs
Map containing external database file names (fids)
Definition: RootDataConnection.h:168
std::vector::clear
T clear(T... args)
std::replace_if
T replace_if(T... args)
std::vector::push_back
T push_back(T... args)
bug_34121.t
t
Definition: bug_34121.py:30
Gaudi::RootDataConnection::m_linkSects
LinkSections m_linkSects
Database link sections.
Definition: RootDataConnection.h:180
Gaudi::IDataConnection::CREATE
@ CREATE
Definition: IIODataManager.h:49
Gaudi::RootDataConnection::ContainerSections
std::vector< ContainerSection > ContainerSections
Definition of container sections to handle merged files.
Definition: RootDataConnection.h:145
StatusCode
Definition: StatusCode.h:65
Gaudi::RootDataConnection::m_mergeFIDs
StringVec m_mergeFIDs
Map containing merge FIDs.
Definition: RootDataConnection.h:174
Gaudi::RootDataConnection::m_setup
std::shared_ptr< RootConnectionSetup > m_setup
Reference to the setup structure.
Definition: RootDataConnection.h:158
CLHEP::begin
double * begin(CLHEP::HepVector &v)
Definition: TupleAlg.cpp:45
Gaudi::RootDataConnection::Status::ROOT_READ_ERROR
@ ROOT_READ_ERROR
POOL_ROOT_StorageType
const long POOL_ROOT_StorageType
Definition: ClassID.h:78
GaudiTesting.BaseTest.which
def which(executable)
Definition: BaseTest.py:745
Gaudi::RootDataConnection::m_mergeSects
MergeSections m_mergeSects
Database section map for merged files.
Definition: RootDataConnection.h:178
std::string::c_str
T c_str(T... args)
POOL_ROOTKEY_StorageType
const long POOL_ROOTKEY_StorageType
Definition: ClassID.h:79
IOpaqueAddress::clID
virtual const CLID & clID() const =0
Retrieve class information from link.
Gaudi::IDataConnection::UPDATE
@ UPDATE
Definition: IIODataManager.h:49
Gaudi::RootDataConnection::m_statistics
std::unique_ptr< TTreePerfStats > m_statistics
I/O read statistics from TTree.
Definition: RootDataConnection.h:160
Gaudi::IDataConnection::m_name
std::string m_name
Connection name/identifier.
Definition: IIODataManager.h:37
GaudiPython.Bindings.nullptr
nullptr
Definition: Bindings.py:93
std::set::erase
T erase(T... args)
Gaudi::IDataConnection::IDataConnection
IDataConnection(const IInterface *own, std::string nam)
Standard constructor.
Definition: IIODataManager.h:55
compareRootHistos.ref
string ref
Definition: compareRootHistos.py:28
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:203
Gaudi::RootDataConnection::makeRef
void makeRef(const IRegistry &pA, RootRef &ref)
Create reference object from registry entry.
Definition: RootDataConnection.cpp:606
ROOT_StorageType
const long ROOT_StorageType
Definition: ClassID.h:62
Gaudi::RootDataConnection::m_tool
std::unique_ptr< Tool > m_tool
Definition: RootDataConnection.h:242
Gaudi::RootDataConnection::m_conts
StringVec m_conts
Map containing external container names.
Definition: RootDataConnection.h:170
Gaudi::IDataConnection::m_fid
std::string m_fid
File ID of the connection.
Definition: IIODataManager.h:39
MsgStream
Definition: MsgStream.h:34
IOTest.end
def end
Definition: IOTest.py:128
Gaudi::PoolTool
Definition: PoolTool.h:27
Gaudi::IDataConnection::m_age
int m_age
Age counter.
Definition: IIODataManager.h:43
GaudiPluginService.cpluginsvc.n
n
Definition: cpluginsvc.py:235
std::string::append
T append(T... args)
StatusCode::ignore
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
Definition: StatusCode.h:139
IRegistry::address
virtual IOpaqueAddress * address() const =0
Retrieve opaque storage address.
std::vector::emplace_back
T emplace_back(T... args)
MSG::VERBOSE
@ VERBOSE
Definition: IMessageSvc.h:25
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
POOL_ROOTTREE_StorageType
const long POOL_ROOTTREE_StorageType
Definition: ClassID.h:80
std::vector::begin
T begin(T... args)
std::set::insert
T insert(T... args)
Gaudi::RootDataConnection::getSection
TTree * getSection(std::string_view sect, bool create=false)
Access TTree section from section name. The section is created if required.
Definition: RootDataConnection.cpp:373
MSG::ERROR
@ ERROR
Definition: IMessageSvc.h:25
DataObject
Definition: DataObject.h:40
Gaudi::IDataConnection::fid
const std::string & fid() const
Access file id.
Definition: IIODataManager.h:63
std::string::empty
T empty(T... args)
Gaudi::IDataConnection::owner
const IInterface * owner() const
Owner instance.
Definition: IIODataManager.h:75
Gaudi::RootDataConnection::m_links
StringVec m_links
Map containing internal links names.
Definition: RootDataConnection.h:172
Gaudi::RootDataConnection::StringVec
std::vector< std::string > StringVec
Type definition for string maps.
Definition: RootDataConnection.h:139
Gaudi::Utils::Histos::fill
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:45
std::map::end
T end(T... args)
Gaudi::IDataConnection::m_pfn
std::string m_pfn
Physical file name of the connection.
Definition: IIODataManager.h:41
Gaudi::IDataConnection::pfn
const std::string & pfn() const
Access physical file name.
Definition: IIODataManager.h:65
Gaudi::RootDataConnection::addClient
void addClient(const IInterface *client)
Add new client to this data source.
Definition: RootDataConnection.cpp:184
Gaudi::RootDataConnection::makeTool
Tool * makeTool()
Create file access tool to encapsulate POOL compatibiliy.
Definition: RootDataConnection.cpp:228
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
Gaudi::RootDataConnection::empty
const std::string & empty() const
Empty string reference.
Definition: RootDataConnection.cpp:473
IIncidentSvc
Definition: IIncidentSvc.h:33
Gaudi::RootDataConnection::m_sections
Sections m_sections
Tree sections in TFile.
Definition: RootDataConnection.h:166
Gaudi::RootDataConnection::getBranch
TBranch * getBranch(std::string_view section, std::string_view branch_name)
Access data branch by name: Get existing branch in read only mode.
Definition: RootDataConnection.h:313
Incident
Definition: Incident.h:27
DataObject::clID
virtual const CLID & clID() const
Retrieve reference to class definition structure.
Definition: DataObject.cpp:67
Gaudi::RootConnectionSetup::compression
static int compression()
Access to global compression level.
Definition: RootDataConnection.cpp:160
Gaudi::RootDataConnection::msgSvc
MsgStream & msgSvc() const
Allow access to printer service.
Definition: RootDataConnection.h:154
Gaudi::RootDataConnection::m_refs
TTree * m_refs
Pointer to the reference tree.
Definition: RootDataConnection.h:164
GaudiPython.Persistency.add
def add(instance)
Definition: Persistency.py:49