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
22{
23 for (auto &fieldContext : fFieldContexts) {
24 fieldContext.ResetConcreteField();
25 }
27 fPageSource->Attach();
29 return fPageSource->GetNEntries();
30}
31
33{
34 auto desc = fPageSource->GetSharedDescriptorGuard();
35
36 for (auto &fieldContext : fFieldContexts) {
37 auto fieldId = desc->FindFieldId(fieldContext.GetProtoField().GetFieldName());
38 if (fieldId == kInvalidDescriptorId) {
39 throw RException(
40 R__FAIL("field \"" + fieldContext.GetProtoField().GetFieldName() + "\" not found in current RNTuple"));
41 }
42
43 fieldContext.SetConcreteField();
44 fieldContext.fConcreteField->SetOnDiskId(desc->FindFieldId(fieldContext.GetProtoField().GetFieldName()));
45 Internal::CallConnectPageSourceOnField(*fieldContext.fConcreteField, *fPageSource);
46
47 auto valuePtr = fEntry->GetPtr<void>(fieldContext.fToken);
48 auto value = fieldContext.fConcreteField->CreateValue();
49 value.Bind(valuePtr);
50 fEntry->UpdateValue(fieldContext.fToken, value);
51 }
52}
53
54ROOT::Experimental::Internal::RNTupleProcessor::RNTupleProcessor(const std::vector<RNTupleSourceSpec> &ntuples,
55 std::unique_ptr<RNTupleModel> model)
56 : fNTuples(ntuples)
57{
58 if (fNTuples.empty())
59 throw RException(R__FAIL("at least one RNTuple must be provided"));
60
62 fPageSource->Attach();
63
64 if (fPageSource->GetNEntries() == 0) {
65 throw RException(R__FAIL("first RNTuple does not contain any entries"));
66 }
67
68 if (!model)
69 model = fPageSource->GetSharedDescriptorGuard()->CreateModel();
70
71 model->Freeze();
72 fEntry = model->CreateEntry();
73
74 for (const auto &value : *fEntry) {
75 auto &field = value.GetField();
76 auto token = fEntry->GetToken(field.GetFieldName());
77
78 // If the model has a default entry, use the value pointers from the entry in the entry managed by the
79 // processor. This way, the pointers returned by RNTupleModel::MakeField can be used in the processor loop to
80 // access the corresponding field values.
81 if (!model->IsBare()) {
82 auto valuePtr = model->GetDefaultEntry().GetPtr<void>(token);
83 fEntry->BindValue(token, valuePtr);
84 }
85
86 fFieldContexts.emplace_back(field.Clone(field.GetFieldName()), token);
87 }
88
90}
#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
RNTupleProcessor(const std::vector< RNTupleSourceSpec > &ntuples, std::unique_ptr< RNTupleModel > model=nullptr)
Constructs a new RNTupleProcessor.
std::unique_ptr< Internal::RPageSource > fPageSource
NTupleSize_t ConnectNTuple(const RNTupleSourceSpec &ntuple)
Connect an RNTuple for processing.
void ConnectFields()
Creates and connects concrete fields to the current page source, based on the proto-fields.
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
void CallConnectPageSourceOnField(RFieldBase &, RPageSource &)
Definition RField.cxx:420
std::uint64_t NTupleSize_t
Integer type long enough to hold the maximum number of entries in a column.
constexpr DescriptorId_t kInvalidDescriptorId
Helper type representing the name and storage location of an RNTuple.