In ROOT 6, what is the canonical way to read a TTree from a TFile and write it entirely to another TFile? Using TTree() or TTreeReader() functionality?
The simplest way is to use the rootcp utility.
From C++, you would use the TTree::CloneTree method.
Thanks for the help.
I don’t know what rootcp is and don’t know how to use/find it.
I tried this in C++:
TFile* rootfile_in = new TFile("in.root", "READ");
TFile* rootfile_out = new TFile("out.root", "RECREATE");
TTree* roottree_in = (TTree*)rootfile_in->Get("tree");
TTree* roottree_out = roottree_in->CloneTree(0);
Works fine. When I try it in Python:
rootfile_in = TFile('in.root', 'READ')
rootfile_out = TFile('out.root', 'RECREATE')
roottree_in = rootfile_in.Get('tree')
roottree_out = roottree_in.CloneTree(0)
I get two TTrees in the output file, one properly filled (cycle 3), the other one only half filled (cycle 2). It works with small trees, but for large TTrees (~ 40000 events), I see this behavior. What am I doing wrong?
rootcp is a utility that we provide as part of the latest releases (v6.06).
Nothing. This is the expected behavior (See the User’s guide for more details), the ‘cycle 2’ is a backup snapshot of the TTree meta-data to reduce the risk of data loss (in case the program filling the tree unexpectedly terminate) [It does not take much of space on the file]
just to put a reference to the new root commandline utils (which include rootcp): root.cern.ch/how/how-quickly-in … ntent-file
In any case, it is just enough to type “rootcp” once ROOT is installed, at least version 6.06.
Thank you very much. All this information is very helpful.
I tried just typing rootcp, but my ROOT installation was apparently not fresh enough.