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?
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 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?
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
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?
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?
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
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
…
}