16#ifndef ROOT7_RNTupleView
17#define ROOT7_RNTupleView
27#include <unordered_map>
30namespace Experimental {
119template <
typename FieldT,
typename SFINAE =
void>
122template <
typename FieldT>
123inline constexpr bool isMappable<FieldT, std::void_t<decltype(std::declval<FieldT>().Map(
NTupleSize_t{}))>> =
true;
143template <
typename T,
bool UserProv
idedAddress>
158 fField.SetOnDiskId(fieldId);
160 if constexpr (!UserProvidedAddress) {
162 throw RException(
R__FAIL(
"view disallowed on field with mappable type and read callback"));
167 :
fField(pageSource->GetSharedDescriptorGuard()->GetFieldDescriptor(fieldId).GetFieldName()),
174 :
fField(pageSource->GetSharedDescriptorGuard()->GetFieldDescriptor(fieldId).GetFieldName()),
181 :
fField(pageSource->GetSharedDescriptorGuard()->GetFieldDescriptor(fieldId).GetFieldName()),
182 fValue(
fField.BindValue(Internal::MakeAliasedSharedPtr(rawPtr)))
199 if constexpr (Internal::isMappable<FieldT> && !UserProvidedAddress) {
200 return *
fField.Map(globalIndex);
209 if constexpr (Internal::isMappable<FieldT> && !UserProvidedAddress) {
210 return *
fField.Map(clusterIndex);
218 template <
typename C = T, std::enable_if_t<Internal::isMappable<FieldT>, C*> =
nullptr>
221 return fField.MapV(globalIndex, nItems);
225 template <
typename C = T, std::enable_if_t<Internal::isMappable<FieldT>, C *> =
nullptr>
228 return fField.MapV(clusterIndex, nItems);
231 void Bind(std::shared_ptr<T> objPtr)
235 "Only views which were created with an external memory location at construction time can be bound to a "
236 "different memory location afterwards. Call the RNTupleReader::GetView overload with a shared_ptr.");
244 "Only views which were created with an external memory location at construction time can be bound to a "
245 "different memory location afterwards. Call the RNTupleReader::GetView overload with a shared_ptr.");
255 static_assert(!(Internal::isMappable<FieldT> && !UserProvidedAddress),
256 "Cannot emplace a new value into a view of a mappable type, unless an external memory location is "
257 "provided at construction time.");
272template <
bool UserProv
idedAddress>
288 fField->SetOnDiskId(fieldId);
293 :
fField(CreateField(fieldId, pageSource->GetSharedDescriptorGuard().GetRef())),
fValue(
fField->CreateValue())
299 :
fField(CreateField(fieldId, pageSource->GetSharedDescriptorGuard().GetRef())),
fValue(
fField->BindValue(objPtr))
305 :
fField(CreateField(fieldId, pageSource->GetSharedDescriptorGuard().GetRef())),
306 fValue(
fField->BindValue(Internal::MakeAliasedSharedPtr(rawPtr)))
325 void Bind(std::shared_ptr<void> objPtr)
329 "Only views which were created with an external memory location at construction time can be bound to a "
330 "different memory location afterwards. Call the RNTupleReader::GetView overload with a shared_ptr.");
338 "Only views which were created with an external memory location at construction time can be bound to a "
339 "different memory location afterwards. Call the RNTupleReader::GetView overload with a shared_ptr.");
388 template <
typename T>
393 throw RException(
R__FAIL(
"no field named '" + std::string(fieldName) +
"' in RNTuple '" +
403 throw RException(
R__FAIL(
"no field named '" + std::string(fieldName) +
"' in RNTuple '" +
#define R__FAIL(msg)
Short-hand to return an RResult<T> in an error state; the RError is implicitly converted into RResult...
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Abstract interface to read data from an ntuple.
const RSharedDescriptorGuard GetSharedDescriptorGuard() const
Takes the read lock for the descriptor.
Addresses a column element or field item relative to a particular cluster, instead of a global NTuple...
DescriptorId_t GetClusterId() const
ClusterSize_t::ValueType GetIndex() const
Base class for all ROOT issued exceptions.
Points to an object with RNTuple I/O support and keeps a pointer to the corresponding field.
void Read(NTupleSize_t globalIndex)
void EmplaceNew()
Replace the current object pointer by a pointer to a new object constructed by the field.
void BindRawPtr(void *rawPtr)
void Bind(std::shared_ptr< void > objPtr)
A field translates read and write calls from/to underlying columns to/from tree values.
static constexpr int kTraitMappable
A field of a fundamental type that can be directly mapped via RField<T>::Map(), i....
std::unique_ptr< RFieldBase > CreateField(const RNTupleDescriptor &ntplDesc) const
In general, we create a field simply from the C++ type name.
void GetCollectionInfo(NTupleSize_t globalIndex, RClusterIndex *collectionStart, ClusterSize_t *size)
Special help for offset fields.
Classes with dictionaries that can be inspected by TClass.
bool operator==(const iterator &rh) const
bool operator!=(const iterator &rh) const
std::forward_iterator_tag iterator_category
RIterator(RClusterIndex index)
Used to loop over entries of collections in a single cluster.
const ClusterSize_t::ValueType fStart
const DescriptorId_t fClusterId
RNTupleClusterRange(DescriptorId_t clusterId, ClusterSize_t::ValueType start, ClusterSize_t::ValueType end)
const ClusterSize_t::ValueType fEnd
A view for a collection, that can itself generate new ntuple views for its nested fields.
RNTupleCollectionView & operator=(RNTupleCollectionView &&other)=default
RNTupleClusterRange GetCollectionRange(RClusterIndex clusterIndex)
ClusterSize_t operator()(RClusterIndex clusterIndex)
RNTupleCollectionView(RNTupleCollectionView &&other)=default
ClusterSize_t operator()(NTupleSize_t globalIndex)
RNTupleCollectionView GetCollectionView(std::string_view fieldName)
Raises an exception if there is no field with the given name.
RNTupleCollectionView & operator=(const RNTupleCollectionView &other)=delete
DescriptorId_t fCollectionFieldId
Internal::RPageSource * fSource
RNTupleView< T, false > GetView(std::string_view fieldName)
Raises an exception if there is no field with the given name.
~RNTupleCollectionView()=default
RNTupleCollectionView(DescriptorId_t fieldId, Internal::RPageSource *source)
RNTupleClusterRange GetCollectionRange(NTupleSize_t globalIndex)
RNTupleCollectionView(const RNTupleCollectionView &other)=delete
The on-storage meta-data of an ntuple.
std::string GetName() const
DescriptorId_t FindFieldId(std::string_view fieldName, DescriptorId_t parentId) const
const RFieldDescriptor & GetFieldDescriptor(DescriptorId_t fieldId) const
bool operator==(const iterator &rh) const
NTupleSize_t difference_type
RIterator(NTupleSize_t index)
bool operator!=(const iterator &rh) const
std::forward_iterator_tag iterator_category
Used to loop over indexes (entries or collections) between start and end.
const NTupleSize_t fStart
RNTupleGlobalRange(NTupleSize_t start, NTupleSize_t end)
An RNTuple that is used to read data from storage.
RFieldBase::RValue fValue
RNTupleGlobalRange GetFieldRange() const
RNTupleView & operator=(const RNTupleView &other)=delete
std::unique_ptr< RFieldBase > fField
const RFieldBase & GetField() const
RNTupleView(DescriptorId_t fieldId, Internal::RPageSource *pageSource, void *rawPtr)
RNTupleView(RNTupleView &&other)=default
RNTupleView(DescriptorId_t fieldId, Internal::RPageSource *pageSource)
RNTupleView(DescriptorId_t fieldId, Internal::RPageSource *pageSource, std::shared_ptr< void > objPtr)
void Bind(std::shared_ptr< void > objPtr)
void SetupField(DescriptorId_t fieldId, Internal::RPageSource *pageSource)
static std::unique_ptr< RFieldBase > CreateField(DescriptorId_t fieldId, const RNTupleDescriptor &desc)
void BindRawPtr(void *rawPtr)
RNTupleView(const RNTupleView &other)=delete
void operator()(RClusterIndex clusterIndex)
const RFieldBase::RValue & GetValue() const
void operator()(NTupleSize_t globalIndex)
RNTupleView & operator=(RNTupleView &&other)=default
An RNTupleView provides read-only access to a single field of the ntuple.
RNTupleView & operator=(RNTupleView &&other)=default
friend class RNTupleCollectionView
const T & operator()(RClusterIndex clusterIndex)
void SetupField(DescriptorId_t fieldId, Internal::RPageSource *pageSource)
RNTupleView(DescriptorId_t fieldId, Internal::RPageSource *pageSource, std::shared_ptr< T > objPtr)
const C * MapV(NTupleSize_t globalIndex, NTupleSize_t &nItems)
RNTupleView & operator=(const RNTupleView &other)=delete
RFieldBase::RValue fValue
Used as a Read() destination for fields that are not mappable.
FieldT fField
fFieldId has fParent always set to null; views access nested fields without looking at the parent
RNTupleView(const RNTupleView &other)=delete
const C * MapV(RClusterIndex clusterIndex, NTupleSize_t &nItems)
void Bind(std::shared_ptr< T > objPtr)
RNTupleView(DescriptorId_t fieldId, Internal::RPageSource *pageSource, T *rawPtr)
const FieldT & GetField() const
void BindRawPtr(T *rawPtr)
RNTupleGlobalRange GetFieldRange() const
RNTupleView(RNTupleView &&other)=default
const T & operator()(NTupleSize_t globalIndex)
RNTupleView(DescriptorId_t fieldId, Internal::RPageSource *pageSource)
constexpr bool isMappable
void CallConnectPageSourceOnField(RFieldBase &, RPageSource &)
std::uint64_t NTupleSize_t
Integer type long enough to hold the maximum number of entries in a column.
std::uint64_t DescriptorId_t
Distriniguishes elements of the same type within a descriptor, e.g. different fields.
constexpr NTupleSize_t kInvalidNTupleIndex
constexpr DescriptorId_t kInvalidDescriptorId
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Wrap the integer in a struct in order to avoid template specialization clash with std::uint64_t.