|
| 1 | +#include <ROOT/RField.hxx> |
| 2 | +#include <ROOT/RNTupleModel.hxx> |
| 3 | +#include <ROOT/RNTupleUtil.hxx> |
| 4 | +#include <ROOT/RNTupleWriteOptions.hxx> |
| 5 | +#include <ROOT/RNTupleWriter.hxx> |
| 6 | + |
| 7 | +using ROOT::Experimental::EColumnType; |
| 8 | +using ROOT::Experimental::RField; |
| 9 | +using ROOT::Experimental::RNTupleModel; |
| 10 | +using ROOT::Experimental::RNTupleWriteOptions; |
| 11 | +using ROOT::Experimental::RNTupleWriter; |
| 12 | + |
| 13 | +#include <cstdint> |
| 14 | +#include <memory> |
| 15 | +#include <string_view> |
| 16 | +#include <unordered_set> |
| 17 | + |
| 18 | +using UnorderedMultiSet = std::unordered_multiset<std::int32_t>; |
| 19 | + |
| 20 | +static std::shared_ptr<UnorderedMultiSet> |
| 21 | +MakeUnorderedMultiSetField(RNTupleModel &model, std::string_view name, |
| 22 | + EColumnType indexType) { |
| 23 | + auto field = std::make_unique<RField<UnorderedMultiSet>>(name); |
| 24 | + field->SetColumnRepresentatives({{indexType}}); |
| 25 | + model.AddField(std::move(field)); |
| 26 | + return model.GetDefaultEntry().GetPtr<UnorderedMultiSet>(name); |
| 27 | +} |
| 28 | + |
| 29 | +void write( |
| 30 | + std::string_view filename = "types.unordered_multiset.fundamental.root") { |
| 31 | + auto model = RNTupleModel::Create(); |
| 32 | + |
| 33 | + // Non-split index encoding |
| 34 | + auto Index32 = |
| 35 | + MakeUnorderedMultiSetField(*model, "Index32", EColumnType::kIndex32); |
| 36 | + auto Index64 = |
| 37 | + MakeUnorderedMultiSetField(*model, "Index64", EColumnType::kIndex64); |
| 38 | + |
| 39 | + // Split index encoding |
| 40 | + auto SplitIndex32 = MakeUnorderedMultiSetField(*model, "SplitIndex32", |
| 41 | + EColumnType::kSplitIndex32); |
| 42 | + auto SplitIndex64 = MakeUnorderedMultiSetField(*model, "SplitIndex64", |
| 43 | + EColumnType::kSplitIndex64); |
| 44 | + |
| 45 | + RNTupleWriteOptions options; |
| 46 | + options.SetCompression(0); |
| 47 | + auto writer = |
| 48 | + RNTupleWriter::Recreate(std::move(model), "ntpl", filename, options); |
| 49 | + |
| 50 | + // First entry: single-element sets, with ascending values |
| 51 | + *Index32 = {1}; |
| 52 | + *Index64 = {2}; |
| 53 | + *SplitIndex32 = {3}; |
| 54 | + *SplitIndex64 = {4}; |
| 55 | + writer->Fill(); |
| 56 | + |
| 57 | + // Second entry: empty sets |
| 58 | + *Index32 = {}; |
| 59 | + *Index64 = {}; |
| 60 | + *SplitIndex32 = {}; |
| 61 | + *SplitIndex64 = {}; |
| 62 | + writer->Fill(); |
| 63 | + |
| 64 | + // Third entry: increasing number of elements in the set |
| 65 | + *Index32 = {1}; |
| 66 | + *Index64 = {2, 3}; |
| 67 | + *SplitIndex32 = {4, 5, 6}; |
| 68 | + *SplitIndex64 = {7, 8, 9, 10}; |
| 69 | + writer->Fill(); |
| 70 | + |
| 71 | + // Fourth entry: duplicate elements in the set |
| 72 | + *Index32 = {1, 1}; |
| 73 | + *Index64 = {2, 2}; |
| 74 | + *SplitIndex32 = {3, 3}; |
| 75 | + *SplitIndex64 = {4, 4}; |
| 76 | + writer->Fill(); |
| 77 | + |
| 78 | + // Fifth entry: unordered elements in the set |
| 79 | + *Index32 = {2, 1}; |
| 80 | + *Index64 = {4, 3}; |
| 81 | + *SplitIndex32 = {6, 5}; |
| 82 | + *SplitIndex64 = {8, 7}; |
| 83 | + writer->Fill(); |
| 84 | + |
| 85 | + // Sixth entry: duplicate and unordered elements in the set |
| 86 | + *Index32 = {2, 1, 2}; |
| 87 | + *Index64 = {4, 4, 3}; |
| 88 | + *SplitIndex32 = {6, 6, 5}; |
| 89 | + *SplitIndex64 = {7, 8, 8}; |
| 90 | + writer->Fill(); |
| 91 | +} |
0 commit comments