How to use Snapshot template parameters in pyRoot


ROOT Version: 6.34.4
Platform: Linux
Compiler: Not Provided


Based on the answer here RDataFrame tree conversion takes too much time and memory - #9 by eguiraud
seems that using Snapshot template parameters makes Snapshot a lot faster.

Is there a way to do it in python assuming that the column types are string and uint64 ?

@vpadulan could you please take a look at this question?

Dear @dimitris_lepipas ,

Thank you for reaching out to the forum!

Good timing on your question! We have just finished an improvement of the capability of the RDataFrame Snapshot such that it won’t be necessary anymore to specify any template arguments at all. At the same time, this will also not require any JIT-compiling. That practically means that you get the benefit of a simpler API (i.e. no need to care about template arguments) with a much, much faster runtime performance.

The change has just been merged to the development branch of ROOT, so it’s going to be available in the next ROOT version 6.38 scheduled for end of this year. In the meanwhile, if you have access to an LCG release via CVMFS, for example using lxplus, you can already see this in action. You can source the environment via e.g.

source /cvmfs/sft.cern.ch/lcg/views/dev3/latest/x86_64-el9-gcc13-opt/setup.sh

In the meanwhile, you might want to hang tight and use the Snapshot API without template arguments, which for now will still be slower but it’s also going to require zero code-changes for you after the update to 6.38. The template overload will be deprecated and slowly phased out.

Lastly, I still believe your question is interesting from a generic Python-C++ interoperability standpoint, so here it goes. If you have any function template in C++, you can call it in Python with the [] syntax, for example:

import ROOT

ROOT.gInterpreter.Declare(r"""
    template <typename T>
    void foo(T val) { std::cout << val << "\n"; }
""")

ROOT.foo[float](42.42)

So you can use the same syntax also in the case of the template Snapshot, although as I mentioned above this template will be removed in a future version of ROOT.

Cheers,
Vincenzo

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