CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch1/src/RecoLuminosity/LumiDB/scripts/lumiPlot.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 VERSION='1.00'
00003 import os,os.path,sys,datetime,time,csv,re
00004 from RecoLuminosity.LumiDB import lumiTime,argparse,matplotRender,sessionManager,lumiCalcAPI,lumiCorrections,lumiParameters,inputFilesetParser
00005 import matplotlib
00006 from matplotlib.figure import Figure
00007 
00008 class RegexValidator(object):
00009     def __init__(self, pattern, statement=None):
00010         self.pattern = re.compile(pattern)
00011         self.statement = statement
00012         if not self.statement:
00013             self.statement = "must match pattern %s" % self.pattern
00014 
00015     def __call__(self, string):
00016         match = self.pattern.search(string)
00017         if not match:
00018             raise ValueError(self.statement)
00019         return string
00020     
00021 def parseInputFiles(inputfilename):
00022     p=inputFilesetParser.inputFilesetParser(inputfilename)
00023     runlsbyfile=p.runsandls()
00024     return runlsbyfile
00025 
00026 ##############################
00027 ## ######################## ##
00028 ## ## ################## ## ##
00029 ## ## ## Main Program ## ## ##
00030 ## ## ################## ## ##
00031 ## ######################## ##
00032 ##############################
00033 
00034 if __name__=='__main__':
00035     referenceLabel='Delivered'#from which label,lumi unit should be calculated
00036     labels=['Delivered','Recorded']#default label order
00037     allowedActions = ['run','time','fill','perday','instpeakperday']
00038     beamChoices=['PROTPHYS','IONPHYS','PAPHYS']
00039     allowedscales=['linear','log','both']
00040     beamModeChoices = [ "stable", "quiet", "either"]
00041     amodetagChoices = [ "PROTPHYS","IONPHYS",'PAPHYS' ]
00042     actiontofilebasemap={'time':'lumivstime','run':'lumivsrun','fill':'lumivsfill','perday':'lumiperday','instpeakperday':'lumipeak'}
00043     #
00044     # parse figure configuration if found
00045     #  
00046     currentdir=os.getcwd()
00047     rcparamfile='.lumiplotrc'
00048     mplrcdir=matplotlib.get_configdir()
00049     mpllumiconfig=os.path.join(mplrcdir,rcparamfile)
00050     locallumiconfig=os.path.join(currentdir,rcparamfile)
00051     figureparams={'sizex':7.5,'sizey':5.7,'dpi':135}
00052     if os.path.exists(locallumiconfig):
00053         import ConfigParser
00054         try:
00055             config=ConfigParser.RawConfigParser()
00056             config.read(locallumiconfig)
00057             figureparams['sizex']=config.getfloat('sizex')
00058             figureparams['sizey']=config.getfloat('sizey')
00059             figureparams['dpi']=config.getint('dpi')
00060         except ConfigParser.NoOptionError:
00061             pass
00062     elif os.path.exists(mpllumiconfig):
00063         import ConfigParser
00064         try:
00065             config=ConfigParser.RawConfigParser()
00066             config.read(mpllumiconfig)
00067             figureparams['sizex']=config.getfloat('sizex')
00068             figureparams['sizey']=config.getfloat('sizey')
00069             figureparams['dpi']=config.getint('dpi')
00070         except ConfigParser.NoOptionError:
00071             pass
00072     #
00073     # parse arguments
00074     #  
00075     #
00076     # basic arguments
00077     #
00078     parser = argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]),
00079                                      description="Plot luminosity as function of the time variable of choice",
00080                                      formatter_class=argparse.ArgumentDefaultsHelpFormatter)
00081     parser.add_argument('-c',
00082                         dest='connect',
00083                         action='store',
00084                         help='connect string to lumiDB',
00085                         default='frontier://LumiCalc/CMS_LUMI_PROD')
00086     parser.add_argument('-P',
00087                         dest='authpath',
00088                         action='store',
00089                         help='path to authentication file')
00090     parser.add_argument('--norm',
00091                         dest='norm',
00092                         action='store',
00093                         default='pp7TeV',
00094                         help='norm factor name or value')
00095     #
00096     #optional arg to select exact run and ls
00097     #
00098     parser.add_argument('-i',
00099                         dest='inputfile',
00100                         action='store',
00101                         help='run/ls selection file')
00102     #
00103     #optional arg to select exact hltpath or pattern
00104     #
00105     parser.add_argument('--hltpath',
00106                         dest='hltpath',
00107                         action='store',
00108                         default=None,
00109                         required=False,
00110                         help='specific hltpath or hltpath pattern to calculate the effectived luminosity (optional)')
00111     #
00112     #optional args to filter run/ls
00113     #
00114     parser.add_argument('-b',
00115                         dest='beamstatus',
00116                         action='store',
00117                         help='selection criteria beam status')
00118     #
00119     #optional args to filter *runs*, they do not select on LS level.
00120     #
00121     parser.add_argument('-f','--fill',
00122                         dest='fillnum',
00123                         action='store',
00124                         type=int,
00125                         help='specific fill',
00126                         default=None)
00127     parser.add_argument('--amodetag',
00128                         dest='amodetag',
00129                         action='store',
00130                         help='accelerator mode')
00131     parser.add_argument('--beamenergy',
00132                         dest='beamenergy',
00133                         action='store',
00134                         type=float,
00135                         default=3500,
00136                         help='beamenergy (in GeV) selection criteria')
00137     parser.add_argument('--beamfluctuation',
00138                         dest='beamfluctuation',
00139                         action='store',
00140                         type=float,
00141                         default=0.2,
00142                         help='allowed fraction of beamenergy to fluctuate')
00143     parser.add_argument('--begin',
00144                         dest='begintime',
00145                         action='store',
00146                         default='03/01/10 00:00:00',
00147                         type=RegexValidator("^\d\d/\d\d/\d\d \d\d:\d\d:\d\d$","must be form mm/dd/yy hh:mm:ss"),
00148                         help='min run start time,mm/dd/yy hh:mm:ss')
00149     parser.add_argument('--end',
00150                         dest='endtime',
00151                         action='store',
00152                         type=RegexValidator("^\d\d/\d\d/\d\d \d\d:\d\d:\d\d$","must be form mm/dd/yy hh:mm:ss"),
00153                         help='max run start time,mm/dd/yy hh:mm:ss')
00154     #
00155     #frontier config options
00156     #
00157     parser.add_argument('--siteconfpath',
00158                         dest='siteconfpath',
00159                         action='store',
00160                         help='specific path to site-local-config.xml file, default to $CMS_PATH/SITECONF/local/JobConfig, if path undefined, fallback to cern proxy&server')
00161     #
00162     #plot options
00163     #
00164     ####input/output file names
00165     parser.add_argument('--inplotdata',
00166                         dest='inplot',
00167                         action='store',
00168                         help='existing base plot(s) in text format')
00169     parser.add_argument('--outplotdata',
00170                         dest='outplot',
00171                         action='store',
00172                         help='output plot. By default, a text dump of the plot is produced.')
00173     ####graphic switches
00174     parser.add_argument('--with-annotation',
00175                         dest='withannotation',
00176                         action='store_true',
00177                         help='annotate boundary run numbers')
00178     parser.add_argument('--interactive',
00179                         dest='interactive',
00180                         action='store_true',
00181                         help='graphical mode to draw plot in a QT pannel.')
00182     parser.add_argument('--without-textoutput',
00183                         dest='withoutTextoutput',
00184                         action='store_true',
00185                         help='not to write out text output file')
00186     parser.add_argument('--yscale',
00187                         dest='yscale',
00188                         action='store',
00189                         default='linear',
00190                         help='y_scale[linear,log,both]')
00191     parser.add_argument('--lastpointfromdb',
00192                         dest='lastpointfromdb',
00193                         action='store_true',
00194                         help='the last point in the plot is always recaculated from current values in LumiDB')
00195     
00196     ####correction switches
00197     parser.add_argument('--without-correction',
00198                         dest='withoutCorrection',
00199                         action='store_true',
00200                         help='without fine correction')    
00201     parser.add_argument('--correctionv3',
00202                         dest='correctionv3',
00203                         action='store_true',
00204                         help='apply correction v3')
00205     ###general switches
00206     parser.add_argument('--verbose',
00207                         dest='verbose',
00208                         action='store_true',
00209                         help='verbose mode, print result also to screen')
00210     parser.add_argument('--debug',
00211                         dest='debug',
00212                         action='store_true',
00213                         help='debug')
00214     parser.add_argument('action',
00215                         choices=allowedActions,
00216                         help='type of plots')
00217     options=parser.parse_args()
00218     if options.yscale=='both' and options.interactive:
00219         print '--interactive mode can draw either yscale log or linear at a time'
00220         exit(0)
00221     outplotfilename = options.outplot
00222     if not outplotfilename:
00223         outplotfilename=actiontofilebasemap[options.action]
00224     outtextfilename = outplotfilename+'.csv'
00225     if options.withoutTextoutput:
00226         outtextfilename=None
00227     lumip=lumiParameters.ParametersObject()
00228     svc=sessionManager.sessionManager(options.connect,
00229                                       authpath=options.authpath,
00230                                       siteconfpath=options.siteconfpath,
00231                                       debugON=options.debug)
00232     session=svc.openSession(isReadOnly=True,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])
00233     lslength=lumip.lslengthsec()
00234     begtime=options.begintime
00235     endtime=options.endtime
00236     lut=lumiTime.lumiTime()
00237     if not endtime:
00238         endtime=lut.DatetimeToStr(datetime.datetime.utcnow(),customfm='%m/%d/%y %H:%M:%S')
00239     pbeammode=None
00240     normfactor=options.norm
00241     if options.beamstatus=='stable':
00242         pbeammode='STABLE BEAMS'
00243     resultlines=[]
00244     inplots=[]
00245     #
00246     ##process old plot csv files,if any, skipping #commentlines
00247     #
00248     inplot=options.inplot
00249     if inplot:
00250         inplots=inplot.split('+')
00251         for ip in inplots:
00252             f=open(ip,'r')
00253             reader=csv.reader(f,delimiter=',')
00254             for row in reader:
00255                 if '#' in row[0]:continue
00256                 resultlines.append(row)
00257     #
00258     ##find runs need to read from DB
00259     #
00260     irunlsdict={}#either from -i or from other selection options
00261     reqTrg=True
00262     reqHlt=False
00263     if options.hltpath:
00264         reqHlt=True
00265     session.transaction().start(True)
00266     schema=session.nominalSchema()
00267     if options.inputfile:
00268         irunlsdict=parseInputFiles(options.inputfile)
00269 
00270     fillrunMap={}
00271     finecorrections=None
00272     runlsfromDB={}#run/ls need to fetch from db
00273     runsnotdrawn=[]
00274     lastDrawnRun=None
00275     maxDrawnDay=None
00276     lastDrawnFill=None
00277     newFirstDay=None
00278     newFirstRun=None
00279     newFirstFill=None
00280 
00281     session.transaction().start(True)
00282     schema=session.nominalSchema()
00283     if options.action=='perday' or options.action=='instpeakperday':
00284         maxDrawnDay=int(lut.StrToDatetime(begtime,customfm='%m/%d/%y %H:%M:%S').date().toordinal())
00285         if resultlines:
00286             for drawnDay in [ int(t[0]) for t in resultlines]:
00287                 if drawnDay>maxDrawnDay:
00288                     maxDrawnDay=drawnDay
00289         #print maxDrawnDay
00290         newFirstDay=maxDrawnDay+1
00291         if options.lastpointfromdb:
00292             newFirstDay=maxDrawnDay
00293         midnight=datetime.time()
00294         begT=datetime.datetime.combine(datetime.date.fromordinal(newFirstDay),midnight)
00295         begTStr=lut.DatetimeToStr(begT,customfm='%m/%d/%y %H:%M:%S')
00296         #find runs not in old plot
00297         runsnotdrawn=lumiCalcAPI.runList(schema,options.fillnum,runmin=None,runmax=None,startT=begTStr,stopT=endtime,l1keyPattern=None,hltkeyPattern=None,amodetag=options.amodetag,nominalEnergy=options.beamenergy,energyFlut=options.beamfluctuation,requiretrg=reqTrg,requirehlt=reqHlt)
00298         
00299     if options.action=='run' or options.action=='time':
00300         lastDrawnRun=132000
00301         if resultlines:#if there's old plot, start to count runs only after that
00302             lastDrawnRun=max([int(t[0]) for t in resultlines])
00303         newFirstRun=lastDrawnRun+1
00304         if options.lastpointfromdb:
00305             newFirstRun=lastDrawnRun
00306         runsnotdrawn=lumiCalcAPI.runList(schema,options.fillnum,runmin=newFirstRun,runmax=None,startT=begtime,stopT=endtime,l1keyPattern=None,hltkeyPattern=None,amodetag=options.amodetag,nominalEnergy=options.beamenergy,energyFlut=options.beamfluctuation,requiretrg=reqTrg,requirehlt=reqHlt)
00307         
00308     if options.action=='fill':
00309         lastDrawnFill=1000
00310         lastDrawnRun=132000
00311         if resultlines:
00312             lastDrawnFill=max([int(t[0]) for t in resultlines])        
00313             lastDrawnRun=min([int(t[1]) for t in resultlines if int(t[0])==lastDrawnFill])
00314         newFirstRun=lastDrawnRun+1
00315         if options.lastpointfromdb:
00316             newFirstRun=lastDrawnRun
00317         runsnotdrawn=lumiCalcAPI.runList(schema,runmin=newFirstRun,runmax=None,startT=begtime,stopT=endtime,l1keyPattern=None,hltkeyPattern=None,amodetag=options.amodetag,nominalEnergy=options.beamenergy,energyFlut=options.beamfluctuation,requiretrg=reqTrg,requirehlt=reqHlt)
00318         fillrunMap=lumiCalcAPI.fillrunMap(schema,runmin=newFirstRun,runmax=None,startT=begtime,stopT=endtime)
00319     session.transaction().commit()
00320     for r in runsnotdrawn:
00321         if irunlsdict:
00322             if not irunlsdict.has_key(r):
00323                 continue                
00324             runlsfromDB[r]=irunlsdict[r]
00325         else:
00326             runlsfromDB[r]=None
00327                 
00328     if options.verbose:
00329         print '[INFO] runs from db: ',runlsfromDB
00330         if lastDrawnRun:
00331             print '[INFO] last run in old plot: ',lastDrawnRun
00332             print '[INFO] first run from DB in fresh plot: ',newFirstRun
00333         if maxDrawnDay:
00334             print '[INFO] last day in old plot: ',maxDrawnDay
00335             print '[INFO] first day from DB in fresh plot: ',newFirstDay
00336     fig=Figure(figsize=(figureparams['sizex'],figureparams['sizey']),dpi=figureparams['dpi'])
00337     m=matplotRender.matplotRender(fig)
00338     logfig=Figure(figsize=(figureparams['sizex'],figureparams['sizey']),dpi=figureparams['dpi'])
00339     mlog=matplotRender.matplotRender(logfig)
00340 
00341     if len(runlsfromDB)==0:
00342         if len(resultlines)!=0:
00343             print '[INFO] drawing all from old plot data'
00344         else:
00345             print '[INFO] found no old nor new data, do nothing'
00346             exit(0)
00347 
00348     finecorrections=None
00349     driftcorrections=None
00350     if not options.withoutCorrection:
00351         rruns=runlsfromDB.keys()
00352         session.transaction().start(True)
00353         schema=session.nominalSchema()
00354         if options.correctionv3:
00355             cterms=lumiCorrections.nonlinearV3()               
00356         else:#default
00357             cterms=lumiCorrections.nonlinearV2()
00358         finecorrections=lumiCorrections.correctionsForRangeV2(schema,rruns,cterms)#constant+nonlinear corrections
00359         driftcorrections=lumiCorrections.driftcorrectionsForRange(schema,rruns,cterms)
00360         session.transaction().commit()
00361     session.transaction().start(True)
00362     if not options.hltpath:
00363         lumibyls=lumiCalcAPI.lumiForRange(session.nominalSchema(),runlsfromDB,amodetag=options.amodetag,egev=options.beamenergy,beamstatus=pbeammode,norm=normfactor,finecorrections=finecorrections,driftcorrections=driftcorrections,usecorrectionv2=True)
00364     else:
00365         referenceLabel='Recorded'
00366         hltname=options.hltpath
00367         hltpat=None
00368         if hltname=='*' or hltname=='all':
00369             hltname=None
00370         elif 1 in [c in hltname for c in '*?[]']: #is a fnmatch pattern
00371             hltpat=hltname
00372             hltname=None
00373         lumibyls=lumiCalcAPI.effectiveLumiForRange(session.nominalSchema(),runlsfromDB,hltpathname=hltname,hltpathpattern=hltpat,amodetag=options.amodetag,egev=options.beamenergy,beamstatus=pbeammode,norm=normfactor,finecorrections=finecorrections,driftcorrections=driftcorrections,usecorrectionv2=True)
00374     session.transaction().commit()
00375     rawdata={}
00376     #
00377     # start to plot
00378     #
00379     if options.action=='run':
00380         for run in sorted(lumibyls):
00381             rundata=lumibyls[run]
00382             if not options.hltpath:
00383                 if len(rundata)!=0:
00384                     rawdata.setdefault('Delivered',[]).append((run,sum([t[5] for t in rundata])))
00385                     rawdata.setdefault('Recorded',[]).append((run,sum([t[6] for t in rundata])))
00386             else:
00387                 labels=['Recorded']
00388                 if len(rundata)!=0:
00389                     pathdict={}#{pathname:[eff,]}
00390                     rawdata.setdefault('Recorded',[]).append((run,sum([t[6] for t in rundata])))
00391                     for perlsdata in rundata:
00392                         effdict=perlsdata[8]
00393                         pathnames=effdict.keys()
00394                         for thispath in pathnames:
00395                             pathdict.setdefault(thispath,[]).append(effdict[thispath][3])
00396                     for thispath in pathdict.keys():
00397                         labels.append(thispath)
00398                         rawdata.setdefault(thispath,[]).append((run,sum([t for t in pathdict[thispath]])))
00399         if options.yscale=='linear':
00400             m.plotSumX_Run(rawdata,resultlines,textoutput=outtextfilename,yscale='linear',referenceLabel=referenceLabel,labels=labels)
00401         elif options.yscale=='log':
00402             m.plotSumX_Run(rawdata,resultlines,textoutput=outtextfilename,yscale='log',referenceLabel=referenceLabel,labels=labels)
00403         else:
00404             m.plotSumX_Run(rawdata,resultlines,textoutput=outtextfilename,yscale='linear',referenceLabel=referenceLabel,labels=labels)
00405             m.plotSumX_Run(rawdata,resultlines,textoutput=outtextfilename,yscale='log',referenceLabel=referenceLabel,labels=labels)
00406     if options.action=='fill':
00407         for fill in sorted(fillrunMap):
00408             for run in fillrunMap[fill]:
00409                 if not lumibyls.has_key(run): continue
00410                 rundata=lumibyls[run]
00411                 if not options.hltpath:
00412                     if len(rundata)!=0:
00413                         rawdata.setdefault('Delivered',[]).append((fill,run,sum([t[5] for t in rundata])))
00414                         rawdata.setdefault('Recorded',[]).append((fill,run,sum([t[6] for t in rundata])))
00415                 else:
00416                     labels=['Recorded']
00417                     if len(rundata)!=0:
00418                         pathdict={}#{pathname:[eff,]}
00419                         rawdata.setdefault('Recorded',[]).append((fill,run,sum([t[6] for t in rundata])))
00420                         for perlsdata in rundata:
00421                             effdict=perlsdata[8]
00422                             pathnames=effdict.keys()
00423                             for thispath in pathnames:
00424                                 pathdict.setdefault(thispath,[]).append(effdict[thispath][3])
00425                         for thispath in pathdict.keys():
00426                             labels.append(thispath)
00427                             rawdata.setdefault(thispath,[]).append((fill,run,sum([t for t in pathdict[thispath]])))
00428         if options.yscale=='linear':
00429             m.plotSumX_Fill(rawdata,resultlines,textoutput=outtextfilename,yscale='linear',referenceLabel=referenceLabel)
00430         elif options.yscale=='log':
00431             m.plotSumX_Fill(rawdata,resultlines,textoutput=outtextfilename,yscale='log',referenceLabel=referenceLabel)
00432         else:
00433             m.plotSumX_Fill(rawdata,resultlines,textoutput=outtextfilename,yscale='linear',referenceLabel=referenceLabel)
00434             m.plotSumX_Fill(rawdata,resultlines,textoutput=outtextfilename,yscale='log',referenceLabel=referenceLabel)
00435     if options.action=='time':
00436         for run in sorted(lumibyls):
00437             rundata=lumibyls[run]
00438             if not options.hltpath:
00439                 if len(rundata)!=0:
00440                     rawdata.setdefault('Delivered',[]).append((run,rundata[0][2],rundata[-1][2],sum([t[5] for t in rundata])))
00441                     rawdata.setdefault('Recorded',[]).append((run,rundata[0][2],rundata[-1][2],sum([t[6] for t in rundata])))
00442             else:
00443                 labels=['Recorded']
00444                 if len(rundata)!=0:
00445                     pathdict={}#{pathname:[eff,]}
00446                     rawdata.setdefault('Recorded',[]).append((run,rundata[0][2],rundata[-1][2],sum([t[6] for t in rundata])))
00447                     for perlsdata in rundata:
00448                         effdict=perlsdata[8]
00449                         pathnames=effdict.keys()
00450                         for thispath in pathnames:
00451                             pathdict.setdefault(thispath,[]).append(effdict[thispath][3])
00452                     for thispath in pathdict.keys():
00453                         labels.append(thispath)
00454                         rawdata.setdefault(thispath,[]).append((run,rundata[0][2],rundata[-1][2],sum([t for t in pathdict[thispath]])))
00455         if options.yscale=='linear':
00456             m.plotSumX_Time(rawdata,resultlines,minTime=begtime,maxTime=endtime,textoutput=outtextfilename,yscale='linear',referenceLabel=referenceLabel)
00457         elif options.yscale=='log':
00458             mlog.plotSumX_Time(rawdata,resultlines,minTime=begtime,maxTime=endtime,textoutput=outtextfilename,yscale='log',referenceLabel=referenceLabel)
00459         else:
00460             m.plotSumX_Time(rawdata,resultlines,minTime=begtime,maxTime=endtime,textoutput=outtextfilename,yscale='linear',referenceLabel=referenceLabel)
00461             mlog.plotSumX_Time(rawdata,resultlines,minTime=begtime,maxTime=endtime,textoutput=outtextfilename,yscale='log',referenceLabel=referenceLabel)
00462     if options.action=='perday':
00463         daydict={}
00464         for run in sorted(lumibyls):
00465             rundata=lumibyls[run]
00466             for lsdata in rundata:
00467                 lumilsnum=lsdata[0]
00468                 lsTS=lsdata[2]
00469                 dellum=lsdata[5]
00470                 reclum=lsdata[6]
00471                 daynumber=lsTS.date().toordinal()
00472                 daydict.setdefault(daynumber,[]).append((run,lumilsnum,dellum,reclum))
00473         for day in sorted(daydict):
00474             daydata=daydict[day]
00475             daybeg=str(daydata[0][0])+':'+str(daydata[0][1])
00476             dayend=str(daydata[-1][0])+':'+str(daydata[-1][1])
00477             daydel=sum([t[2] for t in daydata])
00478             dayrec=sum([t[3] for t in daydata])
00479             rawdata.setdefault('Delivered',[]).append((day,daybeg,dayend,daydel))
00480             rawdata.setdefault('Recorded',[]).append((day,daybeg,dayend,dayrec))
00481         #print 'rawdata ',rawdata
00482         if options.yscale=='linear':
00483             m.plotPerdayX_Time(rawdata,resultlines,minTime=begtime,maxTime=endtime,textoutput=outtextfilename,yscale='linear',referenceLabel=referenceLabel)
00484         elif options.yscale=='log':
00485             mlog.plotPerdayX_Time(rawdata,resultlines,minTime=begtime,maxTime=endtime,textoutput=outtextfilename,yscale='log',referenceLabel=referenceLabel)
00486         else:
00487             m.plotPerdayX_Time(rawdata,resultlines,minTime=begtime,maxTime=endtime,textoutput=outtextfilename,yscale='linear',referenceLabel=referenceLabel)
00488             mlog.plotPerdayX_Time(rawdata,resultlines,minTime=begtime,maxTime=endtime,textoutput=outtextfilename,yscale='log',referenceLabel=referenceLabel)
00489     if options.action=='instpeakperday':
00490         daydict={}#{daynumber:[(runnumber,lumilsnum,inst),..]}
00491         for run in sorted(lumibyls):
00492             rundata=lumibyls[run]
00493             for lsdata in rundata:
00494                 lumilsnum=lsdata[0]
00495                 lsTS=lsdata[2]
00496                 instlum=lsdata[5]/lslength
00497                 daynumber=lsTS.date().toordinal()
00498                 daydict.setdefault(daynumber,[]).append((run,lumilsnum,instlum))
00499         for day in sorted(daydict):
00500             daydata=daydict[day]
00501             daymax_val=0.0
00502             daymax_run=0
00503             daymax_ls=0
00504             for datatp in daydata:
00505                 if datatp[2]>daymax_val:
00506                     daymax_val=datatp[2]
00507                     daymax_run=datatp[0]
00508                     daymax_ls=datatp[1]
00509             rawdata.setdefault('Delivered',[]).append((day,daymax_run,daymax_ls,daymax_val))
00510         if options.yscale=='linear':
00511             m.plotPeakPerday_Time(rawdata,resultlines,minTime=begtime,maxTime=endtime,textoutput=outtextfilename,yscale='linear',referenceLabel=referenceLabel)
00512         elif options.yscale=='log':
00513             mlog.plotPeakPerday_Time(rawdata,resultlines,minTime=begtime,maxTime=endtime,textoutput=outtextfilename,yscale='log',referenceLabel=referenceLabel)
00514         else:
00515             m.plotPeakPerday_Time(rawdata,resultlines,minTime=begtime,maxTime=endtime,textoutput=outtextfilename,yscale='linear',referenceLabel=referenceLabel)
00516             mlog.plotPeakPerday_Time(rawdata,resultlines,minTime=begtime,maxTime=endtime,textoutput=outtextfilename,yscale='log',referenceLabel=referenceLabel)
00517     if options.action=='inst':
00518         thisfillnumber=fillrunMap.keys()[0]
00519         starttime=0
00520         stoptime=0
00521         rawxdata=[]
00522         rawydata={}
00523         for run,rundata in lumibyls.items():
00524             rundata.sort()
00525             totlumils=0
00526             totcmsls=0
00527             starttime=rundata[0][2]
00528             stoptime=rundata[-1][2]
00529             for lsdata in rundata:
00530                 lumilsnum=lsdata[0]
00531                 totlumils+=1
00532                 cmslsnum=lsdata[1]
00533                 if cmslsnum!=0:
00534                     totcmsls+=1
00535                 lsTS=lsdata[2]
00536                 dellumi=lsdata[5]
00537                 reclumi=lsdata[6]
00538                 rawydata.setdefault('Delivered',[]).append(dellumi)
00539                 rawydata.setdefault('Recorded',[]).append(reclumi)
00540             rawxdata=[run,thisfillnumber,starttime,stoptime,totlumils,totcmsls]
00541         m.plotInst_RunLS(rawxdata,rawydata,textoutput=None)
00542     
00543     if options.yscale=='linear':
00544         if options.interactive:
00545             m.drawInteractive()
00546             exit(0)
00547         else:
00548             m.drawPNG(outplotfilename+'.png')
00549     elif options.yscale=='log':
00550         if options.interactive:
00551             mlog.drawInteractive()
00552             exit(0)
00553         else:
00554             mlog.drawPNG(outplotfilename+'_log.png')
00555     else:
00556         m.drawPNG(outplotfilename+'.png')            
00557         mlog.drawPNG(outplotfilename+'_log.png')