Re: [ROOT] Merging files

From: Rene Brun (Rene.Brun@cern.ch)
Date: Thu Dec 20 2001 - 09:26:41 MET


Hi Dennis,

A small example showing how to merge 3 files containing 4 Trees.

{
   const Int_t ntrees = 4;
   const Int_t nfiles = 3;
   char *trees[4] = {"T1","T2","T3","T4"};
   char *files[3] = {"file1.root","file2.root","file3.root"};
   TFile *outFile = new TFile("big.root","recreate");
   for (Int_t t=0;t<ntrees;t++) {
      TChain *chain = new TChain(trees[t]);
      for (Int_t if=0;if<nfiles;if++) chain->Add(files[if]);
      chain->Merge(outFile,0);
      delete chain;
   }
   delete outFile;
}

As indicated in the TChain::Merge documentation, this simple procedure
will work for simple Trees containing mostly basic types or objects with
basic types. It will not work, for example, if your branches include
some STL containers. Branch addressses should be set in this case.

Rene Brun


Dennis C. Arrogancia wrote:
> 
> Dear Rooters,
> 
> I have a little problem regarding merging files containig a tree. I tried
> using the code below and it works fine in my case.
> 
>   TChain ch("T");
>   ch.Add("file1.root");
>   ch.Add("file2.root");
>   ch.Add("file3.root");
>   ch.Merge("big.root");
> 
> Now, my problem is how can i merge these three files if each of them
> contains two or more trees? Say file1.root contains trees such as
> "T1","T2", and "T3". Similarly for file2.root and file3.root, they also
> contain the same number of trees.
> 
> Dennis



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:51:12 MET