Re: TFile: .Open() vs constructor

From: Fons Rademakers <Fons.Rademakers_at_cern.ch>
Date: Wed, 01 Jun 2005 19:52:46 +0200


Please do:

   TFile *b = TFile::Open(....)

   delete b;

   TFile *c = TFile::Open(...)

   delete c;

the TFile ctor (delete b, c) implies a TFile::Close().

Cheers, Fons.

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();
>
> }
>

-- 
Org:    CERN, European Laboratory for Particle Physics.
Mail:   1211 Geneve 23, Switzerland
E-Mail: Fons.Rademakers_at_cern.ch              Phone: +41 22 7679248
WWW:    http://www.rademakers.org/fons/      Fax:   +41 22 7679480
Received on Wed Jun 01 2005 - 19:52:49 MEST

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