I am unable to properly work with a TTree written out to a file with a friend. Both ROOT and PyROOT simply crash on TFile::Close(). What am I doing wrong? I attach a PyROOT script that creates the trees, saves them then reads and attempts to close the file.
Here is a C++ code that crash. The code from eguiraud doesn’t crash here, so I guess now it should be simple - just finding the difference. test_friends.C (618 Bytes)
~TTree for t1 tries to tell t2 that it needs to remove t1 from its friends, but t2 was already deleted
The simplest fix is simply to not read t1 from file, you don’t need it (see my example). Another workaround is to delete t1 manually before calling f1.Close().
You might be able to do something similar in Python.
Indeed the manual deletion of t2 helps the C++ code. However, not reading of t1 would be a huge loss of python capabilities. When you call t2.GetEntry() its friends t1 branches are also loaded and in Python you can access them with t1.something (as you can see in my code). Without loading t1, one needs to set all the branches addresses manually and thus lose this function from python. Also, it is a big mess to read one tree with t2.something1, and other with variable something2 that was passed to t1.SetBranchAddress().
In python simply del t2 didn’t work. Maybe there is another way.