The Gaudi Framework  v36r1 (3e2fb5a8)
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 163 of file RootDataConnection.cpp.

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

Member Function Documentation

◆ addClient()

void RootDataConnection::addClient ( const IInterface client)

Add new client to this data source.

Definition at line 178 of file RootDataConnection.cpp.

178 { m_clients.insert( client ); }

◆ badWriteError()

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

Error handler when bad write statements occur.

Definition at line 194 of file RootDataConnection.cpp.

194  {
195  msgSvc() << MSG::ERROR << "File:" << fid() << "Failed action:" << msg << endmsg;
196 }

◆ connectRead()

StatusCode RootDataConnection::connectRead ( )
overridevirtual

Open data stream in read mode.

Connect the file in READ mode.

Implements Gaudi::IDataConnection.

Definition at line 235 of file RootDataConnection.cpp.

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

◆ connectWrite()

StatusCode RootDataConnection::connectWrite ( IoType  typ)
overridevirtual

Open data stream in write mode.

Implements Gaudi::IDataConnection.

Definition at line 282 of file RootDataConnection.cpp.

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

◆ disconnect()

StatusCode RootDataConnection::disconnect ( )
overridevirtual

Release data stream and release implementation dependent resources.

Implements Gaudi::IDataConnection.

Definition at line 335 of file RootDataConnection.cpp.

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

◆ empty()

CSTR RootDataConnection::empty ( ) const
protected

Empty string reference.

Definition at line 467 of file RootDataConnection.cpp.

467 { return s_empty; }

◆ enableStatistics()

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

Enable TTreePerStats.

Definition at line 208 of file RootDataConnection.cpp.

208  {
209  if ( m_statistics ) {
210  TTree* t = getSection( section, false );
211  if ( t ) {
212  m_statistics.reset( new TTreePerfStats( ( std::string{section} + "_ioperf" ).c_str(), t ) );
213  return;
214  }
215  msgSvc() << MSG::WARNING << "Failed to enable perfstats for tree:" << section << endmsg;
216  return;
217  }
218  msgSvc() << MSG::INFO << "Perfstats are ALREADY ENABLED." << endmsg;
219 }

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

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

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

458  {
459  if ( ( which >= 0 ) && ( size_t( which ) < m_dbs.size() ) ) {
460  if ( *( m_dbs.begin() + which ) == s_local ) return m_fid;
461  return *( m_dbs.begin() + which );
462  }
463  return s_empty;
464 }

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

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

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

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

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

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

◆ loadRefs()

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

Load references object.

Definition at line 557 of file RootDataConnection.cpp.

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

◆ lookupClient()

bool RootDataConnection::lookupClient ( const IInterface client) const

Lookup client for this data source.

Definition at line 188 of file RootDataConnection.cpp.

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

◆ makeLink()

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

Convert path string to path index.

Definition at line 450 of file RootDataConnection.cpp.

450  {
451  auto ip = std::find( std::begin( m_links ), std::end( m_links ), p );
452  if ( ip != std::end( m_links ) ) return std::distance( std::begin( m_links ), ip );
454  return m_links.size() - 1;
455 }

◆ makeRef() [1/2]

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

Create reference object from registry entry.

Definition at line 600 of file RootDataConnection.cpp.

600  {
601  IOpaqueAddress* pA = pR.address();
602  makeRef( pR.name(), pA->clID(), pA->svcType(), pA->par()[0], pA->par()[1], -1, ref );
603 }

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

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

◆ makeTool()

RootDataConnection::Tool * RootDataConnection::makeTool ( )

Create file access tool to encapsulate POOL compatibiliy.

Definition at line 222 of file RootDataConnection.cpp.

222  {
223  if ( !m_refs ) m_refs = (TTree*)m_file->Get( "Refs" );
224  if ( m_refs ) m_tool.reset( new RootTool( this ) );
225 #ifdef __POOL_COMPATIBILITY
226  else if ( m_file->Get( "##Links" ) != nullptr )
227  m_tool.reset( new PoolTool( this ) );
228 #endif
229  else
230  m_tool.reset();
231  return m_tool.get();
232 }

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

181  {
182  auto i = m_clients.find( client );
183  if ( i != m_clients.end() ) m_clients.erase( i );
184  return m_clients.size();
185 }

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

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

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

471  {
472  DataObjectPush push( pObj );
473  return save( section, cnt, cl, pObj, buff_siz, split_lvl, fill );
474 }

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

199  {
200  if ( m_statistics ) {
201  m_statistics->Print();
202  if ( !statisticsFile.empty() ) m_statistics->SaveAs( std::string{statisticsFile}.c_str() );
204  }
205 }

◆ 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:105
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:477
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:355
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:194
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:328
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:18
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:509
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:674
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:74
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:25
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:600
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
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:221
std::string::append
T append(T... args)
StatusCode::ignore
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
Definition: StatusCode.h:156
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:367
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)
IOTest.end
end
Definition: IOTest.py:123
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:178
Gaudi::RootDataConnection::makeTool
Tool * makeTool()
Create file access tool to encapsulate POOL compatibiliy.
Definition: RootDataConnection.cpp:222
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:467
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:66
Gaudi::RootConnectionSetup::compression
static int compression()
Access to global compression level.
Definition: RootDataConnection.cpp:154
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