ATLAS Offline Software
Loading...
Searching...
No Matches
RNTupleContainer.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4//====================================================================
5// Root Database Container RNTuple implementation
6//--------------------------------------------------------------------
7// Author : M.Nowak
8//====================================================================
9#ifndef POOL_RNTUPLECONTAINER_H
10#define POOL_RNTUPLECONTAINER_H 1
11
12// Framework include files
13#include "StorageSvc/DbColumn.h"
16
18
19#include "ROOT/RNTupleView.hxx"
20
21#include <memory>
22#include <optional>
23#include <string>
24#include <vector>
25
26// Forward declarations
27class TClass;
30namespace ROOT { class RNTupleReader; }
31namespace pool { class RootDatabase; }
32
38
40{
42 struct FieldDesc : public pool::DbColumn
43 {
44 std::string fieldname;
45 std::optional< ROOT::RNTupleView<void> > view;
46 std::string sgkey;
47 TClass* clazz = nullptr;
48 void* object = nullptr;
49
50 // if writing char* keep a copy here as an std::string
51 std::string str;
52
53 // ---- extra variables used for AuxDyn attributes
54 // number of rows written to this branch so far
55 size_t rows_written = 0;
56
57 // AuxDyn RNTuple reader (managed by the Database)
58 std::unique_ptr<RootAuxDynIO::IRootAuxDynReader> auxdyn_reader;
59
60 // AuxDyn RNTuple writer
61 std::unique_ptr<RootAuxDynIO::IRNTupleAuxDynWriter> auxdyn_writer;
62
63 explicit FieldDesc(const DbColumn& c);
64 FieldDesc(FieldDesc const& other) = delete;
65 FieldDesc(FieldDesc&& other) = default;
66 ~FieldDesc() = default;
67
68 FieldDesc& operator=(FieldDesc const& other) = delete;
69 FieldDesc& operator=(FieldDesc&& other) = default;
70
71 const std::string typeName();
72 };
73
74 private:
78 std::vector<FieldDesc> m_fieldDescs;
87
88 uint64_t m_index;
89 uint64_t m_indexSize;
90 int64_t m_indexBump;
91 const uint32_t m_indexMulti;
92
95
97 ROOT::RNTupleReader* m_ntupleReader{};
98
100 std::unique_ptr<RootAuxDynIO::IFactoryTool> m_auxDynTool;
101
102 public:
103 explicit RNTupleContainer(const std::string& name);
105
107 virtual StatusCode close() override final;
108
110 virtual StatusCode open(pool::DbDatabase& dbH, const std::string& nam,
111 const pool::DbTypeInfo* info,
112 pool::DbAccessMode mod) override final;
113
115 virtual StatusCode checkAccess(pool::DbDatabase& dbH,
116 const std::string& nam) const override final;
117
119
123 virtual StatusCode getOption(pool::DbOption& opt) override final;
124
126
130 virtual StatusCode setOption(const pool::DbOption& opt) override final;
131
133 virtual uint64_t size() override final;
134
136 const std::string& getName() const { return m_name; }
137
140 bool isDirty() const { return m_isDirty; }
141
143 void clearDirty() { m_isDirty = false; }
144
146
152 virtual StatusCode loadObject(void** ptr, pool::ShapeH shape,
153 Token::OID_t& oid) override final;
154
156 virtual StatusCode writeObject(ActionList::value_type&) override final;
157
158 virtual uint64_t nextRecordId() override final;
159
160 virtual void useNextRecordId(uint64_t nextID) override final;
161
163 virtual StatusCode transAct(pool::Transaction::Action action) override final;
164
166 virtual StatusCode store(const void* object,
167 pool::DbContainer& cntH,
168 pool::ShapeH shape) override final;
169
170 private:
173};
174
175#endif
virtual uint64_t nextRecordId() override final
Number of next record in the container (=size if no delete is allowed)
std::unique_ptr< RootAuxDynIO::IFactoryTool > m_auxDynTool
Factory object from AuxDynIO plugin that creates AuxDyn readers and writers.
pool::DbDatabase m_dbH
Parent Database handle.
const pool::DbTypeInfo * m_type
reference to exact type description
RootStorageSvc::RNTupleWriterHelper * m_ntupleWriter
Internal cache of the RNTupleWriterHelper.
ROOT::RNTupleReader * m_ntupleReader
Internal cache of the native RNTupleReader.
bool m_isDirty
flag set on writing to prevent double writes in the same commit
virtual StatusCode close() override final
Close the container and deallocate resources.
RNTupleContainer(const std::string &name)
virtual StatusCode checkAccess(pool::DbDatabase &dbH, const std::string &nam) const override final
Check if we can access the container for reading with the given type.
std::vector< FieldDesc > m_fieldDescs
List of field descriptors.
virtual StatusCode store(const void *object, pool::DbContainer &cntH, pool::ShapeH shape) override final
Store object in location.
virtual StatusCode getOption(pool::DbOption &opt) override final
Access options.
virtual uint64_t size() override final
Number of entries within the container.
void clearDirty()
Clear the dirty status (used after containing TTree was Filled)
pool::RootDatabase * m_rootDb
Root database file reference.
virtual ~RNTupleContainer()
virtual StatusCode transAct(pool::Transaction::Action action) override final
Execute transaction action.
virtual StatusCode loadObject(void **ptr, pool::ShapeH shape, Token::OID_t &oid) override final
Find object by object identifier and load it into memory.
const std::string & getName() const
Return the name of the container.
int m_ioBytes
Number of bytes written/read during last operation. Set to -1 if it failed.
virtual void useNextRecordId(uint64_t nextID) override final
Suggest next Record ID for tbe next object written - used only with synced indexes.
virtual StatusCode open(pool::DbDatabase &dbH, const std::string &nam, const pool::DbTypeInfo *info, pool::DbAccessMode mod) override final
Open the container for object access.
bool isDirty() const
Return true if this branch container was updated and it's TTree needs to be Filled.
virtual StatusCode writeObject(ActionList::value_type &) override final
Commit single entry to container.
virtual StatusCode setOption(const pool::DbOption &opt) override final
Set options.
const uint32_t m_indexMulti
StatusCode initObjectFieldDesc(FieldDesc &dsc)
Init a field description for an object (i.e. find TClass etc.)
Interface for a RNTuple-based Writer that handles AuxDyn attributes Works in conjuction with the gene...
Description: Definition of the generic column in a (relational) Database.
Definition DbColumn.h:34
DbColumn()
Cache class information (if available) Do not allow unwanted instantiations by users.
Definition DbColumn.h:71
"Generic" Container implementation
std::string m_name
Container name.
virtual std::string name() const override
Get container name.
Description: Handle managing a DbDatabaseObj, a generic Database object.
Definition DbDatabase.h:55
Definition of class DbTypeInfo.
Definition DbTypeInfo.h:49
Description: ROOT specific implementation of Database file.
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
const class Shape * ShapeH
STL namespace.
Definition of a field info structure.
FieldDesc & operator=(FieldDesc const &other)=delete
FieldDesc(const DbColumn &c)
std::unique_ptr< RootAuxDynIO::IRootAuxDynReader > auxdyn_reader
FieldDesc(FieldDesc const &other)=delete
FieldDesc(FieldDesc &&other)=default
std::optional< ROOT::RNTupleView< void > > view
std::unique_ptr< RootAuxDynIO::IRNTupleAuxDynWriter > auxdyn_writer
const std::string typeName()
FieldDesc & operator=(FieldDesc &&other)=default
#define private