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