Is there a way to test if a root file is “good” from a bash script? I’m trying to write a script that resubmits failed jobs to our batch system. These particular root files have a no keys error when opened:
Warning in <TFile::Init>: file myfile.root probably not closed, trying to recover
Warning in <TFile::Init>: no keys recovered, file has been made a Zombie
I have a hint of what causes the error in my log files but the error only causes a problem sometimes
Hi,
how about
root -l -b -q -e 'bool is_zombie = TFile("f0.root").IsZombie(); return is_zombie ? 1 : 0'
Cheers,
Enrico
Hi Enrico, I tried running on the command line and got the following:
Warning in <TApplication::GetOptions>: macro bool is_zombie = TFile not found
f0.root is a valid file name in the directory I’m testing this in
I only get that message if I omit the -e, might that be the case?
I have the -e option. I noticed the -q option doesn’t seem to be working either as after the command it leaves me in the root environment. The root version I’m working with is 5.33/02 in case that is relevant
Ah, yes that’s very relevant, that’s a very old and currently unsupported ROOT version. I would strongly suggest you upgrade to ROOT v6.20 or v6.22.
Unfortunately I don’t have the option to upgrade. I was able to upgrade from 5.26/00 to 5.33/02 but it was the newest version of root capable of being run on the system I’m forced to use. Is it possible to construct a command capable of checking the root files with that version?
If that’s the case, I suggest you write a C++ program or a ROOT macro rather than a bash script: you can easily write a C++ program that takes a filename as argument, opens it with TFile, checks the output of TFile::IsZombie and returns non-zero if IsZombie() is true, e.g.
#include <TFile.h>
int main(int argc, char** argv) {
const bool is_zombie = TFile(argv[1]).IsZombie();
return is_zombie ? 1 : 0;
}
Cheers,
Enrico