Getting status from TGeoManager::Import

I would like to add a new automated step to the Mu2e software validation suite. I would like to load a gdml file using root and programatically verify that it loads without error. I can do this but only by parsing printed output. I would like to know if there is a way to do this by asking the TGeoManager object for status information. Any advice?

Here is the macro I am now using:

void gdmlCheck( char const* gdmlFilename ){
  TGeoManager* geom = TGeoManager::Import(gdmlFilename);
 unsigned status{0.};  // I would like to add a status check here.
  exit(status);
}

It can be invoked with:

root -l gdmlCheck.C\(\"mu2e_good.gdml\"\) 2> good_err.log 1> good_out.log
root -l gdmlCheck.C\(\"mu2e_bad.gdml\"\)   2> bad_err.log 1> bad_out.log

The signature of an error is the caseblind string “error” in the x_err.log file or more than 2 lines in the x_out.log. That feels fragile and, over time, likely to produce both false positives and false negatives. Does anyone see a better way? Ideally I would like to ask the TGeoManager object about the status of the import and return an exit code that reflects the status.

Thanks,

Rob

ROOT Version: 6.22.08
Platform: SL7
Compiler: g++ 9.3.0

Hi @kutschke,

Perhaps, you can use a custom error handler to catch the error on TGeoManager::Import, i.e. (adjusted from above)

unsigned status = 0;

void gdmlCheck(const char *gdmlFilename) {
  ::SetErrorHandler([] (int level, Bool_t abort, const char *location, const char *msg) {
      if (level == kError && strstr(location, "TGeoManager::Import"))
        status = 1;
    });

  auto geom = TGeoManager::Import(gdmlFilename);
  return status;
}

Then, you should be able to tell if the file was parsed successfully looking at the exit status returned by the root process.

Cheers,
J.