ATLAS Offline Software
Loading...
Searching...
No Matches
RootTreeContainer.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4#ifndef ROOTTREECONTAINER_H
5#define ROOTTREECONTAINER_H 1
6
7// Framework include files
10
11#include <map>
12#include <string>
13#include <string_view>
14#include <vector>
15#include <memory>
16
17// Forward declarations
18class StatucCode;
19class TBranch;
20class TTree;
21class TLeaf;
22class TClass;
23
24namespace RootAuxDynIO {
27 class IFactoryTool;
28}
29
30class DbColumn;
31class RootDatabase;
32
46{
47 protected:
48
50 struct BranchDesc {
51 TClass* clazz = nullptr;
52 TBranch* branch = nullptr;
53 TLeaf* leaf = nullptr;
54 void* object = nullptr;
55 void* buffer = nullptr;
56 const DbColumn* column = nullptr;
57
58 // ---- extra variables used for AuxDyn attributes
59 // number of rows written to this branch so far
60 size_t rows_written = 0;
61
64 // AuxDyn writer and the reader for this branch (object type)
65 std::unique_ptr<RootAuxDynIO::IRootAuxDynWriter> auxdyn_writer;
66 std::unique_ptr<RootAuxDynIO::IRootAuxDynReader> auxdyn_reader;
67
68
69 BranchDesc() = default;
70 BranchDesc(TClass* cl, TBranch* b, TLeaf* l, void* o, const DbColumn* c);
71 BranchDesc(BranchDesc && other) = default;
72 BranchDesc(BranchDesc const& other) = delete;
73
74 BranchDesc& operator=(BranchDesc const& other) = delete;
75 BranchDesc& operator=(BranchDesc && other) = default;
76 };
77
79 typedef std::vector<BranchDesc> Branches;
80
82 TTree* m_tree;
92 std::string m_branchName;
99
101 std::unique_ptr<RootAuxDynIO::IFactoryTool> m_auxDynTool;
102
103 private:
104
106 StatusCode addBranch( const DbColumn* col,
107 BranchDesc& dsc,
108 std::string_view desc);
109
111 StatusCode addObject( DbDatabase& dbH,
112 const DbColumn* col,
113 BranchDesc& dsc,
114 const std::string& desc,
115 int splitLevel,
116 int bufferSize,
117 int branchOffsetTabLen);
118
119 // Routine needed for TRANSACT_FLUSH, if branch is specified by user.
120 StatusCode finishTransAct();
121
123 TBranch* branch(const std::string& nam) const;
124
126 void setBranchOffsetTabLen(TBranch* b, int offsettab_len);
127
128 public:
129 explicit RootTreeContainer(const std::string& name);
131
133 virtual StatusCode close() override;
134
136 virtual StatusCode open(DbDatabase& dbH,
137 const std::string& nam,
138 const DbTypeInfo* info,
139 Io::IoFlag mod) override;
140
142 virtual StatusCode checkAccess(DbDatabase& dbH,
143 const std::string& nam) const override final;
144
146
150 virtual StatusCode getOption(DbOption& opt) override;
151
153
157 virtual StatusCode setOption(const DbOption& opt) override;
158
160 virtual uint64_t size() override;
161
163 TTree* getTTree() { return m_tree; }
164
166 const std::string& getName() const { return m_name; }
167
169 bool isBranchContainer() const { return !m_branchName.empty(); }
170
172 void setTreeFillMode(bool mode);
173
175 bool usingTreeFillMode() const { return m_treeFillMode; }
176
178 bool isDirty() const { return m_isDirty; }
179
181 void clearDirty() { m_isDirty = false; }
182
184
190 virtual StatusCode loadObject( void** ptr, const DbTypeInfo* tinfo,
191 Token::OID_t& oid) override;
192
194 virtual StatusCode writeObject(ActionList::value_type&) override;
195
197 virtual StatusCode transAct(Transaction::Action action) override;
198};
199
200#endif
Description: Definition of the generic column in a (relational) Database.
Definition DbColumn.h:20
Description: Handle managing a DbDatabaseObj, a generic Database object.
Definition DbDatabase.h:39
Description: Definition an option to be supplied to database objects.
Definition DbOption.h:22
Definition of class DbTypeInfo.
Definition DbTypeInfo.h:31
Interface for an AuxDyn Writer - TTree based.
Description: ROOT specific implementation of Database file.
bool m_isDirty
flag set when a branch container was updated (but the branch was not Filled)
bool isBranchContainer() const
is this a container in a TBranch? (regular ones take the whole TTree)
virtual StatusCode writeObject(ActionList::value_type &) override
Commit single entry to container.
DbDatabase m_dbH
Parent Database handle.
bool isDirty() const
return true if this branch container was updated and it's TTree needs to be Filled
virtual StatusCode open(DbDatabase &dbH, const std::string &nam, const DbTypeInfo *info, Io::IoFlag mod) override
Open the container for object access.
virtual ~RootTreeContainer()
virtual StatusCode loadObject(void **ptr, const DbTypeInfo *tinfo, Token::OID_t &oid) override
Find object by object identifier and load it into memory.
StatusCode finishTransAct()
TTree * m_tree
Reference to the root tree object.
void setTreeFillMode(bool mode)
set Tree Filling mode (true/false) for branch containers
virtual StatusCode close() override
Close the container and deallocate resources.
std::vector< BranchDesc > Branches
Definition of the branch container.
void setBranchOffsetTabLen(TBranch *b, int offsettab_len)
Recursively set Offset Table length for a branch and it's subbranches.
const std::string & getName() const
return the name of the container
virtual StatusCode setOption(const DbOption &opt) override
Set options.
StatusCode addBranch(const DbColumn *col, BranchDesc &dsc, std::string_view desc)
Add item branch.
bool m_treeFillMode
if True, branch container will not use Branch->Fill() but will be filled with its Tree by the databas...
TBranch * branch(const std::string &nam) const
Access branch by name.
virtual uint64_t size() override
Number of entries within the container.
Branches m_branches
Branch map.
std::unique_ptr< RootAuxDynIO::IFactoryTool > m_auxDynTool
Factory object from AuxDynIO plugin that creates AuxDyn readers and writers.
virtual StatusCode checkAccess(DbDatabase &dbH, const std::string &nam) const override final
Check if we can access the container for reading with the given type.
bool usingTreeFillMode() const
return true if this branch container is using TTree Filling mode
const DbTypeInfo * m_type
reference to exact type description
virtual StatusCode transAct(Transaction::Action action) override
Execute Transaction action.
TTree * getTTree()
return the TTree in which this container is stored
int m_ioBytes
Number of bytes written/read during last operation. Set to -1 if it failed.
StatusCode addObject(DbDatabase &dbH, const DbColumn *col, BranchDesc &dsc, const std::string &desc, int splitLevel, int bufferSize, int branchOffsetTabLen)
Add BLOB.
RootDatabase * m_rootDb
Root database file reference.
std::string m_branchName
Branch name, if branch is specified by user.
RootTreeContainer(const std::string &name)
void clearDirty()
clear the dirty status (used after containing TTree was Filled)
virtual StatusCode getOption(DbOption &opt) override
Access options.
std::string m_name
Container name.
TechContainerBase(const std::string &name)
virtual std::string name() const override
Get container name.
Specialization of RootAuxDynStore for reading Aux Dynamic attributes from RNTuple.
Definiton of a branch descriptor.
std::unique_ptr< RootAuxDynIO::IRootAuxDynWriter > auxdyn_writer
BranchDesc & operator=(BranchDesc const &other)=delete
BranchDesc(BranchDesc &&other)=default
BranchDesc(TClass *cl, TBranch *b, TLeaf *l, void *o, const DbColumn *c)
std::unique_ptr< RootAuxDynIO::IRootAuxDynReader > auxdyn_reader
int aux_iostore_IFoffset
IOStore interface offset for object type in this branch (for casting).
BranchDesc & operator=(BranchDesc &&other)=default
BranchDesc(BranchDesc const &other)=delete