ROOT logo
#if !defined( __CINT__) || defined(__MAKECINT__)
#include <stdio.h>
#include <unistd.h>
#include <TString.h>
#include <TSystem.h>
#include <TROOT.h>
#include <TFile.h>
#endif

Bool_t checkFile(const char* filename)
{
  // This macro returns FALSE in the following cases:
  // - the file doesn't exist
  // - the file is not readable
  // - the file is not a Root file
  // - the file is truncated
  // If the file is opened without any Error message,
  // the macro returns kTRUE

  // checkname is string with appended .check, i.e. Kinematics.root.check
  // The output of TFile::Open will be stored there
  TString checkname = filename;
  checkname += ".check";

  // remove checkname, if it already exists
  gSystem->Unlink(checkname.Data());

  // Copy and store the original stream desriptors
  Int_t origstdout = dup(fileno(stdout));
  Int_t origstderr = dup(fileno(stderr));

  // Redirect the output
  freopen(checkname.Data(),"w",stdout);
  dup2(fileno(stdout),fileno(stderr));

  // Try to open the file. The output goes to the file checkname
  TFile f(filename);

  // Restore the original stream descriptors
  dup2(origstdout,fileno(stdout));
  dup2(origstderr,fileno(stderr));

  // Prepare the grep command, executed by the shell, for example
  // grep Error Kinematics.root.check > /dev/null 2>&1
  TString command = "grep Error ";
  command += checkname;
  command += " > /dev/null 2>&1";
  // Execute the command. The return value is 0 if Error is found
  Bool_t result = gSystem->Exec(command.Data());

  // Remove the checkname
  gSystem->Unlink(checkname.Data());
  return result;
}
 checkFile.C:1
 checkFile.C:2
 checkFile.C:3
 checkFile.C:4
 checkFile.C:5
 checkFile.C:6
 checkFile.C:7
 checkFile.C:8
 checkFile.C:9
 checkFile.C:10
 checkFile.C:11
 checkFile.C:12
 checkFile.C:13
 checkFile.C:14
 checkFile.C:15
 checkFile.C:16
 checkFile.C:17
 checkFile.C:18
 checkFile.C:19
 checkFile.C:20
 checkFile.C:21
 checkFile.C:22
 checkFile.C:23
 checkFile.C:24
 checkFile.C:25
 checkFile.C:26
 checkFile.C:27
 checkFile.C:28
 checkFile.C:29
 checkFile.C:30
 checkFile.C:31
 checkFile.C:32
 checkFile.C:33
 checkFile.C:34
 checkFile.C:35
 checkFile.C:36
 checkFile.C:37
 checkFile.C:38
 checkFile.C:39
 checkFile.C:40
 checkFile.C:41
 checkFile.C:42
 checkFile.C:43
 checkFile.C:44
 checkFile.C:45
 checkFile.C:46
 checkFile.C:47
 checkFile.C:48
 checkFile.C:49
 checkFile.C:50
 checkFile.C:51
 checkFile.C:52
 checkFile.C:53
 checkFile.C:54
 checkFile.C:55