]>
Commit | Line | Data |
---|---|---|
dd412354 | 1 | #if !defined( __CINT__) || defined(__MAKECINT__) |
2 | #include <stdio.h> | |
3 | #include <unistd.h> | |
4 | #include <TString.h> | |
5 | #include <TSystem.h> | |
6 | #include <TROOT.h> | |
7 | #include <TFile.h> | |
8 | #endif | |
9 | ||
10 | Bool_t checkFile(const char* filename) | |
11 | { | |
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 | |
19 | ||
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"; | |
24 | ||
25 | // remove checkname, if it already exists | |
26 | gSystem->Unlink(checkname.Data()); | |
27 | ||
28 | // Copy and store the original stream desriptors | |
29 | Int_t origstdout = dup(fileno(stdout)); | |
30 | Int_t origstderr = dup(fileno(stderr)); | |
31 | ||
32 | // Redirect the output | |
33 | freopen(checkname.Data(),"w",stdout); | |
34 | dup2(fileno(stdout),fileno(stderr)); | |
35 | ||
36 | // Try to open the file. The output goes to the file checkname | |
37 | TFile f(filename); | |
38 | ||
39 | // Restore the original stream descriptors | |
40 | dup2(origstdout,fileno(stdout)); | |
41 | dup2(origstderr,fileno(stderr)); | |
42 | ||
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 "; | |
46 | command += checkname; | |
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()); | |
50 | ||
51 | // Remove the checkname | |
52 | gSystem->Unlink(checkname.Data()); | |
53 | return result; | |
54 | } |