forked from marksan87/hcalraw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlook.py
executable file
·187 lines (143 loc) · 5.16 KB
/
look.py
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/usr/bin/env python2
import collections, optparse, os
import graphs, oneRun, printer, utils
from options import oparser
from configuration import sw
def this_machine(run):
out = []
for filename in sw.files_this_machine(run):
if os.path.exists(filename):
out.append(filename)
return out
def local_eos(run):
out = []
for filename in sw.files_eos_local(run):
shortName = filename[filename.find("/store"):]
if not utils.commandOutputFull("eos stat %s" % shortName)["returncode"]:
out.append(filename)
return out
def global_eos(run, hhmmMin=None, quiet=False):
month_num = {"Jan": 1, "Feb": 2, "Mar": 3, "Apr": 4, "May": 5, "Jun": 6,
"Jul": 7, "Aug": 8, "Sep": 9, "Oct": 10, "Nov": 11, "Dec": 12}
for d in sw.dirs_global(run):
shortName = d[d.find(".ch/") + 4:]
stat = utils.commandOutputFull("eos stat %s" % shortName)
if stat["returncode"]:
continue
ll = utils.commandOutputFull("eos ls -l %s" % d)
listings = filter(lambda x: x, ll["stdout"].split("\n"))
coords = []
for listing in listings:
fields = listing.split()
month, day, hhmm, fileName = fields[-4:]
hh, mm = hhmm.split(":")
coords.append((month_num[month], int(day), int(hh), int(mm), fileName))
coords.sort()
if hhmmMin:
mmMin = hhmmMin % 100
hhMin = hhmmMin / 100
coords = filter(lambda x: hhMin < x[2] or (hhMin == x[2] and mmMin <= x[3]), coords)
if not quiet:
for c in coords:
print c
files = []
for c in coords:
files.append(d + c[-1])
return files
def report(fileNames):
pieces = [f.split("/") for f in fileNames]
bases = set(["/".join(piece[:-1]) for piece in pieces])
assert len(bases) == 1, bases
if len(fileNames) == 1:
printer.info("found matching file %s" % fileNames[0])
else:
printer.info("found %4d file(s) in %s/" % (len(fileNames), "/".join(bases)))
def override(options, run, nRuns):
# Only override output file name if default
if options.outputFile == "output/latest.root":
options.outputFile = "output/%d.root" % run
if not options.nEventsMax:
options.nEventsMax = 4
if (not options.quiet) and (nRuns == 1):
options.progress = True
if options.dump == -1:
options.dump = 0
def opts():
parser = oparser(arg="RUN_NUMBER [RUN_NUMBER2 ...]")
look = optparse.OptionGroup(parser, "Options solely for use with look.py")
look.add_option("--quiet",
dest="quiet",
default=False,
action="store_true",
help="Print less to stdout")
look.add_option("--hhmm",
dest="hhmm",
default=None,
type="int",
help="minimum hhmm")
parser.add_option_group(look)
options, args = parser.parse_args()
runs = []
for arg in args:
try:
runs.append(int(arg))
except ValueError:
printer.warning("Could not convert '%s' to an integer." % arg)
if not runs:
printer.error("Please provide a run number as the argument.")
return options, runs
def search(run):
for search_func in [this_machine, local_eos, global_eos]:
files = search_func(run)
# options.file1 = find_gr(run, grDir, options.hhmm, quiet)
if files:
return files
def pruned(files):
pieces = collections.defaultdict(list)
for f in files:
filename = f.split("/")[-1]
pieces[filename].append(f)
out = []
for filename, bases in sorted(pieces.iteritems()):
out.append(sorted(bases)[0])
return out
def go(options, run, nRuns):
override(options, run, nRuns)
files = ["dummy"] if options.noLoop else search(run)
if not files:
printer.warning("Did not find a matching file for run %d." % run)
return 1, None, None
files = pruned(files)
nFiles = len(files)
if 2 <= nFiles:
options.file1 = ",".join(files)
if options.hhmm is None:
options.sparseLoop = max(1, options.nEventsMax / nFiles)
else:
options.sparseLoop = -1
else:
options.file1 = files[0]
sw.set_default_feds1(options)
if not options.quiet:
report(files)
return oneRun.main(options)
def main():
options, runs = opts()
roots = []
feds1s = []
feds2s = []
for run in runs:
retCode, feds1, feds2 = go(options, run, len(runs))
if not retCode:
roots.append(options.outputFile)
feds1s.append(feds1)
feds2s.append(feds2)
if 2 <= len(roots):
for i, stem in enumerate(graphs.all_pages):
graphs.makeSummaryPdfMulti(inputFiles=roots,
feds1s=feds1s,
feds2s=feds2s,
pdf="output/%d_%s.pdf" % (1 + i, stem),
pages=[stem])
if __name__ == "__main__":
main()