Check a JSON in RDF

Hi Experts, I want to use RDataFrame to remove events in a TTree which do not appear in a JSON file before doing further operations on it. My (intended) strategy is to declare a snippet of C++ code using ROOT.gInterpreter.Declare() to then use in an RDF.Define() which would pass two branches of the tree to the C++ code to give back a yes/no for that event.

I am unsure however how to accomplish this: is there native JSON support in the gInterpreter already, or do I have to build this from scratch? Is there a simple way to do this?

  • Marc

Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided

Hi @osh ,
I guess most of your code is in Python. I think you have two options:

  1. do the parsing in Python, extract the information you need, and then use it in your gInterpreter.Declare() invocation

  2. use a C++ library for JSON parsing, e.g.


Hi Enrico,

Good guess :slight_smile:

For your first suggestion, I’m not sure I understand: you can declare python code in the gInterpreter? Or do you mean to do the computations outside of RDF and then import the results?


  • Marc

You can build the code you declare using Python, so e.g. if you have some numbers in a list l you can Declare them to C++ with

ROOT.gInterpreter.Declare("std::vector<int> myv = {" + ",".join(l) + "};")

Let me also ping @etejedor or @swunsch in case they can thing of something better.


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