Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
RNTupleWriterHelper.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 #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 
18 #if ROOT_VERSION_CODE < ROOT_VERSION( 6, 35, 0 )
19 namespace ROOT {
20  using REntry = ROOT::Experimental::REntry;
21  using RNTupleWriter = ROOT::Experimental::RNTupleWriter;
22  using RNTupleWriteOptions = ROOT::Experimental::RNTupleWriteOptions;
23  using RNTupleModel = ROOT::Experimental::RNTupleModel;
24  using RFieldBase = ROOT::Experimental::RFieldBase;
25 }
26 #endif
27 
28 namespace RootStorageSvc {
29 
31  public:
33  RNTupleWriterHelper(TFile* file, const std::string& ntupleName,
34  bool enableBufferedWrite, bool enableMetrics);
35 
37  ~RNTupleWriterHelper() = default;
38 
40  void makeNewEntry();
41 
43  // The convention for the tuple is <name, type, data>
44  typedef std::tuple<std::string, std::string, void*> attrDataTuple;
45  void addAttribute(const attrDataTuple& in);
46 
48  void addField(const std::string& field_name, const std::string& attr_type);
49 
51  void addFieldValue(const std::string& field_name, void* attr_data);
52 
54  int commit();
55 
57  const std::string& getName() const { return m_ntupleName; }
58 
60  size_t size() const { return m_rowN; }
61 
63  bool needsCommit() const { return m_needsCommit; }
64 
66  bool isGrouped() const { return m_clients > 1; }
67 
70 
72  void close();
73 
74  private:
76  std::map<std::string, void*> m_attrDataMap;
77 
82  std::unique_ptr<ROOT::RNTupleModel> m_model;
83 
85  std::unique_ptr<ROOT::REntry> m_entry;
86 
88  std::unique_ptr<ROOT::RNTupleWriter> m_ntupleWriter;
89 
90  std::string m_ntupleName;
91  TFile* m_tfile;
92  ROOT::RNTupleWriteOptions m_opts;
93  int m_rowN = 0;
94 
97  int m_clients = 0;
98  bool m_needsCommit = false;
99 
102 };
103 
104 } // namespace RootStorageSvc
105 #endif
RootStorageSvc::RNTupleWriterHelper::close
void close()
Close the writer.
RootStorageSvc::RNTupleWriterHelper::~RNTupleWriterHelper
~RNTupleWriterHelper()=default
Default Destructor.
RootStorageSvc::RNTupleWriterHelper::m_ntupleName
std::string m_ntupleName
Definition: RNTupleWriterHelper.h:90
RootStorageSvc::RNTupleWriterHelper::isGrouped
bool isGrouped() const
Is this RNTuple used by more than one APR container?
Definition: RNTupleWriterHelper.h:66
RootStorageSvc::RNTupleWriterHelper::addField
void addField(const std::string &field_name, const std::string &attr_type)
Add a new field to the RNTuple.
RootStorageSvc::RNTupleWriterHelper::addFieldValue
void addFieldValue(const std::string &field_name, void *attr_data)
Supply data address for a given field.
RootStorageSvc::RNTupleWriterHelper::needsCommit
bool needsCommit() const
Check if any data needs to be committed.
Definition: RNTupleWriterHelper.h:63
RootStorageSvc::RNTupleWriterHelper::m_attrDataMap
std::map< std::string, void * > m_attrDataMap
Store data ptr for the first row, when only creating the model.
Definition: RNTupleWriterHelper.h:76
RootStorageSvc::RNTupleWriterHelper::attrDataTuple
std::tuple< std::string, std::string, void * > attrDataTuple
Add a new field to the RNTuple, collect the data pointer for the commit.
Definition: RNTupleWriterHelper.h:44
RootStorageSvc::RNTupleWriterHelper::m_needsCommit
bool m_needsCommit
Definition: RNTupleWriterHelper.h:98
RootStorageSvc::RNTupleWriterHelper::commit
int commit()
Commit the data.
RootStorageSvc::RNTupleWriterHelper::increaseClientCount
void increaseClientCount()
Keep track of how many APR containers are writing to this RNTuple.
Definition: RNTupleWriterHelper.h:69
RootStorageSvc::RNTupleWriterHelper::getName
const std::string & getName() const
Name of the RNTuple.
Definition: RNTupleWriterHelper.h:57
RootStorageSvc::RNTupleWriterHelper::m_rowN
int m_rowN
Definition: RNTupleWriterHelper.h:93
RootStorageSvc::RNTupleWriterHelper::addAttribute
void addAttribute(const attrDataTuple &in)
file
TFile * file
Definition: tile_monitor.h:29
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
RootStorageSvc::RNTupleWriterHelper::m_ntupleWriter
std::unique_ptr< ROOT::RNTupleWriter > m_ntupleWriter
Internal cache for the native RNTupleWriter.
Definition: RNTupleWriterHelper.h:88
RootStorageSvc::RNTupleWriterHelper::m_collectMetrics
bool m_collectMetrics
Enable/Disable Metric Collection.
Definition: RNTupleWriterHelper.h:101
RootStorageSvc::RNTupleWriterHelper::m_entry
std::unique_ptr< ROOT::REntry > m_entry
Internal cache for the RNEntry.
Definition: RNTupleWriterHelper.h:85
RootStorageSvc::RNTupleWriterHelper
Definition: RNTupleWriterHelper.h:30
AthMessaging.h
RootStorageSvc::RNTupleWriterHelper::m_clients
int m_clients
Count how many APR Containers are writing to this RNTuple (more than one makes a Group)
Definition: RNTupleWriterHelper.h:97
RootStorageSvc::RNTupleWriterHelper::m_model
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...
Definition: RNTupleWriterHelper.h:82
RootStorageSvc::RNTupleWriterHelper::m_opts
ROOT::RNTupleWriteOptions m_opts
Definition: RNTupleWriterHelper.h:92
RootStorageSvc::RNTupleWriterHelper::size
size_t size() const
Size of the RNTuple.
Definition: RNTupleWriterHelper.h:60
RootStorageSvc
Definition: RNTupleContainer.h:29
ROOT
Selection rules: declare transient members.
Definition: DataVector.h:580
RootStorageSvc::RNTupleWriterHelper::RNTupleWriterHelper
RNTupleWriterHelper(TFile *file, const std::string &ntupleName, bool enableBufferedWrite, bool enableMetrics)
Constructor.
RootStorageSvc::RNTupleWriterHelper::m_tfile
TFile * m_tfile
Definition: RNTupleWriterHelper.h:91
RootStorageSvc::RNTupleWriterHelper::makeNewEntry
void makeNewEntry()
Create a new empty RNTuple row with the current model (fields)