26 #if ROOT_VERSION_CODE >= ROOT_VERSION( 5, 33, 0 ) 27 # include "Compression.h" 28 static int s_compressionLevel = ROOT::CompressionSettings( ROOT::kLZMA, 4 );
30 static int s_compressionLevel = 1;
37 using namespace Gaudi;
39 typedef const string&
CSTR;
41 static const string s_empty;
42 static const string s_local =
"<localDB>";
44 #ifdef __POOL_COMPATIBILITY 57 const char*
name()
const override {
return "RootDataConnection"; }
62 switch ( static_cast<RootDataConnection::Status>( code ) ) {
63 case RootDataConnection::Status::ROOT_READ_ERROR:
64 return "ROOT_READ_ERROR";
65 case RootDataConnection::Status::ROOT_OPEN_ERROR:
66 return "ROOT_OPEN_ERROR";
73 static bool match_wild(
const char* str,
const char* pat ) {
77 static const auto table = init_table();
81 for (
s = str, p = pat; *
s; ++
s, ++p ) {
84 if ( *
s ==
'.' )
goto starCheck;
89 do { ++pat; }
while ( *pat ==
'*' );
90 if ( !*pat )
return true;
93 if ( table[*
s] != table[*p] )
goto starCheck;
97 while ( *p ==
'*' ) ++p;
101 if ( !star )
return false;
111 #if ROOT_VERSION_CODE >= ROOT_VERSION( 5, 33, 0 ) 112 int res = 0,
level = ROOT::CompressionSettings( ROOT::kLZMA, 6 );
113 auto idx = compression.find(
':' );
114 if ( idx != string::npos ) {
115 auto alg = compression.substr( 0, idx );
116 ROOT::ECompressionAlgorithm alg_code = ROOT::kUseGlobalSetting;
117 if (
alg.size() == 4 && strncasecmp(
alg.data(),
"ZLIB", 4 ) == 0 )
118 alg_code = ROOT::kZLIB;
119 else if (
alg.size() == 4 && strncasecmp(
alg.data(),
"LZMA", 4 ) == 0 )
120 alg_code = ROOT::kLZMA;
126 s_compressionLevel = ROOT::CompressionSettings( alg_code,
level );
129 throw runtime_error(
"ERROR: request to set unknown ROOT compression level:" +
133 s_compressionLevel =
level;
138 if ( !compression.empty() ) {}
158 if ( fname.size() == 36 && fname[8] ==
'-' && fname[13] ==
'-' && fname[18] ==
'-' && fname[23] ==
'-' ) {
160 m_name.append( fname.data(), fname.size() );
215 #ifdef __POOL_COMPATIBILITY 216 else if (
m_file->Get(
"##Links" ) != nullptr )
239 #if ROOT_VERSION_CODE >= ROOT_VERSION( 5, 33, 0 ) 240 if ( sc == Status::ROOT_READ_ERROR ) {
251 if ( elem.first ==
"FID" ) {
253 if ( elem.second !=
m_fid ) {
279 m_refs =
new TTree(
"Refs",
"Root reference data" );
289 m_refs =
new TTree(
"Refs",
"Root reference data" );
302 if ( sc == Status::ROOT_READ_ERROR ) {
303 #if ROOT_VERSION_CODE >= ROOT_VERSION( 5, 33, 0 ) 310 TDirectory::TContext ctxt(
m_file.
get() );
311 m_refs =
new TTree(
"Refs",
"Root reference data" );
327 if ( !
m_file->IsZombie() ) {
328 if (
m_file->IsWritable() ) {
330 TDirectory::TContext ctxt(
m_file.
get() );
337 if ( i.second->Write() < 0 )
badWriteError(
"Write section:" + i.first );
338 msgSvc() <<
"Disconnect section " << i.first <<
" " << i.second->GetName() <<
endmsg;
359 TTree* t = ( it !=
m_sections.
end() ? it->second : nullptr );
362 if ( !t && create ) {
363 TDirectory::TContext ctxt(
m_file.
get() );
367 int cacheSize =
m_setup->cacheSize;
371 if ( section ==
m_setup->loadSection && cacheSize > -2 ) {
373 int learnEntries =
m_setup->learnEntries;
374 t->SetCacheSize( cacheSize );
375 t->SetCacheLearnEntries( learnEntries );
378 msg <<
"Tree:" << section <<
"Setting up tree cache:" << cacheSize <<
endmsg;
382 msg <<
"Tree:" << section <<
" Setting up tree cache:" << cacheSize <<
" Add all branches." <<
endmsg;
383 msg <<
"Tree:" << section <<
" Learn for " << learnEntries <<
" entries." <<
endmsg;
386 msg <<
"Adding (default) all branches to tree cache." <<
endmsg;
387 t->AddBranchToCache(
"*", kTRUE );
389 if ( cB.
size() == 1 && cB[0] ==
"*" ) {
390 msg <<
"Adding all branches to tree cache according to option \"CacheBranches\"." <<
endmsg;
391 t->AddBranchToCache(
"*", kTRUE );
393 for ( TIter it( t->GetListOfBranches() ); it.Next(); ) {
394 const char*
n = ( (TNamed*)( *it ) )->GetName();
395 bool add =
false, veto =
false;
396 for (
const auto& i : cB ) {
397 if ( !match_wild(
n, ( i ).c_str() ) )
continue;
402 if ( !match_wild(
n, ( *i ).c_str() ) )
continue;
406 if (
add && !veto ) {
407 msg <<
"Add " <<
n <<
" to branch cache." <<
endmsg;
408 t->AddBranchToCache(
n, kTRUE );
424 int buff_siz,
int split_lvl ) {
430 TBranch* b = t->GetBranch(
n.c_str() );
431 if ( !b && cl &&
m_file->IsWritable() ) {
432 b = t->Branch(
n.c_str(), cl->GetName(), (
void*)( ptr ? &ptr :
nullptr ), buff_siz, split_lvl );
435 if ( b ) b->SetAutoDelete( kFALSE );
462 DataObjectPush push( pObj );
463 return save( section, cnt, cl, pObj, buff_siz, split_lvl,
fill );
468 void* pObj,
int buff_siz,
int split_lvl,
bool fill_missing ) {
470 TBranch* b =
getBranch( section, cnt, cl, pObj ? &pObj :
nullptr, buff_siz, split_lvl );
472 Long64_t
evt = b->GetEntries();
475 if ( fill_missing ) {
476 Long64_t num, nevt = b->GetTree()->GetEntries();
478 b->SetAddress(
nullptr );
485 <<
" / Branch: " << b->GetEntries() + 1 <<
" NULL entries to:" << cnt <<
endmsg;
486 evt = b->GetEntries();
489 b->SetAddress( &pObj );
490 return {b->Fill(),
evt};
501 TClass* cl = gROOT->GetClass( b->GetClassName(), kTRUE );
506 DataObjectPush push( pObj );
507 b->SetAddress( &pObj );
508 if ( section ==
m_setup->loadSection ) {
509 TTree* t = b->GetTree();
510 if ( Long64_t( entry ) != t->GetReadEntry() ) { t->LoadTree( Long64_t( entry ) ); }
512 nb = b->GetEntry( entry );
514 if (
msgSvc().isActive() ) {
515 msgSvc() <<
"Load [" << entry <<
"] --> " << section <<
":" << cnt <<
" " << nb <<
" bytes." <<
endmsg;
518 #if ROOT_VERSION_CODE >= ROOT_VERSION( 5, 33, 0 ) 522 }
else if ( nb == 0 && pObj->
clID() == CLID_DataObject ) {
523 TFile* f = b->GetFile();
524 int vsn = f->GetVersion();
529 }
else if ( vsn > 1000000 && ( vsn % 1000000 ) < 52400 ) {
549 int nbytes =
m_tool->loadRefs( section, cnt, entry, refs );
550 #if ROOT_VERSION_CODE >= ROOT_VERSION( 5, 33, 0 ) 571 for (
auto j =
s.
cbegin(); j !=
s.
cend(); ++j, ++cnt ) {
573 if ( entry >=
c.start && entry < (
c.start +
c.length ) ) {
584 msgSvc() <<
MSG::DEBUG <<
"Return INVALID MergeSection for:" << container <<
" [" << entry <<
"]" <<
endmsg 586 return {
nullptr,
nullptr};
597 std::string_view cnt,
int entry,
RootRef&
ref ) {
598 auto db = ( dbase ==
m_fid ? std::string_view{s_local} : dbase );
609 if ( !cnt.empty() ) {
623 ref.container = ccnt;
void addClient(const IInterface *client)
Add new client to this data source.
virtual const std::string * par() const =0
Retrieve String parameters.
MergeSections m_mergeSects
Database section map for merged files.
Definition of the MsgStream class used to transmit messages.
TBranch * getBranch(std::string_view section, std::string_view branch_name)
Access data branch by name: Get existing branch in read only mode.
bool isActive() const
Accessor: is MsgStream active.
std::unique_ptr< Tool > m_tool
std::string m_name
Connection name/identifier.
IoType
I/O Connection types.
bool lookupClient(const IInterface *client) const
Lookup client for this data source.
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.
void saveStatistics(std::string_view statisticsFile)
Save TTree access statistics if required.
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.
int makeLink(std::string_view p)
Convert path string to path index.
std::string m_fid
File ID of the connection.
The category assigned to a StatusCode.
std::unique_ptr< TTreePerfStats > m_statistics
I/O read statistics from TTree.
int loadRefs(std::string_view section, std::string_view cnt, unsigned long entry, RootObjectRefs &refs)
Load references object.
static int compression()
Access to global compression level.
Clients m_clients
Client list.
constexpr static const auto SUCCESS
size_t removeClient(const IInterface *client)
Remove client from this data source.
GAUDI_API void fill(AIDA::IHistogram1D *histo, const double value, const double weight=1.0)
simple function to fill AIDA::IHistogram1D objects
const std::string & fid() const
Access file id.
virtual const name_type & name() const =0
Name of the directory (or key)
void setMessageSvc(MsgStream *m)
Set message service reference.
const std::string & getDb(int which) const
Access database/file name from saved index.
StatusCode connectWrite(IoType typ) override
Open data stream in write mode.
virtual long svcType() const =0
Retrieve service type.
Persistent reference object containing all leafs and links corresponding to a Gaudi DataObject.
StringVec m_links
Map containing internal links names.
MsgStream & msgSvc() const
Allow access to printer service.
ParamMap m_params
Parameter map for file parameters.
const long POOL_ROOTKEY_StorageType
const std::string & pfn() const
Access physical file name.
StringVec m_mergeFIDs
Map containing merge FIDs.
std::string m_pfn
Physical file name of the connection.
Persistent reference object.
static StatusCode setCompression(std::string_view compression)
Set the global compression level.
virtual void fireIncident(const Incident &incident)=0
Fire an Incident.
virtual const CLID & clID() const =0
Retrieve class information from link.
virtual std::string message(code_t code) const
Description for code within this category.
TTree * getSection(std::string_view sect, bool create=false)
Access TTree section from section name. The section is created if required.
#define STATUSCODE_ENUM_IMPL(...)
Assign a category to the StatusCode enum declared with STATUSCODE_ENUM_DECL( ENUM )
This class is used for returning status codes from appropriate routines.
Definition of the basic interface.
static const Category & default_category() noexcept
Default Gaudi StatusCode category.
const std::string & empty() const
Empty string reference.
StringVec m_conts
Map containing external container names.
const std::string & name() const
Connection name.
Sections m_sections
Tree sections in TFile.
The IRegistry represents the entry door to the environment any data object residing in a transient da...
const long ROOT_StorageType
const long POOL_ROOT_StorageType
Tool * makeTool()
Create file access tool to encapsulate POOL compatibiliy.
virtual IOpaqueAddress * address() const =0
Retrieve opaque storage address.
int loadObj(std::string_view section, std::string_view cnt, unsigned long entry, DataObject *&pObj)
Load object.
std::pair< const RootRef *, const ContainerSection * > getMergeSection(std::string_view container, int entry) const
Access link section for single container and entry.
void enableStatistics(std::string_view section)
Enable TTreePerStats.
const StatusCode & ignore() const
Ignore/check StatusCode.
StatusCode connectRead() override
Open data stream in read mode.
void badWriteError(std::string_view msg) const
Error handler when bad write statements occur.
virtual const CLID & clID() const
Retrieve reference to class definition structure.
ABC describing basic data connection.
const long POOL_ROOTTREE_StorageType
std::shared_ptr< RootConnectionSetup > m_setup
Reference to the setup structure.
LinkSections m_linkSects
Database link sections.
void resetAge()
Reset age.
Base class for all Incidents (computing events).
constexpr static const auto FAILURE
void makeRef(const IRegistry &pA, RootRef &ref)
Create reference object from registry entry.
RootDataConnection(const IInterface *own, std::string_view nam, std::shared_ptr< RootConnectionSetup > setup)
Standard constructor.
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.
void setIncidentSvc(IIncidentSvc *m)
Set incident service reference.
A DataObject is the base class of any identifiable object on any data store.
TTree * m_refs
Pointer to the reference tree.
Header file for std:chrono::duration-based Counters.
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.
The interface implemented by the IncidentSvc service.
unsigned long code_t
type of StatusCode value
T emplace_back(T... args)