3 from DQDefects
import DefectsDB
4 from DQUtils
import IOVSet, process_iovs, define_iov_type
5 from DQUtils.sugar
import RunLumi, RANGEIOV_VAL
6 from DQUtils.periods
import fetch_project_period_runs
10 "A set of defect names present for each IoV"
14 "Lists of defects only present in one tag or the other"
18 Return a list of iovs with a set for each IoV containing the present defects
20 chans, iovsets = defect_iovs.chans_iovsets
23 for since, until, states
in process_iovs(range_iovs, *iovsets):
24 in_range, defects = states[0], states[1:]
26 result.add(since, until,
set(d.channel
for d
in defects
if d))
28 return result.solidify(DEFECTSET_VAL)
32 Return a list of IoVs containing the set of defects only present in
36 defectset = ((since, until,
37 (t1.defects
if t1
else set(), t2.defects
if t2
else set()))
38 for since, until, (t1, t2)
in process_iovs(defects1, defects2))
39 for since, until, (t1defects, t2defects)
in defectset:
40 if t1defects == t2defects:
43 diff = t1defects.symmetric_difference(t2defects)
44 if ignore_not_considered
and "GLOBAL_NOTCONSIDERED" in diff:
47 tag1only, tag2only = t1defects & diff, t2defects & diff
50 tag1only =
set(x.split(
"_")[0]
for x
in tag1only)
51 tag2only =
set(x.split(
"_")[0]
for x
in tag2only)
53 result.add(since, until, tag1only, tag2only)
55 return result.solidify(DEFECTDIFF_VAL)
62 from argparse
import ArgumentParser, FileType
64 p = ArgumentParser(description=
"Compute differences in the defects "
65 "database between tags")
67 arg(
"tags", metavar=
"DetStatus-Tag", nargs=2, type=str,
68 help=
"Two tags to show the difference between")
69 arg(
"-p",
"--project", default=
None,
70 help=
"Limit considered runs to those in project")
71 arg(
"-P",
"--period", default=
None, help=
"Data period")
72 arg(
"-r",
"--run", type=int, help=
"Run number to process")
73 arg(
"-R",
"--range", help=
"Run range: e.g. 150000-151000")
74 arg(
"-d",
"--defect", action=
"append", dest=
"defects", default=
None,
75 help=
"Defects to show the difference between. "
76 "(If empty, show all. -d can be specified multiple times.)")
77 arg(
"-i",
"--ignore-not-considered", action=
"store_true",
78 help=
"Ignore ranges in which GLOBAL_NOTCONSIDERED is set for either tag")
79 arg(
"--output", default=sys.stdout, type=FileType(
"w"),
80 help=
"Place to out the output (Default stdout)")
81 arg(
"-s",
"--by-system", action=
"store_true",
82 help=
"If specified, show systems which differ, not defects")
83 arg(
"-v",
"--virtual", action=
"store_true",
84 help=
"If specified, show virtual defect differences as well as primary"
85 " (produces a lot of output)")
90 tag1, tag2 = args.tags
93 since, until =
None,
None
99 since, until = (args.run, 0), (args.run+1, 0)
100 range_iovs = IOVSet.from_runs([args.run])
102 run1, run2 = map(int, args.range.split(
"-"))
103 since, until = (run1, 0), (run2, 0)
113 period_dict = project_dict[args.project]
118 runs =
set(period_dict[args.period])
121 for period, period_runs
in period_dict.iteritems():
122 runs.update(period_runs)
124 since, until = (
min(runs), 0), (
max(runs)+1, 0)
125 range_iovs = IOVSet.from_runs(runs)
128 print(
'range to process:')
129 print(
'since, until =', since, until)
134 kwargs = dict(primary_only=
not args.virtual, channels=args.defects, since=since, until=until)
136 def fetch_defects(tag):
140 print(
"Retrieving defects..")
141 defects1, defects2 = fetch_defects(tag1), fetch_defects(tag2)
144 print(
"Computing diff..")
145 diff_iovs =
make_defectdiff_iovs(defects1, defects2, args.by_system, args.ignore_not_considered)
146 for since, until, t1, t2
in diff_iovs:
149 if __name__ ==
"__main__":
150 raise SystemExit(
main())