315def hancool_defects(runNumber, filePath="./", dbConnection="", isESn=True):
316 from . import pix_defect
317 analyzers = []
318 if isESn:
319
320 analyzers += [ctp_defects]
321
322 analyzers += [sct_eff_defect,
323 sct_lowstat_defect,
324 sct_conf_defects,
325 sct_perlb_defects,
326 ]
327
328 if (len(filePath) == 0 or filePath[-1] != '/'):
329 filePath += "/"
330 if (len(dbConnection) < 1):
331 dbConnection = "/afs/cern.ch/user/a/atlasdqm/dqmdisk1/cherrypy-devel/defectstest.db/COMP200"
332
333 import ROOT
334
335 defects_by_function = {}
336
337
338
339 fnames = ([[filePath+"run_"+str(runNumber)+"_han.root"], []]
340 + [glob.glob(os.path.join(filePath, 'run_%s%s*_han.root' % (runNumber, intervalType[i]))) for i in [2, 3]])
341
342 for i, itype in enumerate(fnames):
343 ldefects_by_function = {}
344 for globname in itype:
345 filename = os.path.basename(globname)
346
347 since, until = getLimits(filename)
348 default_iov = defect_iov(*([0]*5))
349 default_iov = default_iov._replace(since=since, until=until)
350
351 fobj = ROOT.TFile.Open(globname)
352 for func in analyzers:
353 rv = func(fobj, i, runNumber)
354 if rv is not None:
355 rvt = [default_iov._replace(**(i._asdict())) for i in rv]
356 if func not in ldefects_by_function:
357 ldefects_by_function[func] = rvt
358 else:
359 ldefects_by_function[func] += rvt
360 defects_by_function.update(ldefects_by_function)
361 defects = sum(defects_by_function.values(), [])
362
363 if isESn:
364 globname = fnames[0][0]
365 filename = os.path.basename(globname)
366 since, until = getLimits(filename)
367 try:
368 defects += pix_defect.execute(runNumber, globname, until-1)
369 except Exception as e:
370 logging.warning('Unable to execute pixel hancool code')
371 logging.warning(
'--> %s: %s',
type(e).__name__, e)
372
373 from DQDefects import DefectsDB, DEFECT_IOV
374 from DQUtils.sugar import RunLumi
375 import json
376 ddb = DefectsDB(dbConnection, read_only=False)
377 if isESn:
378 logging.info('Running detmask_defects')
379 dm_defects = detmask_defects(runNumber)
380
381 defectlist = []
382 for defect in dm_defects + iovs_merge(defects):
383 logger.debug('Working with %s', defect)
384 defectlist.append(DEFECT_IOV(RunLumi(runNumber, defect.since),
385 RunLumi(runNumber, defect.until),
386 channel=defect.defect,
387 comment=defect.comment,
388 present=True,
389 recoverable=defect.recoverable,
390 user='sys:hancool'))
391 secret_path=os.environ.get('COOLFLASK_SECRET', '/afs/cern.ch/user/a/atlasdqm/private/coolflask_secret/coolflask_secret.json')
392 auth = json.loads(open(secret_path).
read())
393 logger.debug('Flask upload')
394 ddb.insert_multiple(defectlist, use_flask=('sqlite' not in dbConnection),
395 flask_auth=auth)
IovVectorMap_t read(const Folder &theFolder, const SelectionCriterion &choice, const unsigned int limit=10)