diff --git a/dev/make-root/rntuple_atomic_bitset.C b/dev/make-root/rntuple_atomic_bitset.C new file mode 100644 index 0000000..45b8f37 --- /dev/null +++ b/dev/make-root/rntuple_atomic_bitset.C @@ -0,0 +1,34 @@ +/* https://root.cern/doc/master/ntpl001__staff_8C.html */ +R__LOAD_LIBRARY(ROOTNTuple) +#include +#include +#include +#include +#include + +#include +#include + +using RNTupleModel = ROOT::Experimental::RNTupleModel; +using RNTupleWriter = ROOT::Experimental::RNTupleWriter; + +void rntuple_atomic_bitset() { + std::string rootFileName{"test_ntuple_atomic_bitset.root"}; + auto model = RNTupleModel::Create(); + auto atomic_int_field = model->MakeField>("atomic_int"); + auto bitset_field = model->MakeField>("bitset"); + auto ntuple = + RNTupleWriter::Recreate(std::move(model), "ntuple", rootFileName); + + *atomic_int_field = 1; + *bitset_field = std::bitset<42>(42); + ntuple->Fill(); + + *atomic_int_field = 2; + *bitset_field |= 0b1010101010101010; + ntuple->Fill(); + + *atomic_int_field = 3; + *bitset_field &= 0b1100110011001100; + ntuple->Fill(); +} diff --git a/dev/make-root/rntuple_emptystruct_invalidvar.C b/dev/make-root/rntuple_emptystruct_invalidvar.C new file mode 100644 index 0000000..79d1b6b --- /dev/null +++ b/dev/make-root/rntuple_emptystruct_invalidvar.C @@ -0,0 +1,46 @@ +/* https://root.cern/doc/master/ntpl001__staff_8C.html */ +R__LOAD_LIBRARY(ROOTNTuple) +#include +#include +#include +#include +#include + +#include +#include + +using RNTupleModel = ROOT::Experimental::RNTupleModel; +using RNTupleWriter = ROOT::Experimental::RNTupleWriter; + +struct EmptyStruct {}; + +struct StructForVariant { + int i; + StructForVariant() = default; + 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"}; + auto model = RNTupleModel::Create(); + auto empty_struct_field = model->MakeField("empty_struct"); + auto variant_field = model->MakeField>("variant"); + auto ntuple = + RNTupleWriter::Recreate(std::move(model), "ntuple", rootFileName); + + *empty_struct_field = EmptyStruct{}; + *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(); +} diff --git a/src/skhep_testdata/data/test_ntuple_atomic_bitset.root b/src/skhep_testdata/data/test_ntuple_atomic_bitset.root new file mode 100644 index 0000000..6ca24dc Binary files /dev/null and b/src/skhep_testdata/data/test_ntuple_atomic_bitset.root differ diff --git a/src/skhep_testdata/data/test_ntuple_emptystruct_invalidvar.root b/src/skhep_testdata/data/test_ntuple_emptystruct_invalidvar.root new file mode 100644 index 0000000..4d06ed1 Binary files /dev/null and b/src/skhep_testdata/data/test_ntuple_emptystruct_invalidvar.root differ