ATLAS Offline Software
Loading...
Searching...
No Matches
python.hancoolmod Namespace Reference

Functions

 getLimits (name)
 stringGetResult (file, rootFolder)
 hancool (runNumber=3070, filePath="/afs/cern.ch/user/a/atlasdqm/dqmdisk/han_results/tier0/FDR2/NoStream/", dbConnection="sqlite://;schema=MyCOOL.db;dbname=CONDBR2", isESn=True, stream='', amitag=None)
 detmask_defects (runNumber)
 ctp_defects (d, i, runNumber)
 sct_lowstat_defect (d, i, runNumber)
 sct_conf_defects (d, i, runNumber)
 sct_perlb_defects (d, i, runNumber)
 sct_rod_retraction (d, runNumber, ddb)
 iovs_merge (l)
 sct_eff_defect (d, i, runNumber)
 dqmf_node_defect (node, defect, badstatuses=['Red'])
 hancool_defects (runNumber, filePath="./", dbConnection="", isESn=True, stream='', amitag=None)

Variables

 CWD = os.getcwd()
 defect_val
 defect_iov
 logger = logging.getLogger('hancoolmod')
float LBlength = 1.0
dict intervalType

Function Documentation

◆ ctp_defects()

python.hancoolmod.ctp_defects ( d,
i,
runNumber )

Definition at line 128 of file hancoolmod.py.

128def ctp_defects(d, i, runNumber):
129 mapping = {1: 'TRIG_L1_CTP_CTP_ROD_bcid',
130 2: 'TRIG_L1_CTP_bcid',
131 3: 'TRIG_L1_CTP_CTP_MuCTPI_bcid',
132 4: 'TRIG_L1_CTP_candnumber',
133 5: 'TRIG_L1_CTP_multpt',
134 6: 'TRIG_L1_CTP_roiNum',
135 7: 'TRIG_L1_CTP_roiCand',
136 8: 'TRIG_L1_CTP_bcidrange',
137 9: 'TRIG_L1_CTP_lumiblockrange',
138 10: 'TRIG_L1_CTP_lumiblocktime',
139 11: 'TRIG_L1_CTP_nanosectime',
140 12: 'TRIG_L1_CTP_TAPnoTBP',
141 13: 'TRIG_L1_CTP_TAVnoTAP',
142 14: 'TRIG_L1_CTP_CTPsim',
143 15: 'TRIG_L1_CTP_incompletefragment',
144 # TODO: add missing-orbit bin here, eventually (i.e. 15: 'TRIG_L1_CTP_missingorbit')
145 }
146
147 rv = []
148 when = d.Get('CentralTrigger/ErrorSummary/errorSummaryPerLumiBlock')
149 if not when:
150 return None
151 bad_lbs = {}
152 overflow_bad_lbs = {}
153 for key in mapping:
154 bad_lbs[key] = []
155
156 # loop over error bin numbers defined in dict above
157 for errorBin in mapping:
158 bad_lbs[errorBin] = [bin for bin in range(1, when.GetNbinsX(
159 )+1) if when.GetBinContent(bin, errorBin) > 0] # fix this line, slicing in Y? is that it?
160 overflow_bad_lbs[errorBin] = (
161 when.GetBinContent(when.GetNbinsX()+1, errorBin) > 0)
162
163 message = 'Automatically set'
164
165 for defect in mapping:
166 for lb in bad_lbs[defect]:
167 rv.append(defect_iov(mapping[defect], message, False, lb, lb+1))
168 if overflow_bad_lbs[defect]:
169 message += '; defect occurred past end of monitoring histogram, marking end of run as bad'
170 from . import detmaskmod # ugly: could happen for more than one defect - should be cheap though
171 nlbs = detmaskmod.getNumLumiBlocks(runNumber)
172 rv.append(defect_iov(defect, message,
173 False, when.GetNbinsX(), nlbs+1))
174 # print "The following defects were extracted: " # TODO: remove this line?
175 # print rv # TODO: remove this line?
176 return rv
177
178

