Hi,
I’ve recently started to handle larger TTrees and discovered what I believe is a stack overflow. My goal was to get the maximum and minimum values for a given expression, but I’m now concerned that code using GetV1
in other places will fail for larger trees.
Here is an example:
#include "TFile.h"
#include "TTree.h"
#include "TRandom.h"
#include <iostream>
void testTree() {
TFile *file = new TFile("test.root", "RECREATE");
TTree *t = new TTree("t", "Tree");
double value;
t->Branch("value", &value);
for (int i=0;i<5000001;i++) {
value = gRandom->Uniform();
t->Fill();
}
t->ResetBranchAddresses();
//This method works, but only for leafs, no expressions.
std::cout << "Min value: " << t->GetMinimum("value") << ", max value: " << t->GetMaximum("value") << "\n";
//This works for expressions, but is susceptible to stack overflows for large trees.
t->Draw("value","","GOFF");
auto entries = std::minmax_element(t->GetV1(), t->GetV1() + t->GetSelectedRows());
std::cout << "Min value: " << *entries.first << ", max value: " << *entries.second << "\n";
}
I see two possible solutions:
- Change GetV1() to assign memory on the heap instead of the stack. (Using
new
or astd::array
?) - For my immediate issue modify
TTree::GetMinimum
andTTree::GetMaximum
to accept expression likeDraw
orScan
. This doesn’t solve the underlying issue withGetV1
, but makesGet[Min|Max]imum
more useful.