Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RRawPtrWriteEntry.hxx
Go to the documentation of this file.
1/// \file ROOT/RRawPtrWriteEntry.hxx
2/// \ingroup NTuple
3/// \author Jonas Hahnfeld <jonas.hahnfeld@cern.ch>
4/// \date 2025-03-19
5/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
6/// is welcome!
7
8/*************************************************************************
9 * Copyright (C) 1995-2025, Rene Brun and Fons Rademakers. *
10 * All rights reserved. *
11 * *
12 * For the licensing terms see $ROOTSYS/LICENSE. *
13 * For the list of contributors see $ROOTSYS/README/CREDITS. *
14 *************************************************************************/
15
16#ifndef ROOT_RRawPtrWriteEntry
17#define ROOT_RRawPtrWriteEntry
18
19#include <ROOT/RFieldBase.hxx>
20#include <ROOT/RFieldToken.hxx>
21#include <ROOT/RError.hxx>
22
23#include <cstdint>
24#include <unordered_map>
25#include <vector>
26
27namespace ROOT {
28
29class RNTupleModel;
30
31namespace Experimental {
32
33class RNTupleFillContext;
34
35namespace Detail {
36
37// clang-format off
38/**
39\class ROOT::Experimental::Detail::RRawPtrWriteEntry
40\ingroup NTuple
41\brief A container of const raw pointers, corresponding to a row in the data set
42
43This class can be used to write constant data products in frameworks. All other users are encouraged to use the API
44provided by REntry, with safe interfaces, type checks, and shared object ownership.
45*/
46// clang-format on
48 friend class ROOT::RNTupleModel;
50
51private:
52 /// The entry must be linked to a specific model, identified by a model ID
53 std::uint64_t fModelId = 0;
54 /// The entry and its tokens are also linked to a specific schema, identified by a schema ID
55 std::uint64_t fSchemaId = 0;
56 /// Corresponds to the fields of the linked model
57 std::vector<ROOT::RFieldBase *> fFields;
58 /// The raw pointers corresponding to the fields
59 std::vector<const void *> fRawPtrs;
60 /// For fast lookup of token IDs given a (sub)field name present in the entry
61 std::unordered_map<std::string, std::size_t> fFieldName2Token;
62
63 explicit RRawPtrWriteEntry(std::uint64_t modelId, std::uint64_t schemaId) : fModelId(modelId), fSchemaId(schemaId) {}
64
66 {
67 fFieldName2Token[field.GetQualifiedFieldName()] = fFields.size();
68 fFields.emplace_back(&field);
69 fRawPtrs.emplace_back(nullptr);
70 }
71
72 std::size_t Append()
73 {
74 std::size_t bytesWritten = 0;
75 for (std::size_t i = 0; i < fFields.size(); i++) {
76 bytesWritten += fFields[i]->Append(fRawPtrs[i]);
77 }
78 return bytesWritten;
79 }
80
82 {
83 if (fSchemaId != token.fSchemaId) {
84 throw RException(R__FAIL("invalid token for this entry, "
85 "make sure to use a token from a model with the same schema as this entry."));
86 }
87 }
88
89public:
94 ~RRawPtrWriteEntry() = default;
95
96 /// The ordinal of the (sub)field fieldName; can be used in other methods to address the corresponding value
97 RFieldToken GetToken(std::string_view fieldName) const
98 {
99 auto it = fFieldName2Token.find(std::string(fieldName));
100 if (it == fFieldName2Token.end()) {
101 throw RException(R__FAIL("invalid field name: " + std::string(fieldName)));
102 }
103 return RFieldToken(it->second, fSchemaId);
104 }
105
106 template <typename T>
108 {
110 fRawPtrs[token.fIndex] = rawPtr;
111 }
112
113 template <typename T>
114 void BindRawPtr(std::string_view fieldName, const T *rawPtr)
115 {
117 }
118
119 std::uint64_t GetModelId() const { return fModelId; }
120 std::uint64_t GetSchemaId() const { return fSchemaId; }
121};
122
123} // namespace Detail
124} // namespace Experimental
125} // namespace ROOT
126
127#endif
#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:299
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
A container of const raw pointers, corresponding to a row in the data set.
RRawPtrWriteEntry & operator=(const RRawPtrWriteEntry &other)=delete
std::unordered_map< std::string, std::size_t > fFieldName2Token
For fast lookup of token IDs given a (sub)field name present in the entry.
void BindRawPtr(std::string_view fieldName, const T *rawPtr)
std::uint64_t fModelId
The entry must be linked to a specific model, identified by a model ID.
RRawPtrWriteEntry(const RRawPtrWriteEntry &other)=delete
RRawPtrWriteEntry(std::uint64_t modelId, std::uint64_t schemaId)
std::vector< ROOT::RFieldBase * > fFields
Corresponds to the fields of the linked model.
std::uint64_t fSchemaId
The entry and its tokens are also linked to a specific schema, identified by a schema ID.
std::vector< const void * > fRawPtrs
The raw pointers corresponding to the fields.
void EnsureMatchingModel(RFieldToken token) const
RRawPtrWriteEntry(RRawPtrWriteEntry &&other)=default
void BindRawPtr(RFieldToken token, const T *rawPtr)
RRawPtrWriteEntry & operator=(RRawPtrWriteEntry &&other)=default
RFieldToken GetToken(std::string_view fieldName) const
The ordinal of the (sub)field fieldName; can be used in other methods to address the corresponding va...
A context for filling entries (data) into clusters of an RNTuple.
Base class for all ROOT issued exceptions.
Definition RError.hxx:79
A field translates read and write calls from/to underlying columns to/from tree values.
A field token identifies a (sub)field in an entry.
The RNTupleModel encapulates the schema of an RNTuple.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...