Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RNTupleProcessorEntry.hxx
Go to the documentation of this file.
1/// \file ROOT/RNTupleProcessor.hxx
2/// \author Florine de Geus <florine.de.geus@cern.ch>
3/// \date 2025-06-25
4/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
5/// is welcome!
6
7/*************************************************************************
8 * Copyright (C) 1995-2024, Rene Brun and Fons Rademakers. *
9 * All rights reserved. *
10 * *
11 * For the licensing terms see $ROOTSYS/LICENSE. *
12 * For the list of contributors see $ROOTSYS/README/CREDITS. *
13 *************************************************************************/
14
15#ifndef ROOT_RNTupleProcessorEntry
16#define ROOT_RNTupleProcessorEntry
17
18#include <ROOT/RFieldBase.hxx>
19
20#include <cassert>
21#include <string>
22#include <string_view>
23#include <unordered_map>
24#include <vector>
25
26namespace ROOT {
27namespace Experimental {
28namespace Internal {
29/**
30\class ROOT::Experimental::RNTupleProcessorProvenance
31\ingroup NTuple
32\brief Identifies how a processor is composed.
33
34The processor provenance is used in RNTupleProcessorEntry to identify how an (auxiliary) field in a composed processor
35can be accessed.
36*/
37// clang-format on
39private:
40 std::string fProvenance{};
41
42public:
45
46 /////////////////////////////////////////////////////////////////////////////
47 /// \brief Get the full processor provenance, in the form of "x.y.z".
48 std::string Get() const { return fProvenance; }
49
50 /////////////////////////////////////////////////////////////////////////////
51 /// \brief Add a new processor to the provenance.
52 ///
53 /// \param[in] processorName Name of the processor to add.
54 ///
55 /// \return The updated provenance.
63
64 /////////////////////////////////////////////////////////////////////////////
65 /// \brief Check whether the provenance subsumes the provenance in `other`.
66 ///
67 /// \param[in] other The other provenance
69 {
70 return fProvenance.rfind(other.fProvenance) != std::string::npos;
71 }
72
73 /////////////////////////////////////////////////////////////////////////////
74 /// \brief Check whether the provided field name contains this provenance.
75 ///
76 /// \param[in] fieldName Field name to check.
77 bool IsPresentInFieldName(std::string_view fieldName) const
78 {
79 return !fProvenance.empty() && fieldName.find(fProvenance + ".") == 0;
80 }
81};
82
83// clang-format off
84/**
85\class ROOT::Experimental::Internal::RNTupleProcessorEntry
86\ingroup NTuple
87\brief Collection of values in an RNTupleProcessor, analogous to REntry, with checks and support for missing values.
88*/
89// clang-format on
91public:
92 // We don't use RFieldTokens here, because it (semantically) does not make sense for the entry to be fixed to the
93 // schema ID of a particular model.
94 using FieldIndex_t = std::uint64_t;
95
96private:
98 std::unique_ptr<ROOT::RFieldBase> fField;
103
104 RProcessorValue(std::unique_ptr<ROOT::RFieldBase> field, std::string_view qualifiedFieldName,
106 : fField(std::move(field)),
108 fValue(std::move(value)),
109 fIsValid(isValid),
111 {
112 }
113 };
114
115 std::vector<RProcessorValue> fProcessorValues;
116 // Maps from the field name to all type alternatives for that field that have been added to the entry.
117 std::unordered_map<std::string, std::vector<FieldIndex_t>> fFieldName2Index;
118
119public:
120 /////////////////////////////////////////////////////////////////////////////
121 /// \brief Clear all fields from the entry.
122 void Clear()
123 {
124 fProcessorValues.clear();
125 fFieldName2Index.clear();
126 }
127
128 /////////////////////////////////////////////////////////////////////////////
129 /// \brief Set the validity of a field, i.e. whether it is possible to read its value in the current entry.
130 ///
131 /// \param[in] fieldIdx The index of the field in the entry.
132 /// \param[in] isValid The new validity of the field.
134 {
136 fProcessorValues[fieldIdx].fIsValid = isValid;
137 }
138
139 /////////////////////////////////////////////////////////////////////////////
140 /// \brief Check whether a field is valid for reading.
141 ///
142 /// \param[in] fieldIdx The index of the field in the entry.
144 {
146 return fProcessorValues[fieldIdx].fIsValid;
147 }
148
149 /////////////////////////////////////////////////////////////////////////////
150 /// \brief Find the name of a field from its field index.
151 ///
152 /// \param[in] fieldIdx The index of the field in the entry.
153 ///
154 /// \warning This function has linear complexity, only use it for more helpful error messages!
155 const std::string &FindFieldName(FieldIndex_t fieldIdx) const;
156
157 /////////////////////////////////////////////////////////////////////////////
158 /// \brief Find the field index of the provided field in the entry.
159 ///
160 /// \param[in] canonicalFieldName The name of the field in the entry, including its processor name prefixes and
161 /// parent field names, if applicable.
162 ///
163 /// \return A `std::optional` containing the field index if it was found.
164 std::optional<FieldIndex_t> FindFieldIndex(std::string_view canonicalFieldName, std::string_view typeName) const;
165
166 /////////////////////////////////////////////////////////////////////////////
167 /// \brief Add a new field to the entry.
168 ///
169 /// \param[in] qualifiedFieldName Name of the field to add, including its parent field if applicable.
170 /// \param[in] field Reference to the field to add, used to to create its corresponding RValue.
171 /// \param[in] valuePtr Pointer to an object corresponding to the field's type to bind to its value. If this is a
172 /// `nullptr`, a pointer will be created.
173 /// \param[in] provenance Processor provenance of the field.
174 ///
175 /// \return The field index of the newly added field.
176 FieldIndex_t AddField(const std::string &qualifiedFieldName, std::unique_ptr<ROOT::RFieldBase> field, void *valuePtr,
178
179 /////////////////////////////////////////////////////////////////////////////
180 /// \brief Update a field in the entry, preserving the value pointer.
181 ///
182 /// \param[in] fieldIdx Index of the field to update.
183 /// \param[in] field The new field to use in the entry.
184 void UpdateField(FieldIndex_t fieldIdx, std::unique_ptr<ROOT::RFieldBase> field);
185
186 /////////////////////////////////////////////////////////////////////////////
187 /// \brief Bind a new value pointer to a field in the entry.
188 ///
189 /// \param[in] fieldIdx The index of the field in the entry.
190 /// \param[in] valuePtr Pointer to the value to bind to the field.
192
193 /////////////////////////////////////////////////////////////////////////////
194 /// \brief Read the field value corresponding to the given field index for the provided entry index.
195 ///
196 /// \param[in] fieldIdx The index of the field in the entry.
197 /// \param[in] entryIdx The entry number to read.
199
205
206 /////////////////////////////////////////////////////////////////////////////
207 /// \brief Get the processor provenance of a field in the entry.
208 ///
209 /// \param[in] fieldIdx The index of the field in the entry.
211 {
213 return fProcessorValues[fieldIdx].fProcessorProvenance;
214 }
215
216 /////////////////////////////////////////////////////////////////////////////
217 /// \brief Get the name of a field in the entry, including its parent fields.
218 ///
219 /// \param[in] fieldIdx The index of the field in the entry.
221 {
223 return fProcessorValues[fieldIdx].fQualifiedFieldName;
224 }
225
226 /////////////////////////////////////////////////////////////////////////////
227 /// \brief Get all field indices of this entry.
228 std::unordered_set<FieldIndex_t> GetFieldIndices() const;
229};
230} // namespace Internal
231} // namespace Experimental
232} // namespace ROOT
233
234#endif // ROOT_RNTupleProcessorEntry
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Collection of values in an RNTupleProcessor, analogous to REntry, with checks and support for missing...
std::unordered_set< FieldIndex_t > GetFieldIndices() const
Get all field indices of this entry.
std::optional< FieldIndex_t > FindFieldIndex(std::string_view canonicalFieldName, std::string_view typeName) const
Find the field index of the provided field in the entry.
std::unordered_map< std::string, std::vector< FieldIndex_t > > fFieldName2Index
void BindRawPtr(FieldIndex_t fieldIdx, void *valuePtr)
Bind a new value pointer to a field in the entry.
std::string GetQualifiedFieldName(FieldIndex_t fieldIdx) const
Get the name of a field in the entry, including its parent fields.
const ROOT::RFieldBase::RValue & GetValue(FieldIndex_t fieldIdx) const
bool IsValidField(FieldIndex_t fieldIdx) const
Check whether a field is valid for reading.
void UpdateField(FieldIndex_t fieldIdx, std::unique_ptr< ROOT::RFieldBase > field)
Update a field in the entry, preserving the value pointer.
const std::string & FindFieldName(FieldIndex_t fieldIdx) const
Find the name of a field from its field index.
void ReadValue(FieldIndex_t fieldIdx, ROOT::NTupleSize_t entryIdx)
Read the field value corresponding to the given field index for the provided entry index.
void SetFieldValidity(FieldIndex_t fieldIdx, bool isValid)
Set the validity of a field, i.e.
FieldIndex_t AddField(const std::string &qualifiedFieldName, std::unique_ptr< ROOT::RFieldBase > field, void *valuePtr, const RNTupleProcessorProvenance &provenance)
Add a new field to the entry.
const RNTupleProcessorProvenance & GetFieldProvenance(FieldIndex_t fieldIdx) const
Get the processor provenance of a field in the entry.
std::string Get() const
Get the full processor provenance, in the form of "x.y.z".
bool Contains(const RNTupleProcessorProvenance &other) const
Check whether the provenance subsumes the provenance in other.
bool IsPresentInFieldName(std::string_view fieldName) const
Check whether the provided field name contains this provenance.
RNTupleProcessorProvenance Evolve(const std::string &processorName) const
Add a new processor to the provenance.
Points to an object with RNTuple I/O support and keeps a pointer to the corresponding field.
std::uint64_t NTupleSize_t
Integer type long enough to hold the maximum number of entries in a column.
RProcessorValue(std::unique_ptr< ROOT::RFieldBase > field, std::string_view qualifiedFieldName, ROOT::RFieldBase::RValue &&value, bool isValid, RNTupleProcessorProvenance provenance)