Re: [ROOT] combining rootfiles

From: Stilianos Kesisoglou (kesisogl@fnal.gov)
Date: Wed Sep 04 2002 - 10:58:52 MEST


Hi Andrea,

    Assuming that you have the files:

    root_file_0.root
    root_file_1.root
    root_file_2.root.
.
.
    root_file_n.root

and all of them have inside the same trees:

    treeA
    treeB
    treeC
.
.
.
    treeZ

then to create a single file named output.root you simply have to do:

{
    TFile *f = new TFile("output.root ", "recreate");

//    Merging chain A.
    TChain *chA = new TChain("treeA");
    chA->Add("root_file_0.root");
    chA->Add("root_file_1.root");
    chA->Add("root_file_2.root");
.
.
    chA->Add("root_file_n.root");
    chA->Merge(f,0);

//    Merging chain B.
    TChain *chB = new TChain("treeB");
    chB->Add("root_file_0.root"); 
    chB->Add("root_file_1.root"); 
    chB->Add("root_file_2.root");
.
.
    chB->Add("root_file_n.root");
    chB->Merge(f,0);


//    .... and then repeat the same for the other chains C, .... Z

    f->Close();
}

    Obviously you can do the above using a loop.

Stelios.

----- Original Message ----- 
From: "Andreas Salzburger" <Andreas.Salzburger@cern.ch>
To: <roottalk@pcroot.cern.ch>
Sent: Wednesday, September 04, 2002 3:32 AM
Subject: [ROOT] combining rootfiles


> dear root-talk community,
> 
> i've got a problem with some rootfiles  that look exactly the same (same
> tree and branch and directory structure).
> and i want to combine them to one big file.
> i know how to do that by writing a macro, declaring all the branches and
> looping over the events, but i wonder if there's a fixed method that may
> probably do this by default?
> 
> so if someone could give me a hint,
> this would help me a lot
> thanks
> andi
> 
> 



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:51:06 MET