# Error in \<TTree::Branch\> with a vector of vectors

**URL:** <https://root-forum.cern.ch/t/error-in-ttree-branch-with-a-vector-of-vectors/14883>\
**Category:** ROOT\
**Created:** [September 7, 2012, 2:03am UTC](https://root-forum.cern.ch/t/error-in-ttree-branch-with-a-vector-of-vectors/14883 "2012-09-07T02:03:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![teb27](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/t/e99b99/32.png) [@teb27](https://root-forum.cern.ch/u/teb27)\
**Post date:** [September 7, 2012, 2:03am UTC](https://root-forum.cern.ch/t/error-in-ttree-branch-with-a-vector-of-vectors/14883/1 "2012-09-07T02:03:52Z")

</div>

Hi,

I have a class with a member whose type is a std::vector\<std::vector \> \*ptr. I want to store this variable as a branch in my tree. I do this using the method

`myTree->Branch("branchName","vector<vector<float> >", &MyBranchName );
`

In the header file I include

```auto
#include <vector>
#ifdef __MAKECINT__
#pragma link C++ class std::vector < std::vector<float> >+;   
#endif

```

The class compiles fine. I then create an executable for my main() program using the syntax

```auto
/afs/cern.ch/sw/lcg/external/gcc/4.3.2/x86_64/bin/g++ -Wall -g `root-config --cflags` -I. `root-config --libs` MyClass.o MainProgram.C -o MainProgram
```

and this creates the exe, as expected. When I try to run the exe, I get the runtime errors

```auto
Error in <TTree::Branch>: The class requested (vector<vector<float> >) for the branch "branchName" refer to an stl collection and do not have a compiled CollectionProxy. Please generate the dictionary for this class (vector<vector<float> >)
```

Any reason why this is happening, even though I #include and link with the appropriate standard library?

---

<div class="post-metadata">

**Author:** ![Pepe\_Le\_Pew](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pepe_le_pew/32/12365_2.png) [@Pepe\_Le\_Pew](https://root-forum.cern.ch/u/Pepe_Le_Pew)\
**Post date:** [September 7, 2012, 5:56am UTC](https://root-forum.cern.ch/t/error-in-ttree-branch-with-a-vector-of-vectors/14883/2 "2012-09-07T05:56:35Z")

</div>

For “std::vector\<std::vector \>” see [url][Storing 2D vector [--\> vector\<vector\<...\> \>] into a TTree](https://root-forum.cern.ch/t/storing-2d-vector-vector-vector-into-a-ttree/14331/1)  
For “std::vector\<std::vectorstd::string \>” see [url][Problem in getting the vector \< vector \<string\> \> branch](https://root-forum.cern.ch/t/problem-in-getting-the-vector-vector-string-branch/14608/1)

BTW. The “#pragma link C++” is irrelevant for the compiler when you compile your class’es source code. You would need to call “rootcint” in order to build the dictionary for your class. A separate additional source code file would be created which you would need to compile and add that additional object file to the linker command line.

---

<div class="post-metadata">

**Author:** ![Pepe\_Le\_Pew](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pepe_le_pew/32/12365_2.png) [@Pepe\_Le\_Pew](https://root-forum.cern.ch/u/Pepe_Le_Pew)\
**Post date:** [September 7, 2012, 8:40am UTC](https://root-forum.cern.ch/t/error-in-ttree-branch-with-a-vector-of-vectors/14883/3 "2012-09-07T08:40:23Z")

</div>

A brutal fix …  
… assuming that the class’es source code file is “MyClass.cxx”, execute: `echo 'gROOT->LoadMacro("MyClass.cxx++"); gSystem->Exit(0);' | root -b -l -n` … or … `root -b -l -n <<EOF
.L MyClass.cxx++
.q
EOF` This will (hopefully) create a “MyClass\_cxx.so” shared library file (it should include the class’es dictionary and all “#pragma link C++” related ones as well). Add this “MyClass\_cxx.so” shared library file (you can also rename it into something like a “[libMyClass.so](http://libMyClass.so)”, if you like) to the link command line instead of the “MyClass.o” file (no need to compile the “MyClass.cxx” file itself separately at all).

See also [url][Compile a macro without running?](https://root-forum.cern.ch/t/compile-a-macro-without-running/14759/1) and [url][Peoblems with passing bash script arguments](https://root-forum.cern.ch/t/peoblems-with-passing-bash-script-arguments/14666/1)

---

<div class="post-metadata">

**Author:** ![teb27](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/t/e99b99/32.png) [@teb27](https://root-forum.cern.ch/u/teb27)\
**Post date:** [September 7, 2012, 3:38pm UTC](https://root-forum.cern.ch/t/error-in-ttree-branch-with-a-vector-of-vectors/14883/4 "2012-09-07T15:38:18Z")

</div>

Thanks. I got it to work by generating the dictionary using rootcint. Here’s the makefile I used

```auto
CC = /afs/cern.ch/sw/lcg/external/gcc/4.3.2/x86_64/bin/g++
CCFLAGS = -Wall -g
INCS = `root-config --cflags` -I.
LIBS = `root-config --libs` -lTreePlayer

SkimMain : SkimMain.C BranchBase.o MuonBranch.o TrigGlobalBranch.o Dict.o
        $(CC) $(CCFLAGS) $< BranchBase.o MuonBranch.o TrigGlobalBranch.o Dict.o -o $@ $(INCS) $(LIBS)

TrigGlobalBranch.o: TrigGlobalBranch.C TrigGlobalBranch.h BranchBase.o
        $(CC) $(CCFLAGS) -c $< $(INCS) $(LIBS)

MuonBranch.o: MuonBranch.C MuonBranch.h BranchBase.o
        $(CC) $(CCFLAGS) -c $< $(INCS) $(LIBS)

BranchBase.o : BranchBase.C BranchBase.h
        $(CC) $(CCFLAGS) -c $< $(INCS) $(LIBS)

Dict.o : Dict.cxx
        $(CC) $(CCFLAGS) -c $< $(INCS) $(LIBS)

Dict.cxx : BranchBase.h
        rootcint -f $@ -c $<+

clean :
        rm -f Dict.o Dict.cxx Dict.h TrigGlobalBranch.o MuonBranch.o BranchBase.o

```
