Hi, all
I have files named like:
1.root
2.root
...
999.root
I want to use a wildcard to load/analyze only first 42 of them.
In bash I would do something like this:
ls {0..42}.root
It seems I can’t do this in a code, as it results in error:
df = ROOT.RDataFrame("tree", "{0..42}.root")
Error in <TFile::TFile>: file /path/to/file/{0..42}.root does not exist
Is there workaround?
cheers,
Bohdan
RDF uses the same wildcard syntax as TChain , but I wouldn’t know how to do that with TChain (@pcanal ?).
A simple workaround it to use a list comprehension:
df = ROOT.RDataFrame("t", [str(n) + ".root" for n in range(1,43)])
Cheers,
Enrico
1 Like
yus
April 1, 2022, 10:52am
3
Hi,
According to ROOT: TChain Class Reference ,
Wildcard treatment is triggered by any of the special characters []*?
which may be used in the file name, e.g., specifying "xxx*.root"
adds all files starting with xxx
in the current file system directory.
Would it be possible to add {}
symbols and their effects to the list of wildcard symbols?
Hi @FoxWise ,
I think you could try with the following
vpadulan@fedora [~/chaintest]: for i in {1..5}
> do
> touch file$i.root
> done
vpadulan@fedora [~/chaintest]: ls
file1.root file2.root file3.root file4.root file5.root
vpadulan@fedora [~/chaintest]: root
root [0] TChain c;
root [1] c.Add("file[1-3].root");
root [2] for (auto *el: *c.GetListOfFiles()) std::cout << el->GetTitle() << std::endl;
/home/vpadulan/chaintest/file1.root
/home/vpadulan/chaintest/file2.root
/home/vpadulan/chaintest/file3.root
Cheers,
Vincenzo
Hi, Vincenzo
[]
doesn’t work with two digit numbers.
[0-42]
is interpreted as [0-4,2]
cheers,
Bohdan
system
Closed
April 18, 2022, 10:18am
7
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.