TObject error when drawing branch of vector of vectors


during checking the TTree output of a program of mine, I encountered an error which I have already described in a [url= thread[/url] (point 3; up to now I had been lacking further information about the error).

The issue is as follows:

When calling TTree::Draw() in order to draw the content of a vector of vectors (“2D vector”), like

I get the following error message multiple times in a row if the vector (in this case: vec[0]) is empty for some of the events to be drawn:

The frequency of the error message seems to depend on the number of events for which the vector within the vector of vectors is empty. When cutting on events where the vector contains at least one entry or when changing the program output to fill in a dummy value into the vector if it is empty, the error message does not appear.
Interestingly, no error message appears for empty “1D” vectors. To clarify:

vector<int> vec1d; // does not generate error when being empty and saved into // TTree branch vector<vector<int>> vec2d; // generates error when saved into TTree branch and one of // the vector<int> objects within the outer vector is empty
I have already checked if my program attempts to store a vector at NULL at some point, but this is not the case (pointer to vector always points at valid vector and TTree object gets deleted by closing the TFile it is contained within before the branch variables go out of scope).

Is this “working as expected”, or is there some “proper” way of dealing with empty vectors within a vector of vectors besides using dummy values?

OS: Linux Mint 17.1
Kernel: 3.13.0-37
g++ version: 4.8.2
ROOT version: 6.03/03 (error also appeared with 5.34)




Indeed, this should have worked without error message. Can you send me a ROOT file showing the problem?


Hi Philippe,

I’ve attached a file containing an example tree which shows the problematic behavior described above.

Tree name:

[li] “vec” - “2D” vector (vector<vector<ULong64_t>>) containing 8 subvectors, i.e. the first index is guaranteed to go from 0 to 7. The range of the second index depends on the subvector content.[/li]
[li] “subVecEntries” - “1D” vector (vector<ULong64_t>) containing the number of entries for each subvector.
To illustrate:

entries[2] == 4 --> vec[2].size() == 4


subvec_tree.root (255 KB)