CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
lumiReport.py
Go to the documentation of this file.
1 ###########################################################
2 # Luminosity/LumiTag/LumiCorrection report API #
3 # #
4 # Author: Zhen Xie #
5 ###########################################################
6 
7 import os,sys,time
8 from RecoLuminosity.LumiDB import tablePrinter, csvReporter,CommonUtil
9 from RecoLuminosity.LumiDB.wordWrappers import wrap_always, wrap_onspace, wrap_onspace_strict
10 
11 def dumptocsv(fieldnames,result,filename):
12  '''
13  utility method to dump result to csv file
14  '''
15  assert(filename)
16  if filename.upper()=='STDOUT':
17  r=sys.stdout
18  r.write(','.join(fieldnames)+'\n')
19  for l in result:
20  r.write(str(l)+'\n')
21  else:
22  r=csvReporter.csvReporter(filename)
23  r.writeRow(fieldnames)
24  r.writeRows(result)
25  r.close()
26 
27 def toScreenHeader(commandname,datatagname,normtag,worktag,updatetag,lumitype,toFile=None):
28  '''
29  input:
30  commandname: commandname
31  datataginfo: tagname
32  normtag: normtag
33  worktag: working version
34  updatetag: updated version if amy
35  '''
36  gmtnowStr=time.asctime(time.gmtime())+' UTC'
37  updatetagStr='None'
38  if updatetag:
39  updatetagStr=updatetag
40  header=''.join(['*']*80)+'\n'
41  header+='* '+gmtnowStr+'\n'
42  header+='* lumitype: '+lumitype+' , datatag: '+datatagname+' , normtag: '+normtag+' , worktag: '+worktag+'\n'
43  header+='* \n'
44  header+='* by:\n'
45  header+='* '+commandname+'\n'
46  header+='* \n'
47  header+='* update: '+updatetag+'\n'
48  header+=''.join(['*']*80)+'\n'
49  if not toFile:
50  sys.stdout.write(header)
51  else:
52  assert(toFile)
53  if toFile.upper()=='STDOUT':
54  r=sys.stdout
55  else:
56  r=open(toFile,'wb')
57  r.write(header)
58 
59 def toScreenNormSummary(allnorms):
60  '''
61  list all known norms summary
62  input: {normname:[data_id(0),lumitype(1),istypedefault(2),comment(3),creationtime(4)]}
63  '''
64  result=[]
65  labels=[('Name','Type','IsTypeDefault','Comment','CreationTime')]
66  print ' == = '
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) )
75 
76 def toScreenNormDetail(normname,norminfo,normvalues):
77  '''
78  list norm detail
79  input:
80  normname
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)]}
83  '''
84  lumitype=norminfo[1]
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')]
92 
93  result=[]
94  print ' == = '
95  for since in sorted(normvalues):
96  normdata=normvalues[since]
97  correctorStr=normdata[0]
98  paramDict=normdata[1]
99  paramDictStr=''
100  count=0
101  for pname in sorted(paramDict):
102  pval=paramDict[pname]
103  if count!=0:
104  paramDictStr+=' '
105  try:
106  fpval=float(pval)
107  if fpval<1.:
108  paramDictStr+=pname+':'+'%.4f'%fpval
109  else:
110  paramDictStr+=pname+':'+'%.2f'%fpval
111  except ValueError:
112  paramDictStr+=pname+':'+pval
113  count+=1
114  amodetag=normdata[2]
115  egev=str(normdata[3])
116  comment=normdata[4]
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) )
119 
120 def toScreenTags(tagdata):
121  result=[]
122  labels=[('Name','Min Run','Max Run','Creation Time')]
123  print ' == = '
124  for tagid in sorted(tagdata):
125  taginfo=tagdata[tagid]
126  name=taginfo[0]
127  minRun=str(taginfo[1])
128  maxRun='Open'
129  if taginfo[2]!=0:
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) )
134 
135 def toScreenSingleTag(taginfo):
136  '''
137  input: {run:(lumidataid,trgdataid,hltdataid,comment)}
138  '''
139  result=[]
140  labels=[('Run','Data Id','Insertion Time','Patch Comment')]
141  print ' == = '
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) )
147 
148 def toScreenTotDelivered(lumidata,resultlines,scalefactor,irunlsdict=None,noWarning=True,toFile=None):
149  '''
150  inputs:
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
155  '''
156  result=[]
157  totOldDeliveredLS=0
158  totOldCMSLS=0
159  totOldDelivered=0.0
160  datarunlsdict={}#{run:[ls,...]}from data. construct it only if there is irunlsdict to compare with
161  for r in resultlines:
162  runfillstr=r[0]
163  [runnumstr,fillnumstr]=runfillstr.split(':')
164  if irunlsdict and not noWarning:
165  if r[1] is not 'n/a':
166  datarunlsdict[int(runnumstr)]=[]
167  dl=0.0
168  if(r[3]!='n/a'): #delivered
169  dl=float(r[3])#in /ub because it comes from file!
170  (rr,lumiu)=CommonUtil.guessUnit(dl)
171  r[3]='%.3f'%(rr)+' ('+lumiu+')'
172  sls=0
173  if(r[1]!='n/a'): #n_ls
174  sls=int(r[1])
175  totcmsls=0
176  if(r[2]!='n/a'):#n_cmsls
177  totcmsls=int(r[2])
178  totOldDeliveredLS+=sls
179  totOldCMSLS+=totcmsls
180  totOldDelivered+=dl
181  if(r[5]!='n/a'): #egev
182  egv=float(r[5])
183  r[5]='%.1f'%egv
184  result.append(r)
185  totls=0
186  totcmsls=0
187  totdelivered=0.0
188  totaltable=[]
189  for run in lumidata.keys():
190  lsdata=lumidata[run]
191  if not lsdata:
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
195  continue
196  fillnum=0
197  if lsdata[0] and lsdata[0][9]:
198  fillnum=lsdata[0][9]
199  deliveredData=[]
200  nls=0
201  existdata=[]
202  selectedcmsls=[]
203  for perlsdata in lsdata:
204  lumilsnum=perlsdata[0]
205  cmslsnum=perlsdata[1]
206  if not noWarning:
207  if cmslsnum:
208  existdata.append(cmslsnum)
209  if irunlsdict and irunlsdict[run]:
210  if lumilsnum and lumilsnum in irunlsdict[run]:
211  deliveredData.append(perlsdata[5])
212  if cmslsnum:
213  selectedcmsls.append(cmslsnum)
214  else:
215  deliveredData.append(perlsdata[5])
216  if cmslsnum:
217  selectedcmsls.append(cmslsnum)
218  datarunlsdict[run]=existdata
219  nls=len(deliveredData)
220  ncmsls=0
221  if selectedcmsls:
222  ncmsls=len(selectedcmsls)
223  totcmsls+=ncmsls
224  totls+=nls
225  totlumi=sum(deliveredData)
226  totdelivered+=totlumi
227  (totlumival,lumiunit)=CommonUtil.guessUnit(totlumi)
228  beamenergyPerLS=[float(x[4]) for x in lsdata if x[3]=='STABLE BEAMS']
229  avgbeamenergy=0.0
230  if len(beamenergyPerLS):
231  avgbeamenergy=sum(beamenergyPerLS)/len(beamenergyPerLS)
232  runstarttime='n/a'
233  if lsdata[0] and lsdata[0][2]:
234  runstarttime=lsdata[0][2]
235  runstarttime=runstarttime.strftime("%m/%d/%y %H:%M:%S")
236  if not toFile:
237  result.append([str(run)+':'+str(fillnum),str(nls),str(ncmsls),'%.3f'%(totlumival*scalefactor)+' ('+lumiunit+')',runstarttime,'%.1f'%(avgbeamenergy)])
238  else:
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]))
241  #print 'sortedresult ',sortedresult
242  if not toFile:
243  labels = [('Run:Fill', 'N_LS','N_CMSLS','Delivered','UTCTime','E(GeV)')]
244  print ' == = '
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 : '
249  (totalDeliveredVal,totalDeliveredUni)=CommonUtil.guessUnit(totdelivered+totOldDelivered)
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))
255  else:
256  fieldnames = ['Run:Fill', 'N_LS','N_CMSLS','Delivered(/ub)','UTCTime','E(GeV)']
257  filename=toFile
258  dumptocsv(fieldnames,sortedresult,filename)
259 
260 def toScreenOverview(lumidata,resultlines,scalefactor,irunlsdict=None,noWarning=True,toFile=None):
261  '''
262  input:
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
265  '''
266  result=[]
267 
268  totOldDeliveredLS=0
269  totOldSelectedLS=0
270  totOldDelivered=0.0
271  totOldRecorded=0.0
272 
273  totaltable=[]
274  totalDeliveredLS = 0
275  totalSelectedLS = 0
276  totalDelivered = 0.0
277  totalRecorded = 0.0
278  datarunlsdict={}#{run:[ls,...]}from data. construct it only if there is irunlsdict to compare with
279  for r in resultlines:
280  runfillstr=r[0]
281  [runnumstr,fillnumstr]=runfillstr.split(':')
282  if irunlsdict and not noWarning:
283  if r[1] is not 'n/a':
284  datarunlsdict[int(runnumstr)]=[]
285  dl=0.0
286  if(r[2]!='n/a'):
287  dl=float(r[2])#delivered in /ub because it comes from file!
288  (rr,lumiu)=CommonUtil.guessUnit(dl)
289  r[2]='%.3f'%(rr)+' ('+lumiu+')'
290  dls=0
291  if(r[1]!='n/a'):
292  dls=int(r[1])
293  totOldDeliveredLS+=dls
294  totOldDelivered+=dl
295  rls=0
296  if(r[3]!='n/a'):
297  rlsstr=r[3]
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])
303  rls=lsmax-lsmin+1
304  totOldSelectedLS+=rls
305  if(r[4]!='n/a'):
306  rcd=float(r[4])#recorded in /ub because it comes from file!
307  (rrcd,rlumiu)=CommonUtil.guessUnit(rcd)
308  r[4]='%.3f'%(rrcd)+' ('+rlumiu+')'
309  totOldRecorded+=rcd
310  result.append(r)
311  for run in lumidata.keys():
312  lsdata=lumidata[run]
313  if not lsdata:
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
317  continue
318  fillnum=0
319  if lsdata[0] and lsdata[0][10]:
320  fillnum=lsdata[0][10]
321  deliveredData=[]
322  recordedData=[]
323  nls=0
324  existdata=[]
325  selectedcmsls=[]
326  for perlsdata in lsdata:
327  lumilsnum=perlsdata[0]
328  cmslsnum=perlsdata[1]
329  if not noWarning:
330  if cmslsnum:
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])
336  if perlsdata[6]:
337  recordedData.append(perlsdata[6])
338  selectedcmsls.append(lumilsnum)
339  else:
340  deliveredData.append(perlsdata[5])
341  if perlsdata[6]:
342  recordedData.append(perlsdata[6])
343  if cmslsnum:
344  selectedcmsls.append(cmslsnum)
345  datarunlsdict[run]=existdata
346  nls=len(deliveredData)
347  totdelivered=sum(deliveredData)
348  totalDelivered+=totdelivered
349  totalDeliveredLS+=len(deliveredData)
350  (totdeliveredlumi,deliveredlumiunit)=CommonUtil.guessUnit(totdelivered)
351  totrecorded=sum(recordedData)
352  totalRecorded+=totrecorded
353  (totrecordedlumi,recordedlumiunit)=CommonUtil.guessUnit(totrecorded)
354  totalSelectedLS+=len(selectedcmsls)
355  if len(selectedcmsls)==0:
356  selectedlsStr='n/a'
357  else:
358  selectedlsStr = CommonUtil.splitlistToRangeString(selectedcmsls)
359  if not toFile:
360  result.append([str(run)+':'+str(fillnum),str(nls),'%.3f'%(totdeliveredlumi*scalefactor)+' ('+deliveredlumiunit+')',selectedlsStr,'%.3f'%(totrecordedlumi*scalefactor)+' ('+recordedlumiunit+')'])
361  else:
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')
368  continue
369  if cmslslist:
370  for ss in cmslslist:
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')
373  if not toFile:
374  labels = [('Run:Fill', 'Delivered LS', 'Delivered','Selected LS','Recorded')]
375  print ' == = '
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 : '
380  (totalDeliveredVal,totalDeliveredUni)=CommonUtil.guessUnit(totalDelivered+totOldDelivered)
381  (totalRecordedVal,totalRecordedUni)=CommonUtil.guessUnit(totalRecorded+totOldRecorded)
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))
387  else:
388  fieldnames = ['Run:Fill', 'DeliveredLS', 'Delivered(/ub)','SelectedLS','Recorded(/ub)']
389  filename=toFile
390  dumptocsv(fieldnames,sortedresult,filename)
391 
392 def toScreenLumiByLS(lumidata,resultlines,scalefactor,irunlsdict=None,noWarning=True,toFile=None):
393  '''
394  input:
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
401  '''
402  result=[]
403  totalrow = []
404 
405  totalDeliveredLS = 0
406  totalSelectedLS = 0
407  totalDelivered = 0.0
408  totalRecorded = 0.0
409 
410  totOldDeliveredLS = 0
411  totOldSelectedLS = 0
412  totOldDelivered = 0.0
413  totOldRecorded = 0.0
414 
415  maxlslumi = 0.0
416  datarunlsdict={}#{run:[ls,...]}from data. construct it only if there is irunlsdict to compare with
417  for rline in resultlines:
418  runfillstr=rline[0]
419  [runnumstr,fillnumstr]=runfillstr.split(':')
420  if irunlsdict and not noWarning:
421  if rline[1] is not 'n/a':
422  datarunlsdict[int(runnumstr)]=[]
423  myls=rline[1]
424  if myls!='n/a':
425  [luls,cmls]=myls.split(':')
426  totOldDeliveredLS+=1
427  if cmls!='0':
428  totOldSelectedLS+=1
429  if irunlsdict and not noWarning:
430  datarunlsdict[int(runnumstr)].append(int(myls))
431  dl=rline[5]
432  if rline[5]!='n/a':
433  dl=float(rline[5])#delivered in /ub
434  if dl>maxlslumi: maxlslumi=dl
435  rline[5]=dl
436  totOldDelivered+=dl
437  rl=rline[6]
438  if rline[6]!='n/a':
439  rl=float(rline[6])#recorded in /ub
440  rline[6]=rl
441  totOldRecorded+=rl
442  result.append(rline)
443 
444  for run in lumidata.keys():
445  lsdata=lumidata[run]
446  if not lsdata:
447  #result.append([str(run),'n/a','n/a','n/a','n/a','n/a','n/a','n/a'])
448  if irunlsdict and irunlsdict[run] and not noWarning:
449  datarunlsdict[run]=None
450  #print '[WARNING] selected but no lumi data for run '+str(run)
451  continue
452  fillnum=0
453  if lsdata[0] and lsdata[0][10]:
454  fillnum=lsdata[0][10]
455  existdata=[]
456  #if irunlsdict and not noWarning:
457  # existdata=[x[1] for x in rundata if x[1] ]
458  # datarunlsdict[run]=existdata
459  for perlsdata in lsdata:
460  lumilsnum=perlsdata[0]
461  cmslsnum=perlsdata[1]#triggered ls
462  if not noWarning:
463  if cmslsnum:
464  existdata.append(cmslsnum)
465  ts=perlsdata[2]
466  bs=perlsdata[3]
467  begev=perlsdata[4]
468  deliveredlumi=perlsdata[5]
469  npu=perlsdata[11]
470  if deliveredlumi>maxlslumi: maxlslumi=deliveredlumi
471  recordedlumi=0.
472  if perlsdata[6]:
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
479  totalDeliveredLS+=1
480  totalSelectedLS+=1
481  else:
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
485  totalDeliveredLS+=1
486  if cmslsnum :
487  totalSelectedLS+=1
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')
494  continue
495  if cmslslist:
496  for ss in cmslslist:
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')
499  if not toFile:
500  (lsunitstring,unitdenomitor)=CommonUtil.lumiUnitForPrint(maxlslumi*scalefactor)
501  labels = [ ('Run:Fill','LS','UTCTime','Beam Status','E(GeV)','Del('+lsunitstring+')','Rec('+lsunitstring+')','avgPU') ]
502  perlsresult=[]
503  for entry in sortedresult:
504  delumi=entry[5]
505  if delumi!='n/a':
506  delumi='%.3f'%float(float(delumi*scalefactor)/float(unitdenomitor))
507  reclumi=entry[6]
508  if reclumi!='n/a':
509  reclumi='%.3f'%float(float(reclumi*scalefactor)/float(unitdenomitor))
510  avgPU=entry[7]
511  if avgPU!='n/a':
512  if avgPU>0:
513  avgPU='%.3f'%avgPU
514  else:
515  avgPU='0'
516  perlsresult.append([entry[0],entry[1],entry[2],entry[3],entry[4],delumi,reclumi,avgPU])
517  totdeliveredlumi=0.0
518  deliveredlumiunit='/ub'
519  (totdeliveredlumi,deliveredlumiunit)=CommonUtil.guessUnit((totalDelivered+totOldDelivered)*scalefactor)
520  totrecordedlumi=0.0
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)])
525  print ' == = '
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))
533  else:
534  fieldnames=['Run:Fill','LS','UTCTime','Beam Status','E(GeV)','Delivered(/ub)','Recorded(/ub)','avgPU']
535  filename=toFile
536  dumptocsv(fieldnames,sortedresult,filename)
537 
538 def toScreenLSEffective(lumidata,resultlines,scalefactor,irunlsdict=None,noWarning=True,toFile=None):
539  '''
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)]}
541  '''
542  result=[]#[run,ls,hltpath,l1bitname,hltpresc,l1presc,efflumi]
543  totalrow=[]
544  totSelectedLSDict={}
545  totRecordedDict={}
546  totEffectiveDict={}
547 
548  totOldSelectedLSDict={}
549  totOldRecordedDict={}
550  totOldEffectiveDict={}
551 
552  maxlslumi = 0.0
553  datarunlsdict={}#{run:[ls,...]}from data. construct it only if there is irunlsdict to compare with
554  for rline in resultlines:
555  runfillstr=rline[0]
556  [runnumstr,fillnumstr]=runfillstr.split(':')
557  if irunlsdict and not noWarning:
558  if rline[1] is not 'n/a':
559  datarunlsdict[int(runnumstr)]=[]
560  myls=rline[1]
561  mypath=rline[2]
562 
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.
567  if myls!='n/a':
568  [luls,cmls]=myls.split(':')
569  if cmls!='0':
570  if totOldSelectedLSDict.has_key(mypath):
571  totOldSelectedLSDict[mypath]+=1
572  if irunlsdict and not noWarning:
573  datarunlsdict[int(runnumstr)].append(int(myls))
574  myrecorded=0.
575  if rline[6]!='n/a':
576  myrecorded=float(rline[6])
577  if myrecorded>maxlslumi:maxlslumi=myrecorded
578  if totOldRecordedDict.has_key(mypath):
579  totOldRecordedDict[mypath]+=myrecorded
580  rline[6]=myrecorded
581  myeff={}
582  if rline[7]!='n/a':
583  myeff=float(rline[7])
584  if totOldEffectiveDict.has_key(mypath):
585  totOldEffectiveDict[mypath]+=myeff
586  rline[7]=myeff
587  result.append(rline)
588 
589  for run in lumidata.keys():#loop over runs
590  lsdata=lumidata[run]
591  if not lsdata:
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
595  continue
596  fillnum=0
597  if lsdata[0] and lsdata[0][11]:
598  fillnum=lsdata[0][11]
599  datarunlsdict[run]=[]
600  for thisls in lsdata:
601  lumilsnum=thisls[0]
602  cmslsnum=thisls[1]#triggered ls
603  if not cmslsnum: continue
604  efflumiDict=thisls[8]# this ls has no such path?
605  recordedlumi=0.
606  if thisls[6]:
607  recordedlumi=thisls[6]
608  if recordedlumi>maxlslumi:maxlslumi=recordedlumi
609  if not efflumiDict:
610  result.append([str(run)+':'+str(fillnum),str(lumilsnum)+':'+str(cmslsnum),'n/a','n/a','n/a','n/a',recordedlumi,'n/a'])
611  continue
612 
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]
624  l1name=pathdata[0]
625  cleanl1name='n/a'
626  if l1name:
627  cleanl1name=l1name.replace('"','')
628  l1presc='0'
629  if pathdata[1]:
630  l1presc=str(pathdata[1])
631  hltpresc='0'
632  if pathdata[2]:
633  hltpresc=str(pathdata[2])
634  lumival=0.
635  if pathdata[3]:
636  lumival=pathdata[3]
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')
647  continue
648  if cmslslist:
649  for ss in cmslslist:
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')
652 
653  if not toFile:
654  (lsunitstring,unitdenomitor)=CommonUtil.lumiUnitForPrint(maxlslumi*scalefactor)
655  labels = [('Run:Fill','LS','HLTpath','L1bit','HLTpresc','L1presc','Recorded('+lsunitstring+')','Effective('+lsunitstring+')')]
656  perlsresult=[]
657  for entry in sortedresult:
658  reclumi=entry[6]
659  if reclumi!='n/a':
660  reclumi='%.3f'%float(float(reclumi*scalefactor)/float(unitdenomitor))
661  efflumi=entry[7]
662  if efflumi!='n/a':
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])
665  print ' == = '
666  print tablePrinter.indent (labels+perlsresult, hasHeader = True, separateRows = False,
667  prefix = '| ', postfix = ' |', justify = 'right',
668  delim = ' | ', wrapfunc = lambda x: wrap_onspace_strict(x,25) )
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))
687  else:
688  fieldnames = ['Run:Fill','LS','HLTpath','L1bit','HLTpresc','L1presc','Recorded(/ub)','Effective(/ub)']
689  filename=toFile
690  dumptocsv(fieldnames,sortedresult,filename)
691 
692 def toScreenTotEffective(lumidata,resultlines,scalefactor,irunlsdict=None,noWarning=True,toFile=None):
693 
694  '''
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
697  '''
698  result=[]#[run,selectedlsStr,recordedofthisrun,hltpath,l1bit,efflumi]
699 
700  totdict={}#{hltpath:[nls,toteff]}
701  selectedcmsls=[]
702  alltotrecorded=0.0
703  alleffective=0.0
704  recordedPerpathPerrun={}#{path:{run:recorded}}
705  selectedPerpathPerrun={}#{path:{run:totselected}}
706  datarunlsdict={}#{run:[ls,...]}from data. construct it only if there is irunlsdict to compare with
707  for rline in resultlines:
708  runfillstr=rline[0]
709  [runnumstr,fillnumstr]=runfillstr.split(':')
710  myls=rline[1]
711  if irunlsdict and not noWarning:
712  if myls is not 'n/a':
713  datarunlsdict[int(runnumstr)]=[]
714  mypath=rline[3]
715  if mypath!='n/a':
716  mypath=mypath.split('(')[0]
717  if not totdict.has_key(mypath):
718  totdict[mypath]=[0,0.0]
719  recordedPerpathPerrun[mypath]={}
720  selectedPerpathPerrun[mypath]={}
721  if myls!='n/a':
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])
727  rls=lsmax-lsmin+1
728  totdict[mypath][0]+=rls
729  selectedPerrun[mypath].setdefault(int(myrun),totdict[mypath][0])
730  myrecorded=rline[2]
731  if myrecorded!='n/a':
732  recordedPerpathPerrun[mypath].setdefault(int(myrun),float(myrecorded))
733  (rr,lumiu)=CommonUtil.guessUnit(float(myrecorded))
734  rline[2]='%.3f'%(rr)+' ('+lumiu+')'
735  myeff=rline[5]
736  if myeff!='n/a':
737  reff=float(myeff)
738  (rr,lumiu)=CommonUtil.guessUnit(float(reff))
739  rline[5]='%.3f'%(rr)+' ('+lumiu+')'
740  totdict[mypath][1]+=reff
741  result.append(rline)
742  for run in lumidata.keys():#loop over runs
743  lsdata=lumidata[run]
744  hprescdict={}
745  lprescdict={}
746  if not lsdata:
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
750  continue
751  fillnum=0
752  if lsdata[0] and lsdata[0][11]:
753  fillnum=lsdata[0][11]
754  selectedcmsls=[x[1] for x in lsdata if x[1]]
755  totefflumiDict={}
756  totrecorded=0.0
757  toteffective=0.0
758  pathmap={}#{hltpathname:1lname}
759  existdata=[]
760  for thisls in lsdata:
761  cmslsnum=thisls[1]
762  if not noWarning:
763  if cmslsnum:
764  existdata.append(cmslsnum)
765  efflumiDict=thisls[8]# this ls has no such path?
766  recordedlumi=0.0
767  if thisls[6]:
768  recordedlumi=thisls[6]
769  totrecorded+=recordedlumi
770  if not efflumiDict:#no hltdata for this LS
771  lumival=0.
772  if cmslsnum in selectedcmsls:
773  selectedcmsls.remove(cmslsnum)
774  continue
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'
780  l1name=pathdata[0]
781  l1presc=pathdata[1]
782  hltpresc=pathdata[2]
783  lumival=pathdata[3]
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:#if found all null prescales and if it is in the selectedcmsls, remove it because incomplete
789  if cmslsnum in selectedcmsls:
790  selectedcmsls.remove(cmslsnum)
791  else:
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)
798  if cmslsnum!=0:
799  totdict[hltpathname][0]+=1
800  if lumival:
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:
807  selectedlsStr='n/a'
808  else:
809  selectedlsStr = CommonUtil.splitlistToRangeString(selectedcmsls)
810  if irunlsdict and not noWarning:
811  datarunlsdict[run]=selectedcmsls
812 
813  for name in sorted(totefflumiDict):
814  lname=pathmap[name]
815  totrecordedinrun=recordedPerpathPerrun[name][run]
816  hprescs=list(set(hprescdict[name]))
817  hprescStr='('+','.join(['%d'%(x) for x in hprescs])+')'
818  (totrecval,totrecunit)=CommonUtil.guessUnit(totrecordedinrun*scalefactor)
819  effval='n/a'
820 
821  effvalStr='n/a'
822  lprescStr='n/a'
823  cleanlname=''
824  if lname!='n/a':
825  effval=totefflumiDict[name]*scalefactor
826  lprescs=list(set(lprescdict[lname]))
827  lprescStr='('+','.join(['%d'%(x) for x in lprescs])+')'
828  cleanlname=lname.replace('"','')
829  (efflumival,efflumiunit)=CommonUtil.guessUnit(effval)
830  effvalStr='%.3f'%(efflumival)+'('+efflumiunit+')'
831  if not toFile:
832  result.append([str(run)+':'+str(fillnum),selectedlsStr,'%.3f'%(totrecval)+'('+totrecunit+')',name+hprescStr,cleanlname+lprescStr,effvalStr])
833  else:
834  result.append([str(run)+':'+str(fillnum),selectedlsStr,totrecordedinrun*scalefactor,name+hprescStr,cleanlname+lprescStr,effval])
835 
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')
840  continue
841  if cmslslist:
842  for ss in cmslslist:
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')
845 
846  sortedresult=sorted(result,key=lambda x : int(str(x[0]).split(':')[0]))
847 
848  if not toFile:
849  labels = [('Run:Fill','SelectedLS','Recorded','HLTpath(Presc)','L1bit(Presc)','Effective')]
850  print ' == = '
851  print tablePrinter.indent (labels+sortedresult, hasHeader = True, separateRows = False,
852  prefix = '| ', postfix = ' |', justify = 'right',
853  delim = ' | ', wrapfunc = lambda x: wrap_onspace_strict(x,22) )
854  print ' == = Total : '
855  lastrowlabels=[('HLTPath','SelectedLS','Recorded','Effective')]
856  totresult=[]
857  for hname in sorted(totdict):
858  hdata=totdict[hname]
859  totnls=hdata[0]
860  (toteffval,toteffunit)=CommonUtil.guessUnit(hdata[1]*scalefactor)
861  alltotrecorded=0.0
862  selectedThispath=selectedPerpathPerrun[hname]
863  for runnumber,nselected in selectedThispath.items():
864  if nselected==0: continue
865  alltotrecorded+=recordedPerpathPerrun[hname][runnumber]
866  (alltotrecordedVal,alltotrecordedunit)=CommonUtil.guessUnit(alltotrecorded*scalefactor)
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) )
870  else:
871  fieldnames=['Run:Fill','SelectedLS','Recorded','HLTpath(Presc)','L1bit(Presc)','Effective(/ub)']
872  filename=toFile
873  dumptocsv(fieldnames,sortedresult,filename)
874 
875 def toCSVLumiByLSXing(lumidata,scalefactor,filename,irunlsdict=None,noWarning=True):
876  '''
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)]}
878  output:
879  fieldnames=['Run:Fill','LS','UTCTime','Delivered(/ub)','Recorded(/ub)','BX']
880  '''
881  result=[]
882  assert(filename)
883  fieldnames=['run:fill','ls','UTCTime','delivered(/ub)','recorded(/ub)','[bx,Hz/ub]']
884  datarunlsdict={}#{run:[ls,...]}from data. construct it only if there is irunlsdict to compare with
885  for run in sorted(lumidata):
886  rundata=lumidata[run]
887  if rundata is None:
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)
891  continue
892  fillnum=0
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:
899  lumilsnum=lsdata[0]
900  cmslsnum=0
901  if lsdata and lsdata[1]:
902  cmslsnum=lsdata[1]
903  tsStr='n/a'
904  if lsdata and lsdata[2]:
905  ts=lsdata[2]
906  tsStr=ts.strftime('%m/%d/%y %H:%M:%S')
907  deliveredlumi=0.
908  if lsdata[5]:
909  deliveredlumi=lsdata[5]
910  recordedlumi=0.
911  if lsdata[6]:
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:
917  bxresult=[]
918  bxinfo=CommonUtil.transposed([bxidxlist,bxvaluelist])
919  bxresult=CommonUtil.flatten([str(run)+':'+str(fillnum),str(lumilsnum)+':'+str(cmslsnum),tsStr,deliveredlumi*scalefactor,recordedlumi*scalefactor,bxinfo])
920  result.append(bxresult)
921  else:
922  result.append([str(run)+':'+str(fillnum),str(lumilsnum)+':'+str(cmslsnum),tsStr,deliveredlumi*scalefactor,recordedlumi*scalefactor])
923  else:
924  if bxidxlist and bxvaluelist:
925  bxresult=[]
926  bxinfo=CommonUtil.transposed([bxidxlist,bxvaluelist])
927  bxresult=CommonUtil.flatten([str(run)+':'+str(fillnum),str(lumilsnum)+':'+str(cmslsnum),tsStr,deliveredlumi*scalefactor,recordedlumi*scalefactor,bxinfo])
928  result.append(bxresult)
929  else:
930  result.append([str(run)+':'+str(fillnum),str(lumilsnum)+':'+str(cmslsnum),tsStr,deliveredlumi*scalefactor,recordedlumi*scalefactor])
931  r=None
932  if filename.upper()=='STDOUT':
933  r=sys.stdout
934  r.write(','.join(fieldnames)+'\n')
935  for l in result:
936  r.write(str(l)+'\n')
937  else:
938  r=csvReporter.csvReporter(filename)
939  r.writeRow(fieldnames)
940  r.writeRows(result)
941 
942 def toScreenLSTrg(trgdata,iresults=[],irunlsdict=None,noWarning=True,toFile=None,withoutmask=False):
943  '''
944  input:{run:[[cmslsnum,deadfrac,deadtimecount,bitzero_count,bitzero_prescale,[(name,count,presc,mask),]],..]
945  '''
946  result=[]
947  datarunlsdict={}#{run:[ls,...]}from data. construct it only if there is irunlsdict to compare with
948  for rline in iresults:
949  runnumStr=rline[0]
950  cmslsnumStr=rline[1]
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))
956  result.append(rline)
957  for run in trgdata.keys():
958  rundata=trgdata[run]
959  if not rundata:
960  ll=[str(run),'n/a','n/a','n/a']
961  result.append(ll)
962  if irunlsdict and not noWarning:
963  print '[WARNING] selected but no trg data for run '+str(run)
964  continue
965  if irunlsdict and not noWarning:
966  existdata=[x[0] for x in rundata if x[0] ]
967  datarunlsdict[run]=existdata
968  deadfrac=0.0
969  bitdataStr='n/a'
970  for lsdata in rundata:
971  cmslsnum=lsdata[0]
972  deadfrac=lsdata[1]
973  deadcount=lsdata[2]
974  bitdata=lsdata[5]# already sorted by name
975  if bitdata:
976  if withoutmask:
977  flatbitdata=["("+x[0]+',%d'%x[1]+',%d'%x[2]+")" for x in bitdata if x[0]!='False']
978  bitdataStr=' '.join(flatbitdata)
979  else:
980  #consider trg mask by default
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])
986  else:
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')
992  continue
993  if cmslslist:
994  for ss in cmslslist:
995  if ss not in datarunlsdict[run]:
996  sys.stdout.write('[WARNING] selected run/ls '+str(run)+' '+str(ss)+' not in lumiDB\n')
997 
998  if not toFile:
999  print ' == = '
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) )
1002  else:
1003  filename=toFile
1004  fieldnames=['Run','LS','dfrac','(bitname,count,presc)']
1005  dumptocsv(fieldnames,result,filename)
1006 
1007 def toScreenLSHlt(hltdata,iresults=[],toFile=None):
1008  '''
1009  input:{runnumber:[(cmslsnum,[(hltpath,hltprescale,l1pass,hltaccept),...]),(cmslsnum,[])})}
1010  '''
1011  result=[]
1012  for r in iresults:
1013  result.append(r)
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']
1017  continue
1018  perrundata=hltdata[run]
1019  for lsdata in perrundata:
1020  cmslsnum=lsdata[0]
1021  allpathinfo=lsdata[1]
1022  allpathresult=[]
1023  for thispathinfo in allpathinfo:
1024  thispathname=thispathinfo[0]
1025  thispathpresc=thispathinfo[1]
1026  thisl1pass=None
1027  thishltaccept=None
1028  thispathresult=[]
1029  thispathresult.append(thispathname)
1030  if thispathpresc is None:
1031  thispathpresc='n/a'
1032  else:
1033  thispathresult.append('%d'%thispathpresc)
1034  thisl1pass=thispathinfo[2]
1035  if thispathinfo[2] is None:
1036  thispathresult.append('n/a')
1037  else:
1038  thispathresult.append('%d'%thisl1pass)
1039  thishltaccept=thispathinfo[3]
1040  if thispathinfo[3] is None:
1041  thispathresult.append('n/a')
1042  else:
1043  thispathresult.append('%d'%thishltaccept)
1044 
1045  thispathresultStr='('+','.join(thispathresult)+')'
1046  allpathresult.append(thispathresultStr)
1047  result.append([str(run),str(cmslsnum),', '.join(allpathresult)])
1048 
1049  if not toFile:
1050  print ' == = '
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) )
1055  else:
1056  fieldnames=['Run','LS','(hltpath,presc,l1pass,hltaccept)']
1057  filename=toFile
1058  dumptocsv(fieldnames,result,filename)
1059 
1060 def toScreenConfHlt(hltconfdata,iresults=[],toFile=None):
1061  '''
1062  input : {runnumber,[(hltpath,l1seedexpr,l1bitname),...]}
1063  '''
1064  result=[]
1065  for r in iresults:
1066  pp=r[1]
1067  pp=' '.join([pp[i:i+25] for i in range(0,len(pp),25)])
1068  sdepr=r[2]
1069  sdepr=' '.join([sdepr[i:i+25] for i in range(0,len(sdepr),25)])
1070  lb=r[3]
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'])
1077  continue
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]
1084  if not thisbit:
1085  thisbit='n/a'
1086  else:
1087  thisbit=' '.join([thisbit[i:i+25] for i in range(0,len(thisbit),25)]).replace('"','')
1088  result.append([str(run),thispath,thisseed,thisbit])
1089  if not toFile:
1090  labels=[('Run','hltpath','l1seedexpr','l1bit')]
1091  print ' == = '
1092  print tablePrinter.indent (labels+result, hasHeader = True, separateRows = False,
1093  prefix = '| ', postfix = ' |', justify = 'left',
1094  delim = ' | ', wrapfunc = lambda x: wrap_onspace(x,25) )
1095  else:
1096  filename=toFile
1097  fieldnames=['Run','hltpath','l1seedexpr','l1bit']
1098  dumptocsv(fieldnames,sortedresult,filename)
1099 
1100 def toScreenLSBeam(beamdata,iresults=[],dumpIntensity=False,toFile=None):
1101  '''
1102  input: {run:[(lumilsnum(0),cmslsnum(1),beamstatus(2),beamenergy(3),ncollidingbunches(4),beaminfolist(4)),..]}
1103  beaminfolist:[(bxidx,b1,b2)]
1104  '''
1105  result=[]
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']
1112  if dumpIntensity:
1113  ll.extend('n/a')
1114  continue
1115  for lsdata in perrundata:
1116  lumilsnum=lsdata[0]
1117  cmslsnum=lsdata[1]
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)])
1123  continue
1124  allbxinfo=lsdata[5]
1125  allbxresult=[]
1126  for thisbxinfo in allbxinfo:
1127  thisbxresultStr='(n/a,n/a,n/a,n/a)'
1128  bxidx=thisbxinfo[0]
1129  b1=thisbxinfo[1]
1130  b2=thisbxinfo[2]
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])
1135 
1136  if not toFile:
1137  labels=[('Run','LS','beamstatus','egev','ncollidingbx')]
1138  if dumpIntensity:
1139  labels=[('Run','LS','beamstatus','egev','ncollidingbx','(bxidx,b1,b2)')]
1140  print ' == = '
1141  print tablePrinter.indent (labels+result, hasHeader = True, separateRows = False,
1142  prefix = '| ', postfix = ' |', justify = 'left',
1143  delim = ' | ', wrapfunc = lambda x: wrap_onspace(x,25) )
1144  else:
1145  fieldnames=['Run','LS','beamstatus','egev','ncollidingbx']
1146  if dumpIntensity:
1147  fieldnames.append('(bxidx,b1,b2)')
1148  filename=toFile
1149  dumptocsv(fieldnames,result,filename)
1150 
1151 if __name__ == "__main__":
1152  toScreenHeader('lumiCalc2.py','V04-00-00','v0','pp8TeV')
def toScreenHeader
Definition: lumiReport.py:27
def toScreenOverview
Definition: lumiReport.py:260
def toScreenLSHlt
Definition: lumiReport.py:1007
def toScreenConfHlt
Definition: lumiReport.py:1060
def toScreenSingleTag
Definition: lumiReport.py:135
def wrap_onspace
Definition: dataformats.py:47
assert(m_qm.get())
def toScreenLumiByLS
Definition: lumiReport.py:392
def toScreenNormSummary
Definition: lumiReport.py:59
def splitlistToRangeString
Definition: CommonUtil.py:256
def transposed
Definition: CommonUtil.py:146
def toScreenLSBeam
Definition: lumiReport.py:1100
def toScreenTotDelivered
Definition: lumiReport.py:148
def toScreenNormDetail
Definition: lumiReport.py:76
def toScreenLSTrg
Definition: lumiReport.py:942
if(c.getParameter< edm::InputTag >("puppiValueMap").label().size()!=0)
def toScreenTotEffective
Definition: lumiReport.py:692
def toScreenLSEffective
Definition: lumiReport.py:538
def dumptocsv
Definition: lumiReport.py:11
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def toScreenTags
Definition: lumiReport.py:120
def lumiUnitForPrint
Definition: CommonUtil.py:30
def guessUnit
Definition: CommonUtil.py:59
def wrap_onspace_strict
Definition: dataformats.py:63
double split
Definition: MVATrainer.cc:139
def flatten
Definition: CommonUtil.py:4
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 toCSVLumiByLSXing
Definition: lumiReport.py:875