Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update RNTuple files to the v1 spec #164

Merged
merged 9 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,8 @@ ENV/
/src/skhep_testdata/version.py
/pip-wheel-metadata/*
/src/skhep_testdata/data/file_list.txt

# Temporary files when generating ROOT files
dev/make-root/*.root
dev/make-root/*.so
dev/make-root/*.d
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
First, download `Run2012BC_DoubleMuParked_Muons.root` from [here](https://opendata.cern.ch/record/12341). Then, run the following commands in ROOT.

```cpp
auto importer = ROOT::Experimental::RNTupleImporter::Create("./Run2012BC_DoubleMuParked_Muons.root", "Events", "./Run2012BC_DoubleMuParked_Muons_rntuple_1000evts.root");
auto importer = ROOT::Experimental::RNTupleImporter::Create("./Run2012BC_DoubleMuParked_Muons.root", "Events", "./Run2012BC_DoubleMuParked_Muons_1000evts_rntuple_v1.root");
auto c = importer.get();
c->SetMaxEntries(1000);
c->Import()
Expand Down
3 changes: 2 additions & 1 deletion dev/make-root/rntuple_1jag_int_float.C
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ R__LOAD_LIBRARY(ROOTNTuple);
#include <ROOT/RField.hxx>
#include <ROOT/RNTuple.hxx>
#include <ROOT/RNTupleModel.hxx>
#include <ROOT/RNTupleWriter.hxx>
#include <ROOT/RRawFile.hxx>

using RNTupleModel = ROOT::Experimental::RNTupleModel;
using RNTupleWriter = ROOT::Experimental::RNTupleWriter;

void rntuple_1jag_int_float() {
std::string rootFileName{"test_ntuple_1jag_int_float.root"};
std::string rootFileName{"test_1jag_int_float_rntuple_v1.root"};
auto model = RNTupleModel::Create();
auto v_int = model->MakeField<std::vector<int>>("one_v_integers");
auto v_float = model->MakeField<std::vector<float>>("two_v_floats");
Expand Down
2 changes: 1 addition & 1 deletion dev/make-root/rntuple_atomic_bitset.C
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ using RNTupleModel = ROOT::Experimental::RNTupleModel;
using RNTupleWriter = ROOT::Experimental::RNTupleWriter;

void rntuple_atomic_bitset() {
std::string rootFileName{"test_ntuple_atomic_bitset.root"};
std::string rootFileName{"test_atomic_bitset_rntuple_v1.root"};
auto model = RNTupleModel::Create();
auto atomic_int_field = model->MakeField<std::atomic<int>>("atomic_int");
auto bitset_field = model->MakeField<std::bitset<42>>("bitset");
Expand Down
3 changes: 2 additions & 1 deletion dev/make-root/rntuple_bit.C
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ R__LOAD_LIBRARY(ROOTNTuple)
#include <ROOT/RField.hxx>
#include <ROOT/RNTuple.hxx>
#include <ROOT/RNTupleModel.hxx>
#include <ROOT/RNTupleWriter.hxx>
#include <ROOT/RRawFile.hxx>

using RNTupleModel = ROOT::Experimental::RNTupleModel;
using RNTupleWriter = ROOT::Experimental::RNTupleWriter;

void rntuple_bit() {
std::string rootFileName{"test_ntuple_bit.root"};
std::string rootFileName{"test_bit_rntuple_v1.root"};
auto model = RNTupleModel::Create();
auto bit_field = model->MakeField<bool>("one_bit");
auto ntuple =
Expand Down
9 changes: 5 additions & 4 deletions dev/make-root/rntuple_emptystruct_invalidvar.C
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ struct EmptyStruct {};
struct StructForVariant {
int i;
StructForVariant() = default;
StructForVariant(int ii) : i(ii) {};
StructForVariant(const StructForVariant &) { throw std::runtime_error("copy ctor"); }
StructForVariant &operator=(const StructForVariant &) = default;
};

void rntuple_emptystruct_invalidvar() {
std::string rootFileName{"test_ntuple_emptystruct_invalidvar.root"};
std::string rootFileName{"test_emptystruct_invalidvar_rntuple_v1.root"};
auto model = RNTupleModel::Create();
auto empty_struct_field = model->MakeField<EmptyStruct>("empty_struct");
auto variant_field = model->MakeField<std::variant<int,StructForVariant>>("variant");
Expand All @@ -33,14 +34,14 @@ void rntuple_emptystruct_invalidvar() {
*variant_field = 1; // valid state
ntuple->Fill();

*variant_field = { 1 }; // valid state
ntuple->Fill();

try {
*variant_field = StructForVariant(); // invalid state
} catch (const std::runtime_error &e) {
std::cerr << "Caught exception: " << e.what() << std::endl;
}
assert(variant_field->valueless_by_exception());
ntuple->Fill();

variant_field->emplace<StructForVariant>(2); // valid state
ntuple->Fill();
}
56 changes: 56 additions & 0 deletions dev/make-root/rntuple_extension_columns.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* https://root.cern/doc/master/ntpl001__staff_8C.html */
R__LOAD_LIBRARY(ROOTNTuple)
#include <ROOT/RField.hxx>
#include <ROOT/RNTuple.hxx>
#include <ROOT/RNTupleModel.hxx>
#include <ROOT/RNTupleWriter.hxx>
#include <ROOT/RNTupleWriteOptions.hxx>
#include <ROOT/RRawFile.hxx>

