Go to the documentation of this file.
   36 #if ROOT_VERSION_CODE >= ROOT_VERSION( 5, 33, 0 ) 
   37 #  include "Compression.h" 
   38 static int s_compressionLevel = ROOT::CompressionSettings( ROOT::kLZMA, 4 );
 
   40 static int s_compressionLevel = 1;
 
   47 using namespace Gaudi;
 
   49 typedef const string& 
CSTR;
 
   51 static const string s_empty;
 
   52 static const string s_local = 
"<localDB>";
 
   54 #ifdef __POOL_COMPATIBILITY 
   67     const char* 
name()
 const override { 
return "RootDataConnection"; }
 
   74         return "ROOT_READ_ERROR";
 
   76         return "ROOT_OPEN_ERROR";
 
   83   static bool match_wild( 
const char* str, 
const char* pat ) {
 
   87     static const auto table = init_table();
 
   91     for ( 
s = str, p = pat; *
s; ++
s, ++p ) {
 
   94         if ( *
s == 
'.' ) 
goto starCheck;
 
   99         do { ++pat; } 
while ( *pat == 
'*' );
 
  100         if ( !*pat ) 
return true;
 
  103         if ( table[*
s] != table[*p] ) 
goto starCheck;
 
  107     while ( *p == 
'*' ) ++p;
 
  111     if ( !star ) 
return false;
 
  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;
 
  136       s_compressionLevel = ROOT::CompressionSettings( alg_code, 
level );
 
  139     throw runtime_error( 
"ERROR: request to set unknown ROOT compression level:" +
 
  143     s_compressionLevel = 
level;
 
  148   if ( !compression.empty() ) {}
 
  168   if ( fname.size() == 36 && fname[8] == 
'-' && fname[13] == 
'-' && fname[18] == 
'-' && fname[23] == 
'-' ) {
 
  170     m_name.append( fname.data(), fname.size() );
 
  225 #ifdef __POOL_COMPATIBILITY 
  249 #if ROOT_VERSION_CODE >= ROOT_VERSION( 5, 33, 0 ) 
  261     if ( elem.first == 
"FID" ) {
 
  263       if ( elem.second != 
m_fid ) {
 
  289     m_refs = 
new TTree( 
"Refs", 
"Root reference data" );
 
  299     m_refs = 
new TTree( 
"Refs", 
"Root reference data" );
 
  313 #if ROOT_VERSION_CODE >= ROOT_VERSION( 5, 33, 0 ) 
  320       TDirectory::TContext ctxt( 
m_file.
get() );
 
  321       m_refs = 
new TTree( 
"Refs", 
"Root reference data" );
 
  337     if ( !
m_file->IsZombie() ) {
 
  338       if ( 
m_file->IsWritable() ) {
 
  340         TDirectory::TContext ctxt( 
m_file.
get() );
 
  347             if ( i.second->Write() < 0 ) 
badWriteError( 
"Write section:" + i.first );
 
  348             msgSvc() << 
"Disconnect section " << i.first << 
" " << i.second->GetName() << 
endmsg;
 
  372     if ( !
t && create ) {
 
  373       TDirectory::TContext ctxt( 
m_file.
get() );
 
  377       int cacheSize = 
m_setup->cacheSize;
 
  381       if ( section == 
m_setup->loadSection && cacheSize > -2 ) {
 
  383         int        learnEntries = 
m_setup->learnEntries;
 
  384         t->SetCacheSize( cacheSize );
 
  385         t->SetCacheLearnEntries( learnEntries );
 
  388           msg << 
"Tree:" << section << 
"Setting up tree cache:" << cacheSize << 
endmsg;
 
  392           msg << 
"Tree:" << section << 
" Setting up tree cache:" << cacheSize << 
" Add all branches." << 
endmsg;
 
  393           msg << 
"Tree:" << section << 
" Learn for " << learnEntries << 
" entries." << 
endmsg;
 
  396             msg << 
"Adding (default) all branches to tree cache." << 
endmsg;
 
  397             t->AddBranchToCache( 
"*", kTRUE );
 
  399           if ( cB.
size() == 1 && cB[0] == 
"*" ) {
 
  400             msg << 
"Adding all branches to tree cache according to option \"CacheBranches\"." << 
endmsg;
 
  401             t->AddBranchToCache( 
"*", kTRUE );
 
  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;
 
  412                 if ( !match_wild( 
n, ( *i ).c_str() ) ) 
continue;
 
  416               if ( 
add && !veto ) {
 
  417                 msg << 
"Add " << 
n << 
" to branch cache." << 
endmsg;
 
  418                 t->AddBranchToCache( 
n, kTRUE );
 
  433 TBranch* RootDataConnection::getBranch( std::string_view section, std::string_view branch_name, TClass* cl, 
void* ptr,
 
  434                                         int buff_siz, 
int split_lvl ) {
 
  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 );
 
  445   if ( b ) b->SetAutoDelete( kFALSE );
 
  472   DataObjectPush push( pObj );
 
  473   return save( section, cnt, cl, pObj, buff_siz, split_lvl, 
fill );
 
  478                                                    void* pObj, 
int buff_siz, 
int split_lvl, 
bool fill_missing ) {
 
  480   TBranch* b = 
getBranch( section, cnt, cl, pObj ? &pObj : 
nullptr, buff_siz, split_lvl );
 
  482     Long64_t 
evt = b->GetEntries();
 
  485     if ( fill_missing ) {
 
  486       Long64_t num, nevt = b->GetTree()->GetEntries();
 
  488         b->SetAddress( 
nullptr );
 
  495                  << 
" / Branch: " << b->GetEntries() + 1 << 
" NULL entries to:" << cnt << 
endmsg;
 
  496         evt = b->GetEntries();
 
  499     b->SetAddress( &pObj );
 
  500     return {b->Fill(), 
evt};
 
  511     TClass* cl = gROOT->GetClass( b->GetClassName(), kTRUE );
 
  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 ) ); }
 
  522         nb = b->GetEntry( entry );
 
  524         if ( 
msgSvc().isActive() ) {
 
  525           msgSvc() << 
"Load [" << entry << 
"] --> " << section << 
":" << cnt << 
"  " << nb << 
" bytes." << 
endmsg;
 
  528 #if ROOT_VERSION_CODE >= ROOT_VERSION( 5, 33, 0 ) 
  532         } 
else if ( nb == 0 && pObj->
clID() == CLID_DataObject ) {
 
  533           TFile* f   = b->GetFile();
 
  534           int    vsn = f->GetVersion();
 
  539           } 
else if ( vsn > 1000000 && ( vsn % 1000000 ) < 52400 ) {
 
  559   int nbytes = 
m_tool->loadRefs( section, cnt, entry, refs );
 
  560 #if ROOT_VERSION_CODE >= ROOT_VERSION( 5, 33, 0 ) 
  581     for ( 
auto j = 
s.
cbegin(); j != 
s.
cend(); ++j, ++cnt ) {
 
  583       if ( entry >= 
c.start && entry < ( 
c.start + 
c.length ) ) {
 
  585           if ( 
msgSvc().isActive() ) {
 
  594   msgSvc() << 
MSG::DEBUG << 
"Return INVALID MergeSection for:" << container << 
"  [" << entry << 
"]" << 
endmsg 
  596   return {
nullptr, 
nullptr};
 
  607                                   std::string_view cnt, 
int entry, 
RootRef& 
ref ) {
 
  608   auto db   = ( dbase == 
m_fid ? std::string_view{s_local} : dbase );
 
  619   if ( !cnt.empty() ) {
 
  633   ref.container = ccnt;
 
  
 
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.
const std::string & name() const
Connection name.
size_t removeClient(const IInterface *client)
Remove client from this data source.
Clients m_clients
Client list.
void enableStatistics(std::string_view section)
Enable TTreePerStats.
virtual const std::string * par() const =0
Retrieve String parameters.
void setMessageSvc(MsgStream *m)
Set message service reference.
static const Category & default_category() noexcept
Default Gaudi StatusCode category.
StatusCode disconnect() override
Release data stream and release implementation dependent resources.
void badWriteError(std::string_view msg) const
Error handler when bad write statements occur.
long
(c) Copyright 1998-2020 CERN for the benefit of the LHCb and ATLAS collaborations # # This software i...
virtual long svcType() const =0
Retrieve service type.
void resetAge()
Reset age.
StatusCode connectRead() override
Open data stream in read mode.
std::unique_ptr< TFile > m_file
Reference to ROOT file.
ParamMap m_params
Parameter map for file parameters.
unsigned long code_t
type of StatusCode value
virtual void fireIncident(const Incident &incident)=0
Fire an Incident.
StringVec m_dbs
Map containing external database file names (fids)
LinkSections m_linkSects
Database link sections.
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.
virtual const name_type & name() const =0
Name of the directory (or key)
const std::string & getDb(int which) const
Access database/file name from saved index.
StringVec m_mergeFIDs
Map containing merge FIDs.
std::shared_ptr< RootConnectionSetup > m_setup
Reference to the setup structure.
double * begin(CLHEP::HepVector &v)
const long POOL_ROOT_StorageType
MergeSections m_mergeSects
Database section map for merged files.
const long POOL_ROOTKEY_StorageType
void setIncidentSvc(IIncidentSvc *m)
Set incident service reference.
virtual const CLID & clID() const =0
Retrieve class information from link.
std::unique_ptr< TTreePerfStats > m_statistics
I/O read statistics from TTree.
std::string m_name
Connection name/identifier.
static StatusCode setCompression(std::string_view compression)
Set the global compression level.
IoType
I/O Connection types.
bool lookupClient(const IInterface *client) const
Lookup client for this data source.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
void makeRef(const IRegistry &pA, RootRef &ref)
Create reference object from registry entry.
const long ROOT_StorageType
std::unique_ptr< Tool > m_tool
StringVec m_conts
Map containing external container names.
std::string m_fid
File ID of the connection.
Header file for std:chrono::duration-based Counters.
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
int makeLink(std::string_view p)
Convert path string to path index.
virtual IOpaqueAddress * address() const =0
Retrieve opaque storage address.
T emplace_back(T... args)
void saveStatistics(std::string_view statisticsFile)
Save TTree access statistics if required.
constexpr static const auto SUCCESS
int loadRefs(std::string_view section, std::string_view cnt, unsigned long entry, RootObjectRefs &refs)
Load references object.
const long POOL_ROOTTREE_StorageType
#define STATUSCODE_ENUM_IMPL(...)
Assign a category to the StatusCode enum declared with STATUSCODE_ENUM_DECL( ENUM )
TTree * getSection(std::string_view sect, bool create=false)
Access TTree section from section name. The section is created if required.
RootDataConnection(const IInterface *own, std::string_view nam, std::shared_ptr< RootConnectionSetup > setup)
Standard constructor.
std::pair< const RootRef *, const ContainerSection * > getMergeSection(std::string_view container, int entry) const
Access link section for single container and entry.
const std::string & fid() const
Access file id.
StringVec m_links
Map containing internal links names.
GAUDI_API void fill(AIDA::IHistogram1D *histo, const double value, const double weight=1.0)
simple function to fill AIDA::IHistogram1D objects
int loadObj(std::string_view section, std::string_view cnt, unsigned long entry, DataObject *&pObj)
Load object.
std::string m_pfn
Physical file name of the connection.
const std::string & pfn() const
Access physical file name.
void addClient(const IInterface *client)
Add new client to this data source.
Tool * makeTool()
Create file access tool to encapsulate POOL compatibiliy.
constexpr static const auto FAILURE
const std::string & empty() const
Empty string reference.
Sections m_sections
Tree sections in TFile.
TBranch * getBranch(std::string_view section, std::string_view branch_name)
Access data branch by name: Get existing branch in read only mode.
virtual const CLID & clID() const
Retrieve reference to class definition structure.
static int compression()
Access to global compression level.
MsgStream & msgSvc() const
Allow access to printer service.
StatusCode connectWrite(IoType typ) override
Open data stream in write mode.
TTree * m_refs
Pointer to the reference tree.
virtual std::string message(code_t code) const
Description for code within this category.