Using Lambda function with variable number of columns

Dear RDataFrame expert,

I was wondering if it’s possible to define a single Lambda function which allow to have a variable number of columns as input.

ptjets,etc are define as “const ROOT::VecOps::RVec &vec”

e.g.
.Define(“Test”, Lambda::Test(), {“ptjets”, “ptleptons”})
or
.Define(“Test”, Lambda::Test(), {“ptjets”, “ptelectrons”,“ptmuons”})

Cheers,
Marco


Please read tips for efficient and successful posting and posting code

Please fill also the fields below. Note that root -b -q will tell you this info, and starting from 6.28/06 upwards, you can call .forum bug from the ROOT prompt to pre-populate a topic.

ROOT Version: 6.32.02
Platform: linuxx8664gcc
Compiler: g++ (GCC) 13.1.0


Hi Marco,

Thanks for the interesting question.
Unfortunately, that is not possible: the number of columns to be fed to the function/lambda is inferred from its arguments.
If this is really a “must have” for you, you could imagine using a jitted Define, for example:

df = df.Define("Test2", "myFunction(ptjets, ptleptons)");
df = df.Define("Test3", "myFunction(ptjets, ptelectrons, ptmuons)");

where myFunction is a callable that is able to handle 2 or 3 input parameters (via overloads or otherwise).

I hope this helps!

Cheers,
Danilo