#include <cassert>
#include <variant>

using RNTupleModel = ROOT::Experimental::RNTupleModel;
using RNTupleWriter = ROOT::Experimental::RNTupleWriter;
using RNTupleWriteOptions = ROOT::Experimental::RNTupleWriteOptions;

void rntuple_extension_columns() {
auto options = RNTupleWriteOptions();
options.SetMaxUnzippedPageSize(700);
options.SetApproxZippedClusterSize(2000);
options.SetMaxUnzippedClusterSize(2000);

std::string rootFileName{"test_extension_columns_rntuple_v1.root"};
auto model = RNTupleModel::Create();
auto int_field = model->MakeField<int>("int_field");

auto ntuple = RNTupleWriter::Recreate(std::move(model), "ntuple", rootFileName, options);

for (int i = 0; i < 200; i++) {
*int_field = i;
ntuple->Fill();
}

auto modelUpdater = ntuple->CreateModelUpdater();
modelUpdater->BeginUpdate();
auto vec_fload = modelUpdater->MakeField<float>("float_field");
modelUpdater->CommitUpdate();

for (int i = 0; i < 200; i++) {
*int_field = i;
*vec_fload = i + 0.5;
ntuple->Fill();
}

auto modelUpdater2 = ntuple->CreateModelUpdater();
modelUpdater2->BeginUpdate();
auto intvec_field = modelUpdater2->MakeField<std::vector<int>>("intvec_field");
modelUpdater2->CommitUpdate();

for (int i = 0; i < 200; i++) {
*int_field = i;
*vec_fload = i + 0.5;
*intvec_field = {i, i + 1};
ntuple->Fill();
}
}
4 changes: 2 additions & 2 deletions dev/make-root/rntuple_index_multicluster.C
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ using RNTupleWriteOptions = ROOT::Experimental::RNTupleWriteOptions;

