Copying tree using Clonetree Method

I Have a tree with large number of events (49932086), and I want to copy it into new tree in different file.
I followed the example of Clone tree and wrot this script

//Open old File and Trees
TFile *input = new TFile(input_rootfile,“READ”);
TTree input_tree = (TTree)input->Get(“T”); //h509:name of the tree in the rootfile
Long64_t nentries = input_tree->GetEntries();

TFile *output = new TFile(output_rootfile,“RECREATE”);
TTree *tree=input_tree->CloneTree(0);

for (int i=0;i<nentries; i++) {

and I obtained one root file with two trees with names T,1 (3372395 entries) and T,2 (49932086 entries).
this was unexpected.

I start to change the filling of for loop (nentries), and choose 100, 1000, 10000. …etc ( for (int i=0;i<100; i++)), and it works fine one root file with the chosen number of entries up to 3372396 entries, root stopped filling in the first tree and create new tree and start filling in T,2.

any explanation and how can I avoid this please

Many Thanks for reply,
I understood that there is indirect call to AutoSave, and in order to avoid this I need to write the last cycle of the tree
I replace
tree->Write(); by tree->Write(0,TObject::kOverwrite);

it works :slight_smile:, thank you

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.