@@ -12,8 +12,9 @@ using ROOT::Experimental::RNTupleReader;
1212#include <variant>
1313#include <vector>
1414
15- using Vector = std ::vector < std ::int32_t > ;
16- using Variant = std ::variant < std ::int32_t , std ::string , Vector > ;
15+ using VectorInt32 = std ::vector < std ::int32_t > ;
16+ using Variant = std ::variant < std ::int32_t , std ::string , VectorInt32 > ;
17+ using Vector = std ::vector < std ::variant < std ::int32_t , std ::string >>;
1718
1819static void PrintVariantValue (const REntry & entry , std ::string_view name ,
1920 std ::ostream & os , bool last = false) {
@@ -24,7 +25,7 @@ static void PrintVariantValue(const REntry &entry, std::string_view name,
2425 } else if (value .index () == 1 ) {
2526 os << "\"" << std ::get < std ::string > (value ) << "\"" ;
2627 } else if (value .index () == 2 ) {
27- Vector & vectorValue = std ::get < Vector > (value );
28+ VectorInt32 & vectorValue = std ::get < VectorInt32 > (value );
2829 os << "[" ;
2930 bool first = true;
3031 for (auto element : vectorValue ) {
@@ -47,6 +48,35 @@ static void PrintVariantValue(const REntry &entry, std::string_view name,
4748 os << "\n" ;
4849}
4950
51+ static void PrintVectorValue (const REntry & entry , std ::string_view name ,
52+ std ::ostream & os , bool last = false) {
53+ Vector & value = * entry .GetPtr < Vector > (name );
54+ os << " \"" << name << "\": [" ;
55+ bool first = true;
56+ for (auto & element : value ) {
57+ if (first ) {
58+ first = false;
59+ } else {
60+ os << "," ;
61+ }
62+ os << "\n " ;
63+ if (element .index () == 0 ) {
64+ os << std ::get < std ::int32_t > (element );
65+ } else if (element .index () == 1 ) {
66+ os << "\"" << std ::get < std ::string > (element ) << "\"" ;
67+ }
68+ }
69+ if (!value .empty ()) {
70+ os << "\n " ;
71+ }
72+ os << "]" ;
73+
74+ if (!last ) {
75+ os << "," ;
76+ }
77+ os << "\n" ;
78+ }
79+
5080void read (std ::string_view input = "types.variant.root" ,
5181 std ::string_view output = "types.variant.json" ) {
5282 std ::ofstream os (std ::string {output });
@@ -65,7 +95,8 @@ void read(std::string_view input = "types.variant.root",
6595 }
6696 os << " {\n" ;
6797
68- PrintVariantValue (entry , "f" , os , /*last=*/ true);
98+ PrintVariantValue (entry , "f" , os );
99+ PrintVectorValue (entry , "Vector" , os , /*last=*/ true);
69100
70101 os << " }" ;
71102 // Newline is intentionally missing, may need to print a comma before the
0 commit comments