◆ detmask_defects()

python.hancoolmod.detmask_defects ( runNumber)

Definition at line 112 of file hancoolmod.py.

112def detmask_defects(runNumber):
113 from . import detmaskmod
114 blacks = detmaskmod.decodeBlack(detmaskmod.getRunMask(runNumber),
115 defects=True)
116 nlbs = detmaskmod.getNumLumiBlocks(runNumber)
117 toinsert = []
118 for defect in blacks:
119 toinsert.append(defect_iov(since=1,
120 until=nlbs+1,
121 defect=defect,
122 recoverable=False,
123 comment='Automatically added by hancool')
124 )
125 return toinsert
126
127

◆ dqmf_node_defect()

python.hancoolmod.dqmf_node_defect ( node,
defect,
badstatuses = ['Red'] )

Definition at line 348 of file hancoolmod.py.

348def dqmf_node_defect(node, defect, badstatuses=['Red']):
349 badstatuses = set(badstatuses)
350
351 def dqmf_node_defect_core(d, i, runNumber):
352 filenode = d.Get(node + '_/Results/Status')
353 if not filenode:
354 return None
355 status = set(x.GetName() for x in filenode.GetListOfKeys())
356 if len(badstatuses & status) > 0:
357 assert len(
358 status) == 1, 'Status must be length one or the file is corrupt'
359 return [defect_val(defect, node + ' DQMF color ' + status.pop(), False)]
360 else:
361 return []
362 return dqmf_node_defect_core
363
364
STL class.

◆ getLimits()

python.hancoolmod.getLimits ( name)

Definition at line 47 of file hancoolmod.py.

47def getLimits(name):
48 try:
49 import re
50 from . import detmaskmod
51 runNumber = re.match(r'run_(\d+)_.*han.root', name).group(1)
52 max_hi_limit = detmaskmod.getNumLumiBlocks(int(runNumber))+1
53 if (name.find('minutes10_') > -1):
54 t = name.split('minutes10_')
55 digit = float(((t[len(t)-1]).split('_'))[0])
56 low_limit = int((digit-1.0)*10.0/LBlength+1)-1
57 hi_limit = int(digit*10.0/LBlength)
58 elif (name.find('minutes30_') > -1):
59 t = name.split('minutes30_')
60 digit = float(((t[len(t)-1]).split('_'))[0])
61 low_limit = int((digit-1.0)*30.0/LBlength+1)-1
62 hi_limit = int(digit*30.0/LBlength)
63 elif 'lowStat_' in name:
64 t = name.split('lowStat_LB')[-1]
65 t = t.split('_han.root')[0]
66 digits = t.split('-')
67 low_limit = int(digits[0])
68 hi_limit = min(int(digits[1])+1, max_hi_limit)
69 elif 'medStat_' in name:
70 t = name.split('medStat_LB')[-1]
71 t = t.split('_han.root')[0]
72 digits = t.split('-')
73 low_limit = int(digits[0])
74 hi_limit = min(int(digits[1])+1, max_hi_limit)
75 else:
76 low_limit = 1
77 hi_limit = max_hi_limit
78 except Exception as e:
79 logging.warning('Could not determine limits because: %s', e)
80 low_limit = 1
81 hi_limit = 4294967295
82
83 return (low_limit, hi_limit)
84
85# Looks up the result in the HanOutputFile
86
87
#define min(a, b)
Definition cfImp.cxx:40
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:179

◆ hancool()

python.hancoolmod.hancool ( runNumber = 3070,
filePath = "/afs/cern.ch/user/a/atlasdqm/dqmdisk/han_results/tier0/FDR2/NoStream/",
dbConnection = "sqlite://;schema=MyCOOL.db;dbname=CONDBR2",
isESn = True,
stream = '',
amitag = None )

Definition at line 103 of file hancoolmod.py.

