Memory resident / File resident TTree

I read in a previous post that it matters a lot whether a TTree was created before a file has been opend or not. If a TTree was created in memory and written to the file at later times it resides completely in memory. Whereas if the file was opend before the tree was created a buffering mechanism is activated and the memory consumption is roughly 60MB no matter how much data is filled into the tree.

This behaviour is somehow glued to the tree instance. Reading the tree from the file puts it completely into memory for the first case and only chunks of data in the second case.

Is there a way to change the behaviour of this buffering of a tree instance? I want to turn on the buffering for a tree that was accidentely created before a file was opened and hence consumes a lot of memory when reading it back from a file.

Is it possible to change the buffer size? I thought it would be TTree::SetMaxVirtualSize but it seems to have no affect on the tree read from the file.

Thanks! Bernhard

You can copy your memory-resident Tree into a disk-resident Tree with the following lines of code

{ TFile f("old.root"); TTree *T = (TTree*)f.Get("T"); //specify the real Tree name TFile ff("new.root","recreate"); TTree *TC = (TTree*)T->CloneTree(); TC->Write(); }
Rene

That helps! Thanks!

The other question was whether one can manipulate the total buffer size. Is TTree:SetMaxVirtualSize the right method, or is it just the basket size of each branch?

Bernhard

I have added 2 more lines to my previous example to set the basket size for all branches of the new tree.

{ TFile f("old.root"); TTree *T = (TTree*)f.Get("T"); //specify the real Tree name TFile ff("new.root","recreate"); TTree *TC = (TTree*)T->CloneTree(0); TC->SetBasketSize("*",64000); TC->CopyEntries(T); TC->Write(); }

Rene