3 from RecoLuminosity.LumiDB
import nameDealer,lumiTime,CommonUtil,lumiCorrections
5 from RecoLuminosity.LumiDB
import argparse, nameDealer, selectionParser, hltTrgSeedMapper, \
6 connectstrParser, cacheconfigParser, tablePrinter, csvReporter, csvSelectionParser
7 from RecoLuminosity.LumiDB.wordWrappers
import wrap_always, wrap_onspace, wrap_onspace_strict
8 from pprint
import pprint, pformat
11 This module defines lowlevel SQL query API for lumiDB 12 We do not like range queries so far because of performance of range scan.Use only necessary. 13 The principle is to query by runnumber and per each coral queryhandle 14 Try reuse db session/transaction and just renew query handle each time to reduce metadata queries. 15 Avoid unnecessary explicit order by 16 Do not handle transaction in here. 17 Do not do explicit del queryhandle in here. 18 Note: all the returned dict format are not sorted by itself.Sort it outside if needed. 46 '''Given the rotation rate, calculate lumi section length and 47 rotation time. This should be called if rotationRate is 53 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>''' 57 l = numorbit * numbx * 25.0e-09
62 input: {lsnum:[deadtime, instlumi, bit_0, norbits,prescale...]} 63 output: {lsnum:[instlumi, recordedlumi...]} 66 for myls, deadArray
in deadtable.items():
67 lstime = lslengthsec (deadArray[3], 3564)
68 instlumi = deadArray[1] * lstime
69 if float( deadArray[2] ) == 0.0:
72 deadfrac = float (deadArray[0]) / (float (deadArray[2])*
float(deadArray[4]))
73 recordedLumi = instlumi * (1.0 - deadfrac)
74 myLsList = [instlumi, recordedLumi]
76 if len (deadArray) > 5:
77 myLsList.extend (deadArray[5:])
78 result[myls] = myLsList
83 '''Takes either single run as a string or dictionary of run ranges''' 86 if isinstance(inputRange, str):
87 runs.append(
int(inputRange))
89 runs=inputRange.runs()
90 for r
in sorted(runs):
91 if parameters.verbose:
96 lumidata.append( deliveredLumiForRun (dbsession, parameters,r,finecorrections=c) )
100 '''Takes either single run as a string or dictionary of run ranges''' 102 if isinstance(inputRange,str):
104 if finecorrections
and finecorrections[run]:
105 lumiDataPiece = recordedLumiForRun (dbsession, parameters,inputRange,lslist=
None,finecorrections=finecorrections[run])
108 if parameters.lumiXing:
110 if finecorrections
and finecorrections[run]:
111 xingLumiDict = xingLuminosityForRun (dbsession, inputRange,
112 parameters,finecorrections=finecorrections[run])
114 xingLumiDict = xingLuminosityForRun (dbsession, inputRange,
116 mergeXingLumi (lumiDataPiece, xingLumiDict)
117 lumidata.append (lumiDataPiece)
121 maxLumiSectionDict = {}
122 for (run, lslist)
in sorted (inputRange.runsandls().
items() ):
124 maxLumiSectionDict[run] = max ( max (lslist),
125 maxLumiSectionDict.get(run,0) )
126 runLsDict.setdefault (run, []).append (lslist)
127 for run, metaLsList
in sorted (runLsDict.iteritems()):
128 if parameters.verbose:
131 for lslist
in metaLsList:
132 if finecorrections
and finecorrections[run]:
133 runLumiData.append( recordedLumiForRun (dbsession, parameters,run,lslist=lslist,finecorrections=finecorrections[run]) )
136 runLumiData.append( recordedLumiForRun (dbsession, parameters,run,lslist=lslist) )
137 if parameters.lumiXing:
139 if finecorrections
and finecorrections[run]:
140 xingLumiDict = xingLuminosityForRun (dbsession, run,
143 maxLumiSectionDict[run],
144 finecorrections=finecorrections[run])
146 xingLumiDict = xingLuminosityForRun (dbsession, run,
149 maxLumiSectionDict[run])
151 for lumiDataPiece
in runLumiData:
152 mergeXingLumi (lumiDataPiece, xingLumiDict)
153 lumidata.append (lumiDataPiece)
155 lumidata.extend( runLumiData )
160 select sum (INSTLUMI), count (INSTLUMI) from lumisummary where runnum = 124025 and lumiversion = '0001'; 161 select INSTLUMI,NUMORBIT from lumisummary where runnum = 124025 and lumiversion = '0001' 162 query result unit E27cm^-2 (= 1 / mb) 164 optional corrections=None/(constfactor,afterglowfactor,nonlinearfactor) 172 conditionstring=
"RUNNUM = :runnum AND LUMIVERSION = :lumiversion" 173 dbsession.transaction().start (
True)
174 schema = dbsession.nominalSchema()
176 query.addToOutputList(
"INSTLUMI",
'instlumi')
177 query.addToOutputList (
"NUMORBIT",
"norbits")
178 queryBind = coral.AttributeList()
179 queryBind.extend (
"runnum",
"unsigned int")
180 queryBind.extend (
"lumiversion",
"string")
181 queryBind[
"runnum"].setData (int (runnum))
182 queryBind[
"lumiversion"].setData (parameters.lumiversion)
184 if len(parameters.beammode)!=0:
185 conditionstring=conditionstring+
' and BEAMSTATUS=:beamstatus' 186 queryBind.extend(
'beamstatus',
'string')
187 queryBind[
'beamstatus'].setData(parameters.beammode)
188 result = coral.AttributeList()
189 result.extend (
"instlumi",
"float")
190 result.extend (
"norbits",
"unsigned int")
191 query.defineOutput (result)
192 query.setCondition (conditionstring,queryBind)
193 cursor = query.execute()
195 instlumi = cursor.currentRow()[
'instlumi'].
data()
196 norbits = cursor.currentRow()[
'norbits'].
data()
197 if finecorrections
is not None:
198 instlumi=lumiCorrections.applyfinecorrection(instlumi,finecorrections[0],finecorrections[1],finecorrections[2])
199 if instlumi
is not None and norbits
is not None:
201 delivered=delivered+instlumi*parameters.norm*lstime
204 dbsession.transaction().commit()
207 lumidata = [str (runnum),
'N/A',
'N/A',
'N/A']
209 lumidata = [str (runnum), str (totalls),
'%.3f'%delivered, parameters.beammode]
211 except Exception
as e:
213 dbsession.transaction().rollback()
218 lslist = [] means take none in the db 219 lslist = None means to take all in the db 220 output: ['runnumber', 'trgtable{}', 'deadtable{}'] 226 lumidata.append (runnum)
227 lumidata.append (trgtable)
228 lumidata.append (deadtable)
230 conditionstring=
'trghltmap.HLTKEY = cmsrunsummary.HLTKEY AND cmsrunsummary.RUNNUM = :runnumber' 232 dbsession.transaction().start (
True)
233 schema = dbsession.nominalSchema()
234 query = schema.newQuery()
237 queryCondition = coral.AttributeList()
238 queryCondition.extend (
"runnumber",
"unsigned int")
239 queryCondition[
"runnumber"].setData (int (runnum))
240 query.setCondition (conditionstring,queryCondition)
241 query.addToOutputList (
"trghltmap.HLTPATHNAME",
"hltpathname")
242 query.addToOutputList (
"trghltmap.L1SEED",
"l1seed")
243 result = coral.AttributeList()
244 result.extend (
"hltpathname",
"string")
245 result.extend (
"l1seed",
"string")
246 query.defineOutput (result)
247 cursor = query.execute()
249 hltpathname = cursor.currentRow()[
"hltpathname"].
data()
250 l1seed = cursor.currentRow()[
"l1seed"].
data()
251 collectedseeds.append ( (hltpathname, l1seed))
254 dbsession.transaction().commit()
256 for (hname, sname)
in collectedseeds:
257 l1bitname = hltTrgSeedMapper.findUniqueSeed (hname, sname)
260 lumidata[1][hname] = []
261 lumidata[1][hname].append (l1bitname.replace (
'\"',
''))
262 dbsession.transaction().start (
True)
263 schema = dbsession.nominalSchema()
265 hltprescQuery.addToOutputList (
"PATHNAME",
"hltpath")
266 hltprescQuery.addToOutputList (
"PRESCALE",
"hltprescale")
267 hltprescCondition = coral.AttributeList()
268 hltprescCondition.extend (
'runnumber',
'unsigned int')
269 hltprescCondition.extend (
'cmslsnum',
'unsigned int')
270 hltprescCondition.extend (
'inf',
'unsigned int')
271 hltprescResult = coral.AttributeList()
272 hltprescResult.extend (
'hltpath',
'string')
273 hltprescResult.extend (
'hltprescale',
'unsigned int')
274 hltprescQuery.defineOutput (hltprescResult)
275 hltprescCondition[
'runnumber'].setData (int (runnum))
276 hltprescCondition[
'cmslsnum'].setData (1)
277 hltprescCondition[
'inf'].setData (0)
278 hltprescQuery.setCondition (
"RUNNUM = :runnumber and CMSLSNUM = :cmslsnum and PRESCALE != :inf",hltprescCondition)
279 cursor = hltprescQuery.execute()
281 hltpath = cursor.currentRow()[
'hltpath'].
data()
282 hltprescale = cursor.currentRow()[
'hltprescale'].
data()
283 if hltpath
in lumidata[1]:
284 lumidata[1][hltpath].append (hltprescale)
288 dbsession.transaction().commit()
289 dbsession.transaction().start (
True)
290 schema = dbsession.nominalSchema()
291 query = schema.newQuery()
294 queryCondition = coral.AttributeList()
295 queryCondition.extend (
"runnumber",
"unsigned int")
296 queryCondition.extend (
"lumiversion",
"string")
297 queryCondition[
"runnumber"].setData (int (runnum))
298 queryCondition[
"lumiversion"].setData (parameters.lumiversion)
299 conditionstring=
'lumisummary.RUNNUM =:runnumber and lumisummary.LUMIVERSION =:lumiversion AND lumisummary.CMSLSNUM=trg.CMSLSNUM and lumisummary.RUNNUM=trg.RUNNUM' 300 if len(parameters.beammode)!=0:
301 conditionstring=conditionstring+
' and lumisummary.BEAMSTATUS=:beamstatus' 302 queryCondition.extend(
'beamstatus',
'string')
303 queryCondition[
'beamstatus'].setData(parameters.beammode)
304 query.setCondition(conditionstring,queryCondition)
305 query.addToOutputList (
"lumisummary.CMSLSNUM",
"cmsls")
306 query.addToOutputList (
"lumisummary.INSTLUMI",
"instlumi")
307 query.addToOutputList (
"lumisummary.NUMORBIT",
"norbits")
308 query.addToOutputList (
"trg.TRGCOUNT",
"trgcount")
309 query.addToOutputList (
"trg.BITNAME",
"bitname")
310 query.addToOutputList (
"trg.DEADTIME",
"trgdeadtime")
311 query.addToOutputList (
"trg.PRESCALE",
"trgprescale")
312 query.addToOutputList (
"trg.BITNUM",
"trgbitnum")
314 result = coral.AttributeList()
315 result.extend (
"cmsls",
"unsigned int")
316 result.extend (
"instlumi",
"float")
317 result.extend (
"norbits",
"unsigned int")
318 result.extend (
"trgcount",
"unsigned int")
319 result.extend (
"bitname",
"string")
320 result.extend (
"trgdeadtime",
"unsigned long long")
321 result.extend (
"trgprescale",
"unsigned int")
322 result.extend (
"trgbitnum",
"unsigned int")
324 query.defineOutput (result)
325 cursor = query.execute()
327 cmsls = cursor.currentRow()[
"cmsls"].
data()
328 instlumi = cursor.currentRow()[
"instlumi"].
data()*parameters.norm
330 instlumi=lumiCorrections.applyfinecorrection(instlumi,finecorrections[0],finecorrections[1],finecorrections[2])
331 norbits = cursor.currentRow()[
"norbits"].
data()
332 trgcount = cursor.currentRow()[
"trgcount"].
data()
333 trgbitname = cursor.currentRow()[
"bitname"].
data()
334 trgdeadtime = cursor.currentRow()[
"trgdeadtime"].
data()
335 trgprescale = cursor.currentRow()[
"trgprescale"].
data()
336 trgbitnum = cursor.currentRow()[
"trgbitnum"].
data()
338 if trgbitname
not in trgprescalemap:
339 trgprescalemap[trgbitname] = trgprescale
341 if cmsls
not in deadtable:
342 deadtable[cmsls] = []
343 deadtable[cmsls].append (trgdeadtime)
344 deadtable[cmsls].append (instlumi)
345 deadtable[cmsls].append (trgcount)
346 deadtable[cmsls].append (norbits)
347 deadtable[cmsls].append (trgprescale)
350 dbsession.transaction().commit()
358 for hpath, trgdataseq
in lumidata[1].
items():
360 if bitn
in trgprescalemap
and len (trgdataseq) == 2:
361 lumidata[1][hpath].append (trgprescalemap[bitn])
363 lumidata[2] = filterDeadtable (deadtable, lslist)
364 if not parameters.noWarnings:
365 if len(lumidata[2])!=0:
366 for lumi, deaddata
in lumidata[2].
items():
367 if deaddata[1] == 0.0
and deaddata[2]!=0
and deaddata[0]!=0:
368 print '[Warning] : run %s :ls %d has 0 instlumi but trigger has data' % (runnum, lumi)
369 if (deaddata[2] == 0
or deaddata[0] == 0)
and deaddata[1]!=0.0:
370 print '[Warning] : run %s :ls %d has 0 dead counts or 0 zerobias bit counts, but inst!=0' % (runnum, lumi)
372 except Exception
as e:
374 dbsession.transaction().rollback()
387 if len (lslist) == 0:
389 for existingLS
in inTable.keys():
390 if existingLS
in lslist:
391 result[existingLS] = inTable[existingLS]
396 labels = [ (
'Run',
'Delivered LS',
'Delivered'+
u' (/\u03bcb)'.encode (
'utf-8'),
'Beam Mode')]
397 print tablePrinter.indent (labels+lumidata, hasHeader =
True, separateRows =
False,
398 prefix =
'| ', postfix =
' |', justify =
'right',
399 delim =
' | ', wrapfunc =
lambda x: wrap_onspace (x, 20) )
403 input params: lumidata [{'fieldname':value}] 408 r.writeRows(lumidata)
412 input: {lsnum:[deadtime, instlumi, bit_0, norbits,prescale]} 416 for myls, d
in deadtable.items():
420 if float (d[2]) == 0.0:
423 deadfrac = float (d[0])/(float (d[2])*float (d[-1]))
424 lstime = lslengthsec (d[3], 3564)
425 recordedLumi += instLumi* (1.0-deadfrac)*lstime
433 result.append ([inPut[0]])
437 result[counter].append (i)
442 return ', '.join ([
'['+str (min (x))+
'-'+str (max (x))+
']' for x
in result])
447 input: trgtable{hltpath:[l1seed, hltprescale, l1prescale]}, totalrecorded (float) 448 output:{hltpath, recorded} 452 for hltpath, data
in trgtable.items():
454 result[hltpath] = totalrecorded/ (data[1]*data[2])
456 result[hltpath] = 0.0
462 inputtable: {lsnum:[deadtime, instlumi, bit_0, norbits,bit_0_prescale]} 463 output: {lsnum:deadfraction} 466 for myls, d
in deadtable.items():
468 if float (d[2]) == 0.0:
471 deadfrac = float (d[0])/ (float (d[2])*
float(d[-1]))
472 result[myls] = deadfrac
477 input lumidata [['runnumber', 'trgtable{}', 'deadtable{}']] 478 deadtable {lsnum:[deadtime, instlumi, bit_0, norbits,prescale]} 482 labels = [ (
'Run',
'LS',
'Delivered',
'Recorded'+
u' (/\u03bcb)'.encode (
'utf-8'))]
483 lastrowlabels = [ (
'Selected LS',
'Delivered'+
u' (/\u03bcb)'.encode (
'utf-8'),
'Recorded'+
u' (/\u03bcb)'.encode (
'utf-8'))]
489 for perrundata
in lumidata:
490 runnumber = perrundata[0]
491 deadtable = perrundata[2]
492 lumiresult = lsBylsLumi (deadtable)
493 totalSelectedLS = totalSelectedLS+len (deadtable)
494 for lsnum, dataperls
in lumiresult.items():
496 if len (dataperls) == 0:
497 rowdata += [str (runnumber), str (lsnum),
'N/A',
'N/A']
499 rowdata += [str (runnumber), str (lsnum),
'%.3f' % (dataperls[0]),
'%.3f' % (dataperls[1])]
500 totalDelivered = totalDelivered+dataperls[0]
501 totalRecorded = totalRecorded+dataperls[1]
502 datatoprint.append (rowdata)
503 totalrow.append ([str (totalSelectedLS),
'%.3f'% (totalDelivered),
'%.3f'% (totalRecorded)])
505 print tablePrinter.indent (labels+datatoprint, hasHeader =
True, separateRows =
False, prefix =
'| ',
506 postfix =
' |', justify =
'right', delim =
' | ',
507 wrapfunc =
lambda x: wrap_onspace_strict (x, 22))
508 print ' == = Total : ' 509 print tablePrinter.indent (lastrowlabels+totalrow, hasHeader =
True, separateRows =
False, prefix =
'| ',
510 postfix =
' |', justify =
'right', delim =
' | ',
511 wrapfunc =
lambda x: wrap_onspace (x, 20))
516 for perrundata
in lumidata:
517 runnumber = perrundata[0]
518 deadtable = perrundata[2]
519 lumiresult = lsBylsLumi (deadtable)
520 for lsnum, dataperls
in lumiresult.items():
522 if len (dataperls) == 0:
523 rowdata += [str (runnumber), str (lsnum),
'N/A',
'N/A']
525 rowdata += [str (runnumber), str (lsnum), dataperls[0], dataperls[1]]
526 if len (dataperls) > 2:
527 rowdata.extend ( flatten (dataperls[2:]) )
528 datatodump.append (rowdata)
535 labels = [ (
'Run',
'HLT path',
'Recorded'+
u' (/\u03bcb)'.encode (
'utf-8'))]
536 lastrowlabels = [ (
'Selected LS',
'Recorded'+
u' (/\u03bcb)'.encode (
'utf-8'))]
537 if len (hltpath) != 0
and hltpath !=
'all':
538 lastrowlabels = [ (
'Selected LS',
'Recorded'+
u' (/\u03bcb)'.encode (
'utf-8'),
539 'Effective '+
u' (/\u03bcb) '.encode (
'utf-8')+hltpath)]
541 labels = [ (
'Run',
'HLT-path',
'L1-bit',
'L1-presc',
'HLT-presc',
'Recorded'+
u' (/\u03bcb)'.encode (
'utf-8'))]
544 totalRecordedInPath = 0.0
546 for dataperRun
in lumidata:
547 runnum = dataperRun[0]
548 if len (dataperRun[1]) == 0:
550 rowdata += [str (runnum)]+2*[
'N/A']
551 datatoprint.append (rowdata)
553 perlsdata = dataperRun[2]
554 totalSelectedLS = totalSelectedLS+len (perlsdata)
557 recordedLumi = calculateTotalRecorded (perlsdata)
558 totalRecorded = totalRecorded+recordedLumi
559 trgdict = dataperRun[1]
560 effective = calculateEffective (trgdict, recordedLumi)
561 if hltpath
in trgdict
and hltpath
in effective:
563 l1bit = trgdict[hltpath][0]
564 if len (trgdict[hltpath]) != 3:
566 rowdata += [str (runnum), hltpath,
'N/A']
568 rowdata += [str (runnum), hltpath, l1bit,
'N/A',
'N/A',
'N/A']
571 rowdata += [str (runnum), hltpath,
'%.3f'% (effective[hltpath])]
573 hltprescale = trgdict[hltpath][1]
574 l1prescale = trgdict[hltpath][2]
575 rowdata += [str (runnum), hltpath, l1bit, str (l1prescale), str (hltprescale),
576 '%.3f'% (effective[hltpath])]
577 totalRecordedInPath = totalRecordedInPath+effective[hltpath]
578 datatoprint.append (rowdata)
581 for trg, trgdata
in trgdict.items():
584 if trg == trgdict.keys()[0]:
585 rowdata += [str (runnum)]
589 if len (trgdata) == 3:
591 rowdata += [trg,
'%.3f'% (effective[trg])]
593 hltprescale = trgdata[1]
594 l1prescale = trgdata[2]
595 rowdata += [trg, l1bit, str (l1prescale), str (hltprescale),
'%.3f'% (effective[trg])]
598 rowdata += [trg,
'N/A']
600 rowdata += [trg, l1bit,
'N/A',
'N/A',
'%.3f'% (effective[trg])]
601 datatoprint.append (rowdata)
604 print tablePrinter.indent (labels+datatoprint, hasHeader =
True, separateRows =
False, prefix =
'| ',
605 postfix =
' |', justify =
'right', delim =
' | ',
606 wrapfunc =
lambda x: wrap_onspace_strict (x, 22))
608 if len (hltpath) != 0
and hltpath !=
'all':
609 totalrow.append ([str (totalSelectedLS),
'%.3f'% (totalRecorded),
'%.3f'% (totalRecordedInPath)])
611 totalrow.append ([str (totalSelectedLS),
'%.3f'% (totalRecorded)])
612 print ' == = Total : ' 613 print tablePrinter.indent (lastrowlabels+totalrow, hasHeader =
True, separateRows =
False, prefix =
'| ',
614 postfix =
' |', justify =
'right', delim =
' | ',
615 wrapfunc =
lambda x: wrap_onspace (x, 20))
618 deadtimelabels = [ (
'Run',
'Lumi section : Dead fraction')]
620 for dataperRun
in lumidata:
621 runnum = dataperRun[0]
622 if len (dataperRun[1]) == 0:
623 deadtoprint.append ([str (runnum),
'N/A'])
625 perlsdata = dataperRun[2]
627 deadT = getDeadfractions (perlsdata)
629 for myls, de
in deadT.items():
631 t += str (myls)+
':nobeam ' 633 t += str (myls)+
':'+
'%.5f'% (de)+
' ' 634 deadtoprint.append ([str (runnum), t])
636 print tablePrinter.indent (deadtimelabels+deadtoprint, hasHeader =
True, separateRows =
True, prefix =
'| ',
637 postfix =
' |', justify =
'right', delim =
' | ',
638 wrapfunc =
lambda x: wrap_onspace (x, 80))
644 for dataperRun
in lumidata:
645 runnum = dataperRun[0]
646 if len (dataperRun[1]) == 0:
648 rowdata += [str (runnum)]+2*[
'N/A']
649 datatodump.append (rowdata)
651 perlsdata = dataperRun[2]
654 recordedLumi = calculateTotalRecorded (perlsdata)
655 trgdict = dataperRun[1]
656 effective = calculateEffective (trgdict, recordedLumi)
657 if hltpath
in trgdict
and hltpath
in effective:
659 l1bit = trgdict[hltpath][0]
660 if len (trgdict[hltpath]) != 3:
661 rowdata += [str (runnum), hltpath,
'N/A']
663 hltprescale = trgdict[hltpath][1]
664 l1prescale = trgdict[hltpath][2]
665 rowdata += [str (runnum), hltpath, effective[hltpath]]
666 datatodump.append (rowdata)
669 for trg, trgdata
in trgdict.items():
672 rowdata += [str (runnum)]
674 if len (trgdata) == 3:
675 rowdata += [trg, effective[trg]]
677 rowdata += [trg,
'N/A']
678 datatodump.append (rowdata)
683 if len (hltpath) == 0
or hltpath ==
'all':
684 toprowlabels = [ (
'Run',
'Delivered LS',
'Delivered'+
u' (/\u03bcb)'.encode (
'utf-8'),
'Selected LS',
'Recorded'+
u' (/\u03bcb)'.encode (
'utf-8') )]
685 lastrowlabels = [ (
'Delivered LS',
'Delivered'+
u' (/\u03bcb)'.encode (
'utf-8'),
'Selected LS',
'Recorded'+
u' (/\u03bcb)'.encode (
'utf-8') ) ]
687 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 )]
688 lastrowlabels = [ (
'Delivered LS',
'Delivered'+
u' (/\u03bcb)'.encode (
'utf-8'),
'Selected LS',
'Recorded'+
u' (/\u03bcb)'.encode (
'utf-8'),
'Effective '+
u' (/\u03bcb) '.encode (
'utf-8')+hltpath)]
695 totalRecordedInPath = 0.0
697 for runidx, deliveredrowdata
in enumerate (delivered):
699 rowdata += [deliveredrowdata[0], deliveredrowdata[1], deliveredrowdata[2]]
700 if deliveredrowdata[1] ==
'N/A':
701 if hltpath !=
'' and hltpath !=
'all':
702 rowdata += [
'N/A',
'N/A',
'N/A']
704 rowdata += [
'N/A',
'N/A']
705 datatable.append (rowdata)
707 totalDeliveredLS += int (deliveredrowdata[1])
708 totalDelivered += float (deliveredrowdata[2])
709 selectedls = recorded[runidx][2].
keys()
712 if len (selectedls) == 0:
715 if hltpath !=
'' and hltpath !=
'all':
716 rowdata += [selectedlsStr,
'N/A',
'N/A']
718 rowdata += [selectedlsStr,
'N/A']
720 selectedlsStr = splitlistToRangeString (selectedls)
721 recordedLumi = calculateTotalRecorded (recorded[runidx][2])
722 lumiinPaths = calculateEffective (recorded[runidx][1], recordedLumi)
723 if hltpath !=
'' and hltpath !=
'all':
724 if hltpath
in lumiinPaths:
725 rowdata += [selectedlsStr,
'%.3f'% (recordedLumi),
'%.3f'% (lumiinPaths[hltpath])]
726 totalRecordedInPath += lumiinPaths[hltpath]
728 rowdata += [selectedlsStr,
'%.3f'% (recordedLumi),
'N/A']
731 rowdata += [selectedlsStr,
'%.3f'% (recordedLumi)]
732 totalSelectedLS += len (selectedls)
733 totalRecorded += recordedLumi
734 datatable.append (rowdata)
736 if hltpath !=
'' and hltpath !=
'all':
737 totaltable = [[str (totalDeliveredLS),
'%.3f'% (totalDelivered), str (totalSelectedLS),
738 '%.3f'% (totalRecorded),
'%.3f'% (totalRecordedInPath)]]
740 totaltable = [[str (totalDeliveredLS),
'%.3f'% (totalDelivered), str (totalSelectedLS),
741 '%.3f'% (totalRecorded)]]
742 print tablePrinter.indent (toprowlabels+datatable, hasHeader =
True, separateRows =
False, prefix =
'| ',
743 postfix =
' |', justify =
'right', delim =
' | ',
744 wrapfunc =
lambda x: wrap_onspace (x, 20))
745 print ' == = Total : ' 746 print tablePrinter.indent (lastrowlabels+totaltable, hasHeader =
True, separateRows =
False, prefix =
'| ',
747 postfix =
' |', justify =
'right', delim =
' | ',
748 wrapfunc =
lambda x: wrap_onspace (x, 20))
754 for runidx, deliveredrowdata
in enumerate (delivered):
756 rowdata += [deliveredrowdata[0], deliveredrowdata[2]]
757 if deliveredrowdata[1] ==
'N/A':
758 rowdata += [
'N/A',
'N/A']
759 datatable.append (rowdata)
761 recordedLumi = calculateTotalRecorded (recorded[runidx][2])
762 lumiinPaths = calculateEffective (recorded[runidx][1], recordedLumi)
763 if hltpath !=
'' and hltpath !=
'all':
764 if hltpath
in lumiinPaths:
765 rowdata += [recordedLumi, lumiinPaths[hltpath]]
767 rowdata += [recordedLumi,
'N/A']
769 rowdata += [recordedLumi, recordedLumi]
770 datatable.append (rowdata)
775 maxLumiSection =
None, finecorrections=
None):
776 '''Given a run number and a minimum xing luminosity value, 777 returns a dictionary (keyed by (run, lumi section)) where the 778 value is a list of tuples of (xingID, xingLum). 780 - For all xing luminosities, simply set minLumValue to 0. 782 - If you want one dictionary for several runs, pass it in to 786 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 789 runnum = int (runnum)
790 dbsession.transaction().start (
True)
791 schema = dbsession.schema (parameters.lumischema)
793 raise 'cannot connect to schema ', parameters.lumischema
794 detailOutput = coral.AttributeList()
795 detailOutput.extend (
'startorbit',
'unsigned int')
796 detailOutput.extend (
'cmslsnum',
'unsigned int')
797 detailOutput.extend (
'bxlumivalue',
'blob')
798 detailOutput.extend (
'bxlumierror',
'blob')
799 detailOutput.extend (
'bxlumiquality',
'blob')
800 detailOutput.extend (
'algoname',
'string')
801 detailCondition = coral.AttributeList()
802 detailCondition.extend (
'runnum',
'unsigned int')
803 detailCondition.extend (
'algoname',
'string')
804 detailCondition[
'runnum'].setData (runnum)
805 detailCondition[
'algoname'].setData (
'OCC1')
806 query = schema.newQuery()
809 query.addToOutputList (
's.STARTORBIT',
'startorbit')
810 query.addToOutputList (
's.CMSLSNUM',
'cmslsnum')
811 query.addToOutputList (
'd.BXLUMIVALUE',
'bxlumivalue')
812 query.addToOutputList (
'd.BXLUMIERROR',
'bxlumierror')
813 query.addToOutputList (
'd.BXLUMIQUALITY',
'bxlumiquality')
814 query.addToOutputList (
'd.ALGONAME',
'algoname')
815 query.setCondition (
's.RUNNUM =:runnum and d.ALGONAME =:algoname and s.LUMISUMMARY_ID=d.LUMISUMMARY_ID',detailCondition)
816 query.addToOrderList (
's.CMSLSNUM')
817 query.defineOutput (detailOutput)
818 cursor = query.execute()
828 cmslsnum = cursor.currentRow()[
'cmslsnum'].
data()
829 algoname = cursor.currentRow()[
'algoname'].
data()
830 bxlumivalue = cursor.currentRow()[
'bxlumivalue'].
data()
831 startorbit = cursor.currentRow()[
'startorbit'].
data()
833 if maxLumiSection
and maxLumiSection < cmslsnum:
837 xingArray = array.array (
'f')
838 xingArray.fromstring( bxlumivalue.readline() )
842 if len(xingArray)!=0:
843 avginstlumi=sum(xingArray)
844 for index, lum
in enumerate (xingArray):
845 mynorm=parameters.normFactor
847 lum=lumiCorrections.applyfinecorrectionBX(lum,avginstlumi*mynorm,mynorm,finecorrections[0],finecorrections[1],finecorrections[2])
850 if lum < parameters.xingMinLum:
852 xingLum.append( (index, lum) )
853 lumiXingDict[ (runnum, cmslsnum) ] = xingLum
855 dbsession.transaction().commit()
857 except Exception
as e:
860 dbsession.transaction().rollback()
865 '''Given nested lists or tuples, returns a single flattened list''' 868 if hasattr (piece,
'__iter__')
and not isinstance (piece, basestring):
869 result.extend( flatten (piece) )
871 result.append (piece)
876 '''Given general xing information and a xingLumiDict, the xing 877 luminosity information is merged with the general information''' 878 runNumber = triplet[0]
879 deadTable = triplet[2]
880 for lumi, lumiList
in deadTable.iteritems():
881 key = (
int(runNumber),
int(lumi) )
882 xingLumiValues = xingLumiDict.get (key)
884 lumiList.append( flatten (xingLumiValues) )
887 def setupSession (connectString, siteconfpath, parameters, debug = False):
888 '''returns database session''' 890 connectparser.parse()
891 usedefaultfrontierconfig =
False 893 if connectparser.needsitelocalinfo():
895 cacheconfigpath = os.environ[
'CMS_PATH']
897 cacheconfigpath = os.path.join (cacheconfigpath,
'SITECONF',
'local',
'JobConfig',
'site-local-config.xml')
899 usedefaultfrontierconfig =
True 901 cacheconfigpath = siteconfpath
902 cacheconfigpath = os.path.join (cacheconfigpath,
'site-local-config.xml')
904 if usedefaultfrontierconfig:
905 ccp.parseString (parameters.defaultfrontierConfigString)
907 ccp.parse (cacheconfigpath)
908 connectString = connectparser.fullfrontierStr (connectparser.schemaname(), ccp.parameterdict())
909 svc = coral.ConnectionService()
911 msg = coral.MessageStream (
'')
912 msg.setMsgVerbosity (coral.message_Level_Debug)
913 parameters.verbose =
True 914 session = svc.connect (connectString, accessMode = coral.access_ReadOnly)
915 session.typeConverter().setCppTypeForSqlType (
"unsigned int",
"NUMBER (10)")
916 session.typeConverter().setCppTypeForSqlType (
"unsigned long long",
"NUMBER (20)")
923 def allruns(schemaHandle,requireRunsummary=True,requireLumisummary=False,requireTrg=False,requireHlt=False):
925 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. 927 if not requireRunsummary
and not requireLumiummary
and not requireTrg
and not requireHlt:
928 print 'must require at least one table' 933 if requireRunsummary:
935 queryHandle=schemaHandle.newQuery()
937 queryHandle.addToOutputList(
"RUNNUM",
"run")
939 result=coral.AttributeList()
940 result.extend(
"run",
"unsigned int")
941 queryHandle.defineOutput(result)
942 cursor=queryHandle.execute()
944 r=cursor.currentRow()[
'run'].
data()
947 if requireLumisummary:
949 queryHandle=schemaHandle.newQuery()
951 queryHandle.addToOutputList(
"distinct RUNNUM",
"run")
953 result=coral.AttributeList()
954 result.extend(
"run",
"unsigned int")
955 queryHandle.defineOutput(result)
956 cursor=queryHandle.execute()
958 r=cursor.currentRow()[
'run'].
data()
963 queryHandle=schemaHandle.newQuery()
965 queryHandle.addToOutputList(
"distinct RUNNUM",
"run")
967 result=coral.AttributeList()
968 result.extend(
"run",
"unsigned int")
969 queryHandle.defineOutput(result)
970 cursor=queryHandle.execute()
972 r=cursor.currentRow()[
'run'].
data()
977 queryHandle=schemaHandle.newQuery()
979 queryHandle.addToOutputList(
"distinct RUNNUM",
"run")
981 result=coral.AttributeList()
982 result.extend(
"run",
"unsigned int")
983 queryHandle.defineOutput(result)
984 cursor=queryHandle.execute()
986 r=cursor.currentRow()[
'run'].
data()
990 for dup
in dupresult:
992 runresult.append(dup[0])
997 '''retrieve validation data per run or all 998 input: run. if not run, retrive all; if cmslsnum selection list pesent, filter out unselected result 999 output: {run:[[cmslsnum,status,comment]]} 1003 queryHandle.addToOutputList(
'RUNNUM',
'runnum')
1004 queryHandle.addToOutputList(
'CMSLSNUM',
'cmslsnum')
1005 queryHandle.addToOutputList(
'FLAG',
'flag')
1006 queryHandle.addToOutputList(
'COMMENT',
'comment')
1008 queryCondition=
'RUNNUM=:runnum' 1009 queryBind=coral.AttributeList()
1010 queryBind.extend(
'runnum',
'unsigned int')
1011 queryBind[
'runnum'].setData(run)
1012 queryHandle.setCondition(queryCondition,queryBind)
1013 queryResult=coral.AttributeList()
1014 queryResult.extend(
'runnum',
'unsigned int')
1015 queryResult.extend(
'cmslsnum',
'unsigned int')
1016 queryResult.extend(
'flag',
'string')
1017 queryResult.extend(
'comment',
'string')
1018 queryHandle.defineOutput(queryResult)
1019 cursor=queryHandle.execute()
1021 runnum=cursor.currentRow()[
'runnum'].
data()
1022 if runnum
not in result:
1024 cmslsnum=cursor.currentRow()[
'cmslsnum'].
data()
1025 flag=cursor.currentRow()[
'flag'].
data()
1026 comment=cursor.currentRow()[
'comment'].
data()
1027 result[runnum].
append([cmslsnum,flag,comment])
1028 if run
and cmsls
and len(cmsls)!=0:
1030 for runnum,perrundata
in result.items():
1031 for lsdata
in perrundata:
1032 if lsdata[0]
not in cmsls:
1034 if runnum
not in selectedresult:
1035 selectedresult[runnum]=[]
1036 selectedresult[runnum].
append(lsdata)
1037 return selectedresult
1042 '''select distinct fillnum from cmsrunsummary 1043 there are crazy fill numbers. we assume they are not valid runs 1047 queryHandle.addToOutputList(
'distinct FILLNUM',
'fillnum')
1050 queryCondition=
'FILLNUM>:zero and FILLNUM<:crazybig' 1051 queryBind=coral.AttributeList()
1052 queryBind.extend(
'zero',
'unsigned int')
1053 queryBind.extend(
'crazybig',
'unsigned int')
1054 queryBind[
'zero'].setData(
int(0))
1055 queryBind[
'crazybig'].setData(
int(29701))
1056 queryHandle.setCondition(queryCondition,queryBind)
1057 queryResult=coral.AttributeList()
1058 queryResult.extend(
'fillnum',
'unsigned int')
1059 queryHandle.defineOutput(queryResult)
1060 cursor=queryHandle.execute()
1062 result.append(cursor.currentRow()[
'fillnum'].
data())
1067 select fillnum,sequence,hltkey,to_char(starttime),to_char(stoptime) from cmsrunsummary where runnum=:runnum 1068 output: [fillnum,sequence,hltkey,starttime,stoptime] 1073 queryCondition=coral.AttributeList()
1074 queryCondition.extend(
'runnum',
'unsigned int')
1075 queryCondition[
'runnum'].setData(
int(runnum))
1076 queryHandle.addToOutputList(
'FILLNUM',
'fillnum')
1077 queryHandle.addToOutputList(
'SEQUENCE',
'sequence')
1078 queryHandle.addToOutputList(
'HLTKEY',
'hltkey')
1079 queryHandle.addToOutputList(
'to_char(STARTTIME,\''+t.coraltimefm+
'\')',
'starttime')
1080 queryHandle.addToOutputList(
'to_char(STOPTIME,\''+t.coraltimefm+
'\')',
'stoptime')
1081 queryHandle.setCondition(
'RUNNUM=:runnum',queryCondition)
1082 queryResult=coral.AttributeList()
1083 queryResult.extend(
'fillnum',
'unsigned int')
1084 queryResult.extend(
'sequence',
'string')
1085 queryResult.extend(
'hltkey',
'string')
1086 queryResult.extend(
'starttime',
'string')
1087 queryResult.extend(
'stoptime',
'string')
1088 queryHandle.defineOutput(queryResult)
1089 cursor=queryHandle.execute()
1091 result.append(cursor.currentRow()[
'fillnum'].
data())
1092 result.append(cursor.currentRow()[
'sequence'].
data())
1093 result.append(cursor.currentRow()[
'hltkey'].
data())
1094 result.append(cursor.currentRow()[
'starttime'].
data())
1095 result.append(cursor.currentRow()[
'stoptime'].
data())
1101 def lumisummaryByrun(queryHandle,runnum,lumiversion,beamstatus=None,beamenergy=None,beamenergyfluctuation=0.09,finecorrections=None):
1103 one can impose beamstatus, beamenergy selections at the SQL query level or process them later from the general result 1104 select cmslsnum,instlumi,numorbit,startorbit,beamstatus,beamenery from lumisummary where runnum=:runnum and lumiversion=:lumiversion order by startorbit; 1105 output: [[cmslsnum,instlumi,numorbit,startorbit,beamstatus,beamenergy,cmsalive]] 1106 Note: the non-cmsalive LS are included in the result 1110 queryCondition=coral.AttributeList()
1111 queryCondition.extend(
'runnum',
'unsigned int')
1112 queryCondition.extend(
'lumiversion',
'string')
1113 conditionstring=
'RUNNUM=:runnum and LUMIVERSION=:lumiversion' 1114 queryCondition[
'runnum'].setData(
int(runnum))
1115 queryCondition[
'lumiversion'].setData(lumiversion)
1116 queryHandle.addToOutputList(
'CMSLSNUM',
'cmslsnum')
1117 queryHandle.addToOutputList(
'INSTLUMI',
'instlumi')
1118 queryHandle.addToOutputList(
'NUMORBIT',
'numorbit')
1119 queryHandle.addToOutputList(
'STARTORBIT',
'startorbit')
1120 queryHandle.addToOutputList(
'BEAMSTATUS',
'beamstatus')
1121 queryHandle.addToOutputList(
'BEAMENERGY',
'beamenergy')
1122 queryHandle.addToOutputList(
'CMSALIVE',
'cmsalive')
1123 if beamstatus
and len(beamstatus)!=0:
1124 conditionstring=conditionstring+
' and BEAMSTATUS=:beamstatus' 1125 queryCondition.extend(
'beamstatus',
'string')
1126 queryCondition[
'beamstatus'].setData(beamstatus)
1128 minBeamenergy=
float(beamenergy*(1.0-beamenergyfluctuation))
1129 maxBeamenergy=
float(beamenergy*(1.0+beamenergyfluctuation))
1130 conditionstring=conditionstring+
' and BEAMENERGY>:minBeamenergy and BEAMENERGY<:maxBeamenergy' 1131 queryCondition.extend(
'minBeamenergy',
'float')
1132 queryCondition.extend(
'maxBeamenergy',
'float')
1133 queryCondition[
'minBeamenergy'].setData(
float(minBeamenergy))
1134 queryCondition[
'maxBeamenergy'].setData(
float(maxBeamenergy))
1135 queryResult=coral.AttributeList()
1136 queryResult.extend(
'cmslsnum',
'unsigned int')
1137 queryResult.extend(
'instlumi',
'float')
1138 queryResult.extend(
'numorbit',
'unsigned int')
1139 queryResult.extend(
'startorbit',
'unsigned int')
1140 queryResult.extend(
'beamstatus',
'string')
1141 queryResult.extend(
'beamenergy',
'float')
1142 queryResult.extend(
'cmsalive',
'unsigned int')
1143 queryHandle.defineOutput(queryResult)
1144 queryHandle.setCondition(conditionstring,queryCondition)
1145 queryHandle.addToOrderList(
'startorbit')
1146 cursor=queryHandle.execute()
1148 cmslsnum=cursor.currentRow()[
'cmslsnum'].
data()
1149 instlumi=cursor.currentRow()[
'instlumi'].
data()
1151 instlumi=lumiCorrections.applyfinecorrection(instlumi,finecorrections[0],finecorrections[1],finecorrections[2])
1152 numorbit=cursor.currentRow()[
'numorbit'].
data()
1153 startorbit=cursor.currentRow()[
'startorbit'].
data()
1154 beamstatus=cursor.currentRow()[
'beamstatus'].
data()
1155 beamenergy=cursor.currentRow()[
'beamenergy'].
data()
1156 cmsalive=cursor.currentRow()[
'cmsalive'].
data()
1157 result.append([cmslsnum,instlumi,numorbit,startorbit,beamstatus,beamenergy,cmsalive])
1160 def lumisumByrun(queryHandle,runnum,lumiversion,beamstatus=None,beamenergy=None,beamenergyfluctuation=0.09,finecorrections=None):
1162 beamenergy unit : GeV 1163 beamenergyfluctuation : fraction allowed to fluctuate around beamenergy value 1164 select instlumi from lumisummary where runnum=:runnum and lumiversion=:lumiversion 1165 output: float sum(instlumi) 1166 Note: the output is the raw result, need to apply LS length in time(sec) 1170 queryCondition=coral.AttributeList()
1171 queryCondition.extend(
'runnum',
'unsigned int')
1172 queryCondition.extend(
'lumiversion',
'string')
1174 queryCondition[
'runnum'].setData(
int(runnum))
1175 queryCondition[
'lumiversion'].setData(lumiversion)
1176 queryHandle.addToOutputList(
'INSTLUMI',
'instlumi')
1177 conditionstring=
'RUNNUM=:runnum and LUMIVERSION=:lumiversion' 1178 if beamstatus
and len(beamstatus)!=0:
1179 conditionstring=conditionstring+
' and BEAMSTATUS=:beamstatus' 1180 queryCondition.extend(
'beamstatus',
'string')
1181 queryCondition[
'beamstatus'].setData(beamstatus)
1182 if beamenergy
and beamenergy!=0.0:
1183 minBeamenergy=
float(beamenergy*(1.0-beamenergyfluctuation))
1184 maxBeamenergy=
float(beamenergy*(1.0+beamenergyfluctuation))
1185 conditionstring=conditionstring+
' and BEAMENERGY>:minBeamenergy and BEAMENERGY<:maxBeamenergy' 1186 queryCondition.extend(
'minBeamenergy',
'float')
1187 queryCondition.extend(
'maxBeamenergy',
'float')
1188 queryCondition[
'minBeamenergy'].setData(
float(minBeamenergy))
1189 queryCondition[
'maxBeamenergy'].setData(
float(maxBeamenergy))
1190 queryHandle.setCondition(conditionstring,queryCondition)
1191 queryResult=coral.AttributeList()
1192 queryResult.extend(
'instlumi',
'float')
1193 queryHandle.defineOutput(queryResult)
1194 cursor=queryHandle.execute()
1196 instlumi=cursor.currentRow()[
'instlumi'].
data()
1199 instlumi=lumiCorrections.applyfinecorrection(instlumi,finecorrections[0],finecorrections[1],finecorrections[2])
1200 result.append(instlumi)
1208 select cmslsnum,trgcount,deadtime,bitname,prescale from trg where runnum=:runnum and bitnum=0; 1209 output: {cmslsnum:[trgcount,deadtime,bitname,prescale]} 1213 queryCondition=coral.AttributeList()
1214 queryCondition.extend(
'runnum',
'unsigned int')
1215 queryCondition.extend(
'bitnum',
'unsigned int')
1216 queryCondition[
'runnum'].setData(
int(runnum))
1217 queryCondition[
'bitnum'].setData(
int(0))
1218 queryHandle.addToOutputList(
'CMSLSNUM',
'cmslsnum')
1219 queryHandle.addToOutputList(
'TRGCOUNT',
'trgcount')
1220 queryHandle.addToOutputList(
'DEADTIME',
'deadtime')
1221 queryHandle.addToOutputList(
'BITNAME',
'bitname')
1222 queryHandle.addToOutputList(
'PRESCALE',
'prescale')
1223 queryHandle.setCondition(
'RUNNUM=:runnum and BITNUM=:bitnum',queryCondition)
1224 queryResult=coral.AttributeList()
1225 queryResult.extend(
'cmslsnum',
'unsigned int')
1226 queryResult.extend(
'trgcount',
'unsigned int')
1227 queryResult.extend(
'deadtime',
'unsigned int')
1228 queryResult.extend(
'bitname',
'string')
1229 queryResult.extend(
'prescale',
'unsigned int')
1230 queryHandle.defineOutput(queryResult)
1231 cursor=queryHandle.execute()
1233 cmslsnum=cursor.currentRow()[
'cmslsnum'].
data()
1234 trgcount=cursor.currentRow()[
'trgcount'].
data()
1235 deadtime=cursor.currentRow()[
'deadtime'].
data()
1236 bitname=cursor.currentRow()[
'bitname'].
data()
1237 prescale=cursor.currentRow()[
'prescale'].
data()
1238 if cmslsnum
not in result:
1239 result[cmslsnum]=[trgcount,deadtime,bitname,prescale]
1244 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; 1245 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. 1246 output: {cmslsnum:[instlumi,numorbit,startorbit,beamstatus,beamenergy,bitzerocount,deadtime,bitname,prescale]} 1247 Note: only cmsalive LS are included in the result. Therefore, this function cannot be used for calculating delivered! 1252 queryCondition=coral.AttributeList()
1253 queryCondition.extend(
'bitnum',
'unsigned int')
1254 queryCondition.extend(
'runnum',
'unsigned int')
1255 queryCondition.extend(
'lumiversion',
'string')
1256 queryCondition[
'bitnum'].setData(
int(0))
1257 queryCondition[
'runnum'].setData(
int(runnum))
1258 queryCondition[
'lumiversion'].setData(lumiversion)
1260 queryHandle.addToOutputList(
'l.CMSLSNUM',
'cmslsnum')
1261 queryHandle.addToOutputList(
'l.INSTLUMI',
'instlumi')
1262 queryHandle.addToOutputList(
'l.NUMORBIT',
'numorbit')
1263 queryHandle.addToOutputList(
'l.STARTORBIT',
'startorbit')
1264 queryHandle.addToOutputList(
'l.BEAMSTATUS',
'beamstatus')
1265 queryHandle.addToOutputList(
'l.BEAMENERGY',
'beamenergy')
1266 queryHandle.addToOutputList(
't.TRGCOUNT',
'trgcount')
1267 queryHandle.addToOutputList(
't.DEADTIME',
'deadtime')
1268 queryHandle.addToOutputList(
't.BITNAME',
'bitname')
1269 queryHandle.addToOutputList(
't.PRESCALE',
'prescale')
1270 conditionstring=
't.BITNUM=:bitnum and l.RUNNUM=:runnum and l.LUMIVERSION=:lumiversion and l.RUNNUM=t.RUNNUM and t.CMSLSNUM=l.CMSLSNUM' 1271 if beamstatus
and len(beamstatus)!=0:
1272 conditionstring=conditionstring+
' and l.BEAMSTATUS=:beamstatus' 1273 queryCondition.extend(
'beamstatus',
'string')
1274 queryCondition[
'beamstatus'].setData(beamstatus)
1275 if beamenergy
and beamenergy!=0.0:
1276 minBeamenergy=
float(beamenergy*(1-beamenergyfluctuation))
1277 maxBeamenergy=
float(beamenergy*(1+beamenergyfluctuation))
1278 conditionstring=conditionstring+
' and l.BEAMENERGY>:minBeamenergy and l.BEAMENERGY<:maxBeamenergy' 1279 queryCondition.extend(
'minBeamenergy',
'float')
1280 queryCondition.extend(
'maxBeamenergy',
'float')
1281 queryCondition[
'minBeamenergy'].setData(
float(minBeamenergy))
1282 queryCondition[
'maxBeamenergy'].setData(
float(maxBeamenergy))
1283 queryHandle.setCondition(conditionstring,queryCondition)
1284 queryResult=coral.AttributeList()
1285 queryResult.extend(
'cmslsnum',
'unsigned int')
1286 queryResult.extend(
'instlumi',
'float')
1287 queryResult.extend(
'numorbit',
'unsigned int')
1288 queryResult.extend(
'startorbit',
'unsigned int')
1289 queryResult.extend(
'beamstatus',
'string')
1290 queryResult.extend(
'beamenergy',
'float')
1291 queryResult.extend(
'trgcount',
'unsigned int')
1292 queryResult.extend(
'deadtime',
'unsigned int')
1293 queryResult.extend(
'bitname',
'string')
1294 queryResult.extend(
'prescale',
'unsigned int')
1295 queryHandle.defineOutput(queryResult)
1296 cursor=queryHandle.execute()
1298 cmslsnum=cursor.currentRow()[
'cmslsnum'].
data()
1299 instlumi=cursor.currentRow()[
'instlumi'].
data()
1301 instlumi=lumiCorrections.applyfinecorrection(instlumi,finecorrections[0],finecorrections[1],finecorrections[2])
1302 numorbit=cursor.currentRow()[
'numorbit'].
data()
1303 startorbit=cursor.currentRow()[
'startorbit'].
data()
1304 beamstatus=cursor.currentRow()[
'beamstatus'].
data()
1305 beamenergy=cursor.currentRow()[
'beamenergy'].
data()
1306 trgcount=cursor.currentRow()[
'trgcount'].
data()
1307 deadtime=cursor.currentRow()[
'deadtime'].
data()
1308 bitname=cursor.currentRow()[
'bitname'].
data()
1309 prescale=cursor.currentRow()[
'prescale'].
data()
1310 if cmslsnum
not in result:
1311 result[cmslsnum]=[instlumi,numorbit,startorbit,beamstatus,beamenergy,trgcount,deadtime,bitname,prescale]
1316 select cmslsnum,trgcount,deadtime,bitnum,prescale from trg where runnum=:runnum and bitname=:bitname; 1317 output: {cmslsnum:[trgcount,deadtime,bitnum,prescale]} 1321 queryCondition=coral.AttributeList()
1322 queryCondition.extend(
'runnum',
'unsigned int')
1323 queryCondition.extend(
'bitname',
'string')
1324 queryCondition[
'runnum'].setData(
int(runnum))
1325 queryCondition[
'bitname'].setData(bitname)
1326 queryHandle.addToOutputList(
'CMSLSNUM',
'cmslsnum')
1327 queryHandle.addToOutputList(
'TRGCOUNT',
'trgcount')
1328 queryHandle.addToOutputList(
'DEADTIME',
'deadtime')
1329 queryHandle.addToOutputList(
'BITNUM',
'bitnum')
1330 queryHandle.addToOutputList(
'PRESCALE',
'prescale')
1331 queryHandle.setCondition(
'RUNNUM=:runnum and BITNAME=:bitname',queryCondition)
1332 queryResult=coral.AttributeList()
1333 queryResult.extend(
'cmslsnum',
'unsigned int')
1334 queryResult.extend(
'trgcount',
'unsigned int')
1335 queryResult.extend(
'deadtime',
'unsigned long long')
1336 queryResult.extend(
'bitnum',
'unsigned int')
1337 queryResult.extend(
'prescale',
'unsigned int')
1338 queryHandle.defineOutput(queryResult)
1339 cursor=queryHandle.execute()
1341 cmslsnum=cursor.currentRow()[
'cmslsnum'].
data()
1342 trgcount=cursor.currentRow()[
'trgcount'].
data()
1343 deadtime=cursor.currentRow()[
'deadtime'].
data()
1344 bitnum=cursor.currentRow()[
'bitnum'].
data()
1345 prescale=cursor.currentRow()[
'prescale'].
data()
1346 if cmslsnum
not in result:
1347 result[cmslsnum]=[trgcount,deadtime,bitnum,prescale]
1352 all you ever want to know about trigger 1353 select cmslsnum,trgcount,deadtime,bitnum,bitname,prescale from trg where runnum=:runnum order by bitnum,cmslsnum 1354 this can be changed to blob query later 1355 output: {cmslsnum:{bitname:[bitnum,trgcount,deadtime,prescale]}} 1359 queryCondition=coral.AttributeList()
1360 queryCondition.extend(
'runnum',
'unsigned int')
1361 queryCondition[
'runnum'].setData(
int(runnum))
1362 queryHandle.addToOutputList(
'cmslsnum')
1363 queryHandle.addToOutputList(
'trgcount')
1364 queryHandle.addToOutputList(
'deadtime')
1365 queryHandle.addToOutputList(
'bitnum')
1366 queryHandle.addToOutputList(
'bitname')
1367 queryHandle.addToOutputList(
'prescale')
1368 queryHandle.setCondition(
'runnum=:runnum',queryCondition)
1369 queryResult=coral.AttributeList()
1370 queryResult.extend(
'cmslsnum',
'unsigned int')
1371 queryResult.extend(
'trgcount',
'unsigned int')
1372 queryResult.extend(
'deadtime',
'unsigned long long')
1373 queryResult.extend(
'bitnum',
'unsigned int')
1374 queryResult.extend(
'bitname',
'string')
1375 queryResult.extend(
'prescale',
'unsigned int')
1376 queryHandle.defineOutput(queryResult)
1377 queryHandle.addToOrderList(
'bitnum')
1378 queryHandle.addToOrderList(
'cmslsnum')
1379 cursor=queryHandle.execute()
1381 cmslsnum=cursor.currentRow()[
'cmslsnum'].
data()
1382 trgcount=cursor.currentRow()[
'trgcount'].
data()
1383 deadtime=cursor.currentRow()[
'deadtime'].
data()
1384 bitnum=cursor.currentRow()[
'bitnum'].
data()
1385 bitname=cursor.currentRow()[
'bitname'].
data()
1386 prescale=cursor.currentRow()[
'prescale'].
data()
1387 if cmslsnum
not in result:
1389 dataperLS[bitname]=[bitnum,trgcount,deadtime,prescale]
1390 result[cmslsnum]=dataperLS
1392 result[cmslsnum][bitname]=[bitnum,trgcount,deadtime,prescale]
1398 select cmslsnum,inputcount,acceptcount,prescale from hlt where runnum=:runnum and pathname=:pathname 1399 output: {cmslsnum:[inputcount,acceptcount,prescale]} 1403 queryCondition=coral.AttributeList()
1404 queryCondition.extend(
'runnum',
'unsigned int')
1405 queryCondition.extend(
'pathname',
'string')
1406 queryCondition[
'runnum'].setData(
int(runnum))
1407 queryCondition[
'pathname'].setData(hltpath)
1408 queryHandle.addToOutputList(
'CMSLSNUM',
'cmslsnum')
1409 queryHandle.addToOutputList(
'INPUTCOUNT',
'inputcount')
1410 queryHandle.addToOutputList(
'ACCEPTCOUNT',
'acceptcount')
1411 queryHandle.addToOutputList(
'PRESCALE',
'prescale')
1412 queryHandle.setCondition(
'RUNNUM=:runnum and PATHNAME=:pathname',queryCondition)
1413 queryResult=coral.AttributeList()
1414 queryResult.extend(
'cmslsnum',
'unsigned int')
1415 queryResult.extend(
'inputcount',
'unsigned int')
1416 queryResult.extend(
'acceptcount',
'unsigned int')
1417 queryResult.extend(
'prescale',
'unsigned int')
1418 queryHandle.defineOutput(queryResult)
1419 cursor=queryHandle.execute()
1421 cmslsnum=cursor.currentRow()[
'cmslsnum'].
data()
1422 inputcount=cursor.currentRow()[
'inputcount'].
data()
1423 acceptcount=cursor.currentRow()[
'acceptcount'].
data()
1424 prescale=cursor.currentRow()[
'prescale'].
data()
1425 if cmslsnum
not in result:
1426 result[cmslsnum]=[inputcount,acceptcount,prescale]
1431 select cmslsnum,inputcount,acceptcount,prescale,pathname from hlt where runnum=:runnum 1432 this can be changed to blob query later 1433 output: {cmslsnum:{pathname:[inputcount,acceptcount,prescale]}} 1437 queryCondition=coral.AttributeList()
1438 queryCondition.extend(
'runnum',
'unsigned int')
1439 queryCondition[
'runnum'].setData(
int(runnum))
1440 queryHandle.addToOutputList(
'CMSLSNUM',
'cmslsnum')
1441 queryHandle.addToOutputList(
'INPUTCOUNT',
'inputcount')
1442 queryHandle.addToOutputList(
'ACCEPTCOUNT',
'acceptcount')
1443 queryHandle.addToOutputList(
'PRESCALE',
'prescale')
1444 queryHandle.addToOutputList(
'PATHNAME',
'pathname')
1445 queryHandle.setCondition(
'RUNNUM=:runnum',queryCondition)
1446 queryResult=coral.AttributeList()
1447 queryResult.extend(
'cmslsnum',
'unsigned int')
1448 queryResult.extend(
'inputcount',
'unsigned int')
1449 queryResult.extend(
'acceptcount',
'unsigned int')
1450 queryResult.extend(
'prescale',
'unsigned int')
1451 queryResult.extend(
'pathname',
'string')
1452 queryHandle.defineOutput(queryResult)
1453 cursor=queryHandle.execute()
1455 cmslsnum=cursor.currentRow()[
'cmslsnum'].
data()
1456 inputcount=cursor.currentRow()[
'inputcount'].
data()
1457 acceptcount=cursor.currentRow()[
'acceptcount'].
data()
1458 prescale=cursor.currentRow()[
'prescale'].
data()
1459 pathname=cursor.currentRow()[
'pathname'].
data()
1460 if cmslsnum
not in result:
1462 dataperLS[pathname]=[inputcount,acceptcount,prescale]
1463 result[cmslsnum]=dataperLS
1465 result[cmslsnum][pathname]=[inputcount,acceptcount,prescale]
1471 select CMSBXINDEXBLOB,BEAMINTENSITYBLOB_1,BEAMINTENSITYBLOB_2 from LUMISUMMARY where runnum=146315 and LUMIVERSION='0001' 1473 output : result {startorbit: [(bxidx,beam1intensity,beam2intensity)]} 1477 lumisummaryOutput=coral.AttributeList()
1478 lumisummaryOutput.extend(
'cmslsnum',
'unsigned int')
1479 lumisummaryOutput.extend(
'startorbit',
'unsigned int')
1480 lumisummaryOutput.extend(
'bxindexblob',
'blob');
1481 lumisummaryOutput.extend(
'beamintensityblob1',
'blob');
1482 lumisummaryOutput.extend(
'beamintensityblob2',
'blob');
1483 condition=coral.AttributeList()
1484 condition.extend(
'runnum',
'unsigned int')
1485 condition.extend(
'lumiversion',
'string')
1486 condition[
'runnum'].setData(
int(runnum))
1487 condition[
'lumiversion'].setData(parameters.lumiversion)
1489 query.addToTableList(parameters.lumisummaryname)
1490 query.addToOutputList(
'CMSLSNUM',
'cmslsnum')
1491 query.addToOutputList(
'STARTORBIT',
'startorbit')
1492 query.addToOutputList(
'CMSBXINDEXBLOB',
'bxindexblob')
1493 query.addToOutputList(
'BEAMINTENSITYBLOB_1',
'beamintensityblob1')
1494 query.addToOutputList(
'BEAMINTENSITYBLOB_2',
'beamintensityblob2')
1495 query.setCondition(
'RUNNUM=:runnum AND LUMIVERSION=:lumiversion',condition)
1496 query.defineOutput(lumisummaryOutput)
1497 cursor=query.execute()
1500 startorbit=cursor.currentRow()[
'startorbit'].
data()
1505 beamintensityblob1=
None 1506 beamintensityblob2=
None 1507 if not cursor.currentRow()[
"bxindexblob"].isNull():
1508 bxindexblob=cursor.currentRow()[
'bxindexblob'].
data()
1509 if bxindexblob
and bxindexblob.readline()!=
None:
1511 if not cursor.currentRow()[
'beamintensityblob1'].isNull():
1512 beamintensityblob1=cursor.currentRow()[
'beamintensityblob1'].
data()
1513 if beamintensityblob1
and beamintensityblob1.readline()!=
None:
1515 if not cursor.currentRow()[
'beamintensityblob2'].isNull():
1516 beamintensityblob2=cursor.currentRow()[
'beamintensityblob2'].
data()
1517 if beamintensityblob2
and beamintensityblob2.readline()!=
None:
1519 if startorbit
not in result:
1520 result[startorbit]=[]
1521 for idx,bxidxvalue
in enumerate(bxidx):
1523 b1intensity=bb1[idx]
1527 b2intensity=bb2[idx]
1530 result[startorbit].
append((bxidxvalue,b1intensity,b2intensity))
1538 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 1539 result={(startorbit,cmslsnum):[(index,lumivalue,lumierr),]} 1542 detailOutput=coral.AttributeList()
1543 detailOutput.extend(
'cmslsnum',
'unsigned int')
1544 detailOutput.extend(
'startorbit',
'unsigned int')
1545 detailOutput.extend(
'bxlumivalue',
'blob')
1546 detailOutput.extend(
'bxlumierror',
'blob')
1547 detailCondition=coral.AttributeList()
1548 detailCondition.extend(
'runnum',
'unsigned int')
1549 detailCondition.extend(
'algoname',
'string')
1550 detailCondition[
'runnum'].setData(runnum)
1551 detailCondition[
'algoname'].setData(algoname)
1553 query.addToTableList(parameters.lumisummaryname,
's')
1554 query.addToTableList(parameters.lumidetailname,
'd')
1555 query.addToOutputList(
's.CMSLSNUM',
'cmslsnum')
1556 query.addToOutputList(
's.STARTORBIT',
'startorbit')
1557 query.addToOutputList(
'd.BXLUMIVALUE',
'bxlumivalue')
1558 query.addToOutputList(
'd.BXLUMIERROR',
'bxlumierror')
1559 query.addToOutputList(
'd.BXLUMIQUALITY',
'bxlumiquality')
1560 query.setCondition(
's.RUNNUM=:runnum and d.ALGONAME=:algoname and s.LUMISUMMARY_ID=d.LUMISUMMARY_ID',detailCondition)
1561 query.defineOutput(detailOutput)
1562 cursor=query.execute()
1564 cmslsnum=cursor.currentRow()[
'cmslsnum'].
data()
1565 bxlumivalue=cursor.currentRow()[
'bxlumivalue'].
data()
1566 bxlumierror=cursor.currentRow()[
'bxlumierror'].
data()
1567 startorbit=cursor.currentRow()[
'startorbit'].
data()
1568 bxlumivalueArray=array.array(
'f')
1569 bxlumivalueArray.fromstring(bxlumivalue.readline())
1570 bxlumierrorArray=array.array(
'f')
1571 bxlumierrorArray.fromstring(bxlumierror.readline())
1575 if len(bxlumivalueArray)!=0:
1576 maxlumi=
max(bxlumivalueArray)
1578 if len(bxlumivalueArray)!=0:
1579 avginstlumi=sum(bxlumivalueArray)
1580 for index,lum
in enumerate(bxlumivalueArray):
1581 lumierror = bxlumierrorArray[index]
1582 if lum<
max(parameters.xingMinLum,maxlumi*0.2):
1584 mynorm=parameters.normFactor
1586 lum=lumiCorrections.applyfinecorrectionBX(lum,avginstlumi*mynorm,mynorm,finecorrection[0],finecorrection[1],finecorrection[2])
1587 lumierror=lumiCorrections.applyfinecorrectionBX(lumierror,avginstlumi*mynorm,mynorm,finecorrection[0],finecorrection[1],finecorrection[2])
1591 xingLum.append( (index,lum,lumierror) )
1593 result[(startorbit,cmslsnum)]=xingLum
1598 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 1599 output: [[cmslsnum,bxlumivalue,bxlumierror,bxlumiquality,startorbit]] 1600 since the output is ordered by time, it has to be in seq list format 1605 queryCondition=coral.AttributeList()
1606 queryCondition.extend(
'runnum',
'unsigned int')
1607 queryCondition.extend(
'algoname',
'string')
1608 queryCondition[
'runnum'].setData(
int(runnum))
1609 queryCondition[
'algoname'].setData(algoname)
1610 queryHandle.addToOutputList(
's.CMSLSNUM',
'cmslsnum')
1611 queryHandle.addToOutputList(
'd.BXLUMIVALUE',
'bxlumivalue')
1612 queryHandle.addToOutputList(
'd.BXLUMIERROR',
'bxlumierror')
1613 queryHandle.addToOutputList(
'd.BXLUMIQUALITY',
'bxlumiquality')
1614 queryHandle.addToOutputList(
's.STARTORBIT',
'startorbit')
1615 queryHandle.setCondition(
's.runnum=:runnum and d.algoname=:algoname and s.lumisummary_id=d.lumisummary_id',queryCondition)
1616 queryResult=coral.AttributeList()
1617 queryResult.extend(
'cmslsnum',
'unsigned int')
1618 queryResult.extend(
'bxlumivalue',
'blob')
1619 queryResult.extend(
'bxlumierror',
'blob')
1620 queryResult.extend(
'bxlumiquality',
'blob')
1621 queryResult.extend(
'startorbit',
'unsigned int')
1622 queryHandle.addToOrderList(
's.STARTORBIT')
1623 queryHandle.defineOutput(queryResult)
1624 cursor=queryHandle.execute()
1626 cmslsnum=cursor.currentRow()[
'cmslsnum'].
data()
1627 bxlumivalue=cursor.currentRow()[
'bxlumivalue'].
data()
1628 bxlumierror=cursor.currentRow()[
'bxlumierror'].
data()
1629 bxlumiquality=cursor.currentRow()[
'bxlumiquality'].
data()
1630 startorbit=cursor.currentRow()[
'startorbit'].
data()
1631 result.append([cmslsnum,bxlumivalue,bxlumierror,bxlumiquality,startorbit])
1636 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 1637 output: {algoname:{cmslsnum:[bxlumivalue,bxlumierror,bxlumiquality,startorbit]}} 1642 queryCondition=coral.AttributeList()
1643 queryCondition.extend(
'runnum',
'unsigned int')
1644 queryCondition[
'runnum'].setData(
int(runnum))
1645 queryHandle.addToOutputList(
's.CMSLSNUM',
'cmslsnum')
1646 queryHandle.addToOutputList(
'd.BXLUMIVALUE',
'bxlumivalue')
1647 queryHandle.addToOutputList(
'd.BXLUMIERROR',
'bxlumierror')
1648 queryHandle.addToOutputList(
'd.BXLUMIQUALITY',
'bxlumiquality')
1649 queryHandle.addToOutputList(
'd.ALGONAME',
'algoname')
1650 queryHandle.addToOutputList(
's.STARTORBIT',
'startorbit')
1651 queryHandle.setCondition(
's.RUNNUM=:runnum and s.LUMISUMMARY_ID=d.LUMISUMMARY_ID',queryCondition)
1652 queryResult=coral.AttributeList()
1653 queryResult.extend(
'cmslsnum',
'unsigned int')
1654 queryResult.extend(
'bxlumivalue',
'blob')
1655 queryResult.extend(
'bxlumierror',
'blob')
1656 queryResult.extend(
'bxlumiquality',
'blob')
1657 queryResult.extend(
'algoname',
'string')
1658 queryResult.extend(
'startorbit',
'unsigned int')
1659 queryHandle.addToOrderList(
'startorbit')
1660 queryHandle.addToOrderList(
'algoname')
1661 queryHandle.defineOutput(queryResult)
1662 cursor=queryHandle.execute()
1664 cmslsnum=cursor.currentRow()[
'cmslsnum'].
data()
1665 bxlumivalue=cursor.currentRow()[
'bxlumivalue'].
data()
1666 bxlumierror=cursor.currentRow()[
'bxlumierror'].
data()
1667 bxlumiquality=cursor.currentRow()[
'bxlumiquality'].
data()
1668 algoname=cursor.currentRow()[
'algoname'].
data()
1669 startorbit=cursor.currentRow()[
'startorbit'].
data()
1670 if algoname
not in result:
1672 dataPerAlgo[cmslsnum]=[bxlumivalue,bxlumierror,bxlumiquality,startorbit]
1673 result[algoname]=dataPerAlgo
1675 result[algoname][cmslsnum]=[bxlumivalue,bxlumierror,bxlumiquality,startorbit]
1680 select m.hltpathname,m.l1seed from cmsrunsummary r,trghltmap m where r.runnum=:runnum and m.hltkey=r.hltkey 1681 output: {hltpath:l1seed} 1686 queryCondition=coral.AttributeList()
1687 queryCondition.extend(
'runnum',
'unsigned int')
1688 queryCondition[
'runnum'].setData(
int(runnum))
1689 queryHandle.addToOutputList(
'm.HLTPATHNAME',
'hltpathname')
1690 queryHandle.addToOutputList(
'm.L1SEED',
'l1seed')
1691 queryHandle.setCondition(
'r.RUNNUM=:runnum and m.HLTKEY=r.HLTKEY',queryCondition)
1692 queryResult=coral.AttributeList()
1693 queryResult.extend(
'hltpathname',
'string')
1694 queryResult.extend(
'l1seed',
'string')
1695 queryHandle.defineOutput(queryResult)
1696 cursor=queryHandle.execute()
1698 hltpathname=cursor.currentRow()[
'hltpathname'].
data()
1699 l1seed=cursor.currentRow()[
'l1seed'].
data()
1700 if hltpathname
not in result:
1701 result[hltpathname]=l1seed
1706 find all runs in the fill range inclusive 1707 select runnum,fillnum from cmsrunsummary where fillnum>=:minFill and fillnum<=:maxFill 1708 output: fillDict={fillnum:[runlist]} 1712 queryCondition=coral.AttributeList()
1713 queryCondition.extend(
'minFill',
'unsigned int')
1714 queryCondition.extend(
'maxFill',
'unsigned int')
1715 queryCondition[
'minFill'].setData(
int(minFill))
1716 queryCondition[
'maxFill'].setData(
int(maxFill))
1717 queryHandle.addToOutputList(
'RUNNUM',
'runnum')
1718 queryHandle.addToOutputList(
'FILLNUM',
'fillnum')
1719 queryHandle.setCondition(
'FILLNUM>=:minFill and FILLNUM<=:maxFill',queryCondition)
1720 queryResult=coral.AttributeList()
1721 queryResult.extend(
'runnum',
'unsigned int')
1722 queryResult.extend(
'fillnum',
'unsigned int')
1723 queryHandle.defineOutput(queryResult)
1724 cursor=queryHandle.execute()
1726 runnum=cursor.currentRow()[
'runnum'].
data()
1727 fillnum=cursor.currentRow()[
'fillnum'].
data()
1728 if fillnum
not in result:
1729 result[fillnum]=[runnum]
1731 result[fillnum].
append(runnum)
1736 find all runs in the time range inclusive 1737 the selected run must have started after minTime and finished by maxTime 1738 select runnum,to_char(startTime),to_char(stopTime) from cmsrunsummary where startTime>=timestamp(minTime) and stopTime<=timestamp(maxTime); 1739 input: minTime,maxTime in python obj datetime.datetime 1740 output: {runnum:[starttime,stoptime]} return in python obj datetime.datetime 1744 coralminTime=coral.TimeStamp(minTime.year,minTime.month,minTime.day,minTime.hour,minTime.minute,minTime.second,0)
1745 coralmaxTime=coral.TimeStamp(maxTime.year,maxTime.month,maxTime.day,maxTime.hour,maxTime.minute,maxTime.second,0)
1747 queryCondition=coral.AttributeList()
1748 queryCondition.extend(
'minTime',
'time stamp')
1749 queryCondition.extend(
'maxTime',
'time stamp')
1750 queryCondition[
'minTime'].setData(coralminTime)
1751 queryCondition[
'maxTime'].setData(coralmaxTime)
1752 queryHandle.addToOutputList(
'RUNNUM',
'runnum')
1753 queryHandle.addToOutputList(
'TO_CHAR(STARTTIME,\''+t.coraltimefm+
'\')',
'starttime')
1754 queryHandle.addToOutputList(
'TO_CHAR(STOPTIME,\''+t.coraltimefm+
'\')',
'stoptime')
1755 queryHandle.setCondition(
'STARTTIME>=:minTime and STOPTIME<=:maxTime',queryCondition)
1756 queryResult=coral.AttributeList()
1757 queryResult.extend(
'runnum',
'unsigned int')
1758 queryResult.extend(
'starttime',
'string')
1759 queryResult.extend(
'stoptime',
'string')
1760 queryHandle.defineOutput(queryResult)
1761 cursor=queryHandle.execute()
1763 runnum=cursor.currentRow()[
'runnum'].
data()
1764 starttimeStr=cursor.currentRow()[
'starttime'].
data()
1765 stoptimeStr=cursor.currentRow()[
'stoptime'].
data()
1766 if runnum
not in result:
1767 result[runnum]=[t.StrToDatetime(starttimeStr),t.StrToDatetime(stoptimeStr)]
1770 if __name__==
'__main__':
1771 msg=coral.MessageStream(
'')
1773 msg.setMsgVerbosity(coral.message_Level_Error)
1774 os.environ[
'CORAL_AUTH_PATH']=
'/afs/cern.ch/cms/DB/lumi' 1775 svc = coral.ConnectionService()
1776 connectstr=
'oracle://cms_orcoff_prod/cms_lumi_prod' 1777 session=svc.connect(connectstr,accessMode=coral.access_ReadOnly)
1778 session.typeConverter().setCppTypeForSqlType(
"unsigned int",
"NUMBER(10)")
1779 session.typeConverter().setCppTypeForSqlType(
"unsigned long long",
"NUMBER(20)")
1780 session.transaction().
start(
True)
1781 schema=session.nominalSchema()
1782 allruns=
allruns(schema,requireLumisummary=
True,requireTrg=
True,requireHlt=
True)
1783 print 'allruns in runsummary and lumisummary and trg and hlt ',len(allruns)
1842 session.transaction().commit()
1877 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)