ATLAS Offline Software
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 "StorageSvc/IDbDatabase.h"
16 #include "StorageSvc/DbDatabase.h"
17 
18 #include <set>
19 #include <map>
20 #include <mutex>
21 #include <unordered_map>
22 
23 // Forward declarations
24 namespace ROOT { namespace Experimental {
25  class RNTupleReader;
26 } }
27 
28 
29 class TFile;
30 class TTree;
31 class TBranch;
32 class IFileMgr;
33 namespace RootAuxDynIO {
34  class IRootAuxDynReader;
35 }
36 namespace RootStorageSvc {
37  class RNTupleWriterHelper;
38 }
39 
40 /*
41  * POOL namespace declaration
42  */
43 namespace pool {
45 
46  class RootTreeContainer;
47 
57  class RootDatabase : public IDbDatabase
58  {
59  public:
60  enum { READ_COUNTER = 0, WRITE_COUNTER = 1, OTHER_COUNTER = 2 };
61 
62  private:
66  TFile* m_file;
68  std::string m_version;
70  long long int m_counters[3];
90  std::string m_treeNameWithCache;
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  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<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; }
143 
145  TTree* getTree(const std::string& name);
146 
148  const std::string& fmtVersion() const { return m_version; }
149 
151 
155  static bool exists(const std::string& nam);
156 
158  virtual long long int size() const;
159 
161  void addByteCount(int which, long long int num_bytes);
162 
164  long long int byteCount(int which) const;
165 
166 
168 
170 
172 
175 
178 
179 
181  bool wasIndexRebuilt(const std::string& treeName) { return m_indexRebuilt.count(treeName)!=0; }
183  void markIndexRebuilt(const std::string& treeName) { m_indexRebuilt.insert(treeName); };
184 
186  std::recursive_mutex& ioMutex() { return m_iomutex; }
187 
189 
194 
196 
200  virtual DbStatus setOption(const DbOption& opt);
201 
204 
206 
213  virtual DbStatus open(const DbDomain& domH,
214  const std::string& nam,
216 
218 
223 
225 
231 
233 
238 
241 
243  RNTupleReader* getNTupleReader(const std::string& ntuple_name);
244 
245  // translate index value to row# for a given RNTuple
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
257  void reduceBasketsSize(TTree* tree);
258 
259  void increaseBasketsSize(TTree* tree);
260 
262  };
263 
264 } // End namespace pool
265 #endif /* POOL_ROOTSTORAGESVC_ROOTDBASE_H */
pool::RootDatabase::RootDatabase
RootDatabase()
Standard Constructor.
pool::RootDatabase::increaseBasketsSize
void increaseBasketsSize(TTree *tree)
pool::DbAccessMode
int DbAccessMode
Definition: Database/APR/StorageSvc/StorageSvc/pool.h:47
pool::RootDatabase::setOption
virtual DbStatus setOption(const DbOption &opt)
Set options.
pool::RootDatabase::transAct
virtual DbStatus transAct(Transaction::Action action)
Execute Database Transaction action.
pool::RootDatabase::READ_COUNTER
@ READ_COUNTER
Definition: RootDatabase.h:60
pool::RootDatabase::close
virtual DbStatus close(DbAccessMode mode)
Close database access.
pool::RootDatabase::m_customSplitLevel
std::map< std::string, int > m_customSplitLevel
Definition: RootDatabase.h:121
pool::DbStatus
Definition: DbStatus.h:67
pool::RootDatabase::currentIndexMasterID
uint64_t currentIndexMasterID() const
Definition: RootDatabase.h:171
pool::RootDatabase::m_branchOffsetTabLen
int m_branchOffsetTabLen
Offset table length for branches.
Definition: RootDatabase.h:88
IDbDatabase.h
pool::RootDatabase::m_defTreeCacheLearnEvents
int m_defTreeCacheLearnEvents
Default tree cache learn events.
Definition: RootDatabase.h:92
pool::RootDatabase::m_ntupleReaderMap
std::map< std::string, std::unique_ptr< RNTupleReader > > m_ntupleReaderMap
Definition: RootDatabase.h:129
pool::RootDatabase::m_maxBufferSize
int m_maxBufferSize
Maximum buffer size parameter for Branches.
Definition: RootDatabase.h:82
pool::RootDatabase::m_indexRebuilt
std::set< std::string > m_indexRebuilt
marks if the index (for index Containers) was rebuilt for given TTree
Definition: RootDatabase.h:109
pool::RootDatabase::size
virtual long long int size() const
Access the size of the database: May be undefined for some technologies.
pool::RootDatabase::m_defSplitLevel
int m_defSplitLevel
Default split level.
Definition: RootDatabase.h:76
pool::RootDatabase::m_indexMasterID
uint64_t m_indexMasterID
nextID of the master index
Definition: RootDatabase.h:103
pool::RootDatabase::WRITE_COUNTER
@ WRITE_COUNTER
Definition: RootDatabase.h:60
pool::RootDatabase::m_indexSizeMap
std::map< TBranch *, uint64_t > m_indexSizeMap
Keep index sizes here, because Branches are emptied when fast merged by SharedWriter.
Definition: RootDatabase.h:106
pool::RootDatabase::m_ntupleWriterMap
std::map< std::string, std::unique_ptr< RootStorageSvc::RNTupleWriterHelper > > m_ntupleWriterMap
Definition: RootDatabase.h:128
pool::RootDatabase::fillBranchContainerTrees
DbStatus fillBranchContainerTrees()
tree
TChain * tree
Definition: tile_monitor.h:30
pool
pool namespace
Definition: libname.h:15
pool::RootDatabase::m_containersInTree
std::map< TTree *, ContainerSet_t > m_containersInTree
Definition: RootDatabase.h:119
pool::RootCollection::RNTupleReader
ROOT::Experimental::RNTupleReader RNTupleReader
Definition: RNTCollection.h:37
pool::RootDatabase::m_dbH
DbDatabase m_dbH
Parent Database handle.
Definition: RootDatabase.h:64
pool::RootDatabase::OTHER_COUNTER
@ OTHER_COUNTER
Definition: RootDatabase.h:60
pool::RootDatabase::m_defCompressionAlg
int m_defCompressionAlg
Default compression algorithm.
Definition: RootDatabase.h:74
pool::RootDatabase::m_rntReaderMetricsEnabled
int m_rntReaderMetricsEnabled
Flag to enable/disable RNTupleReader metrics.
Definition: RootDatabase.h:96
pool::RootDatabase::m_indexMaster
std::string m_indexMaster
name of the container with master index ('*' means use the biggest)
Definition: RootDatabase.h:101
pool::RootDatabase::getNTupleReader
RNTupleReader * getNTupleReader(const std::string &ntuple_name)
return RNTupleReader for a given ntuple_name
pool::RootDatabase::close
DbStatus close()
pool::RootDatabase::m_defWritePolicy
int m_defWritePolicy
Default policy mode for keyed objects.
Definition: RootDatabase.h:86
DbDatabase.h
pool::RootDatabase::m_ntupleIndexMap
std::map< void *, indexLookup_t > m_ntupleIndexMap
Definition: RootDatabase.h:132
pool::RootDatabase::wasIndexRebuilt
bool wasIndexRebuilt(const std::string &treeName)
Check if a given TTree had its index rebuilt.
Definition: RootDatabase.h:181
pool::RootDatabase::m_counters
long long int m_counters[3]
Counter statistics.
Definition: RootDatabase.h:70
pool::RootDatabase::m_rntWriterMetricsEnabled
int m_rntWriterMetricsEnabled
Flag to enable/disable RNTupleWriter metrics.
Definition: RootDatabase.h:98
pool::IDbDatabase
Definition: IDbDatabase.h:41
pool::RootDatabase::ioMutex
std::recursive_mutex & ioMutex()
provide access to the I/O mutex for AuxDynReader and Containers
Definition: RootDatabase.h:186
RNTupleReader
ROOT::Experimental::RNTupleReader RNTupleReader
Definition: RNTCollectionSchemaEditor.h:21
pool::DbOption
Definition: DbOption.h:36
pool::RootDatabase::registerBranchContainer
void registerBranchContainer(RootTreeContainer *)
pool::RootDatabase::getNTupleWriter
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.
pool::RootDatabase::byteCount
long long int byteCount(int which) const
Do some statistics: retrieve number of bytes read/written/other.
pool::RootDatabase::m_defBufferSize
int m_defBufferSize
Default buffer size parameter for Branches.
Definition: RootDatabase.h:80
pool::RootDatabase::m_iomutex
std::recursive_mutex m_iomutex
Definition: RootDatabase.h:126
pool::RootDatabase::file
TFile * file()
Access to the actual implemented file.
Definition: RootDatabase.h:142
dumpFileToPlots.treeName
string treeName
Definition: dumpFileToPlots.py:20
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
Preparation.mode
mode
Definition: Preparation.py:95
pool::RootDatabase::reopen
virtual DbStatus reopen(DbAccessMode mode)
Re-open database with changing access permissions.
python.Utils.unixtools.which
def which(filename, env=os.environ)
UNIX-style which ---------------------------------------------------------—.
Definition: unixtools.py:39
pool::RootTreeContainer
Definition: RootTreeContainer.h:60
pool::RootDatabase::addByteCount
void addByteCount(int which, long long int num_bytes)
Do some statistics: add number of bytes read/written/other.
pool::RootDatabase::indexSize
uint64_t indexSize(TBranch *branch)
get index size for indexed containers
Definition: RootDatabase.h:174
pool::RootDatabase::~RootDatabase
virtual ~RootDatabase()
Standard destructor.
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
pmontree.opt
opt
Definition: pmontree.py:16
pool::RootDatabase::indexLookup_t
std::unordered_map< uint64_t, uint64_t > indexLookup_t
Definition: RootDatabase.h:131
pool::Transaction::Action
Action
Definition: Transaction.h:34
pool::RootDatabase::m_minBufferEntries
int m_minBufferEntries
Minimum buffer entries parameter for Branches.
Definition: RootDatabase.h:84
pool::RootDatabase::markBranchContainerForFill
DbStatus markBranchContainerForFill(RootTreeContainer *)
RootAuxDynIO
Specialization of RootAuxDynStore for reading Aux Dynamic attributes from RNTuple.
Definition: RNTupleContainer.h:25
pool::RootDatabase::reduceBasketsSize
void reduceBasketsSize(TTree *tree)
pool::RootDatabase::open
virtual DbStatus open(const DbDomain &domH, const std::string &nam, DbAccessMode mode)
Open Database object.
pool::DbDomain
Definition: DbDomain.h:47
pool::RootDatabase::getTree
TTree * getTree(const std::string &name)
Get TTree by name from the TFile.
RTTAlgmain.branch
branch
Definition: RTTAlgmain.py:61
pool::RootDatabase::m_rntBufferedWriteEnabled
int m_rntBufferedWriteEnabled
Flag to enable/disable buffered RNTuple writing.
Definition: RootDatabase.h:94
pool::RootDatabase::m_file
TFile * m_file
Reference to the actual implemented file.
Definition: RootDatabase.h:66
pool::RootDatabase::onOpen
virtual DbStatus onOpen(DbDatabase &dbH, DbAccessMode mode)
Callback after successful open of a database object.
RootStorageSvc::RNTupleWriterHelper
Definition: RNTupleWriterHelper.h:36
pool::RootDatabase::fmtVersion
const std::string & fmtVersion() const
Access to the version string.
Definition: RootDatabase.h:148
pool::RootDatabase
Definition: RootDatabase.h:58
pool::RootDatabase::m_defAutoSave
int m_defAutoSave
Default Autosave parameter for trees.
Definition: RootDatabase.h:78
python.CaloScaleNoiseConfig.action
action
Definition: CaloScaleNoiseConfig.py:77
pool::RootDatabase::indexLookup
uint64_t indexLookup(RNTupleReader *ps, uint64_t idx_val)
pool::RootDatabase::m_autoFlushTrees
std::map< std::string, int > m_autoFlushTrees
Definition: RootDatabase.h:115
pool::RootDatabase::getOption
virtual DbStatus getOption(DbOption &opt)
Access options.
pool::RootDatabase::m_defCompression
int m_defCompression
Default compression level.
Definition: RootDatabase.h:72
pool::RootDatabase::markIndexRebuilt
void markIndexRebuilt(const std::string &treeName)
Mark that a given TTree had its index rebuilt.
Definition: RootDatabase.h:183
pool::RootDatabase::m_version
std::string m_version
Persistency format version.
Definition: RootDatabase.h:68
pool::RootDatabase::exists
static bool exists(const std::string &nam)
Check for file-existence.
pool::DbDatabase
Definition: DbDatabase.h:53
pool::RootDatabase::setAutoFlush
virtual DbStatus setAutoFlush(const DbOption &opt)
implementation of TREE_AUTO_FLUSH option - called from setOption()
pool::RootDatabase::indexSizeInc
uint64_t indexSizeInc(TBranch *branch)
increase index size counter for indexed containers (by 1)
Definition: RootDatabase.h:177
pool::RootDatabase::ContainerSet_t
std::set< RootTreeContainer * > ContainerSet_t
Definition: RootDatabase.h:118
RootStorageSvc
Definition: RNTupleContainer.h:26
ROOT
Definition: ViewVectorBaseStreamer.cxx:43
pool::RootDatabase::m_treeNameWithCache
std::string m_treeNameWithCache
Name of tree with cache.
Definition: RootDatabase.h:90
pool::RootDatabase::m_fileMgr
IFileMgr * m_fileMgr
Definition: RootDatabase.h:123