ATLAS Offline Software
Loading...
Searching...
No Matches
RNTupleWriterHelper.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef RNTUPLEWRITERHELPER_H
6#define RNTUPLEWRITERHELPER_H
7
9
10#include "ROOT/REntry.hxx"
11#include "ROOT/RField.hxx"
12#include "ROOT/RNTuple.hxx"
13#include "ROOT/RNTupleWriteOptions.hxx"
14#include "ROOT/RNTupleWriter.hxx"
15
16#include <tuple>
17#include <map>
18#include <set>
19#include <string>
20#include <string_view>
21#include <memory>
22
23class TFile;
24
25namespace RootStorageSvc {
26
28 public:
30 RNTupleWriterHelper(TFile* file, const std::string& ntupleName,
31 bool enableBufferedWrite, bool enableMetrics);
32
35
38
40 // The convention for the tuple is <name, type, data>
41 typedef std::tuple<std::string, std::string, void*> attrDataTuple;
42 void addAttribute(const attrDataTuple& in);
43
45 void addField(const std::string& field_name, const std::string& attr_type);
46
48 void addFieldValue(const std::string& field_name, void* attr_data);
49
51 int commit();
52
54 const std::string& getName() const { return m_ntupleName; }
55
57 size_t size() const { return m_rowN; }
58
60 bool needsCommit() const { return m_needsCommit; }
61
63 bool isGrouped() const { return m_clients > 1; }
64
67
69 void close();
70
72 void setUnsplitFieldsList(std::string_view unsplitFieldsList);
73
74 private:
76 std::map<std::string, void*> m_attrDataMap;
77
79 std::set<std::string, std::less<>> m_unsplitFields;
80
85 std::unique_ptr<ROOT::RNTupleModel> m_model;
86
88 std::unique_ptr<ROOT::REntry> m_entry;
89
91 std::unique_ptr<ROOT::RNTupleWriter> m_ntupleWriter;
92
93 std::string m_ntupleName;
94 TFile* m_tfile;
95 ROOT::RNTupleWriteOptions m_opts;
96 int m_rowN = 0;
97
100 int m_clients = 0;
101 bool m_needsCommit = false;
102
105};
106
107} // namespace RootStorageSvc
108#endif
void setUnsplitFieldsList(std::string_view unsplitFieldsList)
Set comma-separated list of field names to unsplit.
const std::string & getName() const
Name of the RNTuple.
void increaseClientCount()
Keep track of how many APR containers are writing to this RNTuple.
void addAttribute(const attrDataTuple &in)
std::unique_ptr< ROOT::RNTupleModel > m_model
Internal cache for the RNTuple model Before first commit the fields are added to the model At the fir...
bool m_collectMetrics
Enable/Disable Metric Collection.
void close()
Close the writer.
int m_clients
Count how many APR Containers are writing to this RNTuple (more than one makes a Group).
bool isGrouped() const
Is this RNTuple used by more than one APR container?
~RNTupleWriterHelper()=default
Default Destructor.
void makeNewEntry()
Create a new empty RNTuple row with the current model (fields).
size_t size() const
Size of the RNTuple.
std::tuple< std::string, std::string, void * > attrDataTuple
Add a new field to the RNTuple, collect the data pointer for the commit.
RNTupleWriterHelper(TFile *file, const std::string &ntupleName, bool enableBufferedWrite, bool enableMetrics)
Constructor.
void addFieldValue(const std::string &field_name, void *attr_data)
Supply data address for a given field.
std::unique_ptr< ROOT::RNTupleWriter > m_ntupleWriter
Internal cache for the native RNTupleWriter.
void addField(const std::string &field_name, const std::string &attr_type)
Add a new field to the RNTuple.
std::unique_ptr< ROOT::REntry > m_entry
Internal cache for the RNEntry.
bool needsCommit() const
Check if any data needs to be committed.
std::set< std::string, std::less<> > m_unsplitFields
Set of field names that should be unsplit.
std::map< std::string, void * > m_attrDataMap
Store data ptr for the first row, when only creating the model.
AthMessaging wrapper to set the output level in APR components.
Definition DbPrint.h:40
TFile * file