I have a TTree filled with 2D vectors (ie. std::vector<std::vector>) for which a dictionary was generated using genreflex. The first component of the 2D vector is fixed-sized, the second ones are variable.
With TTree:Draw(), it is easy to plot the size of the first component of the 2D vector: Draw("@v.size()","","").
However, I do not manage to get the size of the second component-vector, for a particular entry in the first component (which in my case is always defined):
Draw("@v[0].size()","","") gives the same as above (ie not what one would expect)
Draw("@(v[0]).size()","","") doesn’t work
Draw(“v[0].size()”,"","") doesn’t work either
Draw(“Length$(v[0][])”,"","") always returns 1. Trying Draw(“Iteration$:v[0][]”,"",“colz”) confirms that the second index is not looped over… Is that expected?
Is there a way around this? Otherwise I’ll resort to storing a vector containing the sizes of these second components, but this is obviously inefficient…
[quote]Draw(“Iteration$:v[0][]”,"",“colz”) confirms that the second index is not looped over… Is that expected?[/quote]No … and I can not reproduce this problem.
[quote]Draw(“Length$(v[0][])”,"","") always returns 1. [/quote]I can not reproduce this problem either and actually in my example, it seems to be the answer to your original question. With:{
vector<vector<double>> v;
v.push_back({1,2,3,4});
v.push_back({10,11});
TTree *t = new TTree("t","for vec");
t->Branch("vec",&v);
t->Fill();
v.clear();
v.push_back({1,2,3,4,5,6});
v.push_back({10,11,12,13,14});
t->Fill();
t->Scan("Length$(vec[0][])");
t->Scan("Length$(vec[1][])");
auto c = new TCanvas("c1");
c->Divide(2);
c->cd(1);
t->Draw("Length$(vec[0][])");
c->cd(2);
t->Draw("Iteration$:vec[0][]","","colz");
}
I get [code]************************
Row * Length$(v *
0 * 4 *
1 * 6 *
Row * Length$(v *
0 * 2 *
1 * 5 *
************************[/code]
and the attached picture.
After taking a closer look I found out there was an issue with the vectors written to my tree… So it’s good to see confirmed that the Length$() syntax works for this!