|
| 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_map> |
| 17 | + |
| 18 | +using UnorderedMultimap = std::unordered_multimap<std::string, std::int32_t>; |
| 19 | + |
| 20 | +static std::shared_ptr<UnorderedMultimap> MakeMultimapField(RNTupleModel &model, |
| 21 | + std::string_view name, |
| 22 | + EColumnType indexType) { |
| 23 | + auto field = std::make_unique<RField<UnorderedMultimap>>(name); |
| 24 | + field->SetColumnRepresentatives({{indexType}}); |
| 25 | + model.AddField(std::move(field)); |
| 26 | + return model.GetDefaultEntry().GetPtr<UnorderedMultimap>(name); |
| 27 | +} |
| 28 | + |
| 29 | +void write(std::string_view filename = "types.unordered_multimap.fundamental.root") { |
| 30 | + auto model = RNTupleModel::Create(); |
| 31 | + |
| 32 | + // Non-split index encoding |
| 33 | + auto Index32 = MakeMultimapField(*model, "Index32", EColumnType::kIndex32); |
| 34 | + auto Index64 = MakeMultimapField(*model, "Index64", EColumnType::kIndex64); |
| 35 | + |
| 36 | + // Split index encoding |
| 37 | + auto SplitIndex32 = |
| 38 | + MakeMultimapField(*model, "SplitIndex32", EColumnType::kSplitIndex32); |
| 39 | + auto SplitIndex64 = |
| 40 | + MakeMultimapField(*model, "SplitIndex64", EColumnType::kSplitIndex64); |
| 41 | + |
| 42 | + RNTupleWriteOptions options; |
| 43 | + options.SetCompression(0); |
| 44 | + auto writer = |
| 45 | + RNTupleWriter::Recreate(std::move(model), "ntpl", filename, options); |
| 46 | + |
| 47 | + // First entry: single-element maps, with ascending values |
| 48 | + *Index32 = {{"a", 1}}; |
| 49 | + *Index64 = {{"b", 2}}; |
| 50 | + *SplitIndex32 = {{"c", 3}}; |
| 51 | + *SplitIndex64 = {{"d", 4}}; |
| 52 | + writer->Fill(); |
| 53 | + |
| 54 | + // Second entry: empty maps |
| 55 | + *Index32 = {}; |
| 56 | + *Index64 = {}; |
| 57 | + *SplitIndex32 = {}; |
| 58 | + *SplitIndex64 = {}; |
| 59 | + writer->Fill(); |
| 60 | + |
| 61 | + // Third entry: increasing number of elements in the map |
| 62 | + *Index32 = {{"a", 1}}; |
| 63 | + *Index64 = {{"b", 2}, {"c", 3}}; |
| 64 | + *SplitIndex32 = {{"d", 4}, {"e", 5}, {"f", 6}}; |
| 65 | + *SplitIndex64 = {{"g", 7}, {"h", 8}, {"i", 9}, {"j", 10}}; |
| 66 | + writer->Fill(); |
| 67 | +} |
0 commit comments