# Reading TTree branch: vector of vectors

**URL:** <https://root-forum.cern.ch/t/reading-ttree-branch-vector-of-vectors/63013>\
**Category:** Newbie\
**Created:** [February 24, 2025, 12:51pm UTC](https://root-forum.cern.ch/t/reading-ttree-branch-vector-of-vectors/63013 "2025-02-24T12:51:35Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![cej25](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/90db22/32.png) [@cej25](https://root-forum.cern.ch/u/cej25)\
**Post date:** [February 24, 2025, 12:51pm UTC](https://root-forum.cern.ch/t/reading-ttree-branch-vector-of-vectors/63013/1 "2025-02-24T12:51:36Z")

</div>

Hello,

I have a TTree with the following branches:

HitData.wr\_t – Long64\_t  
HitData.trace – std::vector\<Float\_t\>

“wr\_t” and “trace” are members of my own class, HitData, but I want to assume someone can read this tree without need of my software.  
On an event-by-event analysis, for every event, there is actually a vector of this HitData class item.

I can access wr\_t with: TTreeReaderArray\<Long64\_t\> wr(reader, “HitData.wr\_t”);

I try to access trace with: TTreeReaderArray\<std::vector\<Float\_t\>\> trace(reader, “HitData.trace”);

When looping through the tree, if I print trace.GetSize(); this returns the correct value - the number of HitData items in the event. If I print trace[i].size(), this size is completely incorrect. It seems as if a completely random (large) value is printed.

Am I doing something incorrectly?

To be clear - if I source my software, then I can use TTreeReaderArray hit(reader, “HitData”); and then loop through “hit” on each event, and make use of the Getter methods in my software. But I don’t want to assume that someone will source this software.

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [February 24, 2025, 1:05pm UTC](https://root-forum.cern.ch/t/reading-ttree-branch-vector-of-vectors/63013/2 "2025-02-24T13:05:35Z")

</div>

[TFile::MakeProject](https://root.cern/doc/master/classTFile.html#a5fdd58dba517dd7b70b43332295e529d)

---

<div class="post-metadata">

**Author:** ![cej25](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/90db22/32.png) [@cej25](https://root-forum.cern.ch/u/cej25)\
**Post date:** [February 24, 2025, 1:59pm UTC](https://root-forum.cern.ch/t/reading-ttree-branch-vector-of-vectors/63013/3 "2025-02-24T13:59:00Z")

</div>

Hm, I tried to make use of this…

void mp()  
{  
TFile\* f = TFile::Open(“run.root”);  
f-\>MakeProject(“traces”, “\*”, “RECREATE”);  
}

this simply results in the output:  
MakeProject has generated 0 classes in traces

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [February 24, 2025, 3:47pm UTC](https://root-forum.cern.ch/t/reading-ttree-branch-vector-of-vectors/63013/4 "2025-02-24T15:47:09Z")

</div>

In your library, how did you generate the dictionary (what is the content of the linkdef files)?

---

<div class="post-metadata">

**Author:** ![cej25](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/90db22/32.png) [@cej25](https://root-forum.cern.ch/u/cej25)\
**Post date:** [February 24, 2025, 7:33pm UTC](https://root-forum.cern.ch/t/reading-ttree-branch-vector-of-vectors/63013/5 "2025-02-24T19:33:22Z")

</div>

I’m sorry, I don’t think I understand the question. The MakeProject did not generate the LinkDef file.

In the software used to generate the trees, the DataLinkDef.h looks something like this:

#pragma link C++ class HitData+;

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [February 24, 2025, 9:55pm UTC](https://root-forum.cern.ch/t/reading-ttree-branch-vector-of-vectors/63013/6 "2025-02-24T21:55:38Z")

</div>

Then something unexpected is going on. In particular `MakeProject` resulting in no output.

Can you provide first the `ROOT` file you are trying to look at?

---

<div class="post-metadata">

**Author:** ![cej25](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/90db22/32.png) [@cej25](https://root-forum.cern.ch/u/cej25)\
**Post date:** [February 25, 2025, 6:13pm UTC](https://root-forum.cern.ch/t/reading-ttree-branch-vector-of-vectors/63013/7 "2025-02-25T18:13:39Z")

</div>

Sure, access here: [run\_0075\_test-merge.root - Google Drive](https://drive.google.com/file/d/1N8EGf3YD7UyG8TfhJW1_CY4b_h3w8BdF/view?usp=sharing)

In this example the principle is as i described although some names changed; the tree is “evt”, the branches are part of a class “LisaCalData”, and I cannot extract trace\_febex properly.

I used a macro pretty much identical to my earlier reply to try to generate the “project”.

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [February 25, 2025, 6:44pm UTC](https://root-forum.cern.ch/t/reading-ttree-branch-vector-of-vectors/63013/8 "2025-02-25T18:44:34Z")

</div>

Start ROOT, but make sure it will NOT load your own (shared) libraries:

`root run_0075_test-merge.root`

Then execute:

`gFile->MakeProject("traces", "*", "recreate++");`

---

<div class="post-metadata">

**Author:** ![cej25](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/90db22/32.png) [@cej25](https://root-forum.cern.ch/u/cej25)\
**Post date:** [February 25, 2025, 6:54pm UTC](https://root-forum.cern.ch/t/reading-ttree-branch-vector-of-vectors/63013/9 "2025-02-25T18:54:43Z")

</div>

Ah, this worked, thank you.
