77 parser = ArgumentParser(description="Summarize DQ Defects")
78 a = parser.add_argument
79 add_group = parser.add_argument_group
80
81
82 a(
"-p",
"--project", default=
"data15_13TeV",
83 help="Data project (default: data15_13TeV)")
84 a(
"-P",
"--period", default=
None, nargs=
"*", help=
"Data period(s)")
85 a(
"-r",
"--run", default=
None, nargs=
"*", help=
"Run number(s) to process")
86 a(
"-R",
"--range", help=
"Inclusive run range: e.g. 150000-151000")
87
88
89 a(
"-d",
"--defects", default=
None, nargs=
"*",
90 help="Defects to process. Use * for wildcard (default: None)")
91
92
93 a(
"-q",
"--tree", action=
"store_true",
94 help="Dump virtual defect tree. Set depth with -D")
95
96
97 a(
"-n",
"--num-primary", default=-1, type=int,
98 help="Max number of primary defects to display in default mode (default: all)")
99 a(
"-D",
"--depth", default=-1, type=int,
100 help="Max virtual defect depth to print in virtual tree mode (default: all)")
101 a(
"-c",
"--connection-string", default=DEFAULT_CONNECTION_STRING,
102 help="Database connection to use (default: %s)" % DEFAULT_CONNECTION_STRING)
103 a(
"-l",
"--lumi-tag", default=
'OflLumi-8TeV-002',
104 help="Luminosity tag (default: OflLumi-8TeV-002)")
105 a(
"-t",
"--tag", default=
"HEAD",
106 help="Tag to use (default: HEAD)")
107 a(
"--require-ready", default=
True, type=int,
108 help="Calculate luminosity with respect to ATLAS READY (default: True)")
109 a(
"--reject-busy", default=
False, type=int,
110 help="Calculate luminosity with respect to not-busy (default: False)")
111 a(
"--nb", action=
"store_true", help=
"Show lumi in units of 1/nb instead of 1/pb")
112 a(
"-v",
"--verbose", default=1, type=int,
113 help="Set verbosity (default: 1)")
114
115 args = parser.parse_args()
116
117 init_logger(verbose=args.verbose)
118
119
120 units = 1e3 if args.nb else 1e6
121 unit_string = "(1/nb)" if args.nb else "(1/pb)"
122
123
124 with timer("Instantiate DefectsDB"):
125 db = DefectsDB(args.connection_string, tag=args.tag)
126
127
128
129
130 good_runs = None
131 if args.range:
132 since, until =
map(int, args.range.split(
"-"))
133 elif args.run:
134 good_runs =
set(
map(int, args.run) )
135
136 since, until =
min(good_runs),
max(good_runs)+1
137 else:
138 project_dict = fetch_project_period_runs()
139 if args.period:
140
142 for period in args.period:
143 good_runs.update( project_dict[args.project][period] )
144 since, until =
min(good_runs),
max(good_runs)+1
145 else:
147 for period, period_runs in project_dict[args.project].items():
148 good_runs.update(period_runs)
149 since, until =
min(good_runs),
max(good_runs)+1
150
151
152 iov_range = (since, 0), (until, 0)
153 log.info("Processing range: " + str(iov_range))
154
155
156
157 with timer("Fetch defects"):
158 all_defect_iovs = db.retrieve(*iov_range)
159
160
161 with timer("Fetch defect info"):
162 descriptions = db.all_defect_descriptions
163 intolerables = db.get_intolerable_defects()
164 virtuals = db.virtual_defect_names
165
166
167 with timer("Fetch lumi inputs"):
168 lbs, lumis = fetch_lumi_inputs(iov_range, args.lumi_tag)
169
170
171 with timer("Compute luminosities"):
172
173 exclude_iovs = []
174
175 if args.require_ready:
176 exclude_iovs.append(all_defect_iovs.by_channel["GLOBAL_NOTREADY"])
177
178 if args.reject_busy:
179 exclude_iovs.append(all_defect_iovs.by_channel["GLOBAL_BUSY"])
180
181 lumi_total =
compute_lumi(lbs, lumis, lbs, exclude_iovsets=exclude_iovs,
182 good_runs=good_runs)/units
183
184 lumi_by_defect = compute_lumi_many_channels(lbs, lumis, all_defect_iovs,
185 exclude_iovsets=exclude_iovs,
186 good_runs=good_runs)
187
188 my_defect_names = []
189 if args.defects:
190 all_defect_names = db.defect_names | db.virtual_defect_names
191 for defect_arg in args.defects:
192 my_defect_names.extend(sorted(fnmatch.filter(all_defect_names, defect_arg)))
193
194 logics = db.virtual_defect_logics
195
196
197 all_defects = {}
198 for name, description in sorted(descriptions.items()):
199 virtual, intolerable = name in virtuals, name in intolerables
200 depends = []
201 logic = logics.get(name, None)
202 if logic: depends = logic.clauses
203 all_defects[name] = Defect(name, description, depends, virtual, intolerable,
204 lumi_by_defect.get(name, 0)/units)
205
206
207 my_defects = [ all_defects[d] for d in my_defect_names ]
208 my_defects.sort(key=lambda d: d.lumi, reverse=True)
209
210 print(
"\nTotal luminosity", unit_string,
"\n")
211 print(
"{0:<.2f}".format(lumi_total))
212
213 print(
"\nDefect luminosity", unit_string,
"\n")
214
215
216 for defect in my_defects:
217
218 if args.tree:
219
220 print_virtual_tree(defect, all_defects, depth=0, max_depth=args.depth)
221 else:
222
223 print_primary_defects(defect, all_defects, max_primary=args.num_primary)
224
226
227
void print(char *figname, TCanvas *c1)