TTree->AutoSave()

Root 3.05

I need to store a BIG NTuple
I am trying to call AutoSave every 100 events or so.
I wrote a little method in my class which opens file for "UPDATE"
Flashes TTree with AutoSave() and closes the File.

The file ends up being empty.

void MyClass::AutoSave(){
TFile f(_myFile, “UPDATE”);
_myTTree -> AutoSave();
//Just to check that tree is not empty.
_myTTree ->Print();
f.Close();
}

If I exchange ->AutoSave() with ->Write() (just to check) it works
perfectly. I have many small Trees in my file. :slight_smile:

The manual is quite brief about it. Please help.

Thanks.

Hi,

With the alogorithm you propose, calling Write is the correct call.
You can read more about AutoSave at root.cern.ch/root/html/TTree.html#TTree:AutoSave
In particular it only works if the TTree is attached to the file (this is NOT your case … but could be if you add a call to SetDirectory).

On the other hand, is there a reason why you keep opening and closing the file? In most case, it is more efficient and sufficient to open the file at the start of the session, create the tree after opening the file (or attaching the tree to the file), and calling AutoSave at regular intervals. (See above links for simple examples).

And actually you Tree really contains a large amount of data, your algorithm will eventually fail due to memory exhaustion (unless you add a TTree::Reset after closing the file).

Cheers,
Philippe.