TypeError from RDataFrame::Reduce on std::vector<myClass> column

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())

Hi,

I am sorry to read this code did not work out of the box for you.
I tried it with master, 6.32.08 and 6.34.00 and it worked for me.
What version are you using?

Cheers,
Danilo

Hi Danilo,

Thank you for your prompt response. I apologize for not mentioning earlier the specific ROOT version I am using. It is version 6.20/00.

Based on your reply, I understand that my code should, in principle, be compatible with this version (6.20/00). Could you please verify if this is the case? I would like to determine whether the issue lies with my code or with the ROOT version I am currently using.

Thank you in advance for your help.

Best regards,
Matteo

Hi Matteo,

Yes, we do strive for providing maximum stability of interfaces.
However, let me point out that ROOT 6.20 was released 4.5 y ago - The effort we have at disposal to backport fixes for that releases, provided it’s possible, is very limited.
Is it possible that you update to 6.32.08? Your code will continue to work there.

Cheers,
D

Of course, I wasn’t complaining about that. I understand that it’s my responsibility to upgrade the ROOT version I’m using. I just wanted to confirm that the code is working properly. You can go ahead and close the ticket

Hi Matteo,

Thanks for your reply. I was not implying at all it was your responsibility or fault: it’s just that the effort at our disposal is limited, and we need sometimes to make choices about what is supported - I agree that it would be awesome to maintain versions within, say, a 5 years window, but, so far, the effort at our disposal and the contributions by our community did not allow us to do so.

I am glad you managed to update and solve this problem. Do not hesitate to come back with questions, if any!

Cheers,
D

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