8 from RecoLuminosity.LumiDB
import tablePrinter, csvReporter,CommonUtil
9 from RecoLuminosity.LumiDB.wordWrappers
import wrap_always, wrap_onspace, wrap_onspace_strict
14 utility method to dump result to csv file 17 if filename.upper()==
'STDOUT':
19 r.write(
','.
join(fieldnames)+
'\n')
24 r.writeRow(fieldnames)
28 def toScreenHeader(commandname,datatagname,normtag,worktag,updatetag,lumitype,toFile=None):
31 commandname: commandname 34 worktag: working version 35 updatetag: updated version if amy 37 gmtnowStr=time.asctime(time.gmtime())+
' UTC' 40 updatetagStr=updatetag
41 header=
''.
join([
'*']*80)+
'\n' 42 header+=
'* '+gmtnowStr+
'\n' 43 header+=
'* lumitype: '+lumitype+
' , datatag: '+datatagname+
' , normtag: '+normtag+
' , worktag: '+worktag+
'\n' 46 header+=
'* '+commandname+
'\n' 48 header+=
'* update: '+updatetag+
'\n' 49 header+=
''.
join([
'*']*80)+
'\n' 51 sys.stdout.write(header)
54 if toFile.upper()==
'STDOUT':
62 list all known norms summary 63 input: {normname:[data_id(0),lumitype(1),istypedefault(2),comment(3),creationtime(4)]} 66 labels=[(
'Name',
'Type',
'IsTypeDefault',
'Comment',
'CreationTime')]
68 sorted_allnorms=sorted(six.iteritems(allnorms),key=
lambda x:x[0],reverse=
True)
69 for (normname,normvalues)
in sorted_allnorms:
70 lumitype=normvalues[1]
71 istypedefault=
str(normvalues[2])
72 commentStr=normvalues[3]
73 creationtime=normvalues[4]
74 result.append([normname,lumitype,istypedefault,commentStr,creationtime])
75 print tablePrinter.indent (labels+result, hasHeader =
True, separateRows =
False,prefix =
'| ', postfix =
' |', justify =
'left',delim =
' | ', wrapfunc =
lambda x: wrap_onspace (x,20) )
82 norminfo=[data_id[0],lumitype(1)istypedefault[2],comment[3],creationtime[4]] 83 normvalues={since:[corrector(0),{paramname:paramvalue}(1),amodetag(2),egev(3),comment(4)]} 86 istypedefault=norminfo[2]
87 print '==========================================================' 88 print '* Norm: '+normname
89 print '* Type: '+lumitype
90 print '* isDefault: '+
str(istypedefault)
91 print '==========================================================' 92 labels=[(
'Since',
'Func',
'Parameters',
'amodetag',
'egev',
'comment')]
96 for since
in sorted(normvalues):
97 normdata=normvalues[since]
98 correctorStr=normdata[0]
102 for pname
in sorted(paramDict):
103 pval=paramDict[pname]
109 paramDictStr+=pname+
':'+
'%.4f'%fpval
111 paramDictStr+=pname+
':'+
'%.2f'%fpval
113 paramDictStr+=pname+
':'+pval
116 egev=
str(normdata[3])
118 result.append([
str(since),correctorStr,paramDictStr,amodetag,egev,comment])
119 print tablePrinter.indent (labels+result, hasHeader =
True, separateRows =
False,prefix =
'| ', postfix =
' |', justify =
'left',delim =
' | ', wrapfunc =
lambda x: wrap_onspace (x,40) )
123 labels=[(
'Name',
'Min Run',
'Max Run',
'Creation Time')]
125 for tagid
in sorted(tagdata):
126 taginfo=tagdata[tagid]
128 minRun=
str(taginfo[1])
131 maxRun=
str(taginfo[2])
132 creationtime=taginfo[3]
133 result.append([name,minRun,maxRun,creationtime])
134 print tablePrinter.indent (labels+result, hasHeader =
True, separateRows =
False,prefix =
'| ', postfix =
' |', justify =
'left',delim =
' | ', wrapfunc =
lambda x: wrap_onspace (x,20) )
138 input: {run:(lumidataid,trgdataid,hltdataid,comment)} 141 labels=[(
'Run',
'Data Id',
'Insertion Time',
'Patch Comment')]
143 for run
in sorted(taginfo):
144 (lumidataid,trgdataid,hltdataid,(ctimestr,comment))=taginfo[run]
145 payloadid=
'-'.
join([
str(lumidataid),
str(trgdataid),
str(hltdataid)])
146 result.append([
str(run),payloadid,ctimestr,comment])
147 print tablePrinter.indent (labels+result, hasHeader =
True, separateRows =
False,prefix =
'| ', postfix =
' |', justify =
'left',delim =
' | ', wrapfunc =
lambda x: wrap_onspace (x,25) )
152 lumidata {run:[lumilsnum(0),cmslsnum(1),timestamp(2),beamstatus(3),beamenergy(4),deliveredlumi(5),calibratedlumierror(6),(bxidx,bxvalues,bxerrs)(7),(bxidx,b1intensities,b2intensities)(8),fillnum)(9)]} 153 resultlines [[resultrow1],[resultrow2],...,] existing result row 154 ('Run:Fill', 'N_LS','N_CMSLS','Delivered','UTCTime','E(GeV)') 155 irunlsdict: run/ls selection list. irunlsdict=None means no filter 162 for r
in resultlines:
164 [runnumstr,fillnumstr]=runfillstr.split(
':')
165 if irunlsdict
and not noWarning:
166 if r[1]
is not 'n/a':
167 datarunlsdict[
int(runnumstr)]=[]
172 r[3]=
'%.3f'%(rr)+
' ('+lumiu+
')' 179 totOldDeliveredLS+=sls
180 totOldCMSLS+=totcmsls
190 for run
in lumidata.keys():
193 result.append([
str(run)+
':0',
'n/a',
'n/a',
'n/a',
'n/a',
'n/a'])
194 if irunlsdict
and not noWarning:
195 datarunlsdict[run]=
None 198 if lsdata[0]
and lsdata[0][9]:
204 for perlsdata
in lsdata:
205 lumilsnum=perlsdata[0]
206 cmslsnum=perlsdata[1]
209 existdata.append(cmslsnum)
210 if irunlsdict
and irunlsdict[run]:
211 if lumilsnum
and lumilsnum
in irunlsdict[run]:
212 deliveredData.append(perlsdata[5])
214 selectedcmsls.append(cmslsnum)
216 deliveredData.append(perlsdata[5])
218 selectedcmsls.append(cmslsnum)
219 datarunlsdict[run]=existdata
220 nls=len(deliveredData)
223 ncmsls=len(selectedcmsls)
226 totlumi=sum(deliveredData)
227 totdelivered+=totlumi
229 beamenergyPerLS=[
float(x[4])
for x
in lsdata
if x[3]==
'STABLE BEAMS']
231 if len(beamenergyPerLS):
232 avgbeamenergy=sum(beamenergyPerLS)/len(beamenergyPerLS)
234 if lsdata[0]
and lsdata[0][2]:
235 runstarttime=lsdata[0][2]
236 runstarttime=runstarttime.strftime(
"%m/%d/%y %H:%M:%S")
238 result.append([
str(run)+
':'+
str(fillnum),
str(nls),
str(ncmsls),
'%.3f'%(totlumival*scalefactor)+
' ('+lumiunit+
')',runstarttime,
'%.1f'%(avgbeamenergy)])
240 result.append([
str(run)+
':'+
str(fillnum),
str(nls),
str(ncmsls),(totlumi*scalefactor),runstarttime,
'%.1f'%(avgbeamenergy)])
241 sortedresult=sorted(result,key=
lambda x :
int(
str(x[0]).
split(
':')[0]))
244 labels = [(
'Run:Fill',
'N_LS',
'N_CMSLS',
'Delivered',
'UTCTime',
'E(GeV)')]
246 print tablePrinter.indent (labels+sortedresult, hasHeader =
True, separateRows =
False,
247 prefix =
'| ', postfix =
' |', justify =
'right',
248 delim =
' | ', wrapfunc =
lambda x: wrap_onspace (x,40) )
249 print ' == = Total : ' 251 totrowlabels = [(
'Delivered LS',
'Total CMS LS',
'Delivered('+totalDeliveredUni+
')')]
252 totaltable.append([
str(totls+totOldDeliveredLS),
str(totcmsls+totOldCMSLS),
'%.3f'%(totalDeliveredVal*scalefactor)])
253 print tablePrinter.indent (totrowlabels+totaltable, hasHeader =
True, separateRows =
False, prefix =
'| ',
254 postfix =
' |', justify =
'right', delim =
' | ',
255 wrapfunc =
lambda x: wrap_onspace (x, 20))
257 fieldnames = [
'Run:Fill',
'N_LS',
'N_CMSLS',
'Delivered(/ub)',
'UTCTime',
'E(GeV)']
259 dumptocsv(fieldnames,sortedresult,filename)
261 def toScreenOverview(lumidata,resultlines,scalefactor,irunlsdict=None,noWarning=True,toFile=None):
264 lumidata {run:[lumilsnum(0),cmslsnum(1),timestamp(2),beamstatus(3),beamenergy(4),deliveredlumi(5),recordedlumi(6),calibratedlumierror(7),(bxidx,bxvalues,bxerrs)(8),(bxidx,b1intensities,b2intensities)(9),fillnum(10)]} 265 resultlines [[resultrow1],[resultrow2],...,] existing result row 280 for r
in resultlines:
282 [runnumstr,fillnumstr]=runfillstr.split(
':')
283 if irunlsdict
and not noWarning:
284 if r[1]
is not 'n/a':
285 datarunlsdict[
int(runnumstr)]=[]
290 r[2]=
'%.3f'%(rr)+
' ('+lumiu+
')' 294 totOldDeliveredLS+=dls
299 listcomp=rlsstr.split(
', ')
300 for lstr
in listcomp:
301 enddigs=lstr[1:-1].
split(
'-')
302 lsmin=
int(enddigs[0])
303 lsmax=
int(enddigs[1])
305 totOldSelectedLS+=rls
309 r[4]=
'%.3f'%(rrcd)+
' ('+rlumiu+
')' 312 for run
in lumidata.keys():
315 result.append([
str(run)+
':0',
'n/a',
'n/a',
'n/a',
'n/a'])
316 if irunlsdict
and irunlsdict[run]
and not noWarning:
317 datarunlsdict[run]=
None 320 if lsdata[0]
and lsdata[0][10]:
321 fillnum=lsdata[0][10]
327 for perlsdata
in lsdata:
328 lumilsnum=perlsdata[0]
329 cmslsnum=perlsdata[1]
332 existdata.append(cmslsnum)
333 if irunlsdict
and irunlsdict[run]:
334 if lumilsnum
and lumilsnum
in irunlsdict[run]:
335 if perlsdata[5]
is not None:
336 deliveredData.append(perlsdata[5])
338 recordedData.append(perlsdata[6])
339 selectedcmsls.append(lumilsnum)
341 deliveredData.append(perlsdata[5])
343 recordedData.append(perlsdata[6])
345 selectedcmsls.append(cmslsnum)
346 datarunlsdict[run]=existdata
347 nls=len(deliveredData)
348 totdelivered=sum(deliveredData)
349 totalDelivered+=totdelivered
350 totalDeliveredLS+=len(deliveredData)
352 totrecorded=sum(recordedData)
353 totalRecorded+=totrecorded
355 totalSelectedLS+=len(selectedcmsls)
356 if len(selectedcmsls)==0:
361 result.append([
str(run)+
':'+
str(fillnum),
str(nls),
'%.3f'%(totdeliveredlumi*scalefactor)+
' ('+deliveredlumiunit+
')',selectedlsStr,
'%.3f'%(totrecordedlumi*scalefactor)+
' ('+recordedlumiunit+
')'])
363 result.append([
str(run)+
':'+
str(fillnum),nls,totdelivered*scalefactor,selectedlsStr,totrecorded*scalefactor])
364 sortedresult=sorted(result,key=
lambda x :
int(
str(x[0]).
split(
':')[0]))
365 if irunlsdict
and not noWarning:
366 for run,cmslslist
in irunlsdict.items():
367 if run
not in datarunlsdict.keys()
or datarunlsdict[run]
is None:
368 sys.stdout.write(
'[WARNING] selected run '+
str(run)+
' not in lumiDB or has no qualified data\n')
372 if ss
not in datarunlsdict[run]:
373 sys.stdout.write(
'[WARNING] lumi or trg for selected run/ls '+
str(run)+
' '+
str(ss)+
' not in lumiDB\n')
375 labels = [(
'Run:Fill',
'Delivered LS',
'Delivered',
'Selected LS',
'Recorded')]
377 print tablePrinter.indent (labels+sortedresult, hasHeader =
True, separateRows =
False,
378 prefix =
'| ', postfix =
' |', justify =
'right',
379 delim =
' | ', wrapfunc =
lambda x: wrap_onspace (x,20) )
380 print ' == = Total : ' 383 totrowlabels = [(
'Delivered LS',
'Delivered('+totalDeliveredUni+
')',
'Selected LS',
'Recorded('+totalRecordedUni+
')')]
384 totaltable.append([
str(totalDeliveredLS+totOldDeliveredLS),
'%.3f'%(totalDeliveredVal*scalefactor),
str(totalSelectedLS+totOldSelectedLS),
'%.3f'%(totalRecordedVal*scalefactor)])
385 print tablePrinter.indent (totrowlabels+totaltable, hasHeader =
True, separateRows =
False, prefix =
'| ',
386 postfix =
' |', justify =
'right', delim =
' | ',
387 wrapfunc =
lambda x: wrap_onspace (x, 20))
389 fieldnames = [
'Run:Fill',
'DeliveredLS',
'Delivered(/ub)',
'SelectedLS',
'Recorded(/ub)']
391 dumptocsv(fieldnames,sortedresult,filename)
393 def toScreenLumiByLS(lumidata,resultlines,scalefactor,irunlsdict=None,noWarning=True,toFile=None):
396 lumidata {run:[lumilsnum(0),cmslsnum(1),timestamp(2),beamstatus(3),beamenergy(4),deliveredlumi(5),recordedlumi(6),calibratedlumierror(7),(bxidx,bxvalues,bxerrs)(8),(bxidx,b1intensities,b2intensities)(9),fillnum(10),pu(11)]} 397 {run:None} None means no run in lumiDB, 398 {run:[]} [] means no lumi for this run in lumiDB 399 {run:[....deliveredlumi(5),recordedlumi(6)None]} means no trigger in lumiDB 400 {run:cmslsnum(1)==0} means either not cmslsnum or is cms but not selected, therefore set recordedlumi=0,efflumi=0 401 resultlines [[resultrow1],[resultrow2],...,] existing result row 411 totOldDeliveredLS = 0
413 totOldDelivered = 0.0
418 for rline
in resultlines:
420 [runnumstr,fillnumstr]=runfillstr.split(
':')
421 if irunlsdict
and not noWarning:
422 if rline[1]
is not 'n/a':
423 datarunlsdict[
int(runnumstr)]=[]
426 [luls,cmls]=myls.split(
':')
430 if irunlsdict
and not noWarning:
435 if dl>maxlslumi: maxlslumi=dl
445 for run
in lumidata.keys():
449 if irunlsdict
and irunlsdict[run]
and not noWarning:
450 datarunlsdict[run]=
None 454 if lsdata[0]
and lsdata[0][10]:
455 fillnum=lsdata[0][10]
460 for perlsdata
in lsdata:
461 lumilsnum=perlsdata[0]
462 cmslsnum=perlsdata[1]
465 existdata.append(cmslsnum)
469 deliveredlumi=perlsdata[5]
471 if deliveredlumi>maxlslumi: maxlslumi=deliveredlumi
474 recordedlumi=perlsdata[6]
475 if irunlsdict
and irunlsdict[run]:
476 if run
in irunlsdict
and lumilsnum
in irunlsdict[run]:
477 result.append([
str(run)+
':'+
str(fillnum),
str(lumilsnum)+
':'+
str(cmslsnum),ts.strftime(
'%m/%d/%y %H:%M:%S'),bs,
'%.1f'%begev,deliveredlumi,recordedlumi,npu])
478 totalDelivered+=deliveredlumi
479 totalRecorded+=recordedlumi
483 result.append([
str(run)+
':'+
str(fillnum),
str(lumilsnum)+
':'+
str(cmslsnum),ts.strftime(
'%m/%d/%y %H:%M:%S'),bs,
'%.1f'%begev,deliveredlumi,recordedlumi,npu])
484 totalDelivered+=deliveredlumi
485 totalRecorded+=recordedlumi
489 datarunlsdict[run]=existdata
490 sortedresult=sorted(result,key=
lambda x :
int(
str(x[0]).
split(
':')[0]))
491 if irunlsdict
and not noWarning:
492 for run,cmslslist
in irunlsdict.items():
493 if run
not in datarunlsdict.keys()
or datarunlsdict[run]
is None:
494 sys.stdout.write(
'[WARNING] selected run '+
str(run)+
' not in lumiDB or has no qualified data\n')
498 if ss
not in datarunlsdict[run]:
499 sys.stdout.write(
'[WARNING] lumi or trg for selected run/ls '+
str(run)+
' '+
str(ss)+
' not in lumiDB\n')
502 labels = [ (
'Run:Fill',
'LS',
'UTCTime',
'Beam Status',
'E(GeV)',
'Del('+lsunitstring+
')',
'Rec('+lsunitstring+
')',
'avgPU') ]
504 for entry
in sortedresult:
517 perlsresult.append([entry[0],entry[1],entry[2],entry[3],entry[4],delumi,reclumi,avgPU])
519 deliveredlumiunit=
'/ub' 520 (totdeliveredlumi,deliveredlumiunit)=
CommonUtil.guessUnit((totalDelivered+totOldDelivered)*scalefactor)
522 recordedlumiunit=
'/ub' 523 (totrecordedlumi,recordedlumiunit)=
CommonUtil.guessUnit((totalRecorded+totOldRecorded)*scalefactor)
524 lastrowlabels = [ (
'Delivered LS',
'Selected LS',
'Delivered('+deliveredlumiunit+
')',
'Recorded('+recordedlumiunit+
')')]
525 totalrow.append ([
str(totalDeliveredLS+totOldDeliveredLS),
str(totalSelectedLS+totOldSelectedLS),
'%.3f'%(totdeliveredlumi),
'%.3f'%(totrecordedlumi)])
527 print tablePrinter.indent (labels+perlsresult, hasHeader =
True, separateRows =
False, prefix =
'| ',
528 postfix =
' |', justify =
'right', delim =
' | ',
529 wrapfunc =
lambda x: wrap_onspace_strict (x, 22))
530 print ' == = Total : ' 531 print tablePrinter.indent (lastrowlabels+totalrow, hasHeader =
True, separateRows =
False, prefix =
'| ',
532 postfix =
' |', justify =
'right', delim =
' | ',
533 wrapfunc =
lambda x: wrap_onspace (x, 20))
535 fieldnames=[
'Run:Fill',
'LS',
'UTCTime',
'Beam Status',
'E(GeV)',
'Delivered(/ub)',
'Recorded(/ub)',
'avgPU']
537 dumptocsv(fieldnames,sortedresult,filename)
541 input: {run:[lumilsnum(0),cmslsnum(1),timestamp(2),beamstatus(3),beamenergy(4),deliveredlumi(5),recordedlumi(6),calibratedlumierror(7),{hltpath:[l1name,l1prescale,hltprescale,efflumi]}(8),bxdata(9),beamdata(10),fillnum(11)]} 549 totOldSelectedLSDict={}
550 totOldRecordedDict={}
551 totOldEffectiveDict={}
555 for rline
in resultlines:
557 [runnumstr,fillnumstr]=runfillstr.split(
':')
558 if irunlsdict
and not noWarning:
559 if rline[1]
is not 'n/a':
560 datarunlsdict[
int(runnumstr)]=[]
564 if myls
and myls!=
'n/a' and mpath
and mpath!=
'n/a':
565 totOldSelectedLSDict[mypath]=0
566 totOldRecordedDict[mypath]=0.
567 totOldEffectiveDict[mypath]=0.
569 [luls,cmls]=myls.split(
':')
571 if mypath
in totOldSelectedLSDict:
572 totOldSelectedLSDict[mypath]+=1
573 if irunlsdict
and not noWarning:
577 myrecorded=
float(rline[6])
578 if myrecorded>maxlslumi:maxlslumi=myrecorded
579 if mypath
in totOldRecordedDict:
580 totOldRecordedDict[mypath]+=myrecorded
584 myeff=
float(rline[7])
585 if mypath
in totOldEffectiveDict:
586 totOldEffectiveDict[mypath]+=myeff
590 for run
in lumidata.keys():
593 result.append([
str(run),
'n/a',
'n/a',
'n/a',
'n/a',
'n/a',
'n/a',
'n/a'])
594 if irunlsdict
and irunlsdict[run]
and not noWarning:
595 datarunlsdict[run]=
None 598 if lsdata[0]
and lsdata[0][11]:
599 fillnum=lsdata[0][11]
600 datarunlsdict[run]=[]
601 for thisls
in lsdata:
604 if not cmslsnum:
continue 605 efflumiDict=thisls[8]
608 recordedlumi=thisls[6]
609 if recordedlumi>maxlslumi:maxlslumi=recordedlumi
611 result.append([
str(run)+
':'+
str(fillnum),
str(lumilsnum)+
':'+
str(cmslsnum),
'n/a',
'n/a',
'n/a',
'n/a',recordedlumi,
'n/a'])
614 for hltpathname
in sorted(efflumiDict):
615 if hltpathname
and hltpathname !=
'n/a' :
616 if hltpathname
not in totRecordedDict:
617 totRecordedDict[hltpathname]=0.
618 if hltpathname
not in totSelectedLSDict:
619 totSelectedLSDict[hltpathname]=0
620 if hltpathname
not in totEffectiveDict:
621 totEffectiveDict[hltpathname]=0.
622 totSelectedLSDict[hltpathname]+=1
623 totRecordedDict[hltpathname]+=recordedlumi
624 pathdata=efflumiDict[hltpathname]
628 cleanl1name=l1name.replace(
'"',
'')
631 l1presc=
str(pathdata[1])
634 hltpresc=
str(pathdata[2])
638 result.append([
str(run)+
':'+
str(fillnum),
str(lumilsnum)+
':'+
str(cmslsnum),hltpathname,cleanl1name,hltpresc,l1presc,recordedlumi,lumival])
639 if hltpathname
and hltpathname !=
'n/a' :
640 totEffectiveDict[hltpathname]+=lumival
641 if irunlsdict
and not noWarning:
643 sortedresult=sorted(result,key=
lambda x :
int(
str(x[0]).
split(
':')[0]))
644 if irunlsdict
and not noWarning:
645 for run,cmslslist
in irunlsdict.items():
646 if run
not in datarunlsdict.keys()
or datarunlsdict[run]
is None:
647 sys.stdout.write(
'[WARNING] selected run '+
str(run)+
' not in lumiDB or has no HLT data\n')
651 if ss
not in datarunlsdict[run]:
652 sys.stdout.write(
'[WARNING] selected run/ls '+
str(run)+
' '+
str(ss)+
' not in lumiDB or has no qualified data\n')
656 labels = [(
'Run:Fill',
'LS',
'HLTpath',
'L1bit',
'HLTpresc',
'L1presc',
'Recorded('+lsunitstring+
')',
'Effective('+lsunitstring+
')')]
658 for entry
in sortedresult:
665 perlsresult.append([entry[0],entry[1],entry[2],entry[3],entry[4],entry[5],reclumi,efflumi])
667 print tablePrinter.indent (labels+perlsresult, hasHeader =
True, separateRows =
False,
668 prefix =
'| ', postfix =
' |', justify =
'right',
670 for mpath
in sorted(totRecordedDict):
671 totSelectedLS=totSelectedLSDict[mpath]
672 if mpath
in totOldSelectedLSDict:
673 totSelectedLS+=totOldSelectedLS[mpath]
674 totRecorded=totRecordedDict[mpath]
675 if mpath
in totOldRecordedDict:
676 totRecorded+=totOldRecorded[mpath]
677 totRecorded=
float(totRecorded*scalefactor)/
float(unitdenomitor)
678 totEffective=totEffectiveDict[mpath]
679 if mpath
in totOldEffectiveDict:
680 totEffective+=totOldEffective[mpath]
681 totEffective=
float(totEffective*scalefactor)/
float(unitdenomitor)
682 totalrow.append([
str(totSelectedLS),mpath,
'%.3f'%(totRecorded),
'%.3f'%(totEffective)])
683 lastrowlabels = [ (
'Selected LS',
'HLTPath',
'Recorded('+lsunitstring+
')',
'Effective('+lsunitstring+
')')]
684 print ' == = Total : ' 685 print tablePrinter.indent (lastrowlabels+totalrow, hasHeader =
True, separateRows =
False, prefix =
'| ',
686 postfix =
' |', justify =
'right', delim =
' | ',
687 wrapfunc =
lambda x: wrap_onspace (x, 20))
689 fieldnames = [
'Run:Fill',
'LS',
'HLTpath',
'L1bit',
'HLTpresc',
'L1presc',
'Recorded(/ub)',
'Effective(/ub)']
691 dumptocsv(fieldnames,sortedresult,filename)
696 input: {run:[lumilsnum(0),triggeredls(1),timestamp(2),beamstatus(3),beamenergy(4),deliveredlumi(5),recordedlumi(6),calibratedlumierror(7),{hltpath:[l1name,l1prescale,hltprescale,efflumi]}(8),bxdata(9),beamdata](10),fillnum(11)} 697 screen Run,SelectedLS,Recorded,HLTPath,L1Bit,Effective 705 recordedPerpathPerrun={}
706 selectedPerpathPerrun={}
708 for rline
in resultlines:
710 [runnumstr,fillnumstr]=runfillstr.split(
':')
712 if irunlsdict
and not noWarning:
713 if myls
is not 'n/a':
714 datarunlsdict[
int(runnumstr)]=[]
717 mypath=mypath.split(
'(')[0]
718 if mypath
not in totdict:
719 totdict[mypath]=[0,0.0]
720 recordedPerpathPerrun[mypath]={}
721 selectedPerpathPerrun[mypath]={}
723 listcomp=myls.split(
', ')
724 for lstr
in listcomp:
725 enddigs=lstr[1:-1].
split(
'-')
726 lsmin=
int(enddigs[0])
727 lsmax=
int(enddigs[1])
729 totdict[mypath][0]+=rls
730 selectedPerrun[mypath].setdefault(
int(myrun),totdict[mypath][0])
732 if myrecorded!=
'n/a':
733 recordedPerpathPerrun[mypath].setdefault(
int(myrun),
float(myrecorded))
735 rline[2]=
'%.3f'%(rr)+
' ('+lumiu+
')' 740 rline[5]=
'%.3f'%(rr)+
' ('+lumiu+
')' 741 totdict[mypath][1]+=reff
743 for run
in lumidata.keys():
748 result.append([
str(run),
'n/a',
'n/a',
'n/a',
'n/a',
'n/a'])
749 if irunlsdict
and irunlsdict[run]
and not noWarning:
750 datarunlsdict[run]=
None 753 if lsdata[0]
and lsdata[0][11]:
754 fillnum=lsdata[0][11]
755 selectedcmsls=[x[1]
for x
in lsdata
if x[1]]
761 for thisls
in lsdata:
765 existdata.append(cmslsnum)
766 efflumiDict=thisls[8]
769 recordedlumi=thisls[6]
770 totrecorded+=recordedlumi
773 if cmslsnum
in selectedcmsls:
774 selectedcmsls.remove(cmslsnum)
776 for hltpathname
in sorted(efflumiDict):
777 pathdata=efflumiDict[hltpathname]
778 if hltpathname
not in totefflumiDict:
779 totefflumiDict[hltpathname]=0.0
780 pathmap[hltpathname]=
'n/a' 785 recordedPerpathPerrun.setdefault(hltpathname,{})
786 selectedPerpathPerrun.setdefault(hltpathname,{})
787 if hltpathname
not in totdict:
788 totdict[hltpathname]=[0,0.0]
789 if l1presc
is None or hltpresc
is None:
790 if cmslsnum
in selectedcmsls:
791 selectedcmsls.remove(cmslsnum)
793 if hltpathname
not in hprescdict:
794 hprescdict[hltpathname]=[]
795 hprescdict[hltpathname].
append(hltpresc)
796 if l1name
not in lprescdict:
797 lprescdict[l1name]=[]
798 lprescdict[l1name].
append(l1presc)
800 totdict[hltpathname][0]+=1
802 totdict[hltpathname][1]+=lumival
803 totefflumiDict[hltpathname]+=lumival
804 pathmap[hltpathname]=l1name
805 recordedPerpathPerrun[hltpathname][run]=totrecorded
806 selectedPerpathPerrun[hltpathname][run]=len(selectedcmsls)
807 if len(selectedcmsls)==0:
811 if irunlsdict
and not noWarning:
812 datarunlsdict[run]=selectedcmsls
814 for name
in sorted(totefflumiDict):
816 totrecordedinrun=recordedPerpathPerrun[name][run]
817 hprescs=
list(set(hprescdict[name]))
818 hprescStr=
'('+
','.
join([
'%d'%(x)
for x
in hprescs])+
')' 826 effval=totefflumiDict[name]*scalefactor
827 lprescs=
list(set(lprescdict[lname]))
828 lprescStr=
'('+
','.
join([
'%d'%(x)
for x
in lprescs])+
')' 829 cleanlname=lname.replace(
'"',
'')
831 effvalStr=
'%.3f'%(efflumival)+
'('+efflumiunit+
')' 833 result.append([
str(run)+
':'+
str(fillnum),selectedlsStr,
'%.3f'%(totrecval)+
'('+totrecunit+
')',name+hprescStr,cleanlname+lprescStr,effvalStr])
835 result.append([
str(run)+
':'+
str(fillnum),selectedlsStr,totrecordedinrun*scalefactor,name+hprescStr,cleanlname+lprescStr,effval])
837 if irunlsdict
and not noWarning:
838 for run,cmslslist
in irunlsdict.items():
839 if run
not in datarunlsdict.keys()
or datarunlsdict[run]
is None:
840 sys.stdout.write(
'[WARNING] selected run '+
str(run)+
' not in lumiDB or has no HLT data\n')
844 if ss
not in datarunlsdict[run]:
845 sys.stdout.write(
'[WARNING] selected run/ls '+
str(run)+
' '+
str(ss)+
' not in lumiDB or has no HLT data\n')
847 sortedresult=sorted(result,key=
lambda x :
int(
str(x[0]).
split(
':')[0]))
850 labels = [(
'Run:Fill',
'SelectedLS',
'Recorded',
'HLTpath(Presc)',
'L1bit(Presc)',
'Effective')]
852 print tablePrinter.indent (labels+sortedresult, hasHeader =
True, separateRows =
False,
853 prefix =
'| ', postfix =
' |', justify =
'right',
855 print ' == = Total : ' 856 lastrowlabels=[(
'HLTPath',
'SelectedLS',
'Recorded',
'Effective')]
858 for hname
in sorted(totdict):
863 selectedThispath=selectedPerpathPerrun[hname]
864 for runnumber,nselected
in selectedThispath.items():
865 if nselected==0:
continue 866 alltotrecorded+=recordedPerpathPerrun[hname][runnumber]
868 totresult.append([hname,
str(totnls),
'%.3f'%(alltotrecordedVal)+
'('+alltotrecordedunit+
')',
'%.3f'%(toteffval)+
'('+toteffunit+
')'])
869 print tablePrinter.indent (lastrowlabels+totresult, hasHeader =
True, separateRows =
False,prefix =
'| ', postfix =
' |', justify =
'right',
870 delim =
' | ', wrapfunc =
lambda x: wrap_onspace (x,20) )
872 fieldnames=[
'Run:Fill',
'SelectedLS',
'Recorded',
'HLTpath(Presc)',
'L1bit(Presc)',
'Effective(/ub)']
874 dumptocsv(fieldnames,sortedresult,filename)
878 input:{run:[lumilsnum(0),cmslsnum(1),timestamp(2),beamstatus(3),beamenergy(4),deliveredlumi(5),recordedlumi(6),calibratedlumierror(7),bxdata(8),beamdata(9),fillnum(10)]} 880 fieldnames=['Run:Fill','LS','UTCTime','Delivered(/ub)','Recorded(/ub)','BX'] 884 fieldnames=[
'run:fill',
'ls',
'UTCTime',
'delivered(/ub)',
'recorded(/ub)',
'[bx,Hz/ub]']
886 for run
in sorted(lumidata):
887 rundata=lumidata[run]
889 result.append([
str(run)+
':0',
'n/a',
'n/a',
'n/a',
'n/a',
'n/a'])
890 if irunlsdict
and irunlsdict[run]:
891 print '[WARNING] selected but no lumi data for run '+
str(run)
894 if rundata
and rundata[0][10]:
895 fillnum=rundata[0][10]
896 if irunlsdict
and not noWarning:
897 existdata=[x[1]
for x
in rundata
if x[1] ]
898 datarunlsdict[run]=existdata
899 for lsdata
in rundata:
902 if lsdata
and lsdata[1]:
905 if lsdata
and lsdata[2]:
907 tsStr=ts.strftime(
'%m/%d/%y %H:%M:%S')
910 deliveredlumi=lsdata[5]
913 recordedlumi=lsdata[6]
914 (bxidxlist,bxvaluelist,bxerrorlist)=lsdata[8]
915 if irunlsdict
and irunlsdict[run]:
916 if run
in irunlsdict
and cmslsnum
in irunlsdict[run]:
917 if bxidxlist
and bxvaluelist:
920 bxresult=
CommonUtil.flatten([
str(run)+
':'+
str(fillnum),
str(lumilsnum)+
':'+
str(cmslsnum),tsStr,deliveredlumi*scalefactor,recordedlumi*scalefactor,bxinfo])
921 result.append(bxresult)
923 result.append([
str(run)+
':'+
str(fillnum),
str(lumilsnum)+
':'+
str(cmslsnum),tsStr,deliveredlumi*scalefactor,recordedlumi*scalefactor])
925 if bxidxlist
and bxvaluelist:
928 bxresult=
CommonUtil.flatten([
str(run)+
':'+
str(fillnum),
str(lumilsnum)+
':'+
str(cmslsnum),tsStr,deliveredlumi*scalefactor,recordedlumi*scalefactor,bxinfo])
929 result.append(bxresult)
931 result.append([
str(run)+
':'+
str(fillnum),
str(lumilsnum)+
':'+
str(cmslsnum),tsStr,deliveredlumi*scalefactor,recordedlumi*scalefactor])
933 if filename.upper()==
'STDOUT':
935 r.write(
','.
join(fieldnames)+
'\n')
940 r.writeRow(fieldnames)
943 def toScreenLSTrg(trgdata,iresults=[],irunlsdict=None,noWarning=True,toFile=None,withoutmask=False):
945 input:{run:[[cmslsnum,deadfrac,deadtimecount,bitzero_count,bitzero_prescale,[(name,count,presc,mask),]],..] 949 for rline
in iresults:
952 if irunlsdict
and not noWarning:
953 if runnumStr
is not 'n/a' and int(runnumStr)
not in datarunlsdict:
954 datarunlsdict[
int(runnumstr)]=[]
955 if cmslsnumStr!=
'n/a':
958 for run
in trgdata.keys():
961 ll=[
str(run),
'n/a',
'n/a',
'n/a']
963 if irunlsdict
and not noWarning:
964 print '[WARNING] selected but no trg data for run '+
str(run)
966 if irunlsdict
and not noWarning:
967 existdata=[x[0]
for x
in rundata
if x[0] ]
968 datarunlsdict[run]=existdata
971 for lsdata
in rundata:
978 flatbitdata=[
"("+x[0]+
',%d'%x[1]+
',%d'%x[2]+
")" for x
in bitdata
if x[0]!=
'False']
979 bitdataStr=
' '.
join(flatbitdata)
982 flatbitdata=[
"("+x[0]+
',%d'%x[1]+
',%d'%x[2]+
")" for x
in bitdata
if x[0]!=
'False' and x[3]]
983 bitdataStr=
' '.
join(flatbitdata)
984 if irunlsdict
and irunlsdict[run]:
985 if run
in irunlsdict
and cmslsnum
in irunlsdict[run]:
986 result.append([
str(run),
str(cmslsnum),
'%.4f'%(deadfrac),bitdataStr])
988 result.append([
str(run),
str(cmslsnum),
'%.4f'%(deadfrac),bitdataStr])
989 if irunlsdict
and not noWarning:
990 for run,cmslslist
in irunlsdict.items():
991 if run
not in datarunlsdict.keys()
or datarunlsdict[run]
is None:
992 sys.stdout.write(
'[WARNING] selected run '+
str(run)+
' not in lumiDB or has no qualified data\n')
996 if ss
not in datarunlsdict[run]:
997 sys.stdout.write(
'[WARNING] selected run/ls '+
str(run)+
' '+
str(ss)+
' not in lumiDB\n')
1001 labels = [(
'Run',
'LS',
'dfrac',
'(bitname,count,presc)')]
1002 print tablePrinter.indent (labels+result, hasHeader =
True, separateRows =
False,prefix =
'| ', postfix =
' |', justify =
'left',delim =
' | ', wrapfunc =
lambda x: wrap_onspace (x,70) )
1005 fieldnames=[
'Run',
'LS',
'dfrac',
'(bitname,count,presc)']
1010 input:{runnumber:[(cmslsnum,[(hltpath,hltprescale,l1pass,hltaccept),...]),(cmslsnum,[])})} 1015 for run
in hltdata.keys():
1016 if hltdata[run]
is None:
1017 ll=[
str(run),
'n/a',
'n/a',
'n/a',
'n/a',
'n/a']
1019 perrundata=hltdata[run]
1020 for lsdata
in perrundata:
1022 allpathinfo=lsdata[1]
1024 for thispathinfo
in allpathinfo:
1025 thispathname=thispathinfo[0]
1026 thispathpresc=thispathinfo[1]
1030 thispathresult.append(thispathname)
1031 if thispathpresc
is None:
1034 thispathresult.append(
'%d'%thispathpresc)
1035 thisl1pass=thispathinfo[2]
1036 if thispathinfo[2]
is None:
1037 thispathresult.append(
'n/a')
1039 thispathresult.append(
'%d'%thisl1pass)
1040 thishltaccept=thispathinfo[3]
1041 if thispathinfo[3]
is None:
1042 thispathresult.append(
'n/a')
1044 thispathresult.append(
'%d'%thishltaccept)
1046 thispathresultStr=
'('+
','.
join(thispathresult)+
')' 1047 allpathresult.append(thispathresultStr)
1048 result.append([
str(run),
str(cmslsnum),
', '.
join(allpathresult)])
1052 labels = [(
'Run',
'LS',
'(hltpath,presc,l1pass,hltaccept)')]
1053 print tablePrinter.indent (labels+result, hasHeader =
True, separateRows =
False,
1054 prefix =
'| ', postfix =
' |', justify =
'left',
1055 delim =
' | ', wrapfunc =
lambda x: wrap_onspace (x,70) )
1057 fieldnames=[
'Run',
'LS',
'(hltpath,presc,l1pass,hltaccept)']
1063 input : {runnumber,[(hltpath,l1seedexpr,l1bitname),...]} 1068 pp=
' '.
join([pp[i:i+25]
for i
in range(0,len(pp),25)])
1070 sdepr=
' '.
join([sdepr[i:i+25]
for i
in range(0,len(sdepr),25)])
1072 lb=
' '.
join([lb[i:i+25]
for i
in range(0,len(lb),25)])
1073 result.append([r[0],pp,sdepr,lb])
1074 for run
in sorted(hltconfdata):
1075 pathdata=hltconfdata[run]
1076 if pathdata
is None:
1077 result.append([
str(run),
'n/a',
'n/a',
'n/a'])
1079 for thispathinfo
in pathdata:
1080 thispath=thispathinfo[0]
1081 thispath=
' '.
join([thispath[i:i+25]
for i
in range(0,len(thispath),25)])
1082 thisseed=thispathinfo[1]
1083 thisseed=
' '.
join([thisseed[i:i+25]
for i
in range(0,len(thisseed),25)]).
replace(
'"',
'')
1084 thisbit=thispathinfo[2]
1088 thisbit=
' '.
join([thisbit[i:i+25]
for i
in range(0,len(thisbit),25)]).
replace(
'"',
'')
1089 result.append([
str(run),thispath,thisseed,thisbit])
1091 labels=[(
'Run',
'hltpath',
'l1seedexpr',
'l1bit')]
1093 print tablePrinter.indent (labels+result, hasHeader =
True, separateRows =
False,
1094 prefix =
'| ', postfix =
' |', justify =
'left',
1095 delim =
' | ', wrapfunc =
lambda x:
wrap_onspace(x,25) )
1098 fieldnames=[
'Run',
'hltpath',
'l1seedexpr',
'l1bit']
1099 dumptocsv(fieldnames,sortedresult,filename)
1103 input: {run:[(lumilsnum(0),cmslsnum(1),beamstatus(2),beamenergy(3),ncollidingbunches(4),beaminfolist(4)),..]} 1104 beaminfolist:[(bxidx,b1,b2)] 1107 for rline
in iresults:
1108 result.append(rline)
1109 for run
in sorted(beamdata):
1110 perrundata=beamdata[run]
1111 if perrundata
is None:
1112 ll=[
str(run),
'n/a',
'n/a']
1116 for lsdata
in perrundata:
1119 beamstatus=lsdata[2]
1120 beamenergy=lsdata[3]
1121 ncollidingbx=lsdata[4]
1122 if not dumpIntensity:
1123 result.append([
str(run),
str(lumilsnum)+
':'+
str(cmslsnum),beamstatus,
'%.2f'%beamenergy,
str(ncollidingbx)])
1127 for thisbxinfo
in allbxinfo:
1128 thisbxresultStr=
'(n/a,n/a,n/a,n/a)' 1132 thisbxresultStr=
','.
join([
'%d'%bxidx,
'%.3e'%b1,
'%.3e'%b2])
1133 allbxresult.append(thisbxresultStr)
1134 allbxresultStr=
' '.
join(allbxresult)
1135 result.append([
str(run),
str(lumilsnum)+
':'+
str(cmslsnum),beamstatus,
'%.2f'%beamenergy,
str(ncollidingbx),allbxresultStr])
1138 labels=[(
'Run',
'LS',
'beamstatus',
'egev',
'ncollidingbx')]
1140 labels=[(
'Run',
'LS',
'beamstatus',
'egev',
'ncollidingbx',
'(bxidx,b1,b2)')]
1142 print tablePrinter.indent (labels+result, hasHeader =
True, separateRows =
False,
1143 prefix =
'| ', postfix =
' |', justify =
'left',
1144 delim =
' | ', wrapfunc =
lambda x:
wrap_onspace(x,25) )
1146 fieldnames=[
'Run',
'LS',
'beamstatus',
'egev',
'ncollidingbx']
1148 fieldnames.append(
'(bxidx,b1,b2)')
1152 if __name__ ==
"__main__":
def toScreenOverview(lumidata, resultlines, scalefactor, irunlsdict=None, noWarning=True, toFile=None)
def toScreenLSHlt(hltdata, iresults=[], toFile=None)
def replace(string, replacements)
def toScreenLumiByLS(lumidata, resultlines, scalefactor, irunlsdict=None, noWarning=True, toFile=None)
def guessUnit(inverseubval)
def toScreenConfHlt(hltconfdata, iresults=[], toFile=None)
def toScreenTotDelivered(lumidata, resultlines, scalefactor, irunlsdict=None, noWarning=True, toFile=None)
def toScreenLSTrg(trgdata, iresults=[], irunlsdict=None, noWarning=True, toFile=None, withoutmask=False)
def toCSVLumiByLSXing(lumidata, scalefactor, filename, irunlsdict=None, noWarning=True)
def splitlistToRangeString(inPut)
def transposed(lists, defaultval=None)
def toScreenNormDetail(normname, norminfo, normvalues)
def toScreenTags(tagdata)
def dumptocsv(fieldnames, result, filename)
def toScreenHeader(commandname, datatagname, normtag, worktag, updatetag, lumitype, toFile=None)
static std::string join(char **cmd)
def toScreenTotEffective(lumidata, resultlines, scalefactor, irunlsdict=None, noWarning=True, toFile=None)
def toScreenLSEffective(lumidata, resultlines, scalefactor, irunlsdict=None, noWarning=True, toFile=None)
def toScreenLSBeam(beamdata, iresults=[], dumpIntensity=False, toFile=None)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger list("!*","!HLTx*"if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL.It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of"!*"before the partial wildcard feature was incorporated).Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run
def toScreenNormSummary(allnorms)
def toScreenSingleTag(taginfo)