Skip to content

Commit

Permalink
[tree] Avoid rebuilding the TChainIndex in every MT task
Browse files Browse the repository at this point in the history
Currently, in the creation of the friends to attach to the main chain to be
processed in a MT task, if a friend was attached to a TVirtualIndex-derived
instance, this needs to be rebuilt. Evidence in the past showed that just
cloning was not enough because the cloned index could not appropriately probe
the task-local friend chain afterwards due to a misconfigured connection with
the branches. A call to `LoadTree(0)` before connecting the chain to the cloned
index makes sure that the dataset schema is loaded and the probing can happen
succesfully. In turn, this optimizes the task creation by avoiding the rebuilding
of the chain index for every task.
  • Loading branch information
vepadulano committed Dec 18, 2024
1 parent efb5dd3 commit 3cf572a
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions tree/tree/src/InternalTreeUtils.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -398,13 +398,14 @@ std::vector<std::unique_ptr<TChain>> MakeFriends(const ROOT::TreeUtils::RFriendI

const auto &treeIndex = finfo.fTreeIndexInfos[i];
if (treeIndex) {
// The call to TChain::BuildIndex does much more than just copying
// the indices that may have been already present in the trees of the
// chain. Notably, it calls `LoadTree` for every tree in the chain
// making sure that all branches, indices and relationships are
// properly set. In order to avoid unexpected behaviours, we always
// let the task-local friend chain rebuild its index.
frChain->BuildIndex(treeIndex->GetMajorName(), treeIndex->GetMinorName());
// The call to LoadTree is necessary to make sure that the schema is
// properly loaded and all branches are correctly connected with the
// friend chain. Not doing so would result in the index not being able
// to probe the friend chain afterwards.
frChain->LoadTree(0);
auto *copyOfIndex = static_cast<TVirtualIndex *>(treeIndex->Clone());
copyOfIndex->SetTree(frChain.get());
frChain->SetTreeIndex(copyOfIndex);
}

friends.emplace_back(std::move(frChain));
Expand Down

0 comments on commit 3cf572a

Please sign in to comment.