Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v36r7 (7f57a304)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 if ( alg.size() == 3 && strncasecmp( alg.data(), "LZ4", 3 ) == 0 )
132  alg_code = ROOT::kLZ4;
133 # if ROOT_VERSION_CODE >= ROOT_VERSION( 6, 20, 0 )
134  else if ( alg.size() == 4 && strncasecmp( alg.data(), "ZSTD", 4 ) == 0 )
135  alg_code = ROOT::kZSTD;
136 # endif
137  else
138  throw runtime_error( "ERROR: request to set unknown ROOT compression algorithm:" + std::string{ alg } );
139  res = ::sscanf( std::string{ compression.substr( idx + 1 ) }.c_str(), "%d",
140  &level ); // TODO: use C++17 std::from_chars instead...
141  if ( res == 1 ) {
142  s_compressionLevel = ROOT::CompressionSettings( alg_code, level );
143  return StatusCode::SUCCESS;
144  }
145  throw runtime_error( "ERROR: request to set unknown ROOT compression level:" +
146  std::string{ compression.substr( idx + 1 ) } );
147  } else if ( 1 == ::sscanf( std::string{ compression }.c_str(), "%d", &level ) ) { // TODO: use C++17 std::from_chars
148  // instead
149  s_compressionLevel = level;
150  return StatusCode::SUCCESS;
151  }
152  throw runtime_error( "ERROR: request to set unknown ROOT compression mechanism:" + std::string{ compression } );
153 #else
154  if ( !compression.empty() ) {}
155  return StatusCode::SUCCESS;
156 #endif
157 }
158 
160 int RootConnectionSetup::compression() { return s_compressionLevel; }
161 
163 void RootConnectionSetup::setMessageSvc( MsgStream* m ) { m_msgSvc.reset( m ); }
164 
166 void RootConnectionSetup::setIncidentSvc( IIncidentSvc* s ) { m_incidentSvc.reset( s ); }
167 
169 RootDataConnection::RootDataConnection( const IInterface* owner, std::string_view fname,
171  : IDataConnection( owner, std::string{ fname } )
172  , m_setup( std::move( setup ) ) { // 01234567890123456789012345678901234567890
173  // Check if FID: A82A3BD8-7ECB-DC11-8DC0-000423D950B0
174  if ( fname.size() == 36 && fname[8] == '-' && fname[13] == '-' && fname[18] == '-' && fname[23] == '-' ) {
175  m_name = "FID:";
176  m_name.append( fname.data(), fname.size() );
177  }
178  m_age = 0;
179  m_file.reset();
180  addClient( owner );
181 }
182 
184 void RootDataConnection::addClient( const IInterface* client ) { m_clients.insert( client ); }
185 
188  auto i = m_clients.find( client );
189  if ( i != m_clients.end() ) m_clients.erase( i );
190  return m_clients.size();
191 }
192 
194 bool RootDataConnection::lookupClient( const IInterface* client ) const {
195  auto i = m_clients.find( client );
196  return i != m_clients.end();
197 }
198 
200 void RootDataConnection::badWriteError( std::string_view msg ) const {
201  msgSvc() << MSG::ERROR << "File:" << fid() << "Failed action:" << msg << endmsg;
202 }
203 
205 void RootDataConnection::saveStatistics( std::string_view statisticsFile ) {
206  if ( m_statistics ) {
207  m_statistics->Print();
208  if ( !statisticsFile.empty() ) m_statistics->SaveAs( std::string{ statisticsFile }.c_str() );
210  }
211 }
212 
214 void RootDataConnection::enableStatistics( std::string_view section ) {
215  if ( m_statistics ) {
216  TTree* t = getSection( section, false );
217  if ( t ) {
218  m_statistics.reset( new TTreePerfStats( ( std::string{ section } + "_ioperf" ).c_str(), t ) );
219  return;
220  }
221  msgSvc() << MSG::WARNING << "Failed to enable perfstats for tree:" << section << endmsg;
222  return;
223  }
224  msgSvc() << MSG::INFO << "Perfstats are ALREADY ENABLED." << endmsg;
225 }
226 
229  if ( !m_refs ) m_refs = (TTree*)m_file->Get( "Refs" );
230  if ( m_refs ) m_tool.reset( new RootTool( this ) );
231 #ifdef __POOL_COMPATIBILITY
232  else if ( m_file->Get( "##Links" ) != nullptr )
233  m_tool.reset( new PoolTool( this ) );
234 #endif
235  else
236  m_tool.reset();
237  return m_tool.get();
238 }
239 
242  m_file.reset( TFile::Open( m_pfn.c_str() ) );
243  if ( !m_file || m_file->IsZombie() ) {
244  m_file.reset();
245  return StatusCode::FAILURE;
246  }
248  msgSvc() << MSG::DEBUG << "Opened file " << m_pfn << " in mode READ. [" << m_fid << "]" << endmsg << MSG::DEBUG;
249  if ( msgSvc().isActive() ) m_file->ls();
250  msgSvc() << MSG::VERBOSE;
251  if ( msgSvc().isActive() ) m_file->Print();
252  if ( makeTool() ) {
253  sc = m_tool->readRefs();
254  sc.ignore();
255 #if ROOT_VERSION_CODE >= ROOT_VERSION( 5, 33, 0 )
256  if ( sc == Status::ROOT_READ_ERROR ) {
257  IIncidentSvc* inc = m_setup->incidentSvc();
258  if ( inc ) { inc->fireIncident( Incident( pfn(), IncidentType::CorruptedInputFile ) ); }
259  }
260 #endif
261  }
262  if ( !sc.isSuccess() ) return sc;
263  bool need_fid = m_fid == m_pfn;
264  string fid = m_fid;
265  m_mergeFIDs.clear();
266  for ( auto& elem : m_params ) {
267  if ( elem.first == "FID" ) {
268  m_mergeFIDs.push_back( elem.second );
269  if ( elem.second != m_fid ) {
270  msgSvc() << MSG::DEBUG << "Check FID param:" << elem.second << endmsg;
271  // if ( m_fid == m_pfn ) {
272  m_fid = elem.second;
273  //}
274  }
275  }
276  }
277  if ( !need_fid && fid != m_fid ) {
278  msgSvc() << MSG::ERROR << "FID mismatch:" << fid << "(Catalog) != " << m_fid << "(file)" << endmsg
279  << "for PFN:" << m_pfn << endmsg;
280  return StatusCode::FAILURE;
281  }
282  msgSvc() << MSG::DEBUG << "Using FID " << m_fid << " from params table...." << endmsg << "for PFN:" << m_pfn
283  << endmsg;
284  return sc;
285 }
286 
289  int compress = RootConnectionSetup::compression();
290  msgSvc() << MSG::DEBUG;
291  switch ( typ ) {
292  case CREATE:
293  resetAge();
294  m_file.reset( TFile::Open( m_pfn.c_str(), "CREATE", "Root event data", compress ) );
295  m_refs = new TTree( "Refs", "Root reference data" );
296  msgSvc() << "Opened file " << m_pfn << " in mode CREATE. [" << m_fid << "]" << endmsg;
297  m_params.emplace_back( "PFN", m_pfn );
298  if ( m_fid != m_pfn ) { m_params.emplace_back( "FID", m_fid ); }
299  makeTool();
300  break;
301  case RECREATE:
302  resetAge();
303  m_file.reset( TFile::Open( m_pfn.c_str(), "RECREATE", "Root event data", compress ) );
304  msgSvc() << "Opened file " << m_pfn << " in mode RECREATE. [" << m_fid << "]" << endmsg;
305  m_refs = new TTree( "Refs", "Root reference data" );
306  m_params.emplace_back( "PFN", m_pfn );
307  if ( m_fid != m_pfn ) { m_params.emplace_back( "FID", m_fid ); }
308  makeTool();
309  break;
310  case UPDATE:
311  resetAge();
312  m_file.reset( TFile::Open( m_pfn.c_str(), "UPDATE", "Root event data", compress ) );
313  msgSvc() << "Opened file " << m_pfn << " in mode UPDATE. [" << m_fid << "]" << endmsg;
314  if ( m_file && !m_file->IsZombie() ) {
315  if ( makeTool() ) {
316  StatusCode sc = m_tool->readRefs();
317  sc.ignore();
318  if ( sc == Status::ROOT_READ_ERROR ) {
319 #if ROOT_VERSION_CODE >= ROOT_VERSION( 5, 33, 0 )
320  IIncidentSvc* inc = m_setup->incidentSvc();
321  if ( inc ) { inc->fireIncident( Incident( pfn(), IncidentType::CorruptedInputFile ) ); }
322 #endif
323  }
324  return sc;
325  }
326  TDirectory::TContext ctxt( m_file.get() );
327  m_refs = new TTree( "Refs", "Root reference data" );
328  makeTool();
329  return StatusCode::SUCCESS;
330  }
331  break;
332  default:
333  m_refs = nullptr;
334  m_file.reset();
335  return StatusCode::FAILURE;
336  }
338 }
339 
342  if ( m_file ) {
343  if ( !m_file->IsZombie() ) {
344  if ( m_file->IsWritable() ) {
345  msgSvc() << MSG::DEBUG;
346  TDirectory::TContext ctxt( m_file.get() );
347  if ( m_refs ) {
348  if ( !m_tool->saveRefs().isSuccess() ) badWriteError( "Saving References" );
349  if ( m_refs->Write() < 0 ) badWriteError( "Write Reference branch" );
350  }
351  for ( auto& i : m_sections ) {
352  if ( i.second ) {
353  if ( i.second->Write() < 0 ) badWriteError( "Write section:" + i.first );
354  msgSvc() << "Disconnect section " << i.first << " " << i.second->GetName() << endmsg;
355  }
356  }
357  m_sections.clear();
358  }
359  msgSvc() << MSG::DEBUG;
360  if ( msgSvc().isActive() ) m_file->ls();
361  msgSvc() << MSG::VERBOSE;
362  if ( msgSvc().isActive() ) m_file->Print();
363  m_file->Close();
364  }
365  msgSvc() << MSG::DEBUG << "Disconnected file " << m_pfn << " " << m_file->GetName() << endmsg;
366  m_file.reset();
367  m_tool.reset();
368  }
369  return StatusCode::SUCCESS;
370 }
371 
373 TTree* RootDataConnection::getSection( std::string_view section, bool create ) {
374  auto it = m_sections.find( section );
375  TTree* t = ( it != m_sections.end() ? it->second : nullptr );
376  if ( !t ) {
377  t = (TTree*)m_file->Get( std::string{ section }.c_str() );
378  if ( !t && create ) {
379  TDirectory::TContext ctxt( m_file.get() );
380  t = new TTree( std::string{ section }.c_str(), "Root data for Gaudi" );
381  }
382  if ( t ) {
383  int cacheSize = m_setup->cacheSize;
384  if ( create ) {
385  // t->SetAutoFlush(100);
386  }
387  if ( section == m_setup->loadSection && cacheSize > -2 ) {
388  MsgStream& msg = msgSvc();
389  int learnEntries = m_setup->learnEntries;
390  t->SetCacheSize( cacheSize );
391  t->SetCacheLearnEntries( learnEntries );
392  msg << MSG::DEBUG;
393  if ( create ) {
394  msg << "Tree:" << section << "Setting up tree cache:" << cacheSize << endmsg;
395  } else {
396  const StringVec& vB = m_setup->vetoBranches;
397  const StringVec& cB = m_setup->cacheBranches;
398  msg << "Tree:" << section << " Setting up tree cache:" << cacheSize << " Add all branches." << endmsg;
399  msg << "Tree:" << section << " Learn for " << learnEntries << " entries." << endmsg;
400 
401  if ( cB.empty() && vB.empty() ) {
402  msg << "Adding (default) all branches to tree cache." << endmsg;
403  t->AddBranchToCache( "*", kTRUE );
404  }
405  if ( cB.size() == 1 && cB[0] == "*" ) {
406  msg << "Adding all branches to tree cache according to option \"CacheBranches\"." << endmsg;
407  t->AddBranchToCache( "*", kTRUE );
408  } else {
409  for ( TIter it( t->GetListOfBranches() ); it.Next(); ) {
410  const char* n = ( (TNamed*)( *it ) )->GetName();
411  bool add = false, veto = false;
412  for ( const auto& i : cB ) {
413  if ( !match_wild( n, ( i ).c_str() ) ) continue;
414  add = true;
415  break;
416  }
417  for ( auto i = vB.cbegin(); !add && i != vB.cend(); ++i ) {
418  if ( !match_wild( n, ( *i ).c_str() ) ) continue;
419  veto = true;
420  break;
421  }
422  if ( add && !veto ) {
423  msg << "Add " << n << " to branch cache." << endmsg;
424  t->AddBranchToCache( n, kTRUE );
425  } else {
426  msg << "Do not cache branch " << n << endmsg;
427  }
428  }
429  }
430  }
431  }
432  m_sections[std::string{ section }] = t;
433  }
434  }
435  return t;
436 }
437 
439 TBranch* RootDataConnection::getBranch( std::string_view section, std::string_view branch_name, TClass* cl, void* ptr,
440  int buff_siz, int split_lvl ) {
441  string n = std::string{ branch_name };
443  begin( n ), end( n ), []( const char c ) { return !isalnum( c ); }, '_' );
444  n += ".";
445  TTree* t = getSection( section, true );
446  TBranch* b = t->GetBranch( n.c_str() );
447  if ( !b && cl && m_file->IsWritable() ) {
448  b = t->Branch( n.c_str(), cl->GetName(), (void*)( ptr ? &ptr : nullptr ), buff_siz, split_lvl );
449  }
450  if ( !b ) b = t->GetBranch( std::string{ branch_name }.c_str() );
451  if ( b ) b->SetAutoDelete( kFALSE );
452  return b;
453 }
454 
456 int RootDataConnection::makeLink( std::string_view p ) {
457  auto ip = std::find( std::begin( m_links ), std::end( m_links ), p );
458  if ( ip != std::end( m_links ) ) return std::distance( std::begin( m_links ), ip );
459  m_links.push_back( std::string{ p } );
460  return m_links.size() - 1;
461 }
462 
465  if ( ( which >= 0 ) && ( size_t( which ) < m_dbs.size() ) ) {
466  if ( *( m_dbs.begin() + which ) == s_local ) return m_fid;
467  return *( m_dbs.begin() + which );
468  }
469  return s_empty;
470 }
471 
473 CSTR RootDataConnection::empty() const { return s_empty; }
474 
476 pair<int, unsigned long> RootDataConnection::saveObj( std::string_view section, std::string_view cnt, TClass* cl,
477  DataObject* pObj, int buff_siz, int split_lvl, bool fill ) {
478  DataObjectPush push( pObj );
479  return save( section, cnt, cl, pObj, buff_siz, split_lvl, fill );
480 }
481 
483 pair<int, unsigned long> RootDataConnection::save( std::string_view section, std::string_view cnt, TClass* cl,
484  void* pObj, int buff_siz, int split_lvl, bool fill_missing ) {
485  split_lvl = 0;
486  TBranch* b = getBranch( section, cnt, cl, pObj ? &pObj : nullptr, buff_siz, split_lvl );
487  if ( b ) {
488  Long64_t evt = b->GetEntries();
489  // msgSvc() << MSG::DEBUG << cnt.c_str() << " Obj:" << (void*)pObj
490  // << " Split:" << split_lvl << " Buffer size:" << buff_siz << endl;
491  if ( fill_missing ) {
492  Long64_t num, nevt = b->GetTree()->GetEntries();
493  if ( nevt > evt ) {
494  b->SetAddress( nullptr );
495  num = nevt - evt;
496  while ( num > 0 ) {
497  b->Fill();
498  --num;
499  }
500  msgSvc() << MSG::DEBUG << "Added " << long( nevt - evt ) << " / Tree: " << nevt
501  << " / Branch: " << b->GetEntries() + 1 << " NULL entries to:" << cnt << endmsg;
502  evt = b->GetEntries();
503  }
504  }
505  b->SetAddress( &pObj );
506  return { b->Fill(), evt };
507  }
508  if ( pObj ) { msgSvc() << MSG::ERROR << "Failed to access branch " << m_name << "/" << cnt << endmsg; }
509  return { -1, ~0 };
510 }
511 
513 int RootDataConnection::loadObj( std::string_view section, std::string_view cnt, unsigned long entry,
514  DataObject*& pObj ) {
515  TBranch* b = getBranch( section, cnt );
516  if ( b ) {
517  TClass* cl = gROOT->GetClass( b->GetClassName(), kTRUE );
518  if ( cl ) {
519  int nb = -1;
520  pObj = (DataObject*)cl->New();
521  {
522  DataObjectPush push( pObj );
523  b->SetAddress( &pObj );
524  if ( section == m_setup->loadSection ) {
525  TTree* t = b->GetTree();
526  if ( Long64_t( entry ) != t->GetReadEntry() ) { t->LoadTree( Long64_t( entry ) ); }
527  }
528  nb = b->GetEntry( entry );
529  msgSvc() << MSG::VERBOSE;
530  if ( msgSvc().isActive() ) {
531  msgSvc() << "Load [" << entry << "] --> " << section << ":" << cnt << " " << nb << " bytes." << endmsg;
532  }
533  if ( nb < 0 ) { // This is definitely an error...ROOT says if reads fail, -1 is issued.
534 #if ROOT_VERSION_CODE >= ROOT_VERSION( 5, 33, 0 )
535  IIncidentSvc* inc = m_setup->incidentSvc();
536  if ( inc ) { inc->fireIncident( Incident( pfn(), IncidentType::CorruptedInputFile ) ); }
537 #endif
538  } else if ( nb == 0 && pObj->clID() == CLID_DataObject ) {
539  TFile* f = b->GetFile();
540  int vsn = f->GetVersion();
541  if ( vsn < 52400 ) {
542  // For Gaudi v21r5 (ROOT 5.24.00b) DataObject::m_version was not written!
543  // Still this call be well be successful.
544  nb = 1;
545  } else if ( vsn > 1000000 && ( vsn % 1000000 ) < 52400 ) {
546  // dto. Some POOL files have for unknown reasons a version
547  // not according to ROOT standards. Hack this explicitly.
548  nb = 1;
549  }
550  }
551  if ( nb < 0 ) {
552  delete pObj;
553  pObj = nullptr;
554  }
555  }
556  return nb;
557  }
558  }
559  return -1;
560 }
561 
563 int RootDataConnection::loadRefs( std::string_view section, std::string_view cnt, unsigned long entry,
564  RootObjectRefs& refs ) {
565  int nbytes = m_tool->loadRefs( section, cnt, entry, refs );
566 #if ROOT_VERSION_CODE >= ROOT_VERSION( 5, 33, 0 )
567  if ( nbytes < 0 ) {
568  // This is definitely an error:
569  // -- Either branch not preesent at all or
570  // -- ROOT I/O error, which issues -1
571  IIncidentSvc* inc = m_setup->incidentSvc();
572  if ( inc ) { inc->fireIncident( Incident( pfn(), IncidentType::CorruptedInputFile ) ); }
573  }
574 #endif
575  return nbytes;
576 }
577 
580 RootDataConnection::getMergeSection( std::string_view container, int entry ) const {
581  // size_t idx = cont.find('/',1);
582  // string container = cont[0]=='/' ? cont.substr(1,idx==string::npos?idx:idx-1) : cont;
583  auto i = m_mergeSects.find( container );
584  if ( i != m_mergeSects.end() ) {
585  size_t cnt = 0;
586  const ContainerSections& s = ( *i ).second;
587  for ( auto j = s.cbegin(); j != s.cend(); ++j, ++cnt ) {
588  const ContainerSection& c = *j;
589  if ( entry >= c.start && entry < ( c.start + c.length ) ) {
590  if ( m_linkSects.size() > cnt ) {
591  if ( msgSvc().isActive() ) {
592  msgSvc() << MSG::VERBOSE << "MergeSection for:" << container << " [" << entry << "]" << endmsg
593  << "FID:" << m_fid << " -> PFN:" << m_pfn << endmsg;
594  }
595  return { &( m_linkSects[cnt] ), &c };
596  }
597  }
598  }
599  }
600  msgSvc() << MSG::DEBUG << "Return INVALID MergeSection for:" << container << " [" << entry << "]" << endmsg
601  << "FID:" << m_fid << " -> PFN:" << m_pfn << endmsg;
602  return { nullptr, nullptr };
603 }
604 
607  IOpaqueAddress* pA = pR.address();
608  makeRef( pR.name(), pA->clID(), pA->svcType(), pA->par()[0], pA->par()[1], -1, ref );
609 }
610 
612 void RootDataConnection::makeRef( std::string_view name, long clid, int tech, std::string_view dbase,
613  std::string_view cnt, int entry, RootRef& ref ) {
614  auto db = ( dbase == m_fid ? std::string_view{ s_local } : dbase );
615  ref.entry = entry;
616 
617  int cdb = -1;
618  if ( !db.empty() ) {
619  auto idb = std::find_if( m_dbs.begin(), m_dbs.end(), [&]( const std::string& i ) { return i == db; } );
620  cdb = std::distance( m_dbs.begin(), idb );
621  if ( idb == m_dbs.end() ) m_dbs.push_back( std::string{ db } );
622  }
623 
624  int ccnt = -1;
625  if ( !cnt.empty() ) {
626  auto icnt = std::find_if( m_conts.begin(), m_conts.end(), [&]( const std::string& i ) { return i == cnt; } );
627  ccnt = std::distance( m_conts.begin(), icnt );
628  if ( icnt == m_conts.end() ) m_conts.push_back( std::string{ cnt } );
629  }
630 
631  int clnk = -1;
632  if ( !name.empty() ) {
633  auto ilnk = std::find_if( m_links.begin(), m_links.end(), [&]( const std::string& i ) { return i == name; } );
634  clnk = std::distance( m_links.begin(), ilnk );
635  if ( ilnk == m_links.end() ) m_links.push_back( std::string{ name } );
636  }
637 
638  ref.dbase = cdb;
639  ref.container = ccnt;
640  ref.link = clnk;
641  ref.clid = clid;
642  ref.svc = tech;
643  if ( ref.svc == POOL_ROOT_StorageType || ref.svc == POOL_ROOTKEY_StorageType ||
644  ref.svc == POOL_ROOTTREE_StorageType ) {
645  ref.svc = ROOT_StorageType;
646  }
647 }
IOTest.evt
evt
Definition: IOTest.py:110
Gaudi::RootDataConnection::save
std::pair< int, unsigned long > save(std::string_view section, std::string_view cnt, TClass *cl, void *pObj, int buff_siz, int split_lvl, bool fill_missing=false)
Save object of a given class to section and container.
Definition: RootDataConnection.cpp:483
MSG::DEBUG
@ DEBUG
Definition: IMessageSvc.h:25
Gaudi::IDataConnection::name
const std::string & name() const
Connection name.
Definition: IIODataManager.h:59
GaudiHive.precedence.message
message
Definition: precedence.py:22
Gaudi::RootDataConnection::removeClient
size_t removeClient(const IInterface *client)
Remove client from this data source.
Definition: RootDataConnection.cpp:187
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:214
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:163
StatusCode::default_category
static const Category & default_category() noexcept
Default Gaudi StatusCode category.
Definition: StatusCode.h:310
Gaudi::RootDataConnection::disconnect
StatusCode disconnect() override
Release data stream and release implementation dependent resources.
Definition: RootDataConnection.cpp:341
Gaudi::RootTool
Definition: RootTool.h:26
std::move
T move(T... args)
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:314
MSG::INFO
@ INFO
Definition: IMessageSvc.h:25
Gaudi::RootDataConnection::badWriteError
void badWriteError(std::string_view msg) const
Error handler when bad write statements occur.
Definition: RootDataConnection.cpp:200
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:346
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:19
Gaudi::RootDataConnection::connectRead
StatusCode connectRead() override
Open data stream in read mode.
Definition: RootDataConnection.cpp:241
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:525
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:476
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:464
TimingHistograms.name
name
Definition: TimingHistograms.py:25
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:745
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:166
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:93
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:194
compareRootHistos.ref
string ref
Definition: compareRootHistos.py:28
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:203
Gaudi::RootDataConnection::makeRef
void makeRef(const IRegistry &pA, RootRef &ref)
Create reference object from registry entry.
Definition: RootDataConnection.cpp:606
ROOT_StorageType
const long ROOT_StorageType
Definition: ClassID.h:62
Gaudi::RootDataConnection::m_tool
std::unique_ptr< Tool > m_tool
Definition: RootDataConnection.h:242
Gaudi::RootDataConnection::m_conts
StringVec m_conts
Map containing external container names.
Definition: RootDataConnection.h:170
Gaudi::IDataConnection::m_fid
std::string m_fid
File ID of the connection.
Definition: IIODataManager.h:39
gaudirun.level
level
Definition: gaudirun.py:364
IRegistry.h
Gaudi::RootDataConnection::Status
Status
Definition: RootDataConnection.h:105
MsgStream
Definition: MsgStream.h:34
IOTest.end
def end
Definition: IOTest.py:128
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:235
StatusCode::ignore
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
Definition: StatusCode.h:139
Gaudi::RootDataConnection::makeLink
int makeLink(std::string_view p)
Convert path string to path index.
Definition: RootDataConnection.cpp:456
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:205
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:563
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:295
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:373
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:169
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:580
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:513
std::end
T end(T... args)
Gaudi::IDataConnection::m_pfn
std::string m_pfn
Physical file name of the connection.
Definition: IIODataManager.h:41
Gaudi::IDataConnection::pfn
const std::string & pfn() const
Access physical file name.
Definition: IIODataManager.h:65
Gaudi::RootDataConnection::addClient
void addClient(const IInterface *client)
Add new client to this data source.
Definition: RootDataConnection.cpp:184
Gaudi::RootDataConnection::makeTool
Tool * makeTool()
Create file access tool to encapsulate POOL compatibiliy.
Definition: RootDataConnection.cpp:228
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
Gaudi::RootDataConnection::empty
const std::string & empty() const
Empty string reference.
Definition: RootDataConnection.cpp:473
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:67
Gaudi::RootConnectionSetup::compression
static int compression()
Access to global compression level.
Definition: RootDataConnection.cpp:160
Gaudi::RootDataConnection::msgSvc
MsgStream & msgSvc() const
Allow access to printer service.
Definition: RootDataConnection.h:154
Gaudi::RootDataConnection::connectWrite
StatusCode connectWrite(IoType typ) override
Open data stream in write mode.
Definition: RootDataConnection.cpp:288
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