Skip to content
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
17 changes: 8 additions & 9 deletions tree/dataframe/src/RTTreeDS.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -399,15 +399,14 @@ void ROOT::Internal::RDF::RTTreeDS::Finalize()

void ROOT::Internal::RDF::RTTreeDS::Initialize()
{
if (fNSlots == 1) {
assert(!fTreeReader);
fTreeReader = std::make_unique<TTreeReader>(fTree.get(), fTree->GetEntryList(), /*warnAboutLongerFriends*/ true);
if (fGlobalEntryRange.has_value() && fGlobalEntryRange->first <= std::numeric_limits<Long64_t>::max() &&
fGlobalEntryRange->second <= std::numeric_limits<Long64_t>::max() && fTreeReader &&
fTreeReader->SetEntriesRange(fGlobalEntryRange->first, fGlobalEntryRange->second) !=
TTreeReader::kEntryValid) {
throw std::logic_error("Something went wrong in initializing the TTreeReader.");
}
if (ROOT::IsImplicitMTEnabled())
return;
assert(!fTreeReader);
fTreeReader = std::make_unique<TTreeReader>(fTree.get(), fTree->GetEntryList(), /*warnAboutLongerFriends*/ true);
if (fGlobalEntryRange.has_value() && fGlobalEntryRange->first <= std::numeric_limits<Long64_t>::max() &&
fGlobalEntryRange->second <= std::numeric_limits<Long64_t>::max() && fTreeReader &&
fTreeReader->SetEntriesRange(fGlobalEntryRange->first, fGlobalEntryRange->second) != TTreeReader::kEntryValid) {
throw std::logic_error("Something went wrong in initializing the TTreeReader.");
}
}

Expand Down
44 changes: 44 additions & 0 deletions tree/dataframe/test/datasource_tree.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,47 @@ TEST(RTTreeDS, BranchWithNestedSameName)

expect_vec_eq(branchNames, expectedBranchNames);
}

#ifdef R__USE_IMT
struct Dataset20164RAIII {
const char *fTreeName{"tree_20164"};
const char *fFileName{"tree_20164.root"};

Dataset20164RAIII()
{
std::unique_ptr<TFile> ofile{TFile::Open(fFileName, "recreate")};

std::unique_ptr<TTree> myTree = std::make_unique<TTree>(fTreeName, fTreeName);

int v1{42};

myTree->Branch("v1", &v1);
myTree->Fill();
ofile->Write();

// It's important to use 1 as the logic in RTTreeDS was faulty only for the case fNSlots==1
ROOT::EnableImplicitMT(1);
}

~Dataset20164RAIII()
{
ROOT::DisableImplicitMT();
std::remove(fFileName);
}
};

TEST(RTTreeDS, Regression20164)
{
// Test that TTree thread tasks coherently use the TTreeReader created for the specific task and do not access
// a TTreeReader from the RTTreeDS.
Dataset20164RAIII dataset{};

auto chain = std::make_unique<TChain>(dataset.fTreeName);
chain->Add(dataset.fFileName);

auto val = ROOT::RDataFrame(*chain).Sum<int>("v1").GetValue();

ASSERT_EQ(val, 42);
}

#endif
Loading