Skip to content

Commit

Permalink
[DF] Prefer GetEntriesUnsafe when we know there are no races
Browse files Browse the repository at this point in the history
  • Loading branch information
eguiraud committed Jun 4, 2021
1 parent 248782a commit c9e9c82
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion tree/dataframe/src/RDFUtils.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ std::string GetBranchOrLeafTypeName(TTree &t, const std::string &colName)
}
return be->GetClassName();
}
} else if (branch->IsA() == TBranch::Class() && branch->GetListOfLeaves()->GetEntries() == 1) {
} else if (branch->IsA() == TBranch::Class() && branch->GetListOfLeaves()->GetEntriesUnsafe() == 1) {
// normal branch (not a TBranchElement): if it has only one leaf, we pick the type of the leaf:
// RDF and TTreeReader allow referring to branch.leaf as just branch if branch has only one leaf
leaf = static_cast<TLeaf *>(branch->GetListOfLeaves()->UncheckedAt(0));
Expand Down
2 changes: 1 addition & 1 deletion tree/dataframe/src/RLoopManager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ static void GetBranchNamesImpl(TTree &t, std::set<std::string> &bNamesReg, Colum
if (branch->IsA() == TBranch::Class()) {
// Leaf list
auto listOfLeaves = branch->GetListOfLeaves();
if (listOfLeaves->GetEntries() == 1) {
if (listOfLeaves->GetEntriesUnsafe() == 1) {
auto leaf = static_cast<TLeaf *>(listOfLeaves->UncheckedAt(0));
UpdateList(bNamesReg, bNames, branchName, friendName, foundLeaves, leaf, allowDuplicates);
}
Expand Down
2 changes: 1 addition & 1 deletion tree/dataframe/src/RRootDS.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ RRootDS::RRootDS(std::string_view treeName, std::string_view fileNameGlob)
fModelChain.Add(fFileNameGlob.c_str());

const TObjArray &lob = *fModelChain.GetListOfBranches();
fListOfBranches.resize(lob.GetEntries());
fListOfBranches.resize(lob.GetEntriesUnsafe());

TIterCategory<TObjArray> iter(&lob);
std::transform(iter.Begin(), iter.End(), fListOfBranches.begin(), [](TObject *o) { return o->GetName(); });
Expand Down
2 changes: 1 addition & 1 deletion tree/dataframe/test/datasource_more.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ TEST(RArraysDS, SnapshotAndShortSyntaxForCollectionSizes)
TFile f(fname);
auto *t = f.Get<TTree>("t");
auto *blist = t->GetListOfBranches();
EXPECT_EQ(blist->GetEntries(), 1u);
EXPECT_EQ(blist->GetEntriesUnsafe(), 1u);
EXPECT_STREQ(blist->At(0)->GetName(), "var");
f.Close(); // Windows does not allow deletion/recreation of files that are still in use.

Expand Down

0 comments on commit c9e9c82

Please sign in to comment.