Functor in RDataFrame with multiple overloaded operator()

ROOT Version: 6.16.00
Platform: linux (cc7)
Compiler: gcc 4.8.5

Hi everybody,

Assume I have a functor ‘func’ with various overloaded operator() which only differ in the argument list (type or number or arguments). I’d like to call this functor in different ways to add new columns to my dataframe like in the following snippet:

auto d2 = d.Define(“res1”, func, {“x”}); // calling operator()(int)
.Define(“res2”, func, {“x”, “y”}); // calling operator()(int, int)

However the forwarding to the specific function doesn’t work. I tried to follow a bit this blog:
I admit, most of this I don’t know or understand in much detail.

The only way I could solve this problem so far is by using lambda functions as follows:

auto d2 = d.Define(“res1”, [&feval](int x) -> int { return feval(x); }, {“x”});
.Define(“res2”, [&feval](int x, int y) -> int { return feval(x, y); }, {“x”, “y”});

Is there a more elegant way with or without using lambda functions? Maybe a way where the entire declaration of the function is not required? I could get the example working of the above link.

Many thanks in advance.

The only way I could get this

functors with overloaded call operators (or with template call operators) are not supported.
I would also suggest the lambda to work around the limitation, but you don’t need to explicitly specify the return type -> int. I agree that it’s not the prettiest construct.

The reason overloaded call operators are not supported is that RDataFrame infers the type of the columns that you want to read from the signature of the callable that is passed to Define or Filter. Obviously this breaks down if there is no one signature to read the types from.

Hope this clarifies things a bit.

Hi Enrico,

I see, thanks for the clarification. Good to know that I’m not doing the things more complicated than necessary :wink:
For easy use of my framework, however, I’ll prefer to provide various functors each with unique operator() and avoiding any templates therein.


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