Load multiple root files in one online session

Hi,

I have multiple root files “file1.root”, “file2.root”, “file3.root”, etc… all containing the same TTree (but with different contents).
If I start up root with
root -l file1.root file2.root file3.root
in fact only the last file is loaded into memory.
How do I get all three files loaded and accessible at the same time (I am guessing I have to use a Chain, but is there some easy way to do this?)

Cheers,

Machiel

Hi,

if the content is different but the branches are the same, a TChain is the way to go:

TChain mychain("file*.root");

or, if you want to load the files separately:

TFile f1("file1.root");
TFile f2("file2.root");
TFile f3("file3.root");

Cheers,
D

Thank you very much, this works.

Actually, I didn’t look well to what I got using your method. As a matter of fact, neither method works:

root [0] TChain mychain("…/GAMOS_output_GmSDTTreeUA/Gm*.root");
root [1] mychain->Print()

This returns nothing. It seems nothing is loaded.

root [2] TFile file1("…/GAMOS_output_GmSDTTreeUA/GmSDTTreeUA_tree_1000.root")
root [3] TFile file2("…/GAMOS_output_GmSDTTreeUA/GmSDTTreeUA_tree_1001.root")
root [4] TFile file3("…/GAMOS_output_GmSDTTreeUA/GmSDTTreeUA_tree_1002.root")
root [5] TFile file4("…/GAMOS_output_GmSDTTreeUA/GmSDTTreeUA_tree_1003.root")

Now, only file4 is in memory. When I draw a histogram of the Tree, as contained in all 4 files, clearly, only the contents of file4 are drwan, the contents of the first 3 files are not.

Hi,

apologies! I mixed up the methods. Try

TChain mychain("theNameOfTheTreeInTheFiles");
mychain.Add("file*.root");

Cheers,
D

You’re right. I just tested it, and indeed, this does work.
Many thanks.

Cheers,

Machiel

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