105 dbConnection="sqlite://;schema=MyCOOL.db;dbname=CONDBR2", isESn=True, stream='', amitag=None):
106
107 logger.info('====> Running hancool_defects')
108 hancool_defects(runNumber, filePath, dbConnection, isESn, stream, amitag)
109 logger.info('<==== Done with hancool_defects')
110
111

◆ hancool_defects()

python.hancoolmod.hancool_defects ( runNumber,
filePath = "./",
dbConnection = "",
isESn = True,
stream = '',
amitag = None )

Definition at line 365 of file hancoolmod.py.

365def hancool_defects(runNumber, filePath="./", dbConnection="", isESn=True, stream='', amitag=None):
366 from . import pix_defect
367 isUPCESn = (amitag is not None and 'x' in amitag and stream == 'UPC')
368 analyzers = []
369 if isESn:
370 # CTP
371 analyzers += [ctp_defects]
372 # SCT
373 analyzers += [sct_eff_defect,
374 sct_lowstat_defect,
375 sct_conf_defects,
376 sct_perlb_defects,
377 ]
378 elif isUPCESn:
379 # Heavy-ion UPC express: SCT defects only, no CTP or pixel
380 analyzers += [sct_eff_defect,
381 sct_lowstat_defect,
382 sct_conf_defects,
383 sct_perlb_defects,
384 ]
385
386 if (len(filePath) == 0 or filePath[-1] != '/'):
387 filePath += "/"
388 if (len(dbConnection) < 1):
389 dbConnection = "/afs/cern.ch/user/a/atlasdqm/dqmdisk1/cherrypy-devel/defectstest.db/COMP200"
390
391 import ROOT
392 # Conflict logic: shorter intervals override longer ones
393 defects_by_function = {}
394
395 # empty list for missing high stat, reserved for future use
396
397 fnames = ([[filePath+"run_"+str(runNumber)+"_han.root"], []]
398 + [glob.glob(os.path.join(filePath, 'run_%s%s*_han.root' % (runNumber, intervalType[i]))) for i in [2, 3]])
399
400 for i, itype in enumerate(fnames):
401 ldefects_by_function = {}
402 for globname in itype:
403 filename = os.path.basename(globname)
404
405 since, until = getLimits(filename)
406 default_iov = defect_iov(*([0]*5))
407 default_iov = default_iov._replace(since=since, until=until)
408 #print filename + ':', since, until
409 fobj = ROOT.TFile.Open(globname)
410 for func in analyzers:
411 rv = func(fobj, i, runNumber)
412 if rv is not None:
413 rvt = [default_iov._replace(**(i._asdict())) for i in rv]
414 if func not in ldefects_by_function:
415 ldefects_by_function[func] = rvt
416 else:
417 ldefects_by_function[func] += rvt
418 defects_by_function.update(ldefects_by_function)
419 defects = sum(defects_by_function.values(), [])
420
421 if isESn:
422 globname = fnames[0][0]
423 filename = os.path.basename(globname)
424 since, until = getLimits(filename)
425 try:
426 defects += pix_defect.execute(runNumber, globname, until-1)
427 except Exception as e:
428 logging.warning('Unable to execute pixel hancool code')
429 logging.warning('--> %s: %s', type(e).__name__, e)
430
431 from DQDefects import DefectsDB, DEFECT_IOV
432 from DQUtils.sugar import RunLumi
433 import json
434 ddb = DefectsDB(dbConnection, read_only=False)
435 use_flask = 'sqlite' not in dbConnection
436 if use_flask:
437 secret_path = os.environ.get('COOLFLASK_SECRET', '/afs/cern.ch/user/a/atlasdqm/private/coolflask_secret/coolflask_secret.json')
438 auth = json.loads(open(secret_path).read())
439 else:
440 auth = {}
441
442 if isESn:
443 logging.info('Running detmask_defects')
444 dm_defects = detmask_defects(runNumber)
445
446 defectlist = []
447 for defect in dm_defects + iovs_merge(defects):
448 logger.debug('Working with %s', defect)
449 defectlist.append(DEFECT_IOV(RunLumi(runNumber, defect.since),
450 RunLumi(runNumber, defect.until),
451 channel=defect.defect,
452 comment=defect.comment,
453 present=True,
454 recoverable=defect.recoverable,
455 user='sys:hancool'))
456 logger.debug('Flask upload')
457 ddb.insert_multiple(defectlist, use_flask=use_flask, flask_auth=auth)
458
459 elif isUPCESn and defects:
460 # Heavy-ion UPC express pass: insert SCT defects collected from analyzers above
461 defectlist = [DEFECT_IOV(RunLumi(runNumber, d.since),
462 RunLumi(runNumber, d.until),
463 channel=d.defect,
464 comment=d.comment,
465 present=True,
466 recoverable=d.recoverable,
467 user='sys:hancool')
468 for d in iovs_merge(defects)]
469 logger.debug('Flask upload (UPC express SCT defects)')
470 ddb.insert_multiple(defectlist, use_flask=use_flask, flask_auth=auth)
471
472 elif stream == 'Main' and fnames[0]:
473 # physics_Main pass: cross-check previously auto-set SCT_ROD_OUT against
474 # physics_Main histogram and retract any LBs that no longer meet the threshold
475 fpath = fnames[0][0]
476 if not os.path.exists(fpath):
477 logger.warning('sct_rod_retraction: file not found: %s', fpath)
478 else:
479 fobj = ROOT.TFile.Open(fpath)
480 try:
481 retract_list = sct_rod_retraction(fobj, runNumber, ddb)
482 if retract_list:
483 logger.debug('Flask upload (retraction)')
484 ddb.insert_multiple(retract_list, use_flask=use_flask, flask_auth=auth)
485 except Exception:
486 logger.exception('sct_rod_retraction failed for run %d', runNumber)
487 finally:
488 fobj.Close()
IovVectorMap_t read(const Folder &theFolder, const SelectionCriterion &choice, const unsigned int limit=10)

