3 -- We use matplotlib OO class level api, we do not use its high-level helper modules. Favor endured stability over simplicity. 4 -- PNG as default batch file format 5 -- we support http mode by sending string buf via meme type image/png. Sending a premade static plot to webserver is considered a uploading process instead of http dynamic graphical mode. 7 from __future__
import print_function
8 from builtins
import range
12 from RecoLuminosity.LumiDB
import CommonUtil,lumiTime,csvReporter
15 if 'DISPLAY' not in os.environ
or not os.environ[
'DISPLAY']:
17 matplotlib.use(
'Agg',warn=
False)
20 from RecoLuminosity.LumiDB
import lumiQTWidget
22 print(
'unable to import GUI backend, switch to batch only mode')
23 matplotlib.use(
'Agg',warn=
False)
25 from matplotlib.backends.backend_agg
import FigureCanvasAgg
as CanvasBackend
26 from matplotlib.figure
import Figure
27 from matplotlib.font_manager
import fontManager,FontProperties
28 matplotlib.rcParams[
'lines.linewidth']=1.5
29 matplotlib.rcParams[
'grid.linewidth']=0.2
30 matplotlib.rcParams[
'xtick.labelsize']=11
31 matplotlib.rcParams[
'ytick.labelsize']=11
32 matplotlib.rcParams[
'legend.fontsize']=10
33 matplotlib.rcParams[
'axes.labelsize']=11
34 matplotlib.rcParams[
'font.weight']=567
38 input : largest total lumivalue 39 output: (unitstring,denomitor) 41 unitstring=
'$\mu$b$^{-1}$s$^{-1}$' 43 if t>=1.0e3
and t<1.0e06:
45 unitstring=
'nb$^{-1}$s$^{-1}$' 46 elif t>=1.0e6
and t<1.0e9:
48 unitstring=
'pb$^{-1}$s$^{-1}$' 49 elif t>=1.0e9
and t<1.0e12:
51 unitstring=
'fb$^{-1}$s$^{-1}$' 52 elif t>=1.0e12
and t<1.0e15:
54 unitstring=
'ab$^{-1}$s$^{-1}$' 55 elif t<=1.0e-3
and t>1.0e-6:
57 unitstring=
'mb$^{-1}$s$^{-1}$' 58 elif t<=1.0e-6
and t>1.0e-9:
60 unitstring=
'b$^{-1}$s$^{-1}$' 61 elif t<=1.0e-9
and t>1.0e-12:
63 unitstring=
'kb$^{-1}$s$^{-1}$' 64 return (unitstring,denomitor)
68 input : largest total lumivalue 69 output: (unitstring,denomitor) 71 unitstring=
'$\mu$b$^{-1}$' 73 if t>=1.0e3
and t<1.0e06:
75 unitstring=
'nb$^{-1}$' 76 elif t>=1.0e6
and t<1.0e9:
78 unitstring=
'pb$^{-1}$' 79 elif t>=1.0e9
and t<1.0e12:
81 unitstring=
'fb$^{-1}$' 82 elif t>=1.0e12
and t<1.0e15:
84 unitstring=
'ab$^{-1}$' 85 elif t<=1.0e-3
and t>1.0e-6:
87 unitstring=
'mb$^{-1}$' 88 elif t<=1.0e-6
and t>1.0e-9:
91 elif t<=1.0e-9
and t>1.0e-12:
93 unitstring=
'kb$^{-1}$' 94 return (unitstring,denomitor)
106 def plotSumX_Run(self,rawdata={},resultlines=[],minRun=None,maxRun=None,nticks=6,yscale='linear',withannotation=False,referenceLabel='Delivered',labels=['Delivered','Recorded'],textoutput=None):
109 rawdata = {'Delivered':[(runnumber,lumiperrun),..],'Recorded':[(runnumber,lumiperrun),..]} 110 resultlines = [[runnumber,dellumiperrun,reclumiperrun],[runnumber,dellumiperrun,reclumiperrun],] 111 minRun : minimal runnumber required 112 maxRun : max runnumber required 113 yscale: linear,log or both 114 withannotation: wheather the boundary points should be annotated 115 referenceLabel: the one variable that decides the total unit and the plot x-axis range 116 labels: labels of the variables to plot 117 textoutput: text output file name. 121 for r
in resultlines:
123 if rawdata
and runnumber
in [t[0]
for t
in rawdata[referenceLabel]]:
continue 124 if minRun
and runnumber<minRun:
continue 125 if maxRun
and runnumber>maxRun:
continue 126 for i,lab
in enumerate(labels) :
127 v=
float(r[-(len(labels)-i)-1])
128 rawdata.setdefault(lab,[]).
append((runnumber,v))
130 print(
'[WARNING]: no data to plot , exit')
133 tot=sum([t[1]
for t
in rawdata[referenceLabel]])
138 for label,yvalues
in rawdata.items():
140 flat.append([t[1]
for t
in yvalues])
143 lumivals=[t[1]
for t
in yvalues]
144 for i,val
in enumerate(lumivals):
145 ypoints[label].
append(sum(lumivals[0:i+1])/denomitor)
146 ytotal[label]=sum(lumivals)/denomitor
147 xpoints=[t[0]
for t
in rawdata[referenceLabel]]
148 ax=self.__fig.add_subplot(111)
150 ax.set_yscale(
'linear')
154 raise RuntimeError(
'unsupported yscale '+yscale)
155 ax.set_xlabel(
r'Run',position=(0.95,0))
156 ax.set_ylabel(
r'L '+unitstring,position=(0,0.9))
157 xticklabels=ax.get_xticklabels()
158 for tx
in xticklabels:
160 majorLocator=matplotlib.ticker.LinearLocator( nticks )
161 majorFormatter=matplotlib.ticker.FormatStrFormatter(
'%d')
162 minorLocator=matplotlib.ticker.LinearLocator(numticks=4*nticks)
163 ax.xaxis.set_major_locator(majorLocator)
164 ax.xaxis.set_major_formatter(majorFormatter)
165 ax.xaxis.set_minor_locator(minorLocator)
166 ax.set_xbound(lower=xpoints[0],upper=xpoints[-1])
168 keylist=sorted(ypoints.keys())
169 keylist.insert(0,keylist.pop(keylist.index(referenceLabel)))
172 textsummaryhead=[
'#TotalRun']
173 textsummaryline=[
'#'+
str(len(xpoints))]
174 for ylabel
in keylist:
178 ax.plot(xpoints,ypoints[ylabel],label=ylabel,color=cl,drawstyle=
'steps')
179 legendlist.append(ylabel+
' '+
'%.3f'%(ytotal[ylabel])+
' '+unitstring)
180 textsummaryhead.append(
'Total'+ylabel)
181 textsummaryline.append(
'%.3f'%(ytotal[ylabel])+
' '+unitstring)
185 csvreport.writeRow(head)
186 allruns=[
int(t[0])
for t
in rawdata[referenceLabel]]
187 flat.insert(0,allruns)
189 csvreport.writeRows([
list(t)
for t
in rows])
190 csvreport.writeRow(textsummaryhead)
191 csvreport.writeRow(textsummaryline)
194 ax.legend(tuple(legendlist),loc=
'upper left')
196 self.__fig.subplots_adjust(bottom=0.18,left=0.1)
199 trans=matplotlib.transforms.BlendedGenericTransform(ax.transData,ax.transAxes)
200 ax.text(xpoints[0],1.025,
str(xpoints[0]),transform=trans,horizontalalignment=
'left',size=
'x-small',color=
'green',bbox=
dict(facecolor=
'white'))
201 ax.text(xpoints[-1],1.025,
str(xpoints[-1]),transform=trans,horizontalalignment=
'left',size=
'x-small',color=
'green',bbox=
dict(facecolor=
'white'))
204 def plotSumX_Fill(self,rawdata={},resultlines=[],minFill=None,maxFill=None,nticks=6,yscale='linear',withannotation=False,referenceLabel='Delivered',labels=['Delivered','Recorded'],textoutput=None):
207 rawdata = {'Delivered':[(fill,runnumber,lumiperrun)],'Recorded':[(fill,runnumber,lumiperrun)]} 208 resultlines = [[fillnumber,runnumber,dellumiperrun,reclumiperrun],[fillnumber,runnumber,dellumiperrun,reclumiperrun],] 209 minFill : min fill to draw 210 maxFill : max fill to draw 211 yscale: linear,log or both 212 withannotation: wheather the boundary points should be annotated 213 textoutput: text output file name. 217 for r
in resultlines:
220 if rawdata
and (fillnum,runnum)
in [(t[0],t[1])
for t
in rawdata[referenceLabel]]:
continue 221 if minFill
and fillnum<minFill:
continue 222 if maxFill
and fillnum>maxFill:
continue 223 for i,lab
in enumerate(labels) :
224 v=
float(r[-(len(labels)-i)])
225 rawdata.setdefault(lab,[]).
append((fillnum,runnum,v))
228 print(
'[WARNING]: no data, do nothing')
230 tot=sum([t[2]
for t
in rawdata[referenceLabel]])
237 for label,yvalues
in rawdata.items():
239 flat.append([t[2]
for t
in yvalues])
242 lumivals=[t[2]
for t
in yvalues]
243 for i,val
in enumerate(lumivals):
244 ypoints[label].
append(sum(lumivals[0:i+1])/denomitor)
245 ytotal[label]=sum(lumivals)/denomitor
246 xpoints=[t[0]
for t
in rawdata[referenceLabel]]
247 ax=self.__fig.add_subplot(111)
248 ax.set_xlabel(
r'LHC Fill Number',position=(0.84,0))
249 ax.set_ylabel(
r'L '+unitstring,position=(0,0.9))
250 ax.set_xbound(lower=xpoints[0],upper=xpoints[-1])
252 ax.set_yscale(
'linear')
256 raise RuntimeError(
'unsupported yscale '+yscale)
257 xticklabels=ax.get_xticklabels()
258 majorLocator=matplotlib.ticker.LinearLocator( nticks )
259 majorFormatter=matplotlib.ticker.FormatStrFormatter(
'%d')
261 ax.xaxis.set_major_locator(majorLocator)
262 ax.xaxis.set_major_formatter(majorFormatter)
265 keylist=sorted(ypoints.keys())
266 keylist.insert(0,keylist.pop(keylist.index(referenceLabel)))
269 textsummaryhead=[
'#TotalFill']
270 textsummaryline=[
'#'+
str(len(xpoints))]
271 for ylabel
in keylist:
275 ax.plot(xpoints,ypoints[ylabel],label=ylabel,color=cl,drawstyle=
'steps')
276 legendlist.append(ylabel+
' '+
'%.3f'%(ytotal[ylabel])+
' '+unitstring)
277 textsummaryhead.append(
'Total'+ylabel)
278 textsummaryline.append(
'%.3f'%(ytotal[ylabel])+
' '+unitstring)
282 allfills=[
int(t[0])
for t
in rawdata[referenceLabel]]
283 allruns=[
int(t[1])
for t
in rawdata[referenceLabel]]
284 flat.insert(0,allfills)
285 flat.insert(1,allruns)
287 csvreport.writeRow(head)
288 csvreport.writeRows([
list(t)
for t
in rows])
289 csvreport.writeRow(textsummaryhead)
290 csvreport.writeRow(textsummaryline)
294 trans=matplotlib.transforms.BlendedGenericTransform(ax.transData,ax.transAxes)
295 ax.text(xpoints[0],1.025,beginfo,transform=trans,horizontalalignment=
'left',size=
'x-small',color=
'green',bbox=
dict(facecolor=
'white'))
296 ax.text(xpoints[-1],1.025,endinfo,transform=trans,horizontalalignment=
'left',size=
'x-small',color=
'green',bbox=
dict(facecolor=
'white'))
298 ax.legend(tuple(legendlist),loc=
'upper left')
300 self.__fig.subplots_adjust(bottom=0.1,left=0.1)
302 def plotSumX_Time(self,rawdata={},resultlines=[],minTime=None,maxTime=None,nticks=6,yscale='linear',withannotation=False,referenceLabel='Delivered',labels=['Delivered','Recorded'],textoutput=None):
305 rawdata = {'Delivered':[(runnumber,starttimestamp,stoptimestamp,lumiperrun)],'Recorded':[(runnumber,starttimestamp,stoptimestamp,lumiperrun)]} 306 resultlines = [[runnumber,starttimestampStr,stoptimestampStr,dellumiperrun,reclumiperrun],[runnumber,starttimestampStr,stoptimestampStr,dellumiperrun,reclumiperrun],] 307 minTime (python DateTime) : min *begin* time to draw: format %m/%d/%y %H:%M:%S 308 maxTime (python DateTime): max *begin* time to draw %m/%d/%y %H:%M:%S 309 yscale: linear,log or both 310 withannotation: wheather the boundary points should be annotated 311 referenceLabel: the one variable that decides the total unit and the plot x-axis range 312 labels: labels of the variables to plot 319 minTime=
'03/01/10 00:00:00' 320 minTime=lut.StrToDatetime(minTime,customfm=
'%m/%d/%y %H:%M:%S')
322 maxTime=datetime.datetime.utcnow()
324 maxTime=lut.StrToDatetime(maxTime,customfm=
'%m/%d/%y %H:%M:%S')
325 for r
in resultlines:
327 starttimeStr=r[1].
split(
'.')[0]
328 starttime=lut.StrToDatetime(starttimeStr,customfm=
'%Y-%m-%d %H:%M:%S')
329 stoptimeStr=r[2].
split(
'.')[0]
330 stoptime=lut.StrToDatetime(stoptimeStr,customfm=
'%Y-%m-%d %H:%M:%S')
331 if rawdata
and runnumber
in [t[0]
for t
in rawdata[referenceLabel]]:
continue 332 if starttime<minTime:
continue 333 if starttime>maxTime:
continue 335 for i,lab
in enumerate(labels):
336 v=
float(r[-(len(labels)-i)])
337 rawdata.setdefault(lab,[]).
append((runnumber,starttime,stoptime,v))
339 print(
'[WARNING]: no data, do nothing')
341 tot=sum([t[3]
for t
in rawdata[referenceLabel]])
346 for label,yvalues
in rawdata.items():
348 flat.append([t[3]
for t
in yvalues])
349 if label==referenceLabel:
350 minTime=yvalues[0][1]
351 maxTime=yvalues[-1][1]
353 lumivals=[t[3]
for t
in yvalues]
354 for i,val
in enumerate(lumivals):
355 ypoints[label].
append(sum(lumivals[0:i+1])/denomitor)
356 ytotal[label]=sum(lumivals)/denomitor
357 xpoints=[matplotlib.dates.date2num(t[1])
for t
in rawdata[referenceLabel]]
358 ax=self.__fig.add_subplot(111)
359 ax.set_yscale(yscale)
360 yearStrMin=minTime.strftime(
'%Y')
361 yearStrMax=maxTime.strftime(
'%Y')
362 if yearStrMin==yearStrMax:
363 dateFmt=matplotlib.dates.DateFormatter(
'%d/%m')
365 dateFmt=matplotlib.dates.DateFormatter(
'%d/%m/%y')
366 majorLoc=matplotlib.ticker.LinearLocator(numticks=nticks)
367 ax.xaxis.set_major_locator(majorLoc)
368 minorLoc=matplotlib.ticker.LinearLocator(numticks=nticks*4)
369 ax.xaxis.set_major_formatter(dateFmt)
370 ax.set_xlabel(
r'Date',position=(0.84,0))
371 ax.set_ylabel(
r'L '+unitstring,position=(0,0.9))
372 ax.xaxis.set_minor_locator(minorLoc)
373 ax.set_xbound(lower=xpoints[0],upper=xpoints[-1])
374 xticklabels=ax.get_xticklabels()
375 for tx
in xticklabels:
376 tx.set_horizontalalignment(
'left')
378 keylist=sorted(ypoints.keys())
379 keylist.insert(0,keylist.pop(keylist.index(referenceLabel)))
381 head=[
'#Run',
'StartTime',
'StopTime']
382 textsummaryhead=[
'#TotalRun']
383 textsummaryline=[
'#'+
str(len(xpoints))]
384 for ylabel
in keylist:
388 ax.plot(xpoints,ypoints[ylabel],label=ylabel,color=cl,drawstyle=
'steps')
389 legendlist.append(ylabel+
' '+
'%.3f'%(ytotal[ylabel])+
' '+unitstring)
390 textsummaryhead.append(
'Total'+ylabel)
391 textsummaryline.append(
'%.3f'%(ytotal[ylabel])+
' '+unitstring)
395 csvreport.writeRow(head)
396 allruns=[
int(t[0])
for t
in rawdata[referenceLabel]]
397 allstarts=[ lut.DatetimeToStr(t[1],customfm=
'%Y-%m-%d %H:%M:%S')
for t
in rawdata[referenceLabel] ]
398 allstops=[ lut.DatetimeToStr(t[2],customfm=
'%Y-%m-%d %H:%M:%S')
for t
in rawdata[referenceLabel] ]
399 flat.insert(0,allruns)
400 flat.insert(1,allstarts)
401 flat.insert(2,allstops)
403 csvreport.writeRows([
list(t)
for t
in rows])
404 csvreport.writeRow(textsummaryhead)
405 csvreport.writeRow(textsummaryline)
407 trans=matplotlib.transforms.BlendedGenericTransform(ax.transData,ax.transAxes)
412 runs=[t[0]
for t
in rawdata[referenceLabel]]
413 ax.text(xpoints[0],1.025,
str(runs[0]),transform=trans,horizontalalignment=
'left',size=
'x-small',color=
'green',bbox=
dict(facecolor=
'white'))
414 ax.text(xpoints[-1],1.025,
str(runs[-1]),transform=trans,horizontalalignment=
'left',size=
'x-small',color=
'green',bbox=
dict(facecolor=
'white'))
416 if yearStrMin==yearStrMax:
417 firsttimeStr=rawdata[referenceLabel][1][1].strftime(
'%b %d %H:%M')
418 lasttimeStr=rawdata[referenceLabel][-1][2].strftime(
'%b %d %H:%M')
422 ax.set_title(
'CMS Total Integrated Luminosity '+yearStrMin+
' ('+firsttimeStr+
' - '+lasttimeStr+
' UTC)',size=
'small')
425 ax.set_title(
'CMS Total Integrated Luminosity '+yearStrMin+
'-'+yearStrMax,size=
'small')
426 ax.legend(tuple(legendlist),loc=
'upper left')
427 ax.autoscale_view(tight=
True,scalex=
True,scaley=
False)
428 self.__fig.autofmt_xdate(bottom=0.18,rotation=15,ha=
'right')
429 self.__fig.subplots_adjust(bottom=0.2,left=0.15)
431 def plotPerdayX_Time(self,rawdata={},resultlines=[],minTime=None,maxTime=None,nticks=6,yscale='linear',withannotation=False,referenceLabel='Delivered',labels=['Delivered','Recorded'],textoutput=None):
434 rawdata={'Delivered':[(day,begrun:ls,endrun:ls,lumi)],'Recorded':[(dayofyear,begrun:ls,endrun:ls,lumi)]} 435 resultlines=[[day,begrun:ls,endrun:ls,deliveredperday,recordedperday],[]] 436 minTime (python DateTime) : min *begin* time to draw: format %m/%d/%y %H:%M:%S 437 maxTime (python DateTime): max *begin* time to draw %m/%d/%y %H:%M:%S 438 withannotation: wheather the boundary points should be annotated 439 referenceLabel: the one variable that decides the total unit and the plot x-axis range 440 labels: labels of the variables to plot 447 minTime=
'03/01/10 00:00:00' 448 minTime=lut.StrToDatetime(minTime,customfm=
'%m/%d/%y %H:%M:%S')
450 maxTime=datetime.datetime.utcnow()
452 maxTime=lut.StrToDatetime(maxTime,customfm=
'%m/%d/%y %H:%M:%S')
453 for r
in resultlines:
458 if rawdata
and day
in [t[0]
for t
in rawdata[referenceLabel]]:
continue 459 if day < minTime.date().toordinal():
continue 460 if day > maxTime.date().toordinal():
continue 461 for i,lab
in enumerate(labels):
462 v=
float(r[-(len(labels)-i)-1])
463 rawdata.setdefault(lab,[]).
append((day,begrunls,endrunls,v))
465 print(
'[WARNING]: no data, do nothing')
467 maxlum=
max([t[3]
for t
in rawdata[referenceLabel]])
468 minlum=
min([t[3]
for t
in rawdata[referenceLabel]
if t[3]>0])
473 MinDay=minTime.date().toordinal()
474 MaxDay=maxTime.date().toordinal()
475 fulldays=
list(range(MinDay,MaxDay+1))
478 for label,yvalues
in rawdata.items():
480 flat.append([t[3]
for t
in yvalues])
481 alldays=[t[0]
for t
in yvalues]
482 alldates=[
str(datetime.date.fromordinal(t))
for t
in alldays]
484 lumivals=[t[3]
for t
in yvalues]
487 ypoints[label].
append(0.0)
489 thisdaylumi=[t[3]
for t
in yvalues
if t[0]==d][0]
491 if thisdaylumi<minlum:
492 thisdaylumi=minlum/denomitor
494 thisdaylumi=thisdaylumi/denomitor
496 thisdaylumi=thisdaylumi/denomitor
497 ypoints[label].
append(thisdaylumi)
498 ymax[label]=
max(lumivals)/denomitor
502 head=[
'#day',
'begrunls',
'endrunls',
'delivered',
'recorded',
'date']
503 csvreport.writeRow(head)
504 flat.insert(0,alldays)
505 allstarts=[ t[1]
for t
in rawdata[referenceLabel]]
506 allstops=[ t[2]
for t
in rawdata[referenceLabel]]
508 flat.insert(1,allstarts)
509 flat.insert(2,allstops)
510 flat.append(alldates)
512 csvreport.writeRows([
list(t)
for t
in rows])
513 yearStrMin=minTime.strftime(
'%Y')
514 yearStrMax=maxTime.strftime(
'%Y')
515 if yearStrMin==yearStrMax:
516 dateFmt=matplotlib.dates.DateFormatter(
'%d/%m')
518 dateFmt=matplotlib.dates.DateFormatter(
'%d/%m/%y')
519 ax=self.__fig.add_subplot(111)
521 ax.set_yscale(
'linear')
525 raise RuntimeError(
'unsupported yscale '+yscale)
526 majorLoc=matplotlib.ticker.LinearLocator(numticks=nticks)
527 minorLoc=matplotlib.ticker.LinearLocator(numticks=nticks*4)
528 ax.xaxis.set_major_formatter(dateFmt)
529 ax.set_xlabel(
r'Date',position=(0.84,0))
530 ax.xaxis.set_major_locator(majorLoc)
531 ax.xaxis.set_minor_locator(minorLoc)
532 xticklabels=ax.get_xticklabels()
533 for tx
in xticklabels:
534 tx.set_horizontalalignment(
'right')
537 ax.set_ylabel(
r'L '+unitstring,position=(0,0.9))
538 textsummaryhead=[
'#TotalRunningDays']
539 textsummaryline=[
'#'+
str(len(alldays))]
540 for ylabel
in labels:
544 ax.plot(xpoints,ypoints[ylabel],label=ylabel,color=cl,drawstyle=
'steps')
545 legendlist.append(ylabel+
' Max '+
'%.3f'%(ymax[ylabel])+
' '+unitstring)
546 textsummaryhead.append(
'Max'+ylabel)
547 textsummaryline.append(
'%.3f'%(ymax[ylabel])+
' '+unitstring)
549 csvreport.writeRow(textsummaryhead)
550 csvreport.writeRow(textsummaryline)
551 ax.legend(tuple(legendlist),loc=
'upper left')
552 ax.set_xbound(lower=matplotlib.dates.date2num(minTime),upper=matplotlib.dates.date2num(maxTime))
563 firstday=datetime.date.fromordinal(rawdata[referenceLabel][0][0])
564 lastday=datetime.date.fromordinal(rawdata[referenceLabel][-1][0])
565 firstdayStr=firstday.strftime(
'%Y %b %d')
566 lastdayStr=lastday.strftime(
'%Y %b %d')
567 ax.set_title(
'CMS Integrated Luminosity/Day ('+firstdayStr+
' - '+lastdayStr+
')',size=
'small')
569 ax.autoscale_view(tight=
True,scalex=
True,scaley=
False)
571 self.__fig.autofmt_xdate(bottom=0.18,rotation=15,ha=
'right')
572 self.__fig.subplots_adjust(bottom=0.2,left=0.15)
574 def plotPeakPerday_Time(self,rawdata={},resultlines=[],minTime=None,maxTime=None,nticks=6,withannotation=False,yscale='linear',referenceLabel='Delivered',labels=['Delivered'],textoutput=None):
576 THIS PLOT IS DELIVERED ONLY 578 rawdata={'Delivered':[(day,run,ls,instlumi)]} 579 resultlines=[[day,run,ls,maxinstlum],[]] 580 minTime (python DateTime) : min *begin* time to draw: format %m/%d/%y %H:%M:%S 581 maxTime (python DateTime): max *begin* time to draw %m/%d/%y %H:%M:%S 582 withannotation: wheather the boundary points should be annotated 583 referenceLabel: the one variable that decides the total unit and the plot x-axis range 584 labels: labels of the variables to plot 593 minTime=
'03/01/10 00:00:00' 594 minTime=lut.StrToDatetime(minTime,customfm=
'%m/%d/%y %H:%M:%S')
596 maxTime=datetime.datetime.utcnow()
598 maxTime=lut.StrToDatetime(maxTime,customfm=
'%m/%d/%y %H:%M:%S')
599 for r
in resultlines:
603 if rawdata
and day
in [
int(t[0])
for t
in rawdata[referenceLabel]]:
continue 604 if day < minTime.date().toordinal():
continue 605 if day > maxTime.date().toordinal():
continue 606 for i,lab
in enumerate(labels):
607 v=
float(r[-(len(labels)-i)-1])
608 rawdata.setdefault(lab,[]).
append((day,runnumber,lsnum,v))
610 print(
'[WARNING]: no data, do nothing')
612 maxlum=
max([t[3]
for t
in rawdata[referenceLabel]])
613 minlum=
min([t[3]
for t
in rawdata[referenceLabel]
if t[3]>0])
619 MinDay=minTime.date().toordinal()
620 MaxDay=maxTime.date().toordinal()
621 fulldays=
list(range(MinDay,MaxDay+1))
622 for label
in rawdata.keys():
623 yvalues=sorted(rawdata[label])
624 alldays=[t[0]
for t
in yvalues]
625 alldates=[
str(datetime.date.fromordinal(t))
for t
in alldays]
627 lumivals=[t[3]
for t
in yvalues]
628 flat.append(lumivals)
631 ypoints[label].
append(0.0)
633 thisdaylumi=[t[3]
for t
in yvalues
if t[0]==d][0]
635 if thisdaylumi<minlum:
636 thisdaylumi=minlum/denomitor
638 thisdaylumi=thisdaylumi/denomitor
640 thisdaylumi=thisdaylumi/denomitor
641 ypoints[label].
append(thisdaylumi)
642 ymax[label]=
max(lumivals)/denomitor
643 'ymax ',
max(lumivals)
647 head=[
'#day',
'run',
'lsnum',
'maxinstlumi',
'date']
648 csvreport.writeRow(head)
649 flat.insert(0,alldays)
650 allruns=[ t[1]
for t
in rawdata[referenceLabel]]
651 allls=[ t[2]
for t
in rawdata[referenceLabel]]
652 flat.insert(1,allruns)
654 flat.append(alldates)
656 csvreport.writeRows([
list(t)
for t
in rows])
658 yearStrMin=minTime.strftime(
'%Y')
659 yearStrMax=maxTime.strftime(
'%Y')
660 if yearStrMin==yearStrMax:
661 dateFmt=matplotlib.dates.DateFormatter(
'%d/%m')
663 dateFmt=matplotlib.dates.DateFormatter(
'%d/%m/%y')
664 ax=self.__fig.add_subplot(111)
666 ax.set_yscale(
'linear')
670 raise RuntimeError(
'unsupported yscale '+yscale)
671 majorLoc=matplotlib.ticker.LinearLocator(numticks=nticks)
672 minorLoc=matplotlib.ticker.LinearLocator(numticks=nticks*4)
673 ax.xaxis.set_major_formatter(dateFmt)
674 ax.set_xlabel(
r'Date',position=(0.84,0))
675 ax.set_ylabel(
r'L '+unitstring,position=(0,0.9))
676 ax.xaxis.set_major_locator(majorLoc)
677 ax.xaxis.set_minor_locator(minorLoc)
678 xticklabels=ax.get_xticklabels()
679 for tx
in xticklabels:
680 tx.set_horizontalalignment(
'right')
683 textsummaryhead=[
'#TotalRunningDays']
684 textsummaryline=[
'#'+
str(len(alldays))]
685 for ylabel
in labels:
689 ax.plot(xpoints,ypoints[ylabel],label=
'Max Inst',color=cl,drawstyle=
'steps')
690 legendlist.append(
'Max Inst %.3f'%(ymax[ylabel])+
' '+unitstring)
691 textsummaryhead.append(
'Max Inst'+ylabel)
692 textsummaryline.append(
'%.3f'%(ymax[ylabel])+
' '+unitstring)
694 csvreport.writeRow(textsummaryhead)
695 csvreport.writeRow(textsummaryline)
696 ax.legend(tuple(legendlist),loc=
'upper left')
697 ax.set_xbound(lower=matplotlib.dates.date2num(minTime),upper=matplotlib.dates.date2num(maxTime))
700 trans=matplotlib.transforms.BlendedGenericTransform(ax.transData,ax.transAxes)
701 ax.text(xpoints[0],1.025,beginfo,transform=trans,horizontalalignment=
'left',size=
'x-small',color=
'green',bbox=
dict(facecolor=
'white'))
702 ax.text(xpoints[-1],1.025,endinfo,transform=trans,horizontalalignment=
'left',size=
'x-small',color=
'green',bbox=
dict(facecolor=
'white'))
703 ax.annotate(maxinfo,xy=(xmax,ymax),xycoords=
'data',xytext=(0,13),textcoords=
'offset points',arrowprops=
dict(facecolor=
'green',shrink=0.05),size=
'x-small',horizontalalignment=
'center',color=
'green',bbox=
dict(facecolor=
'white'))
705 firstday=datetime.date.fromordinal(rawdata[referenceLabel][0][0])
706 lastday=datetime.date.fromordinal(rawdata[referenceLabel][-1][0])
707 firstdayStr=firstday.strftime(
'%Y %b %d')
708 lastdayStr=lastday.strftime(
'%Y %b %d')
709 ax.set_title(
'CMS Peak Luminosity/Day ('+firstdayStr+
' - '+lastdayStr+
')',size=
'small')
712 ax.autoscale_view(tight=
True,scalex=
True,scaley=
False)
714 self.__fig.autofmt_xdate(bottom=0.18,rotation=15,ha=
'right')
715 self.__fig.subplots_adjust(bottom=0.2,left=0.15)
719 Input: rawxdata [run,fill,starttime,stoptime,totalls,ncmsls] 720 rawydata {label:[lumi]} 726 starttime=lut.DatetimeToStr(rawxdata[2],customfm=
'%m/%d/%y %H:%M:%S')
727 stoptime=lut.DatetimeToStr(rawxdata[3],customfm=
'%m/%d/%y %H:%M:%S')
730 peakinst=
max(rawydata[
'Delivered'])/lslength
731 totaldelivered=sum(rawydata[
'Delivered'])
732 totalrecorded=sum(rawydata[
'Recorded'])
733 xpoints=
list(range(1,totalls+1))
737 for ylabel,yvalue
in rawydata.items():
738 ypoints[ylabel]=[y/lslength
for y
in yvalue]
739 ymax[ylabel]=
max(yvalue)/lslength
744 bottom_h=bottom+height
745 rect_scatter=[left,bottom,width,height]
746 rect_table=[left,bottom_h,width,0.25]
748 nullfmt=matplotlib.ticker.NullFormatter()
749 nullloc=matplotlib.ticker.NullLocator()
750 axtab=self.__fig.add_axes(rect_table,frameon=
False)
752 axtab.xaxis.set_major_formatter(nullfmt)
753 axtab.yaxis.set_major_formatter(nullfmt)
754 axtab.xaxis.set_major_locator(nullloc)
755 axtab.yaxis.set_major_locator(nullloc)
757 ax=self.__fig.add_axes(rect_scatter)
759 majorLoc=matplotlib.ticker.LinearLocator(numticks=nticks)
760 minorLoc=matplotlib.ticker.LinearLocator(numticks=nticks*4)
761 ax.set_xlabel(
r'LS',position=(0.96,0))
762 ax.set_ylabel(
r'L $\mu$b$^{-1}$s$^{-1}$',position=(0,0.9))
763 ax.xaxis.set_major_locator(majorLoc)
764 ax.xaxis.set_minor_locator(minorLoc)
765 ax.set_xbound(lower=xpoints[0],upper=xpoints[-1])
766 xticklabels=ax.get_xticklabels()
767 for tx
in xticklabels:
768 tx.set_horizontalalignment(
'right')
770 keylist=sorted(ypoints.keys())
773 for ylabel
in keylist:
777 ax.plot(xpoints,ypoints[ylabel],
'.',label=ylabel,color=cl)
778 legendlist.append(ylabel)
780 ax.axvline(xpoints[ncmsls-1],color=
'green',linewidth=0.2)
782 colLabels=(
'run',
'fill',
'max inst(/$\mu$b/s)',
'delivered('+unitstring+
')',
'recorded('+unitstring+
')')
783 cellText=[[
str(runnum),
str(fill),
'%.3f'%(peakinst),
'%.3f'%(totaldelivered/denomitor),
'%.3f'%(totalrecorded/denomitor)]]
785 sumtable=axtab.table(cellText=cellText,colLabels=colLabels,colWidths=[0.12,0.1,0.27,0.27,0.27],cellLoc=
'center',loc=
'center')
786 trans=matplotlib.transforms.BlendedGenericTransform(ax.transData,ax.transAxes)
787 axtab.add_table(sumtable)
789 ax.text(xpoints[0],1.02,starttime[0:17],transform=trans,horizontalalignment=
'left',size=
'x-small',color=
'green',bbox=
dict(facecolor=
'white'))
790 ax.text(xpoints[ncmsls-1],1.02,stoptime[0:17],transform=trans,horizontalalignment=
'left',size=
'x-small',color=
'green',bbox=
dict(facecolor=
'white'))
791 ax.legend(tuple(legendlist),loc=
'upper right',numpoints=1)
795 cherrypy.response.headers[
'Content-Type']=
'image/png' 797 self.__canvas.print_png(buf)
798 return buf.getvalue()
802 self.__canvas.print_figure(filename)
806 print(
'interactive mode is not available for your setup, exit')
812 if __name__==
'__main__':
814 print(
'=====testing plotSumX_Run======')
815 f=open(
'/afs/cern.ch/cms/lumi/www/plots/operation/totallumivsrun-2011.csv',
'r') 816 reader=csv.reader(f,delimiter=',')
819 if not row[0].isdigit():
continue 820 resultlines.append(row)
822 fig=Figure(figsize=(7.2,5.4),dpi=120)
824 m.plotSumX_Run(rawdata={},resultlines=resultlines,minRun=
None,maxRun=
None,nticks=6,yscale=
'linear',withannotation=
False)
830 print '=====testing plotSumX_Fill======' 831 f=open('/afs/cern.ch/cms/lumi/www/plots/operation/totallumivsfill-2011.csv','r') 832 reader=csv.reader(f,delimiter=',')
835 if not row[0].isdigit():
continue 836 resultlines.append(row)
838 fig=Figure(figsize=(7.2,5.4),dpi=120)
840 m.plotSumX_Fill(rawdata={},resultlines=resultlines,minFill=
None,maxFill=
None,nticks=6,yscale=
'linear',withannotation=
True)
841 m.drawPNG(
'totallumivsfill-2011test.png')
843 print '=====testing plotSumX_Time======' 844 f=open(
'/afs/cern.ch/cms/lumi/www/publicplots/totallumivstime-2011.csv',
'r') 845 reader=csv.reader(f,delimiter=',')
848 if not row[0].isdigit():
continue 849 resultlines.append(row)
851 fig=Figure(figsize=(7.25,5.4),dpi=120)
853 m.plotSumX_Time(rawdata={},resultlines=resultlines,minTime=
"03/14/11 09:00:00",maxTime=
None,nticks=6,yscale=
'linear',withannotation=
False)
854 m.drawPNG(
'totallumivstime-2011test.png')
857 print '=====testing plotPerdayX_Time======' 858 f=open(
'/afs/cern.ch/cms/lumi/www/publicplots/lumiperday-2011.csv',
'r') 859 reader=csv.reader(f,delimiter=',')
862 if not row[0].isdigit():
continue 863 resultlines.append(row)
865 fig=Figure(figsize=(7.25,5.4),dpi=120)
867 m.plotPerdayX_Time(rawdata={},resultlines=resultlines,minTime=
"03/14/11 09:00:00",maxTime=
None,nticks=6,yscale=
'linear',withannotation=
False)
868 m.drawPNG(
'lumiperday-2011test.png')
871 print '=====testing plotPeakPerday_Time======' 872 f=open(
'/afs/cern.ch/cms/lumi/www/publicplots/lumipeak-2011.csv',
'r') 873 reader=csv.reader(f,delimiter=',')
876 if not row[0].isdigit():
continue 877 resultlines.append(row)
879 fig=Figure(figsize=(7.25,5.4),dpi=120)
881 m.plotPeakPerday_Time(rawdata={},resultlines=resultlines,minTime=
"03/14/11 09:00:00",maxTime=
None,nticks=6,yscale=
'linear',withannotation=
False)
882 m.drawPNG(
'lumipeak-2011test.png')
def plotInst_RunLS(self, rawxdata, rawydata, nticks=6, textoutput=None)
def plotSumX_Time(self, rawdata={}, resultlines=[], minTime=None, maxTime=None, nticks=6, yscale='linear', withannotation=False, referenceLabel='Delivered', labels=['Delivered', Recorded, textoutput=None)
S & print(S &os, JobReport::InputFile const &f)
def plotPerdayX_Time(self, rawdata={}, resultlines=[], minTime=None, maxTime=None, nticks=6, yscale='linear', withannotation=False, referenceLabel='Delivered', labels=['Delivered', Recorded, textoutput=None)
OutputIterator zip(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
def plotSumX_Fill(self, rawdata={}, resultlines=[], minFill=None, maxFill=None, nticks=6, yscale='linear', withannotation=False, referenceLabel='Delivered', labels=['Delivered', Recorded, textoutput=None)
def plotPeakPerday_Time(self, rawdata={}, resultlines=[], minTime=None, maxTime=None, nticks=6, withannotation=False, yscale='linear', referenceLabel='Delivered', labels=['Delivered'], textoutput=None)
def drawPNG(self, filename)
def plotSumX_Run(self, rawdata={}, resultlines=[], minRun=None, maxRun=None, nticks=6, yscale='linear', withannotation=False, referenceLabel='Delivered', labels=['Delivered', Recorded, textoutput=None)
def drawInteractive(self)
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