Using Tchain for list of root file

Hi Everyone,
My code works for one file root, so I put all the .root file inside a .tex and use TChain and a while loop to process all the .root file. But only the first .root file one the .tex file is taken into account.
Also I can’t have the outdirectory I set, instead I get this error:

Error in <TFile::Open>: no url specified

Here is my code:

// main program starts here
int main(int argc, char **argv) {

 TString reader;
 ifstream fileReader(argv[1]);
 TString dirout = argv[2];
  
   gSystem->Exec("mkdir -p " + dirout );


 TFile* outputFile = TFile::Open(TString::Format("%s/%s.root",argv[2],argv[3]), "recreate");
   SetAtlasStyle(1);





     gStyle->SetPadColor       (0);
     gStyle->SetPadBorderSize  (10);
     gStyle->SetPadBorderMode  (0);
     gStyle->SetPadBottomMargin(0.18);
     gStyle->SetPadTopMargin   (0.06);
     gStyle->SetPadLeftMargin  (0.10);
     gStyle->SetPadRightMargin (0.04);
     gStyle->SetPadGridX       (0);
     gStyle->SetPadGridY       (0);
     gStyle->SetPadTickX       (1);
     gStyle->SetPadTickY       (1);
     gStyle->SetTitleYOffset(1.0);

   gStyle->SetCanvasColor(0);
   gStyle->SetOptStat(0);
   gStyle->SetOptFit(1);
   gStyle->SetStatColor(0);

     TLatex *atexl=new TLatex(0.65,0.85,"ATLAS Internal");atexl->SetNDC();




    new TApplication("ATLAS Week analisys",&argc,argv);
    canv_1 = new TCanvas("canv_1","RAW",10,10,800,800); //canvas instantiated
    canv_1->Divide(3,2);
 
   TChain *treeHandle = new TChain("Nominal/llllTree");
   while (!fileReader.eof()) {
  reader.ReadLine(fileReader);
  if( reader.Length() < 2 ) continue;
  cout << " Adding " << reader << endl;
  treeHandle->Add( reader );
  }
    llllTree2* m = new llllTree2(treeHandle);  
    m->Loop();


 // pause so that you can zoom graphs etc .... then double click to continue
		  Int_t n=1;
 	      while (n>0) {
 	      obj = gPad->WaitPrimitive();
 	      if (!obj) break;  // leave this endless loop on a double click
 	      printf("Mouse Action : Loop i=%d, found objIsA=%s, name=%s\n", n,obj->ClassName(),obj->GetName());
 	   }





	   delete canv_1;
	   delete obj;

   return 0;
   

   outputFile->cd();
 
     outputFile->Close();
}

I would really appreciate if someone could help.
Thanks in advance.
Cheers

Hi,

can you print out the name of the file you are passing to the TFile constructor to see if something is not well defined there?
By the way, in your code I cannot find the lines that perform the operations you describe.

Cheers,
Danilo

Hi,
Thanks for replying, so I attached here the file llllTree.C and llllTree.h generated from MakeClass and Analyse.C which contains the main function.
I run the code by doing

make and ./Analyse listfile.tex 

where listfile.tex contains the root files.
In Analyse.C, from line 204 to 210 I call TChain and put a while loop to add all the root file in the tex file, but only the first file is taken into account.
Cheers
Analyse.C (5.94 KB)
llllTree2.C (10.4 KB)
llllTree2.h (191 KB)

Hi,

are you sure that what you add is a well formed string containing the path of existing root files?

D

Hi Danilo,
you were right, I can’t even understand how I can do this mistake. In fact only the first file was in the same directory than Analyse.C and the others were in another one with the listfile.txt. So if I did ./Analyse directory/listfile.tex only the first one is seen. So I bring them in the same directory than Analyse and the code works.
Thank you so much.
So I will put solved for someone who wanna use TChain with loop while
But I still have this error

Error in <TFile::Open>: no url specified

with my output directory.
Cheers

Hi,

these things happen to everybody, don’t worry.
Now, for the second error: can you isolate a reproducer for it?

Cheers,
D