◆ iovs_merge()

python.hancoolmod.iovs_merge ( l)

Definition at line 303 of file hancoolmod.py.

303def iovs_merge(l):
304 l.sort(key=lambda x: x.since)
305 rl = []
306 i = 0
307 previous = None
308 until = -1
309 while i < len(l):
310 if not previous:
311 previous = l[i]
312 until = previous.until
313 else:
314 if l[i].since != until or previous.comment != l[i].comment:
315 # we have no more to merge for this range
316 rl.append(previous._replace(until=until))
317 previous = l[i]
318 until = previous.until
319 else:
320 until = l[i].until
321 i += 1
322 if previous:
323 rl.append(previous._replace(until=until))
324 return rl
325
326

◆ sct_conf_defects()

python.hancoolmod.sct_conf_defects ( d,
i,
runNumber )

Definition at line 189 of file hancoolmod.py.

189def sct_conf_defects(d, i, runNumber):
190 def sct_conf_defects_core(d, i, runNumber, histname, mapping):
191 rv = []
192 histogram = d.Get(histname)
193 if not histogram:
194 return None
195 for bin in mapping:
196 threshold = 40
197 if mapping[bin] == 'SCT_MOD_OUT_GT40':
198 threshold = 80
199 if histogram.GetBinContent(bin) > threshold:
200 rv.append(defect_val(
201 mapping[bin], '%.1d modules affected' % histogram.GetBinContent(bin), False))
202 return rv
203
204 rv1 = sct_conf_defects_core(d, i, runNumber, 'InnerDetector/SCT/Summary/SCTConfOutM',
205 {1: 'SCT_MOD_OUT_GT40'})
206 rv2 = sct_conf_defects_core(d, i, runNumber, 'InnerDetector/SCT/Summary/SCTConfNew',
207 {3: 'SCT_MOD_ERR_GT40',
208 5: 'SCT_MOD_NOISE_GT40'})
209 if rv1 is None and rv2 is None:
210 return None
211 else:
212 return (rv1 if rv1 is not None else [])+(rv2 if rv2 is not None else [])
213
214

