Saving chained trees into a single .root file

Hi. Is there a simple and fast way of making a TChain chain of .root files, and then saving that chained tree into a single .root file? Right now I have what seems to be a highly inefficient way of doing it:

a) I chain up my .root files; then I open a new TFile file;
b) I then do TTree *newtree = chain->GetTree()->CloneTree(0);
c) after which I individually GetEntry() individual entries from the chain and simulaneously do newtree->Fill();
d) once this is complete I write newtree and close the file.

To do ~7mln entries it takes an hour, on a >2.5GHz core. Methinks that there gotta be a much faster way of doing the same – is there?

It is not clear why you do all this gymnastic. You can merge a set of files containing the same tree structure by doing

hadd -f result.root file1.root file2.root .. fileN.root where hadd is in $ROOTSYS/bin/hadd.
Why do you nee o loop on all entries of the chain to fill your new Tree?
What is the total size of the new Tree?


The reason I do this gymnastics is because I was ignorant of hadd’s existence – thanks for pointing it out!