Root / Numpy type conversion error

Hi,

I have some python code that generates tuples of values, on which I would like to call a macro that I previously loaded.
When I do this, I get a typeerror :

import ROOT as r
from root_numpy import tree2array
r.gROOT.LoadMacro(“myMacro.cc”)
file = r.TFile(‘myfile.root’)
mytree = file.get(‘mytree’)

my_data = tree2array(mytree, branches_list)

my_macro(*my_data[branches_list][0])

When I try to compare the types expected by my_macro and the types in my tuple, they are exactly the same except that the tuple ones are numpy types and not native python types.
Is this the reason why the conversion fails?
If yes, how could I avoid that issue?

edit : just for the sake of completeness, the type conversion error occurs on the first argument which is a np.int16 and expected to be an int, but some of the later arguments are 1D arrays where the macro expects a pointer, if that could be a problem).

Hi,

At least at the moment, root_numpy is not included in ROOT so we can’t provide the best support for it as ROOT developers.

Said that, what is the type of my_data and the type of *my_data[branches_list][0]? What are exactly the types expected by my_macro? Can’t you use native Python types instead of involving numpy?

Enric

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