◆ sct_eff_defect()

python.hancoolmod.sct_eff_defect ( d,
i,
runNumber )

Definition at line 327 of file hancoolmod.py.

327def sct_eff_defect(d, i, runNumber):
328 h1 = d.Get('InnerDetector/SCT/Summary/SctTotalEffBCID_/Results/Status')
329 h2 = d.Get('InnerDetector/SCT/Summary/SctTotalEff_/Results/Status')
330 if not h1 or not h2:
331 return None
332 badstatuses = {'Yellow', 'Red'}
333 statuscheck = []
334 for h in h1, h2:
335 status = set(x.GetName() for x in h.GetListOfKeys())
336 if len(badstatuses & status) > 0:
337 assert len(
338 status) == 1, 'Status must be length one or the file is corrupt'
339 statuscheck.append(True)
340 else:
341 statuscheck.append(False)
342 if all(statuscheck):
343 return [defect_val('SCT_EFF_LT99', 'Automatically set for whole run', False)]
344 else:
345 return []
346
347

◆ sct_lowstat_defect()

python.hancoolmod.sct_lowstat_defect ( d,
i,
runNumber )

Definition at line 179 of file hancoolmod.py.

179def sct_lowstat_defect(d, i, runNumber):
180 histogram = d.Get('InnerDetector/SCT/Summary/tracksPerRegion')
181 if not histogram:
182 return None
183 if histogram.GetEntries() < 200:
184 return [defect_val('SCT_GLOBAL_LOWSTAT', 'Low statistics', False)]
185 else:
186 return []
187
188

◆ sct_perlb_defects()

python.hancoolmod.sct_perlb_defects ( d,
i,
runNumber )

Definition at line 215 of file hancoolmod.py.

215def sct_perlb_defects(d, i, runNumber):
216 pairs = [('InnerDetector/SCT/Summary/SCT_LinksWithLinkLevelErrorsVsLbs',
217 'SCT_PERIOD_ERR_GT40', lambda _: _ > 80),
218 ('InnerDetector/SCT/Summary/SCT_LinksWithRODLevelErrorsVsLbs',
219 'SCT_ROD_OUT', lambda _: _ >= 1)]
220
221 rv = []
222 bad_lbs = {}
223 overflow_bad_lbs = {}
224 message = 'Automatically set'
225 foundany = False
226
227 for hname, dname, policy in pairs:
228 when = d.Get(hname)
229 if not when:
230 continue
231 foundany = True
232
233 # extract bad bins
234 bad_lbs[dname] = [bin for bin in range(
235 1, when.GetNbinsX()+1) if policy(when.GetBinContent(bin))]
236 overflow_bad_lbs[dname] = policy(
237 when.GetBinContent(when.GetNbinsX()+1))
238
239 for lb in bad_lbs[dname]:
240 rv.append(defect_iov(dname, message, False, lb, lb+1))
241 if overflow_bad_lbs[dname]:
242 message += '; defect occurred past end of monitoring histogram, marking end of run as bad'
243 from . import detmaskmod # ugly: could happen for more than one defect - should be cheap though
244 nlbs = detmaskmod.getNumLumiBlocks(runNumber)
245 rv.append(defect_iov(dname, message,
246 False, when.GetNbinsX(), nlbs+1))
247 if foundany:
248 return rv
249 else:
250 return None
251
252

◆ sct_rod_retraction()

python.hancoolmod.sct_rod_retraction ( d,
runNumber,
ddb )

Definition at line 253 of file hancoolmod.py.

