# How to create vector\<Vector3D\> branch w/o dictionary?

**URL:** <https://root-forum.cern.ch/t/how-to-create-vector-vector3d-branch-w-o-dictionary/44176>\
**Category:** ROOT\
**Tags:** tree\
**Created:** [March 26, 2021, 2:03pm UTC](https://root-forum.cern.ch/t/how-to-create-vector-vector3d-branch-w-o-dictionary/44176 "2021-03-26T14:03:15Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![FoxWise](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/foxwise/32/37588_2.png) [@FoxWise](https://root-forum.cern.ch/u/FoxWise)\
**Post date:** [March 26, 2021, 2:03pm UTC](https://root-forum.cern.ch/t/how-to-create-vector-vector3d-branch-w-o-dictionary/44176/1 "2021-03-26T14:03:15Z")

</div>

I am trying to create a branch with a `vector <Vector3D>`.

Why this works using `XYZVector`, but not using `TVector3` or `dd4hep::rec::Vector3D`?

```auto
#include "TFile.h"
#include "TTree.h"
#include <vector>
#include "Math/Vector3D.h"
using namespace ROOT::Math;

int test(){
    TFile f("test.root", "RECREATE");
    TTree* t = new TTree("Test", "Test Tree");
    std::vector <XYZVector> xyz;
    t->Branch("xyz", &xyz);
    xyz.push_back(XYZVector(42., 42.*42., 42.*42.+42.));
    t->Fill();
    f.Write();

    return 0;
}

```

works fine, but using

```auto
#include "TVector3.h"
...
    std::vector <TVector3> xyz;
    xyz.push_back(TVector3(42., 42.*42., 42.*42.+42.));
...

```

or

```auto
#include "DDRec/Vector3D.h"
using dd4hep::rec::Vector3D;
...
    std::vector <Vector3D> xyz;
    xyz.push_back(Vector3D(42., 42.*42., 42.*42.+42.));
...

```

Output:

```auto
Error in <TTree::Branch>: The class requested (vector<dd4hep::rec::Vector3D>) for the branch "xyz" is an instance of an stl collection and does not have a compiled CollectionProxy. Please generate the dictionary for this collection (vector<dd4hep::rec::Vector3D>) to avoid to write corrupted data.

```

with an empty ROOT file. Which I couldn’t fix.

thanks and cheers

_ROOT Version:_ 6.22/00  
_Platform:_ Centos 7

---

<div class="post-metadata">

**Author:** ![Axel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/axel/32/11084_2.png) [@Axel](https://root-forum.cern.ch/u/Axel)\
**Post date:** [March 26, 2021, 5:13pm UTC](https://root-forum.cern.ch/t/how-to-create-vector-vector3d-branch-w-o-dictionary/44176/2 "2021-03-26T17:13:37Z")

</div>

@pcanal correct me if I’m wrong - no, _where_ I’m wrong, but:

- it doesn’t work for `dd4hep::rec::Vector3D` because we don’t have a dictionary;
- it doesn’t work for `TVector3` because that has a custom streamer and thus `vector<TVector3>` needs a dictionary (is that the case, Philippe?)
- it works for `XYZVector` because we have a dictionary and it has a default streamer, and so we know how to stream a `vector<XYZVector>`.

In short: please create a dictionary for `dd4hep::rec::Vector3D` and it should work.

---

<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:** [March 26, 2021, 5:57pm UTC](https://root-forum.cern.ch/t/how-to-create-vector-vector3d-branch-w-o-dictionary/44176/3 "2021-03-26T17:57:29Z")

</div>

It works only because we generate dictionary for ` std::vector<ROOT::Math::XYZVector >` in the GenVector library. To do I/O on an item (including collections) you need to generate a dictionary (for collection the dictionary is often generated implicit alongside the dictionary for a class that uses that collection)

Cheers,  
Philippe.

PS. If you are adventurous it “might” work without a dictionary because all `std::vector` have the same layout in memory by disabling the warning:

```auto
t->Branch("xyz", , "std::vector<dd4hep::rec::Vector3D>", (void*)&xyz);

```

but your mileage may vary so use _this_ solution solely for quick debugging session not for ‘production’ work.

---

<div class="post-metadata">

**Author:** ![FoxWise](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/foxwise/32/37588_2.png) [@FoxWise](https://root-forum.cern.ch/u/FoxWise)\
**Post date:** [March 26, 2021, 7:05pm UTC](https://root-forum.cern.ch/t/how-to-create-vector-vector3d-branch-w-o-dictionary/44176/4 "2021-03-26T19:05:53Z")

</div>

@Axel , @pcanal  
Thanks!

Is there one-line way to generate a dictionary without complicated DictDef.h and cling things?

I have tried to add line:  
`gInterpreter->GenerateDictionary("vector<Vector3D>","vector;DDRec/Vector3D.h");`

But the same error occurs, though some Dictionary files appear in the directory…

---

<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:** [March 26, 2021, 7:51pm UTC](https://root-forum.cern.ch/t/how-to-create-vector-vector3d-branch-w-o-dictionary/44176/5 "2021-03-26T19:51:10Z")

</div>

> Is there one-line way to generate a dictionary without complicated DictDef.h and cling things?

humm … the full solution is not “that” complicated:

```auto
// File ContLinkDef.h
#pragma link C++ class std::vector<dd4hep::rec::Vector3D>+;

```

and

```auto
rootcling -f ContDict.cxx -Iheader_directory vector DDRec/Vector3D.h ContLinkDef.h

```

and then compile and link ContDict.cxx as usual.

> I have tried to add line:

You must use the fully qualified names (except for std:: which is optional):

```auto
gInterpreter->GenerateDictionary("std::vector<dd4hep::rec::Vector3D>","vector;DDRec/Vector3D.h");

```

Cheers,  
Philippe.

---

<div class="post-metadata">

**Author:** ![FoxWise](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/foxwise/32/37588_2.png) [@FoxWise](https://root-forum.cern.ch/u/FoxWise)\
**Post date:** [March 27, 2021, 12:52pm UTC](https://root-forum.cern.ch/t/how-to-create-vector-vector3d-branch-w-o-dictionary/44176/6 "2021-03-27T12:52:55Z")

</div>

Is there a way to do “full solution” without compiling? E.g if I use root cpp script with just `root test.cpp`, without any compilation…

Because if I use this macro for the analysis, the code is changing every second, and recompiling all the time, is just annoying and adds time for every “save file” and “test launch”

cheers,  
Bohdan

---

<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:** [March 27, 2021, 3:50pm UTC](https://root-forum.cern.ch/t/how-to-create-vector-vector3d-branch-w-o-dictionary/44176/7 "2021-03-27T15:50:30Z")

</div>

Create a simple “`rootlogon.C`” file (in your current working directory):

```cpp
{ // rootlogon.C
  // gInterpreter->AddIncludePath("/path/to/include"); // where "DDRec/Vector3D.h" resides
  gInterpreter->GenerateDictionary("std::vector<dd4hep::rec::Vector3D>", "vector;DDRec/Vector3D.h");
  // gSystem->Load("/path/to/libMyClasses");
  // gInterpreter->AddIncludePath("/path/to/MyClasses/include");
  // gROOT->ProcessLine(".L /path/to/MyClasses.C+");
}

```

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [April 10, 2021, 3:50pm UTC](https://root-forum.cern.ch/t/how-to-create-vector-vector3d-branch-w-o-dictionary/44176/8 "2021-04-10T15:50:42Z")

</div>

Closed on April 10, 2021, 3:50pm UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
