diff --git a/dev/make-root/rntuple_float_types.C b/dev/make-root/rntuple_float_types.C new file mode 100644 index 0000000..9f523e4 --- /dev/null +++ b/dev/make-root/rntuple_float_types.C @@ -0,0 +1,136 @@ +/* https://root.cern/doc/master/ntpl001__staff_8C.html */ +R__LOAD_LIBRARY(ROOTNTuple) +#include +#include +#include +#include +#include +#include + +#include +#include + +using RNTupleModel = ROOT::Experimental::RNTupleModel; +using RNTupleWriter = ROOT::Experimental::RNTupleWriter; +template +using RField = ROOT::Experimental::RField; +using EColumnType = ROOT::Experimental::EColumnType; + +void rntuple_float_types() { + std::string rootFileName{"test_float_types_rntuple_v1-0-0-0.root"}; + auto model = RNTupleModel::Create(); + + auto trunc10 = std::make_unique>("trunc10"); + trunc10->SetColumnRepresentatives({{EColumnType::kReal32Trunc}}); + trunc10->SetTruncated(10); + model->AddField(std::move(trunc10)); + + auto trunc16 = std::make_unique>("trunc16"); + trunc16->SetColumnRepresentatives({{EColumnType::kReal32Trunc}}); + trunc16->SetTruncated(16); + model->AddField(std::move(trunc16)); + + auto trunc24 = std::make_unique>("trunc24"); + trunc24->SetColumnRepresentatives({{EColumnType::kReal32Trunc}}); + trunc24->SetTruncated(24); + model->AddField(std::move(trunc24)); + + auto trunc31 = std::make_unique>("trunc31"); + trunc31->SetColumnRepresentatives({{EColumnType::kReal32Trunc}}); + trunc31->SetTruncated(31); + model->AddField(std::move(trunc31)); + + auto quant1 = std::make_unique>("quant1"); + quant1->SetColumnRepresentatives({{EColumnType::kReal32Quant}}); + quant1->SetQuantized(-2.f, 3.f, 1); + model->AddField(std::move(quant1)); + + auto quant8 = std::make_unique>("quant8"); + quant8->SetColumnRepresentatives({{EColumnType::kReal32Quant}}); + quant8->SetQuantized(-2.f, 3.f, 8); + model->AddField(std::move(quant8)); + + auto quant16 = std::make_unique>("quant16"); + quant16->SetColumnRepresentatives({{EColumnType::kReal32Quant}}); + quant16->SetQuantized(-2.f, 3.f, 16); + model->AddField(std::move(quant16)); + + auto quant20 = std::make_unique>("quant20"); + quant20->SetColumnRepresentatives({{EColumnType::kReal32Quant}}); + quant20->SetQuantized(-2.f, 3.f, 20); + model->AddField(std::move(quant20)); + + auto quant24 = std::make_unique>("quant24"); + quant24->SetColumnRepresentatives({{EColumnType::kReal32Quant}}); + quant24->SetQuantized(-2.f, 3.f, 24); + model->AddField(std::move(quant24)); + + auto quant25 = std::make_unique>("quant25"); + quant25->SetColumnRepresentatives({{EColumnType::kReal32Quant}}); + quant25->SetQuantized(-2.f, 3.f, 25); + model->AddField(std::move(quant25)); + + auto quant32 = std::make_unique>("quant32"); + quant32->SetColumnRepresentatives({{EColumnType::kReal32Quant}}); + quant32->SetQuantized(-2.f, 3.f, 32); + model->AddField(std::move(quant32)); + + auto ntuple = RNTupleWriter::Recreate(std::move(model), "ntuple", rootFileName); + auto e = ntuple->CreateEntry(); + + *e->GetPtr("trunc10") = 1.23456789f; // 00111111100111100000011001010010 + *e->GetPtr("trunc16") = 1.23456789f; + *e->GetPtr("trunc24") = 1.23456789f; + *e->GetPtr("trunc31") = 1.23456789f; + *e->GetPtr("quant1") = 1.23456789f; + *e->GetPtr("quant8") = 1.23456789f; + *e->GetPtr("quant16") = 1.23456789f; + *e->GetPtr("quant20") = 1.23456789f; + *e->GetPtr("quant24") = 1.23456789f; + *e->GetPtr("quant25") = 1.23456789f; + *e->GetPtr("quant32") = 1.23456789f; + + ntuple->Fill(*e); + + *e->GetPtr("trunc10") = 1.4660155e13f; // 01010101010101010101010101010101 + *e->GetPtr("trunc16") = 1.4660155e13f; + *e->GetPtr("trunc24") = 1.4660155e13f; + *e->GetPtr("trunc31") = 1.4660155e13f; + *e->GetPtr("quant1") = 1.6666666f; // 00111111110101010101010101010101 + *e->GetPtr("quant8") = 1.6666666f; + *e->GetPtr("quant16") = 1.6666666f; + *e->GetPtr("quant20") = 1.6666666f; + *e->GetPtr("quant24") = 1.6666666f; + *e->GetPtr("quant25") = 1.6666666f; + *e->GetPtr("quant32") = 1.6666666f; + + ntuple->Fill(*e); + + *e->GetPtr("trunc10") = -6.2875986e-22f; // 10011100001111100000011111110000 + *e->GetPtr("trunc16") = -6.2875986e-22f; + *e->GetPtr("trunc24") = -6.2875986e-22f; + *e->GetPtr("trunc31") = -6.2875986e-22f; + *e->GetPtr("quant1") = -6.2875986e-22f; + *e->GetPtr("quant8") = -6.2875986e-22f; + *e->GetPtr("quant16") = -6.2875986e-22f; + *e->GetPtr("quant20") = -6.2875986e-22f; + *e->GetPtr("quant24") = -6.2875986e-22f; + *e->GetPtr("quant25") = -6.2875986e-22f; + *e->GetPtr("quant32") = -6.2875986e-22f; + + ntuple->Fill(*e); + + *e->GetPtr("trunc10") = -1.9060668f; // 10111111111100111111100111111111 + *e->GetPtr("trunc16") = -1.9060668f; + *e->GetPtr("trunc24") = -1.9060668f; + *e->GetPtr("trunc31") = -1.9060668f; + *e->GetPtr("quant1") = -1.9060668f; + *e->GetPtr("quant8") = -1.9060668f; + *e->GetPtr("quant16") = -1.9060668f; + *e->GetPtr("quant20") = -1.9060668f; + *e->GetPtr("quant24") = -1.9060668f; + *e->GetPtr("quant25") = -1.9060668f; + *e->GetPtr("quant32") = -1.9060668f; + + ntuple->Fill(*e); +} diff --git a/dev/make-root/rntuple_multiple_representations.C b/dev/make-root/rntuple_multiple_representations.C new file mode 100644 index 0000000..df72bf4 --- /dev/null +++ b/dev/make-root/rntuple_multiple_representations.C @@ -0,0 +1,43 @@ +/* https://root.cern/doc/master/ntpl001__staff_8C.html */ +R__LOAD_LIBRARY(ROOTNTuple) +#include +#include +#include +#include +#include +#include + +#include +#include + +using RNTupleModel = ROOT::Experimental::RNTupleModel; +using RNTupleWriter = ROOT::Experimental::RNTupleWriter; +using RFieldBase = ROOT::Experimental::RFieldBase; +using EColumnType = ROOT::Experimental::EColumnType; + +void rntuple_multiple_representations() { + std::string rootFileName{"test_multiple_representations_rntuple_v1-0-0-0.root"}; + auto model = RNTupleModel::Create(); + + auto fldReal = RFieldBase::Create("real", "float").Unwrap(); + fldReal->SetColumnRepresentatives({{EColumnType::kReal32}, {EColumnType::kReal16}}); + model->AddField(std::move(fldReal)); + auto ptrReal = model->GetDefaultEntry().GetPtr("real"); + + auto ntuple = RNTupleWriter::Recreate(std::move(model), "ntuple", rootFileName); + + *ptrReal = 1.0; + ntuple->Fill(); + ntuple->CommitCluster(); + + ROOT::Experimental::Internal::RFieldRepresentationModifier::SetPrimaryColumnRepresentation( + const_cast(ntuple->GetModel().GetConstField("real")), 1); + *ptrReal = 2.0; + ntuple->Fill(); + ntuple->CommitCluster(); + + ROOT::Experimental::Internal::RFieldRepresentationModifier::SetPrimaryColumnRepresentation( + const_cast(ntuple->GetModel().GetConstField("real")), 0); + *ptrReal = 3.0; + ntuple->Fill(); +} diff --git a/src/skhep_testdata/data/test_float_types_rntuple_v1-0-0-0.root b/src/skhep_testdata/data/test_float_types_rntuple_v1-0-0-0.root new file mode 100644 index 0000000..b59b82f Binary files /dev/null and b/src/skhep_testdata/data/test_float_types_rntuple_v1-0-0-0.root differ diff --git a/src/skhep_testdata/data/test_multiple_representations_rntuple_v1-0-0-0.root b/src/skhep_testdata/data/test_multiple_representations_rntuple_v1-0-0-0.root new file mode 100644 index 0000000..5e6764a Binary files /dev/null and b/src/skhep_testdata/data/test_multiple_representations_rntuple_v1-0-0-0.root differ