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)
 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)
 iovs_merge (l)
 sct_eff_defect (d, i, runNumber)
 dqmf_node_defect (node, defect, badstatuses=['Red'])
 hancool_defects (runNumber, filePath="./", dbConnection="", isESn=True)

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 296 of file hancoolmod.py.

296def dqmf_node_defect(node, defect, badstatuses=['Red']):
297 badstatuses = set(badstatuses)
298
299 def dqmf_node_defect_core(d, i, runNumber):
300 filenode = d.Get(node + '_/Results/Status')
301 if not filenode:
302 return None
303 status = set(x.GetName() for x in filenode.GetListOfKeys())
304 if len(badstatuses & status) > 0:
305 assert len(
306 status) == 1, 'Status must be length one or the file is corrupt'
307 return [defect_val(defect, node + ' DQMF color ' + status.pop(), False)]
308 else:
309 return []
310 return dqmf_node_defect_core
311
312
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 )

Definition at line 103 of file hancoolmod.py.

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

◆ hancool_defects()

python.hancoolmod.hancool_defects ( runNumber,
filePath = "./",
dbConnection = "",
isESn = True )

Definition at line 313 of file hancoolmod.py.

313def hancool_defects(runNumber, filePath="./", dbConnection="", isESn=True):
314 from . import pix_defect
315 analyzers = []
316 if isESn:
317 # CTP
318 analyzers += [ctp_defects]
319 # SCT
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 # Conflict logic: shorter intervals override longer ones
333 defects_by_function = {}
334
335 # empty list for missing high stat, reserved for future use
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 #print filename + ':', since, until
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)

◆ iovs_merge()

python.hancoolmod.iovs_merge ( l)

Definition at line 251 of file hancoolmod.py.

251def iovs_merge(l):
252 l.sort(key=lambda x: x.since)
253 rl = []
254 i = 0
255 previous = None
256 until = -1
257 while i < len(l):
258 if not previous:
259 previous = l[i]
260 until = previous.until
261 else:
262 if l[i].since != until or previous.comment != l[i].comment:
263 # we have no more to merge for this range
264 rl.append(previous._replace(until=until))
265 previous = l[i]
266 until = previous.until
267 else:
268 until = l[i].until
269 i += 1
270 if previous:
271 rl.append(previous._replace(until=until))
272 return rl
273
274

◆ 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 275 of file hancoolmod.py.

275def sct_eff_defect(d, i, runNumber):
276 h1 = d.Get('InnerDetector/SCT/Summary/SctTotalEffBCID_/Results/Status')
277 h2 = d.Get('InnerDetector/SCT/Summary/SctTotalEff_/Results/Status')
278 if not h1 or not h2:
279 return None
280 badstatuses = {'Yellow', 'Red'}
281 statuscheck = []
282 for h in h1, h2:
283 status = set(x.GetName() for x in h.GetListOfKeys())
284 if len(badstatuses & status) > 0:
285 assert len(
286 status) == 1, 'Status must be length one or the file is corrupt'
287 statuscheck.append(True)
288 else:
289 statuscheck.append(False)
290 if all(statuscheck):
291 return [defect_val('SCT_EFF_LT99', 'Automatically set for whole run', False)]
292 else:
293 return []
294
295

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

◆ 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.