-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzf.cpp
More file actions
100 lines (87 loc) · 2.3 KB
/
Copy pathzf.cpp
File metadata and controls
100 lines (87 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <fstream>
#include <iostream>
#include <unistd.h>
#include <cstdlib>
#include <TFile.h>
#include <TError.h>
// finds root files that have not been closed properly
// needs:
// source /cvmfs/grid.cern.ch/umd-sl6ui-test/etc/profile.d/setup-ui-example.sh
// source /cvmfs/lz.opensciencegrid.org/ROOT/v5.34.32/slc6_gcc44_x86_64/root/bin/thisroot.sh
// input file is generated using
// ./lisfiles.sh 01
int main(int argc, const char **argv)
{
// Disable ROOT error messages
gErrorIgnoreLevel = 5000;
// Get the file name
if (argc != 2)
{
std::cerr << "Usage: zf <input_file>" << std::endl << std::endl;
return 1;
}
// Make sure the prefered ROOT version is setup
std::string rootver = "";
char * rs = getenv("ROOTSYS");
if (rs != NULL) { rootver = rs; }
else { std::cerr << "ROOTSYS not set." << std::endl; return 1;}
if (rootver != "/cvmfs/lz.opensciencegrid.org/ROOT/v5.34.32/slc6_gcc44_x86_64/root") {
std::cerr << "LZ ROOT version expected, got " << rootver << " instead." << std::endl;
return 1;
}
std::ifstream xFD(argv[1]);
std::string xPath;
while (xFD.good())
{
xFD >> xPath;
// Fast path for EOF
if (!xFD.good())
break;
int xRetry = 0;
for (xRetry = 0; xRetry < 3; xRetry++)
{
bool isBad = false;
// Test the file
TFile *xFile = TFile::Open(xPath.c_str());
if (xFile)
{
if (xFile->TestBit(TFile::kRecovered))
{
std::cerr << "Recovered file: " << xPath << std::endl;
isBad = true;
}
else if (xFile->IsZombie())
{
std::cerr << "Zombile file: " << xPath << std::endl;
isBad = true;
}
}
else
{
std::cerr << "Failed to open: " << xPath << std::endl;
sleep(xRetry + 1);
continue;
}
if (isBad)
{
std::cout << xPath << std::endl;
} else
{
std::cerr << "File is OK: " << xPath << std::endl;
}
// Tidy up
if (xFile)
{
xFile->Close();
delete xFile;
}
break;
} // for
if (xRetry == 3)
{
std::cerr << "Totally failed to open: " << xPath << std::endl;
std::cout << xPath << std::endl;
}
} // while
return 0;
}