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 
31 #if ROOT_VERSION_CODE < ROOT_VERSION( 6, 35, 0 )
32 namespace ROOT { using ROOT::Experimental::RNTupleView; }
33 namespace ROOT::Experimental { class RNTupleReader; }
34 namespace ROOT { using ROOT::Experimental::RNTupleReader; }
35 #else
36 namespace ROOT { class RNTupleReader; }
37 #endif
38 
39 // Forward declaration
40 namespace pool {
41  class RootDatabase;
42 }
43 
51 {
53 
55  struct FieldDesc : public pool::DbColumn
56  {
57  std::string fieldname;
58  std::optional< ROOT::RNTupleView<void> > view;
59  std::string sgkey;
60  TClass* clazz = nullptr;
61  void* object = nullptr;
62 
63  // if writing char* keep a copy here as an std::string
64  std::string str;
65 
66  // ---- extra variables used for AuxDyn attributes
67  // number of rows written to this branch so far
68  size_t rows_written = 0;
69 
70  // AuxDyn RNTuple reader (managed by the Database)
71  std::unique_ptr<RootAuxDynIO::IRootAuxDynReader> auxdyn_reader;
72 
73  // AuxDyn RNTuple writer
74  std::unique_ptr<RootAuxDynIO::IRNTupleAuxDynWriter> auxdyn_writer;
75 
76  explicit FieldDesc(const DbColumn& c);
77  FieldDesc(FieldDesc const& other) = delete;
78  FieldDesc(FieldDesc&& other) = default;
79  ~FieldDesc() = default;
80 
81  FieldDesc& operator=(FieldDesc const& other) = delete;
83 
84  const std::string typeName();
85  };
86 
87  private:
91  std::vector<FieldDesc> m_fieldDescs;
97  int m_ioBytes;
99  bool m_isDirty;
100 
103  int64_t m_indexBump;
105 
108 
110  ROOT::RNTupleReader* m_ntupleReader{};
111 
113  std::unique_ptr<RootAuxDynIO::IFactoryTool> m_auxDynTool;
114 
115  public:
118 
119  virtual ~RNTupleContainer();
120 
122  virtual pool::DbStatus close() override final;
123 
125  virtual pool::DbStatus open(pool::DbDatabase& dbH, const std::string& nam,
126  const pool::DbTypeInfo* info,
127  pool::DbAccessMode mod) override final;
128 
130  virtual pool::DbStatus checkAccess(pool::DbDatabase& dbH,
131  const std::string& nam) const override final;
132 
134 
138  virtual pool::DbStatus getOption(pool::DbOption& opt) override final;
139 
141 
145  virtual pool::DbStatus setOption(const pool::DbOption& opt) override final;
146 
148  virtual uint64_t size() override final;
149 
151  const std::string& getName() const { return m_name; }
152 
155  bool isDirty() const { return m_isDirty; }
156 
158  void clearDirty() { m_isDirty = false; }
159 
161 
167  virtual pool::DbStatus loadObject(void** ptr, pool::ShapeH shape,
168  Token::OID_t& oid) override final;
169 
171  virtual pool::DbStatus writeObject(ActionList::value_type&) override final;
172 
173  virtual uint64_t nextRecordId() override final;
174 
175  virtual void useNextRecordId(uint64_t nextID) override final;
176 
178  virtual pool::DbStatus select(pool::DbSelect& sel) override final;
179 
181  using pool::DbContainerImp::fetch;
182  virtual pool::DbStatus fetch(pool::DbSelect& sel) override final;
183 
185  virtual pool::DbStatus transAct(pool::Transaction::Action action) override final;
186 
188  virtual pool::DbStatus save(pool::DbObjectHandle<pool::DbObject>& objH) override final;
189 
190  private:
193 };
194 
195 #endif
RNTupleContainer::FieldDesc::clazz
TClass * clazz
Definition: RNTupleContainer.h:60
pool::DbAccessMode
int DbAccessMode
Definition: Database/APR/StorageSvc/StorageSvc/pool.h:47
RNTupleContainer::isDirty
bool isDirty() const
Return true if this branch container was updated and it's TTree needs to be Filled.
Definition: RNTupleContainer.h:155
pool::DbObject
void DbObject
Definition: Database/APR/StorageSvc/StorageSvc/pool.h:35
RNTupleContainer::writeObject
virtual pool::DbStatus writeObject(ActionList::value_type &) override final
Commit single entry to container.
pool::DbStatus
Definition: DbStatus.h:67
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:51
RNTupleContainer::~RNTupleContainer
virtual ~RNTupleContainer()
RNTupleContainer::m_indexBump
int64_t m_indexBump
Definition: RNTupleContainer.h:103
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:76
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:57
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
DbDatabase.h
RNTupleContainer::FieldDesc::typeName
const std::string typeName()
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:59
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:99
pool::ShapeH
const class Shape * ShapeH
Definition: DbContainerObj.h:27
checkTP.save
def save(self, fileName="./columbo.out")
Definition: checkTP.py:176
RNTupleContainer::m_ntupleReader
ROOT::RNTupleReader * m_ntupleReader
Internal cache of the native RNTupleReader.
Definition: RNTupleContainer.h:110
RootAuxDynIO::IRNTupleAuxDynWriter
Interface for a RNTuple-based Writer that handles AuxDyn attributes Works in conjuction with the gene...
Definition: IRootAuxDynIO.h:78
RNTupleContainer::m_fieldDescs
std::vector< FieldDesc > m_fieldDescs
List of field descriptors.
Definition: RNTupleContainer.h:91
maskDeadModules.mod
mod
Definition: maskDeadModules.py:36
RNTupleContainer::FieldDesc::rows_written
size_t rows_written
Definition: RNTupleContainer.h:68
RNTupleContainer::m_dbH
pool::DbDatabase m_dbH
Parent Database handle.
Definition: RNTupleContainer.h:93
RNTupleContainer::m_auxDynTool
std::unique_ptr< RootAuxDynIO::IFactoryTool > m_auxDynTool
Factory object from AuxDynIO plugin that creates AuxDyn readers and writers.
Definition: RNTupleContainer.h:113
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:64
RNTupleContainer::FieldDesc
Definition of a field info structure.
Definition: RNTupleContainer.h:56
RNTupleContainer::m_indexMulti
const uint32_t m_indexMulti
Definition: RNTupleContainer.h:104
RNTupleContainer::m_index
uint64_t m_index
Definition: RNTupleContainer.h:101
RNTupleContainer::FieldDesc::auxdyn_writer
std::unique_ptr< RootAuxDynIO::IRNTupleAuxDynWriter > auxdyn_writer
Definition: RNTupleContainer.h:74
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:158
RNTupleContainer::m_ntupleWriter
RootStorageSvc::RNTupleWriterHelper * m_ntupleWriter
Internal cache of the RNTupleWriterHelper.
Definition: RNTupleContainer.h:107
RNTupleContainer::FieldDesc::operator=
FieldDesc & operator=(FieldDesc const &other)=delete
RNTupleContainer::FieldDesc::auxdyn_reader
std::unique_ptr< RootAuxDynIO::IRootAuxDynReader > auxdyn_reader
Definition: RNTupleContainer.h:71
RNTupleContainer::getOption
virtual pool::DbStatus getOption(pool::DbOption &opt) override final
Access options.
RootAuxDynIO::IRootAuxDynReader
Definition: IRootAuxDynIO.h:36
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:95
RNTupleContainer::FieldDesc::view
std::optional< ROOT::RNTupleView< void > > view
Definition: RNTupleContainer.h:58
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:97
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::RNTupleContainer
RNTupleContainer()
Standard constructor.
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:30
pool::RootDatabase
Definition: RootDatabase.h:59
RNTupleContainer::m_type
const pool::DbTypeInfo * m_type
reference to exact type description
Definition: RNTupleContainer.h:89
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:151
RNTupleContainer::save
virtual pool::DbStatus save(pool::DbObjectHandle< pool::DbObject > &objH) override final
Add single entry to container.
private
#define private
Definition: xAODTruthCnvAlg.h:20
RNTupleContainer::m_indexSize
uint64_t m_indexSize
Definition: RNTupleContainer.h:102
pool::DbContainerImp::DbContainerImp
DbContainerImp()
pool::DbContainerImp
Definition: DbContainerImp.h:44
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:580
pool::DbTypeInfo
Definition: DbTypeInfo.h:47
IRootAuxDynIO.h