Home | News | Documentation | Download

How to open multiple ROOT files with RDataFrame in pyROOT


#1

Dear ROOT developers,

I am trying to open multiple files with the same TTree using RDataFrame in pyROOT. I am trying something along

from ROOT import RDataFrame
frame = RDataFrame("TTreeName", ["filename1", "filename2", "filename3"])

but that does not seem to work. Is it possible to open multiple ROOT files in one RDataFrame in pyROOT somehow? If yes, are the TTrees from the ROOT files merged by RDataFrame?

Cheers,
Ben


ROOT Version: 6.14.04



#2

Hi Ben,

nice question. The code is not working since you are trying to pass a Python list to a C++ interface which expects a vector of strings and PyROOT is not (yet) able to convert between these types (not that one exists only in Python!).
There are 2 solutions: use a wildcard string or fill a vector of strings.

  1. wildcard (the same wildcard of TChain::Add)
from ROOT import RDataFrame
frame = RDataFrame("TTreeName", "filename*")
  1. vector of strings
from ROOT import RDataFrame
names = ROOT.std.vector('string')()
for n in ["filename1", "filename2", "filename3"]: names.push_back(n)
frame = RDataFrame("TTreeName", names)

Cheers,
D