Re: TFile: .Open() vs constructor

From: Rene Brun <brun_at_pcroot.cern.ch>
Date: Wed, 1 Jun 2005 19:58:06 +0200 (MEST)


Hi Giovanni,

You should not do:

   TFile b; b.Open("File__.root","RECREATE","piffero",1); but

   TFile *b = TFile::Open("File__.root","...

TFile::Open is a static function !

Rene Brun

On Wed, 1 Jun
2005, Giovanni Franzoni wrote:

>
> Dear colleagues,
>
> needing to open a file from two different points of my code, I get
> problems (reported at the bottom) if I make two TFile instantiations which
> point to the same file on disk, and Open()-Close() them.
> [i.e. TFile b; b.Open("File__.root","RECREATE","piffero",1);]
>
> If instead I just instantiate the TFile objects with the path-name of the
> file in the constrictor, the problem does not appear.
> [i.e.: TFile b("File__.root","RECREATE","piffero",1);]
>
> Using:
> ROOTSYS=/afs/cern.ch/sw/root/v4.02.00/rh73_slc3/root/
>
> Best regards, Giovanni
>
>
>
>
> _________ complaint ______________________________________
> Warning in <TFile::Init>: file File__.root probably not closed, cannot read free segments
> Warning in <TFile::Init>: file File__.root probably not closed, trying to recover
> Info in <TFile::Recover>: File__.root, recovered key TH1F:ciao at address 232
> Warning in <TFile::Init>: successfully recovered 1 keys
>
>
>
>
>
> _________ code ___________________________________________
> //c++ `root-config --libs --cflags` file.cpp -o file_haha2
>
> #include <iostream>
> #include "TFile.h"
> #include "TH1F.h"
>
>
> int main(int argc, char * argv[]){
>
> std::cout << "hello world" << std::endl;
>
> TFile b;
> b.Open("File__.root","RECREATE","piffero",1);
> // TFile b("File__.root","RECREATE","piffero",1);
> TH1F a("ciao","ciao1",0,0,1);
> a.Write();
> b.Close();
>
> // TFile c("File__.root","UPDATE","piffero",1);
> TFile c;
> c.Open("File__.root","UPDATE","piffero",1);
> TH1F d("ciao2","ciao3",0,0,1);
> d.Write();
> c.Close();
>
> }
>
>
Received on Wed Jun 01 2005 - 19:58:11 MEST

This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:09 MET