15#ifndef ROOT_RNTupleProcessor
16#define ROOT_RNTupleProcessor
33namespace Experimental {
34class RNTupleProcessor;
37struct RNTupleProcessorEntryLoader;
38const RNTupleProcessorEntry *
42class RNTupleProcessorColumnReader;
66 std::variant<std::string, TDirectory *>
fStorage;
140 return value.template GetPtr<T>();
168 "\" because it has no value for the current entry"));
181 "\" because it has no value for the current entry"));
242 return value.template GetPtr<void>();
280std::unique_ptr<RNTupleProcessor>
282 const std::vector<std::string> &joinFields,
283 const RNTupleProcessorOptions &opts = RNTupleProcessorOptions());
299std::unique_ptr<RNTupleProcessor>
301 std::unique_ptr<RNTupleProcessor> auxProcessor,
const std::vector<std::string> &joinFields,
302 const RNTupleProcessorOptions &opts = RNTupleProcessorOptions());
345 bool includeSubfields);
435 std::shared_ptr<Internal::RNTupleProcessorEntry>
fEntry =
nullptr;
436 std::unordered_set<Internal::RNTupleProcessorEntry::FieldIndex_t>
fFieldIdxs;
446 virtual void Initialize(std::shared_ptr<Internal::RNTupleProcessorEntry> entry) = 0;
459 virtual void Connect(
const std::unordered_set<Internal::RNTupleProcessorEntry::FieldIndex_t> &fieldIdxs,
518 AddFieldToEntry(
const std::string &canonicalFieldName,
const std::string &typeName,
void *valuePtr,
537 AddFieldToEntry(std::unique_ptr<ROOT::RFieldBase> field,
const std::string &canonicalFieldName,
void *valuePtr,
600 template <
typename T>
604 std::string typeName{};
605 if constexpr (!std::is_void_v<T>) {
610 if (
auto fieldIdx =
fEntry->FindFieldIndex(fieldName, typeName)) {
614 if (valuePtr !=
nullptr && valuePtr !=
value.GetPtr<
void>().get()) {
615 throw RException(
R__FAIL(
"attempted to request a field with user-provided value pointer to field \"" +
617 "\", which already exists in the entry. To change the underlying value pointer, "
618 "use RNTupleProcessorOptionalPtr::Bind instead."));
643 RequestField(
const std::string &fieldName,
const std::string &typeName,
void *valuePtr =
nullptr)
741 static std::unique_ptr<RNTupleProcessor>
751 static std::unique_ptr<RNTupleProcessor>
761 static std::unique_ptr<RNTupleProcessor>
762 CreateChain(std::vector<std::unique_ptr<RNTupleProcessor>> innerProcessors,
788 std::unique_ptr<ROOT::RFieldBase>
799 std::unique_ptr<ROOT::RFieldBase>
ConnectField(std::unique_ptr<ROOT::RFieldBase> field);
805 void Initialize(std::shared_ptr<Internal::RNTupleProcessorEntry> entry =
nullptr) final;
809 void Connect(const std::unordered_set<Internal::RNTupleProcessorEntry::FieldIndex_t> &fieldIdxs,
811 bool updateFields = false) final;
849 const std::string &fieldName,
const std::string &typeName,
void *valuePtr =
nullptr,
856 Internal::RNTupleProcessorEntry::FieldIndex_t
919 void Initialize(std::shared_ptr<Internal::RNTupleProcessorEntry> entry =
nullptr) final;
925 void Connect(const std::unordered_set<Internal::RNTupleProcessorEntry::FieldIndex_t> &fieldIdxs,
927 bool updateFields = false) final;
969 const std::string &fieldName,
const std::string &typeName,
void *valuePtr =
nullptr,
976 Internal::RNTupleProcessorEntry::FieldIndex_t
1025 friend std::unique_ptr<RNTupleProcessor>
1027 std::unique_ptr<RNTupleProcessor> auxProcessor,
1038 bool fJoinTableIsBuilt =
false;
1043 void Initialize(std::shared_ptr<Internal::RNTupleProcessorEntry> entry =
nullptr) final;
1049 void Connect(const std::unordered_set<Internal::RNTupleProcessorEntry::FieldIndex_t> &fieldIdxs,
1051 bool updateFields = false) final;
1075 void SetAuxiliaryFieldValidity(
bool validity);
1083 if (!fPrimaryProcessor->CanReadFieldFromDisk(fieldName)) {
1084 if (fieldName.find(fAuxiliaryProcessor->fOptions.GetProcessorName()) == 0)
1085 fieldName = fieldName.substr(fAuxiliaryProcessor->fOptions.GetProcessorName().size() + 1);
1086 return fAuxiliaryProcessor->CanReadFieldFromDisk(fieldName);
1097 const std::string &fieldName,
const std::string &typeName,
void *valuePtr =
nullptr,
1104 Internal::RNTupleProcessorEntry::FieldIndex_t
1136 std::unique_ptr<
RNTupleProcessor> auxProcessor, const std::vector<std::
string> &joinFields,
#define R__FAIL(msg)
Short-hand to return an RResult<T> in an error state; the RError is implicitly converted into RResult...
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Builds a join table on one or several fields of an RNTuple so it can be joined onto other RNTuples.
Collection of values in an RNTupleProcessor, analogous to REntry, with checks and support for missing...
std::uint64_t FieldIndex_t
void Bind(FieldIndex_t fieldIdx, std::shared_ptr< void > valuePtr)
Bind a new value pointer to a field in the entry.
void BindRawPtr(FieldIndex_t fieldIdx, void *valuePtr)
Bind a new value pointer to a field in the entry.
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.
The RDataSource implementation for the RNTupleProcessor.
Processor specialization for vertically combined (chained) RNTupleProcessors.
bool CanReadFieldFromDisk(std::string_view fieldName) final
Check if a field exists on-disk and can be read by the processor.
std::size_t fCurrentProcessorNumber
void PrintStructureImpl(std::ostream &output) const final
Processor-specific implementation for printing its structure, called by PrintStructure().
void AddEntriesToJoinTable(Internal::RNTupleJoinTable &joinTable, ROOT::NTupleSize_t entryOffset=0) final
Add the entry mappings for this processor to the provided join table.
void ConnectInnerProcessor(std::size_t processorNumber)
Update the entry to reflect any missing fields in the current inner processor.
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.
Internal::RNTupleProcessorProvenance fProvenance
void AddAllFieldsToEntry(const Internal::RNTupleProcessorProvenance &provenance, bool includeSubfields) final
Add all known fields (from on-disk information) to the entry.
ROOT::NTupleSize_t GetNEntries() final
Get the total number of entries in this processor.
void Initialize(std::shared_ptr< 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 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 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::NTupleSize_t fLastLoadedEntry
std::vector< std::unique_ptr< RNTupleProcessor > > fInnerProcessors
Processor specialization for horizontally combined (joined) RNTupleProcessors.
std::set< Internal::RNTupleProcessorEntry::FieldIndex_t > fJoinFieldIdxs
std::unordered_set< Internal::RNTupleProcessorEntry::FieldIndex_t > fAuxiliaryFieldIdxs
std::vector< std::string > fJoinFieldNames
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
Specification of the name and location of an RNTuple, used for creating a new RNTupleProcessor.
RNTupleOpenSpec(std::string_view n, const std::string &s)
std::variant< std::string, TDirectory * > fStorage
RNTupleOpenSpec(std::string_view n, TDirectory *s)
std::unique_ptr< ROOT::Internal::RPageSource > CreatePageSource() const
RNTupleProcessorOptionalPtr(Internal::RNTupleProcessorEntry *processorEntry, Internal::RNTupleProcessorEntry::FieldIndex_t fieldIdx)
Internal::RNTupleProcessorEntry * fProcessorEntry
void BindRawPtr(void *valuePtr)
Bind the value to valuePtr.
void * GetRawPtr() const
Get a non-owning pointer to the field value managed by the processor's entry.
Internal::RNTupleProcessorEntry::FieldIndex_t fFieldIndex
friend bool operator==(const RNTupleProcessorOptionalPtr< void > &lhs, const RNTupleProcessorOptionalPtr< void > &rhs)
std::shared_ptr< void > GetPtr() const
Get the pointer to the field value managed by the processor's entry.
bool HasValue() const
Check if the pointer currently holds a valid value.
void Bind(std::shared_ptr< void > valuePtr)
Bind the value to valuePtr.
std::shared_ptr< T > GetPtr() const
Get a shared pointer to the field value managed by the processor's entry.
void Bind(std::shared_ptr< T > valuePtr)
Bind the value to valuePtr.
const T & operator*() const
Get a reference to the field value managed by the processor's entry.
Internal::RNTupleProcessorEntry::FieldIndex_t fFieldIndex
friend bool operator==(const RNTupleProcessorOptionalPtr< T > &lhs, const RNTupleProcessorOptionalPtr< T > &rhs)
const T * operator->() const
Access the field value managed by the processor's entry.
void BindRawPtr(T *valuePtr)
Bind the value to valuePtr.
bool HasValue() const
Check if the pointer currently holds a valid value.
T * GetRawPtr() const
Get a non-owning pointer to the field value managed by the processor's entry.
Internal::RNTupleProcessorEntry * fProcessorEntry
RNTupleProcessorOptionalPtr(Internal::RNTupleProcessorEntry *processorEntry, Internal::RNTupleProcessorEntry::FieldIndex_t fieldIdx)
const std::string & GetProcessorName() const
std::string fProcessorName
By default, the processor name is the name of the underlying RNTuple for RNTupleSingleProcessor,...
void SetProcessorName(std::string_view name)
Identifies how a processor is composed.
Maps a processor's global (outer) entry index to its inner ones.
const REntryMapping & GetAuxiliaryProcessorMapping() const
friend bool operator==(const REntryMapping &lhs, const REntryMapping &rhs)
std::size_t GetInnerProcessorIdx() const
void SetInnerProcessorIdx(std::size_t idx)
REntryMapping & GetAuxiliaryProcessorMapping()
std::size_t fInnerProcessorIdx
std::unique_ptr< REntryMapping > fAuxiliaryMapping
ROOT::NTupleSize_t operator*() const
std::unique_ptr< REntryMapping > fInnerMapping
ROOT::NTupleSize_t GetEntryNumber() const
void SetEntryNumber(ROOT::NTupleSize_t entryNumber)
REntryMapping & GetInnerProcessorMapping()
std::unique_ptr< REntryMapping > fPrimaryMapping
friend bool operator!=(const REntryMapping &lhs, const REntryMapping &rhs)
const REntryMapping & GetPrimaryProcessorMapping() const
REntryMapping & GetPrimaryProcessorMapping()
const REntryMapping & GetInnerProcessorMapping() const
ROOT::NTupleSize_t fEntryNumber
Iterator over the entries of an RNTuple, or vertical concatenation thereof.
RNTupleProcessor & fProcessor
std::forward_iterator_tag iterator_category
const value_type * operator->() const
RIterator(RNTupleProcessor &processor, ROOT::NTupleSize_t firstEntryIdx)
const iterator & operator++(int)
RNTupleProcessor::REntryMapping fEntryMapping
friend bool operator==(const iterator &lh, const iterator &rh)
friend bool operator!=(const iterator &lh, const iterator &rh)
Interface for iterating over entries of vertically ("chained") and/or horizontally ("joined") combine...
Internal::RNTupleProcessorEntry & GetEntry()
Get a reference to the processor's internal entry.
virtual bool CanReadFieldFromDisk(std::string_view fieldName)=0
Check if a field exists on-disk and can be read by the processor.
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.
static std::unique_ptr< RNTupleProcessor > CreateChain(std::vector< RNTupleOpenSpec > ntuples, const RNTupleProcessorOptions &opts=RNTupleProcessorOptions())
Create an RNTupleProcessor for a chain (i.e., a vertical combination) of RNTuples.
RNTupleProcessorOptions fOptions
RNTupleProcessorOptionalPtr< T > RequestField(const std::string &fieldName, void *valuePtr=nullptr)
Request access to a field for reading during processing.
virtual ROOT::NTupleSize_t GetNEntries()=0
Get the total number of entries in this processor.
ROOT::NTupleSize_t fNEntries
Total number of entries.
RNTupleProcessorOptionalPtr< void > RequestField(const std::string &fieldName, const std::string &typeName, void *valuePtr=nullptr)
Request access to a field for reading during processing.
friend struct ROOT::Experimental::Internal::RNTupleProcessorEntryLoader
virtual ~RNTupleProcessor()=default
virtual void AddAllFieldsToEntry(const Internal::RNTupleProcessorProvenance &provenance, bool includeSubfields)=0
Add all known fields (from on-disk information) to the entry.
const RNTupleProcessorOptions & GetOptions() const
Get the options used for this processor.
RNTupleProcessor(RNTupleProcessor &&)=delete
std::shared_ptr< Internal::RNTupleProcessorEntry > fEntry
virtual void PrintStructureImpl(std::ostream &output) const =0
Processor-specific implementation for printing its structure, called by PrintStructure().
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).
ROOT::NTupleSize_t fNEntriesProcessed
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.
virtual void Disconnect()=0
Disconnect the processor from associated physical storage.
std::unordered_set< Internal::RNTupleProcessorEntry::FieldIndex_t > fFieldIdxs
virtual void Initialize(std::shared_ptr< Internal::RNTupleProcessorEntry > entry)=0
Initialize the processor by creating an (initially empty) fEntry, or setting an existing one.
bool IsInitialized() const
Check if the processor already has been initialized.
virtual void AddEntriesToJoinTable(Internal::RNTupleJoinTable &joinTable, ROOT::NTupleSize_t entryOffset=0)=0
Add the entry mappings for this processor to the provided join table.
const Internal::RNTupleProcessorEntry & GetEntry() const
Get a reference to the processor's internal entry.
void IncrementEntryMapping(REntryMapping &mapping)
Increment the local entry mapping by one.
void PrintStructure(std::ostream &output=std::cout)
Print a graphical representation of the processor composition.
void LoadEntry(const REntryMapping &mapping)
Load the entry identified by the entry mapping.
ROOT::NTupleSize_t GetNEntriesProcessed() const
Get the total number of entries processed so far.
RNTupleProcessor(const RNTupleProcessorOptions &options)
Create a new base RNTupleProcessor.
RNTupleProcessor(const RNTupleProcessor &)=delete
RNTupleProcessor & operator=(RNTupleProcessor &&)=delete
virtual void SetEntryMapping(ROOT::NTupleSize_t globalEntryNumber, REntryMapping &mapping)=0
Set the local entry mapping (for nested processors), according to a global entry number.
virtual void LoadEntryImpl(const REntryMapping &mapping)=0
Load the entry identified by the entry mapping.
static std::unique_ptr< RNTupleProcessor > Create(RNTupleOpenSpec ntuple, const RNTupleProcessorOptions &opts=RNTupleProcessorOptions())
Create an RNTupleProcessor for a single RNTuple.
RNTupleProcessor & operator=(const RNTupleProcessor &)=delete
Processor specialization for processing a single RNTuple.
void AddEntriesToJoinTable(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 > ConnectField(std::unique_ptr< ROOT::RFieldBase > field)
Connect an existing field to the processor's page source.
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 Initialize(std::shared_ptr< Internal::RNTupleProcessorEntry > entry=nullptr) final
Initialize the processor by creating an (initially empty) fEntry, or setting an existing one.
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.
RNTupleOpenSpec fNTupleSpec
std::unique_ptr< ROOT::Internal::RPageSource > fPageSource
void LoadEntryImpl(const REntryMapping &mapping) final
Load the entry identified by the entry mapping.
bool CanReadFieldFromDisk(std::string_view fieldName) final
Check if a field exists on-disk and can be read by the processor.
void SetEntryMapping(ROOT::NTupleSize_t globalEntryNumber, REntryMapping &mapping) final
Set the local entry mapping (for nested processors), according to a global entry number.
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.
ROOT::NTupleSize_t GetNEntries() final
Get the total number of entries in this processor.
void AddAllFieldsToEntry(const Internal::RNTupleProcessorProvenance &provenance, bool includeSubfields) final
Add all known fields (from on-disk information) to the entry.
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.
Base class for all ROOT issued exceptions.
A field translates read and write calls from/to underlying columns to/from tree values.
Describe directory structure in memory.
const RNTupleProcessorEntry * LoadFullRNTupleProcessorEntry(ROOT::Experimental::RNTupleProcessor &processor, bool includeSubfields)
std::unique_ptr< RNTupleProcessor > CreateRNTupleJoinProcessor(RNTupleOpenSpec primaryNTuple, RNTupleOpenSpec auxNTuple, const std::vector< std::string > &joinFields, const RNTupleProcessorOptions &opts=RNTupleProcessorOptions())
Create an RNTupleProcessor for a join (i.e., a horizontal combination) of RNTuples.
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.