# Fill Branch from Vector of Vectors

**URL:** <https://root-forum.cern.ch/t/fill-branch-from-vector-of-vectors/55906>\
**Category:** Newbie\
**Created:** [August 3, 2023, 1:17pm UTC](https://root-forum.cern.ch/t/fill-branch-from-vector-of-vectors/55906 "2023-08-03T13:17:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ferusso](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/f/8e8cbc/32.png) [@ferusso](https://root-forum.cern.ch/u/ferusso)\
**Post date:** [August 3, 2023, 1:17pm UTC](https://root-forum.cern.ch/t/fill-branch-from-vector-of-vectors/55906/1 "2023-08-03T13:17:51Z")

</div>

Is it possible to create a branch from a vector of vectors? I tried

```auto
std::vector<std::vector<float>> myVector;
...
myTree->Branch("myVector", &myVector);
std::vector<float> test;
test.push_back(1.);
myVector.push_back(test);
 myTree->Fill();
myVector.clear();

```

The code ran without complaint, but myTree did not have the branch myVector. Did I do something wrong? Or is this only possible with flat vectors?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [August 7, 2023, 1:41pm UTC](https://root-forum.cern.ch/t/fill-branch-from-vector-of-vectors/55906/2 "2023-08-07T13:41:57Z")

</div>

Hi,

You would need to generate first the dictionary for the required class (std::vector\<std::vector\>).  
You can do this by using first ACLIC and then you can run your code.  
Here is the fixed macro:

```auto
#include <vector>
#include <TTree.h>

// line needed to generate the dictionary
#pragma link C++ class std::vector<std::vector<float>>+;

void test() {
auto myVector = new std::vector<std::vector<float>>;
auto myTree = new TTree("t","t");
myTree->Branch("myVector", "std::vector<std::vector<float>>", &myVector);
std::vector<float> test;
test.push_back(1.);
myVector->push_back(test);
myTree->Fill();
myVector->clear();

myTree->Print();

}

```

And you need first to run ACLIC:

```auto
root> .L test.C+
root> test() 

```

---

<div class="post-metadata">

**Author:** ![ferusso](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/f/8e8cbc/32.png) [@ferusso](https://root-forum.cern.ch/u/ferusso)\
**Post date:** [August 8, 2023, 2:32pm UTC](https://root-forum.cern.ch/t/fill-branch-from-vector-of-vectors/55906/3 "2023-08-08T14:32:04Z")

</div>

Thank you!!