void rntuple_index_multicluster() {
auto options = RNTupleWriteOptions();
options.SetApproxUnzippedPageSize(512);
options.SetMaxUnzippedPageSize(512);
options.SetApproxZippedClusterSize(1000);
options.SetMaxUnzippedClusterSize(1024);

std::string rootFileName{"test_ntuple_index_multicluster.root"};
std::string rootFileName{"test_index_multicluster_rntuple_v1.root"};
auto model = RNTupleModel::Create();
auto int_vector = model->MakeField<std::vector<int16_t>>("int_vector");
auto ntuple =
Expand Down
3 changes: 2 additions & 1 deletion dev/make-root/rntuple_int_5e4.C
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ R__LOAD_LIBRARY(ROOTNTuple)
#include <ROOT/RField.hxx>
#include <ROOT/RNTuple.hxx>
#include <ROOT/RNTupleModel.hxx>
#include <ROOT/RNTupleWriter.hxx>
#include <ROOT/RRawFile.hxx>

using RNTupleModel = ROOT::Experimental::RNTupleModel;
using RNTupleWriter = ROOT::Experimental::RNTupleWriter;

void rntuple_int_5e4() {
std::string rootFileName{"test_ntuple_int_5e4.root"};
std::string rootFileName{"test_int_5e4_rntuple_v1.root"};
auto model = RNTupleModel::Create();
auto int_field = model->MakeField<int>("one_integers");
auto ntuple =
Expand Down
3 changes: 2 additions & 1 deletion dev/make-root/rntuple_int_float.C
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ R__LOAD_LIBRARY(ROOTNTuple)
#include <ROOT/RField.hxx>
#include <ROOT/RNTuple.hxx>
#include <ROOT/RNTupleModel.hxx>
#include <ROOT/RNTupleWriter.hxx>
#include <ROOT/RRawFile.hxx>

using RNTupleModel = ROOT::Experimental::RNTupleModel;
using RNTupleWriter = ROOT::Experimental::RNTupleWriter;

void rntuple_int_float() {
std::string rootFileName{"test_ntuple_int_float.root"};
std::string rootFileName{"test_int_float_rntuple_v1.root"};
auto model = RNTupleModel::Create();
auto int_field = model->MakeField<int>("one_integers");
auto float_field = model->MakeField<float>("two_floats");
Expand Down
3 changes: 2 additions & 1 deletion dev/make-root/rntuple_int_multicluster.C
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ R__LOAD_LIBRARY(ROOTNTuple)
#include <ROOT/RField.hxx>
#include <ROOT/RNTuple.hxx>
#include <ROOT/RNTupleModel.hxx>
#include <ROOT/RNTupleWriter.hxx>
#include <ROOT/RRawFile.hxx>

using RNTupleModel = ROOT::Experimental::RNTupleModel;
using RNTupleWriter = ROOT::Experimental::RNTupleWriter;

void rntuple_int_multicluster() {
std::string rootFileName{"test_ntuple_int_multicluster.root"};
std::string rootFileName{"test_int_multicluster_rntuple_v1.root"};
auto model = RNTupleModel::Create();
auto int_field = model->MakeField<int16_t>("one_integers");
auto ntuple =
Expand Down
3 changes: 2 additions & 1 deletion dev/make-root/rntuple_int_vfloat_tlv_vtlv.C
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ R__LOAD_LIBRARY(ROOTNTuple)
#include <ROOT/RField.hxx>
#include <ROOT/RNTuple.hxx>
#include <ROOT/RNTupleModel.hxx>
#include <ROOT/RNTupleWriter.hxx>
#include <ROOT/RRawFile.hxx>

using RNTupleModel = ROOT::Experimental::RNTupleModel;
Expand All @@ -17,7 +18,7 @@ struct LV{
};

void rntuple_int_vfloat_tlv_vtlv() {
std::string rootFileName{"test_ntuple_int_vfloat_tlv_vtlv.root"};
std::string rootFileName{"test_int_vfloat_tlv_vtlv_rntuple_v1.root"};
auto model = RNTupleModel::Create();
auto int_field = model->MakeField<int>("one_integers");
auto v_float_field = model->MakeField<std::vector<float>>("two_v_floats");
Expand Down
46 changes: 46 additions & 0 deletions dev/make-root/rntuple_nested_structs.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* https://root.cern/doc/master/ntpl001__staff_8C.html */
R__LOAD_LIBRARY(ROOTNTuple)
#include <ROOT/RField.hxx>
#include <ROOT/RNTuple.hxx>
#include <ROOT/RNTupleModel.hxx>
#include <ROOT/RNTupleWriter.hxx>
#include <ROOT/RRawFile.hxx>

#include <cassert>
#include <variant>

using RNTupleModel = ROOT::Experimental::RNTupleModel;
using RNTupleWriter = ROOT::Experimental::RNTupleWriter;

struct SubSubSruct {
int i;
std::vector<int> v;
};

struct SubStruct {
int i;
SubSubSruct sub_sub_struct;
};

struct TopStruct {
int i;
SubStruct sub_struct;
};

void rntuple_nested_structs() {
std::string rootFileName{"test_nested_structs_rntuple_v1.root"};
auto model = RNTupleModel::Create();
auto struct_field = model->MakeField<TopStruct>("my_struct");
auto ntuple =
RNTupleWriter::Recreate(std::move(model), "ntuple", rootFileName);


*struct_field = TopStruct();
for (int i = 0; i < 10; i++) {
struct_field->i = i;
struct_field->sub_struct.i = i + 1;
struct_field->sub_struct.sub_sub_struct.i = i + 2;
struct_field->sub_struct.sub_sub_struct.v = {i, i + 1};
ntuple->Fill();
}
}
3 changes: 2 additions & 1 deletion dev/make-root/rntuple_split_3e4.C
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ R__LOAD_LIBRARY(ROOTNTuple)
#include <ROOT/RField.hxx>
#include <ROOT/RNTuple.hxx>
#include <ROOT/RNTupleModel.hxx>
#include <ROOT/RNTupleWriter.hxx>
#include <ROOT/RRawFile.hxx>

using RNTupleModel = ROOT::Experimental::RNTupleModel;
using RNTupleWriter = ROOT::Experimental::RNTupleWriter;

void rntuple_split_3e4() {
std::string rootFileName{"test_ntuple_split_3e4.root"};
std::string rootFileName{"test_split_3e4_rntuple_v1.root"};
auto model = RNTupleModel::Create();
auto splitint_field = model->MakeField<int32_t>("one_int32");
auto splitint_field2 = model->MakeField<uint32_t>("two_uint32");
Expand Down
3 changes: 2 additions & 1 deletion dev/make-root/rntuple_stl_containers.C
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ R__LOAD_LIBRARY(ROOTNTuple)
#include <ROOT/RField.hxx>
#include <ROOT/RNTuple.hxx>
#include <ROOT/RNTupleModel.hxx>
#include <ROOT/RNTupleWriter.hxx>
#include <ROOT/RRawFile.hxx>

using RNTupleModel = ROOT::Experimental::RNTupleModel;
Expand All @@ -25,7 +26,7 @@ struct LV{
};

void rntuple_stl_containers() {
std::string rootFileName{"test_ntuple_stl_containers.root"};
std::string rootFileName{"test_stl_containers_rntuple_v1.root"};
auto model = RNTupleModel::Create();
auto string = model->MakeField<std::string>("string");
auto vector_int32 = model->MakeField<std::vector<int32_t>>("vector_int32");
Expand Down
14 changes: 0 additions & 14 deletions dev/make-root/test_ntuple_extension_columns.md

This file was deleted.

Binary file removed src/skhep_testdata/data/DAOD_TRUTH3_RC2.root
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added src/skhep_testdata/data/test_bit_rntuple_v1.root
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed src/skhep_testdata/data/test_ntuple_bit.root
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed src/skhep_testdata/data/test_ntuple_int_5e4.root
Binary file not shown.
Binary file removed src/skhep_testdata/data/test_ntuple_int_float.root
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed src/skhep_testdata/data/test_ntuple_split_3e4.root
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed src/skhep_testdata/data/uproot-ntpl001_staff.root
Binary file not shown.