00102 :
00103 allowedscales=['linear','log','both']
00104 c=constants()
00105 parser = argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]),description="Plot integrated luminosity as function of the time variable of choice")
00106
00107 parser.add_argument('-c',dest='connect',action='store',required=True,help='connect string to lumiDB')
00108
00109 parser.add_argument('-P',dest='authpath',action='store',help='path to authentication file')
00110 parser.add_argument('-n',dest='normfactor',action='store',help='normalization factor (optional, default to 1.0)')
00111 parser.add_argument('-i',dest='inputfile',action='store',help='lumi range selection file (optional)')
00112 parser.add_argument('-o',dest='outputfile',action='store',help='csv outputfile name (optional)')
00113 parser.add_argument('-b',dest='beammode',action='store',help='beam mode, optional, no default')
00114 parser.add_argument('-lumiversion',dest='lumiversion',action='store',help='lumi data version, optional for all, default 0001')
00115 parser.add_argument('-begin',dest='begin',action='store',help='begin xvalue (required)')
00116 parser.add_argument('-end',dest='end',action='store',help='end xvalue(optional). Default to the maximum exists DB')
00117 parser.add_argument('-batch',dest='batch',action='store',help='graphical mode to produce PNG file. Specify graphical file here. Default to lumiSum.png')
00118 parser.add_argument('-yscale',dest='yscale',action='store',required=False,default='linear',help='y_scale')
00119 parser.add_argument('--interactive',dest='interactive',action='store_true',help='graphical mode to draw plot in a TK pannel.')
00120 parser.add_argument('-timeformat',dest='timeformat',action='store',help='specific python timeformat string (optional). Default mm/dd/yy hh:min:ss.00')
00121 parser.add_argument('-siteconfpath',dest='siteconfpath',action='store',help='specific path to site-local-config.xml file, default to $CMS_PATH/SITECONF/local/JobConfig, if path undefined, fallback to cern proxy&server')
00122 parser.add_argument('action',choices=['peakperday','run'],help='plot type of choice')
00123
00124 parser.add_argument('--annotateboundary',dest='annotateboundary',action='store_true',help='annotate boundary run numbers')
00125 parser.add_argument('--verbose',dest='verbose',action='store_true',help='verbose mode, print result also to screen')
00126 parser.add_argument('--debug',dest='debug',action='store_true',help='debug')
00127
00128 args=parser.parse_args()
00129 connectstring=args.connect
00130 connectparser=connectstrParser.connectstrParser(connectstring)
00131 connectparser.parse()
00132 usedefaultfrontierconfig=False
00133 cacheconfigpath=''
00134 if connectparser.needsitelocalinfo():
00135 if not args.siteconfpath:
00136 cacheconfigpath=os.environ['CMS_PATH']
00137 if cacheconfigpath:
00138 cacheconfigpath=os.path.join(cacheconfigpath,'SITECONF','local','JobConfig','site-local-config.xml')
00139 else:
00140 usedefaultfrontierconfig=True
00141 else:
00142 cacheconfigpath=args.siteconfpath
00143 cacheconfigpath=os.path.join(cacheconfigpath,'site-local-config.xml')
00144 p=cacheconfigParser.cacheconfigParser()
00145 if usedefaultfrontierconfig:
00146 p.parseString(c.defaultfrontierConfigString)
00147 else:
00148 p.parse(cacheconfigpath)
00149 connectstring=connectparser.fullfrontierStr(connectparser.schemaname(),p.parameterdict())
00150 runnumber=0
00151 svc = coral.ConnectionService()
00152 if args.debug :
00153 msg=coral.MessageStream('')
00154 msg.setMsgVerbosity(coral.message_Level_Debug)
00155 ifilename=''
00156 ofilename='instlumi.csv'
00157 beammode='stable'
00158 timeformat=''
00159 selectionDict={}
00160 if args.authpath and len(args.authpath)!=0:
00161 os.environ['CORAL_AUTH_PATH']=args.authpath
00162 if args.normfactor:
00163 c.NORM=float(args.normfactor)
00164 if args.lumiversion:
00165 c.LUMIVERSION=args.lumiversion
00166 if args.beammode:
00167 c.BEAMMODE=args.beammode
00168 if args.verbose:
00169 c.VERBOSE=True
00170 if args.inputfile:
00171 ifilename=args.inputfile
00172 if args.batch:
00173 opicname=args.batch
00174 if args.outputfile:
00175 ofilename=args.outputfile
00176 if args.timeformat:
00177 timeformat=args.timeformat
00178 session=svc.connect(connectstring,accessMode=coral.access_Update)
00179 session.typeConverter().setCppTypeForSqlType("unsigned int","NUMBER(10)")
00180 session.typeConverter().setCppTypeForSqlType("unsigned long long","NUMBER(20)")
00181 if ifilename:
00182 ifparser=inputFilesetParser(ifilename)
00183 runsandls=ifparser.runsandls()
00184 keylist=runsandls.keys()
00185 keylist.sort()
00186 for run in keylist:
00187 if selectionDict.has_key(run):
00188 lslist=runsandls[run]
00189 lslist.sort()
00190 selectionDict[run]=lslist
00191 if args.action == 'run':
00192 minRun=int(args.begin)
00193 if not args.end:
00194 maxRun=minRun
00195 else:
00196 maxRun=int(args.end)
00197 runList=range(minRun,maxRun+1)
00198 elif args.action == 'peakperday':
00199 session.transaction().start(True)
00200 t=lumiTime.lumiTime()
00201 minTime=t.StrToDatetime(args.begin,timeformat)
00202 if not args.end:
00203 maxTime=datetime.datetime.utcnow()
00204 else:
00205 maxTime=t.StrToDatetime(args.end,timeformat)
00206
00207 qHandle=session.nominalSchema().newQuery()
00208 runDict=lumiQueryAPI.runsByTimerange(qHandle,minTime,maxTime)
00209 session.transaction().commit()
00210 runList=runDict.keys()
00211 del qHandle
00212 runList.sort()
00213 else:
00214 print 'unsupported action ',args.action
00215 exit
00216
00217
00218 fig=Figure(figsize=(6,4.5),dpi=100)
00219 m=matplotRender.matplotRender(fig)
00220
00221 logfig=Figure(figsize=(6,4.5),dpi=100)
00222 mlog=matplotRender.matplotRender(logfig)
00223
00224 if args.action == 'peakperday':
00225 l=lumiTime.lumiTime()
00226 lumiperls=getInstLumiPerLS(session,c,runList,selectionDict)
00227 if args.outputfile:
00228 reporter=csvReporter.csvReporter(ofilename)
00229 fieldnames=['day','run','lsnum','maxinstlumi']
00230 reporter.writeRow(fieldnames)
00231
00232
00233 daydict={}
00234 result={}
00235 for lsdata in lumiperls:
00236 runnumber=lsdata[0]
00237 lsnum=lsdata[1]
00238 runstarttimeStr=lsdata[-2]
00239 startorbit=lsdata[5]
00240 deliveredInst=lsdata[2]
00241 lsstarttime=l.OrbitToTime(runstarttimeStr,startorbit)
00242 day=lsstarttime.toordinal()
00243 if not daydict.has_key(day):
00244 daydict[day]=[]
00245 daydict[day].append([runnumber,lsnum,deliveredInst])
00246 days=daydict.keys()
00247 days.sort()
00248 for day in days:
00249 daydata=daydict[day]
00250 transposeddata=CommonUtil.transposed(daydata,defaultval=0.0)
00251 todaysmaxinst=max(transposeddata[2])
00252 todaysmaxidx=transposeddata[2].index(todaysmaxinst)
00253 todaysmaxrun=transposeddata[0][todaysmaxidx]
00254 todaysmaxls=transposeddata[1][todaysmaxidx]
00255 result[day]=[todaysmaxrun,todaysmaxls,todaysmaxinst]
00256 if args.outputfile :
00257 reporter.writeRow([day,todaysmaxrun,todaysmaxls,todaysmaxinst])
00258 m.plotPeakPerday_Time(result,minTime,maxTime,annotateBoundaryRunnum=args.annotateboundary,yscale='linear')
00259 mlog.plotPeakPerday_Time(result,minTime,maxTime,annotateBoundaryRunnum=args.annotateboundary,yscale='log')
00260
00261 if args.action == 'run':
00262 runnumber=runList[0]
00263 lumiperrun=getLumiPerRun(session,c,runnumber)
00264
00265 xdata=[]
00266 ydata={}
00267 ydata['Delivered']=[]
00268 ydata['Recorded']=[]
00269 norbit=lumiperrun[0][3]
00270 fillnum=lumiperrun[0][-3]
00271 starttime=lumiperrun[0][-2]
00272 stoptime=lumiperrun[0][-1]
00273 ncmsls=0
00274 totalls=len(lumiperrun)
00275 for lsdata in lumiperrun:
00276 lsnumber=lsdata[0]
00277 if lsnumber!=0:
00278 ncmsls+=1
00279 deliveredInst=lsdata[1]
00280 recordedInst=lsdata[2]
00281 ydata['Delivered'].append(deliveredInst)
00282 ydata['Recorded'].append(recordedInst)
00283 xdata=[runnumber,fillnum,norbit,starttime,stoptime,totalls,ncmsls]
00284 m.plotInst_RunLS(xdata,ydata)
00285 del session
00286 del svc
00287 if args.batch and args.yscale=='linear':
00288 m.drawPNG(args.batch)
00289 elif args.batch and args.yscale=='log':
00290 mlog.drawPNG(args.batch)
00291 elif args.batch and args.yscale=='both':
00292 m.drawPNG(args.batch)
00293 basename,extension=os.path.splitext(args.batch)
00294 logfilename=basename+'_log'+extension
00295 mlog.drawPNG(logfilename)
00296 else:
00297 raise Exception('unsupported yscale for batch mode : '+args.yscale)
00298
00299 if not args.interactive:
00300 return
00301 if args.interactive is True and args.yscale=='linear':
00302 m.drawInteractive()
00303 elif args.interactive is True and args.yscale=='log':
00304 mlog.drawInteractive()
00305 else:
00306 raise Exception('unsupported yscale for interactive mode : '+args.yscale)