Problems with input files


I use ROOT 4.02/00 and I’d like to draw histograms and graphics with data from 360 files. In order to do so, I make an array of 360 items with the files’ names and I read them through a for-loop.

ROOT gives an error at the 105th entry. Is there any problem with the number of input files that ROOT may deal with?

And is there any better way to make the histograms than using a for loop?

Thank you for your attention.

it depends on what exactly these files contain, and what you draw. If you just add the histograms in all files you can use the binary $ROOTSYS/bin/hadd. If the files contain TTrees use a TChain. If you really want to plot 360*N different histograms you might want to put them into memory:TCanvas* canvas=new TCanvas("Alotofhists", "A lot of histograms"); canvas->Divide(60,60); for (int iFile=0; iFile<360; iFile++) { TFile* f=new TFile(filename[iFile]); TH1* h=0; f->GetObject("myHist",h); h->SetDirectory(0); canvas->cd(iFile+1); h->Draw(); delete f; }TH1::SetDirectory(0) will “unregister” the histogram from the file f, so you can close f with the histogram staying in memory. You might still run into problems if the histograms consume too much memory (too many bins). To diagnose that we would need the error message you get.

Thank you for answering.

I can be more precise now. I’d like to have one final histogram out of the 360 files. They contain letters and numbers, which I read through fscanf.
For making the histogram I was thinking of the for-loop. However any other suggestion is welcome, and I’ll work out the adding-histograms thing, as well as the TChain method.

The error ROOT gives back is the following:

Error: feof param[0]=0 must not be 0 FILE:file_name.C LINE:195
*** Interpreter error recovered ***

line 195 is where the for loop begins:

for(int i = 0; i<90; i++){

fscanf (pFile[i], “%s”,en);

What can I do to solve it?

Thank you again,



okay, that’s completely different. ROOT/Cint claims that one of the pFile[i] is 0. Check by printing pFile[i] before closing. It might also be a problem with Cint’s optimization; try running after issuing the command “.O 0” (dot-oh zero) on the Cint command line.

It could also be that there’s a problem with opening more than 105 files. In that case you should do it like this:for files: open file i read file i close file iThis way you only have one file open at any given time.


It works now! It can deal with more than 105 input files.

Thank you!