Skip to content

Commit e535674

Browse files
committed
[io] add unit test infrastructure for streaming large objects
Uses RStreamerField as a test bed for (de-)serializing large objects with TBufferFile.
1 parent 379cd76 commit e535674

5 files changed

Lines changed: 73 additions & 0 deletions

File tree

tree/ntuple/test/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ ROOT_GENERATE_DICTIONARY(StreamerFieldDict ${CMAKE_CURRENT_SOURCE_DIR}/StreamerF
114114
MODULE rfield_streamer LINKDEF StreamerFieldLinkDef.h OPTIONS -inlineInputHeader
115115
DEPENDENCIES RIO)
116116

117+
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
118+
ROOT_ADD_GTEST(rfield_streamer_beyond rfield_streamer_beyond.cxx StreamerBeyond.cxx LIBRARIES ROOTNTuple)
119+
ROOT_GENERATE_DICTIONARY(StreamerBeyondDict ${CMAKE_CURRENT_SOURCE_DIR}/StreamerBeyond.hxx
120+
MODULE rfield_streamer_beyond LINKDEF StreamerBeyondLinkDef.h OPTIONS -inlineInputHeader
121+
DEPENDENCIES RIO)
122+
endif()
123+
117124
if(MSVC)
118125
set(command ${CMAKE_COMMAND} -E env "ROOTIGNOREPREFIX=1" $<TARGET_FILE:genreflex>)
119126
else()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "StreamerBeyond.hxx"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifndef ROOT_RNTuple_Test_StreamerBeyond
2+
#define ROOT_RNTuple_Test_StreamerBeyond
3+
4+
#include <Rtypes.h>
5+
6+
#include <cstdint>
7+
#include <vector>
8+
9+
struct StreamerBeyond {
10+
std::vector<std::int64_t> fOne;
11+
std::vector<std::int64_t> fTwo;
12+
};
13+
14+
#endif
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#ifdef __CLING__
2+
3+
#pragma link C++ options=rntupleStreamerMode(true) struct StreamerBeyond+;
4+
5+
#endif
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include <ROOT/RFieldBase.hxx>
2+
#include <ROOT/RNTupleModel.hxx>
3+
#include <ROOT/RNTupleReader.hxx>
4+
#include <ROOT/RNTupleWriter.hxx>
5+
6+
#include <ROOT/TestSupport.hxx>
7+
8+
#include <cstdio>
9+
#include <string>
10+
#include <utility>
11+
12+
#include "StreamerBeyond.hxx"
13+
#include "gtest/gtest.h"
14+
15+
TEST(RField, StreamerBeyond)
16+
{
17+
ROOT::TestSupport::FileRaii fileGuard("test_ntuple_rfield_streamer_beyond.root");
18+
19+
{
20+
auto model = ROOT::RNTupleModel::Create();
21+
auto f = ROOT::RFieldBase::Create("f", "StreamerBeyond").Unwrap();
22+
EXPECT_TRUE(dynamic_cast<ROOT::RStreamerField *>(f.get()));
23+
model->AddField(std::move(f));
24+
auto writer = ROOT::RNTupleWriter::Recreate(std::move(model), "ntpl", fileGuard.GetPath());
25+
26+
auto ptr = writer->GetModel().GetDefaultEntry().GetPtr<StreamerBeyond>("f");
27+
ptr->fOne = std::vector<std::int64_t>(100000000, -1);
28+
ptr->fTwo = std::vector<std::int64_t>(100000000, -2);
29+
30+
writer->Fill();
31+
}
32+
33+
auto reader = ROOT::RNTupleReader::Open("ntpl", fileGuard.GetPath());
34+
ASSERT_EQ(1u, reader->GetNEntries());
35+
StreamerBeyond sb;
36+
auto view = reader->GetView("f", &sb, "StreamerBeyond");
37+
38+
view(0);
39+
40+
auto ptr = view.GetValue().GetPtr<StreamerBeyond>();
41+
EXPECT_EQ(100000000u, ptr->fOne.size());
42+
EXPECT_EQ(-1, ptr->fOne.at(1000));
43+
EXPECT_EQ(100000000u, ptr->fTwo.size());
44+
EXPECT_EQ(-2, ptr->fTwo.at(2000));
45+
EXPECT_EQ(-2, ptr->fTwo.at(99999999u));
46+
}

0 commit comments

Comments
 (0)