1 from __future__
import print_function
4 from RecoLuminosity.LumiDB
import nameDealer,lumiTime,CommonUtil,lumiCorrections
9 from RecoLuminosity.LumiDB
import nameDealer, selectionParser, hltTrgSeedMapper, \
10 connectstrParser, cacheconfigParser, tablePrinter, csvReporter, csvSelectionParser
11 from RecoLuminosity.LumiDB.wordWrappers
import wrap_always, wrap_onspace, wrap_onspace_strict
12 from pprint
import pprint, pformat
15 This module defines lowlevel SQL query API for lumiDB 16 We do not like range queries so far because of performance of range scan.Use only necessary. 17 The principle is to query by runnumber and per each coral queryhandle 18 Try reuse db session/transaction and just renew query handle each time to reduce metadata queries. 19 Avoid unnecessary explicit order by 20 Do not handle transaction in here. 21 Do not do explicit del queryhandle in here. 22 Note: all the returned dict format are not sorted by itself.Sort it outside if needed. 50 '''Given the rotation rate, calculate lumi section length and 51 rotation time. This should be called if rotationRate is 57 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>''' 61 l = numorbit * numbx * 25.0e-09
66 input: {lsnum:[deadtime, instlumi, bit_0, norbits,prescale...]} 67 output: {lsnum:[instlumi, recordedlumi...]} 70 for myls, deadArray
in deadtable.items():
71 lstime = lslengthsec (deadArray[3], 3564)
72 instlumi = deadArray[1] * lstime
73 if float( deadArray[2] ) == 0.0:
76 deadfrac = float (deadArray[0]) / (float (deadArray[2])*
float(deadArray[4]))
77 recordedLumi = instlumi * (1.0 - deadfrac)
78 myLsList = [instlumi, recordedLumi]
80 if len (deadArray) > 5:
81 myLsList.extend (deadArray[5:])
82 result[myls] = myLsList
87 '''Takes either single run as a string or dictionary of run ranges''' 90 if isinstance(inputRange, str):
91 runs.append(
int(inputRange))
93 runs=inputRange.runs()
94 for r
in sorted(runs):
95 if parameters.verbose:
100 lumidata.append( deliveredLumiForRun (dbsession, parameters,r,finecorrections=c) )
104 '''Takes either single run as a string or dictionary of run ranges''' 106 if isinstance(inputRange,str):
108 if finecorrections
and finecorrections[run]:
109 lumiDataPiece = recordedLumiForRun (dbsession, parameters,inputRange,lslist=
None,finecorrections=finecorrections[run])
112 if parameters.lumiXing:
114 if finecorrections
and finecorrections[run]:
115 xingLumiDict = xingLuminosityForRun (dbsession, inputRange,
116 parameters,finecorrections=finecorrections[run])
118 xingLumiDict = xingLuminosityForRun (dbsession, inputRange,
120 mergeXingLumi (lumiDataPiece, xingLumiDict)
121 lumidata.append (lumiDataPiece)
125 maxLumiSectionDict = {}
126 for (run, lslist)
in sorted (inputRange.runsandls().
items() ):
128 maxLumiSectionDict[run] = max ( max (lslist),
129 maxLumiSectionDict.get(run,0) )
130 runLsDict.setdefault (run, []).append (lslist)
131 for run, metaLsList
in sorted (six.iteritems(runLsDict)):
132 if parameters.verbose:
135 for lslist
in metaLsList:
136 if finecorrections
and finecorrections[run]:
137 runLumiData.append( recordedLumiForRun (dbsession, parameters,run,lslist=lslist,finecorrections=finecorrections[run]) )
140 runLumiData.append( recordedLumiForRun (dbsession, parameters,run,lslist=lslist) )
141 if parameters.lumiXing:
143 if finecorrections
and finecorrections[run]:
144 xingLumiDict = xingLuminosityForRun (dbsession, run,
147 maxLumiSectionDict[run],
148 finecorrections=finecorrections[run])
150 xingLumiDict = xingLuminosityForRun (dbsession, run,
153 maxLumiSectionDict[run])
155 for lumiDataPiece
in runLumiData:
156 mergeXingLumi (lumiDataPiece, xingLumiDict)
157 lumidata.append (lumiDataPiece)
159 lumidata.extend( runLumiData )
164 select sum (INSTLUMI), count (INSTLUMI) from lumisummary where runnum = 124025 and lumiversion = '0001'; 165 select INSTLUMI,NUMORBIT from lumisummary where runnum = 124025 and lumiversion = '0001' 166 query result unit E27cm^-2 (= 1 / mb) 168 optional corrections=None/(constfactor,afterglowfactor,nonlinearfactor) 176 conditionstring=
"RUNNUM = :runnum AND LUMIVERSION = :lumiversion" 177 dbsession.transaction().start (
True)
178 schema = dbsession.nominalSchema()
180 query.addToOutputList(
"INSTLUMI",
'instlumi')
181 query.addToOutputList (
"NUMORBIT",
"norbits")
182 queryBind = coral.AttributeList()
183 queryBind.extend (
"runnum",
"unsigned int")
184 queryBind.extend (
"lumiversion",
"string")
185 queryBind[
"runnum"].setData (int (runnum))
186 queryBind[
"lumiversion"].setData (parameters.lumiversion)
188 if len(parameters.beammode)!=0:
189 conditionstring=conditionstring+
' and BEAMSTATUS=:beamstatus' 190 queryBind.extend(
'beamstatus',
'string')
191 queryBind[
'beamstatus'].setData(parameters.beammode)
192 result = coral.AttributeList()
193 result.extend (
"instlumi",
"float")
194 result.extend (
"norbits",
"unsigned int")
195 query.defineOutput (result)
196 query.setCondition (conditionstring,queryBind)
197 cursor = query.execute()
199 instlumi = cursor.currentRow()[
'instlumi'].
data()
200 norbits = cursor.currentRow()[
'norbits'].
data()
201 if finecorrections
is not None:
202 instlumi=lumiCorrections.applyfinecorrection(instlumi,finecorrections[0],finecorrections[1],finecorrections[2])
203 if instlumi
is not None and norbits
is not None:
205 delivered=delivered+instlumi*parameters.norm*lstime
208 dbsession.transaction().commit()
211 lumidata = [str (runnum),
'N/A',
'N/A',
'N/A']
213 lumidata = [str (runnum), str (totalls),
'%.3f'%delivered, parameters.beammode]
215 except Exception
as e:
217 dbsession.transaction().rollback()
222 lslist = [] means take none in the db 223 lslist = None means to take all in the db 224 output: ['runnumber', 'trgtable{}', 'deadtable{}'] 230 lumidata.append (runnum)
231 lumidata.append (trgtable)
232 lumidata.append (deadtable)
234 conditionstring=
'trghltmap.HLTKEY = cmsrunsummary.HLTKEY AND cmsrunsummary.RUNNUM = :runnumber' 236 dbsession.transaction().start (
True)
237 schema = dbsession.nominalSchema()
238 query = schema.newQuery()
241 queryCondition = coral.AttributeList()
242 queryCondition.extend (
"runnumber",
"unsigned int")
243 queryCondition[
"runnumber"].setData (int (runnum))
244 query.setCondition (conditionstring,queryCondition)
245 query.addToOutputList (
"trghltmap.HLTPATHNAME",
"hltpathname")
246 query.addToOutputList (
"trghltmap.L1SEED",
"l1seed")
247 result = coral.AttributeList()
248 result.extend (
"hltpathname",
"string")
249 result.extend (
"l1seed",
"string")
250 query.defineOutput (result)
251 cursor = query.execute()
253 hltpathname = cursor.currentRow()[
"hltpathname"].
data()
254 l1seed = cursor.currentRow()[
"l1seed"].
data()
255 collectedseeds.append ( (hltpathname, l1seed))
258 dbsession.transaction().commit()
260 for (hname, sname)
in collectedseeds:
261 l1bitname = hltTrgSeedMapper.findUniqueSeed (hname, sname)
264 lumidata[1][hname] = []
265 lumidata[1][hname].append (l1bitname.replace (
'\"',
''))
266 dbsession.transaction().start (
True)
267 schema = dbsession.nominalSchema()
269 hltprescQuery.addToOutputList (
"PATHNAME",
"hltpath")
270 hltprescQuery.addToOutputList (
"PRESCALE",
"hltprescale")
271 hltprescCondition = coral.AttributeList()
272 hltprescCondition.extend (
'runnumber',
'unsigned int')
273 hltprescCondition.extend (
'cmslsnum',
'unsigned int')
274 hltprescCondition.extend (
'inf',
'unsigned int')
275 hltprescResult = coral.AttributeList()
276 hltprescResult.extend (
'hltpath',
'string')
277 hltprescResult.extend (
'hltprescale',
'unsigned int')
278 hltprescQuery.defineOutput (hltprescResult)
279 hltprescCondition[
'runnumber'].setData (int (runnum))
280 hltprescCondition[
'cmslsnum'].setData (1)
281 hltprescCondition[
'inf'].setData (0)
282 hltprescQuery.setCondition (
"RUNNUM = :runnumber and CMSLSNUM = :cmslsnum and PRESCALE != :inf",hltprescCondition)
283 cursor = hltprescQuery.execute()
285 hltpath = cursor.currentRow()[
'hltpath'].
data()
286 hltprescale = cursor.currentRow()[
'hltprescale'].
data()
287 if hltpath
in lumidata[1]:
288 lumidata[1][hltpath].append (hltprescale)
292 dbsession.transaction().commit()
293 dbsession.transaction().start (
True)
294 schema = dbsession.nominalSchema()
295 query = schema.newQuery()
298 queryCondition = coral.AttributeList()
299 queryCondition.extend (
"runnumber",
"unsigned int")
300 queryCondition.extend (
"lumiversion",
"string")
301 queryCondition[
"runnumber"].setData (int (runnum))
302 queryCondition[
"lumiversion"].setData (parameters.lumiversion)
303 conditionstring=
'lumisummary.RUNNUM =:runnumber and lumisummary.LUMIVERSION =:lumiversion AND lumisummary.CMSLSNUM=trg.CMSLSNUM and lumisummary.RUNNUM=trg.RUNNUM' 304 if len(parameters.beammode)!=0:
305 conditionstring=conditionstring+
' and lumisummary.BEAMSTATUS=:beamstatus' 306 queryCondition.extend(
'beamstatus',
'string')
307 queryCondition[
'beamstatus'].setData(parameters.beammode)
308 query.setCondition(conditionstring,queryCondition)
309 query.addToOutputList (
"lumisummary.CMSLSNUM",
"cmsls")
310 query.addToOutputList (
"lumisummary.INSTLUMI",
"instlumi")
311 query.addToOutputList (
"lumisummary.NUMORBIT",
"norbits")
312 query.addToOutputList (
"trg.TRGCOUNT",
"trgcount")
313 query.addToOutputList (
"trg.BITNAME",
"bitname")
314 query.addToOutputList (
"trg.DEADTIME",
"trgdeadtime")
315 query.addToOutputList (
"trg.PRESCALE",
"trgprescale")
316 query.addToOutputList (
"trg.BITNUM",
"trgbitnum")
318 result = coral.AttributeList()
319 result.extend (
"cmsls",
"unsigned int")
320 result.extend (
"instlumi",
"float")
321 result.extend (
"norbits",
"unsigned int")
322 result.extend (
"trgcount",
"unsigned int")
323 result.extend (
"bitname",
"string")
324 result.extend (
"trgdeadtime",
"unsigned long long")
325 result.extend (
"trgprescale",
"unsigned int")
326 result.extend (
"trgbitnum",
"unsigned int")
328 query.defineOutput (result)
329 cursor = query.execute()
331 cmsls = cursor.currentRow()[
"cmsls"].
data()
332 instlumi = cursor.currentRow()[
"instlumi"].
data()*parameters.norm
334 instlumi=lumiCorrections.applyfinecorrection(instlumi,finecorrections[0],finecorrections[1],finecorrections[2])
335 norbits = cursor.currentRow()[
"norbits"].
data()
336 trgcount = cursor.currentRow()[
"trgcount"].
data()
337 trgbitname = cursor.currentRow()[
"bitname"].
data()
338 trgdeadtime = cursor.currentRow()[
"trgdeadtime"].
data()
339 trgprescale = cursor.currentRow()[
"trgprescale"].
data()
340 trgbitnum = cursor.currentRow()[
"trgbitnum"].
data()
342 if trgbitname
not in trgprescalemap:
343 trgprescalemap[trgbitname] = trgprescale
345 if cmsls
not in deadtable:
346 deadtable[cmsls] = []
347 deadtable[cmsls].append (trgdeadtime)
348 deadtable[cmsls].append (instlumi)
349 deadtable[cmsls].append (trgcount)
350 deadtable[cmsls].append (norbits)
351 deadtable[cmsls].append (trgprescale)
354 dbsession.transaction().commit()
362 for hpath, trgdataseq
in lumidata[1].
items():
364 if bitn
in trgprescalemap
and len (trgdataseq) == 2:
365 lumidata[1][hpath].append (trgprescalemap[bitn])
367 lumidata[2] = filterDeadtable (deadtable, lslist)
368 if not parameters.noWarnings:
369 if len(lumidata[2])!=0:
370 for lumi, deaddata
in lumidata[2].
items():
371 if deaddata[1] == 0.0
and deaddata[2]!=0
and deaddata[0]!=0:
372 print(
'[Warning] : run %s :ls %d has 0 instlumi but trigger has data' % (runnum, lumi))
373 if (deaddata[2] == 0
or deaddata[0] == 0)
and deaddata[1]!=0.0:
374 print(
'[Warning] : run %s :ls %d has 0 dead counts or 0 zerobias bit counts, but inst!=0' % (runnum, lumi))
376 except Exception
as e:
378 dbsession.transaction().rollback()
391 if len (lslist) == 0:
393 for existingLS
in inTable.keys():
394 if existingLS
in lslist:
395 result[existingLS] = inTable[existingLS]
400 labels = [ (
'Run',
'Delivered LS',
'Delivered'+
u' (/\u03bcb)'.encode (
'utf-8'),
'Beam Mode')]
401 print(tablePrinter.indent (labels+lumidata, hasHeader =
True, separateRows =
False,
402 prefix =
'| ', postfix =
' |', justify =
'right',
403 delim =
' | ', wrapfunc =
lambda x: wrap_onspace (x, 20) ))
407 input params: lumidata [{'fieldname':value}] 412 r.writeRows(lumidata)
416 input: {lsnum:[deadtime, instlumi, bit_0, norbits,prescale]} 420 for myls, d
in deadtable.items():
424 if float (d[2]) == 0.0:
427 deadfrac = float (d[0])/(float (d[2])*float (d[-1]))
428 lstime = lslengthsec (d[3], 3564)
429 recordedLumi += instLumi* (1.0-deadfrac)*lstime
437 result.append ([inPut[0]])
441 result[counter].append (i)
446 return ', '.join ([
'['+str (min (x))+
'-'+str (max (x))+
']' for x
in result])
451 input: trgtable{hltpath:[l1seed, hltprescale, l1prescale]}, totalrecorded (float) 452 output:{hltpath, recorded} 456 for hltpath, data
in trgtable.items():
458 result[hltpath] = totalrecorded/ (data[1]*data[2])
460 result[hltpath] = 0.0
466 inputtable: {lsnum:[deadtime, instlumi, bit_0, norbits,bit_0_prescale]} 467 output: {lsnum:deadfraction} 470 for myls, d
in deadtable.items():
472 if float (d[2]) == 0.0:
475 deadfrac = float (d[0])/ (float (d[2])*
float(d[-1]))
476 result[myls] = deadfrac
481 input lumidata [['runnumber', 'trgtable{}', 'deadtable{}']] 482 deadtable {lsnum:[deadtime, instlumi, bit_0, norbits,prescale]} 486 labels = [ (
'Run',
'LS',
'Delivered',
'Recorded'+
u' (/\u03bcb)'.encode (
'utf-8'))]
487 lastrowlabels = [ (
'Selected LS',
'Delivered'+
u' (/\u03bcb)'.encode (
'utf-8'),
'Recorded'+
u' (/\u03bcb)'.encode (
'utf-8'))]
493 for perrundata
in lumidata:
494 runnumber = perrundata[0]
495 deadtable = perrundata[2]
496 lumiresult = lsBylsLumi (deadtable)
497 totalSelectedLS = totalSelectedLS+len (deadtable)
498 for lsnum, dataperls
in lumiresult.items():
500 if len (dataperls) == 0:
501 rowdata += [str (runnumber), str (lsnum),
'N/A',
'N/A']
503 rowdata += [str (runnumber), str (lsnum),
'%.3f' % (dataperls[0]),
'%.3f' % (dataperls[1])]
504 totalDelivered = totalDelivered+dataperls[0]
505 totalRecorded = totalRecorded+dataperls[1]
506 datatoprint.append (rowdata)
507 totalrow.append ([str (totalSelectedLS),
'%.3f'% (totalDelivered),
'%.3f'% (totalRecorded)])
509 print(tablePrinter.indent (labels+datatoprint, hasHeader =
True, separateRows =
False, prefix =
'| ',
510 postfix =
' |', justify =
'right', delim =
' | ',
511 wrapfunc =
lambda x: wrap_onspace_strict (x, 22)))
512 print(
' == = Total : ')
513 print(tablePrinter.indent (lastrowlabels+totalrow, hasHeader =
True, separateRows =
False, prefix =
'| ',
514 postfix =
' |', justify =
'right', delim =
' | ',
515 wrapfunc =
lambda x: wrap_onspace (x, 20)))
520 for perrundata
in lumidata:
521 runnumber = perrundata[0]
522 deadtable = perrundata[2]
523 lumiresult = lsBylsLumi (deadtable)
524 for lsnum, dataperls
in lumiresult.items():
526 if len (dataperls) == 0:
527 rowdata += [str (runnumber), str (lsnum),
'N/A',
'N/A']
529 rowdata += [str (runnumber), str (lsnum), dataperls[0], dataperls[1]]
530 if len (dataperls) > 2:
531 rowdata.extend ( flatten (dataperls[2:]) )
532 datatodump.append (rowdata)
539 labels = [ (
'Run',
'HLT path',
'Recorded'+
u' (/\u03bcb)'.encode (
'utf-8'))]
540 lastrowlabels = [ (
'Selected LS',
'Recorded'+
u' (/\u03bcb)'.encode (
'utf-8'))]
541 if len (hltpath) != 0
and hltpath !=
'all':
542 lastrowlabels = [ (
'Selected LS',
'Recorded'+
u' (/\u03bcb)'.encode (
'utf-8'),
543 'Effective '+
u' (/\u03bcb) '.encode (
'utf-8')+hltpath)]
545 labels = [ (
'Run',
'HLT-path',
'L1-bit',
'L1-presc',
'HLT-presc',
'Recorded'+
u' (/\u03bcb)'.encode (
'utf-8'))]
548 totalRecordedInPath = 0.0
550 for dataperRun
in lumidata:
551 runnum = dataperRun[0]
552 if len (dataperRun[1]) == 0:
554 rowdata += [str (runnum)]+2*[
'N/A']
555 datatoprint.append (rowdata)
557 perlsdata = dataperRun[2]
558 totalSelectedLS = totalSelectedLS+len (perlsdata)
561 recordedLumi = calculateTotalRecorded (perlsdata)
562 totalRecorded = totalRecorded+recordedLumi
563 trgdict = dataperRun[1]
564 effective = calculateEffective (trgdict, recordedLumi)
565 if hltpath
in trgdict
and hltpath
in effective:
567 l1bit = trgdict[hltpath][0]
568 if len (trgdict[hltpath]) != 3:
570 rowdata += [str (runnum), hltpath,
'N/A']
572 rowdata += [str (runnum), hltpath, l1bit,
'N/A',
'N/A',
'N/A']
575 rowdata += [str (runnum), hltpath,
'%.3f'% (effective[hltpath])]
577 hltprescale = trgdict[hltpath][1]
578 l1prescale = trgdict[hltpath][2]
579 rowdata += [str (runnum), hltpath, l1bit, str (l1prescale), str (hltprescale),
580 '%.3f'% (effective[hltpath])]
581 totalRecordedInPath = totalRecordedInPath+effective[hltpath]
582 datatoprint.append (rowdata)
585 for trg, trgdata
in trgdict.items():
588 if trg == trgdict.keys()[0]:
589 rowdata += [str (runnum)]
593 if len (trgdata) == 3:
595 rowdata += [trg,
'%.3f'% (effective[trg])]
597 hltprescale = trgdata[1]
598 l1prescale = trgdata[2]
599 rowdata += [trg, l1bit, str (l1prescale), str (hltprescale),
'%.3f'% (effective[trg])]
602 rowdata += [trg,
'N/A']
604 rowdata += [trg, l1bit,
'N/A',
'N/A',
'%.3f'% (effective[trg])]
605 datatoprint.append (rowdata)
608 print(tablePrinter.indent (labels+datatoprint, hasHeader =
True, separateRows =
False, prefix =
'| ',
609 postfix =
' |', justify =
'right', delim =
' | ',
610 wrapfunc =
lambda x: wrap_onspace_strict (x, 22)))
612 if len (hltpath) != 0
and hltpath !=
'all':
613 totalrow.append ([str (totalSelectedLS),
'%.3f'% (totalRecorded),
'%.3f'% (totalRecordedInPath)])
615 totalrow.append ([str (totalSelectedLS),
'%.3f'% (totalRecorded)])
616 print(
' == = Total : ')
617 print(tablePrinter.indent (lastrowlabels+totalrow, hasHeader =
True, separateRows =
False, prefix =
'| ',
618 postfix =
' |', justify =
'right', delim =
' | ',
619 wrapfunc =
lambda x: wrap_onspace (x, 20)))
622 deadtimelabels = [ (
'Run',
'Lumi section : Dead fraction')]
624 for dataperRun
in lumidata:
625 runnum = dataperRun[0]
626 if len (dataperRun[1]) == 0:
627 deadtoprint.append ([str (runnum),
'N/A'])
629 perlsdata = dataperRun[2]
631 deadT = getDeadfractions (perlsdata)
633 for myls, de
in deadT.items():
635 t += str (myls)+
':nobeam ' 637 t += str (myls)+
':'+
'%.5f'% (de)+
' ' 638 deadtoprint.append ([str (runnum), t])
640 print(tablePrinter.indent (deadtimelabels+deadtoprint, hasHeader =
True, separateRows =
True, prefix =
'| ',
641 postfix =
' |', justify =
'right', delim =
' | ',
642 wrapfunc =
lambda x: wrap_onspace (x, 80)))
648 for dataperRun
in lumidata:
649 runnum = dataperRun[0]
650 if len (dataperRun[1]) == 0:
652 rowdata += [str (runnum)]+2*[
'N/A']
653 datatodump.append (rowdata)
655 perlsdata = dataperRun[2]
658 recordedLumi = calculateTotalRecorded (perlsdata)
659 trgdict = dataperRun[1]
660 effective = calculateEffective (trgdict, recordedLumi)
661 if hltpath
in trgdict
and hltpath
in effective:
663 l1bit = trgdict[hltpath][0]
664 if len (trgdict[hltpath]) != 3:
665 rowdata += [str (runnum), hltpath,
'N/A']
667 hltprescale = trgdict[hltpath][1]
668 l1prescale = trgdict[hltpath][2]
669 rowdata += [str (runnum), hltpath, effective[hltpath]]
670 datatodump.append (rowdata)
673 for trg, trgdata
in trgdict.items():
676 rowdata += [str (runnum)]
678 if len (trgdata) == 3:
679 rowdata += [trg, effective[trg]]
681 rowdata += [trg,
'N/A']
682 datatodump.append (rowdata)
687 if len (hltpath) == 0
or hltpath ==
'all':
688 toprowlabels = [ (
'Run',
'Delivered LS',
'Delivered'+
u' (/\u03bcb)'.encode (
'utf-8'),
'Selected LS',
'Recorded'+
u' (/\u03bcb)'.encode (
'utf-8') )]
689 lastrowlabels = [ (
'Delivered LS',
'Delivered'+
u' (/\u03bcb)'.encode (
'utf-8'),
'Selected LS',
'Recorded'+
u' (/\u03bcb)'.encode (
'utf-8') ) ]
691 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 )]
692 lastrowlabels = [ (
'Delivered LS',
'Delivered'+
u' (/\u03bcb)'.encode (
'utf-8'),
'Selected LS',
'Recorded'+
u' (/\u03bcb)'.encode (
'utf-8'),
'Effective '+
u' (/\u03bcb) '.encode (
'utf-8')+hltpath)]
699 totalRecordedInPath = 0.0
701 for runidx, deliveredrowdata
in enumerate (delivered):
703 rowdata += [deliveredrowdata[0], deliveredrowdata[1], deliveredrowdata[2]]
704 if deliveredrowdata[1] ==
'N/A':
705 if hltpath !=
'' and hltpath !=
'all':
706 rowdata += [
'N/A',
'N/A',
'N/A']
708 rowdata += [
'N/A',
'N/A']
709 datatable.append (rowdata)
711 totalDeliveredLS += int (deliveredrowdata[1])
712 totalDelivered += float (deliveredrowdata[2])
713 selectedls = recorded[runidx][2].
keys()
716 if len (selectedls) == 0:
719 if hltpath !=
'' and hltpath !=
'all':
720 rowdata += [selectedlsStr,
'N/A',
'N/A']
722 rowdata += [selectedlsStr,
'N/A']
724 selectedlsStr = splitlistToRangeString (selectedls)
725 recordedLumi = calculateTotalRecorded (recorded[runidx][2])
726 lumiinPaths = calculateEffective (recorded[runidx][1], recordedLumi)
727 if hltpath !=
'' and hltpath !=
'all':
728 if hltpath
in lumiinPaths:
729 rowdata += [selectedlsStr,
'%.3f'% (recordedLumi),
'%.3f'% (lumiinPaths[hltpath])]
730 totalRecordedInPath += lumiinPaths[hltpath]
732 rowdata += [selectedlsStr,
'%.3f'% (recordedLumi),
'N/A']
735 rowdata += [selectedlsStr,
'%.3f'% (recordedLumi)]
736 totalSelectedLS += len (selectedls)
737 totalRecorded += recordedLumi
738 datatable.append (rowdata)
740 if hltpath !=
'' and hltpath !=
'all':
741 totaltable = [[str (totalDeliveredLS),
'%.3f'% (totalDelivered), str (totalSelectedLS),
742 '%.3f'% (totalRecorded),
'%.3f'% (totalRecordedInPath)]]
744 totaltable = [[str (totalDeliveredLS),
'%.3f'% (totalDelivered), str (totalSelectedLS),
745 '%.3f'% (totalRecorded)]]
746 print(tablePrinter.indent (toprowlabels+datatable, hasHeader =
True, separateRows =
False, prefix =
'| ',
747 postfix =
' |', justify =
'right', delim =
' | ',
748 wrapfunc =
lambda x: wrap_onspace (x, 20)))
749 print(
' == = Total : ')
750 print(tablePrinter.indent (lastrowlabels+totaltable, hasHeader =
True, separateRows =
False, prefix =
'| ',
751 postfix =
' |', justify =
'right', delim =
' | ',
752 wrapfunc =
lambda x: wrap_onspace (x, 20)))
758 for runidx, deliveredrowdata
in enumerate (delivered):
760 rowdata += [deliveredrowdata[0], deliveredrowdata[2]]
761 if deliveredrowdata[1] ==
'N/A':
762 rowdata += [
'N/A',
'N/A']
763 datatable.append (rowdata)
765 recordedLumi = calculateTotalRecorded (recorded[runidx][2])
766 lumiinPaths = calculateEffective (recorded[runidx][1], recordedLumi)
767 if hltpath !=
'' and hltpath !=
'all':
768 if hltpath
in lumiinPaths:
769 rowdata += [recordedLumi, lumiinPaths[hltpath]]
771 rowdata += [recordedLumi,
'N/A']
773 rowdata += [recordedLumi, recordedLumi]
774 datatable.append (rowdata)
779 maxLumiSection =
None, finecorrections=
None):
780 '''Given a run number and a minimum xing luminosity value, 781 returns a dictionary (keyed by (run, lumi section)) where the 782 value is a list of tuples of (xingID, xingLum). 784 - For all xing luminosities, simply set minLumValue to 0. 786 - If you want one dictionary for several runs, pass it in to 790 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 793 runnum = int (runnum)
794 dbsession.transaction().start (
True)
795 schema = dbsession.schema (parameters.lumischema)
797 raise RuntimeError(
'cannot connect to schema '+ parameters.lumischema)
798 detailOutput = coral.AttributeList()
799 detailOutput.extend (
'startorbit',
'unsigned int')
800 detailOutput.extend (
'cmslsnum',
'unsigned int')
801 detailOutput.extend (
'bxlumivalue',
'blob')
802 detailOutput.extend (
'bxlumierror',
'blob')
803 detailOutput.extend (
'bxlumiquality',
'blob')
804 detailOutput.extend (
'algoname',
'string')
805 detailCondition = coral.AttributeList()
806 detailCondition.extend (
'runnum',
'unsigned int')
807 detailCondition.extend (
'algoname',
'string')
808 detailCondition[
'runnum'].setData (runnum)
809 detailCondition[
'algoname'].setData (
'OCC1')
810 query = schema.newQuery()
813 query.addToOutputList (
's.STARTORBIT',
'startorbit')
814 query.addToOutputList (
's.CMSLSNUM',
'cmslsnum')
815 query.addToOutputList (
'd.BXLUMIVALUE',
'bxlumivalue')
816 query.addToOutputList (
'd.BXLUMIERROR',
'bxlumierror')
817 query.addToOutputList (
'd.BXLUMIQUALITY',
'bxlumiquality')
818 query.addToOutputList (
'd.ALGONAME',
'algoname')
819 query.setCondition (
's.RUNNUM =:runnum and d.ALGONAME =:algoname and s.LUMISUMMARY_ID=d.LUMISUMMARY_ID',detailCondition)
820 query.addToOrderList (
's.CMSLSNUM')
821 query.defineOutput (detailOutput)
822 cursor = query.execute()
832 cmslsnum = cursor.currentRow()[
'cmslsnum'].
data()
833 algoname = cursor.currentRow()[
'algoname'].
data()
834 bxlumivalue = cursor.currentRow()[
'bxlumivalue'].
data()
835 startorbit = cursor.currentRow()[
'startorbit'].
data()
837 if maxLumiSection
and maxLumiSection < cmslsnum:
841 xingArray = array.array (
'f')
842 xingArray.fromstring( bxlumivalue.readline() )
846 if len(xingArray)!=0:
847 avginstlumi=sum(xingArray)
848 for index, lum
in enumerate (xingArray):
849 mynorm=parameters.normFactor
851 lum=lumiCorrections.applyfinecorrectionBX(lum,avginstlumi*mynorm,mynorm,finecorrections[0],finecorrections[1],finecorrections[2])
854 if lum < parameters.xingMinLum:
856 xingLum.append( (index, lum) )
857 lumiXingDict[ (runnum, cmslsnum) ] = xingLum
859 dbsession.transaction().commit()
861 except Exception
as e:
864 dbsession.transaction().rollback()
869 '''Given nested lists or tuples, returns a single flattened list''' 872 if hasattr (piece,
'__iter__')
and not isinstance (piece, str):
873 result.extend( flatten (piece) )
875 result.append (piece)
880 '''Given general xing information and a xingLumiDict, the xing 881 luminosity information is merged with the general information''' 882 runNumber = triplet[0]
883 deadTable = triplet[2]
884 for lumi, lumiList
in six.iteritems(deadTable):
885 key = (
int(runNumber),
int(lumi) )
886 xingLumiValues = xingLumiDict.get (key)
888 lumiList.append( flatten (xingLumiValues) )
891 def setupSession (connectString, siteconfpath, parameters, debug = False):
892 '''returns database session''' 894 connectparser.parse()
895 usedefaultfrontierconfig =
False 897 if connectparser.needsitelocalinfo():
899 cacheconfigpath = os.environ[
'CMS_PATH']
901 cacheconfigpath = os.path.join (cacheconfigpath,
'SITECONF',
'local',
'JobConfig',
'site-local-config.xml')
903 usedefaultfrontierconfig =
True 905 cacheconfigpath = siteconfpath
906 cacheconfigpath = os.path.join (cacheconfigpath,
'site-local-config.xml')
908 if usedefaultfrontierconfig:
909 ccp.parseString (parameters.defaultfrontierConfigString)
911 ccp.parse (cacheconfigpath)
912 connectString = connectparser.fullfrontierStr (connectparser.schemaname(), ccp.parameterdict())
913 svc = coral.ConnectionService()
915 msg = coral.MessageStream (
'')
916 msg.setMsgVerbosity (coral.message_Level_Debug)
917 parameters.verbose =
True 918 session = svc.connect (connectString, accessMode = coral.access_ReadOnly)
919 session.typeConverter().setCppTypeForSqlType (
"unsigned int",
"NUMBER (10)")
920 session.typeConverter().setCppTypeForSqlType (
"unsigned long long",
"NUMBER (20)")
927 def allruns(schemaHandle,requireRunsummary=True,requireLumisummary=False,requireTrg=False,requireHlt=False):
929 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. 931 if not requireRunsummary
and not requireLumiummary
and not requireTrg
and not requireHlt:
932 print(
'must require at least one table')
933 raise RuntimeError(
'one table')
937 if requireRunsummary:
939 queryHandle=schemaHandle.newQuery()
941 queryHandle.addToOutputList(
"RUNNUM",
"run")
943 result=coral.AttributeList()
944 result.extend(
"run",
"unsigned int")
945 queryHandle.defineOutput(result)
946 cursor=queryHandle.execute()
948 r=cursor.currentRow()[
'run'].
data()
951 if requireLumisummary:
953 queryHandle=schemaHandle.newQuery()
955 queryHandle.addToOutputList(
"distinct RUNNUM",
"run")
957 result=coral.AttributeList()
958 result.extend(
"run",
"unsigned int")
959 queryHandle.defineOutput(result)
960 cursor=queryHandle.execute()
962 r=cursor.currentRow()[
'run'].
data()
967 queryHandle=schemaHandle.newQuery()
969 queryHandle.addToOutputList(
"distinct RUNNUM",
"run")
971 result=coral.AttributeList()
972 result.extend(
"run",
"unsigned int")
973 queryHandle.defineOutput(result)
974 cursor=queryHandle.execute()
976 r=cursor.currentRow()[
'run'].
data()
981 queryHandle=schemaHandle.newQuery()
983 queryHandle.addToOutputList(
"distinct RUNNUM",
"run")
985 result=coral.AttributeList()
986 result.extend(
"run",
"unsigned int")
987 queryHandle.defineOutput(result)
988 cursor=queryHandle.execute()
990 r=cursor.currentRow()[
'run'].
data()
994 for dup
in dupresult:
996 runresult.append(dup[0])
1001 '''retrieve validation data per run or all 1002 input: run. if not run, retrive all; if cmslsnum selection list pesent, filter out unselected result 1003 output: {run:[[cmslsnum,status,comment]]} 1007 queryHandle.addToOutputList(
'RUNNUM',
'runnum')
1008 queryHandle.addToOutputList(
'CMSLSNUM',
'cmslsnum')
1009 queryHandle.addToOutputList(
'FLAG',
'flag')
1010 queryHandle.addToOutputList(
'COMMENT',
'comment')
1012 queryCondition=
'RUNNUM=:runnum' 1013 queryBind=coral.AttributeList()
1014 queryBind.extend(
'runnum',
'unsigned int')
1015 queryBind[
'runnum'].setData(run)
1016 queryHandle.setCondition(queryCondition,queryBind)
1017 queryResult=coral.AttributeList()
1018 queryResult.extend(
'runnum',
'unsigned int')
1019 queryResult.extend(
'cmslsnum',
'unsigned int')
1020 queryResult.extend(
'flag',
'string')
1021 queryResult.extend(
'comment',
'string')
1022 queryHandle.defineOutput(queryResult)
1023 cursor=queryHandle.execute()
1025 runnum=cursor.currentRow()[
'runnum'].
data()
1026 if runnum
not in result:
1028 cmslsnum=cursor.currentRow()[
'cmslsnum'].
data()
1029 flag=cursor.currentRow()[
'flag'].
data()
1030 comment=cursor.currentRow()[
'comment'].
data()
1031 result[runnum].
append([cmslsnum,flag,comment])
1032 if run
and cmsls
and len(cmsls)!=0:
1034 for runnum,perrundata
in result.items():
1035 for lsdata
in perrundata:
1036 if lsdata[0]
not in cmsls:
1038 if runnum
not in selectedresult:
1039 selectedresult[runnum]=[]
1040 selectedresult[runnum].
append(lsdata)
1041 return selectedresult
1046 '''select distinct fillnum from cmsrunsummary 1047 there are crazy fill numbers. we assume they are not valid runs 1051 queryHandle.addToOutputList(
'distinct FILLNUM',
'fillnum')
1054 queryCondition=
'FILLNUM>:zero and FILLNUM<:crazybig' 1055 queryBind=coral.AttributeList()
1056 queryBind.extend(
'zero',
'unsigned int')
1057 queryBind.extend(
'crazybig',
'unsigned int')
1058 queryBind[
'zero'].setData(
int(0))
1059 queryBind[
'crazybig'].setData(
int(29701))
1060 queryHandle.setCondition(queryCondition,queryBind)
1061 queryResult=coral.AttributeList()
1062 queryResult.extend(
'fillnum',
'unsigned int')
1063 queryHandle.defineOutput(queryResult)
1064 cursor=queryHandle.execute()
1066 result.append(cursor.currentRow()[
'fillnum'].
data())
1071 select fillnum,sequence,hltkey,to_char(starttime),to_char(stoptime) from cmsrunsummary where runnum=:runnum 1072 output: [fillnum,sequence,hltkey,starttime,stoptime] 1077 queryCondition=coral.AttributeList()
1078 queryCondition.extend(
'runnum',
'unsigned int')
1079 queryCondition[
'runnum'].setData(
int(runnum))
1080 queryHandle.addToOutputList(
'FILLNUM',
'fillnum')
1081 queryHandle.addToOutputList(
'SEQUENCE',
'sequence')
1082 queryHandle.addToOutputList(
'HLTKEY',
'hltkey')
1083 queryHandle.addToOutputList(
'to_char(STARTTIME,\''+t.coraltimefm+
'\')',
'starttime')
1084 queryHandle.addToOutputList(
'to_char(STOPTIME,\''+t.coraltimefm+
'\')',
'stoptime')
1085 queryHandle.setCondition(
'RUNNUM=:runnum',queryCondition)
1086 queryResult=coral.AttributeList()
1087 queryResult.extend(
'fillnum',
'unsigned int')
1088 queryResult.extend(
'sequence',
'string')
1089 queryResult.extend(
'hltkey',
'string')
1090 queryResult.extend(
'starttime',
'string')
1091 queryResult.extend(
'stoptime',
'string')
1092 queryHandle.defineOutput(queryResult)
1093 cursor=queryHandle.execute()
1095 result.append(cursor.currentRow()[
'fillnum'].
data())
1096 result.append(cursor.currentRow()[
'sequence'].
data())
1097 result.append(cursor.currentRow()[
'hltkey'].
data())
1098 result.append(cursor.currentRow()[
'starttime'].
data())
1099 result.append(cursor.currentRow()[
'stoptime'].
data())
1105 def lumisummaryByrun(queryHandle,runnum,lumiversion,beamstatus=None,beamenergy=None,beamenergyfluctuation=0.09,finecorrections=None):
1107 one can impose beamstatus, beamenergy selections at the SQL query level or process them later from the general result 1108 select cmslsnum,instlumi,numorbit,startorbit,beamstatus,beamenery from lumisummary where runnum=:runnum and lumiversion=:lumiversion order by startorbit; 1109 output: [[cmslsnum,instlumi,numorbit,startorbit,beamstatus,beamenergy,cmsalive]] 1110 Note: the non-cmsalive LS are included in the result 1114 queryCondition=coral.AttributeList()
1115 queryCondition.extend(
'runnum',
'unsigned int')
1116 queryCondition.extend(
'lumiversion',
'string')
1117 conditionstring=
'RUNNUM=:runnum and LUMIVERSION=:lumiversion' 1118 queryCondition[
'runnum'].setData(
int(runnum))
1119 queryCondition[
'lumiversion'].setData(lumiversion)
1120 queryHandle.addToOutputList(
'CMSLSNUM',
'cmslsnum')
1121 queryHandle.addToOutputList(
'INSTLUMI',
'instlumi')
1122 queryHandle.addToOutputList(
'NUMORBIT',
'numorbit')
1123 queryHandle.addToOutputList(
'STARTORBIT',
'startorbit')
1124 queryHandle.addToOutputList(
'BEAMSTATUS',
'beamstatus')
1125 queryHandle.addToOutputList(
'BEAMENERGY',
'beamenergy')
1126 queryHandle.addToOutputList(
'CMSALIVE',
'cmsalive')
1127 if beamstatus
and len(beamstatus)!=0:
1128 conditionstring=conditionstring+
' and BEAMSTATUS=:beamstatus' 1129 queryCondition.extend(
'beamstatus',
'string')
1130 queryCondition[
'beamstatus'].setData(beamstatus)
1132 minBeamenergy=
float(beamenergy*(1.0-beamenergyfluctuation))
1133 maxBeamenergy=
float(beamenergy*(1.0+beamenergyfluctuation))
1134 conditionstring=conditionstring+
' and BEAMENERGY>:minBeamenergy and BEAMENERGY<:maxBeamenergy' 1135 queryCondition.extend(
'minBeamenergy',
'float')
1136 queryCondition.extend(
'maxBeamenergy',
'float')
1137 queryCondition[
'minBeamenergy'].setData(
float(minBeamenergy))
1138 queryCondition[
'maxBeamenergy'].setData(
float(maxBeamenergy))
1139 queryResult=coral.AttributeList()
1140 queryResult.extend(
'cmslsnum',
'unsigned int')
1141 queryResult.extend(
'instlumi',
'float')
1142 queryResult.extend(
'numorbit',
'unsigned int')
1143 queryResult.extend(
'startorbit',
'unsigned int')
1144 queryResult.extend(
'beamstatus',
'string')
1145 queryResult.extend(
'beamenergy',
'float')
1146 queryResult.extend(
'cmsalive',
'unsigned int')
1147 queryHandle.defineOutput(queryResult)
1148 queryHandle.setCondition(conditionstring,queryCondition)
1149 queryHandle.addToOrderList(
'startorbit')
1150 cursor=queryHandle.execute()
1152 cmslsnum=cursor.currentRow()[
'cmslsnum'].
data()
1153 instlumi=cursor.currentRow()[
'instlumi'].
data()
1155 instlumi=lumiCorrections.applyfinecorrection(instlumi,finecorrections[0],finecorrections[1],finecorrections[2])
1156 numorbit=cursor.currentRow()[
'numorbit'].
data()
1157 startorbit=cursor.currentRow()[
'startorbit'].
data()
1158 beamstatus=cursor.currentRow()[
'beamstatus'].
data()
1159 beamenergy=cursor.currentRow()[
'beamenergy'].
data()
1160 cmsalive=cursor.currentRow()[
'cmsalive'].
data()
1161 result.append([cmslsnum,instlumi,numorbit,startorbit,beamstatus,beamenergy,cmsalive])
1164 def lumisumByrun(queryHandle,runnum,lumiversion,beamstatus=None,beamenergy=None,beamenergyfluctuation=0.09,finecorrections=None):
1166 beamenergy unit : GeV 1167 beamenergyfluctuation : fraction allowed to fluctuate around beamenergy value 1168 select instlumi from lumisummary where runnum=:runnum and lumiversion=:lumiversion 1169 output: float sum(instlumi) 1170 Note: the output is the raw result, need to apply LS length in time(sec) 1174 queryCondition=coral.AttributeList()
1175 queryCondition.extend(
'runnum',
'unsigned int')
1176 queryCondition.extend(
'lumiversion',
'string')
1178 queryCondition[
'runnum'].setData(
int(runnum))
1179 queryCondition[
'lumiversion'].setData(lumiversion)
1180 queryHandle.addToOutputList(
'INSTLUMI',
'instlumi')
1181 conditionstring=
'RUNNUM=:runnum and LUMIVERSION=:lumiversion' 1182 if beamstatus
and len(beamstatus)!=0:
1183 conditionstring=conditionstring+
' and BEAMSTATUS=:beamstatus' 1184 queryCondition.extend(
'beamstatus',
'string')
1185 queryCondition[
'beamstatus'].setData(beamstatus)
1186 if beamenergy
and beamenergy!=0.0:
1187 minBeamenergy=
float(beamenergy*(1.0-beamenergyfluctuation))
1188 maxBeamenergy=
float(beamenergy*(1.0+beamenergyfluctuation))
1189 conditionstring=conditionstring+
' and BEAMENERGY>:minBeamenergy and BEAMENERGY<:maxBeamenergy' 1190 queryCondition.extend(
'minBeamenergy',
'float')
1191 queryCondition.extend(
'maxBeamenergy',
'float')
1192 queryCondition[
'minBeamenergy'].setData(
float(minBeamenergy))
1193 queryCondition[
'maxBeamenergy'].setData(
float(maxBeamenergy))
1194 queryHandle.setCondition(conditionstring,queryCondition)
1195 queryResult=coral.AttributeList()
1196 queryResult.extend(
'instlumi',
'float')
1197 queryHandle.defineOutput(queryResult)
1198 cursor=queryHandle.execute()
1200 instlumi=cursor.currentRow()[
'instlumi'].
data()
1203 instlumi=lumiCorrections.applyfinecorrection(instlumi,finecorrections[0],finecorrections[1],finecorrections[2])
1204 result.append(instlumi)
1212 select cmslsnum,trgcount,deadtime,bitname,prescale from trg where runnum=:runnum and bitnum=0; 1213 output: {cmslsnum:[trgcount,deadtime,bitname,prescale]} 1217 queryCondition=coral.AttributeList()
1218 queryCondition.extend(
'runnum',
'unsigned int')
1219 queryCondition.extend(
'bitnum',
'unsigned int')
1220 queryCondition[
'runnum'].setData(
int(runnum))
1221 queryCondition[
'bitnum'].setData(
int(0))
1222 queryHandle.addToOutputList(
'CMSLSNUM',
'cmslsnum')
1223 queryHandle.addToOutputList(
'TRGCOUNT',
'trgcount')
1224 queryHandle.addToOutputList(
'DEADTIME',
'deadtime')
1225 queryHandle.addToOutputList(
'BITNAME',
'bitname')
1226 queryHandle.addToOutputList(
'PRESCALE',
'prescale')
1227 queryHandle.setCondition(
'RUNNUM=:runnum and BITNUM=:bitnum',queryCondition)
1228 queryResult=coral.AttributeList()
1229 queryResult.extend(
'cmslsnum',
'unsigned int')
1230 queryResult.extend(
'trgcount',
'unsigned int')
1231 queryResult.extend(
'deadtime',
'unsigned int')
1232 queryResult.extend(
'bitname',
'string')
1233 queryResult.extend(
'prescale',
'unsigned int')
1234 queryHandle.defineOutput(queryResult)
1235 cursor=queryHandle.execute()
1237 cmslsnum=cursor.currentRow()[
'cmslsnum'].
data()
1238 trgcount=cursor.currentRow()[
'trgcount'].
data()
1239 deadtime=cursor.currentRow()[
'deadtime'].
data()
1240 bitname=cursor.currentRow()[
'bitname'].
data()
1241 prescale=cursor.currentRow()[
'prescale'].
data()
1242 if cmslsnum
not in result:
1243 result[cmslsnum]=[trgcount,deadtime,bitname,prescale]
1248 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; 1249 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. 1250 output: {cmslsnum:[instlumi,numorbit,startorbit,beamstatus,beamenergy,bitzerocount,deadtime,bitname,prescale]} 1251 Note: only cmsalive LS are included in the result. Therefore, this function cannot be used for calculating delivered! 1256 queryCondition=coral.AttributeList()
1257 queryCondition.extend(
'bitnum',
'unsigned int')
1258 queryCondition.extend(
'runnum',
'unsigned int')
1259 queryCondition.extend(
'lumiversion',
'string')
1260 queryCondition[
'bitnum'].setData(
int(0))
1261 queryCondition[
'runnum'].setData(
int(runnum))
1262 queryCondition[
'lumiversion'].setData(lumiversion)
1264 queryHandle.addToOutputList(
'l.CMSLSNUM',
'cmslsnum')
1265 queryHandle.addToOutputList(
'l.INSTLUMI',
'instlumi')
1266 queryHandle.addToOutputList(
'l.NUMORBIT',
'numorbit')
1267 queryHandle.addToOutputList(
'l.STARTORBIT',
'startorbit')
1268 queryHandle.addToOutputList(
'l.BEAMSTATUS',
'beamstatus')
1269 queryHandle.addToOutputList(
'l.BEAMENERGY',
'beamenergy')
1270 queryHandle.addToOutputList(
't.TRGCOUNT',
'trgcount')
1271 queryHandle.addToOutputList(
't.DEADTIME',
'deadtime')
1272 queryHandle.addToOutputList(
't.BITNAME',
'bitname')
1273 queryHandle.addToOutputList(
't.PRESCALE',
'prescale')
1274 conditionstring=
't.BITNUM=:bitnum and l.RUNNUM=:runnum and l.LUMIVERSION=:lumiversion and l.RUNNUM=t.RUNNUM and t.CMSLSNUM=l.CMSLSNUM' 1275 if beamstatus
and len(beamstatus)!=0:
1276 conditionstring=conditionstring+
' and l.BEAMSTATUS=:beamstatus' 1277 queryCondition.extend(
'beamstatus',
'string')
1278 queryCondition[
'beamstatus'].setData(beamstatus)
1279 if beamenergy
and beamenergy!=0.0:
1280 minBeamenergy=
float(beamenergy*(1-beamenergyfluctuation))
1281 maxBeamenergy=
float(beamenergy*(1+beamenergyfluctuation))
1282 conditionstring=conditionstring+
' and l.BEAMENERGY>:minBeamenergy and l.BEAMENERGY<:maxBeamenergy' 1283 queryCondition.extend(
'minBeamenergy',
'float')
1284 queryCondition.extend(
'maxBeamenergy',
'float')
1285 queryCondition[
'minBeamenergy'].setData(
float(minBeamenergy))
1286 queryCondition[
'maxBeamenergy'].setData(
float(maxBeamenergy))
1287 queryHandle.setCondition(conditionstring,queryCondition)
1288 queryResult=coral.AttributeList()
1289 queryResult.extend(
'cmslsnum',
'unsigned int')
1290 queryResult.extend(
'instlumi',
'float')
1291 queryResult.extend(
'numorbit',
'unsigned int')
1292 queryResult.extend(
'startorbit',
'unsigned int')
1293 queryResult.extend(
'beamstatus',
'string')
1294 queryResult.extend(
'beamenergy',
'float')
1295 queryResult.extend(
'trgcount',
'unsigned int')
1296 queryResult.extend(
'deadtime',
'unsigned int')
1297 queryResult.extend(
'bitname',
'string')
1298 queryResult.extend(
'prescale',
'unsigned int')
1299 queryHandle.defineOutput(queryResult)
1300 cursor=queryHandle.execute()
1302 cmslsnum=cursor.currentRow()[
'cmslsnum'].
data()
1303 instlumi=cursor.currentRow()[
'instlumi'].
data()
1305 instlumi=lumiCorrections.applyfinecorrection(instlumi,finecorrections[0],finecorrections[1],finecorrections[2])
1306 numorbit=cursor.currentRow()[
'numorbit'].
data()
1307 startorbit=cursor.currentRow()[
'startorbit'].
data()
1308 beamstatus=cursor.currentRow()[
'beamstatus'].
data()
1309 beamenergy=cursor.currentRow()[
'beamenergy'].
data()
1310 trgcount=cursor.currentRow()[
'trgcount'].
data()
1311 deadtime=cursor.currentRow()[
'deadtime'].
data()
1312 bitname=cursor.currentRow()[
'bitname'].
data()
1313 prescale=cursor.currentRow()[
'prescale'].
data()
1314 if cmslsnum
not in result:
1315 result[cmslsnum]=[instlumi,numorbit,startorbit,beamstatus,beamenergy,trgcount,deadtime,bitname,prescale]
1320 select cmslsnum,trgcount,deadtime,bitnum,prescale from trg where runnum=:runnum and bitname=:bitname; 1321 output: {cmslsnum:[trgcount,deadtime,bitnum,prescale]} 1325 queryCondition=coral.AttributeList()
1326 queryCondition.extend(
'runnum',
'unsigned int')
1327 queryCondition.extend(
'bitname',
'string')
1328 queryCondition[
'runnum'].setData(
int(runnum))
1329 queryCondition[
'bitname'].setData(bitname)
1330 queryHandle.addToOutputList(
'CMSLSNUM',
'cmslsnum')
1331 queryHandle.addToOutputList(
'TRGCOUNT',
'trgcount')
1332 queryHandle.addToOutputList(
'DEADTIME',
'deadtime')
1333 queryHandle.addToOutputList(
'BITNUM',
'bitnum')
1334 queryHandle.addToOutputList(
'PRESCALE',
'prescale')
1335 queryHandle.setCondition(
'RUNNUM=:runnum and BITNAME=:bitname',queryCondition)
1336 queryResult=coral.AttributeList()
1337 queryResult.extend(
'cmslsnum',
'unsigned int')
1338 queryResult.extend(
'trgcount',
'unsigned int')
1339 queryResult.extend(
'deadtime',
'unsigned long long')
1340 queryResult.extend(
'bitnum',
'unsigned int')
1341 queryResult.extend(
'prescale',
'unsigned int')
1342 queryHandle.defineOutput(queryResult)
1343 cursor=queryHandle.execute()
1345 cmslsnum=cursor.currentRow()[
'cmslsnum'].
data()
1346 trgcount=cursor.currentRow()[
'trgcount'].
data()
1347 deadtime=cursor.currentRow()[
'deadtime'].
data()
1348 bitnum=cursor.currentRow()[
'bitnum'].
data()
1349 prescale=cursor.currentRow()[
'prescale'].
data()
1350 if cmslsnum
not in result:
1351 result[cmslsnum]=[trgcount,deadtime,bitnum,prescale]
1356 all you ever want to know about trigger 1357 select cmslsnum,trgcount,deadtime,bitnum,bitname,prescale from trg where runnum=:runnum order by bitnum,cmslsnum 1358 this can be changed to blob query later 1359 output: {cmslsnum:{bitname:[bitnum,trgcount,deadtime,prescale]}} 1363 queryCondition=coral.AttributeList()
1364 queryCondition.extend(
'runnum',
'unsigned int')
1365 queryCondition[
'runnum'].setData(
int(runnum))
1366 queryHandle.addToOutputList(
'cmslsnum')
1367 queryHandle.addToOutputList(
'trgcount')
1368 queryHandle.addToOutputList(
'deadtime')
1369 queryHandle.addToOutputList(
'bitnum')
1370 queryHandle.addToOutputList(
'bitname')
1371 queryHandle.addToOutputList(
'prescale')
1372 queryHandle.setCondition(
'runnum=:runnum',queryCondition)
1373 queryResult=coral.AttributeList()
1374 queryResult.extend(
'cmslsnum',
'unsigned int')
1375 queryResult.extend(
'trgcount',
'unsigned int')
1376 queryResult.extend(
'deadtime',
'unsigned long long')
1377 queryResult.extend(
'bitnum',
'unsigned int')
1378 queryResult.extend(
'bitname',
'string')
1379 queryResult.extend(
'prescale',
'unsigned int')
1380 queryHandle.defineOutput(queryResult)
1381 queryHandle.addToOrderList(
'bitnum')
1382 queryHandle.addToOrderList(
'cmslsnum')
1383 cursor=queryHandle.execute()
1385 cmslsnum=cursor.currentRow()[
'cmslsnum'].
data()
1386 trgcount=cursor.currentRow()[
'trgcount'].
data()
1387 deadtime=cursor.currentRow()[
'deadtime'].
data()
1388 bitnum=cursor.currentRow()[
'bitnum'].
data()
1389 bitname=cursor.currentRow()[
'bitname'].
data()
1390 prescale=cursor.currentRow()[
'prescale'].
data()
1391 if cmslsnum
not in result:
1393 dataperLS[bitname]=[bitnum,trgcount,deadtime,prescale]
1394 result[cmslsnum]=dataperLS
1396 result[cmslsnum][bitname]=[bitnum,trgcount,deadtime,prescale]
1402 select cmslsnum,inputcount,acceptcount,prescale from hlt where runnum=:runnum and pathname=:pathname 1403 output: {cmslsnum:[inputcount,acceptcount,prescale]} 1407 queryCondition=coral.AttributeList()
1408 queryCondition.extend(
'runnum',
'unsigned int')
1409 queryCondition.extend(
'pathname',
'string')
1410 queryCondition[
'runnum'].setData(
int(runnum))
1411 queryCondition[
'pathname'].setData(hltpath)
1412 queryHandle.addToOutputList(
'CMSLSNUM',
'cmslsnum')
1413 queryHandle.addToOutputList(
'INPUTCOUNT',
'inputcount')
1414 queryHandle.addToOutputList(
'ACCEPTCOUNT',
'acceptcount')
1415 queryHandle.addToOutputList(
'PRESCALE',
'prescale')
1416 queryHandle.setCondition(
'RUNNUM=:runnum and PATHNAME=:pathname',queryCondition)
1417 queryResult=coral.AttributeList()
1418 queryResult.extend(
'cmslsnum',
'unsigned int')
1419 queryResult.extend(
'inputcount',
'unsigned int')
1420 queryResult.extend(
'acceptcount',
'unsigned int')
1421 queryResult.extend(
'prescale',
'unsigned int')
1422 queryHandle.defineOutput(queryResult)
1423 cursor=queryHandle.execute()
1425 cmslsnum=cursor.currentRow()[
'cmslsnum'].
data()
1426 inputcount=cursor.currentRow()[
'inputcount'].
data()
1427 acceptcount=cursor.currentRow()[
'acceptcount'].
data()
1428 prescale=cursor.currentRow()[
'prescale'].
data()
1429 if cmslsnum
not in result:
1430 result[cmslsnum]=[inputcount,acceptcount,prescale]
1435 select cmslsnum,inputcount,acceptcount,prescale,pathname from hlt where runnum=:runnum 1436 this can be changed to blob query later 1437 output: {cmslsnum:{pathname:[inputcount,acceptcount,prescale]}} 1441 queryCondition=coral.AttributeList()
1442 queryCondition.extend(
'runnum',
'unsigned int')
1443 queryCondition[
'runnum'].setData(
int(runnum))
1444 queryHandle.addToOutputList(
'CMSLSNUM',
'cmslsnum')
1445 queryHandle.addToOutputList(
'INPUTCOUNT',
'inputcount')
1446 queryHandle.addToOutputList(
'ACCEPTCOUNT',
'acceptcount')
1447 queryHandle.addToOutputList(
'PRESCALE',
'prescale')
1448 queryHandle.addToOutputList(
'PATHNAME',
'pathname')
1449 queryHandle.setCondition(
'RUNNUM=:runnum',queryCondition)
1450 queryResult=coral.AttributeList()
1451 queryResult.extend(
'cmslsnum',
'unsigned int')
1452 queryResult.extend(
'inputcount',
'unsigned int')
1453 queryResult.extend(
'acceptcount',
'unsigned int')
1454 queryResult.extend(
'prescale',
'unsigned int')
1455 queryResult.extend(
'pathname',
'string')
1456 queryHandle.defineOutput(queryResult)
1457 cursor=queryHandle.execute()
1459 cmslsnum=cursor.currentRow()[
'cmslsnum'].
data()
1460 inputcount=cursor.currentRow()[
'inputcount'].
data()
1461 acceptcount=cursor.currentRow()[
'acceptcount'].
data()
1462 prescale=cursor.currentRow()[
'prescale'].
data()
1463 pathname=cursor.currentRow()[
'pathname'].
data()
1464 if cmslsnum
not in result:
1466 dataperLS[pathname]=[inputcount,acceptcount,prescale]
1467 result[cmslsnum]=dataperLS
1469 result[cmslsnum][pathname]=[inputcount,acceptcount,prescale]
1475 select CMSBXINDEXBLOB,BEAMINTENSITYBLOB_1,BEAMINTENSITYBLOB_2 from LUMISUMMARY where runnum=146315 and LUMIVERSION='0001' 1477 output : result {startorbit: [(bxidx,beam1intensity,beam2intensity)]} 1481 lumisummaryOutput=coral.AttributeList()
1482 lumisummaryOutput.extend(
'cmslsnum',
'unsigned int')
1483 lumisummaryOutput.extend(
'startorbit',
'unsigned int')
1484 lumisummaryOutput.extend(
'bxindexblob',
'blob');
1485 lumisummaryOutput.extend(
'beamintensityblob1',
'blob');
1486 lumisummaryOutput.extend(
'beamintensityblob2',
'blob');
1487 condition=coral.AttributeList()
1488 condition.extend(
'runnum',
'unsigned int')
1489 condition.extend(
'lumiversion',
'string')
1490 condition[
'runnum'].setData(
int(runnum))
1491 condition[
'lumiversion'].setData(parameters.lumiversion)
1493 query.addToTableList(parameters.lumisummaryname)
1494 query.addToOutputList(
'CMSLSNUM',
'cmslsnum')
1495 query.addToOutputList(
'STARTORBIT',
'startorbit')
1496 query.addToOutputList(
'CMSBXINDEXBLOB',
'bxindexblob')
1497 query.addToOutputList(
'BEAMINTENSITYBLOB_1',
'beamintensityblob1')
1498 query.addToOutputList(
'BEAMINTENSITYBLOB_2',
'beamintensityblob2')
1499 query.setCondition(
'RUNNUM=:runnum AND LUMIVERSION=:lumiversion',condition)
1500 query.defineOutput(lumisummaryOutput)
1501 cursor=query.execute()
1504 startorbit=cursor.currentRow()[
'startorbit'].
data()
1509 beamintensityblob1=
None 1510 beamintensityblob2=
None 1511 if not cursor.currentRow()[
"bxindexblob"].isNull():
1512 bxindexblob=cursor.currentRow()[
'bxindexblob'].
data()
1513 if bxindexblob
and bxindexblob.readline()!=
None:
1515 if not cursor.currentRow()[
'beamintensityblob1'].isNull():
1516 beamintensityblob1=cursor.currentRow()[
'beamintensityblob1'].
data()
1517 if beamintensityblob1
and beamintensityblob1.readline()!=
None:
1519 if not cursor.currentRow()[
'beamintensityblob2'].isNull():
1520 beamintensityblob2=cursor.currentRow()[
'beamintensityblob2'].
data()
1521 if beamintensityblob2
and beamintensityblob2.readline()!=
None:
1523 if startorbit
not in result:
1524 result[startorbit]=[]
1525 for idx,bxidxvalue
in enumerate(bxidx):
1527 b1intensity=bb1[idx]
1531 b2intensity=bb2[idx]
1534 result[startorbit].
append((bxidxvalue,b1intensity,b2intensity))
1542 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 1543 result={(startorbit,cmslsnum):[(index,lumivalue,lumierr),]} 1546 detailOutput=coral.AttributeList()
1547 detailOutput.extend(
'cmslsnum',
'unsigned int')
1548 detailOutput.extend(
'startorbit',
'unsigned int')
1549 detailOutput.extend(
'bxlumivalue',
'blob')
1550 detailOutput.extend(
'bxlumierror',
'blob')
1551 detailCondition=coral.AttributeList()
1552 detailCondition.extend(
'runnum',
'unsigned int')
1553 detailCondition.extend(
'algoname',
'string')
1554 detailCondition[
'runnum'].setData(runnum)
1555 detailCondition[
'algoname'].setData(algoname)
1557 query.addToTableList(parameters.lumisummaryname,
's')
1558 query.addToTableList(parameters.lumidetailname,
'd')
1559 query.addToOutputList(
's.CMSLSNUM',
'cmslsnum')
1560 query.addToOutputList(
's.STARTORBIT',
'startorbit')
1561 query.addToOutputList(
'd.BXLUMIVALUE',
'bxlumivalue')
1562 query.addToOutputList(
'd.BXLUMIERROR',
'bxlumierror')
1563 query.addToOutputList(
'd.BXLUMIQUALITY',
'bxlumiquality')
1564 query.setCondition(
's.RUNNUM=:runnum and d.ALGONAME=:algoname and s.LUMISUMMARY_ID=d.LUMISUMMARY_ID',detailCondition)
1565 query.defineOutput(detailOutput)
1566 cursor=query.execute()
1568 cmslsnum=cursor.currentRow()[
'cmslsnum'].
data()
1569 bxlumivalue=cursor.currentRow()[
'bxlumivalue'].
data()
1570 bxlumierror=cursor.currentRow()[
'bxlumierror'].
data()
1571 startorbit=cursor.currentRow()[
'startorbit'].
data()
1572 bxlumivalueArray=array.array(
'f')
1573 bxlumivalueArray.fromstring(bxlumivalue.readline())
1574 bxlumierrorArray=array.array(
'f')
1575 bxlumierrorArray.fromstring(bxlumierror.readline())
1579 if len(bxlumivalueArray)!=0:
1580 maxlumi=
max(bxlumivalueArray)
1582 if len(bxlumivalueArray)!=0:
1583 avginstlumi=sum(bxlumivalueArray)
1584 for index,lum
in enumerate(bxlumivalueArray):
1585 lumierror = bxlumierrorArray[index]
1586 if lum<
max(parameters.xingMinLum,maxlumi*0.2):
1588 mynorm=parameters.normFactor
1590 lum=lumiCorrections.applyfinecorrectionBX(lum,avginstlumi*mynorm,mynorm,finecorrection[0],finecorrection[1],finecorrection[2])
1591 lumierror=lumiCorrections.applyfinecorrectionBX(lumierror,avginstlumi*mynorm,mynorm,finecorrection[0],finecorrection[1],finecorrection[2])
1595 xingLum.append( (index,lum,lumierror) )
1597 result[(startorbit,cmslsnum)]=xingLum
1602 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 1603 output: [[cmslsnum,bxlumivalue,bxlumierror,bxlumiquality,startorbit]] 1604 since the output is ordered by time, it has to be in seq list format 1609 queryCondition=coral.AttributeList()
1610 queryCondition.extend(
'runnum',
'unsigned int')
1611 queryCondition.extend(
'algoname',
'string')
1612 queryCondition[
'runnum'].setData(
int(runnum))
1613 queryCondition[
'algoname'].setData(algoname)
1614 queryHandle.addToOutputList(
's.CMSLSNUM',
'cmslsnum')
1615 queryHandle.addToOutputList(
'd.BXLUMIVALUE',
'bxlumivalue')
1616 queryHandle.addToOutputList(
'd.BXLUMIERROR',
'bxlumierror')
1617 queryHandle.addToOutputList(
'd.BXLUMIQUALITY',
'bxlumiquality')
1618 queryHandle.addToOutputList(
's.STARTORBIT',
'startorbit')
1619 queryHandle.setCondition(
's.runnum=:runnum and d.algoname=:algoname and s.lumisummary_id=d.lumisummary_id',queryCondition)
1620 queryResult=coral.AttributeList()
1621 queryResult.extend(
'cmslsnum',
'unsigned int')
1622 queryResult.extend(
'bxlumivalue',
'blob')
1623 queryResult.extend(
'bxlumierror',
'blob')
1624 queryResult.extend(
'bxlumiquality',
'blob')
1625 queryResult.extend(
'startorbit',
'unsigned int')
1626 queryHandle.addToOrderList(
's.STARTORBIT')
1627 queryHandle.defineOutput(queryResult)
1628 cursor=queryHandle.execute()
1630 cmslsnum=cursor.currentRow()[
'cmslsnum'].
data()
1631 bxlumivalue=cursor.currentRow()[
'bxlumivalue'].
data()
1632 bxlumierror=cursor.currentRow()[
'bxlumierror'].
data()
1633 bxlumiquality=cursor.currentRow()[
'bxlumiquality'].
data()
1634 startorbit=cursor.currentRow()[
'startorbit'].
data()
1635 result.append([cmslsnum,bxlumivalue,bxlumierror,bxlumiquality,startorbit])
1640 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 1641 output: {algoname:{cmslsnum:[bxlumivalue,bxlumierror,bxlumiquality,startorbit]}} 1646 queryCondition=coral.AttributeList()
1647 queryCondition.extend(
'runnum',
'unsigned int')
1648 queryCondition[
'runnum'].setData(
int(runnum))
1649 queryHandle.addToOutputList(
's.CMSLSNUM',
'cmslsnum')
1650 queryHandle.addToOutputList(
'd.BXLUMIVALUE',
'bxlumivalue')
1651 queryHandle.addToOutputList(
'd.BXLUMIERROR',
'bxlumierror')
1652 queryHandle.addToOutputList(
'd.BXLUMIQUALITY',
'bxlumiquality')
1653 queryHandle.addToOutputList(
'd.ALGONAME',
'algoname')
1654 queryHandle.addToOutputList(
's.STARTORBIT',
'startorbit')
1655 queryHandle.setCondition(
's.RUNNUM=:runnum and s.LUMISUMMARY_ID=d.LUMISUMMARY_ID',queryCondition)
1656 queryResult=coral.AttributeList()
1657 queryResult.extend(
'cmslsnum',
'unsigned int')
1658 queryResult.extend(
'bxlumivalue',
'blob')
1659 queryResult.extend(
'bxlumierror',
'blob')
1660 queryResult.extend(
'bxlumiquality',
'blob')
1661 queryResult.extend(
'algoname',
'string')
1662 queryResult.extend(
'startorbit',
'unsigned int')
1663 queryHandle.addToOrderList(
'startorbit')
1664 queryHandle.addToOrderList(
'algoname')
1665 queryHandle.defineOutput(queryResult)
1666 cursor=queryHandle.execute()
1668 cmslsnum=cursor.currentRow()[
'cmslsnum'].
data()
1669 bxlumivalue=cursor.currentRow()[
'bxlumivalue'].
data()
1670 bxlumierror=cursor.currentRow()[
'bxlumierror'].
data()
1671 bxlumiquality=cursor.currentRow()[
'bxlumiquality'].
data()
1672 algoname=cursor.currentRow()[
'algoname'].
data()
1673 startorbit=cursor.currentRow()[
'startorbit'].
data()
1674 if algoname
not in result:
1676 dataPerAlgo[cmslsnum]=[bxlumivalue,bxlumierror,bxlumiquality,startorbit]
1677 result[algoname]=dataPerAlgo
1679 result[algoname][cmslsnum]=[bxlumivalue,bxlumierror,bxlumiquality,startorbit]
1684 select m.hltpathname,m.l1seed from cmsrunsummary r,trghltmap m where r.runnum=:runnum and m.hltkey=r.hltkey 1685 output: {hltpath:l1seed} 1690 queryCondition=coral.AttributeList()
1691 queryCondition.extend(
'runnum',
'unsigned int')
1692 queryCondition[
'runnum'].setData(
int(runnum))
1693 queryHandle.addToOutputList(
'm.HLTPATHNAME',
'hltpathname')
1694 queryHandle.addToOutputList(
'm.L1SEED',
'l1seed')
1695 queryHandle.setCondition(
'r.RUNNUM=:runnum and m.HLTKEY=r.HLTKEY',queryCondition)
1696 queryResult=coral.AttributeList()
1697 queryResult.extend(
'hltpathname',
'string')
1698 queryResult.extend(
'l1seed',
'string')
1699 queryHandle.defineOutput(queryResult)
1700 cursor=queryHandle.execute()
1702 hltpathname=cursor.currentRow()[
'hltpathname'].
data()
1703 l1seed=cursor.currentRow()[
'l1seed'].
data()
1704 if hltpathname
not in result:
1705 result[hltpathname]=l1seed
1710 find all runs in the fill range inclusive 1711 select runnum,fillnum from cmsrunsummary where fillnum>=:minFill and fillnum<=:maxFill 1712 output: fillDict={fillnum:[runlist]} 1716 queryCondition=coral.AttributeList()
1717 queryCondition.extend(
'minFill',
'unsigned int')
1718 queryCondition.extend(
'maxFill',
'unsigned int')
1719 queryCondition[
'minFill'].setData(
int(minFill))
1720 queryCondition[
'maxFill'].setData(
int(maxFill))
1721 queryHandle.addToOutputList(
'RUNNUM',
'runnum')
1722 queryHandle.addToOutputList(
'FILLNUM',
'fillnum')
1723 queryHandle.setCondition(
'FILLNUM>=:minFill and FILLNUM<=:maxFill',queryCondition)
1724 queryResult=coral.AttributeList()
1725 queryResult.extend(
'runnum',
'unsigned int')
1726 queryResult.extend(
'fillnum',
'unsigned int')
1727 queryHandle.defineOutput(queryResult)
1728 cursor=queryHandle.execute()
1730 runnum=cursor.currentRow()[
'runnum'].
data()
1731 fillnum=cursor.currentRow()[
'fillnum'].
data()
1732 if fillnum
not in result:
1733 result[fillnum]=[runnum]
1735 result[fillnum].
append(runnum)
1740 find all runs in the time range inclusive 1741 the selected run must have started after minTime and finished by maxTime 1742 select runnum,to_char(startTime),to_char(stopTime) from cmsrunsummary where startTime>=timestamp(minTime) and stopTime<=timestamp(maxTime); 1743 input: minTime,maxTime in python obj datetime.datetime 1744 output: {runnum:[starttime,stoptime]} return in python obj datetime.datetime 1748 coralminTime=coral.TimeStamp(minTime.year,minTime.month,minTime.day,minTime.hour,minTime.minute,minTime.second,0)
1749 coralmaxTime=coral.TimeStamp(maxTime.year,maxTime.month,maxTime.day,maxTime.hour,maxTime.minute,maxTime.second,0)
1751 queryCondition=coral.AttributeList()
1752 queryCondition.extend(
'minTime',
'time stamp')
1753 queryCondition.extend(
'maxTime',
'time stamp')
1754 queryCondition[
'minTime'].setData(coralminTime)
1755 queryCondition[
'maxTime'].setData(coralmaxTime)
1756 queryHandle.addToOutputList(
'RUNNUM',
'runnum')
1757 queryHandle.addToOutputList(
'TO_CHAR(STARTTIME,\''+t.coraltimefm+
'\')',
'starttime')
1758 queryHandle.addToOutputList(
'TO_CHAR(STOPTIME,\''+t.coraltimefm+
'\')',
'stoptime')
1759 queryHandle.setCondition(
'STARTTIME>=:minTime and STOPTIME<=:maxTime',queryCondition)
1760 queryResult=coral.AttributeList()
1761 queryResult.extend(
'runnum',
'unsigned int')
1762 queryResult.extend(
'starttime',
'string')
1763 queryResult.extend(
'stoptime',
'string')
1764 queryHandle.defineOutput(queryResult)
1765 cursor=queryHandle.execute()
1767 runnum=cursor.currentRow()[
'runnum'].
data()
1768 starttimeStr=cursor.currentRow()[
'starttime'].
data()
1769 stoptimeStr=cursor.currentRow()[
'stoptime'].
data()
1770 if runnum
not in result:
1771 result[runnum]=[t.StrToDatetime(starttimeStr),t.StrToDatetime(stoptimeStr)]
1774 if __name__==
'__main__':
1775 msg=coral.MessageStream(
'')
1777 msg.setMsgVerbosity(coral.message_Level_Error)
1778 os.environ[
'CORAL_AUTH_PATH']=
'/afs/cern.ch/cms/DB/lumi' 1779 svc = coral.ConnectionService()
1780 connectstr=
'oracle://cms_orcoff_prod/cms_lumi_prod' 1781 session=svc.connect(connectstr,accessMode=coral.access_ReadOnly)
1782 session.typeConverter().setCppTypeForSqlType(
"unsigned int",
"NUMBER(10)")
1783 session.typeConverter().setCppTypeForSqlType(
"unsigned long long",
"NUMBER(20)")
1784 session.transaction().
start(
True)
1785 schema=session.nominalSchema()
1786 allruns=
allruns(schema,requireLumisummary=
True,requireTrg=
True,requireHlt=
True)
1787 print(
'allruns in runsummary and lumisummary and trg and hlt ',len(allruns))
1846 session.transaction().commit()
1881 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()
S & print(S &os, JobReport::InputFile const &f)
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)