Large TFile containing only small TTree

Hi all,

I use two TTree objects to write a selection of events to a TFile as follows, in an attempt to save disk space. The procedure below follows my previous question at [url]Applying a cut when filling a TTree

First I create a tree' and abufferTree’:

TTree *tree = new TTree("tree","tree name"); // definition of tree branches here TTree *bufferTree = tree->CloneTree();I add rows to `bufferTree’:

bufferTree->Fill();From time to time, I copy events satisfying some condition over to tree' and I resetbufferTree’:

TTree *tempTree = bufferTree->CopyTree(condition); tree->CopyEntries(tempTree); delete tempTree; bufferTree->Reset();Finally, I periodically AutoSave `tree’ to a TFile.

This works, in the sense that the ROOT file contains only one tree (`tree’) with the events that I have selected. However, the size of the ROOT file is practically the same as what I would get if I just wrote all my events to the file directly. That’s unfortunate, because I’m jumping through all these hoops precisely because I would like to save some disk space. How can I get a normal TFile size?

Regards,
Davide

Hi Davide,

Well, I supose it depends on your condition and the way you save the tree… I just tried with making a selection on a random tree, and it works. Selecting half the events (see snapshot below) produce a half size file…

t = gRandom->Gaus(10,5); bufferTree->Fill(); [...] TTree *tempTree = bufferTree->CopyTree("t>10.0");

Cheers, bertrand.

Hi Bertrand,

Thank you for looking at this. I have come up with a complete minimal example that illustrates my problem. On my machine (running ROOT 5.34 as packaged in Debian) the program results in a 1.9-MB ROOT file containing a tree with 127 events. If I separately generate a 127-event tree, the file size is only ~8 kB. Can you please try it?

Cheers,
Davide
test.cc (519 Bytes)

Hi,

Simply add t->SetDirectory(0); to “disconnect” the original tree from the file, or you can also do it this way (at the end of your loop): TFile *f = new TFile("test.root","RECREATE"); f->WriteObject(tc, "tc"); f->Close();
And BTW, Use either tc->Write() or f->Write() (not both)

Cheers, Bertrand.

Hi Bertrand,

Great, that works! Thank you!

Cheers,
Davide