Warning: file probably not closed

Hello,
in order to properly close ROOT files I added the TTree::GetCurrentFile() line to my code, but sometimes and with no clear reason I keep on getting the same error:

Warning in TRFIOFile::Init: file rfio:///castor/cern.ch/user/b/bifani/na62/kl2g/sc/P5-05/46.root probably not closed, trying to recover
Info in TRFIOFile::Recover: rfio:///castor/cern.ch/user/b/bifani/na62/kl2g/sc/P5-05/46.root, recovered key TTree:Tree at address 805441251
Warning in TRFIOFile::Init: successfully recovered 1 keys

Root is able to successfully recover the file but this warning is a bit unpleasant!
Any idea?

Cheers,
s.

TTree::GetCurrentFile is not closing a file.
You should tell us more on your procedure to close your file(s) if you want a clear diagnostic.

Rene

I’m sorry… TTree::GetCurrentFile just get the pointer to the file.
With properly close the file I mean fill it (TFile::Write()) and then TFile::Close().

Btw… I noticed that no warnings appear if copying the same file from castor to a local directory (/tmp/bifani).
I just wrote an email to the castor support to know if the problem could be related to some castor mis-behavior.

What do you think?
s.

cannot tell you more without a piece of code showing how you close your file(s)

Rene

Here it is:

root_file = tree->GetCurrentFile();
root_file->Write();
root_file->Close();

where:

TFile *root_file;
root_file = new TFile(“compact.root”, “recreate”, “root”, 0);

TTree *tree;
tree = new TTree(“Tree”, “Tree”);

s.

What you do is correct. It could be problem on the castor side. Could you add the new statement in your code and do again a file->Map() when reading to compare the two ouputs?

root_file = tree->GetCurrentFile();
root_file->Write();
root_file->Map();  //new statement
root_file->Close();

Rene

The following lines are used in order to produce a root file and store it in castor:

root_file = tree->GetCurrentFile();
root_file->Write();
root_file->Close();

The unclosed file problem comes out when trying to read it.

Using the TFile::Map() method on the local copy of the castor file I get entries such as:

20080817/084953 At:1899937701 N=29337 TBasket

while directly on the castor file:

SysError in TFile::Seek: cannot seek to position 788434247680 in file /castor/cern.ch/user/b/bifani/na62/kl3/sc/P5-05/0.root, retpos=-1 (Bad file descriptor)
20071204/131915 At:788434247680 N=975784960 CX = 1.51

s.

Btw… after more tests I found out that the unclosed file warning appears also on the local copy of the file and it is recovered at the same address.

local (lxplus216 /tmp/bifani ):
Warning in TFile::Init: file 0.root probably not closed, trying to recover
Info in TFile::Recover: 0.root, recovered key TTree:Tree at address 1005405911Warning in TFile::Init: successfully recovered 1 keys
TCanvas::MakeDefCanvas: created default TCanvas with name c1

castor:
Warning in TRFIOFile::Init: file rfio:///castor/cern.ch/user/b/bifani/na62/kl2g/sc/P5-05/0.root probably not closed, trying to recover
Info in TRFIOFile::Recover: rfio:///castor/cern.ch/user/b/bifani/na62/kl2g/sc/P5-05/0.root, recovered key TTree:Tree at address 1005405911
Warning in TRFIOFile::Init: successfully recovered 1 keys

I see from the result of file->Map that you have reached the maximum default Tree size limit of 1.9 GBytes. You should have received an error message or a warning indicating that the system is automatically switching to a new file. Read carefully the documentation of TTree::ChangeFile at
root.cern.ch/root/html/TTree.htm … ChangeFile

Rene

Yes, I received the message and a new file was created with the suffix “_1” as described in root.cern.ch/root/html/TTree.htm … ChangeFile.
That’s why to overcome the closing file problem I added the root_file = tree->GetCurrentFile(); line.

Are the two files independent? Can I separately open and analyze the two TTrees?

s.

[quote]Are the two files independent? Can I separately open and analyze the two TTrees? [/quote]Yes and Yes.

Cheers,
Philippe.

So… what is wrong with these files? Why do I get an unclosed file error even if they are properly closed?

Cheers,
s.

YOUR FILES ARE NOT PROPERLY CLOSED.
see my advice above.

Rene

Maybe I missed something but how can my files be not properly closed if I followed the recipe in
root.cern.ch/root/html/TTree.htm … ChangeFile (namely using TFile::GetCurrentFile() as described above)?

Moreover, why do I get two different outputs from the TFile::Map command (different date/time and a TFile::Seek SysError as posted above) between the castor file and a local copy of the same file?

s.

This discussion cannot continue if you do not provide the strict minimum to understand your problem, ie
-the shortest possible running setup (not thousands lines of code)
-possibly output files in a public readable area

Rene

The full code is in /afs/cern.ch/na48/user/bifani/na62/kl2g but it is based on the official NA62 software and cannot be easily reduced to few routines.

The ROOT framework has been implemented just for the filling of a TTree by adding few lines to three main routines (user_init, user_ana and user_exit)

TFile *file;
TTree *tree;

user_init() {

file = new TFile(“0.root”, “recreate”, “root”, 0);
tree = new TTree(“Tree”, “Tree”);

// branches declaration

}

user_ana() {

tree->Fill(); // one for each analyzed event

}

user_exit() {

root_file = tree->GetCurrentFile();
root_file->Write();
root_file->Close();

}

You can find an example of output file with the unclosed warning in:

/castor/cern.ch/user/b/bifani/na62/kl2g/sc/P5-05/0.root

and a copy of the same file in:

/tmp/bifani/0.root @ lxplus232

Hello, any news?

PS. I’m trying to provide you the shortest code that produces ROOT files with the same unclosed warning.

s.