Defining static members in RDF

Probably a question for @eguiraud.
Everything I’m doing with RDF right now is defining a set of functions that I compile within a ROOT dictionary and load them in python.
Each of the function is self defined and does not need to access globally defined members.

Now I’d like to evaluate a MVA inside such function, but I would not think instantiating the MVA each time within the function (that will be called for each event) is the way to go.

Are they good recommended practices to define global static stuff that would be called only one, like one would do with a class constructor?



yes, you need a functor class rather than a function:

class MyRDFOp {
  int _datamember;
  MyRDFOp() : _datamember(42) {}
  double operator()(double input1, double input2) { return input1 + input2 + _datamember; }

and then:

df.Define("x", ROOT.MyRDFOp())

I think PyROOT should swallow this without issues. If it complains we might need a little helper function to do the booking also from C++.


thanks for the very quick feedback!
I’m already using functors like here:

will try with a class and let you know if it works out of the box.

class or struct does not make a difference – then you can initialize the MVA in the object constructor and you are done – if the MVA evaluation is thread-safe. Otherwise you might need one MVA object per thread in conjunction with DefineSlot or similar patterns to make thread-unsafe things thread-safe.

1 Like

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