Adapted from tv3.C Illustrates various RNTuple introspection methods.
#include <cassert>
constexpr char const* kNTupleFileName = "ntpl005_introspection.root";
class Vector3 {
private:
double fX = 0;
double fY = 0;
double fZ = 0;
public:
double x()
const {
return fX; }
double y()
const {
return fY; }
double z() const { return fZ; }
void SetXYZ(
double x,
double y,
double z) {
fZ = z;
}
};
void Generate()
{
auto fldVector3 = model->MakeField<Vector3>("v3");
for (unsigned int i = 0; i < 500000; ++i) {
fldVector3->SetXYZ(
r.Gaus(0,1),
r.Landau(0,1),
r.Gaus(100,10));
}
}
void ntpl005_introspection() {
Generate();
reader->PrintInfo();
reader->Show(0);
reader->EnableMetrics();
TH1F h1(
"x",
"x component of Vector3", 100, -3, 3);
{
auto viewX = reader->GetView<double>("v3.fX");
for (auto i : reader->GetEntryRange()) {
}
}
TH1F h2(
"y",
"y component of Vector3", 100, -5, 20);
auto viewY = reader->GetView<double>("v3.fY");
for (auto i : reader->GetEntryRange()) {
h2.Fill(viewY(i));
}
h2.DrawCopy();
auto retval =
gSystem->GetPathInfo(kNTupleFileName, fileStat);
assert(retval == 0);
float fileSize =
static_cast<float>(fileStat.
fSize);
float nbytesRead = reader->GetMetrics().GetCounter("RNTupleReader.RPageSourceFile.szReadPayload")->GetValueAsInt() +
reader->GetMetrics().GetCounter("RNTupleReader.RPageSourceFile.szReadOverhead")->GetValueAsInt();
std::cout << "File size: " << fileSize / 1024. / 1024. << " MiB" << std::endl;
std::cout << "Read from file: " << nbytesRead / 1024. / 1024. << " MiB" << std::endl;
std::cout << "Ratio: " << nbytesRead / fileSize << std::endl;
}
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.
Common user-tunable settings for storing RNTuples.
void SetCompression(std::uint32_t val)
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.
1-D histogram with a float per channel (see TH1 documentation)
This is the base class for the ROOT Random number generators.
@ kUseGeneralPurpose
Use the new recommended general-purpose setting; it is a best trade-off between compression ratio/dec...