# Use RDataFrame with nested vectors (like vector\<vector\<float\>\>) without creating additional dictionaries

**URL:** <https://root-forum.cern.ch/t/use-rdataframe-with-nested-vectors-like-vector-vector-float-without-creating-additional-dictionaries/57356>\
**Category:** Newbie\
**Tags:** rdataframe, tree, io\
**Created:** [December 1, 2023, 1:02pm UTC](https://root-forum.cern.ch/t/use-rdataframe-with-nested-vectors-like-vector-vector-float-without-creating-additional-dictionaries/57356 "2023-12-01T13:02:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![CuriousPeter](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/curiouspeter/32/25433_2.png) [@CuriousPeter](https://root-forum.cern.ch/u/CuriousPeter)\
**Post date:** [December 1, 2023, 1:02pm UTC](https://root-forum.cern.ch/t/use-rdataframe-with-nested-vectors-like-vector-vector-float-without-creating-additional-dictionaries/57356/1 "2023-12-01T13:02:38Z")

</div>

* * *

_Please read [tips for efficient and successful posting](https://root-forum.cern.ch/t/tips-for-efficient-and-successful-posting/28292) and [posting code](https://root-forum.cern.ch/t/posting-code-read-this-first/28293)_

\_ROOT Version: 6.26/02, 6.28/06  
\_Platform: GNU/Linux (CentOS Linux release 7.9.2009)  
\_Compiler: GCC 11.2.0, GCC 13.2.0

* * *

Hi,

My question is quite simple and yet I cannot find a definitive answer: is it possible to work with nested vectors in branches using RDataFrame (create TTree, read TTree) without any additional dictionaries?

Here’s my example macro testTree.C (also attached below):

```auto
void testTree() {
  ROOT::RDataFrame d(10);
  int i(1);
  vector<string> definedNames = {"b1", "b2", "b3"};
  
  d.Define("b1", [&i]() { int j = i; ++i; return j; })
    .Define("b2", [&i]() {
        vector<float> v(i);
        for (auto &k:v)
          k = gRandom->Rndm();
        return v;
      })
     .Define("b3", [&i]() {
        vector< vector<float> > vv;
        for (auto &v1:vv) {
          v1.resize(i);
          for (auto &k:v1)
            k = gRandom->Rndm();
        }
        return vv;
      })
    .Snapshot("tr", "testTree.root", definedNames);
}

```

[testTree.C](https://root-forum.cern.ch/uploads/short-url/6LwIOi14r8SRqbhkKceko7ibhQw.C) (571 Bytes)

If I run this macro in ROOT as follows, it works:

```auto
gInterpreter->GenerateDictionary("vector<vector<float > >")
.x testTree.C

```

but if I run just `root -l -b -q testTree.C` it fails with the following message:

```auto
Error in <TTree::Branch>: The class requested (vector<vector<float> >) for the branch "b3" is an instance of an stl collection and does not have a compiled CollectionProxy. Please generate the dictionary for this collection (vector<vector<float> >) to avoid to write corrupted data.
RDataFrame::Run: event loop was interrupted
terminate called after throwing an instance of 'std::logic_error'
  what(): Trying to insert a null branch address.

```

Yet, when I open resulted file with RDataFrame and check it out (for example `ROOT::RDataFrame d("tr", "testTree.root"); d.Describe()`), it works even without additional dictionary.

Is there a way to modify this code so it would simply run in the interpreter without requiring additional dictionaries (i.e. just `root -l -b -q testTree.C`)? Or is it always mandatory when working with nested vectors in RDataFrame to create them?

Cheers,  
Peter

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [December 1, 2023, 1:32pm UTC](https://root-forum.cern.ch/t/use-rdataframe-with-nested-vectors-like-vector-vector-float-without-creating-additional-dictionaries/57356/2 "2023-12-01T13:32:29Z")

</div>

Maybe @pcanal has another solution, but can’t you simply add `gInterpreter->GenerateDictionary("vector<vector<float>>");` at the beginning of the `testTree()` function? Something like this:

```auto
void testTree()
{
  gInterpreter->GenerateDictionary("vector<vector<float>>");
  ROOT::RDataFrame d(10);
  [...]

```

---

<div class="post-metadata">

**Author:** ![CuriousPeter](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/curiouspeter/32/25433_2.png) [@CuriousPeter](https://root-forum.cern.ch/u/CuriousPeter)\
**Post date:** [December 1, 2023, 2:11pm UTC](https://root-forum.cern.ch/t/use-rdataframe-with-nested-vectors-like-vector-vector-float-without-creating-additional-dictionaries/57356/3 "2023-12-01T14:11:35Z")

</div>

It works, but it will leave 4 additional files (\_.cxx, \_.so, \_.pcm, \_.d) which might be a problem in case of several dictionaries. So I also added a last line that deletes all generated files after the snapshot is done:

```auto
[...]
    .Snapshot("tr", "testTree.root", definedNames);
  gSystem->Exec("rm AutoDict_*");
}

```

Still, I hope there’s more elegant way to do this considering cases, where TTree has some nested vectors (or just 2,3-dimentional arrays), might be quite common - especially when working with data formats from the experiments.

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [December 1, 2023, 2:13pm UTC](https://root-forum.cern.ch/t/use-rdataframe-with-nested-vectors-like-vector-vector-float-without-creating-additional-dictionaries/57356/4 "2023-12-01T14:13:20Z")

</div>

OK, so let’s see if @pcanal or @Axel have a more elegant solution
