Array of vectors in a root Tree

I have written as array of vectors of type UShort_t in a root tree output file. I declared it as, vector<UShort_t> test[20] (it has to be type UShort_t). While trying to make the selector files from the root Tree, I have received an error which says:

Error in <AnalyzeBranch>: Unsupported type for test[20]. 

I tried to write the TTreeReader explicitly but failed to read the array. I am not sure how to handle this error. Does anyone have any suggestions? Thank you so much in advance.

ROOT Version: 24-06-6

Hi @Sbecka,

Could you please provide more details/code that describe exactly what you are doing? Myself or @pcanal might help here when you do :-).


Thanks for your responses. I am providing more concrete information with examples. I am attaching my root file where pulse was declared as a vector of vectors (or an array of vectors which I had mentioned initially, neither worked for me. If I make an array of vector, I cannot even create a selector file, so I have moved to a vectors of vector). After creating my root file (and the tree), I have generated the Selector file where I see pulse as,

TTreeReaderArray<vector<unsigned short>> detector_pulse = {fReader, "detector.pulse"};

Where detector is an object in my detector class. I have written a simple macro to create histograms for ‘pulse’. Before making any histograms, I just tried to get the size of ‘pulse’ and my code crushed.
A few things, does TTreeResder not support a vector of vector, why I am seeing it as an Array of Vectors in the TTReeReader?
How I get the size of my ‘pulse’ vector, is it just detector_pulse->size()?
test-run.root (1.2 MB)

Hi @Sbecka,

Indeed, according to TTree::Print() (see below), the type of the detector.pulse branch is std::vector<std::vector<unsigned short>>.

*Br    5 :detector.pulse : vector<vector<unsigned short> >                   *
*Entries :     7947 : Total  Size=    1539485 bytes  File Size  =    1201817 *
*Baskets :       50 : Basket Size=      32000 bytes  Compression=   1.28     *

@pcanal might correct me, but that means that you should be able to read it using a TTreeReaderValue as follows:

TTreeReader reader{"data", _file0};
TTreeReaderValue<std::vector<std::vector<unsigned short>>> detector_pulse{reader, "detector.pulse"};
while (reader.Next()) {
   // Do something with `detector_pulse`, e.g. you can access the size of the
   // outermost vector via `detector_pulse->size()`, etc.

Also, FWIW, check the examples in ROOT: TTreeReader Class Reference. Let me know whether that works for you.