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.
10 from RecoLuminosity.LumiDB
import CommonUtil,lumiTime,csvReporter
13 if 'DISPLAY' not in os.environ
or not os.environ[
'DISPLAY']:
15 matplotlib.use(
'Agg',warn=
False)
18 from RecoLuminosity.LumiDB
import lumiQTWidget
20 print 'unable to import GUI backend, switch to batch only mode'
21 matplotlib.use(
'Agg',warn=
False)
23 from matplotlib.backends.backend_agg
import FigureCanvasAgg
as CanvasBackend
24 from matplotlib.figure
import Figure
25 from matplotlib.font_manager
import fontManager,FontProperties
26 matplotlib.rcParams[
'lines.linewidth']=1.5
27 matplotlib.rcParams[
'grid.linewidth']=0.2
28 matplotlib.rcParams[
'xtick.labelsize']=11
29 matplotlib.rcParams[
'ytick.labelsize']=11
30 matplotlib.rcParams[
'legend.fontsize']=10
31 matplotlib.rcParams[
'axes.labelsize']=11
32 matplotlib.rcParams[
'font.weight']=567
36 input : largest total lumivalue
37 output: (unitstring,denomitor)
39 unitstring=
'$\mu$b$^{-1}$s$^{-1}$'
41 if t>=1.0e3
and t<1.0e06:
43 unitstring=
'nb$^{-1}$s$^{-1}$'
44 elif t>=1.0e6
and t<1.0e9:
46 unitstring=
'pb$^{-1}$s$^{-1}$'
47 elif t>=1.0e9
and t<1.0e12:
49 unitstring=
'fb$^{-1}$s$^{-1}$'
50 elif t>=1.0e12
and t<1.0e15:
52 unitstring=
'ab$^{-1}$s$^{-1}$'
53 elif t<=1.0e-3
and t>1.0e-6:
55 unitstring=
'mb$^{-1}$s$^{-1}$'
56 elif t<=1.0e-6
and t>1.0e-9:
58 unitstring=
'b$^{-1}$s$^{-1}$'
59 elif t<=1.0e-9
and t>1.0e-12:
61 unitstring=
'kb$^{-1}$s$^{-1}$'
62 return (unitstring,denomitor)
66 input : largest total lumivalue
67 output: (unitstring,denomitor)
69 unitstring=
'$\mu$b$^{-1}$'
71 if t>=1.0e3
and t<1.0e06:
73 unitstring=
'nb$^{-1}$'
74 elif t>=1.0e6
and t<1.0e9:
76 unitstring=
'pb$^{-1}$'
77 elif t>=1.0e9
and t<1.0e12:
79 unitstring=
'fb$^{-1}$'
80 elif t>=1.0e12
and t<1.0e15:
82 unitstring=
'ab$^{-1}$'
83 elif t<=1.0e-3
and t>1.0e-6:
85 unitstring=
'mb$^{-1}$'
86 elif t<=1.0e-6
and t>1.0e-9:
89 elif t<=1.0e-9
and t>1.0e-12:
91 unitstring=
'kb$^{-1}$'
92 return (unitstring,denomitor)
104 def plotSumX_Run(self,rawdata={},resultlines=[],minRun=None,maxRun=None,nticks=6,yscale='linear',withannotation=False,referenceLabel='Delivered',labels=['Delivered','Recorded'],textoutput=None):
107 rawdata = {'Delivered':[(runnumber,lumiperrun),..],'Recorded':[(runnumber,lumiperrun),..]}
108 resultlines = [[runnumber,dellumiperrun,reclumiperrun],[runnumber,dellumiperrun,reclumiperrun],]
109 minRun : minimal runnumber required
110 maxRun : max runnumber required
111 yscale: linear,log or both
112 withannotation: wheather the boundary points should be annotated
113 referenceLabel: the one variable that decides the total unit and the plot x-axis range
114 labels: labels of the variables to plot
115 textoutput: text output file name.
119 for r
in resultlines:
121 if rawdata
and runnumber
in [t[0]
for t
in rawdata[referenceLabel]]:
continue
122 if minRun
and runnumber<minRun:
continue
123 if maxRun
and runnumber>maxRun:
continue
124 for i,lab
in enumerate(labels) :
125 v=float(r[-(len(labels)-i)-1])
126 rawdata.setdefault(lab,[]).
append((runnumber,v))
128 print '[WARNING]: no data to plot , exit'
131 tot=sum([t[1]
for t
in rawdata[referenceLabel]])
136 for label,yvalues
in rawdata.items():
138 flat.append([t[1]
for t
in yvalues])
141 lumivals=[t[1]
for t
in yvalues]
142 for i,val
in enumerate(lumivals):
143 ypoints[label].
append(sum(lumivals[0:i+1])/denomitor)
144 ytotal[label]=sum(lumivals)/denomitor
145 xpoints=[t[0]
for t
in rawdata[referenceLabel]]
146 ax=self.__fig.add_subplot(111)
148 ax.set_yscale(
'linear')
152 raise 'unsupported yscale ',yscale
153 ax.set_xlabel(
r'Run',position=(0.95,0))
154 ax.set_ylabel(
r'L '+unitstring,position=(0,0.9))
155 xticklabels=ax.get_xticklabels()
156 for tx
in xticklabels:
158 majorLocator=matplotlib.ticker.LinearLocator( nticks )
159 majorFormatter=matplotlib.ticker.FormatStrFormatter(
'%d')
160 minorLocator=matplotlib.ticker.LinearLocator(numticks=4*nticks)
161 ax.xaxis.set_major_locator(majorLocator)
162 ax.xaxis.set_major_formatter(majorFormatter)
163 ax.xaxis.set_minor_locator(minorLocator)
164 ax.set_xbound(lower=xpoints[0],upper=xpoints[-1])
166 keylist=ypoints.keys()
168 keylist.insert(0,keylist.pop(keylist.index(referenceLabel)))
171 textsummaryhead=[
'#TotalRun']
172 textsummaryline=[
'#'+str(len(xpoints))]
173 for ylabel
in keylist:
177 ax.plot(xpoints,ypoints[ylabel],label=ylabel,color=cl,drawstyle=
'steps')
178 legendlist.append(ylabel+
' '+
'%.3f'%(ytotal[ylabel])+
' '+unitstring)
179 textsummaryhead.append(
'Total'+ylabel)
180 textsummaryline.append(
'%.3f'%(ytotal[ylabel])+
' '+unitstring)
184 csvreport.writeRow(head)
185 allruns=[int(t[0])
for t
in rawdata[referenceLabel]]
186 flat.insert(0,allruns)
188 csvreport.writeRows([
list(t)
for t
in rows])
189 csvreport.writeRow(textsummaryhead)
190 csvreport.writeRow(textsummaryline)
193 ax.legend(tuple(legendlist),loc=
'upper left')
195 self.__fig.subplots_adjust(bottom=0.18,left=0.1)
198 trans=matplotlib.transforms.BlendedGenericTransform(ax.transData,ax.transAxes)
199 ax.text(xpoints[0],1.025,str(xpoints[0]),transform=trans,horizontalalignment=
'left',size=
'x-small',color=
'green',bbox=
dict(facecolor=
'white'))
200 ax.text(xpoints[-1],1.025,str(xpoints[-1]),transform=trans,horizontalalignment=
'left',size=
'x-small',color=
'green',bbox=
dict(facecolor=
'white'))
203 def plotSumX_Fill(self,rawdata={},resultlines=[],minFill=None,maxFill=None,nticks=6,yscale='linear',withannotation=False,referenceLabel='Delivered',labels=['Delivered','Recorded'],textoutput=None):
206 rawdata = {'Delivered':[(fill,runnumber,lumiperrun)],'Recorded':[(fill,runnumber,lumiperrun)]}
207 resultlines = [[fillnumber,runnumber,dellumiperrun,reclumiperrun],[fillnumber,runnumber,dellumiperrun,reclumiperrun],]
208 minFill : min fill to draw
209 maxFill : max fill to draw
210 yscale: linear,log or both
211 withannotation: wheather the boundary points should be annotated
212 textoutput: text output file name.
216 for r
in resultlines:
219 if rawdata
and (fillnum,runnum)
in [(t[0],t[1])
for t
in rawdata[referenceLabel]]:
continue
220 if minFill
and fillnum<minFill:
continue
221 if maxFill
and fillnum>maxFill:
continue
222 for i,lab
in enumerate(labels) :
223 v=float(r[-(len(labels)-i)])
224 rawdata.setdefault(lab,[]).
append((fillnum,runnum,v))
227 print '[WARNING]: no data, do nothing'
229 tot=sum([t[2]
for t
in rawdata[referenceLabel]])
236 for label,yvalues
in rawdata.items():
238 flat.append([t[2]
for t
in yvalues])
241 lumivals=[t[2]
for t
in yvalues]
242 for i,val
in enumerate(lumivals):
243 ypoints[label].
append(sum(lumivals[0:i+1])/denomitor)
244 ytotal[label]=sum(lumivals)/denomitor
245 xpoints=[t[0]
for t
in rawdata[referenceLabel]]
246 ax=self.__fig.add_subplot(111)
247 ax.set_xlabel(
r'LHC Fill Number',position=(0.84,0))
248 ax.set_ylabel(
r'L '+unitstring,position=(0,0.9))
249 ax.set_xbound(lower=xpoints[0],upper=xpoints[-1])
251 ax.set_yscale(
'linear')
255 raise 'unsupported yscale ',yscale
256 xticklabels=ax.get_xticklabels()
257 majorLocator=matplotlib.ticker.LinearLocator( nticks )
258 majorFormatter=matplotlib.ticker.FormatStrFormatter(
'%d')
260 ax.xaxis.set_major_locator(majorLocator)
261 ax.xaxis.set_major_formatter(majorFormatter)
264 keylist=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=ypoints.keys()
380 keylist.insert(0,keylist.pop(keylist.index(referenceLabel)))
382 head=[
'#Run',
'StartTime',
'StopTime']
383 textsummaryhead=[
'#TotalRun']
384 textsummaryline=[
'#'+str(len(xpoints))]
385 for ylabel
in keylist:
389 ax.plot(xpoints,ypoints[ylabel],label=ylabel,color=cl,drawstyle=
'steps')
390 legendlist.append(ylabel+
' '+
'%.3f'%(ytotal[ylabel])+
' '+unitstring)
391 textsummaryhead.append(
'Total'+ylabel)
392 textsummaryline.append(
'%.3f'%(ytotal[ylabel])+
' '+unitstring)
396 csvreport.writeRow(head)
397 allruns=[int(t[0])
for t
in rawdata[referenceLabel]]
398 allstarts=[ lut.DatetimeToStr(t[1],customfm=
'%Y-%m-%d %H:%M:%S')
for t
in rawdata[referenceLabel] ]
399 allstops=[ lut.DatetimeToStr(t[2],customfm=
'%Y-%m-%d %H:%M:%S')
for t
in rawdata[referenceLabel] ]
400 flat.insert(0,allruns)
401 flat.insert(1,allstarts)
402 flat.insert(2,allstops)
404 csvreport.writeRows([
list(t)
for t
in rows])
405 csvreport.writeRow(textsummaryhead)
406 csvreport.writeRow(textsummaryline)
408 trans=matplotlib.transforms.BlendedGenericTransform(ax.transData,ax.transAxes)
413 runs=[t[0]
for t
in rawdata[referenceLabel]]
414 ax.text(xpoints[0],1.025,str(runs[0]),transform=trans,horizontalalignment=
'left',size=
'x-small',color=
'green',bbox=
dict(facecolor=
'white'))
415 ax.text(xpoints[-1],1.025,str(runs[-1]),transform=trans,horizontalalignment=
'left',size=
'x-small',color=
'green',bbox=
dict(facecolor=
'white'))
417 if yearStrMin==yearStrMax:
418 firsttimeStr=rawdata[referenceLabel][1][1].strftime(
'%b %d %H:%M')
419 lasttimeStr=rawdata[referenceLabel][-1][2].strftime(
'%b %d %H:%M')
423 ax.set_title(
'CMS Total Integrated Luminosity '+yearStrMin+
' ('+firsttimeStr+
' - '+lasttimeStr+
' UTC)',size=
'small')
426 ax.set_title(
'CMS Total Integrated Luminosity '+yearStrMin+
'-'+yearStrMax,size=
'small')
427 ax.legend(tuple(legendlist),loc=
'upper left')
428 ax.autoscale_view(tight=
True,scalex=
True,scaley=
False)
429 self.__fig.autofmt_xdate(bottom=0.18,rotation=15,ha=
'right')
430 self.__fig.subplots_adjust(bottom=0.2,left=0.15)
432 def plotPerdayX_Time(self,rawdata={},resultlines=[],minTime=None,maxTime=None,nticks=6,yscale='linear',withannotation=False,referenceLabel='Delivered',labels=['Delivered','Recorded'],textoutput=None):
435 rawdata={'Delivered':[(day,begrun:ls,endrun:ls,lumi)],'Recorded':[(dayofyear,begrun:ls,endrun:ls,lumi)]}
436 resultlines=[[day,begrun:ls,endrun:ls,deliveredperday,recordedperday],[]]
437 minTime (python DateTime) : min *begin* time to draw: format %m/%d/%y %H:%M:%S
438 maxTime (python DateTime): max *begin* time to draw %m/%d/%y %H:%M:%S
439 withannotation: wheather the boundary points should be annotated
440 referenceLabel: the one variable that decides the total unit and the plot x-axis range
441 labels: labels of the variables to plot
448 minTime=
'03/01/10 00:00:00'
449 minTime=lut.StrToDatetime(minTime,customfm=
'%m/%d/%y %H:%M:%S')
451 maxTime=datetime.datetime.utcnow()
453 maxTime=lut.StrToDatetime(maxTime,customfm=
'%m/%d/%y %H:%M:%S')
454 for r
in resultlines:
459 if rawdata
and day
in [t[0]
for t
in rawdata[referenceLabel]]:
continue
460 if day < minTime.date().toordinal():
continue
461 if day > maxTime.date().toordinal():
continue
462 for i,lab
in enumerate(labels):
463 v=float(r[-(len(labels)-i)-1])
464 rawdata.setdefault(lab,[]).
append((day,begrunls,endrunls,v))
466 print '[WARNING]: no data, do nothing'
468 maxlum=
max([t[3]
for t
in rawdata[referenceLabel]])
469 minlum=
min([t[3]
for t
in rawdata[referenceLabel]
if t[3]>0])
474 MinDay=minTime.date().toordinal()
475 MaxDay=maxTime.date().toordinal()
476 fulldays=range(MinDay,MaxDay+1)
479 for label,yvalues
in rawdata.items():
481 flat.append([t[3]
for t
in yvalues])
482 alldays=[t[0]
for t
in yvalues]
483 alldates=[str(datetime.date.fromordinal(t))
for t
in alldays]
485 lumivals=[t[3]
for t
in yvalues]
488 ypoints[label].
append(0.0)
490 thisdaylumi=[t[3]
for t
in yvalues
if t[0]==d][0]
492 if thisdaylumi<minlum:
493 thisdaylumi=minlum/denomitor
495 thisdaylumi=thisdaylumi/denomitor
497 thisdaylumi=thisdaylumi/denomitor
498 ypoints[label].
append(thisdaylumi)
499 ymax[label]=
max(lumivals)/denomitor
503 head=[
'#day',
'begrunls',
'endrunls',
'delivered',
'recorded',
'date']
504 csvreport.writeRow(head)
505 flat.insert(0,alldays)
506 allstarts=[ t[1]
for t
in rawdata[referenceLabel]]
507 allstops=[ t[2]
for t
in rawdata[referenceLabel]]
509 flat.insert(1,allstarts)
510 flat.insert(2,allstops)
511 flat.append(alldates)
513 csvreport.writeRows([
list(t)
for t
in rows])
514 yearStrMin=minTime.strftime(
'%Y')
515 yearStrMax=maxTime.strftime(
'%Y')
516 if yearStrMin==yearStrMax:
517 dateFmt=matplotlib.dates.DateFormatter(
'%d/%m')
519 dateFmt=matplotlib.dates.DateFormatter(
'%d/%m/%y')
520 ax=self.__fig.add_subplot(111)
522 ax.set_yscale(
'linear')
526 raise 'unsupported yscale ',yscale
527 majorLoc=matplotlib.ticker.LinearLocator(numticks=nticks)
528 minorLoc=matplotlib.ticker.LinearLocator(numticks=nticks*4)
529 ax.xaxis.set_major_formatter(dateFmt)
530 ax.set_xlabel(
r'Date',position=(0.84,0))
531 ax.xaxis.set_major_locator(majorLoc)
532 ax.xaxis.set_minor_locator(minorLoc)
533 xticklabels=ax.get_xticklabels()
534 for tx
in xticklabels:
535 tx.set_horizontalalignment(
'right')
538 ax.set_ylabel(
r'L '+unitstring,position=(0,0.9))
539 textsummaryhead=[
'#TotalRunningDays']
540 textsummaryline=[
'#'+str(len(alldays))]
541 for ylabel
in labels:
545 ax.plot(xpoints,ypoints[ylabel],label=ylabel,color=cl,drawstyle=
'steps')
546 legendlist.append(ylabel+
' Max '+
'%.3f'%(ymax[ylabel])+
' '+unitstring)
547 textsummaryhead.append(
'Max'+ylabel)
548 textsummaryline.append(
'%.3f'%(ymax[ylabel])+
' '+unitstring)
550 csvreport.writeRow(textsummaryhead)
551 csvreport.writeRow(textsummaryline)
552 ax.legend(tuple(legendlist),loc=
'upper left')
553 ax.set_xbound(lower=matplotlib.dates.date2num(minTime),upper=matplotlib.dates.date2num(maxTime))
564 firstday=datetime.date.fromordinal(rawdata[referenceLabel][0][0])
565 lastday=datetime.date.fromordinal(rawdata[referenceLabel][-1][0])
566 firstdayStr=firstday.strftime(
'%Y %b %d')
567 lastdayStr=lastday.strftime(
'%Y %b %d')
568 ax.set_title(
'CMS Integrated Luminosity/Day ('+firstdayStr+
' - '+lastdayStr+
')',size=
'small')
570 ax.autoscale_view(tight=
True,scalex=
True,scaley=
False)
572 self.__fig.autofmt_xdate(bottom=0.18,rotation=15,ha=
'right')
573 self.__fig.subplots_adjust(bottom=0.2,left=0.15)
575 def plotPeakPerday_Time(self,rawdata={},resultlines=[],minTime=None,maxTime=None,nticks=6,withannotation=False,yscale='linear',referenceLabel='Delivered',labels=['Delivered'],textoutput=None):
577 THIS PLOT IS DELIVERED ONLY
579 rawdata={'Delivered':[(day,run,ls,instlumi)]}
580 resultlines=[[day,run,ls,maxinstlum],[]]
581 minTime (python DateTime) : min *begin* time to draw: format %m/%d/%y %H:%M:%S
582 maxTime (python DateTime): max *begin* time to draw %m/%d/%y %H:%M:%S
583 withannotation: wheather the boundary points should be annotated
584 referenceLabel: the one variable that decides the total unit and the plot x-axis range
585 labels: labels of the variables to plot
594 minTime=
'03/01/10 00:00:00'
595 minTime=lut.StrToDatetime(minTime,customfm=
'%m/%d/%y %H:%M:%S')
597 maxTime=datetime.datetime.utcnow()
599 maxTime=lut.StrToDatetime(maxTime,customfm=
'%m/%d/%y %H:%M:%S')
600 for r
in resultlines:
603 lsnum=int(r[2].
split(
'.')[0])
604 if rawdata
and day
in [int(t[0])
for t
in rawdata[referenceLabel]]:
continue
605 if day < minTime.date().toordinal():
continue
606 if day > maxTime.date().toordinal():
continue
607 for i,lab
in enumerate(labels):
608 v=float(r[-(len(labels)-i)-1])
609 rawdata.setdefault(lab,[]).
append((day,runnumber,lsnum,v))
611 print '[WARNING]: no data, do nothing'
613 maxlum=
max([t[3]
for t
in rawdata[referenceLabel]])
614 minlum=
min([t[3]
for t
in rawdata[referenceLabel]
if t[3]>0])
620 MinDay=minTime.date().toordinal()
621 MaxDay=maxTime.date().toordinal()
622 fulldays=range(MinDay,MaxDay+1)
623 for label
in rawdata.keys():
624 yvalues=rawdata[label]
626 alldays=[t[0]
for t
in yvalues]
627 alldates=[str(datetime.date.fromordinal(t))
for t
in alldays]
629 lumivals=[t[3]
for t
in yvalues]
630 flat.append(lumivals)
633 ypoints[label].
append(0.0)
635 thisdaylumi=[t[3]
for t
in yvalues
if t[0]==d][0]
637 if thisdaylumi<minlum:
638 thisdaylumi=minlum/denomitor
640 thisdaylumi=thisdaylumi/denomitor
642 thisdaylumi=thisdaylumi/denomitor
643 ypoints[label].
append(thisdaylumi)
644 ymax[label]=
max(lumivals)/denomitor
645 'ymax ',
max(lumivals)
649 head=[
'#day',
'run',
'lsnum',
'maxinstlumi',
'date']
650 csvreport.writeRow(head)
651 flat.insert(0,alldays)
652 allruns=[ t[1]
for t
in rawdata[referenceLabel]]
653 allls=[ t[2]
for t
in rawdata[referenceLabel]]
654 flat.insert(1,allruns)
656 flat.append(alldates)
658 csvreport.writeRows([
list(t)
for t
in rows])
660 yearStrMin=minTime.strftime(
'%Y')
661 yearStrMax=maxTime.strftime(
'%Y')
662 if yearStrMin==yearStrMax:
663 dateFmt=matplotlib.dates.DateFormatter(
'%d/%m')
665 dateFmt=matplotlib.dates.DateFormatter(
'%d/%m/%y')
666 ax=self.__fig.add_subplot(111)
668 ax.set_yscale(
'linear')
672 raise 'unsupported yscale ',yscale
673 majorLoc=matplotlib.ticker.LinearLocator(numticks=nticks)
674 minorLoc=matplotlib.ticker.LinearLocator(numticks=nticks*4)
675 ax.xaxis.set_major_formatter(dateFmt)
676 ax.set_xlabel(
r'Date',position=(0.84,0))
677 ax.set_ylabel(
r'L '+unitstring,position=(0,0.9))
678 ax.xaxis.set_major_locator(majorLoc)
679 ax.xaxis.set_minor_locator(minorLoc)
680 xticklabels=ax.get_xticklabels()
681 for tx
in xticklabels:
682 tx.set_horizontalalignment(
'right')
685 textsummaryhead=[
'#TotalRunningDays']
686 textsummaryline=[
'#'+str(len(alldays))]
687 for ylabel
in labels:
691 ax.plot(xpoints,ypoints[ylabel],label=
'Max Inst',color=cl,drawstyle=
'steps')
692 legendlist.append(
'Max Inst %.3f'%(ymax[ylabel])+
' '+unitstring)
693 textsummaryhead.append(
'Max Inst'+ylabel)
694 textsummaryline.append(
'%.3f'%(ymax[ylabel])+
' '+unitstring)
696 csvreport.writeRow(textsummaryhead)
697 csvreport.writeRow(textsummaryline)
698 ax.legend(tuple(legendlist),loc=
'upper left')
699 ax.set_xbound(lower=matplotlib.dates.date2num(minTime),upper=matplotlib.dates.date2num(maxTime))
702 trans=matplotlib.transforms.BlendedGenericTransform(ax.transData,ax.transAxes)
703 ax.text(xpoints[0],1.025,beginfo,transform=trans,horizontalalignment=
'left',size=
'x-small',color=
'green',bbox=
dict(facecolor=
'white'))
704 ax.text(xpoints[-1],1.025,endinfo,transform=trans,horizontalalignment=
'left',size=
'x-small',color=
'green',bbox=
dict(facecolor=
'white'))
705 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'))
707 firstday=datetime.date.fromordinal(rawdata[referenceLabel][0][0])
708 lastday=datetime.date.fromordinal(rawdata[referenceLabel][-1][0])
709 firstdayStr=firstday.strftime(
'%Y %b %d')
710 lastdayStr=lastday.strftime(
'%Y %b %d')
711 ax.set_title(
'CMS Peak Luminosity/Day ('+firstdayStr+
' - '+lastdayStr+
')',size=
'small')
714 ax.autoscale_view(tight=
True,scalex=
True,scaley=
False)
716 self.__fig.autofmt_xdate(bottom=0.18,rotation=15,ha=
'right')
717 self.__fig.subplots_adjust(bottom=0.2,left=0.15)
721 Input: rawxdata [run,fill,starttime,stoptime,totalls,ncmsls]
722 rawydata {label:[lumi]}
728 starttime=lut.DatetimeToStr(rawxdata[2],customfm=
'%m/%d/%y %H:%M:%S')
729 stoptime=lut.DatetimeToStr(rawxdata[3],customfm=
'%m/%d/%y %H:%M:%S')
732 peakinst=
max(rawydata[
'Delivered'])/lslength
733 totaldelivered=sum(rawydata[
'Delivered'])
734 totalrecorded=sum(rawydata[
'Recorded'])
735 xpoints=range(1,totalls+1)
739 for ylabel,yvalue
in rawydata.items():
740 ypoints[ylabel]=[y/lslength
for y
in yvalue]
741 ymax[ylabel]=
max(yvalue)/lslength
746 bottom_h=bottom+height
747 rect_scatter=[left,bottom,width,height]
748 rect_table=[left,bottom_h,width,0.25]
750 nullfmt=matplotlib.ticker.NullFormatter()
751 nullloc=matplotlib.ticker.NullLocator()
752 axtab=self.__fig.add_axes(rect_table,frameon=
False)
754 axtab.xaxis.set_major_formatter(nullfmt)
755 axtab.yaxis.set_major_formatter(nullfmt)
756 axtab.xaxis.set_major_locator(nullloc)
757 axtab.yaxis.set_major_locator(nullloc)
759 ax=self.__fig.add_axes(rect_scatter)
761 majorLoc=matplotlib.ticker.LinearLocator(numticks=nticks)
762 minorLoc=matplotlib.ticker.LinearLocator(numticks=nticks*4)
763 ax.set_xlabel(
r'LS',position=(0.96,0))
764 ax.set_ylabel(
r'L $\mu$b$^{-1}$s$^{-1}$',position=(0,0.9))
765 ax.xaxis.set_major_locator(majorLoc)
766 ax.xaxis.set_minor_locator(minorLoc)
767 ax.set_xbound(lower=xpoints[0],upper=xpoints[-1])
768 xticklabels=ax.get_xticklabels()
769 for tx
in xticklabels:
770 tx.set_horizontalalignment(
'right')
772 keylist=ypoints.keys()
776 for ylabel
in keylist:
780 ax.plot(xpoints,ypoints[ylabel],
'.',label=ylabel,color=cl)
781 legendlist.append(ylabel)
783 ax.axvline(xpoints[ncmsls-1],color=
'green',linewidth=0.2)
785 colLabels=(
'run',
'fill',
'max inst(/$\mu$b/s)',
'delivered('+unitstring+
')',
'recorded('+unitstring+
')')
786 cellText=[[str(runnum),str(fill),
'%.3f'%(peakinst),
'%.3f'%(totaldelivered/denomitor),
'%.3f'%(totalrecorded/denomitor)]]
788 sumtable=axtab.table(cellText=cellText,colLabels=colLabels,colWidths=[0.12,0.1,0.27,0.27,0.27],cellLoc=
'center',loc=
'center')
789 trans=matplotlib.transforms.BlendedGenericTransform(ax.transData,ax.transAxes)
790 axtab.add_table(sumtable)
792 ax.text(xpoints[0],1.02,starttime[0:17],transform=trans,horizontalalignment=
'left',size=
'x-small',color=
'green',bbox=
dict(facecolor=
'white'))
793 ax.text(xpoints[ncmsls-1],1.02,stoptime[0:17],transform=trans,horizontalalignment=
'left',size=
'x-small',color=
'green',bbox=
dict(facecolor=
'white'))
794 ax.legend(tuple(legendlist),loc=
'upper right',numpoints=1)
798 cherrypy.response.headers[
'Content-Type']=
'image/png'
800 self.__canvas.print_png(buf)
801 return buf.getvalue()
805 self.__canvas.print_figure(filename)
809 print 'interactive mode is not available for your setup, exit'
815 if __name__==
'__main__':
817 print '=====testing plotSumX_Run======'
818 f=open(
'/afs/cern.ch/cms/lumi/www/plots/operation/totallumivsrun-2011.csv',
'r')
819 reader=csv.reader(f,delimiter=',')
822 if not row[0].isdigit():
continue
823 resultlines.append(row)
825 fig=Figure(figsize=(7.2,5.4),dpi=120)
827 m.plotSumX_Run(rawdata={},resultlines=resultlines,minRun=
None,maxRun=
None,nticks=6,yscale=
'linear',withannotation=
False)
833 print '=====testing plotSumX_Fill======'
834 f=open('/afs/cern.ch/cms/lumi/www/plots/operation/totallumivsfill-2011.csv','r')
835 reader=csv.reader(f,delimiter=',')
838 if not row[0].isdigit():
continue
839 resultlines.append(row)
841 fig=Figure(figsize=(7.2,5.4),dpi=120)
843 m.plotSumX_Fill(rawdata={},resultlines=resultlines,minFill=
None,maxFill=
None,nticks=6,yscale=
'linear',withannotation=
True)
844 m.drawPNG(
'totallumivsfill-2011test.png')
846 print '=====testing plotSumX_Time======'
847 f=open(
'/afs/cern.ch/cms/lumi/www/publicplots/totallumivstime-2011.csv',
'r')
848 reader=csv.reader(f,delimiter=',')
851 if not row[0].isdigit():
continue
852 resultlines.append(row)
854 fig=Figure(figsize=(7.25,5.4),dpi=120)
856 m.plotSumX_Time(rawdata={},resultlines=resultlines,minTime=
"03/14/11 09:00:00",maxTime=
None,nticks=6,yscale=
'linear',withannotation=
False)
857 m.drawPNG(
'totallumivstime-2011test.png')
860 print '=====testing plotPerdayX_Time======'
861 f=open(
'/afs/cern.ch/cms/lumi/www/publicplots/lumiperday-2011.csv',
'r')
862 reader=csv.reader(f,delimiter=',')
865 if not row[0].isdigit():
continue
866 resultlines.append(row)
868 fig=Figure(figsize=(7.25,5.4),dpi=120)
870 m.plotPerdayX_Time(rawdata={},resultlines=resultlines,minTime=
"03/14/11 09:00:00",maxTime=
None,nticks=6,yscale=
'linear',withannotation=
False)
871 m.drawPNG(
'lumiperday-2011test.png')
874 print '=====testing plotPeakPerday_Time======'
875 f=open(
'/afs/cern.ch/cms/lumi/www/publicplots/lumipeak-2011.csv',
'r')
876 reader=csv.reader(f,delimiter=',')
879 if not row[0].isdigit():
continue
880 resultlines.append(row)
882 fig=Figure(figsize=(7.25,5.4),dpi=120)
884 m.plotPeakPerday_Time(rawdata={},resultlines=resultlines,minTime=
"03/14/11 09:00:00",maxTime=
None,nticks=6,yscale=
'linear',withannotation=
False)
885 m.drawPNG(
'lumipeak-2011test.png')
boost::dynamic_bitset append(const boost::dynamic_bitset<> &bs1, const boost::dynamic_bitset<> &bs2)
this method takes two bitsets bs1 and bs2 and returns result of bs2 appended to the end of bs1 ...
OutputIterator zip(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
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