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
371 analyzers += [ctp_defects]
372
373 analyzers += [sct_eff_defect,
374 sct_lowstat_defect,
375 sct_conf_defects,
376 sct_perlb_defects,
377 ]
378 elif isUPCESn:
379
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
393 defects_by_function = {}
394
395
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
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
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
474
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)