RE: [ROOT] Help with TFile

From: Olivas, Alexander Raymond (olivas@SLAC.stanford.edu)
Date: Thu Apr 10 2003 - 00:59:52 MEST


a couple things.
1) my code doesn't compile.

  Int_t i_last=272;
  for(Int_t i=1;i<=i_last;i++){
    char fileName[60];
    sprintf(fileName,"$NTUPLE_DIR/B/BJpsiSkimFeb14%s_%d.root",name,i);
    if(!gSystem->AccessPathname(fileName)){
	TFile f(fileName);
	ksMassNoCuts->Add((TH1F*)f.Get("h1d3"));
	ksMassCuts->Add((TH1F*)f.Get("h1d5"));
	jpsiMassNoCuts->Add((TH1F*)f.Get("h1d7"));
	jpsiMassCuts->Add((TH1F*)f.Get("h1d9"));
    }
  }

  this produces the following error...
KsSkimTestLatest.cxx: In function `int go (char *)':
KsSkimTestLatest.cxx:99: no matching function for call to
`TSystem::AccessPathname (char[60])'
make: *** [KsSkimTestLatest.o] Error 1

2)when i try it interactively it seems to return true regardless of
  whether the file exists or not.
root [7] gSystem->AccessPathName("$NTUPLE_DIR/B/BJpsiSkimFeb14KVTJVTNew_1.root")
(Bool_t)1
root [8] gSystem->AccessPathName("$NTUPLE_DIR/B/BJpsiSkimFeb14KVTJVTNew_1.rt")
(Bool_t)1

  the first example the file name was chosen using tab-complete so i know
it exists.

i'm using version 3.04/02 on redhat 7.2 by the way.

thanks,
alex.

-----Original Message-----
From: Rene Brun
To: Sebastien Greder
Cc: Olivas, Alexander Raymond; 'roottalk@root.cern.ch'
Sent: 4/9/2003 2:39 AM
Subject: Re: [ROOT] Help with TFile

Sebastien,

Thanks for correcting my mistake.

Rene

Sebastien Greder wrote:
> 
> Hi,
> 
> sorry but the AccessPathname return value is the opposite, cf
classindex
> doc :
> 
> Bool_t AccessPathName(const char *, EAccessMode)
> 
> Returns FALSE if one can access a file using the specified access
mode.
>  Attention, bizarre convention of return value!!
> 
> seb.
> 
> On Wed, 9 Apr 2003, Rene Brun wrote:
> 
> > Hi Alex,
> >
> > I don't know that is the "g" object in your statement g.Open !
> >
> > To test if a file exist, you can use
> >    gSystem->AccessPathname(fileName);
> > This will return kTRUE if the file can be accessed, kFALSE
otherwise.
> >
> > Rene Brun
> >
> > "Olivas, Alexander Raymond" wrote:
> > >
> > > I'm not sure if this is the correct place to post this question,
> > > but here it goes.
> > >
> > > I have many jobs currently creating quite a few root files.
> > > I have the files numbered so I can read them using a simple
> > > for loop.  However, some jobs haven't started yet and some
> > > are still running. I would like to read only the files that
> > > exist and are closed.
> > >
> > > I've tried something like...
> > >
> > >   Int_t i_last=272;
> > >   for(Int_t i=1;i<=i_last;i++){
> > >     char fileName[60];
> > >
sprintf(fileName,"$NTUPLE_DIR/B/BJpsiSkimFeb14%s_%d.root",name,i);
> > >     if(g.Open(fileName)){
> > >       TFile f(fileName);
> > >       ksMassNoCuts->Add((TH1F*)f.Get("h1d3"));
> > >     }
> > >   }
> > >
> > > g.Open(fileName) still returns true if the file does not exist.
> > > I've searched through the root page and have had trouble finding
> > > anything that will allow me to assess the state of a file without
> > > explicity trying to open it.
> > >
> > > Any help would be greatly appreciated.
> > > Thanks,
> > > Alex.
> >



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