Here is my story. I need to loop over a tree and do some filter. The parameters are some kind complex. So I store them in a JSON file, something like this:
[
{
"h_idx": 12,
"bin2e": [-7.70332, 7.78929e-02],
"nBinsX": 4096,
"hrange": [200,3700],
"erange": [8.1, 280.5],
"t_gp": [],
"t_bkg": [],
...
},
{
"h_idx": 13,
"bin2e": [ -9.16058, 7.94685e-02],
"nBinsX": 4096,
"hrange": [200,3700],
"erange": [],
"t_gp": [],
"t_bkg": [],
...
},
...
In python, it is really charming to read the JSON:
import simplejson as sj
pars = sj.loads("".join(open("mypars.json").readlines()))
But the same goal is too sophisticated in C++. So, I want to use Python to read parameters, then get the parameters through TPython interface in C++.
First, I defined a struct in C++, and loaded it by “ROOT.gROOT.LoadMacro”. Then I read parameters and assigned them to C++ struct. But I failed in delivering them to C++ Class.
I tried an alternative way. I tried to invoke TPython::Eval in C++ to implement such a goal. Failed again.
Could anyone give me an example to do so?