Skip to content

Commit

Permalink
Added new test files
Browse files Browse the repository at this point in the history
  • Loading branch information
ariostas committed Nov 18, 2024
1 parent 2bec106 commit 1cbfc13
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 14 deletions.
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();
}
}
14 changes: 0 additions & 14 deletions dev/make-root/rntuple_extension_columns.md

This file was deleted.

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();
}
}
Binary file not shown.
Binary file not shown.

0 comments on commit 1cbfc13

Please sign in to comment.