Probem of defining and filling a TTree Branch with structure containing a std::vector in pyROOT

The structure is defined as

 gROOT.ProcessLine(
 "struct data_t {\
    int  m;\
    Char_t  n[5];\
    vector<int> E;\
 };")

I tried the following ways to define the branch containing a std::vectors

 t1.Branch("E", addressof(data, 'E'), 'E/vector<int>');

This one leads to an unknow type error and is not the right way of doing it.

 t1.Branch("E", data.E);

This one correctly defined the tree but had a “*** Break *** bus error” when trying to run

 t1.Scan("E"). 

I attached the example code and any help is appreciated.

ROOT Version: 6.32.2
Platform: ubuntu
Compiler: gcc
__
example.py (535 Bytes)

It turns out one has to do the following:

 gROOT.ProcessLine(
 "struct data_t {\
    int  m;\
    Char_t  n[5];\
    std::vector<int> *E;\
 };")

 data = ROOT.data_t()
 data.E = ROOT.std.vector(int)()
1 Like

Hi,

Thanks a lot for the follow up and for sharing the solution with the Community! Hopefully this will be helpful for others.

Cheers,
D

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