ATLAS Offline Software
Loading...
Searching...
No Matches
RootDatabase.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5//====================================================================
6//
7// Package : RootStorageSvc (The POOL project)
8//
9// Author : M.Frank
10//====================================================================
11#ifndef POOL_ROOTSTORAGESVC_ROOTDBASE_H
12#define POOL_ROOTSTORAGESVC_ROOTDBASE_H 1
13
14// Framework include files
15#include "GaudiKernel/SmartIF.h"
18#include "POOLCore/DbPrint.h"
19
20#include <set>
21#include <map>
22#include <mutex>
23#include <unordered_map>
24
25// Forward declarations
26namespace ROOT { class RNTupleReader; }
27
28class TFile;
29class TTree;
30class TBranch;
31class IFileMgr;
32namespace RootAuxDynIO {
34}
35namespace RootStorageSvc {
37}
38
39/*
40 * POOL namespace declaration
41 */
42namespace pool {
44
54 class RootDatabase : public IDbDatabase, public APRMessaging
55 {
56 public:
58
59 private:
63 TFile* m_file;
65 std::string m_version;
67 long long int m_counters[3];
96
98 std::string m_indexMaster;
101
103 std::map<TBranch*, uint64_t> m_indexSizeMap;
104
106 std::set< std::string > m_indexRebuilt;
107
108 /* --- variables used with TREE_AUTO_FLUSH option for
109 managing combined TTree::Fill for branch containers
110 */
111 // TTree names with requested AUTO_FLUSH value
112 std::map< std::string, int > m_autoFlushTrees;
113
114 // mapping of opened (for update) branch containers, to their TTree
115 typedef std::set< RootTreeContainer* > ContainerSet_t;
116 std::map< TTree*, ContainerSet_t > m_containersInTree;
117
118 std::map< std::string, int > m_customSplitLevel;
119
120 SmartIF<IFileMgr> m_fileMgr;
121
122 // mutex to prevent concurrent read I/O from AuxDynReader
123 std::recursive_mutex m_iomutex;
124
125 std::map<std::string, std::unique_ptr<RootStorageSvc::RNTupleWriterHelper> > m_ntupleWriterMap;
126 std::map<std::string, std::unique_ptr<ROOT::RNTupleReader> > m_ntupleReaderMap;
127
128 using indexLookup_t = std::unordered_map<uint64_t, uint64_t>;
129 std::map<void*, indexLookup_t> m_ntupleIndexMap;
130
131 public:
134
136 virtual ~RootDatabase();
137
139 TFile* file() { return m_file; }
141 std::string name() const;
142
144 TTree* getTree(const std::string& name);
145
147 const std::string& fmtVersion() const { return m_version; }
148
150
154 static bool exists(const std::string& nam);
155
157 virtual long long int size() const;
158
160 void addByteCount(int which, long long int num_bytes);
161
163 long long int byteCount(int which) const;
164
165
167
169
170 uint64_t currentIndexMasterID() const { return m_indexMasterID; }
171
173 uint64_t indexSize(TBranch *branch) { return m_indexSizeMap[branch]; }
174
176 uint64_t indexSizeInc(TBranch *branch) { return ++m_indexSizeMap[branch]; }
177
178
180 bool wasIndexRebuilt(const std::string& treeName) { return m_indexRebuilt.count(treeName)!=0; }
182 void markIndexRebuilt(const std::string& treeName) { m_indexRebuilt.insert(treeName); };
183
185 std::recursive_mutex& ioMutex() { return m_iomutex; }
186
188
193
195
199 virtual DbStatus setOption(const DbOption& opt);
200
202 virtual DbStatus setAutoFlush(const DbOption& opt);
203
205
212 virtual DbStatus open(const DbDomain& domH,
213 const std::string& nam,
214 DbAccessMode mode);
215
217
222
224
230
232
237
240
242 ROOT::RNTupleReader* getNTupleReader(const std::string& ntuple_name);
243
244 // translate index value to row# for a given RNTuple
245 uint64_t indexLookup(ROOT::RNTupleReader *ps, uint64_t idx_val);
246
249 RootStorageSvc::RNTupleWriterHelper* getNTupleWriter(const std::string& ntuple_name, bool create=false);
250
251 protected:
252 // Execute any pending Fills before commit or flush
254
255 // Reduce branches' baskets' size to m_maxBufferSize for a give TTree
257
259
261
262 void printErrno(const char* nam, int err);
263 };
264
265} // End namespace pool
266#endif /* POOL_ROOTSTORAGESVC_ROOTDBASE_H */
APRMessaging(const std::string &name)
Description: Handle managing a DbDatabaseObj, a generic Database object.
Definition DbDatabase.h:53
Description:
Definition DbDomain.h:47
Description: Definition an option to be supplied to database objects.
Definition DbOption.h:36
This class is highly inspired by the error code distribution system as it is used in DEC/VMS or MS/WN...
Definition DbStatus.h:64
IDbDatabase interface.
Definition IDbDatabase.h:41
virtual DbStatus onOpen(DbDatabase &dbH, DbAccessMode mode)
Callback after successful open of a database object.
int m_defCompressionAlg
Default compression algorithm.
virtual long long int size() const
Access the size of the database: May be undefined for some technologies.
int m_rntReaderMetricsEnabled
Flag to enable/disable RNTupleReader metrics.
std::set< std::string > m_indexRebuilt
marks if the index (for index Containers) was rebuilt for given TTree
void markIndexRebuilt(const std::string &treeName)
Mark that a given TTree had its index rebuilt.
TTree * getTree(const std::string &name)
Get TTree by name from the TFile.
DbStatus markBranchContainerForFill(RootTreeContainer *)
long long int m_counters[3]
Counter statistics.
virtual DbStatus open(const DbDomain &domH, const std::string &nam, DbAccessMode mode)
Open Database object.
int m_defTreeCacheLearnEvents
Default tree cache learn events.
virtual DbStatus setOption(const DbOption &opt)
Set options.
std::string m_version
Persistency format version.
std::map< std::string, int > m_customSplitLevel
std::string m_indexMaster
name of the container with master index ('*' means use the biggest)
int m_rntBufferedWriteEnabled
Flag to enable/disable buffered RNTuple writing.
long long int byteCount(int which) const
Do some statistics: retrieve number of bytes read/written/other.
int m_defSplitLevel
Default split level.
TFile * file()
Access to the actual implemented file.
uint64_t m_indexMasterID
nextID of the master index
virtual DbStatus reopen(DbAccessMode mode)
Re-open database with changing access permissions.
virtual ~RootDatabase()
Standard destructor.
RootStorageSvc::RNTupleWriterHelper * getNTupleWriter(const std::string &ntuple_name, bool create=false)
Return RNTupleWriterHelper for a given ntuple_name create a new one if needed when create==true.
ROOT::RNTupleReader * getNTupleReader(const std::string &ntuple_name)
return RNTupleReader for a given ntuple_name
SmartIF< IFileMgr > m_fileMgr
std::map< std::string, int > m_autoFlushTrees
std::map< std::string, std::unique_ptr< RootStorageSvc::RNTupleWriterHelper > > m_ntupleWriterMap
int m_defBufferSize
Default buffer size parameter for Branches.
int m_defCompression
Default compression level.
void reduceBasketsSize(TTree *tree)
DbDatabase m_dbH
Parent Database handle.
std::map< TBranch *, uint64_t > m_indexSizeMap
Keep index sizes here, because Branches are emptied when fast merged by SharedWriter.
uint64_t indexSizeInc(TBranch *branch)
increase index size counter for indexed containers (by 1)
bool wasIndexRebuilt(const std::string &treeName)
Check if a given TTree had its index rebuilt.
std::map< std::string, std::unique_ptr< ROOT::RNTupleReader > > m_ntupleReaderMap
int m_minBufferEntries
Minimum buffer entries parameter for Branches.
virtual DbStatus setAutoFlush(const DbOption &opt)
implementation of TREE_AUTO_FLUSH option - called from setOption()
void registerBranchContainer(RootTreeContainer *)
static bool exists(const std::string &nam)
Check for file-existence.
DbStatus fillBranchContainerTrees()
int m_rntWriterMetricsEnabled
Flag to enable/disable RNTupleWriter metrics.
virtual DbStatus getOption(DbOption &opt)
Access options.
int m_maxBufferSize
Maximum buffer size parameter for Branches.
TFile * m_file
Reference to the actual implemented file.
int m_defAutoSave
Default Autosave parameter for trees.
int m_branchOffsetTabLen
Offset table length for branches.
std::string name() const
Get the DB name (here it is the TFile name)
std::map< void *, indexLookup_t > m_ntupleIndexMap
void addByteCount(int which, long long int num_bytes)
Do some statistics: add number of bytes read/written/other.
virtual DbStatus transAct(Transaction::Action action)
Execute Database Transaction action.
std::set< RootTreeContainer * > ContainerSet_t
std::map< TTree *, ContainerSet_t > m_containersInTree
std::recursive_mutex & ioMutex()
provide access to the I/O mutex for AuxDynReader and Containers
void increaseBasketsSize(TTree *tree)
uint64_t indexLookup(ROOT::RNTupleReader *ps, uint64_t idx_val)
uint64_t indexSize(TBranch *branch)
get index size for indexed containers
const std::string & fmtVersion() const
Access to the version string.
virtual DbStatus close(DbAccessMode mode)
Close database access.
std::unordered_map< uint64_t, uint64_t > indexLookup_t
void printErrno(const char *nam, int err)
uint64_t currentIndexMasterID() const
std::recursive_mutex m_iomutex
RootDatabase()
Standard Constructor.
int m_defWritePolicy
Default policy mode for keyed objects.
std::string m_treeNameWithCache
Name of tree with cache.
Description: ROOT specific implementation of Database container.
Selection rules: declare transient members.
Definition DataVector.h:581
Specialization of RootAuxDynStore for reading Aux Dynamic attributes from RNTuple.
pool namespace
Definition libname.h:15
TChain * tree