I’m writing a data monitoring program which should process data files, fill the branches of a TTree with a set of monitoring variables, plot some of these variables according to user’s input from a GUI and then save the tree on a Root file for later use. I thought about implementing this sequence:
[ol]
[li]create branches[/li]
[li]loop over all events and fill branches[/li]
[li]wait for the user to define which variable to plot, possibly with selection criteria, and then call TTree::Draw[/li]
[li]eventually repeat step 3 for other variables[/li]
[li]write the tree on file if the user asks to[/li][/ol]
I have some concerns about this workflow:
[ul]
[li]what happens if during the loop in step 2 the size of the tree exceeds fMaxVirtualSize? There is still no Root file opened, so I’d guess that branches cannot be flushed to disk…[/li]
[li]if I swap steps 5 and 3 (e.g. save the tree on file before drawing anything) then only the last Fill value is plotted: for example, if I fill a branch 100 times and the last fill value is 10, then after writing the tree on the file TTree::Draw gives a histogram with 100 entries all with value 10 (mean 10, RMS 0). I think that this may have something to do with the flushing of baskets. Do I have to re-read the TTree from the file at this point, before drawing anything??[/li][/ul]
Maybe my workflow and the objects I use are not the best for achieving my goal (a monitoring program with the ability to do plots on the fly with selection criteria, like a TTree does, and which can save the monitoring data for later use). Any help/suggestion on the above topics is welcome. Thanks.
[quote=“couet”]When you open a tree a file, linked to that tree, should be open if you want to avoid any memory size problem.
[/quote]
Understood, thank you.
[quote=“couet”]
you mean you see only the last event ?[/quote]
I mean that calling TTree::Draw I get a histogram with 100 entries (correct) but every entry seems to be equal to the value used for the last call of TTree::Fill, since the histogram has mean equal to that value and RMS = 0.
After writing the tree on the file Scan returns wrong values (in this case it is always the first fill value, not exactly what I reported in my original post but nevertheless a wrong behaviour). Am I doing something wrong or is this a bug?
Thanks.
I am not sure I understand your description. I finished your routine by adding 'file->Write();'
then exited and executed:[code]$ root.exe -b -l test.root
root [0]
Attaching file test.root as _file0…
(class TFile *) 0x7fadd295f7e0
root [1] aTree->Scan()
Row * aBranch *
0 * 1 *
1 * 2 *
2 * 3 *
3 * 4 *
4 * 5 *
5 * 6 *
6 * 7 *
7 * 8 *
8 * 9 *
9 * 10 *
(Long64_t) 10
[/code]which seems fine to me. What are you doing/seeing differently?
Hi Philippe, what I want to do is to fill a TTree, save it to disk and then keep it in memory to let the user draw some histograms. My simple test script just shows that Scan prints different things before and after the call to TTree::Write, and also histograms drawn with TTree::Draw are different when drawn before or after TTree::Write.
Thank you Philippe, your solution works. I had to tweak it a bit because t1->SetBranchAddress(“aBranch”,0) gives me this error:
so I used:
t1->ResetBranchAddress(t1->GetBranch("aBranch"));
right after t1->Write. This makes my small example work.
However, the data monitoring program where the bug showed up the first time still did not work after implementing the fix. I noticed that accessing the variables of the TTree just after resetting the addresses (for example with Scan or Draw) somehow fixed the residual problem. So I put GetEntry(0) just after ResetBranchAddress and this magically fixed everything. I don’t have any idea about why it works, and I have not been able to reproduce this in the example, but now it works so I can move on.
Thanks again!