Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ntuple] Merger: don't abort if a file doesn't contain a RNTuple #17609

Merged
merged 1 commit into from
Feb 7, 2025
Merged
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
5 changes: 2 additions & 3 deletions tree/ntuple/v7/src/RNTupleMerger.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,8 @@ try {
TFile *inFile = dynamic_cast<TFile *>(pitr);
ROOT::RNTuple *anchor = inFile ? inFile->Get<ROOT::RNTuple>(ntupleName.c_str()) : nullptr;
if (!anchor) {
Error("RNTuple::Merge", "Failed to retrieve RNTuple anchor named '%s' from file '%s'", ntupleName.c_str(),
inFile->GetName());
return -1;
Info("RNTuple::Merge", "No RNTuple anchor named '%s' from file '%s'", ntupleName.c_str(), inFile->GetName());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the record, I don't think we issue any message for the similar situation for TTree.

continue;
}

auto source = RPageSourceFile::CreateFromAnchor(*anchor);
Expand Down
2 changes: 1 addition & 1 deletion tree/ntuple/v7/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ if(NOT MSVC)
ROOT_ADD_GTEST(ntuple_emulated ntuple_emulated.cxx LIBRARIES ROOTNTuple)
endif()
ROOT_ADD_GTEST(ntuple_index ntuple_index.cxx LIBRARIES ROOTNTuple)
ROOT_ADD_GTEST(ntuple_merger ntuple_merger.cxx LIBRARIES ROOTNTuple CustomStruct ZLIB::ZLIB)
ROOT_ADD_GTEST(ntuple_merger ntuple_merger.cxx LIBRARIES ROOTNTuple CustomStruct ZLIB::ZLIB Tree INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/tree/tree/inc)
ROOT_ADD_GTEST(ntuple_metrics ntuple_metrics.cxx LIBRARIES ROOTNTuple CustomStruct)
ROOT_ADD_GTEST(ntuple_model ntuple_model.cxx LIBRARIES ROOTNTuple CustomStruct)
ROOT_ADD_GTEST(ntuple_multi_column ntuple_multi_column.cxx LIBRARIES ROOTNTuple)
Expand Down
41 changes: 41 additions & 0 deletions tree/ntuple/v7/test/ntuple_merger.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <unordered_map>
#include <zlib.h>
#include "gmock/gmock.h"
#include <TTree.h>

using ROOT::TestSupport::CheckDiagsRAII;

Expand Down Expand Up @@ -1603,3 +1604,43 @@ TEST(RNTupleMerger, MergeAsymmetric1TFileMerger)
}
}
}

TEST(RNTupleMerger, SkipMissing)
{
// Try merging various files, some containing RNTuples and some not; verify that we ignore the ones that don't.
std::vector<FileRaii> fileGuards;
for (int i = 0; i < 6; ++i) {
auto &fileGuard =
fileGuards.emplace_back(std::string("test_ntuple_merge_skipmissing_") + std::to_string(i) + ".root");

auto file = std::unique_ptr<TFile>(TFile::Open(fileGuard.GetPath().c_str(), "RECREATE"));
if (i % 2) {
auto model = RNTupleModel::Create();
auto p = model->MakeField<std::string>("s");
auto writer = RNTupleWriter::Append(std::move(model), "ntpl", *file);
for (int j = 0; j < 10; ++j) {
*p = std::to_string(j + i);
writer->Fill();
}
} else {
auto tree = std::make_unique<TTree>("tree", "tree");
std::string s;
tree->Branch("s", &s);
for (int j = 0; j < 10; ++j) {
s = std::to_string(j + i);
tree->Fill();
}
tree->Write();
}
}

FileRaii fileOut("test_ntuple_merge_skipmissing_out.root");
TFileMerger merger;
merger.OutputFile(fileOut.GetPath().c_str());
for (const auto &file : fileGuards) {
merger.AddFile(file.GetPath().c_str());
}

bool ok = merger.PartialMerge();
EXPECT_TRUE(ok);
}
2 changes: 2 additions & 0 deletions tree/ntuple/v7/test/ntuple_test.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ private:

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()
{
Expand Down
Loading