The Gaudi Framework  v30r3 (a5ef0a68)
RootDataConnection.cpp
Go to the documentation of this file.
1 //====================================================================
2 // RootDataConnection.cpp
3 //--------------------------------------------------------------------
4 //
5 // Author : M.Frank
6 //====================================================================
7 
8 // Framework include files
10 #include "GaudiKernel/DataObject.h"
13 #include "GaudiKernel/IRegistry.h"
14 #include "GaudiKernel/Incident.h"
16 #include "GaudiKernel/MsgStream.h"
17 #include "GaudiKernel/strcasecmp.h"
18 #include "RootUtils.h"
19 // ROOT include files
20 #include "TBranch.h"
21 #include "TClass.h"
22 #include "TFile.h"
23 #include "TLeaf.h"
24 #include "TROOT.h"
25 #include "TTree.h"
26 #if ROOT_VERSION_CODE >= ROOT_VERSION( 5, 33, 0 )
27 #include "Compression.h"
28 static int s_compressionLevel = ROOT::CompressionSettings( ROOT::kLZMA, 4 );
29 #else
30 static int s_compressionLevel = 1;
31 #endif
32 
33 // C/C++ include files
34 #include <numeric>
35 #include <stdexcept>
36 
37 using namespace Gaudi;
38 using namespace std;
39 typedef const string& CSTR;
40 
41 static const string s_empty;
42 static const string s_local = "<localDB>";
43 
44 #ifdef __POOL_COMPATIBILITY
45 #include "PoolTool.h"
46 #endif
47 #include "RootTool.h"
48 
49 namespace
50 {
51  std::array<char, 256> init_table()
52  {
54  std::iota( std::begin( table ), std::end( table ), 0 );
55  return table;
56  }
57 
58  struct RootDataConnectionCategory : StatusCode::Category {
59  const char* name() const override { return "RootDataConnection"; }
60 
61  bool isRecoverable( StatusCode::code_t ) const override { return false; }
62 
63  std::string message( StatusCode::code_t code ) const override
64  {
65  switch ( static_cast<RootDataConnection::Status>( code ) ) {
66  case RootDataConnection::Status::ROOT_READ_ERROR:
67  return "ROOT_READ_ERROR";
68  case RootDataConnection::Status::ROOT_OPEN_ERROR:
69  return "ROOT_OPEN_ERROR";
70  default:
71  return StatusCode::default_category().message( code );
72  }
73  }
74  };
75 
76  static bool match_wild( const char* str, const char* pat )
77  {
78  //
79  // Credits: Code from Alessandro Felice Cantatore.
80  //
81  static const auto table = init_table();
82  const char * s, *p;
83  bool star = false;
84  loopStart:
85  for ( s = str, p = pat; *s; ++s, ++p ) {
86  switch ( *p ) {
87  case '?':
88  if ( *s == '.' ) goto starCheck;
89  break;
90  case '*':
91  star = true;
92  str = s, pat = p;
93  do {
94  ++pat;
95  } while ( *pat == '*' );
96  if ( !*pat ) return true;
97  goto loopStart;
98  default:
99  if ( table[*s] != table[*p] ) goto starCheck;
100  break;
101  } /* endswitch */
102  } /* endfor */
103  while ( *p == '*' ) ++p;
104  return ( !*p );
105 
106  starCheck:
107  if ( !star ) return false;
108  str++;
109  goto loopStart;
110  }
111 }
112 
113 STATUSCODE_ENUM_IMPL( Gaudi::RootDataConnection::Status, RootDataConnectionCategory )
114 
115 StatusCode RootConnectionSetup::setCompression( boost::string_ref compression )
117 {
118 #if ROOT_VERSION_CODE >= ROOT_VERSION( 5, 33, 0 )
119  int res = 0, level = ROOT::CompressionSettings( ROOT::kLZMA, 6 );
120  auto idx = compression.find( ':' );
121  if ( idx != string::npos ) {
122  auto alg = compression.substr( 0, idx );
123  ROOT::ECompressionAlgorithm alg_code = ROOT::kUseGlobalSetting;
124  if ( alg.size() == 4 && strncasecmp( alg.data(), "ZLIB", 4 ) == 0 )
125  alg_code = ROOT::kZLIB;
126  else if ( alg.size() == 4 && strncasecmp( alg.data(), "LZMA", 4 ) == 0 )
127  alg_code = ROOT::kLZMA;
128  else
129  throw runtime_error( "ERROR: request to set unknown ROOT compression algorithm:" + alg.to_string() );
130  res = ::sscanf( compression.substr( idx + 1 ).to_string().c_str(), "%d",
131  &level ); // TODO: use C++17 std::from_chars instead...
132  if ( res == 1 ) {
133  s_compressionLevel = ROOT::CompressionSettings( alg_code, level );
134  return StatusCode::SUCCESS;
135  }
136  throw runtime_error( "ERROR: request to set unknown ROOT compression level:" +
137  compression.substr( idx + 1 ).to_string() );
138  } else if ( 1 ==
139  ::sscanf( compression.to_string().c_str(), "%d", &level ) ) { // TODO: use C++17 std::from_chars instead
140  s_compressionLevel = level;
141  return StatusCode::SUCCESS;
142  }
143  throw runtime_error( "ERROR: request to set unknown ROOT compression mechanism:" + compression.to_string() );
144 #else
145  if ( !compression.empty() ) {
146  }
147  return StatusCode::SUCCESS;
148 #endif
149 }
150 
152 int RootConnectionSetup::compression() { return s_compressionLevel; }
153 
155 void RootConnectionSetup::setMessageSvc( MsgStream* m ) { m_msgSvc.reset( m ); }
156 
158 void RootConnectionSetup::setIncidentSvc( IIncidentSvc* s ) { m_incidentSvc.reset( s ); }
159 
161 RootDataConnection::RootDataConnection( const IInterface* owner, boost::string_ref fname,
163  : IDataConnection( owner, fname.to_string() ), m_setup( std::move( setup ) )
164 { // 01234567890123456789012345678901234567890
165  // Check if FID: A82A3BD8-7ECB-DC11-8DC0-000423D950B0
166  if ( fname.size() == 36 && fname[8] == '-' && fname[13] == '-' && fname[18] == '-' && fname[23] == '-' ) {
167  m_name = "FID:";
168  m_name.append( fname.data(), fname.size() );
169  }
170  m_age = 0;
171  m_file.reset();
172  addClient( owner );
173 }
174 
176 void RootDataConnection::addClient( const IInterface* client ) { m_clients.insert( client ); }
177 
180 {
181  auto i = m_clients.find( client );
182  if ( i != m_clients.end() ) m_clients.erase( i );
183  return m_clients.size();
184 }
185 
187 bool RootDataConnection::lookupClient( const IInterface* client ) const
188 {
189  auto i = m_clients.find( client );
190  return i != m_clients.end();
191 }
192 
194 void RootDataConnection::badWriteError( boost::string_ref msg ) const
195 {
196  msgSvc() << MSG::ERROR << "File:" << fid() << "Failed action:" << msg << endmsg;
197 }
198 
200 void RootDataConnection::saveStatistics( boost::string_ref statisticsFile )
201 {
202  if ( m_statistics ) {
203  m_statistics->Print();
204  if ( !statisticsFile.empty() ) m_statistics->SaveAs( statisticsFile.to_string().c_str() );
206  }
207 }
208 
210 void RootDataConnection::enableStatistics( boost::string_ref section )
211 {
212  if ( m_statistics ) {
213  TTree* t = getSection( section, false );
214  if ( t ) {
215  m_statistics.reset( new TTreePerfStats( ( section.to_string() + "_ioperf" ).c_str(), t ) );
216  return;
217  }
218  msgSvc() << MSG::WARNING << "Failed to enable perfstats for tree:" << section << endmsg;
219  return;
220  }
221  msgSvc() << MSG::INFO << "Perfstats are ALREADY ENABLED." << endmsg;
222 }
223 
226 {
227  if ( !m_refs ) m_refs = (TTree*)m_file->Get( "Refs" );
228  if ( m_refs ) m_tool.reset( new RootTool( this ) );
229 #ifdef __POOL_COMPATIBILITY
230  else if ( m_file->Get( "##Links" ) != nullptr )
231  m_tool.reset( new PoolTool( this ) );
232 #endif
233  else
234  m_tool.reset();
235  return m_tool.get();
236 }
237 
240 {
241  m_file.reset( TFile::Open( m_pfn.c_str() ) );
242  if ( !m_file || m_file->IsZombie() ) {
243  m_file.reset();
244  return StatusCode::FAILURE;
245  }
247  msgSvc() << MSG::DEBUG << "Opened file " << m_pfn << " in mode READ. [" << m_fid << "]" << endmsg << MSG::DEBUG;
248  if ( msgSvc().isActive() ) m_file->ls();
249  msgSvc() << MSG::VERBOSE;
250  if ( msgSvc().isActive() ) m_file->Print();
251  if ( makeTool() ) {
252  sc = m_tool->readRefs();
253  sc.ignore();
254 #if ROOT_VERSION_CODE >= ROOT_VERSION( 5, 33, 0 )
255  if ( sc == Status::ROOT_READ_ERROR ) {
256  IIncidentSvc* inc = m_setup->incidentSvc();
257  if ( inc ) {
258  inc->fireIncident( Incident( pfn(), IncidentType::CorruptedInputFile ) );
259  }
260  }
261 #endif
262  }
263  if ( !sc.isSuccess() ) return sc;
264  bool need_fid = m_fid == m_pfn;
265  string fid = m_fid;
266  m_mergeFIDs.clear();
267  for ( auto& elem : m_params ) {
268  if ( elem.first == "FID" ) {
269  m_mergeFIDs.push_back( elem.second );
270  if ( elem.second != m_fid ) {
271  msgSvc() << MSG::DEBUG << "Check FID param:" << elem.second << endmsg;
272  // if ( m_fid == m_pfn ) {
273  m_fid = elem.second;
274  //}
275  }
276  }
277  }
278  if ( !need_fid && fid != m_fid ) {
279  msgSvc() << MSG::ERROR << "FID mismatch:" << fid << "(Catalog) != " << m_fid << "(file)" << endmsg
280  << "for PFN:" << m_pfn << endmsg;
281  return StatusCode::FAILURE;
282  }
283  msgSvc() << MSG::DEBUG << "Using FID " << m_fid << " from params table...." << endmsg << "for PFN:" << m_pfn
284  << endmsg;
285  return sc;
286 }
287 
290 {
291  int compress = RootConnectionSetup::compression();
292  msgSvc() << MSG::DEBUG;
293  switch ( typ ) {
294  case CREATE:
295  resetAge();
296  m_file.reset( TFile::Open( m_pfn.c_str(), "CREATE", "Root event data", compress ) );
297  m_refs = new TTree( "Refs", "Root reference data" );
298  msgSvc() << "Opened file " << m_pfn << " in mode CREATE. [" << m_fid << "]" << endmsg;
299  m_params.emplace_back( "PFN", m_pfn );
300  if ( m_fid != m_pfn ) {
301  m_params.emplace_back( "FID", m_fid );
302  }
303  makeTool();
304  break;
305  case RECREATE:
306  resetAge();
307  m_file.reset( TFile::Open( m_pfn.c_str(), "RECREATE", "Root event data", compress ) );
308  msgSvc() << "Opened file " << m_pfn << " in mode RECREATE. [" << m_fid << "]" << endmsg;
309  m_refs = new TTree( "Refs", "Root reference data" );
310  m_params.emplace_back( "PFN", m_pfn );
311  if ( m_fid != m_pfn ) {
312  m_params.emplace_back( "FID", m_fid );
313  }
314  makeTool();
315  break;
316  case UPDATE:
317  resetAge();
318  m_file.reset( TFile::Open( m_pfn.c_str(), "UPDATE", "Root event data", compress ) );
319  msgSvc() << "Opened file " << m_pfn << " in mode UPDATE. [" << m_fid << "]" << endmsg;
320  if ( m_file && !m_file->IsZombie() ) {
321  if ( makeTool() ) {
322  StatusCode sc = m_tool->readRefs();
323  sc.ignore();
324  if ( sc == Status::ROOT_READ_ERROR ) {
325 #if ROOT_VERSION_CODE >= ROOT_VERSION( 5, 33, 0 )
326  IIncidentSvc* inc = m_setup->incidentSvc();
327  if ( inc ) {
328  inc->fireIncident( Incident( pfn(), IncidentType::CorruptedInputFile ) );
329  }
330 #endif
331  }
332  return sc;
333  }
334  TDirectory::TContext ctxt( m_file.get() );
335  m_refs = new TTree( "Refs", "Root reference data" );
336  makeTool();
337  return StatusCode::SUCCESS;
338  }
339  break;
340  default:
341  m_refs = nullptr;
342  m_file.reset();
343  return StatusCode::FAILURE;
344  }
346 }
347 
350 {
351  if ( m_file ) {
352  if ( !m_file->IsZombie() ) {
353  if ( m_file->IsWritable() ) {
354  msgSvc() << MSG::DEBUG;
355  TDirectory::TContext ctxt( m_file.get() );
356  if ( m_refs ) {
357  if ( !m_tool->saveRefs().isSuccess() ) badWriteError( "Saving References" );
358  if ( m_refs->Write() < 0 ) badWriteError( "Write Reference branch" );
359  }
360  for ( auto& i : m_sections ) {
361  if ( i.second ) {
362  if ( i.second->Write() < 0 ) badWriteError( "Write section:" + i.first );
363  msgSvc() << "Disconnect section " << i.first << " " << i.second->GetName() << endmsg;
364  }
365  }
366  m_sections.clear();
367  }
368  msgSvc() << MSG::DEBUG;
369  if ( msgSvc().isActive() ) m_file->ls();
370  msgSvc() << MSG::VERBOSE;
371  if ( msgSvc().isActive() ) m_file->Print();
372  m_file->Close();
373  }
374  msgSvc() << MSG::DEBUG << "Disconnected file " << m_pfn << " " << m_file->GetName() << endmsg;
375  m_file.reset();
376  m_tool.reset();
377  }
378  return StatusCode::SUCCESS;
379 }
380 
382 TTree* RootDataConnection::getSection( boost::string_ref section, bool create )
383 {
384  auto it = m_sections.find( section );
385  TTree* t = ( it != m_sections.end() ? it->second : nullptr );
386  if ( !t ) {
387  t = (TTree*)m_file->Get( section.to_string().c_str() );
388  if ( !t && create ) {
389  TDirectory::TContext ctxt( m_file.get() );
390  t = new TTree( section.to_string().c_str(), "Root data for Gaudi" );
391  }
392  if ( t ) {
393  int cacheSize = m_setup->cacheSize;
394  if ( create ) {
395  // t->SetAutoFlush(100);
396  }
397  if ( section == m_setup->loadSection && cacheSize > -2 ) {
398  MsgStream& msg = msgSvc();
399  int learnEntries = m_setup->learnEntries;
400  t->SetCacheSize( cacheSize );
401  t->SetCacheLearnEntries( learnEntries );
402  msg << MSG::DEBUG;
403  if ( create ) {
404  msg << "Tree:" << section << "Setting up tree cache:" << cacheSize << endmsg;
405  } else {
406  const StringVec& vB = m_setup->vetoBranches;
407  const StringVec& cB = m_setup->cacheBranches;
408  msg << "Tree:" << section << " Setting up tree cache:" << cacheSize << " Add all branches." << endmsg;
409  msg << "Tree:" << section << " Learn for " << learnEntries << " entries." << endmsg;
410 
411  if ( cB.empty() && vB.empty() ) {
412  msg << "Adding (default) all branches to tree cache." << endmsg;
413  t->AddBranchToCache( "*", kTRUE );
414  }
415  if ( cB.size() == 1 && cB[0] == "*" ) {
416  msg << "Adding all branches to tree cache according to option \"CacheBranches\"." << endmsg;
417  t->AddBranchToCache( "*", kTRUE );
418  } else {
419  for ( TIter it( t->GetListOfBranches() ); it.Next(); ) {
420  const char* n = ( (TNamed*)( *it ) )->GetName();
421  bool add = false, veto = false;
422  for ( const auto& i : cB ) {
423  if ( !match_wild( n, ( i ).c_str() ) ) continue;
424  add = true;
425  break;
426  }
427  for ( auto i = vB.cbegin(); !add && i != vB.cend(); ++i ) {
428  if ( !match_wild( n, ( *i ).c_str() ) ) continue;
429  veto = true;
430  break;
431  }
432  if ( add && !veto ) {
433  msg << "Add " << n << " to branch cache." << endmsg;
434  t->AddBranchToCache( n, kTRUE );
435  } else {
436  msg << "Do not cache branch " << n << endmsg;
437  }
438  }
439  }
440  }
441  }
442  m_sections[section.to_string()] = t;
443  }
444  }
445  return t;
446 }
447 
449 TBranch* RootDataConnection::getBranch( boost::string_ref section, boost::string_ref branch_name, TClass* cl, void* ptr,
450  int buff_siz, int split_lvl )
451 {
452  string n = branch_name.to_string();
453  std::replace_if( begin( n ), end( n ), []( const char c ) { return !isalnum( c ); }, '_' );
454  n += ".";
455  TTree* t = getSection( section, true );
456  TBranch* b = t->GetBranch( n.c_str() );
457  if ( !b && cl && m_file->IsWritable() ) {
458  b = t->Branch( n.c_str(), cl->GetName(), (void*)( ptr ? &ptr : nullptr ), buff_siz, split_lvl );
459  }
460  if ( !b ) b = t->GetBranch( branch_name.to_string().c_str() );
461  if ( b ) b->SetAutoDelete( kFALSE );
462  return b;
463 }
464 
466 int RootDataConnection::makeLink( boost::string_ref p )
467 {
468  auto ip = std::find( std::begin( m_links ), std::end( m_links ), p );
469  if ( ip != std::end( m_links ) ) return std::distance( std::begin( m_links ), ip );
470  m_links.push_back( p.to_string() );
471  return m_links.size() - 1;
472 }
473 
476 {
477  if ( ( which >= 0 ) && ( size_t( which ) < m_dbs.size() ) ) {
478  if ( *( m_dbs.begin() + which ) == s_local ) return m_fid;
479  return *( m_dbs.begin() + which );
480  }
481  return s_empty;
482 }
483 
485 CSTR RootDataConnection::empty() const { return s_empty; }
486 
488 pair<int, unsigned long> RootDataConnection::saveObj( boost::string_ref section, boost::string_ref cnt, TClass* cl,
489  DataObject* pObj, int buff_siz, int split_lvl, bool fill )
490 {
491  DataObjectPush push( pObj );
492  return save( section, cnt, cl, pObj, buff_siz, split_lvl, fill );
493 }
494 
496 pair<int, unsigned long> RootDataConnection::save( boost::string_ref section, boost::string_ref cnt, TClass* cl,
497  void* pObj, int buff_siz, int split_lvl, bool fill_missing )
498 {
499  split_lvl = 0;
500  TBranch* b = getBranch( section, cnt, cl, pObj ? &pObj : nullptr, buff_siz, split_lvl );
501  if ( b ) {
502  Long64_t evt = b->GetEntries();
503  // msgSvc() << MSG::DEBUG << cnt.c_str() << " Obj:" << (void*)pObj
504  // << " Split:" << split_lvl << " Buffer size:" << buff_siz << endl;
505  if ( fill_missing ) {
506  Long64_t num, nevt = b->GetTree()->GetEntries();
507  if ( nevt > evt ) {
508  b->SetAddress( nullptr );
509  num = nevt - evt;
510  while ( num > 0 ) {
511  b->Fill();
512  --num;
513  }
514  msgSvc() << MSG::DEBUG << "Added " << long( nevt - evt ) << " / Tree: " << nevt
515  << " / Branch: " << b->GetEntries() + 1 << " NULL entries to:" << cnt << endmsg;
516  evt = b->GetEntries();
517  }
518  }
519  b->SetAddress( &pObj );
520  return {b->Fill(), evt};
521  }
522  if ( pObj ) {
523  msgSvc() << MSG::ERROR << "Failed to access branch " << m_name << "/" << cnt << endmsg;
524  }
525  return {-1, ~0};
526 }
527 
529 int RootDataConnection::loadObj( boost::string_ref section, boost::string_ref cnt, unsigned long entry,
530  DataObject*& pObj )
531 {
532  TBranch* b = getBranch( section, cnt );
533  if ( b ) {
534  TClass* cl = gROOT->GetClass( b->GetClassName(), kTRUE );
535  if ( cl ) {
536  int nb = -1;
537  pObj = (DataObject*)cl->New();
538  {
539  DataObjectPush push( pObj );
540  b->SetAddress( &pObj );
541  if ( section == m_setup->loadSection ) {
542  TTree* t = b->GetTree();
543  if ( Long64_t( entry ) != t->GetReadEntry() ) {
544  t->LoadTree( Long64_t( entry ) );
545  }
546  }
547  nb = b->GetEntry( entry );
548  msgSvc() << MSG::VERBOSE;
549  if ( msgSvc().isActive() ) {
550  msgSvc() << "Load [" << entry << "] --> " << section << ":" << cnt << " " << nb << " bytes." << endmsg;
551  }
552  if ( nb < 0 ) { // This is definitely an error...ROOT says if reads fail, -1 is issued.
553 #if ROOT_VERSION_CODE >= ROOT_VERSION( 5, 33, 0 )
554  IIncidentSvc* inc = m_setup->incidentSvc();
555  if ( inc ) {
556  inc->fireIncident( Incident( pfn(), IncidentType::CorruptedInputFile ) );
557  }
558 #endif
559  } else if ( nb == 0 && pObj->clID() == CLID_DataObject ) {
560  TFile* f = b->GetFile();
561  int vsn = f->GetVersion();
562  if ( vsn < 52400 ) {
563  // For Gaudi v21r5 (ROOT 5.24.00b) DataObject::m_version was not written!
564  // Still this call be well be successful.
565  nb = 1;
566  } else if ( vsn > 1000000 && ( vsn % 1000000 ) < 52400 ) {
567  // dto. Some POOL files have for unknown reasons a version
568  // not according to ROOT standards. Hack this explicitly.
569  nb = 1;
570  }
571  }
572  if ( nb < 0 ) {
573  delete pObj;
574  pObj = nullptr;
575  }
576  }
577  return nb;
578  }
579  }
580  return -1;
581 }
582 
584 int RootDataConnection::loadRefs( boost::string_ref section, boost::string_ref cnt, unsigned long entry,
585  RootObjectRefs& refs )
586 {
587  int nbytes = m_tool->loadRefs( section, cnt, entry, refs );
588 #if ROOT_VERSION_CODE >= ROOT_VERSION( 5, 33, 0 )
589  if ( nbytes < 0 ) {
590  // This is definitely an error:
591  // -- Either branch not preesent at all or
592  // -- ROOT I/O error, which issues -1
593  IIncidentSvc* inc = m_setup->incidentSvc();
594  if ( inc ) {
595  inc->fireIncident( Incident( pfn(), IncidentType::CorruptedInputFile ) );
596  }
597  }
598 #endif
599  return nbytes;
600 }
601 
604 RootDataConnection::getMergeSection( boost::string_ref container, int entry ) const
605 {
606  // size_t idx = cont.find('/',1);
607  // string container = cont[0]=='/' ? cont.substr(1,idx==string::npos?idx:idx-1) : cont;
608  auto i = m_mergeSects.find( container );
609  if ( i != m_mergeSects.end() ) {
610  size_t cnt = 0;
611  const ContainerSections& s = ( *i ).second;
612  for ( auto j = s.cbegin(); j != s.cend(); ++j, ++cnt ) {
613  const ContainerSection& c = *j;
614  if ( entry >= c.start && entry < ( c.start + c.length ) ) {
615  if ( m_linkSects.size() > cnt ) {
616  if ( msgSvc().isActive() ) {
617  msgSvc() << MSG::VERBOSE << "MergeSection for:" << container << " [" << entry << "]" << endmsg
618  << "FID:" << m_fid << " -> PFN:" << m_pfn << endmsg;
619  }
620  return {&( m_linkSects[cnt] ), &c};
621  }
622  }
623  }
624  }
625  msgSvc() << MSG::DEBUG << "Return INVALID MergeSection for:" << container << " [" << entry << "]" << endmsg
626  << "FID:" << m_fid << " -> PFN:" << m_pfn << endmsg;
627  return {nullptr, nullptr};
628 }
629 
632 {
633  IOpaqueAddress* pA = pR.address();
634  makeRef( pR.name(), pA->clID(), pA->svcType(), pA->par()[0], pA->par()[1], -1, ref );
635 }
636 
638 void RootDataConnection::makeRef( boost::string_ref name, long clid, int tech, boost::string_ref dbase,
639  boost::string_ref cnt, int entry, RootRef& ref )
640 {
641  auto db = ( dbase == m_fid ? boost::string_ref{s_local} : dbase );
642  ref.entry = entry;
643 
644  int cdb = -1;
645  if ( !db.empty() ) {
646  auto idb = std::find_if( m_dbs.begin(), m_dbs.end(), [&]( const std::string& i ) { return i == db; } );
647  cdb = std::distance( m_dbs.begin(), idb );
648  if ( idb == m_dbs.end() ) m_dbs.push_back( db.to_string() );
649  }
650 
651  int ccnt = -1;
652  if ( !cnt.empty() ) {
653  auto icnt = std::find_if( m_conts.begin(), m_conts.end(), [&]( const std::string& i ) { return i == cnt; } );
654  ccnt = std::distance( m_conts.begin(), icnt );
655  if ( icnt == m_conts.end() ) m_conts.push_back( cnt.to_string() );
656  }
657 
658  int clnk = -1;
659  if ( !name.empty() ) {
660  auto ilnk = std::find_if( m_links.begin(), m_links.end(), [&]( const std::string& i ) { return i == name; } );
661  clnk = std::distance( m_links.begin(), ilnk );
662  if ( ilnk == m_links.end() ) m_links.push_back( name.to_string() );
663  }
664 
665  ref.dbase = cdb;
666  ref.container = ccnt;
667  ref.link = clnk;
668  ref.clid = clid;
669  ref.svc = tech;
670  if ( ref.svc == POOL_ROOT_StorageType || ref.svc == POOL_ROOTKEY_StorageType ||
671  ref.svc == POOL_ROOTTREE_StorageType ) {
672  ref.svc = ROOT_StorageType;
673  }
674 }
void addClient(const IInterface *client)
Add new client to this data source.
bool lookupClient(const IInterface *client) const
Lookup client for this data source.
constexpr static const auto FAILURE
Definition: StatusCode.h:88
std::pair< int, unsigned long > saveObj(boost::string_ref section, boost::string_ref 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.
MergeSections m_mergeSects
Database section map for merged files.
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
T empty(T...args)
T distance(T...args)
virtual const CLID & clID() const =0
Retrieve class information from link.
int m_age
Age counter.
const std::string & fid() const
Access file id.
std::unique_ptr< Tool > m_tool
std::string m_name
Connection name/identifier.
IoType
I/O Connection types.
T sscanf(T...args)
const std::string & getDb(int which) const
Access database/file name from saved index.
int loadRefs(boost::string_ref section, boost::string_ref cnt, unsigned long entry, RootObjectRefs &refs)
Load references object.
std::string m_fid
File ID of the connection.
bool isSuccess() const
Definition: StatusCode.h:287
The category assigned to a StatusCode.
Definition: StatusCode.h:65
std::unique_ptr< TTreePerfStats > m_statistics
I/O read statistics from TTree.
int makeLink(boost::string_ref p)
Convert path string to path index.
T isalnum(T...args)
static int compression()
Access to global compression level.
Clients m_clients
Client list.
T to_string(T...args)
int start
The start entry of the section.
size_t removeClient(const IInterface *client)
Remove client from this data source.
bool isActive() const
Accessor: is MsgStream active.
Definition: MsgStream.h:116
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:35
STL namespace.
virtual const name_type & name() const =0
Name of the directory (or key)
T end(T...args)
T iota(T...args)
void setMessageSvc(MsgStream *m)
Set message service reference.
StatusCode connectWrite(IoType typ) override
Open data stream in write mode.
virtual const std::string * par() const =0
Retrieve String parameters.
const std::string & pfn() const
Access physical file name.
Persistent reference object containing all leafs and links corresponding to a Gaudi DataObject...
Definition: RootRefs.h:60
StringVec m_links
Map containing internal links names.
void saveStatistics(boost::string_ref statisticsFile)
Save TTree access statistics if required.
ParamMap m_params
Parameter map for file parameters.
STL class.
const long POOL_ROOTKEY_StorageType
Definition: ClassID.h:69
const string & CSTR
StringVec m_mergeFIDs
Map containing merge FIDs.
std::string m_pfn
Physical file name of the connection.
int dbase
Data members to define object location in the persistent world.
Definition: RootRefs.h:33
Persistent reference object.
Definition: RootRefs.h:31
T push_back(T...args)
virtual void fireIncident(const Incident &incident)=0
Fire an Incident.
Description:
Definition: RootTool.h:17
virtual const CLID & clID() const
Retrieve reference to class definition structure.
Definition: DataObject.cpp:62
const std::string & name() const
Connection name.
T replace_if(T...args)
std::pair< int, unsigned long > save(boost::string_ref section, boost::string_ref 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.
void enableStatistics(boost::string_ref section)
Enable TTreePerStats.
Helper class to facilitate an abstraction layer for reading POOL style files with this package...
#define STATUSCODE_ENUM_IMPL(...)
Assign a category to the StatusCode enum declared with STATUSCODE_ENUM_DECL( ENUM ) ...
Definition: StatusCode.h:267
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
constexpr double m
Definition: SystemOfUnits.h:94
void clear(STATE_TYPE _i=std::ios_base::failbit)
Definition: MsgStream.h:187
T append(T...args)
Definition of the basic interface.
Definition: IInterface.h:277
static const Category & default_category() noexcept
Default Gaudi StatusCode category.
Definition: StatusCode.h:282
T erase(T...args)
int loadObj(boost::string_ref section, boost::string_ref cnt, unsigned long entry, DataObject *&pObj)
Load object.
static StatusCode setCompression(boost::string_ref compression)
Set the global compression level.
void badWriteError(boost::string_ref msg) const
Error handler when bad write statements occur.
StringVec m_conts
Map containing external container names.
TTree * getSection(boost::string_ref sect, bool create=false)
Access TTree section from section name. The section is created if required.
const std::string & empty() const
Empty string reference.
Sections m_sections
Tree sections in TFile.
The IRegistry represents the entry door to the environment any data object residing in a transient da...
Definition: IRegistry.h:22
const long ROOT_StorageType
Definition: ClassID.h:52
virtual long svcType() const =0
Retrieve service type.
T reset(T...args)
T clear(T...args)
const long POOL_ROOT_StorageType
Definition: ClassID.h:68
Tool * makeTool()
Create file access tool to encapsulate POOL compatibiliy.
T move(T...args)
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
T get(T...args)
T insert(T...args)
TBranch * getBranch(boost::string_ref section, boost::string_ref branch_name)
Access data branch by name: Get existing branch in read only mode.
T find(T...args)
T size(T...args)
StatusCode connectRead() override
Open data stream in read mode.
ABC describing basic data connection.
const long POOL_ROOTTREE_StorageType
Definition: ClassID.h:70
std::shared_ptr< RootConnectionSetup > m_setup
Reference to the setup structure.
T begin(T...args)
LinkSections m_linkSects
Database link sections.
def which(executable)
Definition: BaseTest.py:571
void resetAge()
Reset age.
const StatusCode & ignore() const
Ignore/check StatusCode.
Definition: StatusCode.h:165
T c_str(T...args)
Base class for all Incidents (computing events).
Definition: Incident.h:17
MsgStream & msgSvc() const
Allow access to printer service.
string s
Definition: gaudirun.py:253
STL class.
void makeRef(const IRegistry &pA, RootRef &ref)
Create reference object from registry entry.
AttribStringParser::Iterator begin(const AttribStringParser &parser)
std::unique_ptr< TFile > m_file
Reference to ROOT file.
Opaque address interface definition.
StringVec m_dbs
Map containing external database file names (fids)
StatusCode disconnect() override
Release data stream and release implementation dependent resources.
std::pair< const RootRef *, const ContainerSection * > getMergeSection(boost::string_ref container, int entry) const
Access link section for single container and entry.
void setIncidentSvc(IIncidentSvc *m)
Set incident service reference.
virtual IOpaqueAddress * address() const =0
Retrieve opaque storage address.
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
TTree * m_refs
Pointer to the reference tree.
virtual std::string message(code_t code) const
Description for code within this category.
Definition: StatusCode.h:73
Helper functions to set/get the application return code.
Definition: __init__.py:1
Internal helper class, which described a TBranch section in a ROOT file.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
The interface implemented by the IncidentSvc service.
Definition: IIncidentSvc.h:23
RootDataConnection(const IInterface *own, boost::string_ref nam, std::shared_ptr< RootConnectionSetup > setup)
Standard constructor.
evt
Definition: IOTest.py:96
unsigned long code_t
type of StatusCode value
Definition: StatusCode.h:54
T emplace_back(T...args)