# Array of vectors in a root Tree

**URL:** <https://root-forum.cern.ch/t/array-of-vectors-in-a-root-tree/54041>\
**Category:** Newbie\
**Tags:** tree\
**Created:** [March 15, 2023, 6:10am UTC](https://root-forum.cern.ch/t/array-of-vectors-in-a-root-tree/54041 "2023-03-15T06:10:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sbecka](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/7c8e57/32.png) [@Sbecka](https://root-forum.cern.ch/u/Sbecka)\
**Post date:** [March 15, 2023, 6:10am UTC](https://root-forum.cern.ch/t/array-of-vectors-in-a-root-tree/54041/1 "2023-03-15T06:10:36Z")

</div>

Hello,  
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:

```auto
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

---

<div class="post-metadata">

**Author:** ![jalopezg](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jalopezg/32/25844_2.png) [@jalopezg](https://root-forum.cern.ch/u/jalopezg)\
**Post date:** [March 15, 2023, 11:30pm UTC](https://root-forum.cern.ch/t/array-of-vectors-in-a-root-tree/54041/2 "2023-03-15T23:30:13Z")

</div>

Hi @Sbecka,

> [@Sbecka](#):
>
> 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.

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

Cheers,  
J.

---

<div class="post-metadata">

**Author:** ![Sbecka](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/7c8e57/32.png) [@Sbecka](https://root-forum.cern.ch/u/Sbecka)\
**Post date:** [March 20, 2023, 1:05pm UTC](https://root-forum.cern.ch/t/array-of-vectors-in-a-root-tree/54041/4 "2023-03-20T13:05:08Z")

</div>

Hello,  
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,

```auto
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](https://root-forum.cern.ch/uploads/short-url/uILU4vszoreAmcg3IFtUbU1IgUi.root) (1.2 MB)

---

<div class="post-metadata">

**Author:** ![jalopezg](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jalopezg/32/25844_2.png) [@jalopezg](https://root-forum.cern.ch/u/jalopezg)\
**Post date:** [March 25, 2023, 2:47am UTC](https://root-forum.cern.ch/t/array-of-vectors-in-a-root-tree/54041/5 "2023-03-25T02:47:47Z")

</div>

Hi @Sbecka,

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

```c++
*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 *
[...]

```

> [@Sbecka](#):
>
> 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?

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

```c++
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](https://root.cern.ch/doc/master/classTTreeReader.html). Let me know whether that works for you.

Cheers,  
J.
