[ROOT] merging histograms files

From: Pascal Perrodo (perrodo@lapp.in2p3.fr)
Date: Fri Aug 25 2000 - 10:52:41 MEST


Hi,

I am trying to merge several ROOT files containing different hisotgrams
(I don't want to add histograms). Each file sizes about 5 Mbytes.
I haven't found any command in ROOT to do this, so I have written the
macro below, inspired from an example given in a ROOTtalk mail. It
works for a few files (4) but with more I get the message:
Fatal in <operator new>: storage exhausted
aborting

How can I solve the problem ? Thanks in advance. Cheers.
                             Pascal.
--------------------------------------------------
{

// Merge ROOT files containing different objects.

gROOT->Reset();

const char *cfiles[] = {
  "file1.root",
  "file2.root",
  "file3.root",
  ""};
const char *outfile="fileout.root";

TFile   *afile, *file1;

// create the result file
TFile *fnew = new TFile(outfile,"RECREATE");
  
//create a support list for the input files
TList *flist = new TList();
  
//open all input files and insert them in the list of files
Int_t nfiles = 0;
while (strlen(cfiles[nfiles])) {
  afile = new TFile(cfiles[nfiles]);
  flist->Add(afile);
  nfiles++;
}
  
gROOT->GetListOfFiles()->Print();

//Get a pointer to the first file
afile = file1 = (TFile*)flist->First();

nfiles = 0;
while( afile != 0 ){
  printf("file %s\n",cfiles[nfiles]);
  TList *l = afile->GetListOfKeys();
  TObject*obj = l->First();
  fnew->cd();
  while( obj != 0 ){
    afile->Get(obj->GetName())->Write();
    obj = l->After(obj);
  }
  l->Delete();

  afile = (TFile*)flist->After((TObject*)afile);
  nfiles++;
}

//gROOT->GetListOfFiles()->Print();
//wait();

fnew->Close();
delete fnew;
printf("%s closed\n",outfile);

flist->Delete();
delete flist;

}



This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:32 MET