195 allowedscales=[
'linear',
'log',
'both']
199 parser.add_argument(
'-c',dest=
'connect',action=
'store',required=
True,help=
'connect string to lumiDB')
201 parser.add_argument(
'-P',dest=
'authpath',action=
'store',help=
'path to authentication file')
202 parser.add_argument(
'-n',dest=
'normfactor',action=
'store',help=
'normalization factor (optional, default to 1.0)')
203 parser.add_argument(
'-i',dest=
'inputfile',action=
'store',help=
'lumi range selection file (optional)')
204 parser.add_argument(
'-o',dest=
'outputfile',action=
'store',help=
'csv outputfile name (optional)')
205 parser.add_argument(
'-lumiversion',dest=
'lumiversion',default=
'0001',action=
'store',required=
False,help=
'lumi data version')
206 parser.add_argument(
'-begin',dest=
'begin',action=
'store',help=
'begin value of x-axi (required)')
207 parser.add_argument(
'-end',dest=
'end',action=
'store',help=
'end value of x-axi (optional). Default to the maximum exists DB')
208 parser.add_argument(
'-beamenergy',dest=
'beamenergy',action=
'store',type=float,required=
False,help=
'beamenergy (in GeV) selection criteria,e.g. 3.5e3')
209 parser.add_argument(
'-beamfluctuation',dest=
'beamfluctuation',action=
'store',type=float,required=
False,help=
'allowed fraction of beamenergy to fluctuate, e.g. 0.1')
210 parser.add_argument(
'-beamstatus',dest=
'beamstatus',action=
'store',required=
False,help=
'selection criteria beam status,e.g. STABLE BEAMS')
211 parser.add_argument(
'-yscale',dest=
'yscale',action=
'store',required=
False,default=
'linear',help=
'y_scale')
212 parser.add_argument(
'-hltpath',dest=
'hltpath',action=
'store',help=
'specific hltpath to calculate the recorded luminosity. If specified aoverlays the recorded luminosity for the hltpath on the plot')
213 parser.add_argument(
'-batch',dest=
'batch',action=
'store',help=
'graphical mode to produce PNG file. Specify graphical file here. Default to lumiSum.png')
214 parser.add_argument(
'--annotateboundary',dest=
'annotateboundary',action=
'store_true',help=
'annotate boundary run numbers')
215 parser.add_argument(
'--interactive',dest=
'interactive',action=
'store_true',help=
'graphical mode to draw plot in a TK pannel.')
216 parser.add_argument(
'-timeformat',dest=
'timeformat',action=
'store',help=
'specific python timeformat string (optional). Default mm/dd/yy hh:min:ss.00')
217 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')
218 parser.add_argument(
'action',choices=[
'run',
'fill',
'time',
'perday'],help=
'x-axis data type of choice')
220 parser.add_argument(
'--verbose',dest=
'verbose',action=
'store_true',help=
'verbose mode, print result also to screen')
221 parser.add_argument(
'--debug',dest=
'debug',action=
'store_true',help=
'debug')
224 args=parser.parse_args()
225 connectstring=args.connect
228 beamstatus=args.beamstatus
229 beamenergy=args.beamenergy
230 beamfluctuation=args.beamfluctuation
233 connectparser.parse()
234 usedefaultfrontierconfig=
False
236 if connectparser.needsitelocalinfo():
237 if not args.siteconfpath:
238 cacheconfigpath=os.environ[
'CMS_PATH']
240 cacheconfigpath=os.path.join(cacheconfigpath,
'SITECONF',
'local',
'JobConfig',
'site-local-config.xml')
242 usedefaultfrontierconfig=
True
244 cacheconfigpath=args.siteconfpath
245 cacheconfigpath=os.path.join(cacheconfigpath,
'site-local-config.xml')
247 if usedefaultfrontierconfig:
248 p.parseString(c.defaultfrontierConfigString)
250 p.parse(cacheconfigpath)
251 connectstring=connectparser.fullfrontierStr(connectparser.schemaname(),p.parameterdict())
254 svc = coral.ConnectionService()
259 msg=coral.MessageStream(
'')
260 msg.setMsgVerbosity(coral.message_Level_Debug)
262 ofilename=
'integratedlumi.png'
264 if args.authpath
and len(args.authpath)!=0:
265 os.environ[
'CORAL_AUTH_PATH']=args.authpath
267 c.NORM=float(args.normfactor)
269 c.LUMIVERSION=args.lumiversion
273 ifilename=args.inputfile
277 ofilename=args.outputfile
279 timeformat=args.timeformat
280 session=svc.connect(connectstring,accessMode=coral.access_Update)
281 session.typeConverter().setCppTypeForSqlType(
"unsigned int",
"NUMBER(10)")
282 session.typeConverter().setCppTypeForSqlType(
"unsigned long long",
"NUMBER(20)")
304 if len(ifilename)!=0:
306 runsandls=ifparser.runsandls()
307 keylist=runsandls.keys()
310 if not selectionDict.has_key(run):
311 lslist=runsandls[run]
313 selectionDict[run]=lslist
314 if args.action ==
'run':
316 session.transaction().
start(
True)
317 schema=session.nominalSchema()
318 lastrun=
max(
lumiQueryAPI.allruns(schema,requireRunsummary=
True,requireLumisummary=
True,requireTrg=
True,requireHlt=
True))
319 session.transaction().commit()
321 lastrun=int(args.end)
322 for r
in range(int(args.begin),lastrun+1):
324 elif args.action ==
'fill':
325 session.transaction().
start(
True)
328 qHandle=session.nominalSchema().newQuery()
332 maxfill=int(args.end)
333 qHandle=session.nominalSchema().newQuery()
336 session.transaction().commit()
338 for fill
in range(int(args.begin),maxfill+1):
339 if fillDict.has_key(fill):
340 for run
in fillDict[fill]:
342 elif args.action ==
'time' or args.action ==
'perday':
343 session.transaction().
start(
True)
345 minTime=t.StrToDatetime(args.begin,timeformat)
347 maxTime=datetime.datetime.utcnow()
349 maxTime=t.StrToDatetime(args.end,timeformat)
351 qHandle=session.nominalSchema().newQuery()
353 session.transaction().commit()
354 runList=runDict.keys()
358 print 'unsupported action ',args.action
364 fig=Figure(figsize=(6,4.5),dpi=100)
367 logfig=Figure(figsize=(6.8,4.5),dpi=100)
370 if args.action ==
'run':
372 result=
getLumiInfoForRuns(session,c,runList,selectionDict,hltpath,beamstatus=beamstatus,beamenergy=beamenergy,beamfluctuation=beamfluctuation)
375 ydata[
'Delivered']=[]
377 keylist=result.keys()
381 fieldnames=[
'run',
'delivered',
'recorded']
382 reporter.writeRow(fieldnames)
385 delivered=result[run][0]
386 recorded=result[run][1]
387 ydata[
'Delivered'].
append(delivered)
388 ydata[
'Recorded'].
append(recorded)
389 if args.outputfile
and (delivered!=0
or recorded!=0):
390 reporter.writeRow([run,result[run][0],result[run][1]])
391 m.plotSumX_Run(xdata,ydata,yscale=
'linear')
392 mlog.plotSumX_Run(xdata,ydata,yscale=
'log')
393 elif args.action ==
'fill':
395 lumiDict=
getLumiInfoForRuns(session,c,runList,selectionDict,hltpath,beamstatus=beamstatus,beamenergy=beamenergy,beamfluctuation=beamfluctuation)
398 ydata[
'Delivered']=[]
404 fieldnames=[
'fill',
'run',
'delivered',
'recorded']
405 reporter.writeRow(fieldnames)
406 fills=fillDict.keys()
413 ydata[
'Delivered'].
append(lumiDict[run][0])
414 ydata[
'Recorded'].
append(lumiDict[run][1])
416 reporter.writeRow([fill,run,lumiDict[run][0],lumiDict[run][1]])
418 m.plotSumX_Fill(xdata,ydata,fillDict,yscale=
'linear')
419 mlog.plotSumX_Fill(xdata,ydata,fillDict,yscale=
'log')
420 elif args.action ==
'time' :
422 lumiDict=
getLumiInfoForRuns(session,c,runList,selectionDict,hltpath,beamstatus=beamstatus,beamenergy=beamenergy,beamfluctuation=beamfluctuation)
426 ydata[
'Delivered']=[]
428 keylist=lumiDict.keys()
432 fieldnames=[
'run',
'starttime',
'stoptime',
'delivered',
'recorded']
433 reporter.writeRow(fieldnames)
435 ydata[
'Delivered'].
append(lumiDict[run][0])
436 ydata[
'Recorded'].
append(lumiDict[run][1])
437 starttime=runDict[run][0]
438 stoptime=runDict[run][1]
439 xdata[run]=[starttime,stoptime]
441 reporter.writeRow([run,starttime,stoptime,lumiDict[run][0],lumiDict[run][1]])
442 m.plotSumX_Time(xdata,ydata,minTime,maxTime,hltpath=hltpath,annotateBoundaryRunnum=args.annotateboundary,yscale=
'linear')
443 mlog.plotSumX_Time(xdata,ydata,minTime,maxTime,hltpath=hltpath,annotateBoundaryRunnum=args.annotateboundary,yscale=
'log')
444 elif args.action ==
'perday':
446 lumibyls=
getLumiOrderByLS(session,c,runList,selectionDict,hltpath,beamstatus=beamstatus,beamenergy=beamenergy,beamfluctuation=beamfluctuation)
451 fieldnames=[
'day',
'begrunls',
'endrunls',
'delivered',
'recorded']
452 reporter.writeRow(fieldnames)
453 beginfo=[lumibyls[0][3],str(lumibyls[0][0])+
':'+str(lumibyls[0][2])]
454 endinfo=[lumibyls[-1][3],str(lumibyls[-1][0])+
':'+str(lumibyls[-1][2])]
455 for perlsdata
in lumibyls:
456 lsstarttime=perlsdata[3]
457 delivered=perlsdata[4]
458 recorded=perlsdata[5]
459 day=lsstarttime.toordinal()
460 if not daydict.has_key(day):
462 daydict[day].
append([delivered,recorded])
469 resultbyday[
'Delivered']=[]
470 resultbyday[
'Recorded']=[]
474 for day
in range(daymin,daymax+1):
475 if not daydict.has_key(day):
481 delivered=sum(mytransposed[0])
482 recorded=sum(mytransposed[1])
483 resultbyday[
'Delivered'].
append(delivered)
484 resultbyday[
'Recorded'].
append(recorded)
486 reporter.writeRow([day,beginfo[1],endinfo[1],delivered,recorded])
490 m.plotPerdayX_Time( range(daymin,daymax+1) ,resultbyday,minTime,maxTime,boundaryInfo=[beginfo,endinfo],annotateBoundaryRunnum=args.annotateboundary,yscale=
'linear')
491 mlog.plotPerdayX_Time( range(daymin,daymax+1),resultbyday,minTime,maxTime,boundaryInfo=[beginfo,endinfo],annotateBoundaryRunnum=args.annotateboundary,yscale=
'log')
493 raise Exception,
'must specify the type of x-axi'
498 if args.batch
and args.yscale==
'linear':
499 m.drawPNG(args.batch)
500 elif args.batch
and args.yscale==
'log':
501 mlog.drawPNG(args.batch)
502 elif args.batch
and args.yscale==
'both':
503 m.drawPNG(args.batch)
504 basename,extension=os.path.splitext(args.batch)
505 logfilename=basename+
'_log'+extension
506 mlog.drawPNG(logfilename)
508 raise Exception(
'unsupported yscale for batch mode : '+args.yscale)
509 if not args.interactive:
511 if args.interactive
is True and args.yscale==
'linear':
513 elif args.interactive
is True and args.yscale==
'log':
514 mlog.drawInteractive()
raise Exception(
'unsupported yscale for interactive mode : '+args.yscale)