1 #if !defined( __CINT__) || defined(__MAKECINT__)
10 Bool_t checkFile(const char* filename)
12 // This macro returns FALSE in the following cases:
13 // - the file doesn't exist
14 // - the file is not readable
15 // - the file is not a Root file
16 // - the file is truncated
17 // If the file is opened without any Error message,
18 // the macro returns kTRUE
20 // checkname is string with appended .check, i.e. Kinematics.root.check
21 // The output of TFile::Open will be stored there
22 TString checkname = filename;
23 checkname += ".check";
25 // remove checkname, if it already exists
26 gSystem->Unlink(checkname.Data());
28 // Copy and store the original stream desriptors
29 Int_t origstdout = dup(fileno(stdout));
30 Int_t origstderr = dup(fileno(stderr));
32 // Redirect the output
33 freopen(checkname.Data(),"w",stdout);
34 dup2(fileno(stdout),fileno(stderr));
36 // Try to open the file. The output goes to the file checkname
39 // Restore the original stream descriptors
40 dup2(origstdout,fileno(stdout));
41 dup2(origstderr,fileno(stderr));
43 // Prepare the grep command, executed by the shell, for example
44 // grep Error Kinematics.root.check > /dev/null 2>&1
45 TString command = "grep Error ";
47 command += " > /dev/null 2>&1";
48 // Execute the command. The return value is 0 if Error is found
49 Bool_t result = gSystem->Exec(command.Data());
51 // Remove the checkname
52 gSystem->Unlink(checkname.Data());