Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RNTupleProcessorEntry.cxx
Go to the documentation of this file.
1/// \file RNTupleProcessor.cxx
2/// \ingroup NTuple
3/// \author Florine de Geus <florine.de.geus@cern.ch>
4/// \date 2026-05-11
5/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
6/// is welcome!
7
8/*************************************************************************
9 * Copyright (C) 1995-2026, Rene Brun and Fons Rademakers. *
10 * All rights reserved. *
11 * *
12 * For the licensing terms see $ROOTSYS/LICENSE. *
13 * For the list of contributors see $ROOTSYS/README/CREDITS. *
14 *************************************************************************/
15
17
19{
21
22 for (const auto &[fieldName, index] : fFieldName2Index) {
23 if (std::find(index.begin(), index.end(), fieldIdx) != index.end()) {
24 return fieldName;
25 }
26 }
27 // Should never happen, but avoid compiler warning about "returning reference to local temporary object".
28 R__ASSERT(false);
29 static const std::string empty = "";
30 return empty;
31}
32
33std::optional<ROOT::Experimental::Internal::RNTupleProcessorEntry::FieldIndex_t>
35 std::string_view typeName) const
36{
37 auto it = fFieldName2Index.find(std::string(canonicalFieldName));
38 if (it == fFieldName2Index.end()) {
39 return std::nullopt;
40 }
41
42 const auto &fieldIdxs = it->second;
43 assert(!fieldIdxs.empty());
44
45 for (auto idx : fieldIdxs) {
46 if (fProcessorValues[idx].fField->GetTypeName() == typeName) {
47 return idx;
48 }
49 }
50
51 return std::nullopt;
52}
53
56 std::unique_ptr<ROOT::RFieldBase> field, void *valuePtr,
58{
60 if (const auto &processorPrefix = provenance.Get(); !processorPrefix.empty())
62
63 if (FindFieldIndex(fieldNameWithProcessorPrefix, field->GetTypeName()))
64 throw ROOT::RException(R__FAIL("field \"" + fieldNameWithProcessorPrefix + "\" is already present in the entry"));
65
66 auto fieldIdx = fProcessorValues.size();
67 fFieldName2Index[fieldNameWithProcessorPrefix].push_back(fieldIdx);
68
70 auto value = field->CreateValue();
71 if (valuePtr)
72 value.BindRawPtr(valuePtr);
73 fProcessorValues.emplace_back(
74 RProcessorValue(std::move(field), qualifiedFieldName, std::move(value), true, provenance));
75
76 return fieldIdx;
77}
78
80 std::unique_ptr<ROOT::RFieldBase> field)
81{
82 assert(fieldIdx < fProcessorValues.size());
83
84 auto &fieldInfo = fProcessorValues[fieldIdx];
85
86 if (field) {
87 auto newValue = field->CreateValue();
88 auto currValuePtr = fieldInfo.fValue.GetPtr<void>();
90 fieldInfo.fField = std::move(field);
91 fieldInfo.fValue = std::move(newValue);
92 fieldInfo.fIsValid = true;
93 } else {
94 fieldInfo.fIsValid = false;
95 }
96}
97
99{
100 assert(fieldIdx < fProcessorValues.size());
101 fProcessorValues[fieldIdx].fValue.BindRawPtr(valuePtr);
102}
103
105{
106 assert(fieldIdx < fProcessorValues.size());
107
108 if (fProcessorValues[fieldIdx].fIsValid) {
109 fProcessorValues[fieldIdx].fValue.Read(entryIdx);
110 }
111}
112
113std::unordered_set<ROOT::Experimental::Internal::RNTupleProcessorEntry::FieldIndex_t>
115{
116 // Field indices are sequentially assigned, and the entry (currently) offers no way to remove fields, so we can just
117 // generate and return a set {0, ..., |fProcessorValues| - 1}.
118 std::unordered_set<FieldIndex_t> fieldIdxs(fProcessorValues.size());
119 std::generate_n(std::inserter(fieldIdxs, fieldIdxs.begin()), fProcessorValues.size(),
120 [i = 0]() mutable { return i++; });
121 return fieldIdxs;
122}
#define R__FAIL(msg)
Short-hand to return an RResult<T> in an error state; the RError is implicitly converted into RResult...
Definition RError.hxx:299
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
Definition TError.h:125
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
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.
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.
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.
Base class for all ROOT issued exceptions.
Definition RError.hxx:78
const_iterator begin() const
std::uint64_t NTupleSize_t
Integer type long enough to hold the maximum number of entries in a column.