# How to generate a dictionary of std::vector\<TVector3\> when compiling my code

**URL:** <https://root-forum.cern.ch/t/how-to-generate-a-dictionary-of-std-vector-tvector3-when-compiling-my-code/59502>\
**Category:** Newbie\
**Tags:** root\
**Created:** [May 29, 2024, 7:19am UTC](https://root-forum.cern.ch/t/how-to-generate-a-dictionary-of-std-vector-tvector3-when-compiling-my-code/59502 "2024-05-29T07:19:44Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Crisps](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/crisps/32/39101_2.png) [@Crisps](https://root-forum.cern.ch/u/Crisps)\
**Post date:** [May 29, 2024, 7:19am UTC](https://root-forum.cern.ch/t/how-to-generate-a-dictionary-of-std-vector-tvector3-when-compiling-my-code/59502/1 "2024-05-29T07:19:44Z")

</div>

Dear experts

I was trying to extract some TTree branch contains `std::vector<TVector3>` type values, I know I can write a macro and add a line: `#pragma link C++ class std::vector<TVector3>+;` and do something like: `root macro.cxx++` to make it work.  
But I want to compile my code by c++ compiler, which means it starts from `int main(int argc, char** argv)` instead of some function. How can I make it work instead of getting this error:

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

```

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [May 29, 2024, 8:02am UTC](https://root-forum.cern.ch/t/how-to-generate-a-dictionary-of-std-vector-tvector3-when-compiling-my-code/59502/2 "2024-05-29T08:02:37Z")

</div>

Hi,

The instructions can be found here [I/O of custom classes - ROOT](https://root.cern/manual/io_custom_classes/) .

Cheers,  
D

---

<div class="post-metadata">

**Author:** ![Crisps](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/crisps/32/39101_2.png) [@Crisps](https://root-forum.cern.ch/u/Crisps)\
**Post date:** [May 29, 2024, 8:31am UTC](https://root-forum.cern.ch/t/how-to-generate-a-dictionary-of-std-vector-tvector3-when-compiling-my-code/59502/3 "2024-05-29T08:31:47Z")

</div>

Thank you for your reply, but I don’t have any custom classes in my code, I just want to use std::vector where std::vector is a STL class and TVector3 is a ROOT class both are already implemented, how can I use the combination of them?

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [May 29, 2024, 10:17am UTC](https://root-forum.cern.ch/t/how-to-generate-a-dictionary-of-std-vector-tvector3-when-compiling-my-code/59502/4 "2024-05-29T10:17:51Z")

</div>

Hi,

Since the dictionary for that class is not already present in ROOT, it counts as a custom class: the documentation above is relevant in this respect.  
Starting from the next ROOT releases, thanks to your post, the dictionary for the `vector<TVector3>` will be available natively ([[math] Add dictionary for vector\<TVector3\> by dpiparo · Pull Request #15669 · root-project/root · GitHub](https://github.com/root-project/root/pull/15669))

Cheers,  
D

---

<div class="post-metadata">

**Author:** ![atd](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/atd/32/33835_2.png) [@atd](https://root-forum.cern.ch/u/atd)\
**Post date:** [May 30, 2024, 4:26pm UTC](https://root-forum.cern.ch/t/how-to-generate-a-dictionary-of-std-vector-tvector3-when-compiling-my-code/59502/5 "2024-05-30T16:26:30Z")

</div>

Hi,

While waiting for the next release, [here](https://github.com/root-project/root/tree/master/tutorials/tree/dictionary) you may find a minimal working code that shows what you want to do.

Best,  
Alvaro

---

<div class="post-metadata">

**Author:** ![Crisps](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/crisps/32/39101_2.png) [@Crisps](https://root-forum.cern.ch/u/Crisps)\
**Post date:** [May 31, 2024, 4:53am UTC](https://root-forum.cern.ch/t/how-to-generate-a-dictionary-of-std-vector-tvector3-when-compiling-my-code/59502/6 "2024-05-31T04:53:59Z")

</div>

Thank you for the information! I think the point is I don’t know what should I write in the `std::vector<TVector3>` cxx file and hxx file… normal custom TObject class has there own definitions, but what should I write in a `std::vector<TVector3>` class?  
I mean, I need to give a name of the custom class at first, right? like:

```auto
class custom : public TVector3, public std::vector<TVector3>
{
};

```

---

<div class="post-metadata">

**Author:** ![atd](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/atd/32/33835_2.png) [@atd](https://root-forum.cern.ch/u/atd)\
**Post date:** [May 31, 2024, 6:54am UTC](https://root-forum.cern.ch/t/how-to-generate-a-dictionary-of-std-vector-tvector3-when-compiling-my-code/59502/7 "2024-05-31T06:54:31Z")

</div>

Hi,

The [example I linked](https://github.com/root-project/root/blob/beb5aead7a4e7ecea8eb4adfb32d7c7eaf6cf03a/tutorials/tree/dictionary/data2Tree.hxx#L20) does not need inheritance.

After defining your own custom class (in files .h, .cxx), use pragmas to make the dictionary for the class and possible containers, as in [the example](https://github.com/root-project/root/blob/beb5aead7a4e7ecea8eb4adfb32d7c7eaf6cf03a/tutorials/tree/dictionary/data2TreeLinkDef.hxx#L17). If you want to use a vector of `TVector3`, I think it is enough to add the corresponding pragma in the file LinkDef.h,

```auto
#pragma link C++ class std::vector<TVector3>+;

```

If `TVector3` is a class of ROOT, in order to make the dictionary maybe it is enough to include the header and link against the corresponding root shared library wherever the definition of that class is.

---

<div class="post-metadata">

**Author:** ![Crisps](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/crisps/32/39101_2.png) [@Crisps](https://root-forum.cern.ch/u/Crisps)\
**Post date:** [May 31, 2024, 7:17am UTC](https://root-forum.cern.ch/t/how-to-generate-a-dictionary-of-std-vector-tvector3-when-compiling-my-code/59502/8 "2024-05-31T07:17:21Z")

</div>

But how to define my class aka. std::vector …? I don’t know what should I write in the class file, what I need is only the variable type of `std::vector<TVector3>` where `std::vector` and `TVector3` are already defined in STL and ROOT

---

<div class="post-metadata">

**Author:** ![Crisps](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/crisps/32/39101_2.png) [@Crisps](https://root-forum.cern.ch/u/Crisps)\
**Post date:** [June 3, 2024, 2:42am UTC](https://root-forum.cern.ch/t/how-to-generate-a-dictionary-of-std-vector-tvector3-when-compiling-my-code/59502/9 "2024-06-03T02:42:36Z")

</div>

I followed the page you shared and tried to generate dictionary:

1. write `LinkDef.h`:

```auto
#ifdef __CLING__
#pragma link C++ class std::vector<TVector3>+;
#endif

```

1. use `rootcling` to generate dictionary:  
`rootcling -f Dict.cxx LinkDef.h`

But I got error:  
`Warning: Unused class rule: std::vector<TVector3>`

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [June 3, 2024, 6:33am UTC](https://root-forum.cern.ch/t/how-to-generate-a-dictionary-of-std-vector-tvector3-when-compiling-my-code/59502/10 "2024-06-03T06:33:47Z")

</div>

Hi,

I think you are forgetting the appropriate headers.  
Have you read [I/O of custom classes - ROOT](https://root.cern/manual/io_custom_classes/#using-rootcling) ?

Cheers,  
D

---

<div class="post-metadata">

**Author:** ![Crisps](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/crisps/32/39101_2.png) [@Crisps](https://root-forum.cern.ch/u/Crisps)\
**Post date:** [June 3, 2024, 7:06am UTC](https://root-forum.cern.ch/t/how-to-generate-a-dictionary-of-std-vector-tvector3-when-compiling-my-code/59502/11 "2024-06-03T07:06:59Z")

</div>

Yes I have read the page you shared, the header files in my case do you mean `TVector3.h` or both `TVector3.h` and `std::vector.h`?

---

<div class="post-metadata">

**Author:** ![Crisps](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/crisps/32/39101_2.png) [@Crisps](https://root-forum.cern.ch/u/Crisps)\
**Post date:** [June 3, 2024, 7:24am UTC](https://root-forum.cern.ch/t/how-to-generate-a-dictionary-of-std-vector-tvector3-when-compiling-my-code/59502/12 "2024-06-03T07:24:51Z")

</div>

Ah, after I add `TVector3.h` in my `rootcling` command it worked.

May I ask another question that what is the meaning of the plus sign “`+`” in the LinkDef.h?  
`#pragma link C++ class std::vector<TVector3>+;`

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [June 3, 2024, 6:24pm UTC](https://root-forum.cern.ch/t/how-to-generate-a-dictionary-of-std-vector-tvector3-when-compiling-my-code/59502/13 "2024-06-03T18:24:19Z")

</div>

Hi,

Excellent: thanks for sharing.  
The `+` after the class name enables extra features and performance improvements in the I/O of the type (for more details, see [here](https://root.cern/manual/io_custom_classes/#selecting-dictionary-entries-linkdefh).

Cheers,  
Danilo
