103 allowedscales=[
'linear',
'log',
'both']
105 parser =
argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]),description=
"Plot integrated luminosity as function of the time variable of choice")
107 parser.add_argument(
'-c',dest=
'connect',action=
'store',required=
True,help=
'connect string to lumiDB')
109 parser.add_argument(
'-P',dest=
'authpath',action=
'store',help=
'path to authentication file')
110 parser.add_argument(
'-n',dest=
'normfactor',action=
'store',help=
'normalization factor (optional, default to 1.0)')
111 parser.add_argument(
'-i',dest=
'inputfile',action=
'store',help=
'lumi range selection file (optional)')
112 parser.add_argument(
'-o',dest=
'outputfile',action=
'store',help=
'csv outputfile name (optional)')
113 parser.add_argument(
'-b',dest=
'beammode',action=
'store',help=
'beam mode, optional, no default')
114 parser.add_argument(
'-lumiversion',dest=
'lumiversion',action=
'store',help=
'lumi data version, optional for all, default 0001')
115 parser.add_argument(
'-begin',dest=
'begin',action=
'store',help=
'begin xvalue (required)')
116 parser.add_argument(
'-end',dest=
'end',action=
'store',help=
'end xvalue(optional). Default to the maximum exists DB')
117 parser.add_argument(
'-batch',dest=
'batch',action=
'store',help=
'graphical mode to produce PNG file. Specify graphical file here. Default to lumiSum.png')
118 parser.add_argument(
'-yscale',dest=
'yscale',action=
'store',required=
False,default=
'linear',help=
'y_scale')
119 parser.add_argument(
'--interactive',dest=
'interactive',action=
'store_true',help=
'graphical mode to draw plot in a TK pannel.')
120 parser.add_argument(
'-timeformat',dest=
'timeformat',action=
'store',help=
'specific python timeformat string (optional). Default mm/dd/yy hh:min:ss.00')
121 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')
122 parser.add_argument(
'action',choices=[
'peakperday',
'run'],help=
'plot type of choice')
124 parser.add_argument(
'--annotateboundary',dest=
'annotateboundary',action=
'store_true',help=
'annotate boundary run numbers')
125 parser.add_argument(
'--verbose',dest=
'verbose',action=
'store_true',help=
'verbose mode, print result also to screen')
126 parser.add_argument(
'--debug',dest=
'debug',action=
'store_true',help=
'debug')
128 args=parser.parse_args()
129 connectstring=args.connect
131 connectparser.parse()
132 usedefaultfrontierconfig=
False
134 if connectparser.needsitelocalinfo():
135 if not args.siteconfpath:
136 cacheconfigpath=os.environ[
'CMS_PATH']
138 cacheconfigpath=os.path.join(cacheconfigpath,
'SITECONF',
'local',
'JobConfig',
'site-local-config.xml')
140 usedefaultfrontierconfig=
True
142 cacheconfigpath=args.siteconfpath
143 cacheconfigpath=os.path.join(cacheconfigpath,
'site-local-config.xml')
145 if usedefaultfrontierconfig:
146 p.parseString(c.defaultfrontierConfigString)
148 p.parse(cacheconfigpath)
149 connectstring=connectparser.fullfrontierStr(connectparser.schemaname(),p.parameterdict())
151 svc = coral.ConnectionService()
153 msg=coral.MessageStream(
'')
154 msg.setMsgVerbosity(coral.message_Level_Debug)
156 ofilename=
'instlumi.csv'
160 if args.authpath
and len(args.authpath)!=0:
161 os.environ[
'CORAL_AUTH_PATH']=args.authpath
163 c.NORM=float(args.normfactor)
165 c.LUMIVERSION=args.lumiversion
167 c.BEAMMODE=args.beammode
171 ifilename=args.inputfile
175 ofilename=args.outputfile
177 timeformat=args.timeformat
178 session=svc.connect(connectstring,accessMode=coral.access_Update)
179 session.typeConverter().setCppTypeForSqlType(
"unsigned int",
"NUMBER(10)")
180 session.typeConverter().setCppTypeForSqlType(
"unsigned long long",
"NUMBER(20)")
183 runsandls=ifparser.runsandls()
184 keylist=runsandls.keys()
187 if selectionDict.has_key(run):
188 lslist=runsandls[run]
190 selectionDict[run]=lslist
191 if args.action ==
'run':
192 minRun=int(args.begin)
197 runList=range(minRun,maxRun+1)
198 elif args.action ==
'peakperday':
199 session.transaction().
start(
True)
201 minTime=t.StrToDatetime(args.begin,timeformat)
203 maxTime=datetime.datetime.utcnow()
205 maxTime=t.StrToDatetime(args.end,timeformat)
207 qHandle=session.nominalSchema().newQuery()
209 session.transaction().commit()
210 runList=runDict.keys()
214 print 'unsupported action ',args.action
218 fig=Figure(figsize=(6,4.5),dpi=100)
221 logfig=Figure(figsize=(6,4.5),dpi=100)
224 if args.action ==
'peakperday':
229 fieldnames=[
'day',
'run',
'lsnum',
'maxinstlumi']
230 reporter.writeRow(fieldnames)
235 for lsdata
in lumiperls:
238 runstarttimeStr=lsdata[-2]
240 deliveredInst=lsdata[2]
241 lsstarttime=l.OrbitToTime(runstarttimeStr,startorbit)
242 day=lsstarttime.toordinal()
243 if not daydict.has_key(day):
245 daydict[day].
append([runnumber,lsnum,deliveredInst])
251 todaysmaxinst=
max(transposeddata[2])
252 todaysmaxidx=transposeddata[2].
index(todaysmaxinst)
253 todaysmaxrun=transposeddata[0][todaysmaxidx]
254 todaysmaxls=transposeddata[1][todaysmaxidx]
255 result[day]=[todaysmaxrun,todaysmaxls,todaysmaxinst]
257 reporter.writeRow([day,todaysmaxrun,todaysmaxls,todaysmaxinst])
258 m.plotPeakPerday_Time(result,minTime,maxTime,annotateBoundaryRunnum=args.annotateboundary,yscale=
'linear')
259 mlog.plotPeakPerday_Time(result,minTime,maxTime,annotateBoundaryRunnum=args.annotateboundary,yscale=
'log')
261 if args.action ==
'run':
267 ydata[
'Delivered']=[]
269 norbit=lumiperrun[0][3]
270 fillnum=lumiperrun[0][-3]
271 starttime=lumiperrun[0][-2]
272 stoptime=lumiperrun[0][-1]
274 totalls=len(lumiperrun)
275 for lsdata
in lumiperrun:
279 deliveredInst=lsdata[1]
280 recordedInst=lsdata[2]
281 ydata[
'Delivered'].
append(deliveredInst)
282 ydata[
'Recorded'].
append(recordedInst)
283 xdata=[runnumber,fillnum,norbit,starttime,stoptime,totalls,ncmsls]
284 m.plotInst_RunLS(xdata,ydata)
287 if args.batch
and args.yscale==
'linear':
288 m.drawPNG(args.batch)
289 elif args.batch
and args.yscale==
'log':
290 mlog.drawPNG(args.batch)
291 elif args.batch
and args.yscale==
'both':
292 m.drawPNG(args.batch)
293 basename,extension=os.path.splitext(args.batch)
294 logfilename=basename+
'_log'+extension
295 mlog.drawPNG(logfilename)
297 raise Exception(
'unsupported yscale for batch mode : '+args.yscale)
299 if not args.interactive:
301 if args.interactive
is True and args.yscale==
'linear':
303 elif args.interactive
is True and args.yscale==
'log':
304 mlog.drawInteractive()
306 raise Exception(
'unsupported yscale for interactive mode : '+args.yscale)