Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RNTupleProcessor.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 2024-03-26
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_RNTupleProcessor
16#define ROOT_RNTupleProcessor
17
18#include <ROOT/REntry.hxx>
19#include <ROOT/RError.hxx>
22#include <ROOT/RNTupleModel.hxx>
23#include <ROOT/RNTupleTypes.hxx>
25#include <ROOT/RPageStorage.hxx>
26
27#include <memory>
28#include <string>
29#include <string_view>
30#include <vector>
31
32namespace ROOT {
33class RNTupleProcessor;
34template <typename T>
35class RNTupleProcessorValuePtr;
36namespace Experimental {
37class RNTupleJoinProcessor;
38
39namespace Internal {
40namespace RDF {
41class RNTupleProcessorColumnReader;
43} // namespace RDF
44} // namespace Internal
45} // namespace Experimental
46
47namespace Internal {
48struct RNTupleProcessorEntryLoader; // for unit tests
49const RNTupleProcessorEntry *
50LoadFullRNTupleProcessorEntry(ROOT::RNTupleProcessor &processor, bool includeSubfields); // for unit tests
51// Enables rebinding fields from an RNTupleProcessorValuePtr<void> to a different reading destination. Used in
52// RNTupleProcessorDataSource.
53ROOT::RFieldBase::RValue CreateRValueFromValuePtr(RNTupleProcessorValuePtr<void> &valuePtr);
54} // namespace Internal
55
57private:
58 /// By default, the processor name is the name of the underlying RNTuple for RNTupleSingleProcessor, the name of the
59 /// first processor for RNTupleChainProcessor, or the name of the primary RNTuple for RNTupleJoinProcessor.
60 std::string fProcessorName = "";
61
62public:
63 /////////////////////////////////////////////////////////////////////////////
64 /// \brief Get the processor's name.
65 const std::string &GetProcessorName() const { return fProcessorName; }
66
67 /////////////////////////////////////////////////////////////////////////////
68 /// \brief Set the processor's name.
69 ///
70 /// \param[in] name Name to assign to the processor.
71 ///
72 /// By default, the processor name is the name of the underlying RNTuple for RNTupleSingleProcessor, the name of the
73 /// first processor for RNTupleChainProcessor, or the name of the primary RNTuple for RNTupleJoinProcessor.
74 void SetProcessorName(std::string_view name) { fProcessorName = name; }
75};
76
77// clang-format off
78/**
79\class ROOT::RNTupleProcessorValuePtr<T>
80\ingroup NTuple
81\brief The RNTupleProcessorValuePtr provides access to values from fields present in an RNTupleProcessor, with support
82and checks for missing values.
83*/
84// clang-format on
85template <typename T>
87 friend class RNTupleProcessor;
88
89private:
92
98
99 /////////////////////////////////////////////////////////////////////////////
100 /// \brief Get a non-owning pointer to the field value managed by the processor's entry.
101 ///
102 /// \return A `T*` if the field is valid in the current entry, or a `nullptr` otherwise.
103 T *GetRawPtr() const { return GetPtr().get(); }
104
105 /////////////////////////////////////////////////////////////////////////////
106 /// \brief Bind the value to `valuePtr`.
107 ///
108 /// \param[in] valuePtr Pointer to bind the value to.
109 ///
110 /// \warning Use this function with care! Values may not always be valid for every entry during processing, for
111 /// example when a field is not present in one of the chained processors or when during a join operation, no matching
112 /// entry in the auxiliary processor can be found. Reading `valuePtr` as-is therefore comes with the risk of reading
113 /// invalid data. After binding a pointer to an `RNTupleProcessorValuePtr`, we *strongly* recommend only accessing
114 /// its data through this interface, to ensure that only valid data can be read.
115 void BindRawPtr(T *valuePtr) { fProcessorEntry->BindRawPtr(fFieldIndex, valuePtr); }
116
117public:
118 /////////////////////////////////////////////////////////////////////////////
119 /// \brief Check if the pointer currently holds a valid value.
121
122 /////////////////////////////////////////////////////////////////////////////
123 /// \brief Get a shared pointer to the field value managed by the processor's entry.
124 ///
125 /// \return A `std::shared_ptr<T>` if the field is valid in the current entry, or a `nullptr` otherwise.
126 std::shared_ptr<T> GetPtr() const
127 {
130 return value.template GetPtr<T>();
131 }
132
133 return nullptr;
134 }
135
136 /////////////////////////////////////////////////////////////////////////////
137 /// \brief Bind the value to `valuePtr`.
138 ///
139 /// \param[in] valuePtr Pointer to bind the value to.
140 ///
141 /// \warning Use this function with care! Values may not always be valid for every entry during processing, for
142 /// example when a field is not present in one of the chained processors or when during a join operation, no matching
143 /// entry in the auxiliary processor can be found. Reading `valuePtr` as-is therefore comes with the risk of reading
144 /// invalid data. After binding a pointer to an `RNTupleProcessorValuePtr`, we *strongly* recommend only accessing
145 /// its data through this interface, to ensure that only valid data can be read.
146 void Bind(std::shared_ptr<T> valuePtr) { fProcessorEntry->Bind(fFieldIndex, std::move(valuePtr)); }
147
148 /////////////////////////////////////////////////////////////////////////////
149 /// \brief Get a reference to the field value managed by the processor's entry.
150 ///
151 /// Throws an exception if the field is invalid in the processor's current entry.
152 const T &operator*() const
153 {
154 if (auto ptr = GetPtr())
155 return *ptr;
156 else
157 throw RException(R__FAIL("cannot read \"" + fProcessorEntry->FindFieldName(fFieldIndex) +
158 "\" because it has no value for the current entry"));
159 }
160
161 /////////////////////////////////////////////////////////////////////////////
162 /// \brief Access the field value managed by the processor's entry.
163 ///
164 /// Throws an exception if the field is invalid in the processor's current entry.
165 const T *operator->() const
166 {
167 if (auto ptr = GetPtr())
168 return ptr.get();
169 else
170 throw RException(R__FAIL("cannot read \"" + fProcessorEntry->FindFieldName(fFieldIndex) +
171 "\" because it has no value for the current entry"));
172 }
173
175 {
176 return lhs.fProcessorEntry == rhs.fProcessorEntry && lhs.fFieldIndex == rhs.fFieldIndex;
177 }
178};
179
180// clang-format off
181/**
182\class ROOT::RNTupleProcessorValuePtr<void>
183\ingroup NTuple
184\brief Specialization of RNTupleProcessorValuePtr<T> for `void`-type pointers.
185*/
186// clang-format on
187template <>
189 friend class RNTupleProcessor;
190
192
193private:
196
202
203 /////////////////////////////////////////////////////////////////////////////
204 /// \brief Get a non-owning pointer to the field value managed by the processor's entry.
205 ///
206 /// \return A `void*` if the field is valid in the current entry, or a `nullptr` otherwise.
207 void *GetRawPtr() const { return GetPtr().get(); }
208
209 /////////////////////////////////////////////////////////////////////////////
210 /// \brief Bind the value to `valuePtr`.
211 ///
212 /// \param[in] valuePtr Pointer to bind the value to.
213 ///
214 /// \warning Use this function with care! Values may not always be valid for every entry during processing, for
215 /// example when a field is not present in one of the chained processors or when during a join operation, no matching
216 /// entry in the auxiliary processor can be found. Reading `valuePtr` as-is therefore comes with the risk of reading
217 /// invalid data. After binding a pointer to an `RNTupleProcessorValuePtr`, we *strongly* recommend only accessing
218 /// its data through this interface, to ensure that only valid data can be read.
219 void BindRawPtr(void *valuePtr) { fProcessorEntry->BindRawPtr(fFieldIndex, valuePtr); }
220
221 /////////////////////////////////////////////////////////////////////////////
222 /// \brief Create an RValue connected to the field managed by the processor's entry.
224
225public:
226 /////////////////////////////////////////////////////////////////////////////
227 /// \brief Check if the pointer currently holds a valid value.
229
230 /////////////////////////////////////////////////////////////////////////////
231 /// \brief Get the pointer to the field value managed by the processor's entry.
232 ///
233 /// \return A `std::shared_ptr<void>` if the field is valid in the current entry, or a `nullptr` otherwise.
234 std::shared_ptr<void> GetPtr() const
235 {
238 return value.template GetPtr<void>();
239 }
240
241 return nullptr;
242 }
243
244 /////////////////////////////////////////////////////////////////////////////
245 /// \brief Bind the value to `valuePtr`.
246 ///
247 /// \param[in] valuePtr Pointer to bind the value to.
248 ///
249 /// \warning Use this function with care! Values may not always be valid for every entry during processing, for
250 /// example when a field is not present in one of the chained processors or when during a join operation, no matching
251 /// entry in the auxiliary processor can be found. Reading `valuePtr` as-is therefore comes with the risk of reading
252 /// invalid data. After binding a pointer to an `RNTupleProcessorValuePtr`, we *strongly* recommend only accessing
253 /// its data through this interface, to ensure that only valid data can be read.
254 void Bind(std::shared_ptr<void> valuePtr) { fProcessorEntry->Bind(fFieldIndex, std::move(valuePtr)); }
255
257 {
258 return lhs.fProcessorEntry == rhs.fProcessorEntry && lhs.fFieldIndex == rhs.fFieldIndex;
259 }
260};
261
262// clang-format off
263/**
264\class ROOT::RNTupleProcessor
265\ingroup NTuple
266\brief Interface for iterating over entries of vertically ("chained") and/or horizontally ("joined") combined RNTuples.
267
268Example usage (see ntpl012_processor_chain.C and ntpl015_processor_join.C for bigger examples):
269
270~~~{.cpp}
271#include <ROOT/RNTupleProcessor.hxx>
272
273std::vector<ROOT::RNTupleInputSpec> ntuples = {{"ntuple1", "ntuple1.root"}, {"ntuple2", "ntuple2.root"}};
274auto processor = ROOT::RNTupleProcessor::CreateChain(ntuples);
275
276auto pt = processor->RequestField<float>("pt");
277
278for (const auto &idx : *processor) {
279 processor->LoadEntry(idx);
280 std::cout << "event = " << idx.GetEntryNumber() << ", pt = " << *pt << std::endl;
281}
282~~~
283
284An RNTupleProcessor is created either:
2851. By providing one or more RNTupleInputSpecs, each of which contains the name and storage location of a single RNTuple;
2862. By providing a previously created RNTupleProcessor.
287
288The RNTupleProcessor provides an iterator which gives access to the index of the current *global* entry of the
289processor, i.e. taking into account previously processed RNTuples.
290
291Because the schemas of each RNTuple that are part of an RNTupleProcessor may not necessarily be identical, or because
292it can occur that entries are only partially complete in a join-based processor, field values may be marked as
293"invalid", at which point their data should not be read. This is handled by the RNTupleProcessorValuePtr
294that is returned by RequestField().
295*/
296// clang-format on
298 friend struct ROOT::Internal::RNTupleProcessorEntryLoader; // for unit tests
301 bool includeSubfields); // For unit tests
306
307protected:
308 /////////////////////////////////////////////////////////////////////////////
309 /// \brief Maps a processor's global (outer) entry index to its inner ones
314
315 private:
317
318 // Used by chain processors
319 std::size_t fInnerProcessorIdx = 0;
320 std::unique_ptr<REntryMapping> fInnerMapping = nullptr;
321
322 // Used by join processors
323 std::unique_ptr<REntryMapping> fPrimaryMapping = nullptr;
324 std::unique_ptr<REntryMapping> fAuxiliaryMapping = nullptr;
325
326 void SetEntryNumber(ROOT::NTupleSize_t entryNumber) { fEntryNumber = entryNumber; }
327
328 std::size_t GetInnerProcessorIdx() const { return fInnerProcessorIdx; }
329 void SetInnerProcessorIdx(std::size_t idx) { fInnerProcessorIdx = idx; }
330
332 {
333 if (!fInnerMapping)
334 fInnerMapping = std::make_unique<REntryMapping>();
335 return *fInnerMapping;
336 }
337
339 {
340 assert(fInnerMapping);
341 return *fInnerMapping;
342 }
343
345 {
346 if (!fPrimaryMapping)
347 fPrimaryMapping = std::make_unique<REntryMapping>();
348 return *fPrimaryMapping;
349 }
350
352 {
353 assert(fPrimaryMapping);
354 return *fPrimaryMapping;
355 }
356
358 {
360 fAuxiliaryMapping = std::make_unique<REntryMapping>();
361 return *fAuxiliaryMapping;
362 }
363
365 {
366 assert(fAuxiliaryMapping);
367 return *fAuxiliaryMapping;
368 }
369
370 friend bool operator==(const REntryMapping &lhs, const REntryMapping &rhs)
371 {
372 return lhs.fEntryNumber == rhs.fEntryNumber && lhs.fInnerProcessorIdx == rhs.fInnerProcessorIdx &&
373 ((lhs.fInnerMapping == nullptr && rhs.fInnerMapping == nullptr) ||
374 *lhs.fInnerMapping == *rhs.fInnerMapping) &&
375 ((lhs.fPrimaryMapping == nullptr && rhs.fPrimaryMapping == nullptr) ||
376 *lhs.fPrimaryMapping == *rhs.fPrimaryMapping) &&
377 ((lhs.fAuxiliaryMapping == nullptr && rhs.fAuxiliaryMapping == nullptr) ||
379 }
380
381 friend bool operator!=(const REntryMapping &lhs, const REntryMapping &rhs) { return !(lhs == rhs); }
382
383 public:
384 REntryMapping() = default;
386 {
389 fInnerMapping = other.fInnerMapping ? std::make_unique<REntryMapping>(*other.fInnerMapping) : nullptr;
390 fPrimaryMapping = other.fPrimaryMapping ? std::make_unique<REntryMapping>(*other.fPrimaryMapping) : nullptr;
392 other.fAuxiliaryMapping ? std::make_unique<REntryMapping>(*other.fAuxiliaryMapping) : nullptr;
393 }
394 REntryMapping(REntryMapping &&other) = default;
396 {
399 fInnerMapping = other.fInnerMapping ? std::make_unique<REntryMapping>(*other.fInnerMapping) : nullptr;
400 fPrimaryMapping = other.fPrimaryMapping ? std::make_unique<REntryMapping>(*other.fPrimaryMapping) : nullptr;
402 other.fAuxiliaryMapping ? std::make_unique<REntryMapping>(*other.fAuxiliaryMapping) : nullptr;
403 return *this;
404 }
406 ~REntryMapping() = default;
407
409
411 };
412
414
415 std::shared_ptr<ROOT::Internal::RNTupleProcessorEntry> fEntry = nullptr;
416 std::unordered_set<Internal::RNTupleProcessorEntry::FieldIndex_t> fFieldIdxs;
417
418 /// Total number of entries. Only to be used internally by the processor, not meant to be exposed in the public
419 /// interface.
421
422 ROOT::NTupleSize_t fNEntriesProcessed = 0; //< Total number of entries processed so far
423
424 /////////////////////////////////////////////////////////////////////////////
425 /// \brief Initialize the processor by creating an (initially empty) `fEntry`, or setting an existing one.
426 virtual void Initialize(std::shared_ptr<ROOT::Internal::RNTupleProcessorEntry> entry) = 0;
427
428 /////////////////////////////////////////////////////////////////////////////
429 /// \brief Check if the processor already has been initialized.
430 bool IsInitialized() const { return fEntry != nullptr; }
431
432 /////////////////////////////////////////////////////////////////////////////
433 /// \brief Connect fields to the page source of the processor's underlying RNTuple(s).
434 ///
435 /// \param[in] fieldIdxs Indices of the fields to connect.
436 /// \param[in] provenance Provenance of the processor.
437 /// \param[in] updateFields Whether the fields in the entry need to be updated, because the current underlying
438 /// RNTuple source changed.
439 virtual void Connect(const std::unordered_set<Internal::RNTupleProcessorEntry::FieldIndex_t> &fieldIdxs,
440 const Internal::RNTupleProcessorProvenance &provenance, bool updateFields) = 0;
441
442 /////////////////////////////////////////////////////////////////////////////
443 /// \brief Disconnect the processor from associated physical storage.
444 virtual void Disconnect() = 0;
445
446 /////////////////////////////////////////////////////////////////////////////
447 /// \brief Set the local entry mapping (for nested processors), according to a global entry number.
448 ///
449 /// \param[in] entryNumber Global entry number to map to
450 /// \param[in] mapping Entry mapping to update
451 virtual void SetEntryMapping(ROOT::NTupleSize_t globalEntryNumber, REntryMapping &mapping) = 0;
452
453 /////////////////////////////////////////////////////////////////////////////
454 /// \brief Increment the local entry mapping by one.
455 ///
456 /// \param[in] mapping Entry mapping to increment
457 void IncrementEntryMapping(REntryMapping &mapping) { SetEntryMapping(mapping.GetEntryNumber() + 1, mapping); }
458
459 /////////////////////////////////////////////////////////////////////////////
460 /// \brief Load the entry identified by the entry mapping.
461 ///
462 /// \param[in] mapping Mapping to the entry to load
463 virtual void LoadEntryImpl(const REntryMapping &mapping) = 0;
464
465 /////////////////////////////////////////////////////////////////////////////
466 /// \brief Get a reference to the processor's internal entry.
468
469 /////////////////////////////////////////////////////////////////////////////
470 /// \brief Get a reference to the processor's internal entry.
472
473 /////////////////////////////////////////////////////////////////////////////
474 /// \brief Get the total number of entries in this processor
476
477 /////////////////////////////////////////////////////////////////////////////
478 /// \brief Check if a field exists on-disk and can be read by the processor.
479 ///
480 /// \param[in] fieldName Name of the field to check.
481 virtual bool CanReadFieldFromDisk(std::string_view fieldName) = 0;
482
483 /////////////////////////////////////////////////////////////////////////////
484 /// \brief Add a field to the entry.
485 ///
486 ///
487 /// \param[in] canonicalFieldName Canonical name of the field to add. This includes the prefix of any parent fields,
488 /// as well as the auxiliary processor name prefix, if present.
489 /// \param[in] typeName Type of the field to add.
490 /// \param[in] valuePtr Pointer to bind to the field's value in the entry. If this is a `nullptr`, a pointer will be
491 /// created.
492 /// \param[in] provenance Provenance of the processor.
493 ///
494 /// \return The index of the newly added field in the entry.
495 ///
496 /// In case the field was already present in the entry, the index of the existing field is returned.
498 AddFieldToEntry(const std::string &canonicalFieldName, const std::string &typeName, void *valuePtr,
499 const Internal::RNTupleProcessorProvenance &provenance) = 0;
500
501 /////////////////////////////////////////////////////////////////////////////
502 /// \brief Add a field to the entry.
503 ///
504 ///
505 /// \param[in] field The field to add.
506 /// \param[in] canonicalFieldName Canonical name of the field to add. This includes the prefix of any parent fields,
507 /// as well as the auxiliary processor name prefix, if present. This is different from the field name stored in
508 /// `field`.
509 /// \param[in] valuePtr Pointer to bind to the field's value in the entry. If this is a `nullptr`, a pointer will be
510 /// created.
511 /// \param[in] provenance Provenance of the processor.
512 ///
513 /// \return The index of the newly added field in the entry.
514 ///
515 /// In case the field was already present in the entry, the index of the existing field is returned.
517 AddFieldToEntry(std::unique_ptr<ROOT::RFieldBase> field, const std::string &canonicalFieldName, void *valuePtr,
518 const Internal::RNTupleProcessorProvenance &provenance) = 0;
519
520 /////////////////////////////////////////////////////////////////////////////
521 /// \brief Add all known fields (from on-disk information) to the entry.
522 ///
523 /// \param[in] provenance Provenance of the processor.
524 /// \param[in] addFieldMode Bitfield indicating how the fields should be added.
525 virtual void AddAllFieldsToEntry(const Internal::RNTupleProcessorProvenance &provenance, bool includeSubfields) = 0;
526
527 /////////////////////////////////////////////////////////////////////////////
528 /// \brief Add the entry mappings for this processor to the provided join table.
529 ///
530 /// \param[in] joinTable the join table to map the entries to.
531 /// \param[in] entryOffset In case the entry mapping is added from a chain, the offset of the entry indexes to use
532 /// with respect to the processor's position in the chain.
533 virtual void
535
536 /////////////////////////////////////////////////////////////////////////////
537 /// \brief Processor-specific implementation for printing its structure, called by PrintStructure().
538 ///
539 /// \param[in,out] output Output stream to print to.
540 virtual void PrintStructureImpl(std::ostream &output) const = 0;
541
542 /////////////////////////////////////////////////////////////////////////////
543 /// \brief Create a new base RNTupleProcessor.
544 ///
545 /// \param[in] processorName Name of the processor. By default, this is the name of the underlying RNTuple for
546 /// RNTupleSingleProcessor, the name of the first processor for RNTupleChainProcessor, or the name of the primary
547 /// RNTuple for RNTupleJoinProcessor.
549
550public:
555 virtual ~RNTupleProcessor() = default;
556
557 /////////////////////////////////////////////////////////////////////////////
558 /// \brief Get the options used for this processor.
559 const RNTupleProcessorOptions &GetOptions() const { return fOptions; }
560
561 /////////////////////////////////////////////////////////////////////////////
562 /// \brief Get the total number of entries processed so far.
564
565 /////////////////////////////////////////////////////////////////////////////
566 /// \brief Request access to a field for reading during processing.
567 ///
568 /// \tparam T Type of the requested field.
569 ///
570 /// \param[in] fieldName Name of the requested field.
571 /// \param[in] valuePtr Pointer to bind to the field's value in the entry. If this is a `nullptr`, a pointer will be
572 /// created.
573 ///
574 /// \return An RNTupleProcessorValuePtr of type `T`, which provides access to the field's value.
575 ///
576 /// \warning Provide a `valuePtr` with care! Values may not always be valid for every entry during processing, for
577 /// example when a field is not present in one of the chained processors or when during a join operation, no matching
578 /// entry in the auxiliary processor can be found. Reading `valuePtr` as-is therefore comes with the risk of reading
579 /// invalid data. After passing a pointer to `RequestField`, we *strongly* recommend only accessing its data through
580 /// the interface of the returned `RNTupleProcessorValuePtr`, to ensure that only valid data can be read.
581 template <typename T>
582 RNTupleProcessorValuePtr<T> RequestField(const std::string &fieldName, void *valuePtr = nullptr)
583 {
585 std::string typeName{};
586 if constexpr (!std::is_void_v<T>) {
587 typeName = ROOT::Internal::GetRenormalizedTypeName(typeid(T));
588 }
589
590 // The field already exists, so return the existing one.
591 if (auto fieldIdx = fEntry->FindFieldIndex(fieldName, typeName)) {
592 auto value = fEntry->GetValue(*fieldIdx);
593 // Need to check that the provided pointer is not conflicting with the existing one
594
595 if (valuePtr != nullptr && valuePtr != value.GetPtr<void>().get()) {
596 throw RException(R__FAIL("attempted to request a field with user-provided value pointer to field \"" +
597 fieldName +
598 "\", which already exists in the entry. To change the underlying value pointer, "
599 "use RNTupleProcessorValuePtr::Bind instead."));
600 }
601 return RNTupleProcessorValuePtr<T>(fEntry.get(), *fieldIdx);
602 }
603
604 auto fieldIdx = AddFieldToEntry(fieldName, typeName, valuePtr, Internal::RNTupleProcessorProvenance());
605 return RNTupleProcessorValuePtr<T>(fEntry.get(), fieldIdx);
606 }
607
608 /////////////////////////////////////////////////////////////////////////////
609 /// \brief Request access to a field for reading during processing.
610 ///
611 /// \param[in] fieldName Name of the requested field.
612 /// \param[in] typeName Type of the requested field.
613 /// \param[in] valuePtr Pointer to bind to the field's value in the entry. If this is a `nullptr`, a pointer will be
614 /// created.
615 ///
616 /// \return An void-type RNTupleProcessorValuePtr, which provides access to the field's value.
617 ///
618 /// \warning Provide a `valuePtr` with care! Values may not always be valid for every entry during processing, for
619 /// example when a field is not present in one of the chained processors or when during a join operation, no matching
620 /// entry in the auxiliary processor can be found. Reading `valuePtr` as-is therefore comes with the risk of reading
621 /// invalid data. After passing a pointer to `RequestField`, we *strongly* recommend only accessing its data through
622 /// the interface of the returned `RNTupleProcessorValuePtr`, to ensure that only valid data can be read.
624 RequestField(const std::string &fieldName, const std::string &typeName, void *valuePtr = nullptr)
625 {
627 auto fieldIdx = AddFieldToEntry(fieldName, typeName, valuePtr, Internal::RNTupleProcessorProvenance());
628 return RNTupleProcessorValuePtr<void>(fEntry.get(), fieldIdx);
629 }
630
631 /////////////////////////////////////////////////////////////////////////////
632 /// \brief Load the entry identified by the entry mapping.
633 ///
634 /// \param[in] mapping Mapping to the entry to load
635 void LoadEntry(const REntryMapping &mapping) { LoadEntryImpl(mapping); }
636
637 /////////////////////////////////////////////////////////////////////////////
638 /// \brief Print a graphical representation of the processor composition.
639 ///
640 /// \param[in,out] output Stream to print to (default is stdout).
641 ///
642 /// ### Example:
643 /// The structure of a processor representing a join between a single primary RNTuple and a chain of two auxiliary
644 /// RNTuples will be printed as follows:
645 /// ~~~
646 /// +-----------------------------+ +-----------------------------+
647 /// | ntuple | | ntuple_aux |
648 /// | ntuple.root | | ntuple_aux1.root |
649 /// +-----------------------------+ +-----------------------------+
650 /// +-----------------------------+
651 /// | ntuple_aux |
652 /// | ntuple_aux2.root |
653 /// +-----------------------------+
654 /// ~~~
655 void PrintStructure(std::ostream &output = std::cout) { PrintStructureImpl(output); }
656
657 // clang-format off
658 /**
659 \class ROOT::RNTupleProcessor::RIterator
660 \ingroup NTuple
661 \brief Iterator over the entries of an RNTuple, or vertical concatenation thereof.
662 */
663 // clang-format on
664 class RIterator {
665 private:
668
669 public:
670 using iterator_category = std::forward_iterator_tag;
674
675 RIterator(RNTupleProcessor &processor, ROOT::NTupleSize_t firstEntryIdx) : fProcessor(processor)
676 {
677 if (fProcessor.fEntry && firstEntryIdx != ROOT::kInvalidNTupleIndex) {
679 /*updateFields=*/false);
681 }
682 }
683
685 {
687
688 return *this;
689 }
690
692 {
693 auto obj = *this;
694 ++(*this);
695 return obj;
696 }
697
699
700 const value_type *operator->() const { return &fEntryMapping; }
701
702 friend bool operator!=(const iterator &lh, const iterator &rh)
703 {
705 }
706 friend bool operator==(const iterator &lh, const iterator &rh)
707 {
709 }
710 };
711
712 RIterator begin() { return RIterator(*this, 0); }
714
715 /////////////////////////////////////////////////////////////////////////////
716 /// \brief Create an RNTupleProcessor for a single RNTuple.
717 ///
718 /// \param[in] ntuple The name and storage location of the RNTuple to process.
719 /// \param[in] opts Options for the processor.
720 ///
721 /// \return A pointer to the newly created RNTupleProcessor.
722 static std::unique_ptr<RNTupleProcessor>
724
725 /////////////////////////////////////////////////////////////////////////////
726 /// \brief Create an RNTupleProcessor for a *chain* (i.e., a vertical combination) of RNTuples.
727 ///
728 /// \param[in] ntuples A list specifying the names and locations of the RNTuples to process.
729 /// \param[in] opts Options for the processor.
730 ///
731 /// \return A pointer to the newly created RNTupleProcessor.
732 static std::unique_ptr<RNTupleProcessor>
733 CreateChain(std::vector<RNTupleInputSpec> ntuples, const RNTupleProcessorOptions &opts = RNTupleProcessorOptions());
734
735 /////////////////////////////////////////////////////////////////////////////
736 /// \brief Create an RNTupleProcessor for a *chain* (i.e., a vertical combination) of other RNTupleProcessors.
737 ///
738 /// \param[in] innerProcessors A list with the processors to chain.
739 /// \param[in] opts Options for the processor.
740 ///
741 /// \return A pointer to the newly created RNTupleProcessor.
742 static std::unique_ptr<RNTupleProcessor>
743 CreateChain(std::vector<std::unique_ptr<RNTupleProcessor>> innerProcessors,
745};
746
747// clang-format off
748/**
749\class ROOT::RNTupleSingleProcessor
750\ingroup NTuple
751\brief Processor specialization for processing a single RNTuple.
752*/
753// clang-format on
755 friend class RNTupleProcessor;
756
757private:
759 std::unique_ptr<ROOT::Internal::RPageSource> fPageSource;
760
761 /////////////////////////////////////////////////////////////////////////////
762 /// \brief Create a new field and connect it to the processor's page source.
763 ///
764 /// \param[in] qualifiedFieldName Name of the field to add, prefixed with its parent fields, if applicable.
765 /// \param[in] typeName Type of the field to add.
766 ///
767 /// \return The newly created field.
768 /// \throws ROOT::RException In case the requested field cannot be found on disk.
769 std::unique_ptr<ROOT::RFieldBase>
770 CreateAndConnectField(const std::string &qualifiedFieldName, const std::string &typeName);
771
772 /////////////////////////////////////////////////////////////////////////////
773 /// \brief Connect an existing field to the processor's page source.
774 ///
775 /// \param[in] field Pointer to the field to add
776 ///
777 /// \return The same field, but wrapped in a new unique pointer. This is needed, because in order to add the field to
778 /// the page source it first needs to be attached to its zero field, in order to correctly handle field
779 /// substitutions. Afterwards, we release the field again from the zero field.
780 std::unique_ptr<ROOT::RFieldBase> ConnectField(std::unique_ptr<ROOT::RFieldBase> field);
781
782 /////////////////////////////////////////////////////////////////////////////
783 /// \brief Initialize the processor by creating an (initially empty) `fEntry`, or setting an existing one.
784 ///
785 /// At this point, the page source for the underlying RNTuple of the processor will be created and opened.
786 void Initialize(std::shared_ptr<ROOT::Internal::RNTupleProcessorEntry> entry = nullptr) final;
787
788 /////////////////////////////////////////////////////////////////////////////
789 /// \brief Connect the provided fields indices in the entry to their on-disk fields.
790 void Connect(const std::unordered_set<Internal::RNTupleProcessorEntry::FieldIndex_t> &fieldIdxs,
791 const Internal::RNTupleProcessorProvenance &provenance = Internal::RNTupleProcessorProvenance(),
792 bool updateFields = false) final;
793
794 /////////////////////////////////////////////////////////////////////////////
795 /// \brief Disconnect the processor from associated physical storage.
796 void Disconnect() final;
797
798 /////////////////////////////////////////////////////////////////////////////
799 /// \brief Set the local entry mapping (for nested processors), according to a global entry number.
800 ///
801 /// \sa ROOT::RNTupleProcessor::SetEntryMapping
802 void SetEntryMapping(ROOT::NTupleSize_t globalEntryNumber, REntryMapping &mapping) final;
803
804 /////////////////////////////////////////////////////////////////////////////
805 /// \brief Load the entry identified by the entry mapping.
806 ///
807 /// \sa ROOT::RNTupleProcessor::LoadEntryImpl
808 void LoadEntryImpl(const REntryMapping &mapping) final;
809
810 /////////////////////////////////////////////////////////////////////////////
811 /// \brief Get the total number of entries in this processor.
813
814 /////////////////////////////////////////////////////////////////////////////
815 /// \brief Check if a field exists on-disk and can be read by the processor.
816 ///
817 /// \sa RNTupleProcessor::CanReadFieldFromDisk()
818 bool CanReadFieldFromDisk(std::string_view fieldName) final;
819
820 /////////////////////////////////////////////////////////////////////////////
821 /// \brief Add a field to the entry.
822 ///
823 /// \sa RNTupleProcessor::AddFieldToEntry()
824 Internal::RNTupleProcessorEntry::FieldIndex_t AddFieldToEntry(
825 const std::string &fieldName, const std::string &typeName, void *valuePtr = nullptr,
826 const Internal::RNTupleProcessorProvenance &provenance = Internal::RNTupleProcessorProvenance()) final;
827
828 /////////////////////////////////////////////////////////////////////////////
829 /// \brief Add a field to the entry.
830 ///
831 /// \sa RNTupleProcessor::AddFieldToEntry()
832 Internal::RNTupleProcessorEntry::FieldIndex_t
833 AddFieldToEntry(std::unique_ptr<ROOT::RFieldBase> field, const std::string &fieldName, void *valuePtr,
834 const Internal::RNTupleProcessorProvenance &provenance) final;
835
836 /////////////////////////////////////////////////////////////////////////////
837 /// \brief Add all known fields (from on-disk information) to the entry.
838 ///
839 /// \sa RNTupleProcessor::AddAllFieldsToEntry()
840 void AddAllFieldsToEntry(const Internal::RNTupleProcessorProvenance &provenance, bool includeSubfields) final;
841
842 /////////////////////////////////////////////////////////////////////////////
843 /// \brief Add the entry mappings for this processor to the provided join table.
844 ///
845 /// \sa ROOT::RNTupleProcessor::AddEntriesToJoinTable
846 void
847 AddEntriesToJoinTable(Experimental::Internal::RNTupleJoinTable &joinTable, ROOT::NTupleSize_t entryOffset = 0) final;
848
849 /////////////////////////////////////////////////////////////////////////////
850 /// \brief Processor-specific implementation for printing its structure, called by PrintStructure().
851 ///
852 /// \sa ROOT::RNTupleProcessor::PrintStructureImpl
853 void PrintStructureImpl(std::ostream &output) const final;
854
855 /////////////////////////////////////////////////////////////////////////////
856 /// \brief Construct a new RNTupleProcessor for processing a single RNTuple.
857 ///
858 /// \param[in] ntuple The source specification (name and storage location) for the RNTuple to process.
859 /// \param[in] opts Options for the processor.
861
862public:
865 RNTupleSingleProcessor &operator=(const RNTupleSingleProcessor &) = delete;
868 {
869 // The entry's fields need to be deleted before fPageSource.
870 if (fEntry)
871 fEntry->Clear();
872 };
873};
874
875// clang-format off
876/**
877\class ROOT::RNTupleChainProcessor
878\ingroup NTuple
879\brief Processor specialization for vertically combined (*chained*) RNTupleProcessors.
880*/
881// clang-format on
883 friend class RNTupleProcessor;
884
885private:
886 std::vector<std::unique_ptr<RNTupleProcessor>> fInnerProcessors;
887 std::vector<ROOT::NTupleSize_t> fInnerNEntries;
888
889 ROOT::NTupleSize_t fLastLoadedEntry = 0; //< Last (global) entry number that was loaded
890 std::size_t fCurrentProcessorNumber = 0; //< Number of the currently open inner processor
891
893
894 /////////////////////////////////////////////////////////////////////////////
895 /// \brief Initialize the processor by creating an (initially empty) `fEntry`, or setting an existing one.
896 void Initialize(std::shared_ptr<ROOT::Internal::RNTupleProcessorEntry> entry = nullptr) final;
897
898 /////////////////////////////////////////////////////////////////////////////
899 /// \brief Connect the provided fields indices in the entry to their on-disk fields.
900 ///
901 /// \sa RNTupleProcessor::Connect()
902 void Connect(const std::unordered_set<Internal::RNTupleProcessorEntry::FieldIndex_t> &fieldIdxs,
903 const Internal::RNTupleProcessorProvenance &provenance = Internal::RNTupleProcessorProvenance(),
904 bool updateFields = false) final;
905
906 /////////////////////////////////////////////////////////////////////////////
907 /// \brief Update the entry to reflect any missing fields in the current inner processor.
908 void ConnectInnerProcessor(std::size_t processorNumber);
909
910 /////////////////////////////////////////////////////////////////////////////
911 /// \brief Disconnect the processor from associated physical storage.
912 void Disconnect() final;
913
914 /////////////////////////////////////////////////////////////////////////////
915 /// \brief Set the local entry mapping (for nested processors), according to a global entry number.
916 ///
917 /// \sa ROOT::RNTupleProcessor::SetEntryMapping
918 void SetEntryMapping(ROOT::NTupleSize_t globalEntryNumber, REntryMapping &mapping) final;
919
920 /////////////////////////////////////////////////////////////////////////////
921 /// \brief Load the entry identified by the entry mapping.
922 ///
923 /// \sa ROOT::RNTupleProcessor::LoadEntryImpl
924 void LoadEntryImpl(const REntryMapping &mapping) final;
925
926 /////////////////////////////////////////////////////////////////////////////
927 /// \brief Get the total number of entries in this processor.
928 ///
929 /// \note This requires opening all underlying RNTuples being processed in the chain, and could become costly!
931
932 /////////////////////////////////////////////////////////////////////////////
933 /// \brief Check if a field exists on-disk and can be read by the processor.
934 ///
935 /// \sa RNTupleProcessor::CanReadFieldFromDisk()
936 bool CanReadFieldFromDisk(std::string_view fieldName) final
937 {
938 return fInnerProcessors[fCurrentProcessorNumber]->CanReadFieldFromDisk(fieldName);
939 }
940
941 /////////////////////////////////////////////////////////////////////////////
942 /// \brief Add a field to the entry.
943 ///
944 /// \sa RNTupleProcessor::AddFieldToEntry()
946 const std::string &fieldName, const std::string &typeName, void *valuePtr = nullptr,
948
949 /////////////////////////////////////////////////////////////////////////////
950 /// \brief Add a field to the entry.
951 ///
952 /// \sa RNTupleProcessor::AddFieldToEntry()
953 Internal::RNTupleProcessorEntry::FieldIndex_t
954 AddFieldToEntry(std::unique_ptr<ROOT::RFieldBase> field, const std::string &fieldName, void *valuePtr,
955 const Internal::RNTupleProcessorProvenance &provenance) final;
956
957 /////////////////////////////////////////////////////////////////////////////
958 /// \brief Add all known fields (from on-disk information) to the entry.
959 ///
960 /// \sa RNTupleProcessor::AddAllFieldsToEntry()
961 void AddAllFieldsToEntry(const Internal::RNTupleProcessorProvenance &provenance, bool includeSubfields) final;
962
963 /////////////////////////////////////////////////////////////////////////////
964 /// \brief Add the entry mappings for this processor to the provided join table.
965 ///
966 /// \sa ROOT::RNTupleProcessor::AddEntriesToJoinTable
967 void
968 AddEntriesToJoinTable(Experimental::Internal::RNTupleJoinTable &joinTable, ROOT::NTupleSize_t entryOffset = 0) final;
969
970 /////////////////////////////////////////////////////////////////////////////
971 /// \brief Processor-specific implementation for printing its structure, called by PrintStructure().
972 ///
973 /// \sa ROOT::RNTupleProcessor::PrintStructureImpl
974 void PrintStructureImpl(std::ostream &output) const final;
975
976 /////////////////////////////////////////////////////////////////////////////
977 /// \brief Construct a new RNTupleChainProcessor.
978 ///
979 /// \param[in] ntuples The source specification (name and storage location) for each RNTuple to process.
980 /// \param[in] opts Options for the processor.
981 ///
982 /// RNTuples are processed in the order in which they are specified.
983 RNTupleChainProcessor(std::vector<std::unique_ptr<RNTupleProcessor>> processors,
984 const RNTupleProcessorOptions &opts);
985
986public:
989 RNTupleChainProcessor &operator=(const RNTupleChainProcessor &) = delete;
991 ~RNTupleChainProcessor() override = default;
992};
993
994namespace Experimental {
995/////////////////////////////////////////////////////////////////////////////
996/// \brief Create an RNTupleProcessor for a *join* (i.e., a horizontal combination) of RNTuples.
997///
998/// \param[in] primaryNTuple The name and location of the primary RNTuple. Its entries are processed in sequential
999/// order.
1000/// \param[in] auxNTuple The name and location of the RNTuple to join the primary RNTuple with. The order in which
1001/// its entries are processed is determined by the primary RNTuple and doesn't necessarily have to be sequential.
1002/// \param[in] joinFields The names of the fields on which to join, in case the specified RNTuples are unaligned.
1003/// The join is made based on the combined join field values, and therefore each field has to be present in each
1004/// specified RNTuple. If an empty list is provided, it is assumed that the specified ntuple are fully aligned.
1005/// \param[in] opts Options for the processor.
1006///
1007/// \return A pointer to the newly created RNTupleProcessor.
1008// TODO(fdegeus) Move back to RNTupleProcessor::CreateJoin once RNTupleProcessor moves out of Experimental.
1009std::unique_ptr<RNTupleProcessor>
1010CreateRNTupleJoinProcessor(RNTupleInputSpec primaryNTuple, RNTupleInputSpec auxNTuple,
1011 const std::vector<std::string> &joinFields,
1013
1014/////////////////////////////////////////////////////////////////////////////
1015/// \brief Create an RNTupleProcessor for a *join* (i.e., a horizontal combination) of RNTuples.
1016///
1017/// \param[in] primaryProcessor The primary processor. Its entries are processed in sequential order.
1018/// \param[in] auxProcessor The processor to join the primary processor with. The order in which its entries are
1019/// processed is determined by the primary processor and doesn't necessarily have to be sequential.
1020/// \param[in] joinFields The names of the fields on which to join, in case the specified processors are unaligned.
1021/// The join is made based on the combined join field values, and therefore each field has to be present in each
1022/// specified processors. If an empty list is provided, it is assumed that the specified processors are fully
1023/// aligned.
1024/// \param[in] opts Options for the processor.
1025///
1026/// \return A pointer to the newly created RNTupleProcessor.
1027// TODO(fdegeus) Move back to RNTupleProcessor::CreateJoin once RNTupleProcessor moves out of Experimental.
1028std::unique_ptr<RNTupleProcessor>
1029CreateRNTupleJoinProcessor(std::unique_ptr<RNTupleProcessor> primaryProcessor,
1030 std::unique_ptr<RNTupleProcessor> auxProcessor, const std::vector<std::string> &joinFields,
1032
1033// clang-format off
1034/**
1035\class ROOT::Experimental::RNTupleJoinProcessor
1036\ingroup NTuple
1037\brief Processor specialization for horizontally combined (*joined*) RNTupleProcessors.
1038*/
1039// clang-format on
1041 friend class RNTupleProcessor;
1042 friend std::unique_ptr<RNTupleProcessor>
1043 CreateRNTupleJoinProcessor(std::unique_ptr<RNTupleProcessor> primaryProcessor,
1044 std::unique_ptr<RNTupleProcessor> auxProcessor,
1045 const std::vector<std::string> &joinFields, const RNTupleProcessorOptions &opts);
1046
1047private:
1048 std::unique_ptr<RNTupleProcessor> fPrimaryProcessor;
1049 std::unique_ptr<RNTupleProcessor> fAuxiliaryProcessor;
1050
1051 std::vector<std::string> fJoinFieldNames;
1052 std::set<ROOT::Internal::RNTupleProcessorEntry::FieldIndex_t> fJoinFieldIdxs;
1053
1054 std::unique_ptr<Internal::RNTupleJoinTable> fJoinTable;
1055 bool fJoinTableIsBuilt = false;
1056
1057 std::unordered_set<ROOT::Internal::RNTupleProcessorEntry::FieldIndex_t> fAuxiliaryFieldIdxs;
1058
1059 /// \brief Initialize the processor by creating an (initially empty) `fEntry`, or setting an existing one.
1060 void Initialize(std::shared_ptr<ROOT::Internal::RNTupleProcessorEntry> entry = nullptr) final;
1061
1062 /////////////////////////////////////////////////////////////////////////////
1063 /// \brief Connect the provided fields indices in the entry to their on-disk fields.
1064 ///
1065 /// \sa RNTupleProcessor::Connect()
1066 void
1067 Connect(const std::unordered_set<ROOT::Internal::RNTupleProcessorEntry::FieldIndex_t> &fieldIdxs,
1068 const ROOT::Internal::RNTupleProcessorProvenance &provenance = ROOT::Internal::RNTupleProcessorProvenance(),
1069 bool updateFields = false) final;
1070
1071 /////////////////////////////////////////////////////////////////////////////
1072 /// \brief Disconnect the processor from associated physical storage.
1073 void Disconnect() final;
1074
1075 /////////////////////////////////////////////////////////////////////////////
1076 /// \brief Set the local entry mapping (for nested processors), according to a global entry number.
1077 ///
1078 /// \sa ROOT::RNTupleProcessor::SetEntryMapping
1079 void SetEntryMapping(ROOT::NTupleSize_t globalEntryNumber, REntryMapping &mapping) final;
1080
1081 /////////////////////////////////////////////////////////////////////////////
1082 /// \brief Load the entry identified by the entry mapping.
1083 ///
1084 /// \sa ROOT::RNTupleProcessor::LoadEntryImpl
1085 void LoadEntryImpl(const REntryMapping &mapping) final;
1086
1087 /////////////////////////////////////////////////////////////////////////////
1088 /// \brief Get the total number of entries in this processor.
1089 ROOT::NTupleSize_t GetNEntries() final;
1090
1091 /////////////////////////////////////////////////////////////////////////////
1092 /// \brief Set the validity for all fields in the auxiliary processor at once.
1093 void SetAuxiliaryFieldValidity(bool validity);
1094
1095 /////////////////////////////////////////////////////////////////////////////
1096 /// \brief Check if a field exists on-disk and can be read by the processor.
1097 ///
1098 /// \sa RNTupleProcessor::CanReadFieldFromDisk()
1099 bool CanReadFieldFromDisk(std::string_view fieldName) final
1100 {
1101 if (!fPrimaryProcessor->CanReadFieldFromDisk(fieldName)) {
1102 if (fieldName.find(fAuxiliaryProcessor->fOptions.GetProcessorName()) == 0)
1103 fieldName = fieldName.substr(fAuxiliaryProcessor->fOptions.GetProcessorName().size() + 1);
1104 return fAuxiliaryProcessor->CanReadFieldFromDisk(fieldName);
1105 }
1106
1107 return true;
1108 }
1109
1110 /////////////////////////////////////////////////////////////////////////////
1111 /// \brief Add a field to the entry.
1112 ///
1113 /// \sa RNTupleProcessor::AddFieldToEntry()
1115 AddFieldToEntry(const std::string &fieldName, const std::string &typeName, void *valuePtr = nullptr,
1118
1119 /////////////////////////////////////////////////////////////////////////////
1120 /// \brief Add a field to the entry.
1121 ///
1122 /// \sa RNTupleProcessor::AddFieldToEntry()
1123 ROOT::Internal::RNTupleProcessorEntry::FieldIndex_t
1124 AddFieldToEntry(std::unique_ptr<ROOT::RFieldBase> field, const std::string &fieldName, void *valuePtr,
1125 const ROOT::Internal::RNTupleProcessorProvenance &provenance) final;
1126
1127 /////////////////////////////////////////////////////////////////////////////
1128 /// \brief Add all known fields (from on-disk information) to the entry.
1129 ///
1130 /// \sa RNTupleProcessor::AddAllFieldsToEntry()
1131 void AddAllFieldsToEntry(const ROOT::Internal::RNTupleProcessorProvenance &provenance, bool includeSubfields) final;
1132
1133 /////////////////////////////////////////////////////////////////////////////
1134 /// \brief Add the entry mappings for this processor to the provided join table.
1135 ///
1136 /// \sa ROOT::RNTupleProcessor::AddEntriesToJoinTable
1137 void AddEntriesToJoinTable(Internal::RNTupleJoinTable &joinTable, ROOT::NTupleSize_t entryOffset = 0) final;
1138
1139 /////////////////////////////////////////////////////////////////////////////
1140 /// \brief Processor-specific implementation for printing its structure, called by PrintStructure().
1141 ///
1142 /// \sa ROOT::RNTupleProcessor::PrintStructureImpl
1143 void PrintStructureImpl(std::ostream &output) const final;
1144
1145 /////////////////////////////////////////////////////////////////////////////
1146 /// \brief Construct a new RNTupleJoinProcessor.
1147 /// \param[in] primaryProcessor The primary processor. Its entries are processed in sequential order.
1148 /// \param[in] auxProcessor The processor to join the primary processor with. The order in which its entries are
1149 /// processed is determined by the primary processor and doesn't necessarily have to be sequential.
1150 /// \param[in] joinFields The names of the fields on which to join, in case the specified processors are unaligned.
1151 /// The join is made based on the combined join field values, and therefore each field has to be present in each
1152 /// specified processor. If an empty list is provided, it is assumed that the processors are fully aligned.
1153 /// \param[in] opts Options for the processor.
1154 RNTupleJoinProcessor(std::unique_ptr<RNTupleProcessor> primaryProcessor,
1155 std::unique_ptr<RNTupleProcessor> auxProcessor, const std::vector<std::string> &joinFields,
1156 const RNTupleProcessorOptions &opts);
1157
1158public:
1160 RNTupleJoinProcessor operator=(const RNTupleJoinProcessor &) = delete;
1163 ~RNTupleJoinProcessor() override = default;
1164};
1165} // namespace Experimental
1166} // namespace ROOT
1167
1168#endif // ROOT_RNTupleProcessor
#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:322
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
char name[80]
Definition TGX11.cxx:142
Builds a join table on one or several fields of an RNTuple so it can be joined onto other RNTuples.
The RDataSource implementation for the RNTupleProcessor.
Processor specialization for horizontally combined (joined) RNTupleProcessors.
std::unordered_set< ROOT::Internal::RNTupleProcessorEntry::FieldIndex_t > fAuxiliaryFieldIdxs
std::set< ROOT::Internal::RNTupleProcessorEntry::FieldIndex_t > fJoinFieldIdxs
std::unique_ptr< RNTupleProcessor > fPrimaryProcessor
std::unique_ptr< Internal::RNTupleJoinTable > fJoinTable
friend std::unique_ptr< RNTupleProcessor > CreateRNTupleJoinProcessor(std::unique_ptr< RNTupleProcessor > primaryProcessor, std::unique_ptr< RNTupleProcessor > auxProcessor, const std::vector< std::string > &joinFields, const RNTupleProcessorOptions &opts)
Create an RNTupleProcessor for a join (i.e., a horizontal combination) of RNTuples.
std::unique_ptr< RNTupleProcessor > fAuxiliaryProcessor
Collection of values in an RNTupleProcessor, analogous to REntry, with checks and support for missing...
ROOT::RFieldBase::RValue CreateValue(FieldIndex_t fieldIdx)
Create an RValue connected to the field identified by fieldIdx.
const ROOT::RFieldBase::RValue & GetValue(FieldIndex_t fieldIdx) const
bool IsValidField(FieldIndex_t fieldIdx) const
Check whether a field is valid for reading.
const std::string & FindFieldName(FieldIndex_t fieldIdx) const
Find the name of a field from its field index.
void BindRawPtr(FieldIndex_t fieldIdx, void *valuePtr)
Bind a new value pointer to a field in the entry.
void Bind(FieldIndex_t fieldIdx, std::shared_ptr< void > valuePtr)
Bind a new value pointer to a field in the entry.
Base class for all ROOT issued exceptions.
Definition RError.hxx:78
Points to an object with RNTuple I/O support and keeps a pointer to the corresponding field.
A field translates read and write calls from/to underlying columns to/from tree values.
Processor specialization for vertically combined (chained) RNTupleProcessors.
std::vector< std::unique_ptr< RNTupleProcessor > > fInnerProcessors
void AddAllFieldsToEntry(const Internal::RNTupleProcessorProvenance &provenance, bool includeSubfields) final
Add all known fields (from on-disk information) to the entry.
void ConnectInnerProcessor(std::size_t processorNumber)
Update the entry to reflect any missing fields in the current inner processor.
bool CanReadFieldFromDisk(std::string_view fieldName) final
Check if a field exists on-disk and can be read by the processor.
void Initialize(std::shared_ptr< ROOT::Internal::RNTupleProcessorEntry > entry=nullptr) final
Initialize the processor by creating an (initially empty) fEntry, or setting an existing one.
std::vector< ROOT::NTupleSize_t > fInnerNEntries
void Connect(const std::unordered_set< Internal::RNTupleProcessorEntry::FieldIndex_t > &fieldIdxs, const Internal::RNTupleProcessorProvenance &provenance=Internal::RNTupleProcessorProvenance(), bool updateFields=false) final
Connect the provided fields indices in the entry to their on-disk fields.
Internal::RNTupleProcessorEntry::FieldIndex_t AddFieldToEntry(const std::string &fieldName, const std::string &typeName, void *valuePtr=nullptr, const Internal::RNTupleProcessorProvenance &provenance=Internal::RNTupleProcessorProvenance()) final
Add a field to the entry.
void LoadEntryImpl(const REntryMapping &mapping) final
Load the entry identified by the entry mapping.
void SetEntryMapping(ROOT::NTupleSize_t globalEntryNumber, REntryMapping &mapping) final
Set the local entry mapping (for nested processors), according to a global entry number.
void AddEntriesToJoinTable(Experimental::Internal::RNTupleJoinTable &joinTable, ROOT::NTupleSize_t entryOffset=0) final
Add the entry mappings for this processor to the provided join table.
ROOT::NTupleSize_t fLastLoadedEntry
void PrintStructureImpl(std::ostream &output) const final
Processor-specific implementation for printing its structure, called by PrintStructure().
void Disconnect() final
Disconnect the processor from associated physical storage.
Internal::RNTupleProcessorProvenance fProvenance
ROOT::NTupleSize_t GetNEntries() final
Get the total number of entries in this processor.
std::string fProcessorName
By default, the processor name is the name of the underlying RNTuple for RNTupleSingleProcessor,...
const std::string & GetProcessorName() const
Get the processor's name.
void SetProcessorName(std::string_view name)
Set the processor's name.
std::shared_ptr< void > GetPtr() const
Get the pointer to the field value managed by the processor's entry.
void Bind(std::shared_ptr< void > valuePtr)
Bind the value to valuePtr.
ROOT::RFieldBase::RValue CreateValue()
Create an RValue connected to the field managed by the processor's entry.
ROOT::Internal::RNTupleProcessorEntry::FieldIndex_t fFieldIndex
bool HasValue() const
Check if the pointer currently holds a valid value.
void * GetRawPtr() const
Get a non-owning pointer to the field value managed by the processor's entry.
RNTupleProcessorValuePtr(ROOT::Internal::RNTupleProcessorEntry *processorEntry, ROOT::Internal::RNTupleProcessorEntry::FieldIndex_t fieldIdx)
friend bool operator==(const RNTupleProcessorValuePtr< void > &lhs, const RNTupleProcessorValuePtr< void > &rhs)
void BindRawPtr(void *valuePtr)
Bind the value to valuePtr.
ROOT::Internal::RNTupleProcessorEntry * fProcessorEntry
void BindRawPtr(T *valuePtr)
Bind the value to valuePtr.
const T * operator->() const
Access the field value managed by the processor's entry.
RNTupleProcessorValuePtr(ROOT::Internal::RNTupleProcessorEntry *processorEntry, ROOT::Internal::RNTupleProcessorEntry::FieldIndex_t fieldIdx)
ROOT::Internal::RNTupleProcessorEntry::FieldIndex_t fFieldIndex
const T & operator*() const
Get a reference to the field value managed by the processor's entry.
ROOT::Internal::RNTupleProcessorEntry * fProcessorEntry
bool HasValue() const
Check if the pointer currently holds a valid value.
void Bind(std::shared_ptr< T > valuePtr)
Bind the value to valuePtr.
friend bool operator==(const RNTupleProcessorValuePtr< T > &lhs, const RNTupleProcessorValuePtr< T > &rhs)
T * GetRawPtr() const
Get a non-owning pointer to the field value managed by the processor's entry.
std::shared_ptr< T > GetPtr() const
Get a shared pointer to the field value managed by the processor's entry.
Maps a processor's global (outer) entry index to its inner ones.
friend bool operator==(const REntryMapping &lhs, const REntryMapping &rhs)
REntryMapping & operator=(const REntryMapping &other)
REntryMapping(REntryMapping &&other)=default
REntryMapping(const REntryMapping &other)
std::unique_ptr< REntryMapping > fPrimaryMapping
const REntryMapping & GetAuxiliaryProcessorMapping() const
const REntryMapping & GetInnerProcessorMapping() const
void SetEntryNumber(ROOT::NTupleSize_t entryNumber)
ROOT::NTupleSize_t GetEntryNumber() const
std::unique_ptr< REntryMapping > fAuxiliaryMapping
friend bool operator!=(const REntryMapping &lhs, const REntryMapping &rhs)
REntryMapping & operator=(REntryMapping &&other)=default
const REntryMapping & GetPrimaryProcessorMapping() const
std::unique_ptr< REntryMapping > fInnerMapping
Iterator over the entries of an RNTuple, or vertical concatenation thereof.
RIterator(RNTupleProcessor &processor, ROOT::NTupleSize_t firstEntryIdx)
const value_type * operator->() const
friend bool operator==(const iterator &lh, const iterator &rh)
friend bool operator!=(const iterator &lh, const iterator &rh)
std::forward_iterator_tag iterator_category
RNTupleProcessor::REntryMapping fEntryMapping
Interface for iterating over entries of vertically ("chained") and/or horizontally ("joined") combine...
friend struct ROOT::Internal::RNTupleProcessorEntryLoader
ROOT::NTupleSize_t fNEntries
Total number of entries.
virtual void Disconnect()=0
Disconnect the processor from associated physical storage.
virtual Internal::RNTupleProcessorEntry::FieldIndex_t AddFieldToEntry(const std::string &canonicalFieldName, const std::string &typeName, void *valuePtr, const Internal::RNTupleProcessorProvenance &provenance)=0
Add a field to the entry.
RNTupleProcessorValuePtr< void > RequestField(const std::string &fieldName, const std::string &typeName, void *valuePtr=nullptr)
Request access to a field for reading during processing.
virtual void Connect(const std::unordered_set< Internal::RNTupleProcessorEntry::FieldIndex_t > &fieldIdxs, const Internal::RNTupleProcessorProvenance &provenance, bool updateFields)=0
Connect fields to the page source of the processor's underlying RNTuple(s).
std::unordered_set< Internal::RNTupleProcessorEntry::FieldIndex_t > fFieldIdxs
virtual void AddAllFieldsToEntry(const Internal::RNTupleProcessorProvenance &provenance, bool includeSubfields)=0
Add all known fields (from on-disk information) to the entry.
static std::unique_ptr< RNTupleProcessor > CreateChain(std::vector< RNTupleInputSpec > ntuples, const RNTupleProcessorOptions &opts=RNTupleProcessorOptions())
Create an RNTupleProcessor for a chain (i.e., a vertical combination) of RNTuples.
virtual void PrintStructureImpl(std::ostream &output) const =0
Processor-specific implementation for printing its structure, called by PrintStructure().
virtual ROOT::NTupleSize_t GetNEntries()=0
Get the total number of entries in this processor.
virtual void Initialize(std::shared_ptr< ROOT::Internal::RNTupleProcessorEntry > entry)=0
Initialize the processor by creating an (initially empty) fEntry, or setting an existing one.
const ROOT::Internal::RNTupleProcessorEntry & GetEntry() const
Get a reference to the processor's internal entry.
RNTupleProcessor & operator=(RNTupleProcessor &&)=delete
RNTupleProcessor(const RNTupleProcessor &)=delete
RNTupleProcessor(RNTupleProcessor &&)=delete
void LoadEntry(const REntryMapping &mapping)
Load the entry identified by the entry mapping.
RNTupleProcessor(const RNTupleProcessorOptions &options)
Create a new base RNTupleProcessor.
ROOT::NTupleSize_t GetNEntriesProcessed() const
Get the total number of entries processed so far.
void PrintStructure(std::ostream &output=std::cout)
Print a graphical representation of the processor composition.
ROOT::Internal::RNTupleProcessorEntry & GetEntry()
Get a reference to the processor's internal entry.
ROOT::NTupleSize_t fNEntriesProcessed
virtual void SetEntryMapping(ROOT::NTupleSize_t globalEntryNumber, REntryMapping &mapping)=0
Set the local entry mapping (for nested processors), according to a global entry number.
RNTupleProcessorValuePtr< T > RequestField(const std::string &fieldName, void *valuePtr=nullptr)
Request access to a field for reading during processing.
static std::unique_ptr< RNTupleProcessor > Create(RNTupleInputSpec ntuple, const RNTupleProcessorOptions &opts=RNTupleProcessorOptions())
Create an RNTupleProcessor for a single RNTuple.
virtual void LoadEntryImpl(const REntryMapping &mapping)=0
Load the entry identified by the entry mapping.
void IncrementEntryMapping(REntryMapping &mapping)
Increment the local entry mapping by one.
virtual ~RNTupleProcessor()=default
virtual Internal::RNTupleProcessorEntry::FieldIndex_t AddFieldToEntry(std::unique_ptr< ROOT::RFieldBase > field, const std::string &canonicalFieldName, void *valuePtr, const Internal::RNTupleProcessorProvenance &provenance)=0
Add a field to the entry.
const RNTupleProcessorOptions & GetOptions() const
Get the options used for this processor.
RNTupleProcessorOptions fOptions
virtual void AddEntriesToJoinTable(Experimental::Internal::RNTupleJoinTable &joinTable, ROOT::NTupleSize_t entryOffset=0)=0
Add the entry mappings for this processor to the provided join table.
bool IsInitialized() const
Check if the processor already has been initialized.
std::shared_ptr< ROOT::Internal::RNTupleProcessorEntry > fEntry
virtual bool CanReadFieldFromDisk(std::string_view fieldName)=0
Check if a field exists on-disk and can be read by the processor.
RNTupleProcessor & operator=(const RNTupleProcessor &)=delete
Processor specialization for processing a single RNTuple.
void SetEntryMapping(ROOT::NTupleSize_t globalEntryNumber, REntryMapping &mapping) final
Set the local entry mapping (for nested processors), according to a global entry number.
void PrintStructureImpl(std::ostream &output) const final
Processor-specific implementation for printing its structure, called by PrintStructure().
std::unique_ptr< ROOT::Internal::RPageSource > fPageSource
void LoadEntryImpl(const REntryMapping &mapping) final
Load the entry identified by the entry mapping.
std::unique_ptr< ROOT::RFieldBase > ConnectField(std::unique_ptr< ROOT::RFieldBase > field)
Connect an existing field to the processor's page source.
bool CanReadFieldFromDisk(std::string_view fieldName) final
Check if a field exists on-disk and can be read by the processor.
void Initialize(std::shared_ptr< ROOT::Internal::RNTupleProcessorEntry > entry=nullptr) final
Initialize the processor by creating an (initially empty) fEntry, or setting an existing one.
Internal::RNTupleProcessorEntry::FieldIndex_t AddFieldToEntry(const std::string &fieldName, const std::string &typeName, void *valuePtr=nullptr, const Internal::RNTupleProcessorProvenance &provenance=Internal::RNTupleProcessorProvenance()) final
Add a field to the entry.
void AddAllFieldsToEntry(const Internal::RNTupleProcessorProvenance &provenance, bool includeSubfields) final
Add all known fields (from on-disk information) to the entry.
void AddEntriesToJoinTable(Experimental::Internal::RNTupleJoinTable &joinTable, ROOT::NTupleSize_t entryOffset=0) final
Add the entry mappings for this processor to the provided join table.
std::unique_ptr< ROOT::RFieldBase > CreateAndConnectField(const std::string &qualifiedFieldName, const std::string &typeName)
Create a new field and connect it to the processor's page source.
ROOT::NTupleSize_t GetNEntries() final
Get the total number of entries in this processor.
void Connect(const std::unordered_set< Internal::RNTupleProcessorEntry::FieldIndex_t > &fieldIdxs, const Internal::RNTupleProcessorProvenance &provenance=Internal::RNTupleProcessorProvenance(), bool updateFields=false) final
Connect the provided fields indices in the entry to their on-disk fields.
void Disconnect() final
Disconnect the processor from associated physical storage.
ROOT::RFieldBase::RValue CreateRValueFromValuePtr(RNTupleProcessorValuePtr< void > &valuePtr)
const RNTupleProcessorEntry * LoadFullRNTupleProcessorEntry(ROOT::RNTupleProcessor &processor, bool includeSubfields)
std::string GetRenormalizedTypeName(const std::string &metaNormalizedName)
Given a type name normalized by ROOT meta, renormalize it for RNTuple. E.g., insert std::prefix.
constexpr NTupleSize_t kInvalidNTupleIndex
std::uint64_t NTupleSize_t
Integer type long enough to hold the maximum number of entries in a column.