Skip to content

Commit

Permalink
[DF] Fix snapshot of array branch with out-of-order size branch
Browse files Browse the repository at this point in the history
This commit fixes root-project#10920 and root-project#6932.
  • Loading branch information
eguiraud authored and j-mathe committed Jul 26, 2022
1 parent d2a9d0c commit e1447d2
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions tree/dataframe/inc/ROOT/RDF/ActionHelpers.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -1422,8 +1422,16 @@ void SetBranchesHelper(TTree *inputTree, TTree &outputTree, const std::string &i
// must construct the leaflist for the output branch and create the branch in the output tree
auto *const leaf = static_cast<TLeaf *>(inputBranch->GetListOfLeaves()->UncheckedAt(0));
const auto bname = leaf->GetName();
const auto counterStr =
leaf->GetLeafCount() ? std::string(leaf->GetLeafCount()->GetName()) : std::to_string(leaf->GetLenStatic());
auto *sizeLeaf = leaf->GetLeafCount();
const auto sizeLeafName = sizeLeaf ? std::string(sizeLeaf->GetName()) : std::to_string(leaf->GetLenStatic());
if (sizeLeaf && !outputBranches.Get(sizeLeafName)) { // we need a size branch but it's not there yet
const auto sizeTypeStr = TypeName2ROOTTypeName(sizeLeaf->GetTypeName());
const auto sizeBufSize = sizeLeaf->GetBranch()->GetBasketSize();
// the null address will be reset later when we call SetBranchesHelper for this branch
auto *sizeBranch = outputTree.Branch(sizeLeafName.c_str(), (void *)nullptr,
(sizeLeafName + '/' + sizeTypeStr).c_str(), sizeBufSize);
outputBranches.Insert(sizeLeafName, sizeBranch);
}
const auto btype = leaf->GetTypeName();
const auto rootbtype = TypeName2ROOTTypeName(btype);
if (rootbtype == ' ') {
Expand All @@ -1432,7 +1440,7 @@ void SetBranchesHelper(TTree *inputTree, TTree &outputTree, const std::string &i
"column will not be written out.",
bname);
} else {
const auto leaflist = std::string(bname) + "[" + counterStr + "]/" + rootbtype;
const auto leaflist = std::string(bname) + "[" + sizeLeafName + "]/" + rootbtype;
outputBranch = outputTree.Branch(outName.c_str(), dataPtr, leaflist.c_str());
outputBranch->SetTitle(inputBranch->GetTitle());
outputBranches.Insert(outName, outputBranch);
Expand Down

0 comments on commit e1447d2

Please sign in to comment.