Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RNTupleProcessor.cxx
Go to the documentation of this file.
1/// \file RNTupleProcessor.cxx
2/// \ingroup NTuple ROOT7
3/// \author Florine de Geus <florine.de.geus@cern.ch>
4/// \date 2024-03-26
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-2024, 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
18#include <ROOT/RFieldBase.hxx>
19
20std::unique_ptr<ROOT::Experimental::RNTupleProcessor>
21ROOT::Experimental::RNTupleProcessor::CreateChain(const std::vector<RNTupleOpenSpec> &ntuples,
22 std::unique_ptr<RNTupleModel> model)
23{
24 return std::unique_ptr<RNTupleChainProcessor>(new RNTupleChainProcessor(ntuples, std::move(model)));
25}
26
27//------------------------------------------------------------------------------
28
29ROOT::Experimental::RNTupleChainProcessor::RNTupleChainProcessor(const std::vector<RNTupleOpenSpec> &ntuples,
30 std::unique_ptr<RNTupleModel> model)
31 : RNTupleProcessor(ntuples)
32{
33 if (fNTuples.empty())
34 throw RException(R__FAIL("at least one RNTuple must be provided"));
35
36 fPageSource = Internal::RPageSource::Create(fNTuples[0].fNTupleName, fNTuples[0].fStorage);
37 fPageSource->Attach();
38
39 if (fPageSource->GetNEntries() == 0) {
40 throw RException(R__FAIL("first RNTuple does not contain any entries"));
41 }
42
43 if (!model)
44 model = fPageSource->GetSharedDescriptorGuard()->CreateModel();
45
46 model->Freeze();
47 fEntry = model->CreateEntry();
48
49 for (const auto &value : *fEntry) {
50 auto &field = value.GetField();
51 auto token = fEntry->GetToken(field.GetFieldName());
52
53 // If the model has a default entry, use the value pointers from the entry in the entry managed by the
54 // processor. This way, the pointers returned by RNTupleModel::MakeField can be used in the processor loop to
55 // access the corresponding field values.
56 if (!model->IsBare()) {
57 auto valuePtr = model->GetDefaultEntry().GetPtr<void>(token);
58 fEntry->BindValue(token, valuePtr);
59 }
60
61 fFieldContexts.emplace_back(field.Clone(field.GetFieldName()), token);
62 }
63
65}
66
68{
69 for (auto &fieldContext : fFieldContexts) {
70 fieldContext.ResetConcreteField();
71 }
72 fPageSource = Internal::RPageSource::Create(ntuple.fNTupleName, ntuple.fStorage);
73 fPageSource->Attach();
74 ConnectFields();
75 return fPageSource->GetNEntries();
76}
77
79{
80 auto desc = fPageSource->GetSharedDescriptorGuard();
81
82 for (auto &fieldContext : fFieldContexts) {
83 auto fieldId = desc->FindFieldId(fieldContext.GetProtoField().GetFieldName());
84 if (fieldId == kInvalidDescriptorId) {
85 throw RException(
86 R__FAIL("field \"" + fieldContext.GetProtoField().GetFieldName() + "\" not found in current RNTuple"));
87 }
88
89 fieldContext.SetConcreteField();
90 fieldContext.fConcreteField->SetOnDiskId(desc->FindFieldId(fieldContext.GetProtoField().GetFieldName()));
91 Internal::CallConnectPageSourceOnField(*fieldContext.fConcreteField, *fPageSource);
92
93 auto valuePtr = fEntry->GetPtr<void>(fieldContext.fToken);
94 auto value = fieldContext.fConcreteField->CreateValue();
95 value.Bind(valuePtr);
96 fEntry->UpdateValue(fieldContext.fToken, value);
97 }
98}
99
101{
102 ++fNEntriesProcessed;
103
104 if (++fLocalEntryNumber >= fPageSource->GetNEntries()) {
105 do {
106 if (++fCurrentNTupleNumber >= fNTuples.size()) {
107 return kInvalidNTupleIndex;
108 }
109 // Skip over empty ntuples we might encounter.
110 } while (ConnectNTuple(fNTuples.at(fCurrentNTupleNumber)) == 0);
111
112 fLocalEntryNumber = 0;
113 }
114
115 fEntry->Read(fLocalEntryNumber);
116
117 return fNEntriesProcessed;
118}
#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:290
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
static std::unique_ptr< RPageSource > Create(std::string_view ntupleName, std::string_view location, const RNTupleReadOptions &options=RNTupleReadOptions())
Guess the concrete derived page source from the file name (location)
Base class for all ROOT issued exceptions.
Definition RError.hxx:78
Processor specializiation for vertically concatenated RNTuples (chains).
void ConnectFields() final
Creates and connects concrete fields to the current page source, based on the proto-fields.
NTupleSize_t Advance() final
Advance the processor to the next available entry.
RNTupleChainProcessor(const std::vector< RNTupleOpenSpec > &ntuples, std::unique_ptr< RNTupleModel > model=nullptr)
Constructs a new RNTupleChainProcessor.
NTupleSize_t ConnectNTuple(const RNTupleOpenSpec &ntuple) final
Connect an RNTuple for processing.
Interface for iterating over entries of RNTuples and vertically concatenated RNTuples (chains).
std::vector< RFieldContext > fFieldContexts
static std::unique_ptr< RNTupleProcessor > CreateChain(const std::vector< RNTupleOpenSpec > &ntuples, std::unique_ptr< RNTupleModel > model=nullptr)
Create a new RNTuple processor chain for vertical concatenation of RNTuples.
std::unique_ptr< Internal::RPageSource > fPageSource
std::vector< RNTupleOpenSpec > fNTuples
void CallConnectPageSourceOnField(RFieldBase &, RPageSource &)
Definition RField.cxx:411
std::uint64_t NTupleSize_t
Integer type long enough to hold the maximum number of entries in a column.
constexpr NTupleSize_t kInvalidNTupleIndex
constexpr DescriptorId_t kInvalidDescriptorId
Used to specify the underlying RNTuples in RNTupleProcessor and RNTupleReader::OpenFriends()