Skip to content

Commit

Permalink
[ntuple] Forbid RNTupleParallelWriter with a non-binary TFile
Browse files Browse the repository at this point in the history
  • Loading branch information
hahnjo committed Jan 8, 2025
1 parent 11e88b7 commit 536f972
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tree/ntuple/v7/src/RNTupleParallelWriter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
#include <ROOT/RPageStorage.hxx>
#include <ROOT/RPageStorageFile.hxx>

#include <TDirectory.h>
#include <TError.h>
#include <TFile.h>

namespace {

Expand Down Expand Up @@ -168,6 +170,16 @@ std::unique_ptr<ROOT::Experimental::RNTupleParallelWriter>
ROOT::Experimental::RNTupleParallelWriter::Append(std::unique_ptr<RNTupleModel> model, std::string_view ntupleName,
TDirectory &fileOrDirectory, const RNTupleWriteOptions &options)
{
auto file = fileOrDirectory.GetFile();
if (!file) {
throw RException(
R__FAIL("RNTupleParallelWriter only supports writing to a ROOT file. Cannot write into a directory "
"that is not backed by a file"));
}
if (!file->IsBinary()) {
throw RException(R__FAIL("RNTupleParallelWriter only supports writing to a ROOT file. Cannot write into " +
std::string(file->GetName())));
}
if (!options.GetUseBufferedWrite()) {
throw RException(R__FAIL("parallel writing requires buffering"));
}
Expand Down
10 changes: 10 additions & 0 deletions tree/ntuple/v7/test/ntuple_parallel_writer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,16 @@ TEST(RNTupleParallelWriter, ForbidModelWithSubfields)
}
}

TEST(RNTupleParallelWriter, ForbidNonRootTFiles)
{
FileRaii fileGuard("test_ntuple_parallel_forbid_xml.xml");

auto model = RNTupleModel::Create();
auto file = std::unique_ptr<TFile>(TFile::Open(fileGuard.GetPath().c_str(), "RECREATE"));
// Opening an XML TFile should fail
EXPECT_THROW(RNTupleParallelWriter::Append(std::move(model), "ntpl", *file), ROOT::RException);
}

TEST(RNTupleFillContext, FlushColumns)
{
FileRaii fileGuard("test_ntuple_context_flush.root");
Expand Down

0 comments on commit 536f972

Please sign in to comment.