-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathwrite.C
More file actions
51 lines (43 loc) · 1.47 KB
/
write.C
File metadata and controls
51 lines (43 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <ROOT/RNTupleModel.hxx>
#include <ROOT/RNTupleWriteOptions.hxx>
#include <ROOT/RNTupleWriter.hxx>
using ROOT::Experimental::RNTupleModel;
using ROOT::Experimental::RNTupleWriteOptions;
using ROOT::Experimental::RNTupleWriter;
#include <cstdint>
#include <memory>
#include <string>
#include <string_view>
#include <tuple>
#include <variant>
#include <vector>
using Tuple_Int32_String = std::tuple<std::int32_t, std::string>;
using VectorInt32 = std::vector<std::int32_t>;
void write(std::string_view filename = "types.tuple.root") {
auto model = RNTupleModel::Create();
auto Int32_String_Vector =
model->MakeField<std::tuple<std::int32_t, std::string, VectorInt32>>(
"Int32_String_Vector");
auto Variant =
model->MakeField<std::tuple<std::variant<std::int32_t, std::string>>>(
"Variant");
auto Tuple = model->MakeField<std::tuple<Tuple_Int32_String>>("Tuple");
auto VectorTuple =
model->MakeField<std::vector<Tuple_Int32_String>>("VectorTuple");
RNTupleWriteOptions options;
options.SetCompression(0);
auto writer =
RNTupleWriter::Recreate(std::move(model), "ntpl", filename, options);
// First entry: simple values
*Int32_String_Vector = {1, "abc", {2, 3, 4}};
*Variant = {"def"};
*Tuple = {{5, "ghi"}};
*VectorTuple = {{6, "jkl"}, {7, "mno"}};
writer->Fill();
// Second entry: zero / empty values
*Int32_String_Vector = {0, "", {}};
*Variant = {0};
*Tuple = {{0, ""}};
*VectorTuple = {};
writer->Fill();
}