9 from __future__
import print_function
11 from RecoLuminosity.LumiDB
import sessionManager,lumiTime,inputFilesetParser,csvSelectionParser,selectionParser,csvReporter,argparse,CommonUtil,revisionDML,lumiCalcAPI,lumiReport,RegexValidator,normDML
13 beamChoices=[
'PROTPHYS',
'IONPHYS',
'PAPHYS']
17 output ({run:[cmsls,cmsls,...]},[[resultlines]]) 22 runlsbyfile=p.runsandls()
23 selectedProcessedRuns=p.selectedRunsWithresult()
24 selectedNonProcessedRuns=p.selectedRunsWithoutresult()
25 resultlines=p.resultlines()
26 for runinfile
in selectedNonProcessedRuns:
27 selectedrunlsInDB[runinfile]=runlsbyfile[runinfile]
28 return (selectedrunlsInDB,resultlines)
38 if __name__ ==
'__main__':
39 parser = argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]),description =
"Lumi Calculation",formatter_class=argparse.ArgumentDefaultsHelpFormatter)
40 allowedActions = [
'overview',
'delivered',
'recorded',
'lumibyls',
'lumibylsXing']
41 beamModeChoices = [
"stable"]
42 amodetagChoices = [
"PROTPHYS",
"IONPHYS",
'PAPHYS' ]
43 xingAlgoChoices =[
"OCC1",
"OCC2",
"ET"]
51 parser.add_argument(
'action',choices=allowedActions,
52 help=
'command actions')
53 parser.add_argument(
'-c',dest=
'connect',action=
'store',
55 help=
'connect string to lumiDB,optional',
56 default=
'frontier://LumiCalc/CMS_LUMI_PROD')
57 parser.add_argument(
'-P',dest=
'authpath',action=
'store',
59 help=
'path to authentication file')
60 parser.add_argument(
'-r',dest=
'runnumber',action=
'store',
64 parser.add_argument(
'-o',dest=
'outputfile',action=
'store',
66 help=
'output to csv file' )
71 parser.add_argument(
'-i',dest=
'inputfile',action=
'store',
73 help=
'lumi range selection file')
77 parser.add_argument(
'--hltpath',dest=
'hltpath',action=
'store',
78 default=
None,required=
False,
79 help=
'specific hltpath or hltpath pattern to calculate the effectived luminosity')
83 parser.add_argument(
'--normtag',dest=
'normtag',action=
'store',
85 help=
'version of lumi norm/correction')
86 parser.add_argument(
'--datatag',dest=
'datatag',action=
'store',
88 help=
'version of lumi/trg/hlt data')
93 parser.add_argument(
'-f',
'--fill',dest=
'fillnum',action=
'store',
94 default=
None,required=
False,
95 help=
'fill number (optional) ')
96 parser.add_argument(
'--amodetag',dest=
'amodetag',action=
'store',
97 choices=amodetagChoices,
99 help=
'specific accelerator mode choices [PROTOPHYS,IONPHYS,PAPHYS] (optional)')
100 parser.add_argument(
'--beamenergy',dest=
'beamenergy',action=
'store',
103 help=
'nominal beam energy in GeV')
104 parser.add_argument(
'--beamfluctuation',dest=
'beamfluctuation',
105 type=float,action=
'store',
108 help=
'fluctuation in fraction allowed to nominal beam energy, default 0.2, to be used together with -beamenergy (optional)')
110 parser.add_argument(
'--begin',dest=
'begin',action=
'store',
114 help=
'min run start time (mm/dd/yy hh:mm:ss),min fill or min run' 116 parser.add_argument(
'--end',dest=
'end',action=
'store',
120 help=
'max run start time (mm/dd/yy hh:mm:ss),max fill or max run' 122 parser.add_argument(
'--minBiasXsec',dest=
'minbiasxsec',action=
'store',
126 help=
'minbias cross-section in ub' 131 parser.add_argument(
'-b',dest=
'beammode',action=
'store',
132 choices=beamModeChoices,
134 help=
'beam mode choices [stable]')
136 parser.add_argument(
'--xingMinLum', dest =
'xingMinLum',
140 help=
'Minimum perbunch luminosity to print, default=1e-03/ub')
142 parser.add_argument(
'--xingAlgo', dest =
'xingAlgo',
145 help=
'algorithm name for per-bunch lumi ')
150 parser.add_argument(
'-n',dest=
'scalefactor',action=
'store',
154 help=
'user defined global scaling factor on displayed lumi values,optional')
159 parser.add_argument(
'--siteconfpath',dest=
'siteconfpath',action=
'store',
162 help=
'specific path to site-local-config.xml file, optional. If path undefined, fallback to cern proxy&server')
164 parser.add_argument(
'--headerfile',dest=
'headerfile',action=
'store',
167 help=
'write command header output to specified file' 172 parser.add_argument(
'--without-correction',
175 help=
'without any correction/calibration' 177 parser.add_argument(
'--without-checkforupdate',
178 dest=
'withoutCheckforupdate',
180 help=
'without check for update' 187 parser.add_argument(
'--nowarning',
190 help=
'suppress bad for lumi warnings' 192 parser.add_argument(
'--debug',
197 options=parser.parse_args()
198 if not options.runnumber
and not options.inputfile
and not options.fillnum
and not options.begin:
199 raise RuntimeError(
'at least one run selection argument in [-r,-f,-i,--begin] is required')
206 timeFilter=[
None,
None]
207 noWarning=options.nowarning
209 if options.beammode==
'stable':
210 pbeammode =
'STABLE BEAMS' 214 if options.action==
'overview' or options.action==
'lumibyls' or options.action==
'lumibylsXing':
216 if options.action==
'lumibyls' and options.hltpath:
218 if options.action==
'recorded':
221 if options.runnumber:
222 reqrunmax=options.runnumber
223 reqrunmin=options.runnumber
225 reqfillmin=options.fillnum
226 reqfillmax=options.fillnum
241 reqtimeminT=lute.StrToDatetime(reqtimemin,customfm=
'%m/%d/%y %H:%M:%S')
242 timeFilter[0]=reqtimeminT
255 reqtimemaxT=lute.StrToDatetime(reqtimemax,customfm=
'%m/%d/%y %H:%M:%S')
256 timeFilter[1]=reqtimemaxT
257 if options.inputfile
and (reqtimemax
or reqtimemin):
264 workingversion=
'UNKNOWN' 267 if not options.withoutCheckforupdate:
268 from RecoLuminosity.LumiDB
import checkforupdate
269 cmsswWorkingBase=os.environ[
'CMSSW_BASE']
270 if not cmsswWorkingBase:
271 print(
'Please check out RecoLuminosity/LumiDB from CVS,scram b,cmsenv')
274 workingversion=c.runningVersion(cmsswWorkingBase,
'lumiCalc2.py',isverbose=
False)
276 updateversionList=c.checkforupdate(workingversion,isverbose=
False)
277 if updateversionList:
278 updateversion=updateversionList[-1][0]
283 os.environ[
'CORAL_AUTH_PATH'] = options.authpath
289 if options.action==
'recorded':
290 if not options.hltpath:
291 raise RuntimeError(
'argument --hltpath pathname is required for recorded action')
294 authpath=options.authpath,
295 siteconfpath=options.siteconfpath,
296 debugON=options.debug)
297 session=svc.openSession(isReadOnly=
True,cpp2sqltype=[(
'unsigned int',
'NUMBER(10)'),(
'unsigned long long',
'NUMBER(20)')])
304 session.transaction().
start(
True)
306 if options.inputfile:
308 filerunlist=irunlsdict.keys()
321 datatagname=options.datatag
327 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)
329 print(
'[INFO] No qualified run found, do nothing')
333 for irun,(lid,tid,hid)
in dataidmap.items():
335 print(
'[INFO] No qualified lumi data found for run, ',irun)
336 if reqTrg
and not tid:
337 print(
'[INFO] No qualified trg data found for run ',irun)
339 if reqHlt
and not hid:
340 print(
'[INFO] No qualified hlt data found for run ',irun)
344 irunlsdict=
dict(
list(
zip(rruns,[
None]*len(rruns))))
346 for selectedrun
in irunlsdict.keys():
347 if selectedrun
not in rruns:
348 del irunlsdict[selectedrun]
350 print(
'[INFO] No qualified run found, do nothing')
359 if not options.withoutNorm:
360 normname=options.normtag
364 normname=normmap.keys()[0]
365 normid=normmap[normname]
369 raise RuntimeError(
'[ERROR] cannot resolve norm/correction')
372 session.transaction().commit()
379 session.transaction().
start(
True)
382 if options.action ==
'delivered':
383 result=
lumiCalcAPI.deliveredLumiForIds(session.nominalSchema(),irunlsdict,dataidmap,runsummaryMap=GrunsummaryData,beamstatusfilter=pbeammode,timeFilter=timeFilter,normmap=normvalueDict,lumitype=
'HF')
385 if options.action ==
'overview':
386 result=
lumiCalcAPI.lumiForIds(session.nominalSchema(),irunlsdict,dataidmap,runsummaryMap=GrunsummaryData,beamstatusfilter=pbeammode,timeFilter=timeFilter,normmap=normvalueDict,lumitype=
'HF')
387 lumiReport.toScreenOverview(result,iresults,options.scalefactor,irunlsdict=irunlsdict,noWarning=noWarning,toFile=options.outputfile)
388 if options.action ==
'lumibyls':
389 if not options.hltpath:
390 result=
lumiCalcAPI.lumiForIds(session.nominalSchema(),irunlsdict,dataidmap,runsummaryMap=GrunsummaryData,beamstatusfilter=pbeammode,timeFilter=timeFilter,normmap=normvalueDict,lumitype=
'HF',minbiasXsec=options.minbiasxsec)
391 lumiReport.toScreenLumiByLS(result,iresults,options.scalefactor,irunlsdict=irunlsdict,noWarning=noWarning,toFile=options.outputfile)
393 hltname=options.hltpath
395 if hltname==
'*' or hltname==
'all':
397 elif 1
in [c
in hltname
for c
in '*?[]']:
400 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')
402 if options.action ==
'recorded':
403 hltname=options.hltpath
405 if hltname
is not None:
406 if hltname==
'*' or hltname==
'all':
408 elif 1
in [c
in hltname
for c
in '*?[]']:
411 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')
413 if options.action ==
'lumibylsXing':
414 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')
415 outfile=options.outputfile
417 print(
'[WARNING] no output file given. lumibylsXing writes per-bunch lumi only to default file lumibylsXing.csv')
418 outfile=
'lumibylsXing.csv' 420 session.transaction().commit()
def toScreenOverview(lumidata, resultlines, scalefactor, irunlsdict=None, noWarning=True, toFile=None)
def effectiveLumiForIds(schema, irunlsdict, dataidmap, runsummaryMap=None, beamstatusfilter=None, timeFilter=None, normmap=None, hltpathname=None, hltpathpattern=None, withBXInfo=False, bxAlgo=None, xingMinLum=None, withBeamIntensity=False, lumitype='HF', minbiasXsec=None)
def normIdByName(schema, normname)
def currentDataTag(schema, lumitype='HF')
def toScreenLumiByLS(lumidata, resultlines, scalefactor, irunlsdict=None, noWarning=True, toFile=None)
def parseInputFiles(inputfilename)
S & print(S &os, JobReport::InputFile const &f)
def normIdByType(schema, lumitype='HF', defaultonly=True)
def runsummaryMap(schema, irunlsdict, dataidmap, lumitype='HF')
def toScreenTotDelivered(lumidata, resultlines, scalefactor, irunlsdict=None, noWarning=True, toFile=None)
def lumiForIds(schema, irunlsdict, dataidmap, runsummaryMap, beamstatusfilter=None, timeFilter=None, normmap=None, withBXInfo=False, bxAlgo=None, xingMinLum=None, withBeamIntensity=False, lumitype='HF', minbiasXsec=None)
def toCSVLumiByLSXing(lumidata, scalefactor, filename, irunlsdict=None, noWarning=True)
OutputIterator zip(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
def toScreenHeader(commandname, datatagname, normtag, worktag, updatetag, lumitype, toFile=None)
def normValueById(schema, normid)
def toScreenTotEffective(lumidata, resultlines, scalefactor, irunlsdict=None, noWarning=True, toFile=None)
def toScreenLSEffective(lumidata, resultlines, scalefactor, irunlsdict=None, noWarning=True, toFile=None)
def deliveredLumiForIds(schema, irunlsdict, dataidmap, runsummaryMap, beamstatusfilter=None, timeFilter=None, normmap=None, withBXInfo=False, bxAlgo=None, xingMinLum=None, withBeamIntensity=False, lumitype='HF', minbiasXsec=None)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger list("!*","!HLTx*"if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL.It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of"!*"before the partial wildcard feature was incorporated).Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run
def getDataTagId(schema, tagname, lumitype='HF')
def runList(schema, datatagid, runmin=None, runmax=None, fillmin=None, fillmax=None, startT=None, stopT=None, l1keyPattern=None, hltkeyPattern=None, amodetag=None, nominalEnergy=None, energyFlut=0.2, requiretrg=True, requirehlt=True, preselectedruns=None, lumitype='HF')