RE: [ROOT] Adding files with several trees

From: Philippe Canal (pcanal@fnal.gov)
Date: Thu Aug 14 2003 - 20:28:25 MEST


Hi Frank,

You can use TChain::Merge(TFile*) as follow

	TFile *file = new TFile("output.root","RECREATE");
	firstChain->Merge(file);
	// Merge close the file so let's reopen it
	file = new TFile("output.root","UPDATE");
	secondChain->Merge(file);

Note that if the data does not fit in one file, the TTree::ChangeFile
mechanism will be run.  This mechanism assumes one tree per file and always
'recreate' file that it needs (see doc).

Alternatively you could try:

	TFile *file = new TFile("output.root","RECREATE");
	firstChain->CloneTree();
	// the chain might change the current directory.
	file->cd();
	secondChain->CloneTree();
	file->Write();

However the same caveat about TTree::ChangeFile is in effect.

Cheers,
Philippe.

-----Original Message-----
From: owner-roottalk@pcroot.cern.ch
[mailto:owner-roottalk@pcroot.cern.ch]On Behalf Of Frank Simon
Sent: Thursday, August 14, 2003 10:33 AM
To: roottalk@pcroot.cern.ch
Subject: [ROOT] Adding files with several trees


Hi all,

I'm trying to add a large number of files that contain several
different trees (same set of trees in each file).
I know that for cases with one tree per file, the way to go is
TChain::Merge("add.root"). However, this does not work if I want to
have all my trees in one file at the end.

The macro
http://root.cern.ch/root/html/examples/hadd.C.html

claims to be able to do it, but it only creates empty trees in the
file (works fine for histograms, though...)

I would not mind doing the operation in two steps, eg. creating one
file per tree with TChain::Merge() and then combining these files into
one, but I don't see how to do that...

Thanks for your help!

Frank


 ================================================================
| Frank Simon                    http://www.mppmu.mpg.de/~fsimon |
|                                                                |
| Max-Planck-Institut fuer Physik       +49-89-32354-226         |
| Foehringer Ring 6                                              |
| 80805 Muenchen                        Brookhaven Nat. Lab.:    |
| Germany                               +1-631-344-3121          |
 ================================================================



This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:14 MET