How should a single tree of many big ROOT files be merged?

I have many big ROOT files (totalling in size up to about 0.5 TB) that contain various trees, histograms etc. I want to merge them into a single ROOT file keeping only the tree called “nominal” that is in all of the files. How should this be done? Is there an approach that would be efficient in time?

Hi,

this should be possible using a TChain. Have a look at the Merge-Method:

root.cern.ch/root/html604/TChai … hain:Merge

Cheers,
Jochen

Hi Jochen

Thanks for your help on that! The TChain worked well as a solution for that. I have another question, if you have a moment: If I wanted to have two trees, would I need two TChain objects? If yes, how could I merge these two TChains such that the two trees are saved to one ROOT file?

root.cern.ch/root/html604/TChai … hain:Add@1

Will

Hi,

I have not done anything like that yet. But I would guess that you could do somthing like that:

TChain *numberOne = … // create and populate first chain

TChain *numberTwo = … // create and populate second chain

TFile *foo = TFile::Open(“filetoputchainsin.root”,“recreate”);

foo->cd(); // making sure that foo is current directory
numberOne->Merge(foo,0,""); // you could try the option “fast” as third parameter…
foo->cd(); // making sure that foo is current directory
numberTwo->Merge(foo,0,""); // writing the second chain

foo->Close();

As I said, I’ve no idea if that will actually work :wink:

Cheers,
Jochen