13#ifndef ROOT_RField_Fundamental
14#define ROOT_RField_Fundamental
17#error "Please include RField.hxx!"
46 static std::string
TypeName() {
return "void"; }
64 std::unique_ptr<RFieldBase>
CloneImpl(std::string_view newName)
const final
66 return std::make_unique<RField>(newName);
69 const RColumnRepresentations &GetColumnRepresentations() const final;
72 static std::
string TypeName() {
return "bool"; }
86 std::unique_ptr<RFieldBase>
CloneImpl(std::string_view newName)
const final
88 return std::make_unique<RField>(newName);
91 const RColumnRepresentations &GetColumnRepresentations() const final;
94 static std::
string TypeName() {
return "char"; }
118 const RColumnRepresentations &GetColumnRepresentations()
const final;
121 static std::string TypeName() {
return "std::int8_t"; }
122 explicit RIntegralField(std::string_view
name) : RSimpleField(
name, TypeName()) {}
127 void AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor)
const final;
135 const RColumnRepresentations &GetColumnRepresentations() const final;
138 static std::
string TypeName() {
return "std::uint8_t"; }
144 void AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor)
const final;
152 const RColumnRepresentations &GetColumnRepresentations() const final;
155 static std::
string TypeName() {
return "std::int16_t"; }
161 void AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor)
const final;
169 const RColumnRepresentations &GetColumnRepresentations() const final;
172 static std::
string TypeName() {
return "std::uint16_t"; }
178 void AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor)
const final;
186 const RColumnRepresentations &GetColumnRepresentations() const final;
189 static std::
string TypeName() {
return "std::int32_t"; }
195 void AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor)
const final;
203 const RColumnRepresentations &GetColumnRepresentations() const final;
206 static std::
string TypeName() {
return "std::uint32_t"; }
212 void AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor)
const final;
220 const RColumnRepresentations &GetColumnRepresentations() const final;
223 static std::
string TypeName() {
return "std::int64_t"; }
229 void AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor)
const final;
237 const RColumnRepresentations &GetColumnRepresentations() const final;
240 static std::
string TypeName() {
return "std::uint64_t"; }
246 void AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor)
const final;
262 static_assert(
sizeof(
signed char) ==
sizeof(std::int8_t));
267 static_assert(
sizeof(
unsigned char) ==
sizeof(std::uint8_t));
272 static_assert(
sizeof(short) ==
sizeof(std::int16_t));
277 static_assert(
sizeof(
unsigned short) ==
sizeof(std::uint16_t));
282 static_assert(
sizeof(
int) ==
sizeof(std::int32_t));
287 static_assert(
sizeof(
unsigned int) ==
sizeof(std::uint32_t));
292 static_assert(
sizeof(long) ==
sizeof(std::int32_t) ||
sizeof(long) ==
sizeof(std::int64_t));
293 using type = std::conditional_t<
sizeof(long) ==
sizeof(std::int32_t), std::int32_t, std::int64_t>;
297 static_assert(
sizeof(
unsigned long) ==
sizeof(std::uint32_t) ||
sizeof(
unsigned long) ==
sizeof(std::uint64_t));
298 using type = std::conditional_t<
sizeof(
unsigned long) ==
sizeof(std::uint32_t), std::uint32_t, std::uint64_t>;
302 static_assert(
sizeof(
long long) ==
sizeof(std::int64_t));
307 static_assert(
sizeof(
unsigned long long) ==
sizeof(std::uint64_t));
313class RField<T, typename std::enable_if<std::is_integral_v<T>>
::type> final
314 :
public RIntegralField<typename Internal::RIntegralTypeMap<T>::type> {
316 static_assert(
sizeof(T) ==
sizeof(MappedType),
"invalid size of mapped type");
317 static_assert(std::is_signed_v<T> == std::is_signed_v<MappedType>,
"invalid signedness of mapped type");
321 std::unique_ptr<RFieldBase>
CloneImpl(std::string_view newName)
const final
323 return std::make_unique<RField>(newName);
327 RField(std::string_view
name) : RIntegralField<MappedType>(
name) {}
332 T *Map(ROOT::
NTupleSize_t globalIndex) {
return reinterpret_cast<T *
>(this->BaseType::Map(globalIndex)); }
333 T *
Map(RNTupleLocalIndex localIndex) {
return reinterpret_cast<T *
>(this->BaseType::Map(localIndex)); }
336 return reinterpret_cast<T *
>(this->BaseType::MapV(globalIndex, nItems));
340 return reinterpret_cast<T *
>(this->BaseType::MapV(localIndex, nItems));
376 const auto n =
r.size();
378 for (std::uint16_t i = 0; i <
n; ++i) {
392 std::uint16_t representationIndex = 0;
395 if (onDiskTypes.empty())
402 const auto &coldesc = desc.GetColumnDescriptor(fdesc.GetLogicalColumnIds()[0]);
403 column->SetBitsOnStorage(coldesc.GetBitsOnStorage());
406 const auto &coldesc = desc.GetColumnDescriptor(fdesc.GetLogicalColumnIds()[0]);
407 assert(coldesc.GetValueRange().has_value());
408 const auto [valMin, valMax] = *coldesc.GetValueRange();
409 column->SetBitsOnStorage(coldesc.GetBitsOnStorage());
410 column->SetValueRange(valMin, valMax);
413 if (representationIndex > 0) {
417 representationIndex++;
444 const auto &[minBits, maxBits] =
446 if (nBits < minBits || nBits > maxBits) {
447 throw RException(
R__FAIL(
"SetTruncated() argument nBits = " + std::to_string(nBits) +
448 " is out of valid range [" + std::to_string(minBits) +
", " +
449 std::to_string(maxBits) +
"])"));
466 const auto &[minBits, maxBits] =
468 if (valueRange.second < valueRange.first) {
469 throw RException(
R__FAIL(
"value range given to SetQuantized() has max < min! (" +
470 std::to_string(valueRange.second) +
" < " + std::to_string(valueRange.first) +
")"));
472 if (nBits < minBits || nBits > maxBits) {
473 throw RException(
R__FAIL(
"SetQuantized() argument nBits = " + std::to_string(nBits) +
474 " is out of valid range [" + std::to_string(minBits) +
", " +
475 std::to_string(maxBits) +
"])"));
490 std::unique_ptr<RFieldBase>
CloneImpl(std::string_view newName)
const final
492 return std::unique_ptr<RField>(
new RField(newName, *
this));
509 std::unique_ptr<RFieldBase>
CloneImpl(std::string_view newName)
const final
511 return std::unique_ptr<RField>(
new RField(newName, *
this));
#define R__FAIL(msg)
Short-hand to return an RResult<T> in an error state; the RError is implicitly converted into RResult...
Binding & operator=(OUT(*fun)(void))
Abstract base class for classes implementing the visitor design pattern.
static std::pair< std::uint16_t, std::uint16_t > GetValidBitRange(ROOT::ENTupleColumnType type)
Most types have a fixed on-disk bit width.
static std::unique_ptr< RColumn > Create(ROOT::ENTupleColumnType type, std::uint32_t columnIdx, std::uint16_t representationIdx)
std::unique_ptr< RFieldBase > CloneImpl(std::string_view newName) const final
Called by Clone(), which additionally copies the on-disk ID.
Base class for all ROOT issued exceptions.
The list of column representations a field can have.
void SetColumnRepresentatives(const RColumnRepresentations::Selection_t &representatives)
Fixes a column representative.
ROOT::Internal::RColumn * fPrincipalColumn
All fields that have columns have a distinct main column.
const ColumnRepresentation_t & EnsureCompatibleColumnTypes(const ROOT::RNTupleDescriptor &desc, std::uint16_t representationIndex) const
Returns the on-disk column types found in the provided descriptor for fOnDiskId and the given represe...
std::vector< std::reference_wrapper< const ColumnRepresentation_t > > fColumnRepresentatives
Pointers into the static vector returned by RColumnRepresentations::GetSerializationTypes() when SetC...
std::vector< std::unique_ptr< ROOT::Internal::RColumn > > fAvailableColumns
The columns are connected either to a sink or to a source (not to both); they are owned by the field.
RFieldBase(std::string_view name, std::string_view type, ROOT::ENTupleStructure structure, bool isSimple, std::size_t nRepetitions=0)
The constructor creates the underlying column objects and connects them to either a sink or a source.
RColumnRepresentations::Selection_t GetColumnRepresentatives() const
Returns the fColumnRepresentative pointee or, if unset (always the case for artificial fields),...
const std::string & GetTypeName() const
ROOT::DescriptorId_t GetOnDiskId() const
void AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor) const final
static std::string TypeName()
std::unique_ptr< RFieldBase > CloneImpl(std::string_view newName) const final
Called by Clone(), which additionally copies the on-disk ID.
RField(std::string_view name)
RField & operator=(RField &&other)=default
RField(RField &&other)=default
std::unique_ptr< RFieldBase > CloneImpl(std::string_view newName) const final
Called by Clone(), which additionally copies the on-disk ID.
RField(RField &&other)=default
RField & operator=(RField &&other)=default
RField(std::string_view name)
static std::string TypeName()
void AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor) const final
RField(std::string_view name, const RField &source)
RField(std::string_view name)
const RColumnRepresentations & GetColumnRepresentations() const final
Implementations in derived classes should return a static RColumnRepresentations object.
static std::string TypeName()
std::unique_ptr< RFieldBase > CloneImpl(std::string_view newName) const final
Called by Clone(), which additionally copies the on-disk ID.
static std::string TypeName()
RField(std::string_view name)
const RColumnRepresentations & GetColumnRepresentations() const final
Implementations in derived classes should return a static RColumnRepresentations object.
RField(std::string_view name, const RField &source)
std::unique_ptr< RFieldBase > CloneImpl(std::string_view newName) const final
Called by Clone(), which additionally copies the on-disk ID.
static std::string TypeName()
RField & operator=(const RField &)=delete
RField(const RField &)=delete
Classes with dictionaries that can be inspected by TClass.
RField & operator=(RField &&other)=default
RField(std::string_view name)
The on-storage metadata of an RNTuple.
~RRealField() override=default
RRealField(std::string_view name, const RRealField &source)
Called by derived fields' CloneImpl().
RRealField(std::string_view name, std::string_view typeName)
void SetHalfPrecision()
Sets this field to use a half precision representation, occupying half as much storage space (16 bits...
void SetQuantized(std::size_t nBits, std::pair< T, T > valueRange)
Sets this field to use a quantized integer representation using nBits per value.
void GenerateColumns() final
Implementations in derived classes should create the backing columns corresponding to the field type ...
void SetTruncated(std::size_t nBits)
Set the on-disk representation of this field to a single-precision float truncated to nBits.
RRealField & operator=(RRealField &&other)=default
void GenerateColumns(const ROOT::RNTupleDescriptor &desc) final
Implementations in derived classes should create the backing columns corresponding to the field type ...
RRealField(RRealField &&other)=default
RSimpleField(std::string_view name, std::string_view type)
auto Map(Args &&... args)
Create new collection applying a callable to the elements of the input collection.
Special implementation of ROOT::RRangeCast for TCollection, including a check that the cast target ty...
Namespace for ROOT features in testing.
std::uint64_t NTupleSize_t
Integer type long enough to hold the maximum number of entries in a column.
std::conditional_t< sizeof(long)==sizeof(std::int32_t), std::int32_t, std::int64_t > type
std::conditional_t< sizeof(unsigned long)==sizeof(std::uint32_t), std::uint32_t, std::uint64_t > type