ATLAS Offline Software
Loading...
Searching...
No Matches
RootDatabase.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 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
16#include "GaudiKernel/SmartIF.h"
19#include "StorageSvc/DbPrint.h"
20
21// ROOT include files
22#include "ROOT/RNTupleReader.hxx"
23
24#include <optional>
25#include <set>
26#include <map>
27#include <mutex>
28#include <unordered_map>
29
30// Forward declarations
31class StatusCode;
32
33class TFile;
34class TTree;
35class TBranch;
36class IFileMgr;
37namespace RootAuxDynIO {
39}
40namespace RootStorageSvc {
42}
43
44/*
45 * POOL namespace declaration
46 */
47namespace pool {
49
59 class RootDatabase : public IDbDatabase, public APRMessaging
60 {
61 public:
63
64 private:
68 TFile* m_file;
70 std::string m_version;
72 long long int m_counters[3];
101
103 std::string m_indexMaster;
106
108 std::map<TBranch*, uint64_t> m_indexSizeMap;
109
111 std::set< std::string > m_indexRebuilt;
112
113 /* --- variables used with TREE_AUTO_FLUSH option for
114 managing combined TTree::Fill for branch containers
115 */
116 // TTree names with requested AUTO_FLUSH value
117 std::map< std::string, int > m_autoFlushTrees;
118
119 // mapping of opened (for update) branch containers, to their TTree
120 typedef std::set< RootTreeContainer* > ContainerSet_t;
121 std::map< TTree*, ContainerSet_t > m_containersInTree;
122
123 std::map< std::string, int > m_customSplitLevel;
124
125 SmartIF<IFileMgr> m_fileMgr;
126
127 // mutex to prevent concurrent read I/O from AuxDynReader
128 std::recursive_mutex m_iomutex;
129
130 std::map<std::string, std::unique_ptr<RootStorageSvc::RNTupleWriterHelper> > m_ntupleWriterMap;
131 std::map<std::string, std::unique_ptr<ROOT::RNTupleReader> > m_ntupleReaderMap;
132
133 using indexLookup_t = std::unordered_map<uint64_t, uint64_t>;
134 std::map<void*, indexLookup_t> m_ntupleIndexMap;
135
136 // RootDatabase currently holds an optional slot-specific active entry token for the main event data container
137 std::optional<SG::SlotSpecificObj<std::unique_ptr<ROOT::RNTupleReader::RActiveEntryToken>>> m_activeEntryTokenPtr;
138
139 public:
142
144 virtual ~RootDatabase();
145
147 TFile* file() { return m_file; }
149 std::string name() const;
150
152 TTree* getTree(const std::string& name);
153
155 const std::string& fmtVersion() const { return m_version; }
156
158
162 static bool exists(const std::string& nam);
163
165 virtual long long int size() const;
166
168 void addByteCount(int which, long long int num_bytes);
169
171 long long int byteCount(int which) const;
172
173
175
177
178 uint64_t currentIndexMasterID() const { return m_indexMasterID; }
179
181 uint64_t indexSize(TBranch *branch) { return m_indexSizeMap[branch]; }
182
184 uint64_t indexSizeInc(TBranch *branch) { return ++m_indexSizeMap[branch]; }
185
186
188 bool wasIndexRebuilt(const std::string& treeName) { return m_indexRebuilt.count(treeName)!=0; }
190 void markIndexRebuilt(const std::string& treeName) { m_indexRebuilt.insert(treeName); };
191
193 std::recursive_mutex& ioMutex() { return m_iomutex; }
194
196
200 virtual StatusCode getOption(DbOption& opt);
201
203
207 virtual StatusCode setOption(const DbOption& opt);
208
210 virtual StatusCode setAutoFlush(const DbOption& opt);
211
213
220 virtual StatusCode open(const DbDomain& domH,
221 const std::string& nam,
222 Io::IoFlag mode);
223
225
230 virtual StatusCode onOpen(DbDatabase& dbH, Io::IoFlag mode);
231
233
237 virtual StatusCode close(Io::IoFlag mode);
238
240 virtual StatusCode transAct(Transaction::Action action);
241
243 ROOT::RNTupleReader* getNTupleReader(const std::string& ntuple_name);
244
245 // translate index value to row# for a given RNTuple
246 uint64_t indexLookup(ROOT::RNTupleReader *ps, uint64_t idx_val);
247
250 RootStorageSvc::RNTupleWriterHelper* getNTupleWriter(const std::string& ntuple_name, bool create=false);
251
252 protected:
253 // Execute any pending Fills before commit or flush
255
256 // Reduce branches' baskets' size to m_maxBufferSize for a give TTree
258
260
261 StatusCode close();
262
263 void printErrno(const char* nam, int err);
264 };
265
266} // End namespace pool
267#endif /* POOL_ROOTSTORAGESVC_ROOTDBASE_H */
Maintain a set of objects, one per slot.
APRMessaging(const std::string &name)
Description: Handle managing a DbDatabaseObj, a generic Database object.
Definition DbDatabase.h:54
Description:
Definition DbDomain.h:47
Description: Definition an option to be supplied to database objects.
Definition DbOption.h:36
IDbDatabase interface.
Definition IDbDatabase.h:41
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.
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
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.
StatusCode fillBranchContainerTrees()
std::optional< SG::SlotSpecificObj< std::unique_ptr< ROOT::RNTupleReader::RActiveEntryToken > > > m_activeEntryTokenPtr
void registerBranchContainer(RootTreeContainer *)
static bool exists(const std::string &nam)
Check for file-existence.
virtual StatusCode open(const DbDomain &domH, const std::string &nam, Io::IoFlag mode)
Open Database object.
int m_rntWriterMetricsEnabled
Flag to enable/disable RNTupleWriter metrics.
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.
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)
virtual StatusCode onOpen(DbDatabase &dbH, Io::IoFlag mode)
Callback after successful open of a database object.
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
virtual StatusCode close(Io::IoFlag mode)
Close database access.
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.
::StatusCode StatusCode
StatusCode definition for legacy code.
Specialization of RootAuxDynStore for reading Aux Dynamic attributes from RNTuple.
Framework include files.
Definition libname.h:15
TChain * tree