Dear ROOT experts,
I am trying to add to a TChain a friend TTree, then pass this to a RDataFrame where I want to have access to the branches of both objects.
The TChain contains two TTrees from two root files created from a RDataFrame with EnableImplicitMT
, and so, when I add the friend tree, I get
Error in <AddFriend>: Tree 't' has the kEntriesReshuffled bit set, and cannot be used as friend
nor can be added as a friend unless the main tree has a TTreeIndex on the friend tree 't_friend'.
You can also unset the bit manually if you know what you are doing.
As I know what I am doing, I tried unsetting the bit manually as in the minimal example attached bellow, and it didn’t work. The code bellow returns error because the column y
doesn’t of course exist in the RDataFrame.
Is there a way to do this? I have checked several posts similar to this (specially this one but I can’t find a solution to my problem).
import ROOT
# -- Save several TTrees with ImplicitMT
ROOT.EnableImplicitMT(2)
ROOT.RDataFrame(5).Define("x", "42").Snapshot("t", "f1.root")
ROOT.RDataFrame(5).Define("x", "52").Snapshot("t", "f2.root")
ROOT.DisableImplicitMT()
chain = ROOT.TChain("t")
chain.Add("f1.root")
chain.Add("f2.root")
# Load first entry to initialize internal structures
chain.GetEntry(0)
# Now loop over all trees in the chain
n_trees = chain.GetNtrees() # total number of files added
for i in range(n_trees):
chain.LoadTree(chain.GetTreeOffset()[i]) # load first entry of this tree
tree = chain.GetTree() # get current TTree from the file
tree.ResetBit( ROOT.TTree.EStatusBits.kEntriesReshuffled )
ROOT.RDataFrame(10).Define("y", "43").Snapshot("t_friend", "f_friend.root")
f2 = ROOT.TFile("f_friend.root")
t2 = f2.Get("t_friend")
t2.ResetBit(ROOT.TTree.EStatusBits.kEntriesReshuffled)
chain.AddFriend(t2)
f2.Close()
rdf = ROOT.RDataFrame(chain)
rdf.Display(["x","y"],10).Print()
ROOT Version: 6.28/04