Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion io/io/src/TBufferFile.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,13 @@ void TBufferFile::SetByteCount(ULong64_t cntpos, Bool_t packInVersion)
&& (fBufCur >= fBuffer)
&& static_cast<ULong64_t>(fBufCur - fBuffer) <= std::numeric_limits<UInt_t>::max()
&& "Byte count position is after the end of the buffer");
const UInt_t cnt = UInt_t(fBufCur - fBuffer) - UInt_t(cntpos) - sizeof(UInt_t);

char *buf = (char *)(fBuffer + cntpos);
if ((fBufCur - fBuffer - cntpos - sizeof(UInt_t)) >= kMaxMapCount) {
tobuf(buf, 0 | kByteCountMask);
return;
}
const UInt_t cnt = UInt_t(fBufCur - fBuffer) - UInt_t(cntpos) - sizeof(UInt_t);

// if true, pack byte count in two consecutive shorts, so it can
// be read by ReadVersion()
Expand Down
5 changes: 5 additions & 0 deletions tree/ntuple/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ ROOT_GENERATE_DICTIONARY(StreamerFieldDict ${CMAKE_CURRENT_SOURCE_DIR}/StreamerF
MODULE rfield_streamer LINKDEF StreamerFieldLinkDef.h OPTIONS -inlineInputHeader
DEPENDENCIES RIO)

ROOT_ADD_GTEST(rfield_streamer_beyond rfield_streamer_beyond.cxx StreamerBeyond.cxx LIBRARIES ROOTNTuple)
ROOT_GENERATE_DICTIONARY(StreamerBeyondDict ${CMAKE_CURRENT_SOURCE_DIR}/StreamerBeyond.hxx
MODULE rfield_streamer_beyond LINKDEF StreamerBeyondLinkDef.h OPTIONS -inlineInputHeader
DEPENDENCIES RIO)

if(MSVC)
set(command ${CMAKE_COMMAND} -E env "ROOTIGNOREPREFIX=1" $<TARGET_FILE:genreflex>)
else()
Expand Down
1 change: 1 addition & 0 deletions tree/ntuple/test/StreamerBeyond.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "StreamerBeyond.hxx"
14 changes: 14 additions & 0 deletions tree/ntuple/test/StreamerBeyond.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef ROOT_RNTuple_Test_StreamerBeyond
#define ROOT_RNTuple_Test_StreamerBeyond

#include <Rtypes.h>

#include <cstdint>
#include <vector>

struct StreamerBeyond {
std::vector<std::int64_t> fOne;
std::vector<std::int64_t> fTwo;
};

#endif
5 changes: 5 additions & 0 deletions tree/ntuple/test/StreamerBeyondLinkDef.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#ifdef __CLING__

#pragma link C++ options=rntupleStreamerMode(true) struct StreamerBeyond+;

#endif
70 changes: 70 additions & 0 deletions tree/ntuple/test/rfield_streamer_beyond.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include <ROOT/RFieldBase.hxx>
#include <ROOT/RNTupleModel.hxx>
#include <ROOT/RNTupleReader.hxx>
#include <ROOT/RNTupleWriter.hxx>

#include <cstdio>
#include <string>
#include <utility>

#include "StreamerBeyond.hxx"
#include "gtest/gtest.h"

namespace {

class FileRaii {
private:
std::string fPath;
bool fPreserveFile = false;

public:
explicit FileRaii(const std::string &path) : fPath(path) {}
FileRaii(FileRaii &&) = default;
FileRaii(const FileRaii &) = delete;
FileRaii &operator=(FileRaii &&) = default;
FileRaii &operator=(const FileRaii &) = delete;
~FileRaii()
{
if (!fPreserveFile)
std::remove(fPath.c_str());
}
std::string GetPath() const { return fPath; }

// Useful if you want to keep a test file after the test has finished running
// for debugging purposes. Should only be used locally and never pushed.
void PreserveFile() { fPreserveFile = true; }
};

} // anonymous namespace

TEST(RField, StreamerBeyond)
{
FileRaii fileGuard("test_ntuple_rfield_streamer_beyond.root");

{
auto model = ROOT::RNTupleModel::Create();
auto f = ROOT::RFieldBase::Create("f", "StreamerBeyond").Unwrap();
EXPECT_TRUE(dynamic_cast<ROOT::RStreamerField *>(f.get()));
model->AddField(std::move(f));
auto writer = ROOT::RNTupleWriter::Recreate(std::move(model), "ntpl", fileGuard.GetPath());

auto ptr = writer->GetModel().GetDefaultEntry().GetPtr<StreamerBeyond>("f");
ptr->fOne = std::vector<std::int64_t>(100000000, -1);
ptr->fTwo = std::vector<std::int64_t>(100000000, -2);

writer->Fill();
}

auto reader = ROOT::RNTupleReader::Open("ntpl", fileGuard.GetPath());
ASSERT_EQ(1u, reader->GetNEntries());
StreamerBeyond sb;
auto view = reader->GetView("f", &sb, "StreamerBeyond");

view(0);

auto ptr = view.GetValue().GetPtr<StreamerBeyond>();
EXPECT_EQ(100000000u, ptr->fOne.size());
EXPECT_EQ(-1, ptr->fOne.at(1000));
EXPECT_EQ(100000000u, ptr->fTwo.size());
EXPECT_EQ(-2, ptr->fTwo.at(2000));
}
Loading