3 from RecoLuminosity.LumiDB
import nameDealer,lumiTime,CommonUtil,lumiCorrections
8 from RecoLuminosity.LumiDB
import nameDealer, selectionParser, hltTrgSeedMapper, \
9 connectstrParser, cacheconfigParser, tablePrinter, csvReporter, csvSelectionParser
10 from RecoLuminosity.LumiDB.wordWrappers
import wrap_always, wrap_onspace, wrap_onspace_strict
11 from pprint
import pprint, pformat
14 This module defines lowlevel SQL query API for lumiDB 15 We do not like range queries so far because of performance of range scan.Use only necessary. 16 The principle is to query by runnumber and per each coral queryhandle 17 Try reuse db session/transaction and just renew query handle each time to reduce metadata queries. 18 Avoid unnecessary explicit order by 19 Do not handle transaction in here. 20 Do not do explicit del queryhandle in here. 21 Note: all the returned dict format are not sorted by itself.Sort it outside if needed. 49 '''Given the rotation rate, calculate lumi section length and 50 rotation time. This should be called if rotationRate is 56 return '''<frontier-connect><proxy url = "http://cmst0frontier.cern.ch:3128"/><proxy url = "http://cmst0frontier.cern.ch:3128"/><proxy url = "http://cmst0frontier1.cern.ch:3128"/><proxy url = "http://cmst0frontier2.cern.ch:3128"/><server url = "http://cmsfrontier.cern.ch:8000/FrontierInt"/><server url = "http://cmsfrontier.cern.ch:8000/FrontierInt"/><server url = "http://cmsfrontier1.cern.ch:8000/FrontierInt"/><server url = "http://cmsfrontier2.cern.ch:8000/FrontierInt"/><server url = "http://cmsfrontier3.cern.ch:8000/FrontierInt"/><server url = "http://cmsfrontier4.cern.ch:8000/FrontierInt"/></frontier-connect>''' 60 l = numorbit * numbx * 25.0e-09
65 input: {lsnum:[deadtime, instlumi, bit_0, norbits,prescale...]} 66 output: {lsnum:[instlumi, recordedlumi...]} 69 for myls, deadArray
in deadtable.items():
70 lstime = lslengthsec (deadArray[3], 3564)
71 instlumi = deadArray[1] * lstime
72 if float( deadArray[2] ) == 0.0:
75 deadfrac = float (deadArray[0]) / (float (deadArray[2])*
float(deadArray[4]))
76 recordedLumi = instlumi * (1.0 - deadfrac)
77 myLsList = [instlumi, recordedLumi]
79 if len (deadArray) > 5:
80 myLsList.extend (deadArray[5:])
81 result[myls] = myLsList
86 '''Takes either single run as a string or dictionary of run ranges''' 89 if isinstance(inputRange, str):
90 runs.append(
int(inputRange))
92 runs=inputRange.runs()
93 for r
in sorted(runs):
94 if parameters.verbose:
99 lumidata.append( deliveredLumiForRun (dbsession, parameters,r,finecorrections=c) )
103 '''Takes either single run as a string or dictionary of run ranges''' 105 if isinstance(inputRange,str):
107 if finecorrections
and finecorrections[run]:
108 lumiDataPiece = recordedLumiForRun (dbsession, parameters,inputRange,lslist=
None,finecorrections=finecorrections[run])
111 if parameters.lumiXing:
113 if finecorrections
and finecorrections[run]:
114 xingLumiDict = xingLuminosityForRun (dbsession, inputRange,
115 parameters,finecorrections=finecorrections[run])
117 xingLumiDict = xingLuminosityForRun (dbsession, inputRange,
119 mergeXingLumi (lumiDataPiece, xingLumiDict)
120 lumidata.append (lumiDataPiece)
124 maxLumiSectionDict = {}
125 for (run, lslist)
in sorted (inputRange.runsandls().
items() ):
127 maxLumiSectionDict[run] = max ( max (lslist),
128 maxLumiSectionDict.get(run,0) )
129 runLsDict.setdefault (run, []).append (lslist)
130 for run, metaLsList
in sorted (six.iteritems(runLsDict)):
131 if parameters.verbose:
134 for lslist
in metaLsList:
135 if finecorrections
and finecorrections[run]:
136 runLumiData.append( recordedLumiForRun (dbsession, parameters,run,lslist=lslist,finecorrections=finecorrections[run]) )
139 runLumiData.append( recordedLumiForRun (dbsession, parameters,run,lslist=lslist) )
140 if parameters.lumiXing:
142 if finecorrections
and finecorrections[run]:
143 xingLumiDict = xingLuminosityForRun (dbsession, run,
146 maxLumiSectionDict[run],
147 finecorrections=finecorrections[run])
149 xingLumiDict = xingLuminosityForRun (dbsession, run,
152 maxLumiSectionDict[run])
154 for lumiDataPiece
in runLumiData:
155 mergeXingLumi (lumiDataPiece, xingLumiDict)
156 lumidata.append (lumiDataPiece)
158 lumidata.extend( runLumiData )
163 select sum (INSTLUMI), count (INSTLUMI) from lumisummary where runnum = 124025 and lumiversion = '0001'; 164 select INSTLUMI,NUMORBIT from lumisummary where runnum = 124025 and lumiversion = '0001' 165 query result unit E27cm^-2 (= 1 / mb) 167 optional corrections=None/(constfactor,afterglowfactor,nonlinearfactor) 175 conditionstring=
"RUNNUM = :runnum AND LUMIVERSION = :lumiversion" 176 dbsession.transaction().start (
True)
177 schema = dbsession.nominalSchema()
179 query.addToOutputList(
"INSTLUMI",
'instlumi')
180 query.addToOutputList (
"NUMORBIT",
"norbits")
181 queryBind = coral.AttributeList()
182 queryBind.extend (
"runnum",
"unsigned int")
183 queryBind.extend (
"lumiversion",
"string")
184 queryBind[
"runnum"].setData (int (runnum))
185 queryBind[
"lumiversion"].setData (parameters.lumiversion)
187 if len(parameters.beammode)!=0:
188 conditionstring=conditionstring+
' and BEAMSTATUS=:beamstatus' 189 queryBind.extend(
'beamstatus',
'string')
190 queryBind[
'beamstatus'].setData(parameters.beammode)
191 result = coral.AttributeList()
192 result.extend (
"instlumi",
"float")
193 result.extend (
"norbits",
"unsigned int")
194 query.defineOutput (result)
195 query.setCondition (conditionstring,queryBind)
196 cursor = query.execute()
198 instlumi = cursor.currentRow()[
'instlumi'].
data()
199 norbits = cursor.currentRow()[
'norbits'].
data()
200 if finecorrections
is not None:
201 instlumi=lumiCorrections.applyfinecorrection(instlumi,finecorrections[0],finecorrections[1],finecorrections[2])
202 if instlumi
is not None and norbits
is not None:
204 delivered=delivered+instlumi*parameters.norm*lstime
207 dbsession.transaction().commit()
210 lumidata = [str (runnum),
'N/A',
'N/A',
'N/A']
212 lumidata = [str (runnum), str (totalls),
'%.3f'%delivered, parameters.beammode]
214 except Exception
as e:
216 dbsession.transaction().rollback()
221 lslist = [] means take none in the db 222 lslist = None means to take all in the db 223 output: ['runnumber', 'trgtable{}', 'deadtable{}'] 229 lumidata.append (runnum)
230 lumidata.append (trgtable)
231 lumidata.append (deadtable)
233 conditionstring=
'trghltmap.HLTKEY = cmsrunsummary.HLTKEY AND cmsrunsummary.RUNNUM = :runnumber' 235 dbsession.transaction().start (
True)
236 schema = dbsession.nominalSchema()
237 query = schema.newQuery()
240 queryCondition = coral.AttributeList()
241 queryCondition.extend (
"runnumber",
"unsigned int")
242 queryCondition[
"runnumber"].setData (int (runnum))
243 query.setCondition (conditionstring,queryCondition)
244 query.addToOutputList (
"trghltmap.HLTPATHNAME",
"hltpathname")
245 query.addToOutputList (
"trghltmap.L1SEED",
"l1seed")
246 result = coral.AttributeList()
247 result.extend (
"hltpathname",
"string")
248 result.extend (
"l1seed",
"string")
249 query.defineOutput (result)
250 cursor = query.execute()
252 hltpathname = cursor.currentRow()[
"hltpathname"].
data()
253 l1seed = cursor.currentRow()[
"l1seed"].
data()
254 collectedseeds.append ( (hltpathname, l1seed))
257 dbsession.transaction().commit()
259 for (hname, sname)
in collectedseeds:
260 l1bitname = hltTrgSeedMapper.findUniqueSeed (hname, sname)
263 lumidata[1][hname] = []
264 lumidata[1][hname].append (l1bitname.replace (
'\"',
''))
265 dbsession.transaction().start (
True)
266 schema = dbsession.nominalSchema()
268 hltprescQuery.addToOutputList (
"PATHNAME",
"hltpath")
269 hltprescQuery.addToOutputList (
"PRESCALE",
"hltprescale")
270 hltprescCondition = coral.AttributeList()
271 hltprescCondition.extend (
'runnumber',
'unsigned int')
272 hltprescCondition.extend (
'cmslsnum',
'unsigned int')
273 hltprescCondition.extend (
'inf',
'unsigned int')
274 hltprescResult = coral.AttributeList()
275 hltprescResult.extend (
'hltpath',
'string')
276 hltprescResult.extend (
'hltprescale',
'unsigned int')
277 hltprescQuery.defineOutput (hltprescResult)
278 hltprescCondition[
'runnumber'].setData (int (runnum))
279 hltprescCondition[
'cmslsnum'].setData (1)
280 hltprescCondition[
'inf'].setData (0)
281 hltprescQuery.setCondition (
"RUNNUM = :runnumber and CMSLSNUM = :cmslsnum and PRESCALE != :inf",hltprescCondition)
282 cursor = hltprescQuery.execute()
284 hltpath = cursor.currentRow()[
'hltpath'].
data()
285 hltprescale = cursor.currentRow()[
'hltprescale'].
data()
286 if hltpath
in lumidata[1]:
287 lumidata[1][hltpath].append (hltprescale)
291 dbsession.transaction().commit()
292 dbsession.transaction().start (
True)
293 schema = dbsession.nominalSchema()
294 query = schema.newQuery()
297 queryCondition = coral.AttributeList()
298 queryCondition.extend (
"runnumber",
"unsigned int")
299 queryCondition.extend (
"lumiversion",
"string")
300 queryCondition[
"runnumber"].setData (int (runnum))
301 queryCondition[
"lumiversion"].setData (parameters.lumiversion)
302 conditionstring=
'lumisummary.RUNNUM =:runnumber and lumisummary.LUMIVERSION =:lumiversion AND lumisummary.CMSLSNUM=trg.CMSLSNUM and lumisummary.RUNNUM=trg.RUNNUM' 303 if len(parameters.beammode)!=0:
304 conditionstring=conditionstring+
' and lumisummary.BEAMSTATUS=:beamstatus' 305 queryCondition.extend(
'beamstatus',
'string')
306 queryCondition[
'beamstatus'].setData(parameters.beammode)
307 query.setCondition(conditionstring,queryCondition)
308 query.addToOutputList (
"lumisummary.CMSLSNUM",
"cmsls")
309 query.addToOutputList (
"lumisummary.INSTLUMI",
"instlumi")
310 query.addToOutputList (
"lumisummary.NUMORBIT",
"norbits")
311 query.addToOutputList (
"trg.TRGCOUNT",
"trgcount")
312 query.addToOutputList (
"trg.BITNAME",
"bitname")
313 query.addToOutputList (
"trg.DEADTIME",
"trgdeadtime")
314 query.addToOutputList (
"trg.PRESCALE",
"trgprescale")
315 query.addToOutputList (
"trg.BITNUM",
"trgbitnum")
317 result = coral.AttributeList()
318 result.extend (
"cmsls",
"unsigned int")
319 result.extend (
"instlumi",
"float")
320 result.extend (
"norbits",
"unsigned int")
321 result.extend (
"trgcount",
"unsigned int")
322 result.extend (
"bitname",
"string")
323 result.extend (
"trgdeadtime",
"unsigned long long")
324 result.extend (
"trgprescale",
"unsigned int")
325 result.extend (
"trgbitnum",
"unsigned int")
327 query.defineOutput (result)
328 cursor = query.execute()
330 cmsls = cursor.currentRow()[
"cmsls"].
data()
331 instlumi = cursor.currentRow()[
"instlumi"].
data()*parameters.norm
333 instlumi=lumiCorrections.applyfinecorrection(instlumi,finecorrections[0],finecorrections[1],finecorrections[2])
334 norbits = cursor.currentRow()[
"norbits"].
data()
335 trgcount = cursor.currentRow()[
"trgcount"].
data()
336 trgbitname = cursor.currentRow()[
"bitname"].
data()
337 trgdeadtime = cursor.currentRow()[
"trgdeadtime"].
data()
338 trgprescale = cursor.currentRow()[
"trgprescale"].
data()
339 trgbitnum = cursor.currentRow()[
"trgbitnum"].
data()
341 if trgbitname
not in trgprescalemap:
342 trgprescalemap[trgbitname] = trgprescale
344 if cmsls
not in deadtable:
345 deadtable[cmsls] = []
346 deadtable[cmsls].append (trgdeadtime)
347 deadtable[cmsls].append (instlumi)
348 deadtable[cmsls].append (trgcount)
349 deadtable[cmsls].append (norbits)
350 deadtable[cmsls].append (trgprescale)
353 dbsession.transaction().commit()
361 for hpath, trgdataseq
in lumidata[1].
items():
363 if bitn
in trgprescalemap
and len (trgdataseq) == 2:
364 lumidata[1][hpath].append (trgprescalemap[bitn])
366 lumidata[2] = filterDeadtable (deadtable, lslist)
367 if not parameters.noWarnings:
368 if len(lumidata[2])!=0:
369 for lumi, deaddata
in lumidata[2].
items():
370 if deaddata[1] == 0.0
and deaddata[2]!=0
and deaddata[0]!=0:
371 print '[Warning] : run %s :ls %d has 0 instlumi but trigger has data' % (runnum, lumi)
372 if (deaddata[2] == 0
or deaddata[0] == 0)
and deaddata[1]!=0.0:
373 print '[Warning] : run %s :ls %d has 0 dead counts or 0 zerobias bit counts, but inst!=0' % (runnum, lumi)
375 except Exception
as e:
377 dbsession.transaction().rollback()
390 if len (lslist) == 0:
392 for existingLS
in inTable.keys():
393 if existingLS
in lslist:
394 result[existingLS] = inTable[existingLS]
399 labels = [ (
'Run',
'Delivered LS',
'Delivered'+
u' (/\u03bcb)'.encode (
'utf-8'),
'Beam Mode')]
400 print tablePrinter.indent (labels+lumidata, hasHeader =
True, separateRows =
False,
401 prefix =
'| ', postfix =
' |', justify =
'right',
402 delim =
' | ', wrapfunc =
lambda x: wrap_onspace (x, 20) )
406 input params: lumidata [{'fieldname':value}] 411 r.writeRows(lumidata)
415 input: {lsnum:[deadtime, instlumi, bit_0, norbits,prescale]} 419 for myls, d
in deadtable.items():
423 if float (d[2]) == 0.0:
426 deadfrac = float (d[0])/(float (d[2])*float (d[-1]))
427 lstime = lslengthsec (d[3], 3564)
428 recordedLumi += instLumi* (1.0-deadfrac)*lstime
436 result.append ([inPut[0]])
440 result[counter].append (i)
445 return ', '.join ([
'['+str (min (x))+
'-'+str (max (x))+
']' for x
in result])
450 input: trgtable{hltpath:[l1seed, hltprescale, l1prescale]}, totalrecorded (float) 451 output:{hltpath, recorded} 455 for hltpath, data
in trgtable.items():
457 result[hltpath] = totalrecorded/ (data[1]*data[2])
459 result[hltpath] = 0.0
465 inputtable: {lsnum:[deadtime, instlumi, bit_0, norbits,bit_0_prescale]} 466 output: {lsnum:deadfraction} 469 for myls, d
in deadtable.items():
471 if float (d[2]) == 0.0:
474 deadfrac = float (d[0])/ (float (d[2])*
float(d[-1]))
475 result[myls] = deadfrac
480 input lumidata [['runnumber', 'trgtable{}', 'deadtable{}']] 481 deadtable {lsnum:[deadtime, instlumi, bit_0, norbits,prescale]} 485 labels = [ (
'Run',
'LS',
'Delivered',
'Recorded'+
u' (/\u03bcb)'.encode (
'utf-8'))]
486 lastrowlabels = [ (
'Selected LS',
'Delivered'+
u' (/\u03bcb)'.encode (
'utf-8'),
'Recorded'+
u' (/\u03bcb)'.encode (
'utf-8'))]
492 for perrundata
in lumidata:
493 runnumber = perrundata[0]
494 deadtable = perrundata[2]
495 lumiresult = lsBylsLumi (deadtable)
496 totalSelectedLS = totalSelectedLS+len (deadtable)
497 for lsnum, dataperls
in lumiresult.items():
499 if len (dataperls) == 0:
500 rowdata += [str (runnumber), str (lsnum),
'N/A',
'N/A']
502 rowdata += [str (runnumber), str (lsnum),
'%.3f' % (dataperls[0]),
'%.3f' % (dataperls[1])]
503 totalDelivered = totalDelivered+dataperls[0]
504 totalRecorded = totalRecorded+dataperls[1]
505 datatoprint.append (rowdata)
506 totalrow.append ([str (totalSelectedLS),
'%.3f'% (totalDelivered),
'%.3f'% (totalRecorded)])
508 print tablePrinter.indent (labels+datatoprint, hasHeader =
True, separateRows =
False, prefix =
'| ',
509 postfix =
' |', justify =
'right', delim =
' | ',
510 wrapfunc =
lambda x: wrap_onspace_strict (x, 22))
511 print ' == = Total : ' 512 print tablePrinter.indent (lastrowlabels+totalrow, hasHeader =
True, separateRows =
False, prefix =
'| ',
513 postfix =
' |', justify =
'right', delim =
' | ',
514 wrapfunc =
lambda x: wrap_onspace (x, 20))
519 for perrundata
in lumidata:
520 runnumber = perrundata[0]
521 deadtable = perrundata[2]
522 lumiresult = lsBylsLumi (deadtable)
523 for lsnum, dataperls
in lumiresult.items():
525 if len (dataperls) == 0:
526 rowdata += [str (runnumber), str (lsnum),
'N/A',
'N/A']
528 rowdata += [str (runnumber), str (lsnum), dataperls[0], dataperls[1]]
529 if len (dataperls) > 2:
530 rowdata.extend ( flatten (dataperls[2:]) )
531 datatodump.append (rowdata)
538 labels = [ (
'Run',
'HLT path',
'Recorded'+
u' (/\u03bcb)'.encode (
'utf-8'))]
539 lastrowlabels = [ (
'Selected LS',
'Recorded'+
u' (/\u03bcb)'.encode (
'utf-8'))]
540 if len (hltpath) != 0
and hltpath !=
'all':
541 lastrowlabels = [ (
'Selected LS',
'Recorded'+
u' (/\u03bcb)'.encode (
'utf-8'),
542 'Effective '+
u' (/\u03bcb) '.encode (
'utf-8')+hltpath)]
544 labels = [ (
'Run',
'HLT-path',
'L1-bit',
'L1-presc',
'HLT-presc',
'Recorded'+
u' (/\u03bcb)'.encode (
'utf-8'))]
547 totalRecordedInPath = 0.0
549 for dataperRun
in lumidata:
550 runnum = dataperRun[0]
551 if len (dataperRun[1]) == 0:
553 rowdata += [str (runnum)]+2*[
'N/A']
554 datatoprint.append (rowdata)
556 perlsdata = dataperRun[2]
557 totalSelectedLS = totalSelectedLS+len (perlsdata)
560 recordedLumi = calculateTotalRecorded (perlsdata)
561 totalRecorded = totalRecorded+recordedLumi
562 trgdict = dataperRun[1]
563 effective = calculateEffective (trgdict, recordedLumi)
564 if hltpath
in trgdict
and hltpath
in effective:
566 l1bit = trgdict[hltpath][0]
567 if len (trgdict[hltpath]) != 3:
569 rowdata += [str (runnum), hltpath,
'N/A']
571 rowdata += [str (runnum), hltpath, l1bit,
'N/A',
'N/A',
'N/A']
574 rowdata += [str (runnum), hltpath,
'%.3f'% (effective[hltpath])]
576 hltprescale = trgdict[hltpath][1]
577 l1prescale = trgdict[hltpath][2]
578 rowdata += [str (runnum), hltpath, l1bit, str (l1prescale), str (hltprescale),
579 '%.3f'% (effective[hltpath])]
580 totalRecordedInPath = totalRecordedInPath+effective[hltpath]
581 datatoprint.append (rowdata)
584 for trg, trgdata
in trgdict.items():
587 if trg == trgdict.keys()[0]:
588 rowdata += [str (runnum)]
592 if len (trgdata) == 3:
594 rowdata += [trg,
'%.3f'% (effective[trg])]
596 hltprescale = trgdata[1]
597 l1prescale = trgdata[2]
598 rowdata += [trg, l1bit, str (l1prescale), str (hltprescale),
'%.3f'% (effective[trg])]
601 rowdata += [trg,
'N/A']
603 rowdata += [trg, l1bit,
'N/A',
'N/A',
'%.3f'% (effective[trg])]
604 datatoprint.append (rowdata)
607 print tablePrinter.indent (labels+datatoprint, hasHeader =
True, separateRows =
False, prefix =
'| ',
608 postfix =
' |', justify =
'right', delim =
' | ',
609 wrapfunc =
lambda x: wrap_onspace_strict (x, 22))
611 if len (hltpath) != 0
and hltpath !=
'all':
612 totalrow.append ([str (totalSelectedLS),
'%.3f'% (totalRecorded),
'%.3f'% (totalRecordedInPath)])
614 totalrow.append ([str (totalSelectedLS),
'%.3f'% (totalRecorded)])
615 print ' == = Total : ' 616 print tablePrinter.indent (lastrowlabels+totalrow, hasHeader =
True, separateRows =
False, prefix =
'| ',
617 postfix =
' |', justify =
'right', delim =
' | ',
618 wrapfunc =
lambda x: wrap_onspace (x, 20))
621 deadtimelabels = [ (
'Run',
'Lumi section : Dead fraction')]
623 for dataperRun
in lumidata:
624 runnum = dataperRun[0]
625 if len (dataperRun[1]) == 0:
626 deadtoprint.append ([str (runnum),
'N/A'])
628 perlsdata = dataperRun[2]
630 deadT = getDeadfractions (perlsdata)
632 for myls, de
in deadT.items():
634 t += str (myls)+
':nobeam ' 636 t += str (myls)+
':'+
'%.5f'% (de)+
' ' 637 deadtoprint.append ([str (runnum), t])
639 print tablePrinter.indent (deadtimelabels+deadtoprint, hasHeader =
True, separateRows =
True, prefix =
'| ',
640 postfix =
' |', justify =
'right', delim =
' | ',
641 wrapfunc =
lambda x: wrap_onspace (x, 80))
647 for dataperRun
in lumidata:
648 runnum = dataperRun[0]
649 if len (dataperRun[1]) == 0:
651 rowdata += [str (runnum)]+2*[
'N/A']
652 datatodump.append (rowdata)
654 perlsdata = dataperRun[2]
657 recordedLumi = calculateTotalRecorded (perlsdata)
658 trgdict = dataperRun[1]
659 effective = calculateEffective (trgdict, recordedLumi)
660 if hltpath
in trgdict
and hltpath
in effective:
662 l1bit = trgdict[hltpath][0]
663 if len (trgdict[hltpath]) != 3:
664 rowdata += [str (runnum), hltpath,
'N/A']
666 hltprescale = trgdict[hltpath][1]
667 l1prescale = trgdict[hltpath][2]
668 rowdata += [str (runnum), hltpath, effective[hltpath]]
669 datatodump.append (rowdata)
672 for trg, trgdata
in trgdict.items():
675 rowdata += [str (runnum)]
677 if len (trgdata) == 3:
678 rowdata += [trg, effective[trg]]
680 rowdata += [trg,
'N/A']
681 datatodump.append (rowdata)
686 if len (hltpath) == 0
or hltpath ==
'all':
687 toprowlabels = [ (
'Run',
'Delivered LS',
'Delivered'+
u' (/\u03bcb)'.encode (
'utf-8'),
'Selected LS',
'Recorded'+
u' (/\u03bcb)'.encode (
'utf-8') )]
688 lastrowlabels = [ (
'Delivered LS',
'Delivered'+
u' (/\u03bcb)'.encode (
'utf-8'),
'Selected LS',
'Recorded'+
u' (/\u03bcb)'.encode (
'utf-8') ) ]
690 toprowlabels = [ (
'Run',
'Delivered LS',
'Delivered'+
u' (/\u03bcb)'.encode (
'utf-8'),
'Selected LS',
'Recorded'+
u' (/\u03bcb)'.encode (
'utf-8'),
'Effective'+
u' (/\u03bcb) '.encode (
'utf-8')+hltpath )]
691 lastrowlabels = [ (
'Delivered LS',
'Delivered'+
u' (/\u03bcb)'.encode (
'utf-8'),
'Selected LS',
'Recorded'+
u' (/\u03bcb)'.encode (
'utf-8'),
'Effective '+
u' (/\u03bcb) '.encode (
'utf-8')+hltpath)]
698 totalRecordedInPath = 0.0
700 for runidx, deliveredrowdata
in enumerate (delivered):
702 rowdata += [deliveredrowdata[0], deliveredrowdata[1], deliveredrowdata[2]]
703 if deliveredrowdata[1] ==
'N/A':
704 if hltpath !=
'' and hltpath !=
'all':
705 rowdata += [
'N/A',
'N/A',
'N/A']
707 rowdata += [
'N/A',
'N/A']
708 datatable.append (rowdata)
710 totalDeliveredLS += int (deliveredrowdata[1])
711 totalDelivered += float (deliveredrowdata[2])
712 selectedls = recorded[runidx][2].
keys()
715 if len (selectedls) == 0:
718 if hltpath !=
'' and hltpath !=
'all':
719 rowdata += [selectedlsStr,
'N/A',
'N/A']
721 rowdata += [selectedlsStr,
'N/A']
723 selectedlsStr = splitlistToRangeString (selectedls)
724 recordedLumi = calculateTotalRecorded (recorded[runidx][2])
725 lumiinPaths = calculateEffective (recorded[runidx][1], recordedLumi)
726 if hltpath !=
'' and hltpath !=
'all':
727 if hltpath
in lumiinPaths:
728 rowdata += [selectedlsStr,
'%.3f'% (recordedLumi),
'%.3f'% (lumiinPaths[hltpath])]
729 totalRecordedInPath += lumiinPaths[hltpath]
731 rowdata += [selectedlsStr,
'%.3f'% (recordedLumi),
'N/A']
734 rowdata += [selectedlsStr,
'%.3f'% (recordedLumi)]
735 totalSelectedLS += len (selectedls)
736 totalRecorded += recordedLumi
737 datatable.append (rowdata)
739 if hltpath !=
'' and hltpath !=
'all':
740 totaltable = [[str (totalDeliveredLS),
'%.3f'% (totalDelivered), str (totalSelectedLS),
741 '%.3f'% (totalRecorded),
'%.3f'% (totalRecordedInPath)]]
743 totaltable = [[str (totalDeliveredLS),
'%.3f'% (totalDelivered), str (totalSelectedLS),
744 '%.3f'% (totalRecorded)]]
745 print tablePrinter.indent (toprowlabels+datatable, hasHeader =
True, separateRows =
False, prefix =
'| ',
746 postfix =
' |', justify =
'right', delim =
' | ',
747 wrapfunc =
lambda x: wrap_onspace (x, 20))
748 print ' == = Total : ' 749 print tablePrinter.indent (lastrowlabels+totaltable, hasHeader =
True, separateRows =
False, prefix =
'| ',
750 postfix =
' |', justify =
'right', delim =
' | ',
751 wrapfunc =
lambda x: wrap_onspace (x, 20))
757 for runidx, deliveredrowdata
in enumerate (delivered):
759 rowdata += [deliveredrowdata[0], deliveredrowdata[2]]
760 if deliveredrowdata[1] ==
'N/A':
761 rowdata += [
'N/A',
'N/A']
762 datatable.append (rowdata)
764 recordedLumi = calculateTotalRecorded (recorded[runidx][2])
765 lumiinPaths = calculateEffective (recorded[runidx][1], recordedLumi)
766 if hltpath !=
'' and hltpath !=
'all':
767 if hltpath
in lumiinPaths:
768 rowdata += [recordedLumi, lumiinPaths[hltpath]]
770 rowdata += [recordedLumi,
'N/A']
772 rowdata += [recordedLumi, recordedLumi]
773 datatable.append (rowdata)
778 maxLumiSection =
None, finecorrections=
None):
779 '''Given a run number and a minimum xing luminosity value, 780 returns a dictionary (keyed by (run, lumi section)) where the 781 value is a list of tuples of (xingID, xingLum). 783 - For all xing luminosities, simply set minLumValue to 0. 785 - If you want one dictionary for several runs, pass it in to 789 s.cmslsnum, d.bxlumivalue, d.bxlumierror, d.bxlumiquality, d.algoname from LUMIDETAIL d, LUMISUMMARY s where s.runnum = 133885 and d.algoname = 'OCC1' and s.lumisummary_id = d.lumisummary_id order by s.startorbit, s.cmslsnum 792 runnum = int (runnum)
793 dbsession.transaction().start (
True)
794 schema = dbsession.schema (parameters.lumischema)
796 raise 'cannot connect to schema ', parameters.lumischema
797 detailOutput = coral.AttributeList()
798 detailOutput.extend (
'startorbit',
'unsigned int')
799 detailOutput.extend (
'cmslsnum',
'unsigned int')
800 detailOutput.extend (
'bxlumivalue',
'blob')
801 detailOutput.extend (
'bxlumierror',
'blob')
802 detailOutput.extend (
'bxlumiquality',
'blob')
803 detailOutput.extend (
'algoname',
'string')
804 detailCondition = coral.AttributeList()
805 detailCondition.extend (
'runnum',
'unsigned int')
806 detailCondition.extend (
'algoname',
'string')
807 detailCondition[
'runnum'].setData (runnum)
808 detailCondition[
'algoname'].setData (
'OCC1')
809 query = schema.newQuery()
812 query.addToOutputList (
's.STARTORBIT',
'startorbit')
813 query.addToOutputList (
's.CMSLSNUM',
'cmslsnum')
814 query.addToOutputList (
'd.BXLUMIVALUE',
'bxlumivalue')
815 query.addToOutputList (
'd.BXLUMIERROR',
'bxlumierror')
816 query.addToOutputList (
'd.BXLUMIQUALITY',
'bxlumiquality')
817 query.addToOutputList (
'd.ALGONAME',
'algoname')
818 query.setCondition (
's.RUNNUM =:runnum and d.ALGONAME =:algoname and s.LUMISUMMARY_ID=d.LUMISUMMARY_ID',detailCondition)
819 query.addToOrderList (
's.CMSLSNUM')
820 query.defineOutput (detailOutput)
821 cursor = query.execute()
831 cmslsnum = cursor.currentRow()[
'cmslsnum'].
data()
832 algoname = cursor.currentRow()[
'algoname'].
data()
833 bxlumivalue = cursor.currentRow()[
'bxlumivalue'].
data()
834 startorbit = cursor.currentRow()[
'startorbit'].
data()
836 if maxLumiSection
and maxLumiSection < cmslsnum:
840 xingArray = array.array (
'f')
841 xingArray.fromstring( bxlumivalue.readline() )
845 if len(xingArray)!=0:
846 avginstlumi=sum(xingArray)
847 for index, lum
in enumerate (xingArray):
848 mynorm=parameters.normFactor
850 lum=lumiCorrections.applyfinecorrectionBX(lum,avginstlumi*mynorm,mynorm,finecorrections[0],finecorrections[1],finecorrections[2])
853 if lum < parameters.xingMinLum:
855 xingLum.append( (index, lum) )
856 lumiXingDict[ (runnum, cmslsnum) ] = xingLum
858 dbsession.transaction().commit()
860 except Exception
as e:
863 dbsession.transaction().rollback()
868 '''Given nested lists or tuples, returns a single flattened list''' 871 if hasattr (piece,
'__iter__')
and not isinstance (piece, str):
872 result.extend( flatten (piece) )
874 result.append (piece)
879 '''Given general xing information and a xingLumiDict, the xing 880 luminosity information is merged with the general information''' 881 runNumber = triplet[0]
882 deadTable = triplet[2]
883 for lumi, lumiList
in six.iteritems(deadTable):
884 key = (
int(runNumber),
int(lumi) )
885 xingLumiValues = xingLumiDict.get (key)
887 lumiList.append( flatten (xingLumiValues) )
890 def setupSession (connectString, siteconfpath, parameters, debug = False):
891 '''returns database session''' 893 connectparser.parse()
894 usedefaultfrontierconfig =
False 896 if connectparser.needsitelocalinfo():
898 cacheconfigpath = os.environ[
'CMS_PATH']
900 cacheconfigpath = os.path.join (cacheconfigpath,
'SITECONF',
'local',
'JobConfig',
'site-local-config.xml')
902 usedefaultfrontierconfig =
True 904 cacheconfigpath = siteconfpath
905 cacheconfigpath = os.path.join (cacheconfigpath,
'site-local-config.xml')
907 if usedefaultfrontierconfig:
908 ccp.parseString (parameters.defaultfrontierConfigString)
910 ccp.parse (cacheconfigpath)
911 connectString = connectparser.fullfrontierStr (connectparser.schemaname(), ccp.parameterdict())
912 svc = coral.ConnectionService()
914 msg = coral.MessageStream (
'')
915 msg.setMsgVerbosity (coral.message_Level_Debug)
916 parameters.verbose =
True 917 session = svc.connect (connectString, accessMode = coral.access_ReadOnly)
918 session.typeConverter().setCppTypeForSqlType (
"unsigned int",
"NUMBER (10)")
919 session.typeConverter().setCppTypeForSqlType (
"unsigned long long",
"NUMBER (20)")
926 def allruns(schemaHandle,requireRunsummary=True,requireLumisummary=False,requireTrg=False,requireHlt=False):
928 find all runs in the DB. By default requires cmsrunsummary table contain the run. The condition can be loosed in situation where db loading failed on certain data portions. 930 if not requireRunsummary
and not requireLumiummary
and not requireTrg
and not requireHlt:
931 print 'must require at least one table' 936 if requireRunsummary:
938 queryHandle=schemaHandle.newQuery()
940 queryHandle.addToOutputList(
"RUNNUM",
"run")
942 result=coral.AttributeList()
943 result.extend(
"run",
"unsigned int")
944 queryHandle.defineOutput(result)
945 cursor=queryHandle.execute()
947 r=cursor.currentRow()[
'run'].
data()
950 if requireLumisummary:
952 queryHandle=schemaHandle.newQuery()
954 queryHandle.addToOutputList(
"distinct RUNNUM",
"run")
956 result=coral.AttributeList()
957 result.extend(
"run",
"unsigned int")
958 queryHandle.defineOutput(result)
959 cursor=queryHandle.execute()
961 r=cursor.currentRow()[
'run'].
data()
966 queryHandle=schemaHandle.newQuery()
968 queryHandle.addToOutputList(
"distinct RUNNUM",
"run")
970 result=coral.AttributeList()
971 result.extend(
"run",
"unsigned int")
972 queryHandle.defineOutput(result)
973 cursor=queryHandle.execute()
975 r=cursor.currentRow()[
'run'].
data()
980 queryHandle=schemaHandle.newQuery()
982 queryHandle.addToOutputList(
"distinct RUNNUM",
"run")
984 result=coral.AttributeList()
985 result.extend(
"run",
"unsigned int")
986 queryHandle.defineOutput(result)
987 cursor=queryHandle.execute()
989 r=cursor.currentRow()[
'run'].
data()
993 for dup
in dupresult:
995 runresult.append(dup[0])
1000 '''retrieve validation data per run or all 1001 input: run. if not run, retrive all; if cmslsnum selection list pesent, filter out unselected result 1002 output: {run:[[cmslsnum,status,comment]]} 1006 queryHandle.addToOutputList(
'RUNNUM',
'runnum')
1007 queryHandle.addToOutputList(
'CMSLSNUM',
'cmslsnum')
1008 queryHandle.addToOutputList(
'FLAG',
'flag')
1009 queryHandle.addToOutputList(
'COMMENT',
'comment')
1011 queryCondition=
'RUNNUM=:runnum' 1012 queryBind=coral.AttributeList()
1013 queryBind.extend(
'runnum',
'unsigned int')
1014 queryBind[
'runnum'].setData(run)
1015 queryHandle.setCondition(queryCondition,queryBind)
1016 queryResult=coral.AttributeList()
1017 queryResult.extend(
'runnum',
'unsigned int')
1018 queryResult.extend(
'cmslsnum',
'unsigned int')
1019 queryResult.extend(
'flag',
'string')
1020 queryResult.extend(
'comment',
'string')
1021 queryHandle.defineOutput(queryResult)
1022 cursor=queryHandle.execute()
1024 runnum=cursor.currentRow()[
'runnum'].
data()
1025 if runnum
not in result:
1027 cmslsnum=cursor.currentRow()[
'cmslsnum'].
data()
1028 flag=cursor.currentRow()[
'flag'].
data()
1029 comment=cursor.currentRow()[
'comment'].
data()
1030 result[runnum].
append([cmslsnum,flag,comment])
1031 if run
and cmsls
and len(cmsls)!=0:
1033 for runnum,perrundata
in result.items():
1034 for lsdata
in perrundata:
1035 if lsdata[0]
not in cmsls:
1037 if runnum
not in selectedresult:
1038 selectedresult[runnum]=[]
1039 selectedresult[runnum].
append(lsdata)
1040 return selectedresult
1045 '''select distinct fillnum from cmsrunsummary 1046 there are crazy fill numbers. we assume they are not valid runs 1050 queryHandle.addToOutputList(
'distinct FILLNUM',
'fillnum')
1053 queryCondition=
'FILLNUM>:zero and FILLNUM<:crazybig' 1054 queryBind=coral.AttributeList()
1055 queryBind.extend(
'zero',
'unsigned int')
1056 queryBind.extend(
'crazybig',
'unsigned int')
1057 queryBind[
'zero'].setData(
int(0))
1058 queryBind[
'crazybig'].setData(
int(29701))
1059 queryHandle.setCondition(queryCondition,queryBind)
1060 queryResult=coral.AttributeList()
1061 queryResult.extend(
'fillnum',
'unsigned int')
1062 queryHandle.defineOutput(queryResult)
1063 cursor=queryHandle.execute()
1065 result.append(cursor.currentRow()[
'fillnum'].
data())
1070 select fillnum,sequence,hltkey,to_char(starttime),to_char(stoptime) from cmsrunsummary where runnum=:runnum 1071 output: [fillnum,sequence,hltkey,starttime,stoptime] 1076 queryCondition=coral.AttributeList()
1077 queryCondition.extend(
'runnum',
'unsigned int')
1078 queryCondition[
'runnum'].setData(
int(runnum))
1079 queryHandle.addToOutputList(
'FILLNUM',
'fillnum')
1080 queryHandle.addToOutputList(
'SEQUENCE',
'sequence')
1081 queryHandle.addToOutputList(
'HLTKEY',
'hltkey')
1082 queryHandle.addToOutputList(
'to_char(STARTTIME,\''+t.coraltimefm+
'\')',
'starttime')
1083 queryHandle.addToOutputList(
'to_char(STOPTIME,\''+t.coraltimefm+
'\')',
'stoptime')
1084 queryHandle.setCondition(
'RUNNUM=:runnum',queryCondition)
1085 queryResult=coral.AttributeList()
1086 queryResult.extend(
'fillnum',
'unsigned int')
1087 queryResult.extend(
'sequence',
'string')
1088 queryResult.extend(
'hltkey',
'string')
1089 queryResult.extend(
'starttime',
'string')
1090 queryResult.extend(
'stoptime',
'string')
1091 queryHandle.defineOutput(queryResult)
1092 cursor=queryHandle.execute()
1094 result.append(cursor.currentRow()[
'fillnum'].
data())
1095 result.append(cursor.currentRow()[
'sequence'].
data())
1096 result.append(cursor.currentRow()[
'hltkey'].
data())
1097 result.append(cursor.currentRow()[
'starttime'].
data())
1098 result.append(cursor.currentRow()[
'stoptime'].
data())
1104 def lumisummaryByrun(queryHandle,runnum,lumiversion,beamstatus=None,beamenergy=None,beamenergyfluctuation=0.09,finecorrections=None):
1106 one can impose beamstatus, beamenergy selections at the SQL query level or process them later from the general result 1107 select cmslsnum,instlumi,numorbit,startorbit,beamstatus,beamenery from lumisummary where runnum=:runnum and lumiversion=:lumiversion order by startorbit; 1108 output: [[cmslsnum,instlumi,numorbit,startorbit,beamstatus,beamenergy,cmsalive]] 1109 Note: the non-cmsalive LS are included in the result 1113 queryCondition=coral.AttributeList()
1114 queryCondition.extend(
'runnum',
'unsigned int')
1115 queryCondition.extend(
'lumiversion',
'string')
1116 conditionstring=
'RUNNUM=:runnum and LUMIVERSION=:lumiversion' 1117 queryCondition[
'runnum'].setData(
int(runnum))
1118 queryCondition[
'lumiversion'].setData(lumiversion)
1119 queryHandle.addToOutputList(
'CMSLSNUM',
'cmslsnum')
1120 queryHandle.addToOutputList(
'INSTLUMI',
'instlumi')
1121 queryHandle.addToOutputList(
'NUMORBIT',
'numorbit')
1122 queryHandle.addToOutputList(
'STARTORBIT',
'startorbit')
1123 queryHandle.addToOutputList(
'BEAMSTATUS',
'beamstatus')
1124 queryHandle.addToOutputList(
'BEAMENERGY',
'beamenergy')
1125 queryHandle.addToOutputList(
'CMSALIVE',
'cmsalive')
1126 if beamstatus
and len(beamstatus)!=0:
1127 conditionstring=conditionstring+
' and BEAMSTATUS=:beamstatus' 1128 queryCondition.extend(
'beamstatus',
'string')
1129 queryCondition[
'beamstatus'].setData(beamstatus)
1131 minBeamenergy=
float(beamenergy*(1.0-beamenergyfluctuation))
1132 maxBeamenergy=
float(beamenergy*(1.0+beamenergyfluctuation))
1133 conditionstring=conditionstring+
' and BEAMENERGY>:minBeamenergy and BEAMENERGY<:maxBeamenergy' 1134 queryCondition.extend(
'minBeamenergy',
'float')
1135 queryCondition.extend(
'maxBeamenergy',
'float')
1136 queryCondition[
'minBeamenergy'].setData(
float(minBeamenergy))
1137 queryCondition[
'maxBeamenergy'].setData(
float(maxBeamenergy))
1138 queryResult=coral.AttributeList()
1139 queryResult.extend(
'cmslsnum',
'unsigned int')
1140 queryResult.extend(
'instlumi',
'float')
1141 queryResult.extend(
'numorbit',
'unsigned int')
1142 queryResult.extend(
'startorbit',
'unsigned int')
1143 queryResult.extend(
'beamstatus',
'string')
1144 queryResult.extend(
'beamenergy',
'float')
1145 queryResult.extend(
'cmsalive',
'unsigned int')
1146 queryHandle.defineOutput(queryResult)
1147 queryHandle.setCondition(conditionstring,queryCondition)
1148 queryHandle.addToOrderList(
'startorbit')
1149 cursor=queryHandle.execute()
1151 cmslsnum=cursor.currentRow()[
'cmslsnum'].
data()
1152 instlumi=cursor.currentRow()[
'instlumi'].
data()
1154 instlumi=lumiCorrections.applyfinecorrection(instlumi,finecorrections[0],finecorrections[1],finecorrections[2])
1155 numorbit=cursor.currentRow()[
'numorbit'].
data()
1156 startorbit=cursor.currentRow()[
'startorbit'].
data()
1157 beamstatus=cursor.currentRow()[
'beamstatus'].
data()
1158 beamenergy=cursor.currentRow()[
'beamenergy'].
data()
1159 cmsalive=cursor.currentRow()[
'cmsalive'].
data()
1160 result.append([cmslsnum,instlumi,numorbit,startorbit,beamstatus,beamenergy,cmsalive])
1163 def lumisumByrun(queryHandle,runnum,lumiversion,beamstatus=None,beamenergy=None,beamenergyfluctuation=0.09,finecorrections=None):
1165 beamenergy unit : GeV 1166 beamenergyfluctuation : fraction allowed to fluctuate around beamenergy value 1167 select instlumi from lumisummary where runnum=:runnum and lumiversion=:lumiversion 1168 output: float sum(instlumi) 1169 Note: the output is the raw result, need to apply LS length in time(sec) 1173 queryCondition=coral.AttributeList()
1174 queryCondition.extend(
'runnum',
'unsigned int')
1175 queryCondition.extend(
'lumiversion',
'string')
1177 queryCondition[
'runnum'].setData(
int(runnum))
1178 queryCondition[
'lumiversion'].setData(lumiversion)
1179 queryHandle.addToOutputList(
'INSTLUMI',
'instlumi')
1180 conditionstring=
'RUNNUM=:runnum and LUMIVERSION=:lumiversion' 1181 if beamstatus
and len(beamstatus)!=0:
1182 conditionstring=conditionstring+
' and BEAMSTATUS=:beamstatus' 1183 queryCondition.extend(
'beamstatus',
'string')
1184 queryCondition[
'beamstatus'].setData(beamstatus)
1185 if beamenergy
and beamenergy!=0.0:
1186 minBeamenergy=
float(beamenergy*(1.0-beamenergyfluctuation))
1187 maxBeamenergy=
float(beamenergy*(1.0+beamenergyfluctuation))
1188 conditionstring=conditionstring+
' and BEAMENERGY>:minBeamenergy and BEAMENERGY<:maxBeamenergy' 1189 queryCondition.extend(
'minBeamenergy',
'float')
1190 queryCondition.extend(
'maxBeamenergy',
'float')
1191 queryCondition[
'minBeamenergy'].setData(
float(minBeamenergy))
1192 queryCondition[
'maxBeamenergy'].setData(
float(maxBeamenergy))
1193 queryHandle.setCondition(conditionstring,queryCondition)
1194 queryResult=coral.AttributeList()
1195 queryResult.extend(
'instlumi',
'float')
1196 queryHandle.defineOutput(queryResult)
1197 cursor=queryHandle.execute()
1199 instlumi=cursor.currentRow()[
'instlumi'].
data()
1202 instlumi=lumiCorrections.applyfinecorrection(instlumi,finecorrections[0],finecorrections[1],finecorrections[2])
1203 result.append(instlumi)
1211 select cmslsnum,trgcount,deadtime,bitname,prescale from trg where runnum=:runnum and bitnum=0; 1212 output: {cmslsnum:[trgcount,deadtime,bitname,prescale]} 1216 queryCondition=coral.AttributeList()
1217 queryCondition.extend(
'runnum',
'unsigned int')
1218 queryCondition.extend(
'bitnum',
'unsigned int')
1219 queryCondition[
'runnum'].setData(
int(runnum))
1220 queryCondition[
'bitnum'].setData(
int(0))
1221 queryHandle.addToOutputList(
'CMSLSNUM',
'cmslsnum')
1222 queryHandle.addToOutputList(
'TRGCOUNT',
'trgcount')
1223 queryHandle.addToOutputList(
'DEADTIME',
'deadtime')
1224 queryHandle.addToOutputList(
'BITNAME',
'bitname')
1225 queryHandle.addToOutputList(
'PRESCALE',
'prescale')
1226 queryHandle.setCondition(
'RUNNUM=:runnum and BITNUM=:bitnum',queryCondition)
1227 queryResult=coral.AttributeList()
1228 queryResult.extend(
'cmslsnum',
'unsigned int')
1229 queryResult.extend(
'trgcount',
'unsigned int')
1230 queryResult.extend(
'deadtime',
'unsigned int')
1231 queryResult.extend(
'bitname',
'string')
1232 queryResult.extend(
'prescale',
'unsigned int')
1233 queryHandle.defineOutput(queryResult)
1234 cursor=queryHandle.execute()
1236 cmslsnum=cursor.currentRow()[
'cmslsnum'].
data()
1237 trgcount=cursor.currentRow()[
'trgcount'].
data()
1238 deadtime=cursor.currentRow()[
'deadtime'].
data()
1239 bitname=cursor.currentRow()[
'bitname'].
data()
1240 prescale=cursor.currentRow()[
'prescale'].
data()
1241 if cmslsnum
not in result:
1242 result[cmslsnum]=[trgcount,deadtime,bitname,prescale]
1247 select l.cmslsnum,l.instlumi,l.numorbit,l.startorbit,l.beamstatus,l.beamenery,t.trgcount,t.deadtime,t.bitname,t.prescale from trg t,lumisummary l where t.bitnum=:bitnum and l.runnum=:runnum and l.lumiversion=:lumiversion and l.runnum=t.runnum and t.cmslsnum=l.cmslsnum; 1248 Everything you ever need to know about bitzero and avg luminosity. Since we do not know if joint query is better of sperate, support both. 1249 output: {cmslsnum:[instlumi,numorbit,startorbit,beamstatus,beamenergy,bitzerocount,deadtime,bitname,prescale]} 1250 Note: only cmsalive LS are included in the result. Therefore, this function cannot be used for calculating delivered! 1255 queryCondition=coral.AttributeList()
1256 queryCondition.extend(
'bitnum',
'unsigned int')
1257 queryCondition.extend(
'runnum',
'unsigned int')
1258 queryCondition.extend(
'lumiversion',
'string')
1259 queryCondition[
'bitnum'].setData(
int(0))
1260 queryCondition[
'runnum'].setData(
int(runnum))
1261 queryCondition[
'lumiversion'].setData(lumiversion)
1263 queryHandle.addToOutputList(
'l.CMSLSNUM',
'cmslsnum')
1264 queryHandle.addToOutputList(
'l.INSTLUMI',
'instlumi')
1265 queryHandle.addToOutputList(
'l.NUMORBIT',
'numorbit')
1266 queryHandle.addToOutputList(
'l.STARTORBIT',
'startorbit')
1267 queryHandle.addToOutputList(
'l.BEAMSTATUS',
'beamstatus')
1268 queryHandle.addToOutputList(
'l.BEAMENERGY',
'beamenergy')
1269 queryHandle.addToOutputList(
't.TRGCOUNT',
'trgcount')
1270 queryHandle.addToOutputList(
't.DEADTIME',
'deadtime')
1271 queryHandle.addToOutputList(
't.BITNAME',
'bitname')
1272 queryHandle.addToOutputList(
't.PRESCALE',
'prescale')
1273 conditionstring=
't.BITNUM=:bitnum and l.RUNNUM=:runnum and l.LUMIVERSION=:lumiversion and l.RUNNUM=t.RUNNUM and t.CMSLSNUM=l.CMSLSNUM' 1274 if beamstatus
and len(beamstatus)!=0:
1275 conditionstring=conditionstring+
' and l.BEAMSTATUS=:beamstatus' 1276 queryCondition.extend(
'beamstatus',
'string')
1277 queryCondition[
'beamstatus'].setData(beamstatus)
1278 if beamenergy
and beamenergy!=0.0:
1279 minBeamenergy=
float(beamenergy*(1-beamenergyfluctuation))
1280 maxBeamenergy=
float(beamenergy*(1+beamenergyfluctuation))
1281 conditionstring=conditionstring+
' and l.BEAMENERGY>:minBeamenergy and l.BEAMENERGY<:maxBeamenergy' 1282 queryCondition.extend(
'minBeamenergy',
'float')
1283 queryCondition.extend(
'maxBeamenergy',
'float')
1284 queryCondition[
'minBeamenergy'].setData(
float(minBeamenergy))
1285 queryCondition[
'maxBeamenergy'].setData(
float(maxBeamenergy))
1286 queryHandle.setCondition(conditionstring,queryCondition)
1287 queryResult=coral.AttributeList()
1288 queryResult.extend(
'cmslsnum',
'unsigned int')
1289 queryResult.extend(
'instlumi',
'float')
1290 queryResult.extend(
'numorbit',
'unsigned int')
1291 queryResult.extend(
'startorbit',
'unsigned int')
1292 queryResult.extend(
'beamstatus',
'string')
1293 queryResult.extend(
'beamenergy',
'float')
1294 queryResult.extend(
'trgcount',
'unsigned int')
1295 queryResult.extend(
'deadtime',
'unsigned int')
1296 queryResult.extend(
'bitname',
'string')
1297 queryResult.extend(
'prescale',
'unsigned int')
1298 queryHandle.defineOutput(queryResult)
1299 cursor=queryHandle.execute()
1301 cmslsnum=cursor.currentRow()[
'cmslsnum'].
data()
1302 instlumi=cursor.currentRow()[
'instlumi'].
data()
1304 instlumi=lumiCorrections.applyfinecorrection(instlumi,finecorrections[0],finecorrections[1],finecorrections[2])
1305 numorbit=cursor.currentRow()[
'numorbit'].
data()
1306 startorbit=cursor.currentRow()[
'startorbit'].
data()
1307 beamstatus=cursor.currentRow()[
'beamstatus'].
data()
1308 beamenergy=cursor.currentRow()[
'beamenergy'].
data()
1309 trgcount=cursor.currentRow()[
'trgcount'].
data()
1310 deadtime=cursor.currentRow()[
'deadtime'].
data()
1311 bitname=cursor.currentRow()[
'bitname'].
data()
1312 prescale=cursor.currentRow()[
'prescale'].
data()
1313 if cmslsnum
not in result:
1314 result[cmslsnum]=[instlumi,numorbit,startorbit,beamstatus,beamenergy,trgcount,deadtime,bitname,prescale]
1319 select cmslsnum,trgcount,deadtime,bitnum,prescale from trg where runnum=:runnum and bitname=:bitname; 1320 output: {cmslsnum:[trgcount,deadtime,bitnum,prescale]} 1324 queryCondition=coral.AttributeList()
1325 queryCondition.extend(
'runnum',
'unsigned int')
1326 queryCondition.extend(
'bitname',
'string')
1327 queryCondition[
'runnum'].setData(
int(runnum))
1328 queryCondition[
'bitname'].setData(bitname)
1329 queryHandle.addToOutputList(
'CMSLSNUM',
'cmslsnum')
1330 queryHandle.addToOutputList(
'TRGCOUNT',
'trgcount')
1331 queryHandle.addToOutputList(
'DEADTIME',
'deadtime')
1332 queryHandle.addToOutputList(
'BITNUM',
'bitnum')
1333 queryHandle.addToOutputList(
'PRESCALE',
'prescale')
1334 queryHandle.setCondition(
'RUNNUM=:runnum and BITNAME=:bitname',queryCondition)
1335 queryResult=coral.AttributeList()
1336 queryResult.extend(
'cmslsnum',
'unsigned int')
1337 queryResult.extend(
'trgcount',
'unsigned int')
1338 queryResult.extend(
'deadtime',
'unsigned long long')
1339 queryResult.extend(
'bitnum',
'unsigned int')
1340 queryResult.extend(
'prescale',
'unsigned int')
1341 queryHandle.defineOutput(queryResult)
1342 cursor=queryHandle.execute()
1344 cmslsnum=cursor.currentRow()[
'cmslsnum'].
data()
1345 trgcount=cursor.currentRow()[
'trgcount'].
data()
1346 deadtime=cursor.currentRow()[
'deadtime'].
data()
1347 bitnum=cursor.currentRow()[
'bitnum'].
data()
1348 prescale=cursor.currentRow()[
'prescale'].
data()
1349 if cmslsnum
not in result:
1350 result[cmslsnum]=[trgcount,deadtime,bitnum,prescale]
1355 all you ever want to know about trigger 1356 select cmslsnum,trgcount,deadtime,bitnum,bitname,prescale from trg where runnum=:runnum order by bitnum,cmslsnum 1357 this can be changed to blob query later 1358 output: {cmslsnum:{bitname:[bitnum,trgcount,deadtime,prescale]}} 1362 queryCondition=coral.AttributeList()
1363 queryCondition.extend(
'runnum',
'unsigned int')
1364 queryCondition[
'runnum'].setData(
int(runnum))
1365 queryHandle.addToOutputList(
'cmslsnum')
1366 queryHandle.addToOutputList(
'trgcount')
1367 queryHandle.addToOutputList(
'deadtime')
1368 queryHandle.addToOutputList(
'bitnum')
1369 queryHandle.addToOutputList(
'bitname')
1370 queryHandle.addToOutputList(
'prescale')
1371 queryHandle.setCondition(
'runnum=:runnum',queryCondition)
1372 queryResult=coral.AttributeList()
1373 queryResult.extend(
'cmslsnum',
'unsigned int')
1374 queryResult.extend(
'trgcount',
'unsigned int')
1375 queryResult.extend(
'deadtime',
'unsigned long long')
1376 queryResult.extend(
'bitnum',
'unsigned int')
1377 queryResult.extend(
'bitname',
'string')
1378 queryResult.extend(
'prescale',
'unsigned int')
1379 queryHandle.defineOutput(queryResult)
1380 queryHandle.addToOrderList(
'bitnum')
1381 queryHandle.addToOrderList(
'cmslsnum')
1382 cursor=queryHandle.execute()
1384 cmslsnum=cursor.currentRow()[
'cmslsnum'].
data()
1385 trgcount=cursor.currentRow()[
'trgcount'].
data()
1386 deadtime=cursor.currentRow()[
'deadtime'].
data()
1387 bitnum=cursor.currentRow()[
'bitnum'].
data()
1388 bitname=cursor.currentRow()[
'bitname'].
data()
1389 prescale=cursor.currentRow()[
'prescale'].
data()
1390 if cmslsnum
not in result:
1392 dataperLS[bitname]=[bitnum,trgcount,deadtime,prescale]
1393 result[cmslsnum]=dataperLS
1395 result[cmslsnum][bitname]=[bitnum,trgcount,deadtime,prescale]
1401 select cmslsnum,inputcount,acceptcount,prescale from hlt where runnum=:runnum and pathname=:pathname 1402 output: {cmslsnum:[inputcount,acceptcount,prescale]} 1406 queryCondition=coral.AttributeList()
1407 queryCondition.extend(
'runnum',
'unsigned int')
1408 queryCondition.extend(
'pathname',
'string')
1409 queryCondition[
'runnum'].setData(
int(runnum))
1410 queryCondition[
'pathname'].setData(hltpath)
1411 queryHandle.addToOutputList(
'CMSLSNUM',
'cmslsnum')
1412 queryHandle.addToOutputList(
'INPUTCOUNT',
'inputcount')
1413 queryHandle.addToOutputList(
'ACCEPTCOUNT',
'acceptcount')
1414 queryHandle.addToOutputList(
'PRESCALE',
'prescale')
1415 queryHandle.setCondition(
'RUNNUM=:runnum and PATHNAME=:pathname',queryCondition)
1416 queryResult=coral.AttributeList()
1417 queryResult.extend(
'cmslsnum',
'unsigned int')
1418 queryResult.extend(
'inputcount',
'unsigned int')
1419 queryResult.extend(
'acceptcount',
'unsigned int')
1420 queryResult.extend(
'prescale',
'unsigned int')
1421 queryHandle.defineOutput(queryResult)
1422 cursor=queryHandle.execute()
1424 cmslsnum=cursor.currentRow()[
'cmslsnum'].
data()
1425 inputcount=cursor.currentRow()[
'inputcount'].
data()
1426 acceptcount=cursor.currentRow()[
'acceptcount'].
data()
1427 prescale=cursor.currentRow()[
'prescale'].
data()
1428 if cmslsnum
not in result:
1429 result[cmslsnum]=[inputcount,acceptcount,prescale]
1434 select cmslsnum,inputcount,acceptcount,prescale,pathname from hlt where runnum=:runnum 1435 this can be changed to blob query later 1436 output: {cmslsnum:{pathname:[inputcount,acceptcount,prescale]}} 1440 queryCondition=coral.AttributeList()
1441 queryCondition.extend(
'runnum',
'unsigned int')
1442 queryCondition[
'runnum'].setData(
int(runnum))
1443 queryHandle.addToOutputList(
'CMSLSNUM',
'cmslsnum')
1444 queryHandle.addToOutputList(
'INPUTCOUNT',
'inputcount')
1445 queryHandle.addToOutputList(
'ACCEPTCOUNT',
'acceptcount')
1446 queryHandle.addToOutputList(
'PRESCALE',
'prescale')
1447 queryHandle.addToOutputList(
'PATHNAME',
'pathname')
1448 queryHandle.setCondition(
'RUNNUM=:runnum',queryCondition)
1449 queryResult=coral.AttributeList()
1450 queryResult.extend(
'cmslsnum',
'unsigned int')
1451 queryResult.extend(
'inputcount',
'unsigned int')
1452 queryResult.extend(
'acceptcount',
'unsigned int')
1453 queryResult.extend(
'prescale',
'unsigned int')
1454 queryResult.extend(
'pathname',
'string')
1455 queryHandle.defineOutput(queryResult)
1456 cursor=queryHandle.execute()
1458 cmslsnum=cursor.currentRow()[
'cmslsnum'].
data()
1459 inputcount=cursor.currentRow()[
'inputcount'].
data()
1460 acceptcount=cursor.currentRow()[
'acceptcount'].
data()
1461 prescale=cursor.currentRow()[
'prescale'].
data()
1462 pathname=cursor.currentRow()[
'pathname'].
data()
1463 if cmslsnum
not in result:
1465 dataperLS[pathname]=[inputcount,acceptcount,prescale]
1466 result[cmslsnum]=dataperLS
1468 result[cmslsnum][pathname]=[inputcount,acceptcount,prescale]
1474 select CMSBXINDEXBLOB,BEAMINTENSITYBLOB_1,BEAMINTENSITYBLOB_2 from LUMISUMMARY where runnum=146315 and LUMIVERSION='0001' 1476 output : result {startorbit: [(bxidx,beam1intensity,beam2intensity)]} 1480 lumisummaryOutput=coral.AttributeList()
1481 lumisummaryOutput.extend(
'cmslsnum',
'unsigned int')
1482 lumisummaryOutput.extend(
'startorbit',
'unsigned int')
1483 lumisummaryOutput.extend(
'bxindexblob',
'blob');
1484 lumisummaryOutput.extend(
'beamintensityblob1',
'blob');
1485 lumisummaryOutput.extend(
'beamintensityblob2',
'blob');
1486 condition=coral.AttributeList()
1487 condition.extend(
'runnum',
'unsigned int')
1488 condition.extend(
'lumiversion',
'string')
1489 condition[
'runnum'].setData(
int(runnum))
1490 condition[
'lumiversion'].setData(parameters.lumiversion)
1492 query.addToTableList(parameters.lumisummaryname)
1493 query.addToOutputList(
'CMSLSNUM',
'cmslsnum')
1494 query.addToOutputList(
'STARTORBIT',
'startorbit')
1495 query.addToOutputList(
'CMSBXINDEXBLOB',
'bxindexblob')
1496 query.addToOutputList(
'BEAMINTENSITYBLOB_1',
'beamintensityblob1')
1497 query.addToOutputList(
'BEAMINTENSITYBLOB_2',
'beamintensityblob2')
1498 query.setCondition(
'RUNNUM=:runnum AND LUMIVERSION=:lumiversion',condition)
1499 query.defineOutput(lumisummaryOutput)
1500 cursor=query.execute()
1503 startorbit=cursor.currentRow()[
'startorbit'].
data()
1508 beamintensityblob1=
None 1509 beamintensityblob2=
None 1510 if not cursor.currentRow()[
"bxindexblob"].isNull():
1511 bxindexblob=cursor.currentRow()[
'bxindexblob'].
data()
1512 if bxindexblob
and bxindexblob.readline()!=
None:
1514 if not cursor.currentRow()[
'beamintensityblob1'].isNull():
1515 beamintensityblob1=cursor.currentRow()[
'beamintensityblob1'].
data()
1516 if beamintensityblob1
and beamintensityblob1.readline()!=
None:
1518 if not cursor.currentRow()[
'beamintensityblob2'].isNull():
1519 beamintensityblob2=cursor.currentRow()[
'beamintensityblob2'].
data()
1520 if beamintensityblob2
and beamintensityblob2.readline()!=
None:
1522 if startorbit
not in result:
1523 result[startorbit]=[]
1524 for idx,bxidxvalue
in enumerate(bxidx):
1526 b1intensity=bb1[idx]
1530 b2intensity=bb2[idx]
1533 result[startorbit].
append((bxidxvalue,b1intensity,b2intensity))
1541 s.cmslsnum,d.bxlumivalue,d.bxlumierror,d.bxlumiquality,d.algoname from LUMIDETAIL d,LUMISUMMARY s where s.runnum=133885 and d.algoname='OCC1' and s.lumisummary_id=d.lumisummary_id order by s.startorbit,s.cmslsnum 1542 result={(startorbit,cmslsnum):[(index,lumivalue,lumierr),]} 1545 detailOutput=coral.AttributeList()
1546 detailOutput.extend(
'cmslsnum',
'unsigned int')
1547 detailOutput.extend(
'startorbit',
'unsigned int')
1548 detailOutput.extend(
'bxlumivalue',
'blob')
1549 detailOutput.extend(
'bxlumierror',
'blob')
1550 detailCondition=coral.AttributeList()
1551 detailCondition.extend(
'runnum',
'unsigned int')
1552 detailCondition.extend(
'algoname',
'string')
1553 detailCondition[
'runnum'].setData(runnum)
1554 detailCondition[
'algoname'].setData(algoname)
1556 query.addToTableList(parameters.lumisummaryname,
's')
1557 query.addToTableList(parameters.lumidetailname,
'd')
1558 query.addToOutputList(
's.CMSLSNUM',
'cmslsnum')
1559 query.addToOutputList(
's.STARTORBIT',
'startorbit')
1560 query.addToOutputList(
'd.BXLUMIVALUE',
'bxlumivalue')
1561 query.addToOutputList(
'd.BXLUMIERROR',
'bxlumierror')
1562 query.addToOutputList(
'd.BXLUMIQUALITY',
'bxlumiquality')
1563 query.setCondition(
's.RUNNUM=:runnum and d.ALGONAME=:algoname and s.LUMISUMMARY_ID=d.LUMISUMMARY_ID',detailCondition)
1564 query.defineOutput(detailOutput)
1565 cursor=query.execute()
1567 cmslsnum=cursor.currentRow()[
'cmslsnum'].
data()
1568 bxlumivalue=cursor.currentRow()[
'bxlumivalue'].
data()
1569 bxlumierror=cursor.currentRow()[
'bxlumierror'].
data()
1570 startorbit=cursor.currentRow()[
'startorbit'].
data()
1571 bxlumivalueArray=array.array(
'f')
1572 bxlumivalueArray.fromstring(bxlumivalue.readline())
1573 bxlumierrorArray=array.array(
'f')
1574 bxlumierrorArray.fromstring(bxlumierror.readline())
1578 if len(bxlumivalueArray)!=0:
1579 maxlumi=
max(bxlumivalueArray)
1581 if len(bxlumivalueArray)!=0:
1582 avginstlumi=sum(bxlumivalueArray)
1583 for index,lum
in enumerate(bxlumivalueArray):
1584 lumierror = bxlumierrorArray[index]
1585 if lum<
max(parameters.xingMinLum,maxlumi*0.2):
1587 mynorm=parameters.normFactor
1589 lum=lumiCorrections.applyfinecorrectionBX(lum,avginstlumi*mynorm,mynorm,finecorrection[0],finecorrection[1],finecorrection[2])
1590 lumierror=lumiCorrections.applyfinecorrectionBX(lumierror,avginstlumi*mynorm,mynorm,finecorrection[0],finecorrection[1],finecorrection[2])
1594 xingLum.append( (index,lum,lumierror) )
1596 result[(startorbit,cmslsnum)]=xingLum
1601 select s.cmslsnum,d.bxlumivalue,d.bxlumierror,d.bxlumiquality,s.startorbit from LUMIDETAIL d,LUMISUMMARY s where s.runnum=:runnum and d.algoname=:algoname and s.lumisummary_id=d.lumisummary_id order by s.startorbit 1602 output: [[cmslsnum,bxlumivalue,bxlumierror,bxlumiquality,startorbit]] 1603 since the output is ordered by time, it has to be in seq list format 1608 queryCondition=coral.AttributeList()
1609 queryCondition.extend(
'runnum',
'unsigned int')
1610 queryCondition.extend(
'algoname',
'string')
1611 queryCondition[
'runnum'].setData(
int(runnum))
1612 queryCondition[
'algoname'].setData(algoname)
1613 queryHandle.addToOutputList(
's.CMSLSNUM',
'cmslsnum')
1614 queryHandle.addToOutputList(
'd.BXLUMIVALUE',
'bxlumivalue')
1615 queryHandle.addToOutputList(
'd.BXLUMIERROR',
'bxlumierror')
1616 queryHandle.addToOutputList(
'd.BXLUMIQUALITY',
'bxlumiquality')
1617 queryHandle.addToOutputList(
's.STARTORBIT',
'startorbit')
1618 queryHandle.setCondition(
's.runnum=:runnum and d.algoname=:algoname and s.lumisummary_id=d.lumisummary_id',queryCondition)
1619 queryResult=coral.AttributeList()
1620 queryResult.extend(
'cmslsnum',
'unsigned int')
1621 queryResult.extend(
'bxlumivalue',
'blob')
1622 queryResult.extend(
'bxlumierror',
'blob')
1623 queryResult.extend(
'bxlumiquality',
'blob')
1624 queryResult.extend(
'startorbit',
'unsigned int')
1625 queryHandle.addToOrderList(
's.STARTORBIT')
1626 queryHandle.defineOutput(queryResult)
1627 cursor=queryHandle.execute()
1629 cmslsnum=cursor.currentRow()[
'cmslsnum'].
data()
1630 bxlumivalue=cursor.currentRow()[
'bxlumivalue'].
data()
1631 bxlumierror=cursor.currentRow()[
'bxlumierror'].
data()
1632 bxlumiquality=cursor.currentRow()[
'bxlumiquality'].
data()
1633 startorbit=cursor.currentRow()[
'startorbit'].
data()
1634 result.append([cmslsnum,bxlumivalue,bxlumierror,bxlumiquality,startorbit])
1639 select s.cmslsnum,d.bxlumivalue,d.bxlumierror,d.bxlumiquality,d.algoname,s.startorbit from LUMIDETAIL d,LUMISUMMARY s where s.runnum=:runnumber and s.lumisummary_id=d.lumisummary_id order by s.startorbit,d.algoname 1640 output: {algoname:{cmslsnum:[bxlumivalue,bxlumierror,bxlumiquality,startorbit]}} 1645 queryCondition=coral.AttributeList()
1646 queryCondition.extend(
'runnum',
'unsigned int')
1647 queryCondition[
'runnum'].setData(
int(runnum))
1648 queryHandle.addToOutputList(
's.CMSLSNUM',
'cmslsnum')
1649 queryHandle.addToOutputList(
'd.BXLUMIVALUE',
'bxlumivalue')
1650 queryHandle.addToOutputList(
'd.BXLUMIERROR',
'bxlumierror')
1651 queryHandle.addToOutputList(
'd.BXLUMIQUALITY',
'bxlumiquality')
1652 queryHandle.addToOutputList(
'd.ALGONAME',
'algoname')
1653 queryHandle.addToOutputList(
's.STARTORBIT',
'startorbit')
1654 queryHandle.setCondition(
's.RUNNUM=:runnum and s.LUMISUMMARY_ID=d.LUMISUMMARY_ID',queryCondition)
1655 queryResult=coral.AttributeList()
1656 queryResult.extend(
'cmslsnum',
'unsigned int')
1657 queryResult.extend(
'bxlumivalue',
'blob')
1658 queryResult.extend(
'bxlumierror',
'blob')
1659 queryResult.extend(
'bxlumiquality',
'blob')
1660 queryResult.extend(
'algoname',
'string')
1661 queryResult.extend(
'startorbit',
'unsigned int')
1662 queryHandle.addToOrderList(
'startorbit')
1663 queryHandle.addToOrderList(
'algoname')
1664 queryHandle.defineOutput(queryResult)
1665 cursor=queryHandle.execute()
1667 cmslsnum=cursor.currentRow()[
'cmslsnum'].
data()
1668 bxlumivalue=cursor.currentRow()[
'bxlumivalue'].
data()
1669 bxlumierror=cursor.currentRow()[
'bxlumierror'].
data()
1670 bxlumiquality=cursor.currentRow()[
'bxlumiquality'].
data()
1671 algoname=cursor.currentRow()[
'algoname'].
data()
1672 startorbit=cursor.currentRow()[
'startorbit'].
data()
1673 if algoname
not in result:
1675 dataPerAlgo[cmslsnum]=[bxlumivalue,bxlumierror,bxlumiquality,startorbit]
1676 result[algoname]=dataPerAlgo
1678 result[algoname][cmslsnum]=[bxlumivalue,bxlumierror,bxlumiquality,startorbit]
1683 select m.hltpathname,m.l1seed from cmsrunsummary r,trghltmap m where r.runnum=:runnum and m.hltkey=r.hltkey 1684 output: {hltpath:l1seed} 1689 queryCondition=coral.AttributeList()
1690 queryCondition.extend(
'runnum',
'unsigned int')
1691 queryCondition[
'runnum'].setData(
int(runnum))
1692 queryHandle.addToOutputList(
'm.HLTPATHNAME',
'hltpathname')
1693 queryHandle.addToOutputList(
'm.L1SEED',
'l1seed')
1694 queryHandle.setCondition(
'r.RUNNUM=:runnum and m.HLTKEY=r.HLTKEY',queryCondition)
1695 queryResult=coral.AttributeList()
1696 queryResult.extend(
'hltpathname',
'string')
1697 queryResult.extend(
'l1seed',
'string')
1698 queryHandle.defineOutput(queryResult)
1699 cursor=queryHandle.execute()
1701 hltpathname=cursor.currentRow()[
'hltpathname'].
data()
1702 l1seed=cursor.currentRow()[
'l1seed'].
data()
1703 if hltpathname
not in result:
1704 result[hltpathname]=l1seed
1709 find all runs in the fill range inclusive 1710 select runnum,fillnum from cmsrunsummary where fillnum>=:minFill and fillnum<=:maxFill 1711 output: fillDict={fillnum:[runlist]} 1715 queryCondition=coral.AttributeList()
1716 queryCondition.extend(
'minFill',
'unsigned int')
1717 queryCondition.extend(
'maxFill',
'unsigned int')
1718 queryCondition[
'minFill'].setData(
int(minFill))
1719 queryCondition[
'maxFill'].setData(
int(maxFill))
1720 queryHandle.addToOutputList(
'RUNNUM',
'runnum')
1721 queryHandle.addToOutputList(
'FILLNUM',
'fillnum')
1722 queryHandle.setCondition(
'FILLNUM>=:minFill and FILLNUM<=:maxFill',queryCondition)
1723 queryResult=coral.AttributeList()
1724 queryResult.extend(
'runnum',
'unsigned int')
1725 queryResult.extend(
'fillnum',
'unsigned int')
1726 queryHandle.defineOutput(queryResult)
1727 cursor=queryHandle.execute()
1729 runnum=cursor.currentRow()[
'runnum'].
data()
1730 fillnum=cursor.currentRow()[
'fillnum'].
data()
1731 if fillnum
not in result:
1732 result[fillnum]=[runnum]
1734 result[fillnum].
append(runnum)
1739 find all runs in the time range inclusive 1740 the selected run must have started after minTime and finished by maxTime 1741 select runnum,to_char(startTime),to_char(stopTime) from cmsrunsummary where startTime>=timestamp(minTime) and stopTime<=timestamp(maxTime); 1742 input: minTime,maxTime in python obj datetime.datetime 1743 output: {runnum:[starttime,stoptime]} return in python obj datetime.datetime 1747 coralminTime=coral.TimeStamp(minTime.year,minTime.month,minTime.day,minTime.hour,minTime.minute,minTime.second,0)
1748 coralmaxTime=coral.TimeStamp(maxTime.year,maxTime.month,maxTime.day,maxTime.hour,maxTime.minute,maxTime.second,0)
1750 queryCondition=coral.AttributeList()
1751 queryCondition.extend(
'minTime',
'time stamp')
1752 queryCondition.extend(
'maxTime',
'time stamp')
1753 queryCondition[
'minTime'].setData(coralminTime)
1754 queryCondition[
'maxTime'].setData(coralmaxTime)
1755 queryHandle.addToOutputList(
'RUNNUM',
'runnum')
1756 queryHandle.addToOutputList(
'TO_CHAR(STARTTIME,\''+t.coraltimefm+
'\')',
'starttime')
1757 queryHandle.addToOutputList(
'TO_CHAR(STOPTIME,\''+t.coraltimefm+
'\')',
'stoptime')
1758 queryHandle.setCondition(
'STARTTIME>=:minTime and STOPTIME<=:maxTime',queryCondition)
1759 queryResult=coral.AttributeList()
1760 queryResult.extend(
'runnum',
'unsigned int')
1761 queryResult.extend(
'starttime',
'string')
1762 queryResult.extend(
'stoptime',
'string')
1763 queryHandle.defineOutput(queryResult)
1764 cursor=queryHandle.execute()
1766 runnum=cursor.currentRow()[
'runnum'].
data()
1767 starttimeStr=cursor.currentRow()[
'starttime'].
data()
1768 stoptimeStr=cursor.currentRow()[
'stoptime'].
data()
1769 if runnum
not in result:
1770 result[runnum]=[t.StrToDatetime(starttimeStr),t.StrToDatetime(stoptimeStr)]
1773 if __name__==
'__main__':
1774 msg=coral.MessageStream(
'')
1776 msg.setMsgVerbosity(coral.message_Level_Error)
1777 os.environ[
'CORAL_AUTH_PATH']=
'/afs/cern.ch/cms/DB/lumi' 1778 svc = coral.ConnectionService()
1779 connectstr=
'oracle://cms_orcoff_prod/cms_lumi_prod' 1780 session=svc.connect(connectstr,accessMode=coral.access_ReadOnly)
1781 session.typeConverter().setCppTypeForSqlType(
"unsigned int",
"NUMBER(10)")
1782 session.typeConverter().setCppTypeForSqlType(
"unsigned long long",
"NUMBER(20)")
1783 session.transaction().
start(
True)
1784 schema=session.nominalSchema()
1785 allruns=
allruns(schema,requireLumisummary=
True,requireTrg=
True,requireHlt=
True)
1786 print 'allruns in runsummary and lumisummary and trg and hlt ',len(allruns)
1845 session.transaction().commit()
1880 print 'all fills ',allfills
def mergeXingLumi(triplet, xingLumiDict)
def calculateTimeParameters(self)
def printDeliveredLumi(lumidata, mode)
def splitlistToRangeString(inPut)
def getDeadfractions(deadtable)
def deliveredLumiForRun(dbsession, parameters, runnum, finecorrections=None)
def trgbitzeroByrun(queryHandle, runnum)
def printPerLSLumi(lumidata, isVerbose=False)
def calculateTotalRecorded(deadtable)
def validation(queryHandle, run=None, cmsls=None)
def lumidetailByrunByAlgo(queryHandle, runnum, algoname='OCC1')
def setupSession(connectString, siteconfpath, parameters, debug=False)
def defaultfrontierConfigString(self)
def unpackBlobtoArray(iblob, itemtypecode)
def hltBypathByrun(queryHandle, runnum, hltpath)
def hlttrgMappingByrun(queryHandle, runnum)
def lumidetailAllalgosByrun(queryHandle, runnum)
def lumidetailTableName()
def runsummaryByrun(queryHandle, runnum)
def dumpPerLSLumi(lumidata)
def lumisummaryTableName()
def trgAllbitsByrun(queryHandle, runnum)
def calculateEffective(trgtable, totalrecorded)
def printRecordedLumi(lumidata, isVerbose=False, hltpath='')
def beamIntensityForRun(query, parameters, runnum)
def filterDeadtable(inTable, lslist)
def deliveredLumiForRange(dbsession, parameters, inputRange, finecorrections=None)
def lslengthsec(numorbit, numbx)
def runsByfillrange(queryHandle, minFill, maxFill)
==============temporarilly here======###
def recordedLumiForRange(dbsession, parameters, inputRange, finecorrections=None)
def printOverviewData(delivered, recorded, hltpath='')
def lumivalidationTableName()
def runsByTimerange(queryHandle, minTime, maxTime)
def xingLuminosityForRun(dbsession, runnum, parameters, lumiXingDict={}, maxLumiSection=None, finecorrections=None)
def dumpData(lumidata, filename)
def recordedLumiForRun(dbsession, parameters, runnum, lslist=None, finecorrections=None)
def dumpRecordedLumi(lumidata, hltpath='')
def calibratedDetailForRunLimitresult(query, parameters, runnum, algoname='OCC1', finecorrection=None)
def lsBylsLumi(deadtable)
def lumisummaryByrun(queryHandle, runnum, lumiversion, beamstatus=None, beamenergy=None, beamenergyfluctuation=0.09, finecorrections=None)
char data[epos_bytes_allocation]
def lumisummarytrgbitzeroByrun(queryHandle, runnum, lumiversion, beamstatus=None, beamenergy=None, beamenergyfluctuation=0.09, finecorrections=None)
def lumisumByrun(queryHandle, runnum, lumiversion, beamstatus=None, beamenergy=None, beamenergyfluctuation=0.09, finecorrections=None)
def cmsrunsummaryTableName()
def dumpOverview(delivered, recorded, hltpath='')
def hltAllpathByrun(queryHandle, runnum)
def trgBybitnameByrun(queryHandle, runnum, bitname)