I have a TTree, which I fill with data, which I read in pieces from an other source. After each piece, I want to save the tree to a file, so I do:
TFile *fntp = new TFile("frames_tree.root", "RECREATE");
stars_tree->Write();
fntp->Close();
The problem is, that this works properly only if I do it once, for example after reading all the pieces and finishing the task. If I do it more than once, I got mess in my TTree. Is it a normal behaviour?
It’s working better in this sample than in my real case, but still bad. The attached file is the wrong case by default - although tframe should change from 1800 to 1802, it is 1802 for all entries. When you save the tree only after both loops (the commented out part), it is saved properly - all 3 values of “tframe”.
In my real case, which is difficult to reproduce, sometimes there are also values of tframe that seem to be random and I cannot scan/draw other variables - root gives some strange errors with includes. tt.C (849 Bytes)
I guess the main thing was the “disconnect” thing - is it documented anywhere? For sure it workded for me that way with ntuple.
However, I have some questions:
Is it important to open file before filling the tree?
I wrote all the iterations to the same file by intent - when filling a tree takes long time, I like to have intermediate results stored on HD. Is there any simpler way to “flush” contents of TTree to disk?
[quote]Is it important to open file before filling the tree?
[/quote]
If you create the Tree before creating the file, you have to tell the Tree later on that you want to have the tree buffers written to the file (SetDirectory call)
[quote]I wrote all the iterations to the same file by intent - when filling a tree takes long time, I like to have intermediate results stored on HD. Is there any simpler way to “flush” contents of TTree to disk?
[/quote]
see TTree::AutoSave