Reading branch generated by PyROOT in C

Hi,

I’m trying to read a root file generated by python. The file can be open and draw successfully, but when it comes to a c-program it always gives the following error:

0x00000000004138ba in std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::operator[] (this=0x445dbf024395b7ec, __n=0) at /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_vector.h:611
0x000000000040862d in AnalysisSort::Loop (this=0x7ffcb9c84010, FlagSave=2, FlagNrModel=1) at Analysis.C:74
0x0000000000406138 in main (argc=5, argv=0x7ffcb9c95bd8) at xx.C:68

It seems that it cannot recognize the branch I defined.
Here’s how I defined branch in python

type = std.vector('string')()
#newtree.Branch('type', type, 'type[ntype]/C')
newtree._type = type
newtree.Branch('type', type)
for entry in range(nb_entries):
    tree.GetEntry(entry)
    tree_type = list(tree.type)
    type.clear()
    for t in tree_type:
        type.push_back(t)
    newtree.Fill()

Do you know how can I define the branch so that it can be read by a c program?

Hi,

this should do the job for reading a tree

import ROOT
f = ROOT.TFile.Open("myfile.root")
# there is a tree called mytree in the file and it has a branch called mybranch
for e in f.mytree:
   print e.mybranch

Cheers,
D

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