Skip to content

Commit 093163a

Browse files
committed
[rntuple] add testing of streamed element
1 parent 9d5eb1a commit 093163a

3 files changed

Lines changed: 28 additions & 4 deletions

File tree

demo/node/rntuple_test.cxx

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include <ROOT/RNTupleModel.hxx>
22
#include <ROOT/RNTupleWriter.hxx>
33

4+
#include <TDictAttributeMap.h>
5+
46

57
#include <cstdio>
68
#include <iostream>
@@ -15,12 +17,18 @@
1517
#include <set>
1618
#include <bitset>
1719

20+
21+
struct CyclicStruct {
22+
int fA = 0;
23+
std::vector<CyclicStruct> fV;
24+
};
25+
1826
class TestClass {
1927
public:
2028
std::string fName;
2129
std::string fTitle;
22-
double fValue{0.};
23-
30+
double fValue = 0.;
31+
CyclicStruct fStreamed;
2432
};
2533

2634
#ifdef __ROOTCLING__
@@ -32,6 +40,7 @@ class TestClass {
3240
#pragma link C++ class std::tuple<std::string,int,bool>+;
3341
#pragma link C++ class std::bitset<25>+;
3442
#pragma link C++ class std::bitset<117>+;
43+
#pragma link C++ struct CyclicStruct;
3544
#pragma link C++ class TestClass+;
3645
#endif
3746

@@ -45,6 +54,11 @@ constexpr int kNEvents = 10;
4554
// Generate kNEvents with vectors in kNTupleFileName
4655
void rntuple_test()
4756
{
57+
auto cl = TClass::GetClass("CyclicStruct");
58+
cl->CreateAttributeMap();
59+
cl->GetAttributeMap()->AddProperty("rntuple.streamerMode", "true");
60+
61+
4862
// We create a unique pointer to an empty data model
4963
auto model = ROOT::RNTupleModel::Create();
5064

@@ -109,6 +123,13 @@ void rntuple_test()
109123
TestClassField->fName = "name_" + std::to_string(i);
110124
TestClassField->fTitle = "title_" + std::to_string(i);
111125
TestClassField->fValue = i;
126+
TestClassField->fStreamed.fA = -i;
127+
TestClassField->fStreamed.fV.clear();
128+
for(int n = 0; n < 1 + i % 3; ++n) {
129+
CyclicStruct inner;
130+
inner.fA = n + 5;
131+
TestClassField->fStreamed.fV.push_back(inner);
132+
}
112133

113134
VectString->clear();
114135
VectInt->clear();

demo/node/rntuple_test.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ selector.Process = function(entryIndex) {
142142
BitsetField: 1 << entryIndex * 3 % 25,
143143
LargeBitsetField: (1n << BigInt((entryIndex + 7) % 117)) | (1n << BigInt((entryIndex + 35) % 117)),
144144
AtomicDoubleField: entryIndex * 111.444,
145-
TestClassField: { _typename: 'TestClass', fName: `name_${entryIndex}`, fTitle: `title_${entryIndex}`, fValue: entryIndex },
145+
TestClassField: { _typename: 'TestClass', fName: `name_${entryIndex}`, fTitle: `title_${entryIndex}`, fValue: entryIndex, fStreamed: { _typename: 'CyclicStruct', fA: -entryIndex, fV: [] } },
146146
VariantField: null,
147-
TupleField: { _0: `tuple_${entryIndex}`, _1: entryIndex*3, _2: (entryIndex % 3 === 1) },
147+
TupleField: { _0: `tuple_${entryIndex}`, _1: entryIndex * 3, _2: (entryIndex % 3 === 1) },
148148
VectString: [],
149149
VectInt: [],
150150
VectBool: [],
@@ -156,6 +156,9 @@ selector.Process = function(entryIndex) {
156156
MapStringBool: []
157157
}, npx = (entryIndex + 5) % 7;
158158

159+
for (let n = 0; n < 1 + entryIndex % 3; ++n)
160+
expectedValues.TestClassField.fStreamed.fV.push({ _typename: 'CyclicStruct', fA: n + 5, fV: [] });
161+
159162
switch (entryIndex % 3) {
160163
case 0: expectedValues.VariantField = `varint_${entryIndex}`; break;
161164
case 1: expectedValues.VariantField = entryIndex; break;

demo/node/rntuple_test.root

581 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)