The Gaudi Framework  v36r1 (3e2fb5a8)
RootDataConnection.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 //====================================================================
12 // RootDataConnection.cpp
13 //--------------------------------------------------------------------
14 //
15 // Author : M.Frank
16 //====================================================================
17 
18 // Framework include files
20 #include "GaudiKernel/DataObject.h"
23 #include "GaudiKernel/IRegistry.h"
24 #include "GaudiKernel/Incident.h"
26 #include "GaudiKernel/MsgStream.h"
27 #include "GaudiKernel/strcasecmp.h"
28 #include "RootUtils.h"
29 // ROOT include files
30 #include "TBranch.h"
31 #include "TClass.h"
32 #include "TFile.h"
33 #include "TLeaf.h"
34 #include "TROOT.h"
35 #include "TTree.h"
36 #if ROOT_VERSION_CODE >= ROOT_VERSION( 5, 33, 0 )
37 # include "Compression.h"
38 static int s_compressionLevel = ROOT::CompressionSettings( ROOT::kLZMA, 4 );
39 #else
40 static int s_compressionLevel = 1;
41 #endif
42 
43 // C/C++ include files
44 #include <numeric>
45 #include <stdexcept>
46 
47 using namespace Gaudi;
48 using namespace std;
49 typedef const string& CSTR;
50 
51 static const string s_empty;
52 static const string s_local = "<localDB>";
53 
54 #ifdef __POOL_COMPATIBILITY
55 # include "PoolTool.h"
56 #endif
57 #include "RootTool.h"
58 
59 namespace {
60  std::array<char, 256> init_table() {
62  std::iota( std::begin( table ), std::end( table ), 0 );
63  return table;
64  }
65 
66  struct RootDataConnectionCategory : StatusCode::Category {
67  const char* name() const override { return "RootDataConnection"; }
68 
69  bool isRecoverable( StatusCode::code_t ) const override { return false; }
70 
71  std::string message( StatusCode::code_t code ) const override {
72  switch ( static_cast<RootDataConnection::Status>( code ) ) {
74  return "ROOT_READ_ERROR";
76  return "ROOT_OPEN_ERROR";
77  default:
78  return StatusCode::default_category().message( code );
79  }
80  }
81  };
82 
83  static bool match_wild( const char* str, const char* pat ) {
84  //
85  // Credits: Code from Alessandro Felice Cantatore.
86  //
87  static const auto table = init_table();
88  const char * s, *p;
89  bool star = false;
90  loopStart:
91  for ( s = str, p = pat; *s; ++s, ++p ) {
92  switch ( *p ) {
93  case '?':
94  if ( *s == '.' ) goto starCheck;
95  break;
96  case '*':
97  star = true;
98  str = s, pat = p;
99  do { ++pat; } while ( *pat == '*' );
100  if ( !*pat ) return true;
101  goto loopStart;
102  default:
103  if ( table[*s] != table[*p] ) goto starCheck;
104  break;
105  } /* endswitch */
106  } /* endfor */
107  while ( *p == '*' ) ++p;
108  return ( !*p );
109 
110  starCheck:
111  if ( !star ) return false;
112  str++;
113  goto loopStart;
114  }
115 } // namespace
116 
117 STATUSCODE_ENUM_IMPL( Gaudi::RootDataConnection::Status, RootDataConnectionCategory )
118 
119 StatusCode RootConnectionSetup::setCompression( std::string_view compression ) {
121 #if ROOT_VERSION_CODE >= ROOT_VERSION( 5, 33, 0 )
122  int res = 0, level = ROOT::CompressionSettings( ROOT::kLZMA, 6 );
123  auto idx = compression.find( ':' );
124  if ( idx != string::npos ) {
125  auto alg = compression.substr( 0, idx );
126  ROOT::ECompressionAlgorithm alg_code = ROOT::kUseGlobalSetting;
127  if ( alg.size() == 4 && strncasecmp( alg.data(), "ZLIB", 4 ) == 0 )
128  alg_code = ROOT::kZLIB;
129  else if ( alg.size() == 4 && strncasecmp( alg.data(), "LZMA", 4 ) == 0 )
130  alg_code = ROOT::kLZMA;
131  else
132  throw runtime_error( "ERROR: request to set unknown ROOT compression algorithm:" + std::string{alg} );
133  res = ::sscanf( std::string{compression.substr( idx + 1 )}.c_str(), "%d",
134  &level ); // TODO: use C++17 std::from_chars instead...
135  if ( res == 1 ) {
136  s_compressionLevel = ROOT::CompressionSettings( alg_code, level );
137  return StatusCode::SUCCESS;
138  }
139  throw runtime_error( "ERROR: request to set unknown ROOT compression level:" +
140  std::string{compression.substr( idx + 1 )} );
141  } else if ( 1 == ::sscanf( std::string{compression}.c_str(), "%d", &level ) ) { // TODO: use C++17 std::from_chars
142  // instead
143  s_compressionLevel = level;
144  return StatusCode::SUCCESS;
145  }
146  throw runtime_error( "ERROR: request to set unknown ROOT compression mechanism:" + std::string{compression} );
147 #else
148  if ( !compression.empty() ) {}
149  return StatusCode::SUCCESS;
150 #endif
151 }
152 
154 int RootConnectionSetup::compression() { return s_compressionLevel; }
155 
157 void RootConnectionSetup::setMessageSvc( MsgStream* m ) { m_msgSvc.reset( m ); }
158 
160 void RootConnectionSetup::setIncidentSvc( IIncidentSvc* s ) { m_incidentSvc.reset( s ); }
161 
163 RootDataConnection::RootDataConnection( const IInterface* owner, std::string_view fname,
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 }
176 
178 void RootDataConnection::addClient( const IInterface* client ) { m_clients.insert( client ); }
179 
182  auto i = m_clients.find( client );
183  if ( i != m_clients.end() ) m_clients.erase( i );
184  return m_clients.size();
185 }
186 
188 bool RootDataConnection::lookupClient( const IInterface* client ) const {
189  auto i = m_clients.find( client );
190  return i != m_clients.end();
191 }
192 
194 void RootDataConnection::badWriteError( std::string_view msg ) const {
195  msgSvc() << MSG::ERROR << "File:" << fid() << "Failed action:" << msg << endmsg;
196 }
197 
199 void RootDataConnection::saveStatistics( std::string_view statisticsFile ) {
200  if ( m_statistics ) {
201  m_statistics->Print();
202  if ( !statisticsFile.empty() ) m_statistics->SaveAs( std::string{statisticsFile}.c_str() );
204  }
205 }
206 
208 void RootDataConnection::enableStatistics( std::string_view section ) {
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 }
220 
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 }
233 
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 }
280 
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 }
333 
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 }
365 
367 TTree* RootDataConnection::getSection( std::string_view section, bool create ) {
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 }
431 
433 TBranch* RootDataConnection::getBranch( std::string_view section, std::string_view branch_name, TClass* cl, void* ptr,
434  int buff_siz, int split_lvl ) {
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 }
448 
450 int RootDataConnection::makeLink( std::string_view p ) {
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 }
456 
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 }
465 
467 CSTR RootDataConnection::empty() const { return s_empty; }
468 
470 pair<int, unsigned long> RootDataConnection::saveObj( std::string_view section, std::string_view cnt, TClass* cl,
471  DataObject* pObj, int buff_siz, int split_lvl, bool fill ) {
472  DataObjectPush push( pObj );
473  return save( section, cnt, cl, pObj, buff_siz, split_lvl, fill );
474 }
475 
477 pair<int, unsigned long> RootDataConnection::save( std::string_view section, std::string_view cnt, TClass* cl,
478  void* pObj, int buff_siz, int split_lvl, bool fill_missing ) {
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 }
505 
507 int RootDataConnection::loadObj( std::string_view section, std::string_view cnt, unsigned long entry,
508  DataObject*& pObj ) {
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 }
555 
557 int RootDataConnection::loadRefs( std::string_view section, std::string_view cnt, unsigned long entry,
558  RootObjectRefs& refs ) {
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 }
571 
574 RootDataConnection::getMergeSection( std::string_view container, int entry ) const {
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 }
598 
601  IOpaqueAddress* pA = pR.address();
602  makeRef( pR.name(), pA->clID(), pA->svcType(), pA->par()[0], pA->par()[1], -1, ref );
603 }
604 
606 void RootDataConnection::makeRef( std::string_view name, long clid, int tech, std::string_view dbase,
607  std::string_view cnt, int entry, RootRef& ref ) {
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 }
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
GaudiHive.precedence.message
message
Definition: precedence.py:21
Gaudi::RootDataConnection::removeClient
size_t removeClient(const IInterface *client)
Remove client from this data source.
Definition: RootDataConnection.cpp:181
std::string
STL class.
std::shared_ptr
STL class.
Gaudi::RootDataConnection::m_clients
Clients m_clients
Client list.
Definition: RootDataConnection.h:182
Gaudi::RootDataConnection::enableStatistics
void enableStatistics(std::string_view section)
Enable TTreePerStats.
Definition: RootDataConnection.cpp:208
IOpaqueAddress::par
virtual const std::string * par() const =0
Retrieve String parameters.
Gaudi::RootConnectionSetup::setMessageSvc
void setMessageSvc(MsgStream *m)
Set message service reference.
Definition: RootDataConnection.cpp:157
StatusCode::default_category
static const Category & default_category() noexcept
Default Gaudi StatusCode category.
Definition: StatusCode.h:351
Gaudi::RootDataConnection::disconnect
StatusCode disconnect() override
Release data stream and release implementation dependent resources.
Definition: RootDataConnection.cpp:335
Gaudi::RootTool
Definition: RootTool.h:26
std::move
T move(T... args)
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
Gaudi::IDataConnection
Definition: IIODataManager.h:34
std::pair
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::vector< std::string >
std::set::find
T find(T... args)
strcasecmp.h
std::set::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::connectRead
StatusCode connectRead() override
Open data stream in read mode.
Definition: RootDataConnection.cpp:235
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::ContainerSection
Definition: RootDataConnection.h:117
Gaudi::RootDataConnection::m_params
ParamMap m_params
Parameter map for file parameters.
Definition: RootDataConnection.h:176
std::isalnum
T isalnum(T... args)
RootTool.h
std::sscanf
T sscanf(T... args)
gaudirun.c
c
Definition: gaudirun.py:509
IRegistry
Definition: IRegistry.h:32
StatusCode::code_t
unsigned long code_t
type of StatusCode value
Definition: StatusCode.h:67
RootDataConnection.h
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)
Gaudi::RootObjectRefs
Definition: RootRefs.h:68
std::replace_if
T replace_if(T... args)
basic.alg
alg
Definition: basic.py:15
IIncidentSvc.h
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::saveObj
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.
Definition: RootDataConnection.cpp:470
IRegistry::name
virtual const name_type & name() const =0
Name of the directory (or key)
Gaudi::RootDataConnection::getDb
const std::string & getDb(int which) const
Access database/file name from saved index.
Definition: RootDataConnection.cpp:458
TimingHistograms.name
name
Definition: TimingHistograms.py:23
StatusCode
Definition: StatusCode.h:65
StatusCode::Category
Definition: StatusCode.h:78
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
Gaudi::Units::m
constexpr double m
Definition: SystemOfUnits.h:108
CLHEP::begin
double * begin(CLHEP::HepVector &v)
Definition: TupleAlg.cpp:45
Gaudi::RootDataConnection::Status::ROOT_READ_ERROR
@ ROOT_READ_ERROR
IOpaqueAddress.h
POOL_ROOT_StorageType
const long POOL_ROOT_StorageType
Definition: ClassID.h:78
GaudiTesting.BaseTest.which
def which(executable)
Definition: BaseTest.py:674
Gaudi::RootDataConnection::Status::ROOT_OPEN_ERROR
@ ROOT_OPEN_ERROR
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
Gaudi::RootConnectionSetup::setIncidentSvc
void setIncidentSvc(IIncidentSvc *m)
Set incident service reference.
Definition: RootDataConnection.cpp:160
IOpaqueAddress::clID
virtual const CLID & clID() const =0
Retrieve class information from link.
Gaudi::IDataConnection::UPDATE
@ UPDATE
Definition: IIODataManager.h:49
std::array
STL class.
Gaudi::RootDataConnection::m_statistics
std::unique_ptr< TTreePerfStats > m_statistics
I/O read statistics from TTree.
Definition: RootDataConnection.h:160
Gaudi::RootRef
Definition: RootRefs.h:40
Gaudi::IDataConnection::m_name
std::string m_name
Connection name/identifier.
Definition: IIODataManager.h:37
GaudiPython.Bindings.nullptr
nullptr
Definition: Bindings.py:74
Gaudi::RootConnectionSetup::setCompression
static StatusCode setCompression(std::string_view compression)
Set the global compression level.
Definition: RootDataConnection.cpp:120
std::set::erase
T erase(T... args)
Gaudi::IDataConnection::IoType
IoType
I/O Connection types.
Definition: IIODataManager.h:49
std::runtime_error
STL class.
Gaudi::RootDataConnection::lookupClient
bool lookupClient(const IInterface *client) const
Lookup client for this data source.
Definition: RootDataConnection.cpp:188
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
gaudirun.level
level
Definition: gaudirun.py:346
IRegistry.h
Gaudi::RootDataConnection::Status
Status
Definition: RootDataConnection.h:105
MsgStream
Definition: MsgStream.h:34
Gaudi::PoolTool
Definition: PoolTool.h:27
Gaudi
Header file for std:chrono::duration-based Counters.
Definition: __init__.py:1
GaudiPluginService.cpluginsvc.n
n
Definition: cpluginsvc.py:221
StatusCode::ignore
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
Definition: StatusCode.h:156
Gaudi::RootDataConnection::makeLink
int makeLink(std::string_view p)
Convert path string to path index.
Definition: RootDataConnection.cpp:450
std::string::substr
T substr(T... args)
IRegistry::address
virtual IOpaqueAddress * address() const =0
Retrieve opaque storage address.
std::vector::emplace_back
T emplace_back(T... args)
Gaudi::RootDataConnection::saveStatistics
void saveStatistics(std::string_view statisticsFile)
Save TTree access statistics if required.
Definition: RootDataConnection.cpp:199
MSG::VERBOSE
@ VERBOSE
Definition: IMessageSvc.h:25
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
DataObject.h
Gaudi::RootDataConnection::loadRefs
int loadRefs(std::string_view section, std::string_view cnt, unsigned long entry, RootObjectRefs &refs)
Load references object.
Definition: RootDataConnection.cpp:557
POOL_ROOTTREE_StorageType
const long POOL_ROOTTREE_StorageType
Definition: ClassID.h:80
std::begin
T begin(T... args)
STATUSCODE_ENUM_IMPL
#define STATUSCODE_ENUM_IMPL(...)
Assign a category to the StatusCode enum declared with STATUSCODE_ENUM_DECL( ENUM )
Definition: StatusCode.h:336
std
STL namespace.
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
IInterface
Definition: IInterface.h:237
Gaudi::RootDataConnection::RootDataConnection
RootDataConnection(const IInterface *own, std::string_view nam, std::shared_ptr< RootConnectionSetup > setup)
Standard constructor.
Definition: RootDataConnection.cpp:163
std::iota
T iota(T... args)
DataObject
Definition: DataObject.h:40
Gaudi::RootDataConnection::getMergeSection
std::pair< const RootRef *, const ContainerSection * > getMergeSection(std::string_view container, int entry) const
Access link section for single container and entry.
Definition: RootDataConnection.cpp:574
Gaudi::IDataConnection::fid
const std::string & fid() const
Access file id.
Definition: IIODataManager.h:63
RootUtils.h
std::vector::empty
T empty(T... args)
Gaudi::RootDataConnection::m_links
StringVec m_links
Map containing internal links names.
Definition: RootDataConnection.h:172
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
Gaudi::RootDataConnection::loadObj
int loadObj(std::string_view section, std::string_view cnt, unsigned long entry, DataObject *&pObj)
Load object.
Definition: RootDataConnection.cpp:507
std::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
PoolTool.h
Incident.h
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::connectWrite
StatusCode connectWrite(IoType typ) override
Open data stream in write mode.
Definition: RootDataConnection.cpp:282
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
MsgStream.h
Gaudi::RootDataConnection::Tool
Definition: RootDataConnection.h:202
StatusCode::Category::message
virtual std::string message(code_t code) const
Description for code within this category.
Definition: StatusCode.h:86
CSTR
const string & CSTR
Definition: RootDataConnection.cpp:49