Running the code below results in:
Traceback (most recent call last):
File “/storage/gpfs_data/neutrino/users/mt/ANA/spill_slicing/test.py”, line 52, in
my_vect = rdf.Reduce(ROOT.myS_aggregator(), “v”, ROOT.std.vector(ROOT.myS)())
TypeError: can not resolve method template call for ‘Reduce’
It is not clear to me what’s wrong with the code.
Using ROOT::VecOps::Rec
as suggested here doesn.'t solve the issue.
# %%
import ROOT
# %%
ROOT.gInterpreter.ProcessLine("""
struct myS {
int a;
int b;
}
""")
# %%
ROOT.gInterpreter.ProcessLine("""
std::vector<myS> fill_row() {
return std::vector<myS>(2);
}
""")
# %%
ROOT.gInterpreter.ProcessLine("""
int counter() {
static int counter = 0;
return counter++;
}
""")
# %%
rdf = ROOT.RDataFrame(5)
rdf = rdf.Define("i", "counter()")
rdf = rdf.Define("v", "fill_row()")
# %%
ROOT.gInterpreter.ProcessLine("""
struct myS_aggregator {
std::vector<myS> operator()(std::vector<myS> orig, std::vector<myS> toadd) {
orig.insert(orig.end(), toadd.begin(), toadd.end());
return orig;
}
};
""")
# %%
ROOT.gInterpreter.ProcessLine("""
struct my_sum {
int operator()(int orig, int toadd) {
return orig + toadd;
}
};
""")
# %%
my_vect = rdf.Reduce(ROOT.myS_aggregator(), "v", ROOT.std.vector(ROOT.myS)())
print(my_vect)
# %%
my_sum = rdf.Reduce(ROOT.my_sum(), "i", 0)
print(my_sum.GetValue())