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
26class StatusCode;
27namespace ROOT { class RNTupleReader; }
28
29class TFile;
30class TTree;
31class TBranch;
32class IFileMgr;
33namespace RootAuxDynIO {
35}
36namespace RootStorageSvc {
38}
39
40/*
41 * POOL namespace declaration
42 */
43namespace pool {
45
55 class RootDatabase : public IDbDatabase, public APRMessaging
56 {
57 public:
59
60 private:
64 TFile* m_file;
66 std::string m_version;
68 long long int m_counters[3];
99
101 std::string m_indexMaster;
104
106 std::map<TBranch*, uint64_t> m_indexSizeMap;
107
109 std::set< std::string > m_indexRebuilt;
110
111 /* --- variables used with TREE_AUTO_FLUSH option for
112 managing combined TTree::Fill for branch containers
113 */
114 // TTree names with requested AUTO_FLUSH value
115 std::map< std::string, int > m_autoFlushTrees;
116
117 // mapping of opened (for update) branch containers, to their TTree
118 typedef std::set< RootTreeContainer* > ContainerSet_t;
119 std::map< TTree*, ContainerSet_t > m_containersInTree;
120
121 std::map< std::string, int > m_customSplitLevel;
122
123 SmartIF<IFileMgr> m_fileMgr;
124
125 // mutex to prevent concurrent read I/O from AuxDynReader
126 std::recursive_mutex m_iomutex;
127
128 std::map<std::string, std::unique_ptr<RootStorageSvc::RNTupleWriterHelper> > m_ntupleWriterMap;
129 std::map<std::string, std::unique_ptr<ROOT::RNTupleReader> > m_ntupleReaderMap;
130
131 using indexLookup_t = std::unordered_map<uint64_t, uint64_t>;
132 std::map<void*, indexLookup_t> m_ntupleIndexMap;
133
134 public:
137
139 virtual ~RootDatabase();
140
142 TFile* file() { return m_file; }
144 std::string name() const;
145
147 TTree* getTree(const std::string& name);
148
150 const std::string& fmtVersion() const { return m_version; }
151
153
157 static bool exists(const std::string& nam);
158
160 virtual long long int size() const;
161
163 void addByteCount(int which, long long int num_bytes);
164
166 long long int byteCount(int which) const;
167
168
170
172
173 uint64_t currentIndexMasterID() const { return m_indexMasterID; }
174
176 uint64_t indexSize(TBranch *branch) { return m_indexSizeMap[branch]; }
177
179 uint64_t indexSizeInc(TBranch *branch) { return ++m_indexSizeMap[branch]; }
180
181
183 bool wasIndexRebuilt(const std::string& treeName) { return m_indexRebuilt.count(treeName)!=0; }
185 void markIndexRebuilt(const std::string& treeName) { m_indexRebuilt.insert(treeName); };
186
188 std::recursive_mutex& ioMutex() { return m_iomutex; }
189
191
195 virtual StatusCode getOption(DbOption& opt);
196
198
202 virtual StatusCode setOption(const DbOption& opt);
203
205 virtual StatusCode setAutoFlush(const DbOption& opt);
206
208
215 virtual StatusCode open(const DbDomain& domH,
216 const std::string& nam,
217 DbAccessMode mode);
218
220
224 virtual StatusCode reopen(DbAccessMode mode);
225
227
232 virtual StatusCode onOpen(DbDatabase& dbH, DbAccessMode mode);
233
235
239 virtual StatusCode close(DbAccessMode mode);
240
242 virtual StatusCode transAct(Transaction::Action action);
243
245 ROOT::RNTupleReader* getNTupleReader(const std::string& ntuple_name);
246
247 // translate index value to row# for a given RNTuple
248 uint64_t indexLookup(ROOT::RNTupleReader *ps, uint64_t idx_val);
249
252 RootStorageSvc::RNTupleWriterHelper* getNTupleWriter(const std::string& ntuple_name, bool create=false);
253
254 protected:
255 // Execute any pending Fills before commit or flush
257
258 // Reduce branches' baskets' size to m_maxBufferSize for a give TTree
260
262
263 StatusCode close();
264
265 void printErrno(const char* nam, int err);
266 };
267
268} // End namespace pool
269#endif /* POOL_ROOTSTORAGESVC_ROOTDBASE_H */
APRMessaging(const std::string &name)
Description: Handle managing a DbDatabaseObj, a generic Database object.
Definition DbDatabase.h:55
Description:
Definition DbDomain.h:47
Description: Definition an option to be supplied to database objects.
Definition DbOption.h:37
IDbDatabase interface.
Definition IDbDatabase.h:42
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.
long long int m_counters[3]
Counter statistics.
int m_defTreeCacheLearnEvents
Default tree cache learn events.
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)
virtual StatusCode setAutoFlush(const DbOption &opt)
implementation of TREE_AUTO_FLUSH option - called from setOption()
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 ~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
virtual StatusCode setOption(const DbOption &opt)
Set options.
std::map< std::string, int > m_autoFlushTrees
std::map< std::string, std::unique_ptr< RootStorageSvc::RNTupleWriterHelper > > m_ntupleWriterMap
virtual StatusCode reopen(DbAccessMode mode)
Re-open database with changing access permissions.
int m_defBufferSize
Default buffer size parameter for Branches.
virtual StatusCode transAct(Transaction::Action action)
Execute Database Transaction action.
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
std::string m_rntUnsplitFieldList
Comma separated list of unsplit field patterns for RNTupleWriter.
int m_minBufferEntries
Minimum buffer entries parameter for Branches.
virtual StatusCode open(const DbDomain &domH, const std::string &nam, DbAccessMode mode)
Open Database object.
StatusCode fillBranchContainerTrees()
void registerBranchContainer(RootTreeContainer *)
static bool exists(const std::string &nam)
Check for file-existence.
int m_rntWriterMetricsEnabled
Flag to enable/disable RNTupleWriter metrics.
virtual StatusCode onOpen(DbDatabase &dbH, DbAccessMode mode)
Callback after successful open of a database object.
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.
virtual StatusCode getOption(DbOption &opt)
Access options.
virtual StatusCode close(DbAccessMode mode)
Close database access.
int m_branchOffsetTabLen
Offset table length for branches.
StatusCode close()
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.
StatusCode markBranchContainerForFill(RootTreeContainer *)
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.
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