Skip to content

Commit 7587e0d

Browse files
committed
[ntuple] Move RField out of Experimental
1 parent 95e6d65 commit 7587e0d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+984
-994
lines changed

gui/browsable/src/RFieldProvider.hxx

+21-27
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@ using namespace ROOT::Browsable;
2828

2929
using namespace std::string_literals;
3030

31-
// FIXME: this exposes RField and RIntegralField into the global namespace
32-
template<typename T>
33-
using RField = ROOT::Experimental::RField<T>;
34-
template<typename T>
35-
using RIntegralField = ROOT::Experimental::RIntegralField<T>;
36-
3731
// ==============================================================================================
3832

3933
/** \class RFieldProvider
@@ -83,7 +77,7 @@ class RFieldProvider : public RProvider {
8377
}
8478

8579
template <typename T>
86-
void FillHistogramImpl(const ROOT::Experimental::RFieldBase &field, ROOT::Experimental::RNTupleView<T> &view)
80+
void FillHistogramImpl(const ROOT::RFieldBase &field, ROOT::Experimental::RNTupleView<T> &view)
8781
{
8882
std::string title = "Drawing of RField "s + field.GetFieldName();
8983

@@ -107,21 +101,21 @@ class RFieldProvider : public RProvider {
107101
fHist->BufferEmpty();
108102
}
109103

110-
template<typename T>
111-
void FillHistogram(const RIntegralField<T> &field)
104+
template <typename T>
105+
void FillHistogram(const ROOT::RIntegralField<T> &field)
112106
{
113107
auto view = fNtplReader->GetView<T>(field.GetOnDiskId());
114108
FillHistogramImpl(field, view);
115109
}
116110

117-
template<typename T>
118-
void FillHistogram(const RField<T> &field)
111+
template <typename T>
112+
void FillHistogram(const ROOT::RField<T> &field)
119113
{
120114
auto view = fNtplReader->GetView<T>(field.GetOnDiskId());
121115
FillHistogramImpl(field, view);
122116
}
123117

124-
void FillStringHistogram(const RField<std::string> &field)
118+
void FillStringHistogram(const ROOT::RField<std::string> &field)
125119
{
126120
std::map<std::string, int> values;
127121

@@ -161,21 +155,21 @@ class RFieldProvider : public RProvider {
161155
return fHist.release();
162156
}
163157

164-
void VisitField(const ROOT::Experimental::RFieldBase & /* field */) final {}
165-
void VisitBoolField(const RField<bool> &field) final { FillHistogram(field); }
166-
void VisitFloatField(const RField<float> &field) final { FillHistogram(field); }
167-
void VisitDoubleField(const RField<double> &field) final { FillHistogram(field); }
168-
void VisitCharField(const RField<char> &field) final { FillHistogram(field); }
169-
void VisitInt8Field(const RIntegralField<std::int8_t> &field) final { FillHistogram(field); }
170-
void VisitInt16Field(const RIntegralField<std::int16_t> &field) final { FillHistogram(field); }
171-
void VisitInt32Field(const RIntegralField<std::int32_t> &field) final { FillHistogram(field); }
172-
void VisitInt64Field(const RIntegralField<std::int64_t> &field) final { FillHistogram(field); }
173-
void VisitStringField(const RField<std::string> &field) final { FillStringHistogram(field); }
174-
void VisitUInt16Field(const RIntegralField<std::uint16_t> &field) final { FillHistogram(field); }
175-
void VisitUInt32Field(const RIntegralField<std::uint32_t> &field) final { FillHistogram(field); }
176-
void VisitUInt64Field(const RIntegralField<std::uint64_t> &field) final { FillHistogram(field); }
177-
void VisitUInt8Field(const RIntegralField<std::uint8_t> &field) final { FillHistogram(field); }
178-
void VisitCardinalityField(const ROOT::Experimental::RCardinalityField &field) final
158+
void VisitField(const ROOT::RFieldBase & /* field */) final {}
159+
void VisitBoolField(const ROOT::RField<bool> &field) final { FillHistogram(field); }
160+
void VisitFloatField(const ROOT::RField<float> &field) final { FillHistogram(field); }
161+
void VisitDoubleField(const ROOT::RField<double> &field) final { FillHistogram(field); }
162+
void VisitCharField(const ROOT::RField<char> &field) final { FillHistogram(field); }
163+
void VisitInt8Field(const ROOT::RIntegralField<std::int8_t> &field) final { FillHistogram(field); }
164+
void VisitInt16Field(const ROOT::RIntegralField<std::int16_t> &field) final { FillHistogram(field); }
165+
void VisitInt32Field(const ROOT::RIntegralField<std::int32_t> &field) final { FillHistogram(field); }
166+
void VisitInt64Field(const ROOT::RIntegralField<std::int64_t> &field) final { FillHistogram(field); }
167+
void VisitStringField(const ROOT::RField<std::string> &field) final { FillStringHistogram(field); }
168+
void VisitUInt16Field(const ROOT::RIntegralField<std::uint16_t> &field) final { FillHistogram(field); }
169+
void VisitUInt32Field(const ROOT::RIntegralField<std::uint32_t> &field) final { FillHistogram(field); }
170+
void VisitUInt64Field(const ROOT::RIntegralField<std::uint64_t> &field) final { FillHistogram(field); }
171+
void VisitUInt8Field(const ROOT::RIntegralField<std::uint8_t> &field) final { FillHistogram(field); }
172+
void VisitCardinalityField(const ROOT::RCardinalityField &field) final
179173
{
180174
if (const auto f32 = field.As32Bit()) {
181175
FillHistogram(*f32);

tree/dataframe/inc/ROOT/RNTupleDS.hxx

+3-4
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333

3434
namespace ROOT {
3535
class RNTuple;
36+
class RFieldBase;
3637

3738
namespace Experimental {
38-
class RFieldBase;
3939

4040
namespace Internal {
4141
class RNTupleColumnReader;
@@ -84,13 +84,12 @@ class RNTupleDS final : public ROOT::RDF::RDataSource {
8484
/// in GetColumnReaders(), we move a clone of the field into a new column reader for RDataFrame.
8585
/// Only the clone connects to the backing page store and acquires I/O resources.
8686
/// The field IDs are set in the context of the first source and used as keys in fFieldId2QualifiedName.
87-
std::vector<std::unique_ptr<ROOT::Experimental::RFieldBase>> fProtoFields;
87+
std::vector<std::unique_ptr<ROOT::RFieldBase>> fProtoFields;
8888
/// Columns may be requested with types other than with which they were initially added as proto fields. For example,
8989
/// a column with a `ROOT::RVec<float>` proto field may instead be requested as a `std::vector<float>`. In case this
9090
/// happens, we create an alternative proto field and store it here, with the original index in `fProtoFields` as
9191
/// key. A single column can have more than one alternative proto fields.
92-
std::unordered_map<std::size_t, std::vector<std::unique_ptr<ROOT::Experimental::RFieldBase>>>
93-
fAlternativeProtoFields;
92+
std::unordered_map<std::size_t, std::vector<std::unique_ptr<ROOT::RFieldBase>>> fAlternativeProtoFields;
9493
/// Connects the IDs of active proto fields and their subfields to their fully qualified name (a.b.c.d).
9594
/// This enables the column reader to rewire the field IDs when the file changes (chain),
9695
/// using the fully qualified name as a search key in the descriptor of the other page sources.

tree/dataframe/src/RNTupleDS.cxx

+22-25
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,16 @@ namespace Internal {
6161
/// This field owns the collection offset field but instead of exposing the collection offsets it exposes
6262
/// the collection sizes (offset(N+1) - offset(N)). For the time being, we offer this functionality only in RDataFrame.
6363
/// TODO(jblomer): consider providing a general set of useful virtual fields as part of RNTuple.
64-
class RRDFCardinalityField final : public ROOT::Experimental::RFieldBase {
64+
class RRDFCardinalityField final : public ROOT::RFieldBase {
6565
protected:
66-
std::unique_ptr<ROOT::Experimental::RFieldBase> CloneImpl(std::string_view /* newName */) const final
66+
std::unique_ptr<ROOT::RFieldBase> CloneImpl(std::string_view /* newName */) const final
6767
{
6868
return std::make_unique<RRDFCardinalityField>();
6969
}
7070
void ConstructValue(void *where) const final { *static_cast<std::size_t *>(where) = 0; }
7171

7272
public:
73-
RRDFCardinalityField()
74-
: ROOT::Experimental::RFieldBase("", "std::size_t", ROOT::ENTupleStructure::kLeaf, false /* isSimple */)
75-
{
76-
}
73+
RRDFCardinalityField() : ROOT::RFieldBase("", "std::size_t", ROOT::ENTupleStructure::kLeaf, false /* isSimple */) {}
7774
RRDFCardinalityField(RRDFCardinalityField &&other) = default;
7875
RRDFCardinalityField &operator=(RRDFCardinalityField &&other) = default;
7976
~RRDFCardinalityField() = default;
@@ -122,11 +119,11 @@ class RRDFCardinalityField final : public ROOT::Experimental::RFieldBase {
122119
* This is the implementation of `R_rdf_sizeof_column` in case `column` contains
123120
* fixed-size arrays on disk.
124121
*/
125-
class RArraySizeField final : public ROOT::Experimental::RFieldBase {
122+
class RArraySizeField final : public ROOT::RFieldBase {
126123
private:
127124
std::size_t fArrayLength;
128125

129-
std::unique_ptr<ROOT::Experimental::RFieldBase> CloneImpl(std::string_view) const final
126+
std::unique_ptr<ROOT::RFieldBase> CloneImpl(std::string_view) const final
130127
{
131128
return std::make_unique<RArraySizeField>(fArrayLength);
132129
}
@@ -143,7 +140,7 @@ class RArraySizeField final : public ROOT::Experimental::RFieldBase {
143140

144141
public:
145142
RArraySizeField(std::size_t arrayLength)
146-
: ROOT::Experimental::RFieldBase("", "std::size_t", ROOT::ENTupleStructure::kLeaf, false /* isSimple */),
143+
: ROOT::RFieldBase("", "std::size_t", ROOT::ENTupleStructure::kLeaf, false /* isSimple */),
147144
fArrayLength(arrayLength)
148145
{
149146
}
@@ -160,7 +157,7 @@ class RArraySizeField final : public ROOT::Experimental::RFieldBase {
160157

161158
/// Every RDF column is represented by exactly one RNTuple field
162159
class RNTupleColumnReader : public ROOT::Detail::RDF::RColumnReaderBase {
163-
using RFieldBase = ROOT::Experimental::RFieldBase;
160+
using RFieldBase = ROOT::RFieldBase;
164161
using RPageSource = ROOT::Experimental::Internal::RPageSource;
165162

166163
RNTupleDS *fDataSource; ///< The data source that owns this column reader
@@ -199,7 +196,7 @@ class RNTupleColumnReader : public ROOT::Detail::RDF::RColumnReaderBase {
199196
}
200197

201198
try {
202-
ROOT::Experimental::Internal::CallConnectPageSourceOnField(*fField, source);
199+
ROOT::Internal::CallConnectPageSourceOnField(*fField, source);
203200
} catch (const ROOT::RException &err) {
204201
auto onDiskType = source.GetSharedDescriptorGuard()->GetFieldDescriptor(fField->GetOnDiskId()).GetTypeName();
205202
std::string msg = "RNTupleDS: invalid type \"" + fField->GetTypeName() + "\" for column \"" +
@@ -314,15 +311,15 @@ void RNTupleDS::AddField(const RNTupleDescriptor &desc, std::string_view colName
314311

315312
// The fieldID could be the root field or the class of fieldId might not be loaded.
316313
// In these cases, only the inner fields are exposed as RDF columns.
317-
auto fieldOrException = RFieldBase::Create(fieldDesc.GetFieldName(), fieldDesc.GetTypeName());
314+
auto fieldOrException = ROOT::RFieldBase::Create(fieldDesc.GetFieldName(), fieldDesc.GetTypeName());
318315
if (!fieldOrException)
319316
return;
320317
auto valueField = fieldOrException.Unwrap();
321318
valueField->SetOnDiskId(fieldId);
322319
for (auto &f : *valueField) {
323320
f.SetOnDiskId(desc.FindFieldId(f.GetFieldName(), f.GetParent()->GetOnDiskId()));
324321
}
325-
std::unique_ptr<RFieldBase> cardinalityField;
322+
std::unique_ptr<ROOT::RFieldBase> cardinalityField;
326323
// Collections get the additional "number of" RDF column (e.g. "R_rdf_sizeof_tracks")
327324
if (!fieldInfos.empty()) {
328325
const auto &info = fieldInfos.back();
@@ -339,16 +336,15 @@ void RNTupleDS::AddField(const RNTupleDescriptor &desc, std::string_view colName
339336

340337
if (fieldInfo.fNRepetitions > 0) {
341338
// Fixed-size array, read it as ROOT::RVec in memory
342-
valueField =
343-
std::make_unique<ROOT::Experimental::RArrayAsRVecField>("", std::move(valueField), fieldInfo.fNRepetitions);
339+
valueField = std::make_unique<ROOT::RArrayAsRVecField>("", std::move(valueField), fieldInfo.fNRepetitions);
344340
} else {
345341
// Actual collection. A std::vector or ROOT::RVec gets added as a ROOT::RVec. All other collection types keep
346342
// their original type.
347343
if (convertToRVec) {
348-
valueField = std::make_unique<ROOT::Experimental::RRVecField>("", std::move(valueField));
344+
valueField = std::make_unique<ROOT::RRVecField>("", std::move(valueField));
349345
} else {
350346
auto outerFieldType = desc.GetFieldDescriptor(fieldInfo.fFieldId).GetTypeName();
351-
valueField = RFieldBase::Create("", outerFieldType).Unwrap();
347+
valueField = ROOT::RFieldBase::Create("", outerFieldType).Unwrap();
352348
}
353349
}
354350

@@ -359,11 +355,11 @@ void RNTupleDS::AddField(const RNTupleDescriptor &desc, std::string_view colName
359355
if (i != fieldInfos.rbegin()) {
360356
if (fieldInfo.fNRepetitions > 0) {
361357
// This collection level refers to a fixed-size array
362-
cardinalityField = std::make_unique<ROOT::Experimental::RArrayAsRVecField>("", std::move(cardinalityField),
363-
fieldInfo.fNRepetitions);
358+
cardinalityField =
359+
std::make_unique<ROOT::RArrayAsRVecField>("", std::move(cardinalityField), fieldInfo.fNRepetitions);
364360
} else {
365361
// This collection level refers to an RVec
366-
cardinalityField = std::make_unique<ROOT::Experimental::RRVecField>("", std::move(cardinalityField));
362+
cardinalityField = std::make_unique<ROOT::RRVecField>("", std::move(cardinalityField));
367363
}
368364

369365
cardinalityField->SetOnDiskId(fieldInfo.fFieldId);
@@ -450,19 +446,20 @@ RNTupleDS::GetColumnReaders(unsigned int slot, std::string_view name, const std:
450446
const auto index = std::distance(fColumnNames.begin(), std::find(fColumnNames.begin(), fColumnNames.end(), name));
451447
const auto requestedType = ROOT::Internal::GetRenormalizedTypeName(ROOT::Internal::RDF::TypeID2TypeName(tid));
452448

453-
RFieldBase *field;
449+
ROOT::RFieldBase *field;
454450
// If the field corresponding to the provided name is not a cardinality column and the requested type is different
455451
// from the proto field that was created when the data source was constructed, we first have to create an
456452
// alternative proto field for the column reader. Otherwise, we can directly use the existing proto field.
457453
if (name.substr(0, 13) != "R_rdf_sizeof_" && requestedType != fColumnTypes[index]) {
458454
auto &altProtoFields = fAlternativeProtoFields[index];
459-
auto altProtoField = std::find_if(
460-
altProtoFields.begin(), altProtoFields.end(),
461-
[&requestedType](const std::unique_ptr<RFieldBase> &fld) { return fld->GetTypeName() == requestedType; });
455+
auto altProtoField = std::find_if(altProtoFields.begin(), altProtoFields.end(),
456+
[&requestedType](const std::unique_ptr<ROOT::RFieldBase> &fld) {
457+
return fld->GetTypeName() == requestedType;
458+
});
462459
if (altProtoField != altProtoFields.end()) {
463460
field = altProtoField->get();
464461
} else {
465-
auto newAltProtoFieldOrException = RFieldBase::Create(std::string(name), requestedType);
462+
auto newAltProtoFieldOrException = ROOT::RFieldBase::Create(std::string(name), requestedType);
466463
if (!newAltProtoFieldOrException) {
467464
throw std::runtime_error("RNTupleDS: Could not create field with type \"" + requestedType +
468465
"\" for column \"" + std::string(name));

tree/dataframe/test/datasource_ntuple.cxx

+6-7
Original file line numberDiff line numberDiff line change
@@ -377,17 +377,16 @@ TEST(RNTupleDS, CollectionFieldTypes)
377377
std::set<std::set<Electron>>{{Electron{1.f}, Electron{2.f}}, {Electron{3.f}}};
378378

379379
// Untyped collection
380-
auto fldJetPt = ROOT::Experimental::RVectorField::CreateUntyped(
381-
"jet_pt", std::make_unique<ROOT::Experimental::RField<float>>("_0"));
380+
auto fldJetPt = ROOT::RVectorField::CreateUntyped("jet_pt", std::make_unique<ROOT::RField<float>>("_0"));
382381
model->AddField(std::move(fldJetPt));
383382

384383
// Untyped collection with an untyped record, with a projection
385-
std::vector<std::unique_ptr<ROOT::Experimental::RFieldBase>> muon;
386-
muon.emplace_back(std::make_unique<ROOT::Experimental::RField<float>>("muon_pt"));
387-
auto fldMuonRecord = std::make_unique<ROOT::Experimental::RRecordField>("_0", std::move(muon));
388-
auto fldMuons = ROOT::Experimental::RVectorField::CreateUntyped("muon", std::move(fldMuonRecord));
384+
std::vector<std::unique_ptr<ROOT::RFieldBase>> muon;
385+
muon.emplace_back(std::make_unique<ROOT::RField<float>>("muon_pt"));
386+
auto fldMuonRecord = std::make_unique<ROOT::RRecordField>("_0", std::move(muon));
387+
auto fldMuons = ROOT::RVectorField::CreateUntyped("muon", std::move(fldMuonRecord));
389388
model->AddField(std::move(fldMuons));
390-
auto muonPtField = ROOT::Experimental::RFieldBase::Create("muon_pt", "ROOT::VecOps::RVec<float>").Unwrap();
389+
auto muonPtField = ROOT::RFieldBase::Create("muon_pt", "ROOT::VecOps::RVec<float>").Unwrap();
391390
model->AddProjectedField(std::move(muonPtField), [](const std::string &fieldName) {
392391
if (fieldName == "muon_pt")
393392
return "muon";

tree/ntuple/v7/inc/ROOT/REntry.hxx

+11-11
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ private:
7878
/// The entry and its tokens are also linked to a specific schema, identified by a schema ID
7979
std::uint64_t fSchemaId = 0;
8080
/// Corresponds to the fields of the linked model
81-
std::vector<RFieldBase::RValue> fValues;
81+
std::vector<ROOT::RFieldBase::RValue> fValues;
8282
/// For fast lookup of token IDs given a (sub)field name present in the entry
8383
std::unordered_map<std::string, std::size_t> fFieldName2Token;
8484
/// To ensure that the entry is standalone, a copy of all field types
@@ -89,7 +89,7 @@ private:
8989
REntry() = default;
9090
explicit REntry(std::uint64_t modelId, std::uint64_t schemaId) : fModelId(modelId), fSchemaId(schemaId) {}
9191

92-
void AddValue(RFieldBase::RValue &&value)
92+
void AddValue(ROOT::RFieldBase::RValue &&value)
9393
{
9494
fFieldName2Token[value.GetField().GetQualifiedFieldName()] = fValues.size();
9595
fFieldTypes.push_back(value.GetField().GetTypeName());
@@ -98,7 +98,7 @@ private:
9898

9999
/// While building the entry, adds a new value to the list and return the value's shared pointer
100100
template <typename T>
101-
std::shared_ptr<T> AddValue(RField<T> &field)
101+
std::shared_ptr<T> AddValue(ROOT::RField<T> &field)
102102
{
103103
fFieldName2Token[field.GetQualifiedFieldName()] = fValues.size();
104104
fFieldTypes.push_back(field.GetTypeName());
@@ -107,14 +107,14 @@ private:
107107
return value.template GetPtr<T>();
108108
}
109109

110-
/// Update the RValue for a field in the entry. To be used when its underlying RFieldBase changes, which typically
111-
/// happens when page source the field values are read from changes.
112-
void UpdateValue(RFieldToken token, RFieldBase::RValue &&value) { std::swap(fValues.at(token.fIndex), value); }
113-
void UpdateValue(RFieldToken token, RFieldBase::RValue &value) { std::swap(fValues.at(token.fIndex), value); }
110+
/// Update the RValue for a field in the entry. To be used when its underlying ROOT::RFieldBase changes, which
111+
/// typically happens when page source the field values are read from changes.
112+
void UpdateValue(RFieldToken token, ROOT::RFieldBase::RValue &&value) { std::swap(fValues.at(token.fIndex), value); }
113+
void UpdateValue(RFieldToken token, ROOT::RFieldBase::RValue &value) { std::swap(fValues.at(token.fIndex), value); }
114114

115115
/// Return the RValue currently bound to the provided field.
116-
RFieldBase::RValue &GetValue(RFieldToken token) { return fValues.at(token.fIndex); }
117-
RFieldBase::RValue &GetValue(std::string_view fieldName) { return GetValue(GetToken(fieldName)); }
116+
ROOT::RFieldBase::RValue &GetValue(RFieldToken token) { return fValues.at(token.fIndex); }
117+
ROOT::RFieldBase::RValue &GetValue(std::string_view fieldName) { return GetValue(GetToken(fieldName)); }
118118

119119
void Read(ROOT::NTupleSize_t index)
120120
{
@@ -157,9 +157,9 @@ private:
157157
void EnsureMatchingType(RFieldToken token [[maybe_unused]]) const
158158
{
159159
if constexpr (!std::is_void_v<T>) {
160-
if (fFieldTypes[token.fIndex] != RField<T>::TypeName()) {
160+
if (fFieldTypes[token.fIndex] != ROOT::RField<T>::TypeName()) {
161161
throw RException(R__FAIL("type mismatch for field " + FindFieldName(token) + ": " +
162-
fFieldTypes[token.fIndex] + " vs. " + RField<T>::TypeName()));
162+
fFieldTypes[token.fIndex] + " vs. " + ROOT::RField<T>::TypeName()));
163163
}
164164
}
165165
}

0 commit comments

Comments
 (0)