10 from RecoLuminosity.LumiDB
import sessionManager,lumiTime,inputFilesetParser,csvSelectionParser,selectionParser,csvReporter,argparse,CommonUtil,revisionDML,lumiCalcAPI,lumiReport,RegexValidator,normDML
12 beamChoices=[
'PROTPHYS',
'IONPHYS',
'PAPHYS']
16 output ({run:[cmsls,cmsls,...]},[[resultlines]])
21 runlsbyfile=p.runsandls()
22 selectedProcessedRuns=p.selectedRunsWithresult()
23 selectedNonProcessedRuns=p.selectedRunsWithoutresult()
24 resultlines=p.resultlines()
25 for runinfile
in selectedNonProcessedRuns:
26 selectedrunlsInDB[runinfile]=runlsbyfile[runinfile]
27 return (selectedrunlsInDB,resultlines)
37 if __name__ ==
'__main__':
39 allowedActions = [
'overview',
'delivered',
'recorded',
'lumibyls',
'lumibylsXing']
40 beamModeChoices = [
"stable"]
41 amodetagChoices = [
"PROTPHYS",
"IONPHYS",
'PAPHYS' ]
42 xingAlgoChoices =[
"OCC1",
"OCC2",
"ET"]
50 parser.add_argument(
'action',choices=allowedActions,
51 help=
'command actions')
52 parser.add_argument(
'-c',dest=
'connect',action=
'store',
54 help=
'connect string to lumiDB,optional',
55 default=
'frontier://LumiCalc/CMS_LUMI_PROD')
56 parser.add_argument(
'-P',dest=
'authpath',action=
'store',
58 help=
'path to authentication file')
59 parser.add_argument(
'-r',dest=
'runnumber',action=
'store',
63 parser.add_argument(
'-o',dest=
'outputfile',action=
'store',
65 help=
'output to csv file' )
70 parser.add_argument(
'-i',dest=
'inputfile',action=
'store',
72 help=
'lumi range selection file')
76 parser.add_argument(
'--hltpath',dest=
'hltpath',action=
'store',
77 default=
None,required=
False,
78 help=
'specific hltpath or hltpath pattern to calculate the effectived luminosity')
82 parser.add_argument(
'--normtag',dest=
'normtag',action=
'store',
84 help=
'version of lumi norm/correction')
85 parser.add_argument(
'--datatag',dest=
'datatag',action=
'store',
87 help=
'version of lumi/trg/hlt data')
92 parser.add_argument(
'-f',
'--fill',dest=
'fillnum',action=
'store',
93 default=
None,required=
False,
94 help=
'fill number (optional) ')
95 parser.add_argument(
'--amodetag',dest=
'amodetag',action=
'store',
96 choices=amodetagChoices,
98 help=
'specific accelerator mode choices [PROTOPHYS,IONPHYS,PAPHYS] (optional)')
99 parser.add_argument(
'--beamenergy',dest=
'beamenergy',action=
'store',
102 help=
'nominal beam energy in GeV')
103 parser.add_argument(
'--beamfluctuation',dest=
'beamfluctuation',
104 type=float,action=
'store',
107 help=
'fluctuation in fraction allowed to nominal beam energy, default 0.2, to be used together with -beamenergy (optional)')
109 parser.add_argument(
'--begin',dest=
'begin',action=
'store',
113 help=
'min run start time (mm/dd/yy hh:mm:ss),min fill or min run'
115 parser.add_argument(
'--end',dest=
'end',action=
'store',
119 help=
'max run start time (mm/dd/yy hh:mm:ss),max fill or max run'
121 parser.add_argument(
'--minBiasXsec',dest=
'minbiasxsec',action=
'store',
125 help=
'minbias cross-section in ub'
130 parser.add_argument(
'-b',dest=
'beammode',action=
'store',
131 choices=beamModeChoices,
133 help=
'beam mode choices [stable]')
135 parser.add_argument(
'--xingMinLum', dest =
'xingMinLum',
139 help=
'Minimum perbunch luminosity to print, default=1e-03/ub')
141 parser.add_argument(
'--xingAlgo', dest =
'xingAlgo',
144 help=
'algorithm name for per-bunch lumi ')
149 parser.add_argument(
'-n',dest=
'scalefactor',action=
'store',
153 help=
'user defined global scaling factor on displayed lumi values,optional')
158 parser.add_argument(
'--siteconfpath',dest=
'siteconfpath',action=
'store',
161 help=
'specific path to site-local-config.xml file, optional. If path undefined, fallback to cern proxy&server')
163 parser.add_argument(
'--headerfile',dest=
'headerfile',action=
'store',
166 help=
'write command header output to specified file'
171 parser.add_argument(
'--without-correction',
174 help=
'without any correction/calibration'
176 parser.add_argument(
'--without-checkforupdate',
177 dest=
'withoutCheckforupdate',
179 help=
'without check for update'
186 parser.add_argument(
'--nowarning',
189 help=
'suppress bad for lumi warnings'
191 parser.add_argument(
'--debug',
196 options=parser.parse_args()
197 if not options.runnumber
and not options.inputfile
and not options.fillnum
and not options.begin:
198 raise RuntimeError(
'at least one run selection argument in [-r,-f,-i,--begin] is required')
205 timeFilter=[
None,
None]
206 noWarning=options.nowarning
208 if options.beammode==
'stable':
209 pbeammode =
'STABLE BEAMS'
213 if options.action==
'overview' or options.action==
'lumibyls' or options.action==
'lumibylsXing':
215 if options.action==
'recorded':
218 if options.runnumber:
219 reqrunmax=options.runnumber
220 reqrunmin=options.runnumber
222 reqfillmin=options.fillnum
223 reqfillmax=options.fillnum
238 reqtimeminT=lute.StrToDatetime(reqtimemin,customfm=
'%m/%d/%y %H:%M:%S')
239 timeFilter[0]=reqtimeminT
252 reqtimemaxT=lute.StrToDatetime(reqtimemax,customfm=
'%m/%d/%y %H:%M:%S')
253 timeFilter[1]=reqtimemaxT
254 if options.inputfile
and (reqtimemax
or reqtimemin):
261 workingversion=
'UNKNOWN'
264 if not options.withoutCheckforupdate:
265 from RecoLuminosity.LumiDB
import checkforupdate
266 cmsswWorkingBase=os.environ[
'CMSSW_BASE']
267 if not cmsswWorkingBase:
268 print 'Please check out RecoLuminosity/LumiDB from CVS,scram b,cmsenv'
271 workingversion=c.runningVersion(cmsswWorkingBase,
'lumiCalc2.py',isverbose=
False)
273 updateversionList=c.checkforupdate(workingversion,isverbose=
False)
274 if updateversionList:
275 updateversion=updateversionList[-1][0]
280 os.environ[
'CORAL_AUTH_PATH'] = options.authpath
286 if options.action==
'recorded':
287 if not options.hltpath:
288 raise RuntimeError(
'argument --hltpath pathname is required for recorded action')
291 authpath=options.authpath,
292 siteconfpath=options.siteconfpath,
293 debugON=options.debug)
294 session=svc.openSession(isReadOnly=
True,cpp2sqltype=[(
'unsigned int',
'NUMBER(10)'),(
'unsigned long long',
'NUMBER(20)')])
301 session.transaction().
start(
True)
303 if options.inputfile:
305 filerunlist=irunlsdict.keys()
318 datatagname=options.datatag
324 dataidmap=
lumiCalcAPI.runList(session.nominalSchema(),datatagid,runmin=reqrunmin,runmax=reqrunmax,fillmin=reqfillmin,fillmax=reqfillmax,startT=reqtimemin,stopT=reqtimemax,l1keyPattern=
None,hltkeyPattern=
None,amodetag=options.amodetag,nominalEnergy=options.beamenergy,energyFlut=options.beamfluctuation,requiretrg=reqTrg,requirehlt=reqHlt,preselectedruns=filerunlist)
326 print '[INFO] No qualified run found, do nothing'
330 for irun,(lid,tid,hid)
in dataidmap.items():
332 print '[INFO] No qualified lumi data found for run, ',irun
333 if reqTrg
and not tid:
334 print '[INFO] No qualified trg data found for run ',irun
336 if reqHlt
and not hid:
337 print '[INFO] No qualified hlt data found for run ',irun
341 irunlsdict=
dict(zip(rruns,[
None]*len(rruns)))
343 for selectedrun
in irunlsdict.keys():
344 if selectedrun
not in rruns:
345 del irunlsdict[selectedrun]
347 print '[INFO] No qualified run found, do nothing'
355 if not options.withoutNorm:
356 normname=options.normtag
360 normname=normmap.keys()[0]
361 normid=normmap[normname]
365 raise RuntimeError(
'[ERROR] cannot resolve norm/correction')
368 session.transaction().commit()
375 session.transaction().
start(
True)
378 if options.action ==
'delivered':
379 result=
lumiCalcAPI.deliveredLumiForIds(session.nominalSchema(),irunlsdict,dataidmap,runsummaryMap=GrunsummaryData,beamstatusfilter=pbeammode,timeFilter=timeFilter,normmap=normvalueDict,lumitype=
'HF')
381 if options.action ==
'overview':
382 result=
lumiCalcAPI.lumiForIds(session.nominalSchema(),irunlsdict,dataidmap,runsummaryMap=GrunsummaryData,beamstatusfilter=pbeammode,timeFilter=timeFilter,normmap=normvalueDict,lumitype=
'HF')
383 lumiReport.toScreenOverview(result,iresults,options.scalefactor,irunlsdict=irunlsdict,noWarning=noWarning,toFile=options.outputfile)
384 if options.action ==
'lumibyls':
385 if not options.hltpath:
386 result=
lumiCalcAPI.lumiForIds(session.nominalSchema(),irunlsdict,dataidmap,runsummaryMap=GrunsummaryData,beamstatusfilter=pbeammode,timeFilter=timeFilter,normmap=normvalueDict,lumitype=
'HF',minbiasXsec=options.minbiasxsec)
387 lumiReport.toScreenLumiByLS(result,iresults,options.scalefactor,irunlsdict=irunlsdict,noWarning=noWarning,toFile=options.outputfile)
389 hltname=options.hltpath
391 if hltname==
'*' or hltname==
'all':
393 elif 1
in [c
in hltname
for c
in '*?[]']:
396 result=
lumiCalcAPI.effectiveLumiForIds(session.nominalSchema(),irunlsdict,dataidmap,runsummaryMap=GrunsummaryData,beamstatusfilter=pbeammode,timeFilter=timeFilter,normmap=normvalueDict,hltpathname=hltname,hltpathpattern=hltpat,withBXInfo=
False,bxAlgo=
None,xingMinLum=options.xingMinLum,withBeamIntensity=
False,lumitype=
'HF')
398 if options.action ==
'recorded':
399 hltname=options.hltpath
401 if hltname
is not None:
402 if hltname==
'*' or hltname==
'all':
404 elif 1
in [c
in hltname
for c
in '*?[]']:
407 result=
lumiCalcAPI.effectiveLumiForIds(session.nominalSchema(),irunlsdict,dataidmap,runsummaryMap=GrunsummaryData,beamstatusfilter=pbeammode,timeFilter=timeFilter,normmap=normvalueDict,hltpathname=hltname,hltpathpattern=hltpat,withBXInfo=
False,bxAlgo=
None,xingMinLum=options.xingMinLum,withBeamIntensity=
False,lumitype=
'HF')
409 if options.action ==
'lumibylsXing':
410 result=
lumiCalcAPI.lumiForIds(session.nominalSchema(),irunlsdict,dataidmap,runsummaryMap=GrunsummaryData,beamstatusfilter=pbeammode,timeFilter=timeFilter,normmap=normvalueDict,withBXInfo=
True,bxAlgo=options.xingAlgo,xingMinLum=options.xingMinLum,withBeamIntensity=
False,lumitype=
'HF')
411 outfile=options.outputfile
413 print '[WARNING] no output file given. lumibylsXing writes per-bunch lumi only to default file lumibylsXing.csv'
414 outfile=
'lumibylsXing.csv'
416 session.transaction().commit()