8 from RecoLuminosity.LumiDB
import tablePrinter, csvReporter,CommonUtil
9 from RecoLuminosity.LumiDB.wordWrappers
import wrap_always, wrap_onspace, wrap_onspace_strict
13 utility method to dump result to csv file
16 if filename.upper()==
'STDOUT':
18 r.write(
','.
join(fieldnames)+
'\n')
23 r.writeRow(fieldnames)
27 def toScreenHeader(commandname,datatagname,normtag,worktag,updatetag,lumitype,toFile=None):
30 commandname: commandname
33 worktag: working version
34 updatetag: updated version if amy
36 gmtnowStr=time.asctime(time.gmtime())+
' UTC'
39 updatetagStr=updatetag
40 header=
''.
join([
'*']*80)+
'\n'
41 header+=
'* '+gmtnowStr+
'\n'
42 header+=
'* lumitype: '+lumitype+
' , datatag: '+datatagname+
' , normtag: '+normtag+
' , worktag: '+worktag+
'\n'
45 header+=
'* '+commandname+
'\n'
47 header+=
'* update: '+updatetag+
'\n'
48 header+=
''.
join([
'*']*80)+
'\n'
50 sys.stdout.write(header)
53 if toFile.upper()==
'STDOUT':
61 list all known norms summary
62 input: {normname:[data_id(0),lumitype(1),istypedefault(2),comment(3),creationtime(4)]}
65 labels=[(
'Name',
'Type',
'IsTypeDefault',
'Comment',
'CreationTime')]
67 sorted_allnorms=sorted(allnorms.iteritems(),key=
lambda x:x[0],reverse=
True)
68 for (normname,normvalues)
in sorted_allnorms:
69 lumitype=normvalues[1]
70 istypedefault=str(normvalues[2])
71 commentStr=normvalues[3]
72 creationtime=normvalues[4]
73 result.append([normname,lumitype,istypedefault,commentStr,creationtime])
74 print tablePrinter.indent (labels+result, hasHeader =
True, separateRows =
False,prefix =
'| ', postfix =
' |', justify =
'left',delim =
' | ', wrapfunc =
lambda x: wrap_onspace (x,20) )
81 norminfo=[data_id[0],lumitype(1)istypedefault[2],comment[3],creationtime[4]]
82 normvalues={since:[corrector(0),{paramname:paramvalue}(1),amodetag(2),egev(3),comment(4)]}
85 istypedefault=norminfo[2]
86 print '=========================================================='
87 print '* Norm: '+normname
88 print '* Type: '+lumitype
89 print '* isDefault: '+str(istypedefault)
90 print '=========================================================='
91 labels=[(
'Since',
'Func',
'Parameters',
'amodetag',
'egev',
'comment')]
95 for since
in sorted(normvalues):
96 normdata=normvalues[since]
97 correctorStr=normdata[0]
101 for pname
in sorted(paramDict):
102 pval=paramDict[pname]
108 paramDictStr+=pname+
':'+
'%.4f'%fpval
110 paramDictStr+=pname+
':'+
'%.2f'%fpval
112 paramDictStr+=pname+
':'+pval
115 egev=str(normdata[3])
117 result.append([str(since),correctorStr,paramDictStr,amodetag,egev,comment])
118 print tablePrinter.indent (labels+result, hasHeader =
True, separateRows =
False,prefix =
'| ', postfix =
' |', justify =
'left',delim =
' | ', wrapfunc =
lambda x: wrap_onspace (x,40) )
122 labels=[(
'Name',
'Min Run',
'Max Run',
'Creation Time')]
124 for tagid
in sorted(tagdata):
125 taginfo=tagdata[tagid]
127 minRun=str(taginfo[1])
130 maxRun=str(taginfo[2])
131 creationtime=taginfo[3]
132 result.append([name,minRun,maxRun,creationtime])
133 print tablePrinter.indent (labels+result, hasHeader =
True, separateRows =
False,prefix =
'| ', postfix =
' |', justify =
'left',delim =
' | ', wrapfunc =
lambda x: wrap_onspace (x,20) )
137 input: {run:(lumidataid,trgdataid,hltdataid,comment)}
140 labels=[(
'Run',
'Data Id',
'Insertion Time',
'Patch Comment')]
142 for run
in sorted(taginfo):
143 (lumidataid,trgdataid,hltdataid,(ctimestr,comment))=taginfo[run]
144 payloadid=
'-'.
join([str(lumidataid),str(trgdataid),str(hltdataid)])
145 result.append([str(run),payloadid,ctimestr,comment])
146 print tablePrinter.indent (labels+result, hasHeader =
True, separateRows =
False,prefix =
'| ', postfix =
' |', justify =
'left',delim =
' | ', wrapfunc =
lambda x: wrap_onspace (x,25) )
151 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)]}
152 resultlines [[resultrow1],[resultrow2],...,] existing result row
153 ('Run:Fill', 'N_LS','N_CMSLS','Delivered','UTCTime','E(GeV)')
154 irunlsdict: run/ls selection list. irunlsdict=None means no filter
161 for r
in resultlines:
163 [runnumstr,fillnumstr]=runfillstr.split(
':')
164 if irunlsdict
and not noWarning:
165 if r[1]
is not 'n/a':
166 datarunlsdict[int(runnumstr)]=[]
171 r[3]=
'%.3f'%(rr)+
' ('+lumiu+
')'
178 totOldDeliveredLS+=sls
179 totOldCMSLS+=totcmsls
189 for run
in lumidata.keys():
192 result.append([str(run)+
':0',
'n/a',
'n/a',
'n/a',
'n/a',
'n/a'])
193 if irunlsdict
and not noWarning:
194 datarunlsdict[run]=
None
197 if lsdata[0]
and lsdata[0][9]:
203 for perlsdata
in lsdata:
204 lumilsnum=perlsdata[0]
205 cmslsnum=perlsdata[1]
208 existdata.append(cmslsnum)
209 if irunlsdict
and irunlsdict[run]:
210 if lumilsnum
and lumilsnum
in irunlsdict[run]:
211 deliveredData.append(perlsdata[5])
213 selectedcmsls.append(cmslsnum)
215 deliveredData.append(perlsdata[5])
217 selectedcmsls.append(cmslsnum)
218 datarunlsdict[run]=existdata
219 nls=len(deliveredData)
222 ncmsls=len(selectedcmsls)
225 totlumi=sum(deliveredData)
226 totdelivered+=totlumi
228 beamenergyPerLS=[float(x[4])
for x
in lsdata
if x[3]==
'STABLE BEAMS']
230 if len(beamenergyPerLS):
231 avgbeamenergy=sum(beamenergyPerLS)/len(beamenergyPerLS)
233 if lsdata[0]
and lsdata[0][2]:
234 runstarttime=lsdata[0][2]
235 runstarttime=runstarttime.strftime(
"%m/%d/%y %H:%M:%S")
237 result.append([str(run)+
':'+str(fillnum),str(nls),str(ncmsls),
'%.3f'%(totlumival*scalefactor)+
' ('+lumiunit+
')',runstarttime,
'%.1f'%(avgbeamenergy)])
239 result.append([str(run)+
':'+str(fillnum),str(nls),str(ncmsls),(totlumi*scalefactor),runstarttime,
'%.1f'%(avgbeamenergy)])
240 sortedresult=sorted(result,key=
lambda x : int(str(x[0]).
split(
':')[0]))
243 labels = [(
'Run:Fill',
'N_LS',
'N_CMSLS',
'Delivered',
'UTCTime',
'E(GeV)')]
245 print tablePrinter.indent (labels+sortedresult, hasHeader =
True, separateRows =
False,
246 prefix =
'| ', postfix =
' |', justify =
'right',
247 delim =
' | ', wrapfunc =
lambda x: wrap_onspace (x,40) )
248 print ' == = Total : '
250 totrowlabels = [(
'Delivered LS',
'Total CMS LS',
'Delivered('+totalDeliveredUni+
')')]
251 totaltable.append([str(totls+totOldDeliveredLS),str(totcmsls+totOldCMSLS),
'%.3f'%(totalDeliveredVal*scalefactor)])
252 print tablePrinter.indent (totrowlabels+totaltable, hasHeader =
True, separateRows =
False, prefix =
'| ',
253 postfix =
' |', justify =
'right', delim =
' | ',
254 wrapfunc =
lambda x: wrap_onspace (x, 20))
256 fieldnames = [
'Run:Fill',
'N_LS',
'N_CMSLS',
'Delivered(/ub)',
'UTCTime',
'E(GeV)']
258 dumptocsv(fieldnames,sortedresult,filename)
260 def toScreenOverview(lumidata,resultlines,scalefactor,irunlsdict=None,noWarning=True,toFile=None):
263 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)]}
264 resultlines [[resultrow1],[resultrow2],...,] existing result row
279 for r
in resultlines:
281 [runnumstr,fillnumstr]=runfillstr.split(
':')
282 if irunlsdict
and not noWarning:
283 if r[1]
is not 'n/a':
284 datarunlsdict[int(runnumstr)]=[]
289 r[2]=
'%.3f'%(rr)+
' ('+lumiu+
')'
293 totOldDeliveredLS+=dls
298 listcomp=rlsstr.split(
', ')
299 for lstr
in listcomp:
300 enddigs=lstr[1:-1].
split(
'-')
301 lsmin=int(enddigs[0])
302 lsmax=int(enddigs[1])
304 totOldSelectedLS+=rls
308 r[4]=
'%.3f'%(rrcd)+
' ('+rlumiu+
')'
311 for run
in lumidata.keys():
314 result.append([str(run)+
':0',
'n/a',
'n/a',
'n/a',
'n/a'])
315 if irunlsdict
and irunlsdict[run]
and not noWarning:
316 datarunlsdict[run]=
None
319 if lsdata[0]
and lsdata[0][10]:
320 fillnum=lsdata[0][10]
326 for perlsdata
in lsdata:
327 lumilsnum=perlsdata[0]
328 cmslsnum=perlsdata[1]
331 existdata.append(cmslsnum)
332 if irunlsdict
and irunlsdict[run]:
333 if lumilsnum
and lumilsnum
in irunlsdict[run]:
334 if perlsdata[5]
is not None:
335 deliveredData.append(perlsdata[5])
337 recordedData.append(perlsdata[6])
338 selectedcmsls.append(lumilsnum)
340 deliveredData.append(perlsdata[5])
342 recordedData.append(perlsdata[6])
344 selectedcmsls.append(cmslsnum)
345 datarunlsdict[run]=existdata
346 nls=len(deliveredData)
347 totdelivered=sum(deliveredData)
348 totalDelivered+=totdelivered
349 totalDeliveredLS+=len(deliveredData)
351 totrecorded=sum(recordedData)
352 totalRecorded+=totrecorded
354 totalSelectedLS+=len(selectedcmsls)
355 if len(selectedcmsls)==0:
360 result.append([str(run)+
':'+str(fillnum),str(nls),
'%.3f'%(totdeliveredlumi*scalefactor)+
' ('+deliveredlumiunit+
')',selectedlsStr,
'%.3f'%(totrecordedlumi*scalefactor)+
' ('+recordedlumiunit+
')'])
362 result.append([str(run)+
':'+str(fillnum),nls,totdelivered*scalefactor,selectedlsStr,totrecorded*scalefactor])
363 sortedresult=sorted(result,key=
lambda x : int(str(x[0]).
split(
':')[0]))
364 if irunlsdict
and not noWarning:
365 for run,cmslslist
in irunlsdict.items():
366 if run
not in datarunlsdict.keys()
or datarunlsdict[run]
is None:
367 sys.stdout.write(
'[WARNING] selected run '+str(run)+
' not in lumiDB or has no qualified data\n')
371 if ss
not in datarunlsdict[run]:
372 sys.stdout.write(
'[WARNING] lumi or trg for selected run/ls '+str(run)+
' '+str(ss)+
' not in lumiDB\n')
374 labels = [(
'Run:Fill',
'Delivered LS',
'Delivered',
'Selected LS',
'Recorded')]
376 print tablePrinter.indent (labels+sortedresult, hasHeader =
True, separateRows =
False,
377 prefix =
'| ', postfix =
' |', justify =
'right',
378 delim =
' | ', wrapfunc =
lambda x: wrap_onspace (x,20) )
379 print ' == = Total : '
382 totrowlabels = [(
'Delivered LS',
'Delivered('+totalDeliveredUni+
')',
'Selected LS',
'Recorded('+totalRecordedUni+
')')]
383 totaltable.append([str(totalDeliveredLS+totOldDeliveredLS),
'%.3f'%(totalDeliveredVal*scalefactor),str(totalSelectedLS+totOldSelectedLS),
'%.3f'%(totalRecordedVal*scalefactor)])
384 print tablePrinter.indent (totrowlabels+totaltable, hasHeader =
True, separateRows =
False, prefix =
'| ',
385 postfix =
' |', justify =
'right', delim =
' | ',
386 wrapfunc =
lambda x: wrap_onspace (x, 20))
388 fieldnames = [
'Run:Fill',
'DeliveredLS',
'Delivered(/ub)',
'SelectedLS',
'Recorded(/ub)']
390 dumptocsv(fieldnames,sortedresult,filename)
392 def toScreenLumiByLS(lumidata,resultlines,scalefactor,irunlsdict=None,noWarning=True,toFile=None):
395 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)]}
396 {run:None} None means no run in lumiDB,
397 {run:[]} [] means no lumi for this run in lumiDB
398 {run:[....deliveredlumi(5),recordedlumi(6)None]} means no trigger in lumiDB
399 {run:cmslsnum(1)==0} means either not cmslsnum or is cms but not selected, therefore set recordedlumi=0,efflumi=0
400 resultlines [[resultrow1],[resultrow2],...,] existing result row
410 totOldDeliveredLS = 0
412 totOldDelivered = 0.0
417 for rline
in resultlines:
419 [runnumstr,fillnumstr]=runfillstr.split(
':')
420 if irunlsdict
and not noWarning:
421 if rline[1]
is not 'n/a':
422 datarunlsdict[int(runnumstr)]=[]
425 [luls,cmls]=myls.split(
':')
429 if irunlsdict
and not noWarning:
430 datarunlsdict[int(runnumstr)].
append(int(myls))
434 if dl>maxlslumi: maxlslumi=dl
444 for run
in lumidata.keys():
448 if irunlsdict
and irunlsdict[run]
and not noWarning:
449 datarunlsdict[run]=
None
453 if lsdata[0]
and lsdata[0][10]:
454 fillnum=lsdata[0][10]
459 for perlsdata
in lsdata:
460 lumilsnum=perlsdata[0]
461 cmslsnum=perlsdata[1]
464 existdata.append(cmslsnum)
468 deliveredlumi=perlsdata[5]
470 if deliveredlumi>maxlslumi: maxlslumi=deliveredlumi
473 recordedlumi=perlsdata[6]
474 if irunlsdict
and irunlsdict[run]:
475 if run
in irunlsdict
and lumilsnum
in irunlsdict[run]:
476 result.append([str(run)+
':'+str(fillnum),str(lumilsnum)+
':'+str(cmslsnum),ts.strftime(
'%m/%d/%y %H:%M:%S'),bs,
'%.1f'%begev,deliveredlumi,recordedlumi,npu])
477 totalDelivered+=deliveredlumi
478 totalRecorded+=recordedlumi
482 result.append([str(run)+
':'+str(fillnum),str(lumilsnum)+
':'+str(cmslsnum),ts.strftime(
'%m/%d/%y %H:%M:%S'),bs,
'%.1f'%begev,deliveredlumi,recordedlumi,npu])
483 totalDelivered+=deliveredlumi
484 totalRecorded+=recordedlumi
488 datarunlsdict[run]=existdata
489 sortedresult=sorted(result,key=
lambda x : int(str(x[0]).
split(
':')[0]))
490 if irunlsdict
and not noWarning:
491 for run,cmslslist
in irunlsdict.items():
492 if run
not in datarunlsdict.keys()
or datarunlsdict[run]
is None:
493 sys.stdout.write(
'[WARNING] selected run '+str(run)+
' not in lumiDB or has no qualified data\n')
497 if ss
not in datarunlsdict[run]:
498 sys.stdout.write(
'[WARNING] lumi or trg for selected run/ls '+str(run)+
' '+str(ss)+
' not in lumiDB\n')
501 labels = [ (
'Run:Fill',
'LS',
'UTCTime',
'Beam Status',
'E(GeV)',
'Del('+lsunitstring+
')',
'Rec('+lsunitstring+
')',
'avgPU') ]
503 for entry
in sortedresult:
506 delumi=
'%.3f'%float(float(delumi*scalefactor)/float(unitdenomitor))
509 reclumi=
'%.3f'%float(float(reclumi*scalefactor)/float(unitdenomitor))
516 perlsresult.append([entry[0],entry[1],entry[2],entry[3],entry[4],delumi,reclumi,avgPU])
518 deliveredlumiunit=
'/ub'
519 (totdeliveredlumi,deliveredlumiunit)=
CommonUtil.guessUnit((totalDelivered+totOldDelivered)*scalefactor)
521 recordedlumiunit=
'/ub'
522 (totrecordedlumi,recordedlumiunit)=
CommonUtil.guessUnit((totalRecorded+totOldRecorded)*scalefactor)
523 lastrowlabels = [ (
'Delivered LS',
'Selected LS',
'Delivered('+deliveredlumiunit+
')',
'Recorded('+recordedlumiunit+
')')]
524 totalrow.append ([str(totalDeliveredLS+totOldDeliveredLS),str(totalSelectedLS+totOldSelectedLS),
'%.3f'%(totdeliveredlumi),
'%.3f'%(totrecordedlumi)])
526 print tablePrinter.indent (labels+perlsresult, hasHeader =
True, separateRows =
False, prefix =
'| ',
527 postfix =
' |', justify =
'right', delim =
' | ',
528 wrapfunc =
lambda x: wrap_onspace_strict (x, 22))
529 print ' == = Total : '
530 print tablePrinter.indent (lastrowlabels+totalrow, hasHeader =
True, separateRows =
False, prefix =
'| ',
531 postfix =
' |', justify =
'right', delim =
' | ',
532 wrapfunc =
lambda x: wrap_onspace (x, 20))
534 fieldnames=[
'Run:Fill',
'LS',
'UTCTime',
'Beam Status',
'E(GeV)',
'Delivered(/ub)',
'Recorded(/ub)',
'avgPU']
536 dumptocsv(fieldnames,sortedresult,filename)
540 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)]}
548 totOldSelectedLSDict={}
549 totOldRecordedDict={}
550 totOldEffectiveDict={}
554 for rline
in resultlines:
556 [runnumstr,fillnumstr]=runfillstr.split(
':')
557 if irunlsdict
and not noWarning:
558 if rline[1]
is not 'n/a':
559 datarunlsdict[int(runnumstr)]=[]
563 if myls
and myls!=
'n/a' and mpath
and mpath!=
'n/a':
564 totOldSelectedLSDict[mypath]=0
565 totOldRecordedDict[mypath]=0.
566 totOldEffectiveDict[mypath]=0.
568 [luls,cmls]=myls.split(
':')
570 if totOldSelectedLSDict.has_key(mypath):
571 totOldSelectedLSDict[mypath]+=1
572 if irunlsdict
and not noWarning:
573 datarunlsdict[int(runnumstr)].
append(int(myls))
576 myrecorded=float(rline[6])
577 if myrecorded>maxlslumi:maxlslumi=myrecorded
578 if totOldRecordedDict.has_key(mypath):
579 totOldRecordedDict[mypath]+=myrecorded
583 myeff=float(rline[7])
584 if totOldEffectiveDict.has_key(mypath):
585 totOldEffectiveDict[mypath]+=myeff
589 for run
in lumidata.keys():
592 result.append([str(run),
'n/a',
'n/a',
'n/a',
'n/a',
'n/a',
'n/a',
'n/a'])
593 if irunlsdict
and irunlsdict[run]
and not noWarning:
594 datarunlsdict[run]=
None
597 if lsdata[0]
and lsdata[0][11]:
598 fillnum=lsdata[0][11]
599 datarunlsdict[run]=[]
600 for thisls
in lsdata:
603 if not cmslsnum:
continue
604 efflumiDict=thisls[8]
607 recordedlumi=thisls[6]
608 if recordedlumi>maxlslumi:maxlslumi=recordedlumi
610 result.append([str(run)+
':'+str(fillnum),str(lumilsnum)+
':'+str(cmslsnum),
'n/a',
'n/a',
'n/a',
'n/a',recordedlumi,
'n/a'])
613 for hltpathname
in sorted(efflumiDict):
614 if hltpathname
and hltpathname !=
'n/a' :
615 if not totRecordedDict.has_key(hltpathname):
616 totRecordedDict[hltpathname]=0.
617 if not totSelectedLSDict.has_key(hltpathname):
618 totSelectedLSDict[hltpathname]=0
619 if not totEffectiveDict.has_key(hltpathname):
620 totEffectiveDict[hltpathname]=0.
621 totSelectedLSDict[hltpathname]+=1
622 totRecordedDict[hltpathname]+=recordedlumi
623 pathdata=efflumiDict[hltpathname]
627 cleanl1name=l1name.replace(
'"',
'')
630 l1presc=str(pathdata[1])
633 hltpresc=str(pathdata[2])
637 result.append([str(run)+
':'+str(fillnum),str(lumilsnum)+
':'+str(cmslsnum),hltpathname,cleanl1name,hltpresc,l1presc,recordedlumi,lumival])
638 if hltpathname
and hltpathname !=
'n/a' :
639 totEffectiveDict[hltpathname]+=lumival
640 if irunlsdict
and not noWarning:
641 datarunlsdict[run].
append(int(cmslsnum))
642 sortedresult=sorted(result,key=
lambda x : int(str(x[0]).
split(
':')[0]))
643 if irunlsdict
and not noWarning:
644 for run,cmslslist
in irunlsdict.items():
645 if run
not in datarunlsdict.keys()
or datarunlsdict[run]
is None:
646 sys.stdout.write(
'[WARNING] selected run '+str(run)+
' not in lumiDB or has no HLT data\n')
650 if ss
not in datarunlsdict[run]:
651 sys.stdout.write(
'[WARNING] selected run/ls '+str(run)+
' '+str(ss)+
' not in lumiDB or has no qualified data\n')
655 labels = [(
'Run:Fill',
'LS',
'HLTpath',
'L1bit',
'HLTpresc',
'L1presc',
'Recorded('+lsunitstring+
')',
'Effective('+lsunitstring+
')')]
657 for entry
in sortedresult:
660 reclumi=
'%.3f'%float(float(reclumi*scalefactor)/float(unitdenomitor))
663 efflumi=
'%.3f'%float(float(efflumi*scalefactor)/float(unitdenomitor))
664 perlsresult.append([entry[0],entry[1],entry[2],entry[3],entry[4],entry[5],reclumi,efflumi])
666 print tablePrinter.indent (labels+perlsresult, hasHeader =
True, separateRows =
False,
667 prefix =
'| ', postfix =
' |', justify =
'right',
669 for mpath
in sorted(totRecordedDict):
670 totSelectedLS=totSelectedLSDict[mpath]
671 if totOldSelectedLSDict.has_key(mpath):
672 totSelectedLS+=totOldSelectedLS[mpath]
673 totRecorded=totRecordedDict[mpath]
674 if totOldRecordedDict.has_key(mpath):
675 totRecorded+=totOldRecorded[mpath]
676 totRecorded=float(totRecorded*scalefactor)/float(unitdenomitor)
677 totEffective=totEffectiveDict[mpath]
678 if totOldEffectiveDict.has_key(mpath):
679 totEffective+=totOldEffective[mpath]
680 totEffective=float(totEffective*scalefactor)/float(unitdenomitor)
681 totalrow.append([str(totSelectedLS),mpath,
'%.3f'%(totRecorded),
'%.3f'%(totEffective)])
682 lastrowlabels = [ (
'Selected LS',
'HLTPath',
'Recorded('+lsunitstring+
')',
'Effective('+lsunitstring+
')')]
683 print ' == = Total : '
684 print tablePrinter.indent (lastrowlabels+totalrow, hasHeader =
True, separateRows =
False, prefix =
'| ',
685 postfix =
' |', justify =
'right', delim =
' | ',
686 wrapfunc =
lambda x: wrap_onspace (x, 20))
688 fieldnames = [
'Run:Fill',
'LS',
'HLTpath',
'L1bit',
'HLTpresc',
'L1presc',
'Recorded(/ub)',
'Effective(/ub)']
690 dumptocsv(fieldnames,sortedresult,filename)
695 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)}
696 screen Run,SelectedLS,Recorded,HLTPath,L1Bit,Effective
704 recordedPerpathPerrun={}
705 selectedPerpathPerrun={}
707 for rline
in resultlines:
709 [runnumstr,fillnumstr]=runfillstr.split(
':')
711 if irunlsdict
and not noWarning:
712 if myls
is not 'n/a':
713 datarunlsdict[int(runnumstr)]=[]
716 mypath=mypath.split(
'(')[0]
717 if not totdict.has_key(mypath):
718 totdict[mypath]=[0,0.0]
719 recordedPerpathPerrun[mypath]={}
720 selectedPerpathPerrun[mypath]={}
722 listcomp=myls.split(
', ')
723 for lstr
in listcomp:
724 enddigs=lstr[1:-1].
split(
'-')
725 lsmin=int(enddigs[0])
726 lsmax=int(enddigs[1])
728 totdict[mypath][0]+=rls
729 selectedPerrun[mypath].setdefault(int(myrun),totdict[mypath][0])
731 if myrecorded!=
'n/a':
732 recordedPerpathPerrun[mypath].setdefault(int(myrun),float(myrecorded))
734 rline[2]=
'%.3f'%(rr)+
' ('+lumiu+
')'
739 rline[5]=
'%.3f'%(rr)+
' ('+lumiu+
')'
740 totdict[mypath][1]+=reff
742 for run
in lumidata.keys():
747 result.append([str(run),
'n/a',
'n/a',
'n/a',
'n/a',
'n/a'])
748 if irunlsdict
and irunlsdict[run]
and not noWarning:
749 datarunlsdict[run]=
None
752 if lsdata[0]
and lsdata[0][11]:
753 fillnum=lsdata[0][11]
754 selectedcmsls=[x[1]
for x
in lsdata
if x[1]]
760 for thisls
in lsdata:
764 existdata.append(cmslsnum)
765 efflumiDict=thisls[8]
768 recordedlumi=thisls[6]
769 totrecorded+=recordedlumi
772 if cmslsnum
in selectedcmsls:
773 selectedcmsls.remove(cmslsnum)
775 for hltpathname
in sorted(efflumiDict):
776 pathdata=efflumiDict[hltpathname]
777 if not totefflumiDict.has_key(hltpathname):
778 totefflumiDict[hltpathname]=0.0
779 pathmap[hltpathname]=
'n/a'
784 recordedPerpathPerrun.setdefault(hltpathname,{})
785 selectedPerpathPerrun.setdefault(hltpathname,{})
786 if not totdict.has_key(hltpathname):
787 totdict[hltpathname]=[0,0.0]
788 if l1presc
is None or hltpresc
is None:
789 if cmslsnum
in selectedcmsls:
790 selectedcmsls.remove(cmslsnum)
792 if not hprescdict.has_key(hltpathname):
793 hprescdict[hltpathname]=[]
794 hprescdict[hltpathname].
append(hltpresc)
795 if not lprescdict.has_key(l1name):
796 lprescdict[l1name]=[]
797 lprescdict[l1name].
append(l1presc)
799 totdict[hltpathname][0]+=1
801 totdict[hltpathname][1]+=lumival
802 totefflumiDict[hltpathname]+=lumival
803 pathmap[hltpathname]=l1name
804 recordedPerpathPerrun[hltpathname][run]=totrecorded
805 selectedPerpathPerrun[hltpathname][run]=len(selectedcmsls)
806 if len(selectedcmsls)==0:
810 if irunlsdict
and not noWarning:
811 datarunlsdict[run]=selectedcmsls
813 for name
in sorted(totefflumiDict):
815 totrecordedinrun=recordedPerpathPerrun[name][run]
816 hprescs=
list(set(hprescdict[name]))
817 hprescStr=
'('+
','.
join([
'%d'%(x)
for x
in hprescs])+
')'
825 effval=totefflumiDict[name]*scalefactor
826 lprescs=
list(set(lprescdict[lname]))
827 lprescStr=
'('+
','.
join([
'%d'%(x)
for x
in lprescs])+
')'
828 cleanlname=lname.replace(
'"',
'')
830 effvalStr=
'%.3f'%(efflumival)+
'('+efflumiunit+
')'
832 result.append([str(run)+
':'+str(fillnum),selectedlsStr,
'%.3f'%(totrecval)+
'('+totrecunit+
')',name+hprescStr,cleanlname+lprescStr,effvalStr])
834 result.append([str(run)+
':'+str(fillnum),selectedlsStr,totrecordedinrun*scalefactor,name+hprescStr,cleanlname+lprescStr,effval])
836 if irunlsdict
and not noWarning:
837 for run,cmslslist
in irunlsdict.items():
838 if run
not in datarunlsdict.keys()
or datarunlsdict[run]
is None:
839 sys.stdout.write(
'[WARNING] selected run '+str(run)+
' not in lumiDB or has no HLT data\n')
843 if ss
not in datarunlsdict[run]:
844 sys.stdout.write(
'[WARNING] selected run/ls '+str(run)+
' '+str(ss)+
' not in lumiDB or has no HLT data\n')
846 sortedresult=sorted(result,key=
lambda x : int(str(x[0]).
split(
':')[0]))
849 labels = [(
'Run:Fill',
'SelectedLS',
'Recorded',
'HLTpath(Presc)',
'L1bit(Presc)',
'Effective')]
851 print tablePrinter.indent (labels+sortedresult, hasHeader =
True, separateRows =
False,
852 prefix =
'| ', postfix =
' |', justify =
'right',
854 print ' == = Total : '
855 lastrowlabels=[(
'HLTPath',
'SelectedLS',
'Recorded',
'Effective')]
857 for hname
in sorted(totdict):
862 selectedThispath=selectedPerpathPerrun[hname]
863 for runnumber,nselected
in selectedThispath.items():
864 if nselected==0:
continue
865 alltotrecorded+=recordedPerpathPerrun[hname][runnumber]
867 totresult.append([hname,str(totnls),
'%.3f'%(alltotrecordedVal)+
'('+alltotrecordedunit+
')',
'%.3f'%(toteffval)+
'('+toteffunit+
')'])
868 print tablePrinter.indent (lastrowlabels+totresult, hasHeader =
True, separateRows =
False,prefix =
'| ', postfix =
' |', justify =
'right',
869 delim =
' | ', wrapfunc =
lambda x: wrap_onspace (x,20) )
871 fieldnames=[
'Run:Fill',
'SelectedLS',
'Recorded',
'HLTpath(Presc)',
'L1bit(Presc)',
'Effective(/ub)']
873 dumptocsv(fieldnames,sortedresult,filename)
877 input:{run:[lumilsnum(0),cmslsnum(1),timestamp(2),beamstatus(3),beamenergy(4),deliveredlumi(5),recordedlumi(6),calibratedlumierror(7),bxdata(8),beamdata(9),fillnum(10)]}
879 fieldnames=['Run:Fill','LS','UTCTime','Delivered(/ub)','Recorded(/ub)','BX']
883 fieldnames=[
'run:fill',
'ls',
'UTCTime',
'delivered(/ub)',
'recorded(/ub)',
'[bx,Hz/ub]']
885 for run
in sorted(lumidata):
886 rundata=lumidata[run]
888 result.append([str(run)+
':0',
'n/a',
'n/a',
'n/a',
'n/a',
'n/a'])
889 if irunlsdict
and irunlsdict[run]:
890 print '[WARNING] selected but no lumi data for run '+str(run)
893 if rundata
and rundata[0][10]:
894 fillnum=rundata[0][10]
895 if irunlsdict
and not noWarning:
896 existdata=[x[1]
for x
in rundata
if x[1] ]
897 datarunlsdict[run]=existdata
898 for lsdata
in rundata:
901 if lsdata
and lsdata[1]:
904 if lsdata
and lsdata[2]:
906 tsStr=ts.strftime(
'%m/%d/%y %H:%M:%S')
909 deliveredlumi=lsdata[5]
912 recordedlumi=lsdata[6]
913 (bxidxlist,bxvaluelist,bxerrorlist)=lsdata[8]
914 if irunlsdict
and irunlsdict[run]:
915 if run
in irunlsdict
and cmslsnum
in irunlsdict[run]:
916 if bxidxlist
and bxvaluelist:
919 bxresult=
CommonUtil.flatten([str(run)+
':'+str(fillnum),str(lumilsnum)+
':'+str(cmslsnum),tsStr,deliveredlumi*scalefactor,recordedlumi*scalefactor,bxinfo])
920 result.append(bxresult)
922 result.append([str(run)+
':'+str(fillnum),str(lumilsnum)+
':'+str(cmslsnum),tsStr,deliveredlumi*scalefactor,recordedlumi*scalefactor])
924 if bxidxlist
and bxvaluelist:
927 bxresult=
CommonUtil.flatten([str(run)+
':'+str(fillnum),str(lumilsnum)+
':'+str(cmslsnum),tsStr,deliveredlumi*scalefactor,recordedlumi*scalefactor,bxinfo])
928 result.append(bxresult)
930 result.append([str(run)+
':'+str(fillnum),str(lumilsnum)+
':'+str(cmslsnum),tsStr,deliveredlumi*scalefactor,recordedlumi*scalefactor])
932 if filename.upper()==
'STDOUT':
934 r.write(
','.
join(fieldnames)+
'\n')
939 r.writeRow(fieldnames)
942 def toScreenLSTrg(trgdata,iresults=[],irunlsdict=None,noWarning=True,toFile=None,withoutmask=False):
944 input:{run:[[cmslsnum,deadfrac,deadtimecount,bitzero_count,bitzero_prescale,[(name,count,presc,mask),]],..]
948 for rline
in iresults:
951 if irunlsdict
and not noWarning:
952 if runnumStr
is not 'n/a' and not datarunlsdict.has_key(int(runnumStr)):
953 datarunlsdict[int(runnumstr)]=[]
954 if cmslsnumStr!=
'n/a':
955 datarunlsdict[int(runnumStr)].
append(int(cmslsnumStr))
957 for run
in trgdata.keys():
960 ll=[str(run),
'n/a',
'n/a',
'n/a']
962 if irunlsdict
and not noWarning:
963 print '[WARNING] selected but no trg data for run '+str(run)
965 if irunlsdict
and not noWarning:
966 existdata=[x[0]
for x
in rundata
if x[0] ]
967 datarunlsdict[run]=existdata
970 for lsdata
in rundata:
977 flatbitdata=[
"("+x[0]+
',%d'%x[1]+
',%d'%x[2]+
")" for x
in bitdata
if x[0]!=
'False']
978 bitdataStr=
' '.
join(flatbitdata)
981 flatbitdata=[
"("+x[0]+
',%d'%x[1]+
',%d'%x[2]+
")" for x
in bitdata
if x[0]!=
'False' and x[3]]
982 bitdataStr=
' '.
join(flatbitdata)
983 if irunlsdict
and irunlsdict[run]:
984 if run
in irunlsdict
and cmslsnum
in irunlsdict[run]:
985 result.append([str(run),str(cmslsnum),
'%.4f'%(deadfrac),bitdataStr])
987 result.append([str(run),str(cmslsnum),
'%.4f'%(deadfrac),bitdataStr])
988 if irunlsdict
and not noWarning:
989 for run,cmslslist
in irunlsdict.items():
990 if run
not in datarunlsdict.keys()
or datarunlsdict[run]
is None:
991 sys.stdout.write(
'[WARNING] selected run '+str(run)+
' not in lumiDB or has no qualified data\n')
995 if ss
not in datarunlsdict[run]:
996 sys.stdout.write(
'[WARNING] selected run/ls '+str(run)+
' '+str(ss)+
' not in lumiDB\n')
1000 labels = [(
'Run',
'LS',
'dfrac',
'(bitname,count,presc)')]
1001 print tablePrinter.indent (labels+result, hasHeader =
True, separateRows =
False,prefix =
'| ', postfix =
' |', justify =
'left',delim =
' | ', wrapfunc =
lambda x: wrap_onspace (x,70) )
1004 fieldnames=[
'Run',
'LS',
'dfrac',
'(bitname,count,presc)']
1009 input:{runnumber:[(cmslsnum,[(hltpath,hltprescale,l1pass,hltaccept),...]),(cmslsnum,[])})}
1014 for run
in hltdata.keys():
1015 if hltdata[run]
is None:
1016 ll=[str(run),
'n/a',
'n/a',
'n/a',
'n/a',
'n/a']
1018 perrundata=hltdata[run]
1019 for lsdata
in perrundata:
1021 allpathinfo=lsdata[1]
1023 for thispathinfo
in allpathinfo:
1024 thispathname=thispathinfo[0]
1025 thispathpresc=thispathinfo[1]
1029 thispathresult.append(thispathname)
1030 if thispathpresc
is None:
1033 thispathresult.append(
'%d'%thispathpresc)
1034 thisl1pass=thispathinfo[2]
1035 if thispathinfo[2]
is None:
1036 thispathresult.append(
'n/a')
1038 thispathresult.append(
'%d'%thisl1pass)
1039 thishltaccept=thispathinfo[3]
1040 if thispathinfo[3]
is None:
1041 thispathresult.append(
'n/a')
1043 thispathresult.append(
'%d'%thishltaccept)
1045 thispathresultStr=
'('+
','.
join(thispathresult)+
')'
1046 allpathresult.append(thispathresultStr)
1047 result.append([str(run),str(cmslsnum),
', '.
join(allpathresult)])
1051 labels = [(
'Run',
'LS',
'(hltpath,presc,l1pass,hltaccept)')]
1052 print tablePrinter.indent (labels+result, hasHeader =
True, separateRows =
False,
1053 prefix =
'| ', postfix =
' |', justify =
'left',
1054 delim =
' | ', wrapfunc =
lambda x: wrap_onspace (x,70) )
1056 fieldnames=[
'Run',
'LS',
'(hltpath,presc,l1pass,hltaccept)']
1062 input : {runnumber,[(hltpath,l1seedexpr,l1bitname),...]}
1067 pp=
' '.
join([pp[i:i+25]
for i
in range(0,len(pp),25)])
1069 sdepr=
' '.
join([sdepr[i:i+25]
for i
in range(0,len(sdepr),25)])
1071 lb=
' '.
join([lb[i:i+25]
for i
in range(0,len(lb),25)])
1072 result.append([r[0],pp,sdepr,lb])
1073 for run
in sorted(hltconfdata):
1074 pathdata=hltconfdata[run]
1075 if pathdata
is None:
1076 result.append([str(run),
'n/a',
'n/a',
'n/a'])
1078 for thispathinfo
in pathdata:
1079 thispath=thispathinfo[0]
1080 thispath=
' '.
join([thispath[i:i+25]
for i
in range(0,len(thispath),25)])
1081 thisseed=thispathinfo[1]
1082 thisseed=
' '.
join([thisseed[i:i+25]
for i
in range(0,len(thisseed),25)]).
replace(
'"',
'')
1083 thisbit=thispathinfo[2]
1087 thisbit=
' '.
join([thisbit[i:i+25]
for i
in range(0,len(thisbit),25)]).
replace(
'"',
'')
1088 result.append([str(run),thispath,thisseed,thisbit])
1090 labels=[(
'Run',
'hltpath',
'l1seedexpr',
'l1bit')]
1092 print tablePrinter.indent (labels+result, hasHeader =
True, separateRows =
False,
1093 prefix =
'| ', postfix =
' |', justify =
'left',
1094 delim =
' | ', wrapfunc =
lambda x:
wrap_onspace(x,25) )
1097 fieldnames=[
'Run',
'hltpath',
'l1seedexpr',
'l1bit']
1098 dumptocsv(fieldnames,sortedresult,filename)
1102 input: {run:[(lumilsnum(0),cmslsnum(1),beamstatus(2),beamenergy(3),ncollidingbunches(4),beaminfolist(4)),..]}
1103 beaminfolist:[(bxidx,b1,b2)]
1106 for rline
in iresults:
1107 result.append(rline)
1108 for run
in sorted(beamdata):
1109 perrundata=beamdata[run]
1110 if perrundata
is None:
1111 ll=[str(run),
'n/a',
'n/a']
1115 for lsdata
in perrundata:
1118 beamstatus=lsdata[2]
1119 beamenergy=lsdata[3]
1120 ncollidingbx=lsdata[4]
1121 if not dumpIntensity:
1122 result.append([str(run),str(lumilsnum)+
':'+str(cmslsnum),beamstatus,
'%.2f'%beamenergy,str(ncollidingbx)])
1126 for thisbxinfo
in allbxinfo:
1127 thisbxresultStr=
'(n/a,n/a,n/a,n/a)'
1131 thisbxresultStr=
','.
join([
'%d'%bxidx,
'%.3e'%b1,
'%.3e'%b2])
1132 allbxresult.append(thisbxresultStr)
1133 allbxresultStr=
' '.
join(allbxresult)
1134 result.append([str(run),str(lumilsnum)+
':'+str(cmslsnum),beamstatus,
'%.2f'%beamenergy,str(ncollidingbx),allbxresultStr])
1137 labels=[(
'Run',
'LS',
'beamstatus',
'egev',
'ncollidingbx')]
1139 labels=[(
'Run',
'LS',
'beamstatus',
'egev',
'ncollidingbx',
'(bxidx,b1,b2)')]
1141 print tablePrinter.indent (labels+result, hasHeader =
True, separateRows =
False,
1142 prefix =
'| ', postfix =
' |', justify =
'left',
1143 delim =
' | ', wrapfunc =
lambda x:
wrap_onspace(x,25) )
1145 fieldnames=[
'Run',
'LS',
'beamstatus',
'egev',
'ncollidingbx']
1147 fieldnames.append(
'(bxidx,b1,b2)')
1151 if __name__ ==
"__main__":
def splitlistToRangeString
if(c.getParameter< edm::InputTag >("puppiValueMap").label().size()!=0)
static std::string join(char **cmd)
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