Skip to content

Commit

Permalink
[DF][RDatasetSpec] Error out when fEnd > fBegin > NumEntries (in non-…
Browse files Browse the repository at this point in the history
…chains)
  • Loading branch information
ikabadzhov committed May 16, 2022
1 parent 2629171 commit 9f71619
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
3 changes: 2 additions & 1 deletion tree/dataframe/src/RLoopManager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,8 @@ void RLoopManager::RunTreeReader()

TTreeReader r(fTree.get(), fTree->GetEntryList());

r.SetEntriesRange(fStartEntry, fEndEntry);
if (r.SetEntriesRange(fStartEntry, fEndEntry)) // returning > 0 indicates invalid fStartEntry
throw std::runtime_error("RLoopManager: fStartEntry cannot be larger than the number of entries.");

if (0 == fTree->GetEntriesFast())
return;
Expand Down
33 changes: 20 additions & 13 deletions tree/dataframe/test/dataframe_datasetspec.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,16 @@ TEST(RDFDatasetSpec, SingleFileSingleColConstructor)
},
std::logic_error);

// specify range [5, 6) (neither is a valid index, but 5 < 6) => despite the ROOT error, assignment is made
// disregarding the range
auto dfRDS10 = RDataFrame(RDatasetSpec("tree", "file.root", {5, 6})).Display<int>({"x"});
std::string dfRDS10AsString;
ROOT_EXPECT_ERROR(dfRDS10AsString = dfRDS10->AsString(), "TTreeReader::SetEntriesRange()",
"first entry out of range 0..5");
EXPECT_EQ(dfRDS10AsString, dfSimple);
// specify range [5, 6) (neither is a valid index, but 5 < 6) => error out
auto h = RDataFrame(RDatasetSpec("tree", "file.root", {5, 6})).Display<int>({"x"});
EXPECT_THROW(
try {
ROOT_EXPECT_ERROR(h->AsString(), "TTreeReader::SetEntriesRange()", "first entry out of range 0..5");
} catch (const std::runtime_error &err) {
EXPECT_EQ(std::string(err.what()), "RLoopManager: fStartEntry cannot be larger than the number of entries.");
throw;
},
std::runtime_error);

// test the second constructor, second argument is now a vector
const auto dfRDS13 = RDataFrame(RDatasetSpec("tree", {"file.root"s})).Display<int>({"x"})->AsString();
Expand Down Expand Up @@ -132,12 +135,16 @@ TEST(RDFDatasetSpec, SingleFileMultiColsConstructor)
const auto dfRDS4 = RDataFrame(RDatasetSpec("tree", "file.root", {2, 4})).Display()->AsString();
EXPECT_EQ(dfRDS4, dfRange0);

// specify irregular range [5, 6) (similar to above)
auto dfRDS8 = RDataFrame(RDatasetSpec("tree", "file.root", {5, 6})).Display();
std::string dfRDS8AsString;
ROOT_EXPECT_ERROR(dfRDS8AsString = dfRDS8->AsString(), "TTreeReader::SetEntriesRange()",
"first entry out of range 0..5");
EXPECT_EQ(dfRDS8AsString, dfSimple);
// specify range [5, 6) (neither is a valid index, but 5 < 6) => error out
auto h = RDataFrame(RDatasetSpec("tree", "file.root", {5, 6})).Display<int>({"x"});
EXPECT_THROW(
try {
ROOT_EXPECT_ERROR(h->AsString(), "TTreeReader::SetEntriesRange()", "first entry out of range 0..5");
} catch (const std::runtime_error &err) {
EXPECT_EQ(std::string(err.what()), "RLoopManager: fStartEntry cannot be larger than the number of entries.");
throw;
},
std::runtime_error);

// specify irrelgular ranges (similar to above): [2, 2), [7, 7), [2, 6), [2, 0), [9, 7), [9, 2)
const auto dfRDS9 = RDataFrame(RDatasetSpec("tree", "file.root", {2, 2})).Display()->AsString();
Expand Down

0 comments on commit 9f71619

Please sign in to comment.