Quiet testing if a file is a ROOT file

In C++, I know how to test to see if a file is a ROOT file:

bool test = TFile("filename").IsZombie();

However, when I make this test, I get error output if it’s not a ROOT file:

Error in <TFile::Init>: filename not a ROOT file

For what I’m trying to do, I have my program doing one thing if filename is not a ROOT file and another if it is. In my case, neither is an error. In fact, it’s more likely that filename is not a ROOT file.

How do I suppress this message? Or is there another way of testing this that produces no output?

ROOT Version: 6.22/06
Platform: CentOS 7
Compiler: GCC 10.2.0

I found an answer to my own question. The trick is to suppress ROOT’s error message handling:

#include "TROOT.h"
// ...
auto saveErrorLevel = gErrorIgnoreLevel;
gErrorIgnoreLevel = 5000;
bool test = TFile("filename").IsZombie();
gErrorIgnoreLevel = saveErrorLevel;

Many Bothans died to bring us this information; that is, I had to trace through the ROOT source code to find this out.


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.