ATLAS Offline Software
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"
15 #include "StorageSvc/DbDatabase.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
27 class TClass;
29 namespace RootStorageSvc { class RNTupleWriterHelper; }
30 namespace ROOT { class RNTupleReader; }
31 
32 // Forward declaration
33 namespace pool {
34  class RootDatabase;
35 }
36 
44 {
46  struct FieldDesc : public pool::DbColumn
47  {
48  std::string fieldname;
49  std::optional< ROOT::RNTupleView<void> > view;
50  std::string sgkey;
51  TClass* clazz = nullptr;
52  void* object = nullptr;
53 
54  // if writing char* keep a copy here as an std::string
55  std::string str;
56 
57  // ---- extra variables used for AuxDyn attributes
58  // number of rows written to this branch so far
59  size_t rows_written = 0;
60 
61  // AuxDyn RNTuple reader (managed by the Database)
62  std::unique_ptr<RootAuxDynIO::IRootAuxDynReader> auxdyn_reader;
63 
64  // AuxDyn RNTuple writer
65  std::unique_ptr<RootAuxDynIO::IRNTupleAuxDynWriter> auxdyn_writer;
66 
67  explicit FieldDesc(const DbColumn& c);
68  FieldDesc(FieldDesc const& other) = delete;
69  FieldDesc(FieldDesc&& other) = default;
70  ~FieldDesc() = default;
71 
72  FieldDesc& operator=(FieldDesc const& other) = delete;
74 
75  const std::string typeName();
76  };
77 
78  private:
82  std::vector<FieldDesc> m_fieldDescs;
88  int m_ioBytes;
90  bool m_isDirty;
91 
94  int64_t m_indexBump;
96 
99 
101  ROOT::RNTupleReader* m_ntupleReader{};
102 
104  std::unique_ptr<RootAuxDynIO::IFactoryTool> m_auxDynTool;
105 
106  public:
107  explicit RNTupleContainer(const std::string& name);
108  virtual ~RNTupleContainer();
109 
111  virtual pool::DbStatus close() override final;
112 
114  virtual pool::DbStatus open(pool::DbDatabase& dbH, const std::string& nam,
115  const pool::DbTypeInfo* info,
116  pool::DbAccessMode mod) override final;
117 
119  virtual pool::DbStatus checkAccess(pool::DbDatabase& dbH,
120  const std::string& nam) const override final;
121 
123 
127  virtual pool::DbStatus getOption(pool::DbOption& opt) override final;
128 
130 
134  virtual pool::DbStatus setOption(const pool::DbOption& opt) override final;
135 
137  virtual uint64_t size() override final;
138 
140  const std::string& getName() const { return m_name; }
141 
144  bool isDirty() const { return m_isDirty; }
145 
147  void clearDirty() { m_isDirty = false; }
148 
150 
156  virtual pool::DbStatus loadObject(void** ptr, pool::ShapeH shape,
157  Token::OID_t& oid) override final;
158 
160  virtual pool::DbStatus writeObject(ActionList::value_type&) override final;
161 
162  virtual uint64_t nextRecordId() override final;
163 
164  virtual void useNextRecordId(uint64_t nextID) override final;
165 
167  virtual pool::DbStatus select(pool::DbSelect& sel) override final;
168 
170  using pool::DbContainerImp::fetch;
171  virtual pool::DbStatus fetch(pool::DbSelect& sel) override final;
172 
174  virtual pool::DbStatus transAct(pool::Transaction::Action action) override final;
175 
177  virtual pool::DbStatus store(const void* object,
178  pool::DbContainer& cntH,
179  pool::ShapeH shape) override final;
180 
181  private:
184 };
185 
186 #endif
RNTupleContainer::FieldDesc::clazz
TClass * clazz
Definition: RNTupleContainer.h:51
pool::DbAccessMode
int DbAccessMode
Definition: Database/APR/StorageSvc/StorageSvc/pool.h:34
pool::DbContainerImp::name
virtual std::string name() const override
Get container name.
Definition: DbContainerImp.h:107
RNTupleContainer::isDirty
bool isDirty() const
Return true if this branch container was updated and it's TTree needs to be Filled.
Definition: RNTupleContainer.h:144
RNTupleContainer::writeObject
virtual pool::DbStatus writeObject(ActionList::value_type &) override final
Commit single entry to container.
pool::DbStatus
Definition: DbStatus.h:64
make_coralServer_rep.opt
opt
Definition: make_coralServer_rep.py:19
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
RNTupleContainer::transAct
virtual pool::DbStatus transAct(pool::Transaction::Action action) override final
Execute transaction action.
pool
pool namespace
Definition: libname.h:15
RNTupleContainer
Definition: RNTupleContainer.h:44
RNTupleContainer::RNTupleContainer
RNTupleContainer(const std::string &name)
RNTupleContainer::~RNTupleContainer
virtual ~RNTupleContainer()
RNTupleContainer::m_indexBump
int64_t m_indexBump
Definition: RNTupleContainer.h:94
RNTupleContainer::fetch
virtual pool::DbStatus fetch(pool::DbSelect &sel) override final
Fetch next object address of the selection to set token.
RNTupleContainer::open
virtual pool::DbStatus open(pool::DbDatabase &dbH, const std::string &nam, const pool::DbTypeInfo *info, pool::DbAccessMode mod) override final
Open the container for object access.
pool::DbContainerImp::m_name
std::string m_name
Container name.
Definition: DbContainerImp.h:77
dbg::ptr
void * ptr(T *p)
Definition: SGImplSvc.cxx:74
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:560
RNTupleContainer::FieldDesc::fieldname
std::string fieldname
Definition: RNTupleContainer.h:48
RNTupleContainer::checkAccess
virtual pool::DbStatus checkAccess(pool::DbDatabase &dbH, const std::string &nam) const override final
Check if we can access the container for reading with the given type.
DbColumn.h
RNTupleContainer::FieldDesc::FieldDesc
FieldDesc(FieldDesc &&other)=default
ReadBchFromCrest.mod
mod
Definition: ReadBchFromCrest.py:72
DbDatabase.h
RNTupleContainer::FieldDesc::typeName
const std::string typeName()
RNTupleContainer::store
virtual pool::DbStatus store(const void *object, pool::DbContainer &cntH, pool::ShapeH shape) override final
Store object in location.
RNTupleContainer::FieldDesc::FieldDesc
FieldDesc(FieldDesc const &other)=delete
RNTupleContainer::nextRecordId
virtual uint64_t nextRecordId() override final
Number of next record in the container (=size if no delete is allowed)
RNTupleContainer::FieldDesc::sgkey
std::string sgkey
Definition: RNTupleContainer.h:50
Token::OID_t
Definition: Token.h:24
RNTupleContainer::m_isDirty
bool m_isDirty
flag set on writing to prevent double writes in the same commit
Definition: RNTupleContainer.h:90
pool::ShapeH
const class Shape * ShapeH
Definition: DbContainerObj.h:27
RNTupleContainer::m_ntupleReader
ROOT::RNTupleReader * m_ntupleReader
Internal cache of the native RNTupleReader.
Definition: RNTupleContainer.h:101
RootAuxDynIO::IRNTupleAuxDynWriter
Interface for a RNTuple-based Writer that handles AuxDyn attributes Works in conjuction with the gene...
Definition: IRootAuxDynIO.h:74
RNTupleContainer::m_fieldDescs
std::vector< FieldDesc > m_fieldDescs
List of field descriptors.
Definition: RNTupleContainer.h:82
RNTupleContainer::FieldDesc::rows_written
size_t rows_written
Definition: RNTupleContainer.h:59
RNTupleContainer::m_dbH
pool::DbDatabase m_dbH
Parent Database handle.
Definition: RNTupleContainer.h:84
RNTupleContainer::m_auxDynTool
std::unique_ptr< RootAuxDynIO::IFactoryTool > m_auxDynTool
Factory object from AuxDynIO plugin that creates AuxDyn readers and writers.
Definition: RNTupleContainer.h:104
sel
sel
Definition: SUSYToolsTester.cxx:92
RNTupleContainer::size
virtual uint64_t size() override final
Number of entries within the container.
RNTupleContainer::setOption
virtual pool::DbStatus setOption(const pool::DbOption &opt) override final
Set options.
RNTupleContainer::close
virtual pool::DbStatus close() override final
Close the container and deallocate resources.
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
RNTupleContainer::FieldDesc::str
std::string str
Definition: RNTupleContainer.h:55
pool::DbContainerImp::DbContainerImp
DbContainerImp(const std::string &name)
RNTupleContainer::FieldDesc
Definition of a field info structure.
Definition: RNTupleContainer.h:47
RNTupleContainer::m_indexMulti
const uint32_t m_indexMulti
Definition: RNTupleContainer.h:95
RNTupleContainer::m_index
uint64_t m_index
Definition: RNTupleContainer.h:92
RNTupleContainer::FieldDesc::auxdyn_writer
std::unique_ptr< RootAuxDynIO::IRNTupleAuxDynWriter > auxdyn_writer
Definition: RNTupleContainer.h:65
RNTupleContainer::initObjectFieldDesc
pool::DbStatus initObjectFieldDesc(FieldDesc &dsc)
Init a field description for an object (i.e. find TClass etc.)
columnar::final
CM final
Definition: ColumnAccessor.h:106
RNTupleContainer::clearDirty
void clearDirty()
Clear the dirty status (used after containing TTree was Filled)
Definition: RNTupleContainer.h:147
RNTupleContainer::m_ntupleWriter
RootStorageSvc::RNTupleWriterHelper * m_ntupleWriter
Internal cache of the RNTupleWriterHelper.
Definition: RNTupleContainer.h:98
RNTupleContainer::FieldDesc::operator=
FieldDesc & operator=(FieldDesc const &other)=delete
RNTupleContainer::FieldDesc::auxdyn_reader
std::unique_ptr< RootAuxDynIO::IRootAuxDynReader > auxdyn_reader
Definition: RNTupleContainer.h:62
RNTupleContainer::getOption
virtual pool::DbStatus getOption(pool::DbOption &opt) override final
Access options.
RootAuxDynIO::IRootAuxDynReader
Definition: IRootAuxDynIO.h:32
RNTupleContainer::select
virtual pool::DbStatus select(pool::DbSelect &sel) override final
Define selection.
RNTupleContainer::m_rootDb
pool::RootDatabase * m_rootDb
Root database file reference.
Definition: RNTupleContainer.h:86
RNTupleContainer::FieldDesc::view
std::optional< ROOT::RNTupleView< void > > view
Definition: RNTupleContainer.h:49
RNTupleContainer::FieldDesc::FieldDesc
FieldDesc(const DbColumn &c)
RootAuxDynIO
Specialization of RootAuxDynStore for reading Aux Dynamic attributes from RNTuple.
Definition: RNTupleContainer.h:28
pool::DbColumn
Definition: DbColumn.h:35
RNTupleContainer::m_ioBytes
int m_ioBytes
Number of bytes written/read during last operation. Set to -1 if it failed.
Definition: RNTupleContainer.h:88
RNTupleContainer::FieldDesc::operator=
FieldDesc & operator=(FieldDesc &&other)=default
RNTupleContainer::loadObject
virtual pool::DbStatus loadObject(void **ptr, pool::ShapeH shape, Token::OID_t &oid) override final
Find object by object identifier and load it into memory.
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
RNTupleContainer::useNextRecordId
virtual void useNextRecordId(uint64_t nextID) override final
Suggest next Record ID for tbe next object written - used only with synced indexes.
RootStorageSvc::RNTupleWriterHelper
Definition: RNTupleWriterHelper.h:20
pool::RootDatabase
Definition: RootDatabase.h:55
RNTupleContainer::m_type
const pool::DbTypeInfo * m_type
reference to exact type description
Definition: RNTupleContainer.h:80
python.CaloScaleNoiseConfig.action
action
Definition: CaloScaleNoiseConfig.py:77
DbContainerImp.h
RNTupleContainer::getName
const std::string & getName() const
Return the name of the container.
Definition: RNTupleContainer.h:140
private
#define private
Definition: xAODTruthCnvAlg.h:20
RNTupleContainer::m_indexSize
uint64_t m_indexSize
Definition: RNTupleContainer.h:93
pool::DbContainerImp
Definition: DbContainerImp.h:45
pool::DbDatabase
Definition: DbDatabase.h:53
pool::DbColumn::DbColumn
DbColumn()
Cache class information (if available) Do not allow unwanted instantiations by users.
Definition: DbColumn.h:72
RNTupleContainer::FieldDesc::~FieldDesc
~FieldDesc()=default
python.compressB64.c
def c
Definition: compressB64.py:93
python.ParticleTypeUtil.info
def info
Definition: ParticleTypeUtil.py:87
RootStorageSvc
Definition: RNTupleContainer.h:29
ROOT
Selection rules: declare transient members.
Definition: DataVector.h:581
pool::DbTypeInfo
Definition: DbTypeInfo.h:47
IRootAuxDynIO.h