CMS 3D CMS Logo

lumiReport.py
Go to the documentation of this file.
1 from __future__ import print_function
2 ###########################################################
3 # Luminosity/LumiTag/LumiCorrection report API #
4 # #
5 # Author: Zhen Xie #
6 ###########################################################
7 
8 import os,sys,time
9 from RecoLuminosity.LumiDB import tablePrinter, csvReporter,CommonUtil
10 from RecoLuminosity.LumiDB.wordWrappers import wrap_always, wrap_onspace, wrap_onspace_strict
11 import six
12 
13 def dumptocsv(fieldnames,result,filename):
14  '''
15  utility method to dump result to csv file
16  '''
17  assert(filename)
18  if filename.upper()=='STDOUT':
19  r=sys.stdout
20  r.write(','.join(fieldnames)+'\n')
21  for l in result:
22  r.write(str(l)+'\n')
23  else:
24  r=csvReporter.csvReporter(filename)
25  r.writeRow(fieldnames)
26  r.writeRows(result)
27  r.close()
28 
29 def toScreenHeader(commandname,datatagname,normtag,worktag,updatetag,lumitype,toFile=None):
30  '''
31  input:
32  commandname: commandname
33  datataginfo: tagname
34  normtag: normtag
35  worktag: working version
36  updatetag: updated version if amy
37  '''
38  gmtnowStr=time.asctime(time.gmtime())+' UTC'
39  updatetagStr='None'
40  if updatetag:
41  updatetagStr=updatetag
42  header=''.join(['*']*80)+'\n'
43  header+='* '+gmtnowStr+'\n'
44  header+='* lumitype: '+lumitype+' , datatag: '+datatagname+' , normtag: '+normtag+' , worktag: '+worktag+'\n'
45  header+='* \n'
46  header+='* by:\n'
47  header+='* '+commandname+'\n'
48  header+='* \n'
49  header+='* update: '+updatetag+'\n'
50  header+=''.join(['*']*80)+'\n'
51  if not toFile:
52  sys.stdout.write(header)
53  else:
54  assert(toFile)
55  if toFile.upper()=='STDOUT':
56  r=sys.stdout
57  else:
58  r=open(toFile,'wb')
59  r.write(header)
60 
61 def toScreenNormSummary(allnorms):
62  '''
63  list all known norms summary
64  input: {normname:[data_id(0),lumitype(1),istypedefault(2),comment(3),creationtime(4)]}
65  '''
66  result=[]
67  labels=[('Name','Type','IsTypeDefault','Comment','CreationTime')]
68  print(' == = ')
69  sorted_allnorms=sorted(six.iteritems(allnorms),key=lambda x:x[0],reverse=True)
70  for (normname,normvalues) in sorted_allnorms:
71  lumitype=normvalues[1]
72  istypedefault=str(normvalues[2])
73  commentStr=normvalues[3]
74  creationtime=normvalues[4]
75  result.append([normname,lumitype,istypedefault,commentStr,creationtime])
76  print(tablePrinter.indent (labels+result, hasHeader = True, separateRows = False,prefix = '| ', postfix = ' |', justify = 'left',delim = ' | ', wrapfunc = lambda x: wrap_onspace (x,20) ))
77 
78 def toScreenNormDetail(normname,norminfo,normvalues):
79  '''
80  list norm detail
81  input:
82  normname
83  norminfo=[data_id[0],lumitype(1)istypedefault[2],comment[3],creationtime[4]]
84  normvalues={since:[corrector(0),{paramname:paramvalue}(1),amodetag(2),egev(3),comment(4)]}
85  '''
86  lumitype=norminfo[1]
87  istypedefault=norminfo[2]
88  print('==========================================================')
89  print('* Norm: '+normname)
90  print('* Type: '+lumitype)
91  print('* isDefault: '+str(istypedefault))
92  print('==========================================================')
93  labels=[('Since','Func','Parameters','amodetag','egev','comment')]
94 
95  result=[]
96  print(' == = ')
97  for since in sorted(normvalues):
98  normdata=normvalues[since]
99  correctorStr=normdata[0]
100  paramDict=normdata[1]
101  paramDictStr=''
102  count=0
103  for pname in sorted(paramDict):
104  pval=paramDict[pname]
105  if count!=0:
106  paramDictStr+=' '
107  try:
108  fpval=float(pval)
109  if fpval<1.:
110  paramDictStr+=pname+':'+'%.4f'%fpval
111  else:
112  paramDictStr+=pname+':'+'%.2f'%fpval
113  except ValueError:
114  paramDictStr+=pname+':'+pval
115  count+=1
116  amodetag=normdata[2]
117  egev=str(normdata[3])
118  comment=normdata[4]
119  result.append([str(since),correctorStr,paramDictStr,amodetag,egev,comment])
120  print(tablePrinter.indent (labels+result, hasHeader = True, separateRows = False,prefix = '| ', postfix = ' |', justify = 'left',delim = ' | ', wrapfunc = lambda x: wrap_onspace (x,40) ))
121 
122 def toScreenTags(tagdata):
123  result=[]
124  labels=[('Name','Min Run','Max Run','Creation Time')]
125  print(' == = ')
126  for tagid in sorted(tagdata):
127  taginfo=tagdata[tagid]
128  name=taginfo[0]
129  minRun=str(taginfo[1])
130  maxRun='Open'
131  if taginfo[2]!=0:
132  maxRun=str(taginfo[2])
133  creationtime=taginfo[3]
134  result.append([name,minRun,maxRun,creationtime])
135  print(tablePrinter.indent (labels+result, hasHeader = True, separateRows = False,prefix = '| ', postfix = ' |', justify = 'left',delim = ' | ', wrapfunc = lambda x: wrap_onspace (x,20) ))
136 
137 def toScreenSingleTag(taginfo):
138  '''
139  input: {run:(lumidataid,trgdataid,hltdataid,comment)}
140  '''
141  result=[]
142  labels=[('Run','Data Id','Insertion Time','Patch Comment')]
143  print(' == = ')
144  for run in sorted(taginfo):
145  (lumidataid,trgdataid,hltdataid,(ctimestr,comment))=taginfo[run]
146  payloadid='-'.join([str(lumidataid),str(trgdataid),str(hltdataid)])
147  result.append([str(run),payloadid,ctimestr,comment])
148  print(tablePrinter.indent (labels+result, hasHeader = True, separateRows = False,prefix = '| ', postfix = ' |', justify = 'left',delim = ' | ', wrapfunc = lambda x: wrap_onspace (x,25) ))
149 
150 def toScreenTotDelivered(lumidata,resultlines,scalefactor,irunlsdict=None,noWarning=True,toFile=None):
151  '''
152  inputs:
153  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)]}
154  resultlines [[resultrow1],[resultrow2],...,] existing result row
155  ('Run:Fill', 'N_LS','N_CMSLS','Delivered','UTCTime','E(GeV)')
156  irunlsdict: run/ls selection list. irunlsdict=None means no filter
157  '''
158  result=[]
159  totOldDeliveredLS=0
160  totOldCMSLS=0
161  totOldDelivered=0.0
162  datarunlsdict={}#{run:[ls,...]}from data. construct it only if there is irunlsdict to compare with
163  for r in resultlines:
164  runfillstr=r[0]
165  [runnumstr,fillnumstr]=runfillstr.split(':')
166  if irunlsdict and not noWarning:
167  if r[1] is not 'n/a':
168  datarunlsdict[int(runnumstr)]=[]
169  dl=0.0
170  if(r[3]!='n/a'): #delivered
171  dl=float(r[3])#in /ub because it comes from file!
172  (rr,lumiu)=CommonUtil.guessUnit(dl)
173  r[3]='%.3f'%(rr)+' ('+lumiu+')'
174  sls=0
175  if(r[1]!='n/a'): #n_ls
176  sls=int(r[1])
177  totcmsls=0
178  if(r[2]!='n/a'):#n_cmsls
179  totcmsls=int(r[2])
180  totOldDeliveredLS+=sls
181  totOldCMSLS+=totcmsls
182  totOldDelivered+=dl
183  if(r[5]!='n/a'): #egev
184  egv=float(r[5])
185  r[5]='%.1f'%egv
186  result.append(r)
187  totls=0
188  totcmsls=0
189  totdelivered=0.0
190  totaltable=[]
191  for run in lumidata.keys():
192  lsdata=lumidata[run]
193  if not lsdata:
194  result.append([str(run)+':0','n/a','n/a','n/a','n/a','n/a'])
195  if irunlsdict and not noWarning:
196  datarunlsdict[run]=None
197  continue
198  fillnum=0
199  if lsdata[0] and lsdata[0][9]:
200  fillnum=lsdata[0][9]
201  deliveredData=[]
202  nls=0
203  existdata=[]
204  selectedcmsls=[]
205  for perlsdata in lsdata:
206  lumilsnum=perlsdata[0]
207  cmslsnum=perlsdata[1]
208  if not noWarning:
209  if cmslsnum:
210  existdata.append(cmslsnum)
211  if irunlsdict and irunlsdict[run]:
212  if lumilsnum and lumilsnum in irunlsdict[run]:
213  deliveredData.append(perlsdata[5])
214  if cmslsnum:
215  selectedcmsls.append(cmslsnum)
216  else:
217  deliveredData.append(perlsdata[5])
218  if cmslsnum:
219  selectedcmsls.append(cmslsnum)
220  datarunlsdict[run]=existdata
221  nls=len(deliveredData)
222  ncmsls=0
223  if selectedcmsls:
224  ncmsls=len(selectedcmsls)
225  totcmsls+=ncmsls
226  totls+=nls
227  totlumi=sum(deliveredData)
228  totdelivered+=totlumi
229  (totlumival,lumiunit)=CommonUtil.guessUnit(totlumi)
230  beamenergyPerLS=[float(x[4]) for x in lsdata if x[3]=='STABLE BEAMS']
231  avgbeamenergy=0.0
232  if len(beamenergyPerLS):
233  avgbeamenergy=sum(beamenergyPerLS)/len(beamenergyPerLS)
234  runstarttime='n/a'
235  if lsdata[0] and lsdata[0][2]:
236  runstarttime=lsdata[0][2]
237  runstarttime=runstarttime.strftime("%m/%d/%y %H:%M:%S")
238  if not toFile:
239  result.append([str(run)+':'+str(fillnum),str(nls),str(ncmsls),'%.3f'%(totlumival*scalefactor)+' ('+lumiunit+')',runstarttime,'%.1f'%(avgbeamenergy)])
240  else:
241  result.append([str(run)+':'+str(fillnum),str(nls),str(ncmsls),(totlumi*scalefactor),runstarttime,'%.1f'%(avgbeamenergy)])
242  sortedresult=sorted(result,key=lambda x : int(str(x[0]).split(':')[0]))
243  #print 'sortedresult ',sortedresult
244  if not toFile:
245  labels = [('Run:Fill', 'N_LS','N_CMSLS','Delivered','UTCTime','E(GeV)')]
246  print(' == = ')
247  print(tablePrinter.indent (labels+sortedresult, hasHeader = True, separateRows = False,
248  prefix = '| ', postfix = ' |', justify = 'right',
249  delim = ' | ', wrapfunc = lambda x: wrap_onspace (x,40) ))
250  print(' == = Total : ')
251  (totalDeliveredVal,totalDeliveredUni)=CommonUtil.guessUnit(totdelivered+totOldDelivered)
252  totrowlabels = [('Delivered LS','Total CMS LS','Delivered('+totalDeliveredUni+')')]
253  totaltable.append([str(totls+totOldDeliveredLS),str(totcmsls+totOldCMSLS),'%.3f'%(totalDeliveredVal*scalefactor)])
254  print(tablePrinter.indent (totrowlabels+totaltable, hasHeader = True, separateRows = False, prefix = '| ',
255  postfix = ' |', justify = 'right', delim = ' | ',
256  wrapfunc = lambda x: wrap_onspace (x, 20)))
257  else:
258  fieldnames = ['Run:Fill', 'N_LS','N_CMSLS','Delivered(/ub)','UTCTime','E(GeV)']
259  filename=toFile
260  dumptocsv(fieldnames,sortedresult,filename)
261 
262 def toScreenOverview(lumidata,resultlines,scalefactor,irunlsdict=None,noWarning=True,toFile=None):
263  '''
264  input:
265  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)]}
266  resultlines [[resultrow1],[resultrow2],...,] existing result row
267  '''
268  result=[]
269 
270  totOldDeliveredLS=0
271  totOldSelectedLS=0
272  totOldDelivered=0.0
273  totOldRecorded=0.0
274 
275  totaltable=[]
276  totalDeliveredLS = 0
277  totalSelectedLS = 0
278  totalDelivered = 0.0
279  totalRecorded = 0.0
280  datarunlsdict={}#{run:[ls,...]}from data. construct it only if there is irunlsdict to compare with
281  for r in resultlines:
282  runfillstr=r[0]
283  [runnumstr,fillnumstr]=runfillstr.split(':')
284  if irunlsdict and not noWarning:
285  if r[1] is not 'n/a':
286  datarunlsdict[int(runnumstr)]=[]
287  dl=0.0
288  if(r[2]!='n/a'):
289  dl=float(r[2])#delivered in /ub because it comes from file!
290  (rr,lumiu)=CommonUtil.guessUnit(dl)
291  r[2]='%.3f'%(rr)+' ('+lumiu+')'
292  dls=0
293  if(r[1]!='n/a'):
294  dls=int(r[1])
295  totOldDeliveredLS+=dls
296  totOldDelivered+=dl
297  rls=0
298  if(r[3]!='n/a'):
299  rlsstr=r[3]
300  listcomp=rlsstr.split(', ')
301  for lstr in listcomp:
302  enddigs=lstr[1:-1].split('-')
303  lsmin=int(enddigs[0])
304  lsmax=int(enddigs[1])
305  rls=lsmax-lsmin+1
306  totOldSelectedLS+=rls
307  if(r[4]!='n/a'):
308  rcd=float(r[4])#recorded in /ub because it comes from file!
309  (rrcd,rlumiu)=CommonUtil.guessUnit(rcd)
310  r[4]='%.3f'%(rrcd)+' ('+rlumiu+')'
311  totOldRecorded+=rcd
312  result.append(r)
313  for run in lumidata.keys():
314  lsdata=lumidata[run]
315  if not lsdata:
316  result.append([str(run)+':0','n/a','n/a','n/a','n/a'])
317  if irunlsdict and irunlsdict[run] and not noWarning:
318  datarunlsdict[run]=None
319  continue
320  fillnum=0
321  if lsdata[0] and lsdata[0][10]:
322  fillnum=lsdata[0][10]
323  deliveredData=[]
324  recordedData=[]
325  nls=0
326  existdata=[]
327  selectedcmsls=[]
328  for perlsdata in lsdata:
329  lumilsnum=perlsdata[0]
330  cmslsnum=perlsdata[1]
331  if not noWarning:
332  if cmslsnum:
333  existdata.append(cmslsnum)
334  if irunlsdict and irunlsdict[run]:
335  if lumilsnum and lumilsnum in irunlsdict[run]:
336  if perlsdata[5] is not None:
337  deliveredData.append(perlsdata[5])
338  if perlsdata[6]:
339  recordedData.append(perlsdata[6])
340  selectedcmsls.append(lumilsnum)
341  else:
342  deliveredData.append(perlsdata[5])
343  if perlsdata[6]:
344  recordedData.append(perlsdata[6])
345  if cmslsnum:
346  selectedcmsls.append(cmslsnum)
347  datarunlsdict[run]=existdata
348  nls=len(deliveredData)
349  totdelivered=sum(deliveredData)
350  totalDelivered+=totdelivered
351  totalDeliveredLS+=len(deliveredData)
352  (totdeliveredlumi,deliveredlumiunit)=CommonUtil.guessUnit(totdelivered)
353  totrecorded=sum(recordedData)
354  totalRecorded+=totrecorded
355  (totrecordedlumi,recordedlumiunit)=CommonUtil.guessUnit(totrecorded)
356  totalSelectedLS+=len(selectedcmsls)
357  if len(selectedcmsls)==0:
358  selectedlsStr='n/a'
359  else:
360  selectedlsStr = CommonUtil.splitlistToRangeString(selectedcmsls)
361  if not toFile:
362  result.append([str(run)+':'+str(fillnum),str(nls),'%.3f'%(totdeliveredlumi*scalefactor)+' ('+deliveredlumiunit+')',selectedlsStr,'%.3f'%(totrecordedlumi*scalefactor)+' ('+recordedlumiunit+')'])
363  else:
364  result.append([str(run)+':'+str(fillnum),nls,totdelivered*scalefactor,selectedlsStr,totrecorded*scalefactor])
365  sortedresult=sorted(result,key=lambda x : int(str(x[0]).split(':')[0]))
366  if irunlsdict and not noWarning:
367  for run,cmslslist in irunlsdict.items():
368  if run not in datarunlsdict.keys() or datarunlsdict[run] is None:
369  sys.stdout.write('[WARNING] selected run '+str(run)+' not in lumiDB or has no qualified data\n')
370  continue
371  if cmslslist:
372  for ss in cmslslist:
373  if ss not in datarunlsdict[run]:
374  sys.stdout.write('[WARNING] lumi or trg for selected run/ls '+str(run)+' '+str(ss)+' not in lumiDB\n')
375  if not toFile:
376  labels = [('Run:Fill', 'Delivered LS', 'Delivered','Selected LS','Recorded')]
377  print(' == = ')
378  print(tablePrinter.indent (labels+sortedresult, hasHeader = True, separateRows = False,
379  prefix = '| ', postfix = ' |', justify = 'right',
380  delim = ' | ', wrapfunc = lambda x: wrap_onspace (x,20) ))
381  print(' == = Total : ')
382  (totalDeliveredVal,totalDeliveredUni)=CommonUtil.guessUnit(totalDelivered+totOldDelivered)
383  (totalRecordedVal,totalRecordedUni)=CommonUtil.guessUnit(totalRecorded+totOldRecorded)
384  totrowlabels = [('Delivered LS','Delivered('+totalDeliveredUni+')','Selected LS','Recorded('+totalRecordedUni+')')]
385  totaltable.append([str(totalDeliveredLS+totOldDeliveredLS),'%.3f'%(totalDeliveredVal*scalefactor),str(totalSelectedLS+totOldSelectedLS),'%.3f'%(totalRecordedVal*scalefactor)])
386  print(tablePrinter.indent (totrowlabels+totaltable, hasHeader = True, separateRows = False, prefix = '| ',
387  postfix = ' |', justify = 'right', delim = ' | ',
388  wrapfunc = lambda x: wrap_onspace (x, 20)))
389  else:
390  fieldnames = ['Run:Fill', 'DeliveredLS', 'Delivered(/ub)','SelectedLS','Recorded(/ub)']
391  filename=toFile
392  dumptocsv(fieldnames,sortedresult,filename)
393 
394 def toScreenLumiByLS(lumidata,resultlines,scalefactor,irunlsdict=None,noWarning=True,toFile=None):
395  '''
396  input:
397  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)]}
398  {run:None} None means no run in lumiDB,
399  {run:[]} [] means no lumi for this run in lumiDB
400  {run:[....deliveredlumi(5),recordedlumi(6)None]} means no trigger in lumiDB
401  {run:cmslsnum(1)==0} means either not cmslsnum or is cms but not selected, therefore set recordedlumi=0,efflumi=0
402  resultlines [[resultrow1],[resultrow2],...,] existing result row
403  '''
404  result=[]
405  totalrow = []
406 
407  totalDeliveredLS = 0
408  totalSelectedLS = 0
409  totalDelivered = 0.0
410  totalRecorded = 0.0
411 
412  totOldDeliveredLS = 0
413  totOldSelectedLS = 0
414  totOldDelivered = 0.0
415  totOldRecorded = 0.0
416 
417  maxlslumi = 0.0
418  datarunlsdict={}#{run:[ls,...]}from data. construct it only if there is irunlsdict to compare with
419  for rline in resultlines:
420  runfillstr=rline[0]
421  [runnumstr,fillnumstr]=runfillstr.split(':')
422  if irunlsdict and not noWarning:
423  if rline[1] is not 'n/a':
424  datarunlsdict[int(runnumstr)]=[]
425  myls=rline[1]
426  if myls!='n/a':
427  [luls,cmls]=myls.split(':')
428  totOldDeliveredLS+=1
429  if cmls!='0':
430  totOldSelectedLS+=1
431  if irunlsdict and not noWarning:
432  datarunlsdict[int(runnumstr)].append(int(myls))
433  dl=rline[5]
434  if rline[5]!='n/a':
435  dl=float(rline[5])#delivered in /ub
436  if dl>maxlslumi: maxlslumi=dl
437  rline[5]=dl
438  totOldDelivered+=dl
439  rl=rline[6]
440  if rline[6]!='n/a':
441  rl=float(rline[6])#recorded in /ub
442  rline[6]=rl
443  totOldRecorded+=rl
444  result.append(rline)
445 
446  for run in lumidata.keys():
447  lsdata=lumidata[run]
448  if not lsdata:
449  #result.append([str(run),'n/a','n/a','n/a','n/a','n/a','n/a','n/a'])
450  if irunlsdict and irunlsdict[run] and not noWarning:
451  datarunlsdict[run]=None
452  #print '[WARNING] selected but no lumi data for run '+str(run)
453  continue
454  fillnum=0
455  if lsdata[0] and lsdata[0][10]:
456  fillnum=lsdata[0][10]
457  existdata=[]
458  #if irunlsdict and not noWarning:
459  # existdata=[x[1] for x in rundata if x[1] ]
460  # datarunlsdict[run]=existdata
461  for perlsdata in lsdata:
462  lumilsnum=perlsdata[0]
463  cmslsnum=perlsdata[1]#triggered ls
464  if not noWarning:
465  if cmslsnum:
466  existdata.append(cmslsnum)
467  ts=perlsdata[2]
468  bs=perlsdata[3]
469  begev=perlsdata[4]
470  deliveredlumi=perlsdata[5]
471  npu=perlsdata[11]
472  if deliveredlumi>maxlslumi: maxlslumi=deliveredlumi
473  recordedlumi=0.
474  if perlsdata[6]:
475  recordedlumi=perlsdata[6]
476  if irunlsdict and irunlsdict[run]:
477  if run in irunlsdict and lumilsnum in irunlsdict[run]:
478  result.append([str(run)+':'+str(fillnum),str(lumilsnum)+':'+str(cmslsnum),ts.strftime('%m/%d/%y %H:%M:%S'),bs,'%.1f'%begev,deliveredlumi,recordedlumi,npu])
479  totalDelivered+=deliveredlumi
480  totalRecorded+=recordedlumi
481  totalDeliveredLS+=1
482  totalSelectedLS+=1
483  else:
484  result.append([str(run)+':'+str(fillnum),str(lumilsnum)+':'+str(cmslsnum),ts.strftime('%m/%d/%y %H:%M:%S'),bs,'%.1f'%begev,deliveredlumi,recordedlumi,npu])
485  totalDelivered+=deliveredlumi
486  totalRecorded+=recordedlumi
487  totalDeliveredLS+=1
488  if cmslsnum :
489  totalSelectedLS+=1
490  datarunlsdict[run]=existdata
491  sortedresult=sorted(result,key=lambda x : int(str(x[0]).split(':')[0]))
492  if irunlsdict and not noWarning:
493  for run,cmslslist in irunlsdict.items():
494  if run not in datarunlsdict.keys() or datarunlsdict[run] is None:
495  sys.stdout.write('[WARNING] selected run '+str(run)+' not in lumiDB or has no qualified data\n')
496  continue
497  if cmslslist:
498  for ss in cmslslist:
499  if ss not in datarunlsdict[run]:
500  sys.stdout.write('[WARNING] lumi or trg for selected run/ls '+str(run)+' '+str(ss)+' not in lumiDB\n')
501  if not toFile:
502  (lsunitstring,unitdenomitor)=CommonUtil.lumiUnitForPrint(maxlslumi*scalefactor)
503  labels = [ ('Run:Fill','LS','UTCTime','Beam Status','E(GeV)','Del('+lsunitstring+')','Rec('+lsunitstring+')','avgPU') ]
504  perlsresult=[]
505  for entry in sortedresult:
506  delumi=entry[5]
507  if delumi!='n/a':
508  delumi='%.3f'%float(float(delumi*scalefactor)/float(unitdenomitor))
509  reclumi=entry[6]
510  if reclumi!='n/a':
511  reclumi='%.3f'%float(float(reclumi*scalefactor)/float(unitdenomitor))
512  avgPU=entry[7]
513  if avgPU!='n/a':
514  if avgPU>0:
515  avgPU='%.3f'%avgPU
516  else:
517  avgPU='0'
518  perlsresult.append([entry[0],entry[1],entry[2],entry[3],entry[4],delumi,reclumi,avgPU])
519  totdeliveredlumi=0.0
520  deliveredlumiunit='/ub'
521  (totdeliveredlumi,deliveredlumiunit)=CommonUtil.guessUnit((totalDelivered+totOldDelivered)*scalefactor)
522  totrecordedlumi=0.0
523  recordedlumiunit='/ub'
524  (totrecordedlumi,recordedlumiunit)=CommonUtil.guessUnit((totalRecorded+totOldRecorded)*scalefactor)
525  lastrowlabels = [ ('Delivered LS','Selected LS', 'Delivered('+deliveredlumiunit+')', 'Recorded('+recordedlumiunit+')')]
526  totalrow.append ([str(totalDeliveredLS+totOldDeliveredLS),str(totalSelectedLS+totOldSelectedLS),'%.3f'%(totdeliveredlumi),'%.3f'%(totrecordedlumi)])
527  print(' == = ')
528  print(tablePrinter.indent (labels+perlsresult, hasHeader = True, separateRows = False, prefix = '| ',
529  postfix = ' |', justify = 'right', delim = ' | ',
530  wrapfunc = lambda x: wrap_onspace_strict (x, 22)))
531  print(' == = Total : ')
532  print(tablePrinter.indent (lastrowlabels+totalrow, hasHeader = True, separateRows = False, prefix = '| ',
533  postfix = ' |', justify = 'right', delim = ' | ',
534  wrapfunc = lambda x: wrap_onspace (x, 20)))
535  else:
536  fieldnames=['Run:Fill','LS','UTCTime','Beam Status','E(GeV)','Delivered(/ub)','Recorded(/ub)','avgPU']
537  filename=toFile
538  dumptocsv(fieldnames,sortedresult,filename)
539 
540 def toScreenLSEffective(lumidata,resultlines,scalefactor,irunlsdict=None,noWarning=True,toFile=None):
541  '''
542  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)]}
543  '''
544  result=[]#[run,ls,hltpath,l1bitname,hltpresc,l1presc,efflumi]
545  totalrow=[]
546  totSelectedLSDict={}
547  totRecordedDict={}
548  totEffectiveDict={}
549 
550  totOldSelectedLSDict={}
551  totOldRecordedDict={}
552  totOldEffectiveDict={}
553 
554  maxlslumi = 0.0
555  datarunlsdict={}#{run:[ls,...]}from data. construct it only if there is irunlsdict to compare with
556  for rline in resultlines:
557  runfillstr=rline[0]
558  [runnumstr,fillnumstr]=runfillstr.split(':')
559  if irunlsdict and not noWarning:
560  if rline[1] is not 'n/a':
561  datarunlsdict[int(runnumstr)]=[]
562  myls=rline[1]
563  mypath=rline[2]
564 
565  if myls and myls!='n/a' and mpath and mpath!='n/a':
566  totOldSelectedLSDict[mypath]=0
567  totOldRecordedDict[mypath]=0.
568  totOldEffectiveDict[mypath]=0.
569  if myls!='n/a':
570  [luls,cmls]=myls.split(':')
571  if cmls!='0':
572  if mypath in totOldSelectedLSDict:
573  totOldSelectedLSDict[mypath]+=1
574  if irunlsdict and not noWarning:
575  datarunlsdict[int(runnumstr)].append(int(myls))
576  myrecorded=0.
577  if rline[6]!='n/a':
578  myrecorded=float(rline[6])
579  if myrecorded>maxlslumi:maxlslumi=myrecorded
580  if mypath in totOldRecordedDict:
581  totOldRecordedDict[mypath]+=myrecorded
582  rline[6]=myrecorded
583  myeff={}
584  if rline[7]!='n/a':
585  myeff=float(rline[7])
586  if mypath in totOldEffectiveDict:
587  totOldEffectiveDict[mypath]+=myeff
588  rline[7]=myeff
589  result.append(rline)
590 
591  for run in lumidata.keys():#loop over runs
592  lsdata=lumidata[run]
593  if not lsdata:
594  result.append([str(run),'n/a','n/a','n/a','n/a','n/a','n/a','n/a'])
595  if irunlsdict and irunlsdict[run] and not noWarning:
596  datarunlsdict[run]=None
597  continue
598  fillnum=0
599  if lsdata[0] and lsdata[0][11]:
600  fillnum=lsdata[0][11]
601  datarunlsdict[run]=[]
602  for thisls in lsdata:
603  lumilsnum=thisls[0]
604  cmslsnum=thisls[1]#triggered ls
605  if not cmslsnum: continue
606  efflumiDict=thisls[8]# this ls has no such path?
607  recordedlumi=0.
608  if thisls[6]:
609  recordedlumi=thisls[6]
610  if recordedlumi>maxlslumi:maxlslumi=recordedlumi
611  if not efflumiDict:
612  result.append([str(run)+':'+str(fillnum),str(lumilsnum)+':'+str(cmslsnum),'n/a','n/a','n/a','n/a',recordedlumi,'n/a'])
613  continue
614 
615  for hltpathname in sorted(efflumiDict):
616  if hltpathname and hltpathname !='n/a' :
617  if hltpathname not in totRecordedDict:
618  totRecordedDict[hltpathname]=0.
619  if hltpathname not in totSelectedLSDict:
620  totSelectedLSDict[hltpathname]=0
621  if hltpathname not in totEffectiveDict:
622  totEffectiveDict[hltpathname]=0.
623  totSelectedLSDict[hltpathname]+=1
624  totRecordedDict[hltpathname]+=recordedlumi
625  pathdata=efflumiDict[hltpathname]
626  l1name=pathdata[0]
627  cleanl1name='n/a'
628  if l1name:
629  cleanl1name=l1name.replace('"','')
630  l1presc='0'
631  if pathdata[1]:
632  l1presc=str(pathdata[1])
633  hltpresc='0'
634  if pathdata[2]:
635  hltpresc=str(pathdata[2])
636  lumival=0.
637  if pathdata[3]:
638  lumival=pathdata[3]
639  result.append([str(run)+':'+str(fillnum),str(lumilsnum)+':'+str(cmslsnum),hltpathname,cleanl1name,hltpresc,l1presc,recordedlumi,lumival])
640  if hltpathname and hltpathname !='n/a' :
641  totEffectiveDict[hltpathname]+=lumival
642  if irunlsdict and not noWarning:
643  datarunlsdict[run].append(int(cmslsnum))
644  sortedresult=sorted(result,key=lambda x : int(str(x[0]).split(':')[0]))
645  if irunlsdict and not noWarning:
646  for run,cmslslist in irunlsdict.items():
647  if run not in datarunlsdict.keys() or datarunlsdict[run] is None:
648  sys.stdout.write('[WARNING] selected run '+str(run)+' not in lumiDB or has no HLT data\n')
649  continue
650  if cmslslist:
651  for ss in cmslslist:
652  if ss not in datarunlsdict[run]:
653  sys.stdout.write('[WARNING] selected run/ls '+str(run)+' '+str(ss)+' not in lumiDB or has no qualified data\n')
654 
655  if not toFile:
656  (lsunitstring,unitdenomitor)=CommonUtil.lumiUnitForPrint(maxlslumi*scalefactor)
657  labels = [('Run:Fill','LS','HLTpath','L1bit','HLTpresc','L1presc','Recorded('+lsunitstring+')','Effective('+lsunitstring+')')]
658  perlsresult=[]
659  for entry in sortedresult:
660  reclumi=entry[6]
661  if reclumi!='n/a':
662  reclumi='%.3f'%float(float(reclumi*scalefactor)/float(unitdenomitor))
663  efflumi=entry[7]
664  if efflumi!='n/a':
665  efflumi='%.3f'%float(float(efflumi*scalefactor)/float(unitdenomitor))
666  perlsresult.append([entry[0],entry[1],entry[2],entry[3],entry[4],entry[5],reclumi,efflumi])
667  print(' == = ')
668  print(tablePrinter.indent (labels+perlsresult, hasHeader = True, separateRows = False,
669  prefix = '| ', postfix = ' |', justify = 'right',
670  delim = ' | ', wrapfunc = lambda x: wrap_onspace_strict(x,25) ))
671  for mpath in sorted(totRecordedDict):
672  totSelectedLS=totSelectedLSDict[mpath]
673  if mpath in totOldSelectedLSDict:
674  totSelectedLS+=totOldSelectedLS[mpath]
675  totRecorded=totRecordedDict[mpath]
676  if mpath in totOldRecordedDict:
677  totRecorded+=totOldRecorded[mpath]
678  totRecorded=float(totRecorded*scalefactor)/float(unitdenomitor)
679  totEffective=totEffectiveDict[mpath]
680  if mpath in totOldEffectiveDict:
681  totEffective+=totOldEffective[mpath]
682  totEffective=float(totEffective*scalefactor)/float(unitdenomitor)
683  totalrow.append([str(totSelectedLS),mpath,'%.3f'%(totRecorded),'%.3f'%(totEffective)])
684  lastrowlabels = [ ('Selected LS','HLTPath','Recorded('+lsunitstring+')','Effective('+lsunitstring+')')]
685  print(' == = Total : ')
686  print(tablePrinter.indent (lastrowlabels+totalrow, hasHeader = True, separateRows = False, prefix = '| ',
687  postfix = ' |', justify = 'right', delim = ' | ',
688  wrapfunc = lambda x: wrap_onspace (x, 20)))
689  else:
690  fieldnames = ['Run:Fill','LS','HLTpath','L1bit','HLTpresc','L1presc','Recorded(/ub)','Effective(/ub)']
691  filename=toFile
692  dumptocsv(fieldnames,sortedresult,filename)
693 
694 def toScreenTotEffective(lumidata,resultlines,scalefactor,irunlsdict=None,noWarning=True,toFile=None):
695 
696  '''
697  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)}
698  screen Run,SelectedLS,Recorded,HLTPath,L1Bit,Effective
699  '''
700  result=[]#[run,selectedlsStr,recordedofthisrun,hltpath,l1bit,efflumi]
701 
702  totdict={}#{hltpath:[nls,toteff]}
703  selectedcmsls=[]
704  alltotrecorded=0.0
705  alleffective=0.0
706  recordedPerpathPerrun={}#{path:{run:recorded}}
707  selectedPerpathPerrun={}#{path:{run:totselected}}
708  datarunlsdict={}#{run:[ls,...]}from data. construct it only if there is irunlsdict to compare with
709  for rline in resultlines:
710  runfillstr=rline[0]
711  [runnumstr,fillnumstr]=runfillstr.split(':')
712  myls=rline[1]
713  if irunlsdict and not noWarning:
714  if myls is not 'n/a':
715  datarunlsdict[int(runnumstr)]=[]
716  mypath=rline[3]
717  if mypath!='n/a':
718  mypath=mypath.split('(')[0]
719  if mypath not in totdict:
720  totdict[mypath]=[0,0.0]
721  recordedPerpathPerrun[mypath]={}
722  selectedPerpathPerrun[mypath]={}
723  if myls!='n/a':
724  listcomp=myls.split(', ')
725  for lstr in listcomp:
726  enddigs=lstr[1:-1].split('-')
727  lsmin=int(enddigs[0])
728  lsmax=int(enddigs[1])
729  rls=lsmax-lsmin+1
730  totdict[mypath][0]+=rls
731  selectedPerrun[mypath].setdefault(int(myrun),totdict[mypath][0])
732  myrecorded=rline[2]
733  if myrecorded!='n/a':
734  recordedPerpathPerrun[mypath].setdefault(int(myrun),float(myrecorded))
735  (rr,lumiu)=CommonUtil.guessUnit(float(myrecorded))
736  rline[2]='%.3f'%(rr)+' ('+lumiu+')'
737  myeff=rline[5]
738  if myeff!='n/a':
739  reff=float(myeff)
740  (rr,lumiu)=CommonUtil.guessUnit(float(reff))
741  rline[5]='%.3f'%(rr)+' ('+lumiu+')'
742  totdict[mypath][1]+=reff
743  result.append(rline)
744  for run in lumidata.keys():#loop over runs
745  lsdata=lumidata[run]
746  hprescdict={}
747  lprescdict={}
748  if not lsdata:
749  result.append([str(run),'n/a','n/a','n/a','n/a','n/a'])
750  if irunlsdict and irunlsdict[run] and not noWarning:
751  datarunlsdict[run]=None
752  continue
753  fillnum=0
754  if lsdata[0] and lsdata[0][11]:
755  fillnum=lsdata[0][11]
756  selectedcmsls=[x[1] for x in lsdata if x[1]]
757  totefflumiDict={}
758  totrecorded=0.0
759  toteffective=0.0
760  pathmap={}#{hltpathname:1lname}
761  existdata=[]
762  for thisls in lsdata:
763  cmslsnum=thisls[1]
764  if not noWarning:
765  if cmslsnum:
766  existdata.append(cmslsnum)
767  efflumiDict=thisls[8]# this ls has no such path?
768  recordedlumi=0.0
769  if thisls[6]:
770  recordedlumi=thisls[6]
771  totrecorded+=recordedlumi
772  if not efflumiDict:#no hltdata for this LS
773  lumival=0.
774  if cmslsnum in selectedcmsls:
775  selectedcmsls.remove(cmslsnum)
776  continue
777  for hltpathname in sorted(efflumiDict):
778  pathdata=efflumiDict[hltpathname]
779  if hltpathname not in totefflumiDict:
780  totefflumiDict[hltpathname]=0.0
781  pathmap[hltpathname]='n/a'
782  l1name=pathdata[0]
783  l1presc=pathdata[1]
784  hltpresc=pathdata[2]
785  lumival=pathdata[3]
786  recordedPerpathPerrun.setdefault(hltpathname,{})
787  selectedPerpathPerrun.setdefault(hltpathname,{})
788  if hltpathname not in totdict:
789  totdict[hltpathname]=[0,0.0]
790  if l1presc is None or hltpresc is None:#if found all null prescales and if it is in the selectedcmsls, remove it because incomplete
791  if cmslsnum in selectedcmsls:
792  selectedcmsls.remove(cmslsnum)
793  else:
794  if hltpathname not in hprescdict:
795  hprescdict[hltpathname]=[]
796  hprescdict[hltpathname].append(hltpresc)
797  if l1name not in lprescdict:
798  lprescdict[l1name]=[]
799  lprescdict[l1name].append(l1presc)
800  if cmslsnum!=0:
801  totdict[hltpathname][0]+=1
802  if lumival:
803  totdict[hltpathname][1]+=lumival
804  totefflumiDict[hltpathname]+=lumival
805  pathmap[hltpathname]=l1name
806  recordedPerpathPerrun[hltpathname][run]=totrecorded
807  selectedPerpathPerrun[hltpathname][run]=len(selectedcmsls)
808  if len(selectedcmsls)==0:
809  selectedlsStr='n/a'
810  else:
811  selectedlsStr = CommonUtil.splitlistToRangeString(selectedcmsls)
812  if irunlsdict and not noWarning:
813  datarunlsdict[run]=selectedcmsls
814 
815  for name in sorted(totefflumiDict):
816  lname=pathmap[name]
817  totrecordedinrun=recordedPerpathPerrun[name][run]
818  hprescs=list(set(hprescdict[name]))
819  hprescStr='('+','.join(['%d'%(x) for x in hprescs])+')'
820  (totrecval,totrecunit)=CommonUtil.guessUnit(totrecordedinrun*scalefactor)
821  effval='n/a'
822 
823  effvalStr='n/a'
824  lprescStr='n/a'
825  cleanlname=''
826  if lname!='n/a':
827  effval=totefflumiDict[name]*scalefactor
828  lprescs=list(set(lprescdict[lname]))
829  lprescStr='('+','.join(['%d'%(x) for x in lprescs])+')'
830  cleanlname=lname.replace('"','')
831  (efflumival,efflumiunit)=CommonUtil.guessUnit(effval)
832  effvalStr='%.3f'%(efflumival)+'('+efflumiunit+')'
833  if not toFile:
834  result.append([str(run)+':'+str(fillnum),selectedlsStr,'%.3f'%(totrecval)+'('+totrecunit+')',name+hprescStr,cleanlname+lprescStr,effvalStr])
835  else:
836  result.append([str(run)+':'+str(fillnum),selectedlsStr,totrecordedinrun*scalefactor,name+hprescStr,cleanlname+lprescStr,effval])
837 
838  if irunlsdict and not noWarning:
839  for run,cmslslist in irunlsdict.items():
840  if run not in datarunlsdict.keys() or datarunlsdict[run] is None:
841  sys.stdout.write('[WARNING] selected run '+str(run)+' not in lumiDB or has no HLT data\n')
842  continue
843  if cmslslist:
844  for ss in cmslslist:
845  if ss not in datarunlsdict[run]:
846  sys.stdout.write('[WARNING] selected run/ls '+str(run)+' '+str(ss)+' not in lumiDB or has no HLT data\n')
847 
848  sortedresult=sorted(result,key=lambda x : int(str(x[0]).split(':')[0]))
849 
850  if not toFile:
851  labels = [('Run:Fill','SelectedLS','Recorded','HLTpath(Presc)','L1bit(Presc)','Effective')]
852  print(' == = ')
853  print(tablePrinter.indent (labels+sortedresult, hasHeader = True, separateRows = False,
854  prefix = '| ', postfix = ' |', justify = 'right',
855  delim = ' | ', wrapfunc = lambda x: wrap_onspace_strict(x,22) ))
856  print(' == = Total : ')
857  lastrowlabels=[('HLTPath','SelectedLS','Recorded','Effective')]
858  totresult=[]
859  for hname in sorted(totdict):
860  hdata=totdict[hname]
861  totnls=hdata[0]
862  (toteffval,toteffunit)=CommonUtil.guessUnit(hdata[1]*scalefactor)
863  alltotrecorded=0.0
864  selectedThispath=selectedPerpathPerrun[hname]
865  for runnumber,nselected in selectedThispath.items():
866  if nselected==0: continue
867  alltotrecorded+=recordedPerpathPerrun[hname][runnumber]
868  (alltotrecordedVal,alltotrecordedunit)=CommonUtil.guessUnit(alltotrecorded*scalefactor)
869  totresult.append([hname,str(totnls),'%.3f'%(alltotrecordedVal)+'('+alltotrecordedunit+')','%.3f'%(toteffval)+'('+toteffunit+')'])
870  print(tablePrinter.indent (lastrowlabels+totresult, hasHeader = True, separateRows = False,prefix = '| ', postfix = ' |', justify = 'right',
871  delim = ' | ', wrapfunc = lambda x: wrap_onspace (x,20) ))
872  else:
873  fieldnames=['Run:Fill','SelectedLS','Recorded','HLTpath(Presc)','L1bit(Presc)','Effective(/ub)']
874  filename=toFile
875  dumptocsv(fieldnames,sortedresult,filename)
876 
877 def toCSVLumiByLSXing(lumidata,scalefactor,filename,irunlsdict=None,noWarning=True):
878  '''
879  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  output:
881  fieldnames=['Run:Fill','LS','UTCTime','Delivered(/ub)','Recorded(/ub)','BX']
882  '''
883  result=[]
884  assert(filename)
885  fieldnames=['run:fill','ls','UTCTime','delivered(/ub)','recorded(/ub)','[bx,Hz/ub]']
886  datarunlsdict={}#{run:[ls,...]}from data. construct it only if there is irunlsdict to compare with
887  for run in sorted(lumidata):
888  rundata=lumidata[run]
889  if rundata is None:
890  result.append([str(run)+':0','n/a','n/a','n/a','n/a','n/a'])
891  if irunlsdict and irunlsdict[run]:
892  print('[WARNING] selected but no lumi data for run '+str(run))
893  continue
894  fillnum=0
895  if rundata and rundata[0][10]:
896  fillnum=rundata[0][10]
897  if irunlsdict and not noWarning:
898  existdata=[x[1] for x in rundata if x[1] ]
899  datarunlsdict[run]=existdata
900  for lsdata in rundata:
901  lumilsnum=lsdata[0]
902  cmslsnum=0
903  if lsdata and lsdata[1]:
904  cmslsnum=lsdata[1]
905  tsStr='n/a'
906  if lsdata and lsdata[2]:
907  ts=lsdata[2]
908  tsStr=ts.strftime('%m/%d/%y %H:%M:%S')
909  deliveredlumi=0.
910  if lsdata[5]:
911  deliveredlumi=lsdata[5]
912  recordedlumi=0.
913  if lsdata[6]:
914  recordedlumi=lsdata[6]
915  (bxidxlist,bxvaluelist,bxerrorlist)=lsdata[8]
916  if irunlsdict and irunlsdict[run]:
917  if run in irunlsdict and cmslsnum in irunlsdict[run]:
918  if bxidxlist and bxvaluelist:
919  bxresult=[]
920  bxinfo=CommonUtil.transposed([bxidxlist,bxvaluelist])
921  bxresult=CommonUtil.flatten([str(run)+':'+str(fillnum),str(lumilsnum)+':'+str(cmslsnum),tsStr,deliveredlumi*scalefactor,recordedlumi*scalefactor,bxinfo])
922  result.append(bxresult)
923  else:
924  result.append([str(run)+':'+str(fillnum),str(lumilsnum)+':'+str(cmslsnum),tsStr,deliveredlumi*scalefactor,recordedlumi*scalefactor])
925  else:
926  if bxidxlist and bxvaluelist:
927  bxresult=[]
928  bxinfo=CommonUtil.transposed([bxidxlist,bxvaluelist])
929  bxresult=CommonUtil.flatten([str(run)+':'+str(fillnum),str(lumilsnum)+':'+str(cmslsnum),tsStr,deliveredlumi*scalefactor,recordedlumi*scalefactor,bxinfo])
930  result.append(bxresult)
931  else:
932  result.append([str(run)+':'+str(fillnum),str(lumilsnum)+':'+str(cmslsnum),tsStr,deliveredlumi*scalefactor,recordedlumi*scalefactor])
933  r=None
934  if filename.upper()=='STDOUT':
935  r=sys.stdout
936  r.write(','.join(fieldnames)+'\n')
937  for l in result:
938  r.write(str(l)+'\n')
939  else:
940  r=csvReporter.csvReporter(filename)
941  r.writeRow(fieldnames)
942  r.writeRows(result)
943 
944 def toScreenLSTrg(trgdata,iresults=[],irunlsdict=None,noWarning=True,toFile=None,withoutmask=False):
945  '''
946  input:{run:[[cmslsnum,deadfrac,deadtimecount,bitzero_count,bitzero_prescale,[(name,count,presc,mask),]],..]
947  '''
948  result=[]
949  datarunlsdict={}#{run:[ls,...]}from data. construct it only if there is irunlsdict to compare with
950  for rline in iresults:
951  runnumStr=rline[0]
952  cmslsnumStr=rline[1]
953  if irunlsdict and not noWarning:
954  if runnumStr is not 'n/a' and int(runnumStr) not in datarunlsdict:
955  datarunlsdict[int(runnumstr)]=[]
956  if cmslsnumStr!='n/a':
957  datarunlsdict[int(runnumStr)].append(int(cmslsnumStr))
958  result.append(rline)
959  for run in trgdata.keys():
960  rundata=trgdata[run]
961  if not rundata:
962  ll=[str(run),'n/a','n/a','n/a']
963  result.append(ll)
964  if irunlsdict and not noWarning:
965  print('[WARNING] selected but no trg data for run '+str(run))
966  continue
967  if irunlsdict and not noWarning:
968  existdata=[x[0] for x in rundata if x[0] ]
969  datarunlsdict[run]=existdata
970  deadfrac=0.0
971  bitdataStr='n/a'
972  for lsdata in rundata:
973  cmslsnum=lsdata[0]
974  deadfrac=lsdata[1]
975  deadcount=lsdata[2]
976  bitdata=lsdata[5]# already sorted by name
977  if bitdata:
978  if withoutmask:
979  flatbitdata=["("+x[0]+',%d'%x[1]+',%d'%x[2]+")" for x in bitdata if x[0]!='False']
980  bitdataStr=' '.join(flatbitdata)
981  else:
982  #consider trg mask by default
983  flatbitdata=["("+x[0]+',%d'%x[1]+',%d'%x[2]+")" for x in bitdata if x[0]!='False' and x[3]]
984  bitdataStr=' '.join(flatbitdata)
985  if irunlsdict and irunlsdict[run]:
986  if run in irunlsdict and cmslsnum in irunlsdict[run]:
987  result.append([str(run),str(cmslsnum),'%.4f'%(deadfrac),bitdataStr])
988  else:
989  result.append([str(run),str(cmslsnum),'%.4f'%(deadfrac),bitdataStr])
990  if irunlsdict and not noWarning:
991  for run,cmslslist in irunlsdict.items():
992  if run not in datarunlsdict.keys() or datarunlsdict[run] is None:
993  sys.stdout.write('[WARNING] selected run '+str(run)+' not in lumiDB or has no qualified data\n')
994  continue
995  if cmslslist:
996  for ss in cmslslist:
997  if ss not in datarunlsdict[run]:
998  sys.stdout.write('[WARNING] selected run/ls '+str(run)+' '+str(ss)+' not in lumiDB\n')
999 
1000  if not toFile:
1001  print(' == = ')
1002  labels = [('Run', 'LS', 'dfrac','(bitname,count,presc)')]
1003  print(tablePrinter.indent (labels+result, hasHeader = True, separateRows = False,prefix = '| ', postfix = ' |', justify = 'left',delim = ' | ', wrapfunc = lambda x: wrap_onspace (x,70) ))
1004  else:
1005  filename=toFile
1006  fieldnames=['Run','LS','dfrac','(bitname,count,presc)']
1007  dumptocsv(fieldnames,result,filename)
1008 
1009 def toScreenLSHlt(hltdata,iresults=[],toFile=None):
1010  '''
1011  input:{runnumber:[(cmslsnum,[(hltpath,hltprescale,l1pass,hltaccept),...]),(cmslsnum,[])})}
1012  '''
1013  result=[]
1014  for r in iresults:
1015  result.append(r)
1016  for run in hltdata.keys():
1017  if hltdata[run] is None:
1018  ll=[str(run),'n/a','n/a','n/a','n/a','n/a']
1019  continue
1020  perrundata=hltdata[run]
1021  for lsdata in perrundata:
1022  cmslsnum=lsdata[0]
1023  allpathinfo=lsdata[1]
1024  allpathresult=[]
1025  for thispathinfo in allpathinfo:
1026  thispathname=thispathinfo[0]
1027  thispathpresc=thispathinfo[1]
1028  thisl1pass=None
1029  thishltaccept=None
1030  thispathresult=[]
1031  thispathresult.append(thispathname)
1032  if thispathpresc is None:
1033  thispathpresc='n/a'
1034  else:
1035  thispathresult.append('%d'%thispathpresc)
1036  thisl1pass=thispathinfo[2]
1037  if thispathinfo[2] is None:
1038  thispathresult.append('n/a')
1039  else:
1040  thispathresult.append('%d'%thisl1pass)
1041  thishltaccept=thispathinfo[3]
1042  if thispathinfo[3] is None:
1043  thispathresult.append('n/a')
1044  else:
1045  thispathresult.append('%d'%thishltaccept)
1046 
1047  thispathresultStr='('+','.join(thispathresult)+')'
1048  allpathresult.append(thispathresultStr)
1049  result.append([str(run),str(cmslsnum),', '.join(allpathresult)])
1050 
1051  if not toFile:
1052  print(' == = ')
1053  labels = [('Run', 'LS', '(hltpath,presc,l1pass,hltaccept)')]
1054  print(tablePrinter.indent (labels+result, hasHeader = True, separateRows = False,
1055  prefix = '| ', postfix = ' |', justify = 'left',
1056  delim = ' | ', wrapfunc = lambda x: wrap_onspace (x,70) ))
1057  else:
1058  fieldnames=['Run','LS','(hltpath,presc,l1pass,hltaccept)']
1059  filename=toFile
1060  dumptocsv(fieldnames,result,filename)
1061 
1062 def toScreenConfHlt(hltconfdata,iresults=[],toFile=None):
1063  '''
1064  input : {runnumber,[(hltpath,l1seedexpr,l1bitname),...]}
1065  '''
1066  result=[]
1067  for r in iresults:
1068  pp=r[1]
1069  pp=' '.join([pp[i:i+25] for i in range(0,len(pp),25)])
1070  sdepr=r[2]
1071  sdepr=' '.join([sdepr[i:i+25] for i in range(0,len(sdepr),25)])
1072  lb=r[3]
1073  lb=' '.join([lb[i:i+25] for i in range(0,len(lb),25)])
1074  result.append([r[0],pp,sdepr,lb])
1075  for run in sorted(hltconfdata):
1076  pathdata=hltconfdata[run]
1077  if pathdata is None:
1078  result.append([str(run),'n/a','n/a','n/a'])
1079  continue
1080  for thispathinfo in pathdata:
1081  thispath=thispathinfo[0]
1082  thispath=' '.join([thispath[i:i+25] for i in range(0,len(thispath),25)])
1083  thisseed=thispathinfo[1]
1084  thisseed=' '.join([thisseed[i:i+25] for i in range(0,len(thisseed),25)]).replace('"','')
1085  thisbit=thispathinfo[2]
1086  if not thisbit:
1087  thisbit='n/a'
1088  else:
1089  thisbit=' '.join([thisbit[i:i+25] for i in range(0,len(thisbit),25)]).replace('"','')
1090  result.append([str(run),thispath,thisseed,thisbit])
1091  if not toFile:
1092  labels=[('Run','hltpath','l1seedexpr','l1bit')]
1093  print(' == = ')
1094  print(tablePrinter.indent (labels+result, hasHeader = True, separateRows = False,
1095  prefix = '| ', postfix = ' |', justify = 'left',
1096  delim = ' | ', wrapfunc = lambda x: wrap_onspace(x,25) ))
1097  else:
1098  filename=toFile
1099  fieldnames=['Run','hltpath','l1seedexpr','l1bit']
1100  dumptocsv(fieldnames,sortedresult,filename)
1101 
1102 def toScreenLSBeam(beamdata,iresults=[],dumpIntensity=False,toFile=None):
1103  '''
1104  input: {run:[(lumilsnum(0),cmslsnum(1),beamstatus(2),beamenergy(3),ncollidingbunches(4),beaminfolist(4)),..]}
1105  beaminfolist:[(bxidx,b1,b2)]
1106  '''
1107  result=[]
1108  for rline in iresults:
1109  result.append(rline)
1110  for run in sorted(beamdata):
1111  perrundata=beamdata[run]
1112  if perrundata is None:
1113  ll=[str(run),'n/a','n/a']
1114  if dumpIntensity:
1115  ll.extend('n/a')
1116  continue
1117  for lsdata in perrundata:
1118  lumilsnum=lsdata[0]
1119  cmslsnum=lsdata[1]
1120  beamstatus=lsdata[2]
1121  beamenergy=lsdata[3]
1122  ncollidingbx=lsdata[4]
1123  if not dumpIntensity:
1124  result.append([str(run),str(lumilsnum)+':'+str(cmslsnum),beamstatus,'%.2f'%beamenergy,str(ncollidingbx)])
1125  continue
1126  allbxinfo=lsdata[5]
1127  allbxresult=[]
1128  for thisbxinfo in allbxinfo:
1129  thisbxresultStr='(n/a,n/a,n/a,n/a)'
1130  bxidx=thisbxinfo[0]
1131  b1=thisbxinfo[1]
1132  b2=thisbxinfo[2]
1133  thisbxresultStr=','.join(['%d'%bxidx,'%.3e'%b1,'%.3e'%b2])
1134  allbxresult.append(thisbxresultStr)
1135  allbxresultStr=' '.join(allbxresult)
1136  result.append([str(run),str(lumilsnum)+':'+str(cmslsnum),beamstatus,'%.2f'%beamenergy,str(ncollidingbx),allbxresultStr])
1137 
1138  if not toFile:
1139  labels=[('Run','LS','beamstatus','egev','ncollidingbx')]
1140  if dumpIntensity:
1141  labels=[('Run','LS','beamstatus','egev','ncollidingbx','(bxidx,b1,b2)')]
1142  print(' == = ')
1143  print(tablePrinter.indent (labels+result, hasHeader = True, separateRows = False,
1144  prefix = '| ', postfix = ' |', justify = 'left',
1145  delim = ' | ', wrapfunc = lambda x: wrap_onspace(x,25) ))
1146  else:
1147  fieldnames=['Run','LS','beamstatus','egev','ncollidingbx']
1148  if dumpIntensity:
1149  fieldnames.append('(bxidx,b1,b2)')
1150  filename=toFile
1151  dumptocsv(fieldnames,result,filename)
1152 
1153 if __name__ == "__main__":
1154  toScreenHeader('lumiCalc2.py','V04-00-00','v0','pp8TeV')
def toScreenOverview(lumidata, resultlines, scalefactor, irunlsdict=None, noWarning=True, toFile=None)
Definition: lumiReport.py:262
def toScreenLSHlt(hltdata, iresults=[], toFile=None)
Definition: lumiReport.py:1009
def replace(string, replacements)
def toScreenLumiByLS(lumidata, resultlines, scalefactor, irunlsdict=None, noWarning=True, toFile=None)
Definition: lumiReport.py:394
def guessUnit(inverseubval)
Definition: CommonUtil.py:60
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
def toScreenConfHlt(hltconfdata, iresults=[], toFile=None)
Definition: lumiReport.py:1062
def toScreenTotDelivered(lumidata, resultlines, scalefactor, irunlsdict=None, noWarning=True, toFile=None)
Definition: lumiReport.py:150
def toScreenLSTrg(trgdata, iresults=[], irunlsdict=None, noWarning=True, toFile=None, withoutmask=False)
Definition: lumiReport.py:944
def toCSVLumiByLSXing(lumidata, scalefactor, filename, irunlsdict=None, noWarning=True)
Definition: lumiReport.py:877
def splitlistToRangeString(inPut)
Definition: CommonUtil.py:257
def transposed(lists, defaultval=None)
Definition: CommonUtil.py:147
def toScreenNormDetail(normname, norminfo, normvalues)
Definition: lumiReport.py:78
def flatten(obj)
Definition: CommonUtil.py:5
def toScreenTags(tagdata)
Definition: lumiReport.py:122
def dumptocsv(fieldnames, result, filename)
Definition: lumiReport.py:13
def toScreenHeader(commandname, datatagname, normtag, worktag, updatetag, lumitype, toFile=None)
Definition: lumiReport.py:29
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def wrap_onspace(text, width)
Definition: dataformats.py:48
def lumiUnitForPrint(t)
Definition: CommonUtil.py:31
def wrap_onspace_strict(text, width)
Definition: dataformats.py:64
def toScreenTotEffective(lumidata, resultlines, scalefactor, irunlsdict=None, noWarning=True, toFile=None)
Definition: lumiReport.py:694
def toScreenLSEffective(lumidata, resultlines, scalefactor, irunlsdict=None, noWarning=True, toFile=None)
Definition: lumiReport.py:540
#define str(s)
def toScreenLSBeam(beamdata, iresults=[], dumpIntensity=False, toFile=None)
Definition: lumiReport.py:1102
double split
Definition: MVATrainer.cc:139
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)
Definition: lumiReport.py:61
def toScreenSingleTag(taginfo)
Definition: lumiReport.py:137