253def sct_rod_retraction(d, runNumber, ddb):
254 from DQDefects import DEFECT_IOV
255 from DQUtils.sugar import RunLumi
256
257 histogram = d.Get('InnerDetector/SCT/Summary/SCT_LinksWithRODLevelErrorsVsLbs')
258 if not histogram:
259 logger.warning('sct_rod_retraction: histogram not found in physics_Main, skipping')
260 return []
261
262 existing = ddb.retrieve(RunLumi(runNumber, 0), RunLumi(runNumber, 0xFFFFFFFF),
263 channels=['SCT_ROD_OUT'], primary_only=True)
264 auto_set = [iov for iov in existing if iov.user == 'sys:hancool' and iov.present]
265
266 if not auto_set:
267 logger.info('sct_rod_retraction: no auto-set SCT_ROD_OUT found for run %d', runNumber)
268 return []
269
270 logger.info('sct_rod_retraction: found %d auto-set SCT_ROD_OUT IOV(s) for run %d',
271 len(auto_set), runNumber)
272
273 # Retract LBs where physics_Main does not satisfy the original assignment policy (>= 1)
274 rod_out_policy = lambda _: _ >= 1
275 clean_lbs = []
276 for iov in auto_set:
277 for lb in range(iov.since.lumi, iov.until.lumi):
278 if lb > histogram.GetNbinsX():
279 logger.warning('sct_rod_retraction: LB %d beyond histogram range, skipping', lb)
280 continue
281 if not rod_out_policy(histogram.GetBinContent(lb)):
282 clean_lbs.append(defect_iov('SCT_ROD_OUT',
283 'Retracted: no ROD errors in physics_Main',
284 False, lb, lb + 1))
285
286 if not clean_lbs:
287 logger.info('sct_rod_retraction: no LBs to retract for run %d', runNumber)
288 return []
289
290 merged = iovs_merge(clean_lbs)
291 logger.info('sct_rod_retraction: retracting %d IOV(s) for run %d', len(merged), runNumber)
292
293 return [DEFECT_IOV(RunLumi(runNumber, r.since),
294 RunLumi(runNumber, r.until),
295 channel=r.defect,
296 comment=r.comment,
297 present=False,
298 recoverable=False,
299 user='sys:hancool')
300 for r in merged]
301
302

◆ stringGetResult()

python.hancoolmod.stringGetResult ( file,
rootFolder )

Definition at line 88 of file hancoolmod.py.

88def stringGetResult(file, rootFolder):
89 rootFolder = file+":"+rootFolder
90 of = dqutils.HanOutputFile(file)
91# result = of.getStatus(rootFolder) #until DataQualityUtils-02-02-00
92 result = of.getStringName(rootFolder)
93 return result
94
95# /afs/cern.ch/user/a/atlasdqm/dqmdisk/han_results/tier0/FDR2/NoStream/run_3070_han.root
96
97# path="/afs/cern.ch/user/a/atlasdqm/dqmdisk/han_results/tier0/physics_HLT_Cosmic_AllTeIDSelected/"
98# path="/afs/cern.ch/user/a/atlasdqm/dqmdisk/han_results/tier0/FDR2/NoStream/"
99
100# -------------------------------------------------------------
101
102

Variable Documentation

◆ CWD

python.hancoolmod.CWD = os.getcwd()

Definition at line 9 of file hancoolmod.py.

◆ defect_iov

python.hancoolmod.defect_iov
Initial value:
1= collections.namedtuple('defect_iov',
2 'defect, comment, recoverable, since, until')

Definition at line 24 of file hancoolmod.py.

◆ defect_val

python.hancoolmod.defect_val
Initial value:
1= collections.namedtuple('defect_val',
2 'defect, comment, recoverable')

Definition at line 22 of file hancoolmod.py.

◆ intervalType

dict python.hancoolmod.intervalType
Initial value:
1= {
2 0: "_minutes30_",
3 1: "_minutes10_",
4 2: "_medStat_",
5 3: "_lowStat_",
6 4: "ERROR"
7}

Definition at line 38 of file hancoolmod.py.

◆ LBlength

float python.hancoolmod.LBlength = 1.0

Definition at line 34 of file hancoolmod.py.

◆ logger

python.hancoolmod.logger = logging.getLogger('hancoolmod')

Definition at line 27 of file hancoolmod.py.