Example creating low-precision floating point fields in RNTuple
RNTuple supports storing floating points on disk with less precision than their in-memory representation. Under the right circumstances, this can in save storage space while not significantly altering the results of an analysis.
Storing low-precision floats is done by setting their column representation to one of the dedicated column types:
- Real16 (half-precision IEEE754 fp),
- Real32Trunc (single-precision IEEE754 with truncated mantissa, using from 10 to 31 bits in total) and
- Real32Quant (floating point within a specified range, represented as an integer with N bits of precision in a linear quantized form).
To use these column types in RNTuple, one creates a RField<float> or RField<double> and sets its desired column representation by calling, respectively:
- RField<float>::SetHalfPrecision() (for Real16)
- RField<float>::SetTruncated() (for Real32Trunc)
- RField<float>::SetQuantized() (for Real32Quant)
Other than these, one can also setup the field to use the ROOT Double32_t type, either via RField<double>::SetDouble32() or by directly creating one such field via RFieldBase::Create("f", "Double32_t").
␝¸␁
static constexpr char const *
kNTupleFileName =
"ntpl018_low_precision_floats.root";
std::vector<float> fPt;
std::vector<double> fE;
};
static void Write()
{
{
auto fieldReal16 = std::make_unique<ROOT::RField<float>>(
"myReal16");
}
{
}
{
}
{
auto fieldEvents = std::make_unique<ROOT::RField<Event>>(
"myEvents");
std::cout <<
"Setting field " <<
field.GetQualifiedFieldName() <<
" to truncated.\n";
std::cout <<
"Setting field " <<
field.GetQualifiedFieldName() <<
" to truncated.\n";
}
}
}
const auto &
entry = model->GetDefaultEntry();
}
}
static void Read()
{
const auto &
entry =
reader->GetModel().GetDefaultEntry();
for (
auto idx :
reader->GetEntryRange()) {
<< "\n";
}
}
{
Write();
Read();
}
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
R__EXTERN TRandom * gRandom
Classes with dictionaries that can be inspected by TClass.
static std::unique_ptr< RNTupleModel > Create()
static std::unique_ptr< RNTupleReader > Open(std::string_view ntupleName, std::string_view storage, const ROOT::RNTupleReadOptions &options=ROOT::RNTupleReadOptions())
Open an RNTuple for reading.
static std::unique_ptr< RNTupleWriter > Recreate(std::unique_ptr< ROOT::RNTupleModel > model, std::string_view ntupleName, std::string_view storage, const ROOT::RNTupleWriteOptions &options=ROOT::RNTupleWriteOptions())
Creates an RNTupleWriter backed by storage, overwriting it if one with the same URI exists.
virtual void SetSeed(ULong_t seed=0)
Set the random generator seed.
Double_t Rndm() override
Machine independent random number generator.
- Date
- February 2026
- Author
- The ROOT Team
Definition in file ntpl018_low_precision_floats.C.