9 from __future__
import print_function
11 from RecoLuminosity.LumiDB
import sessionManager,lumiTime,inputFilesetParser,csvSelectionParser,csvReporter,argparse,CommonUtil,lumiCalcAPI,lumiReport,RegexValidator,lumiTime,revisionDML
15 output ({run:[cmsls,cmsls,...]},[[resultlines]]) 20 runlsbyfile=p.runsandls()
21 selectedProcessedRuns=p.selectedRunsWithresult()
22 selectedNonProcessedRuns=p.selectedRunsWithoutresult()
23 resultlines=p.resultlines()
24 for runinfile
in selectedNonProcessedRuns:
25 selectedrunlsInDB[runinfile]=runlsbyfile[runinfile]
26 return (selectedrunlsInDB,resultlines)
36 if __name__ ==
'__main__':
37 parser = argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]),description =
"Additional information needed in the lumi calculation",formatter_class=argparse.ArgumentDefaultsHelpFormatter)
38 allowedActions = [
'hltbyls',
'hltmenu',
'trgbyls',
'beambyls',
'runsummary']
39 amodetagChoices = [
"PROTPHYS",
"IONPHYS",
"PAPHYS" ]
40 beamModeChoices = [
"stable"]
49 parser.add_argument(
'action',choices=allowedActions,
50 help=
'command actions')
51 parser.add_argument(
'-c',dest=
'connect',action=
'store',
53 help=
'connect string to lumiDB,optional',
54 default=
'frontier://LumiCalc/CMS_LUMI_PROD')
55 parser.add_argument(
'-P',dest=
'authpath',action=
'store',
57 help=
'path to authentication file (optional)')
58 parser.add_argument(
'-r',dest=
'runnumber',action=
'store',
61 help=
'run number (optional)')
62 parser.add_argument(
'-o',dest=
'outputfile',action=
'store',
64 help=
'output to csv file (optional)')
68 parser.add_argument(
'-i',dest=
'inputfile',action=
'store',
70 help=
'run/ls selection file (optional)')
71 parser.add_argument(
'--name',dest=
'name',action=
'store',
72 help=
'hltpath/l1bit name/pattern' 77 parser.add_argument(
'-b',dest=
'beammode',action=
'store',
78 choices=beamModeChoices,
80 help=
'beam mode choices [stable] (optional)')
81 parser.add_argument(
'-f',
'--fill',dest=
'fillnum',action=
'store',
82 default=
None,required=
False,
83 help=
'fill number (optional) ')
84 parser.add_argument(
'--amodetag',dest=
'amodetag',action=
'store',
85 choices=amodetagChoices,
87 help=
'specific accelerator mode choices [PROTOPHYS,IONPHYS] (optional)')
88 parser.add_argument(
'--beamenergy',dest=
'beamenergy',action=
'store',
91 help=
'nominal beam energy in GeV')
92 parser.add_argument(
'--beamfluctuation',dest=
'beamfluctuation',
93 type=float,action=
'store',
96 help=
'fluctuation in fraction allowed to nominal beam energy, default 0.2, to be used together with -beamenergy (optional)')
97 parser.add_argument(
'--minintensity',dest=
'minintensity',
98 type=float,action=
'store',
101 help=
'filter on beam intensity , effective with --with-beamintensity (optional)')
102 parser.add_argument(
'--begin',dest=
'begin',action=
'store',
106 help=
'min run start time, mm/dd/yy hh:mm:ss)' 108 parser.add_argument(
'--end',dest=
'end',action=
'store',
112 help=
'max run start time, mm/dd/yy hh:mm:ss' 117 parser.add_argument(
'--datatag',dest=
'datatag',action=
'store',
119 help=
'version of lumi/trg/hlt data' 124 parser.add_argument(
'--siteconfpath',dest=
'siteconfpath',action=
'store',
127 help=
'specific path to site-local-config.xml file, optional. If path undefined, fallback to cern proxy&server')
131 parser.add_argument(
'--with-beamintensity',
132 dest=
'withbeamintensity',
134 help=
'dump beam intensity' 136 parser.add_argument(
'--without-mask',
139 help=
'not considering trigger mask' 141 parser.add_argument(
'--verbose',
144 help=
'verbose mode for printing' )
145 parser.add_argument(
'--nowarning',
148 help=
'suppress bad for lumi warnings' 150 parser.add_argument(
'--debug',
155 options=parser.parse_args()
156 if not options.runnumber
and not options.inputfile
and not options.fillnum
and not options.begin:
157 raise RuntimeError(
'at least one run selection argument in [-r,-f,-i,--begin] is required')
164 timeFilter=[
None,
None]
169 if options.beammode==
'stable':
170 pbeammode =
'STABLE BEAMS' 171 if options.action==
'trgbyls':
173 if options.action==
'hltbyls':
175 if options.runnumber:
176 reqrunmax=options.runnumber
177 reqrunmin=options.runnumber
179 reqfillmin=options.fillnum
180 reqfillmax=options.fillnum
185 reqtimeminT=lute.StrToDatetime(reqtimemin,customfm=
'%m/%d/%y %H:%M:%S')
186 timeFilter[0]=reqtimeminT
191 reqtimemaxT=lute.StrToDatetime(reqtimemax,customfm=
'%m/%d/%y %H:%M:%S')
192 timeFilter[1]=reqtimemaxT
196 if sname
is not None:
198 if sname==
'*' or sname==
'all':
200 elif 1
in [c
in sname
for c
in '*?[]']:
203 if options.action ==
'beambyls' and options.withbeamintensity
and not options.outputfile:
204 print(
'[warning] --with-beamintensity must write data to a file, none specified using default "beamintensity.csv"')
205 options.outputfile=
'beamintensity.csv' 214 os.environ[
'CORAL_AUTH_PATH'] = options.authpath
217 authpath=options.authpath,
218 siteconfpath=options.siteconfpath,
219 debugON=options.debug)
220 session=svc.openSession(isReadOnly=
True,cpp2sqltype=[(
'unsigned int',
'NUMBER(10)'),(
'unsigned long long',
'NUMBER(20)')])
228 session.transaction().
start(
True)
230 if options.inputfile:
232 filerunlist=irunlsdict.keys()
234 datatagname=options.datatag
240 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)
242 print(
'[INFO] No qualified run found, do nothing')
246 for irun,(lid,tid,hid)
in dataidmap.items():
248 print(
'[INFO] No qualified lumi data found for run, ',irun)
249 if reqTrg
and not tid:
250 print(
'[INFO] No qualified trg data found for run ',irun)
252 if reqHlt
and not hid:
253 print(
'[INFO] No qualified hlt data found for run ',irun)
257 irunlsdict=
dict(
list(
zip(rruns,[
None]*len(rruns))))
259 for selectedrun
in irunlsdict.keys():
260 if selectedrun
not in rruns:
261 del irunlsdict[selectedrun]
263 print(
'[INFO] No qualified run found, do nothing')
266 session.transaction().commit()
270 if options.action ==
'trgbyls':
271 session.transaction().
start(
True)
272 result=
lumiCalcAPI.trgForIds(session.nominalSchema(),irunlsdict,dataidmap,trgbitname=sname,trgbitnamepattern=spattern,withL1Count=
True,withPrescale=
True)
273 session.transaction().commit()
274 if not options.outputfile:
275 lumiReport.toScreenLSTrg(result,iresults=iresults,irunlsdict=irunlsdict,noWarning=options.nowarning,withoutmask=options.withoutmask)
277 lumiReport.toScreenLSTrg(result,iresults=iresults,irunlsdict=irunlsdict,noWarning=options.nowarning,toFile=options.outputfile,withoutmask=options.withoutmask)
280 if options.action ==
'hltbyls':
282 print(
'[ERROR] --name option is required by hltbyls, do nothing')
286 session.transaction().
start(
True)
287 result=
lumiCalcAPI.hltForIds(session.nominalSchema(),irunlsdict,dataidmap,hltpathname=sname,hltpathpattern=spattern,withL1Pass=withL1Pass,withHLTAccept=withHLTAccept)
288 session.transaction().commit()
289 if not options.outputfile:
293 if options.action ==
'hltmenu':
294 session.transaction().
start(
True)
296 session.transaction().commit()
298 if not options.outputfile:
302 if options.action ==
'beambyls':
303 session.transaction().
start(
True)
304 dumpbeamintensity=
False 305 if options.outputfile
and options.verbose:
306 dumpbeamintensity=
True 307 result=
lumiCalcAPI.beamForIds(session.nominalSchema(),irunlsdict,dataidmap,withBeamIntensity=options.withbeamintensity,minIntensity=options.minintensity)
308 session.transaction().commit()
309 if not options.outputfile:
313 if options.action ==
'runsummary':
314 session.transaction().
start(
True)
316 session.transaction().commit()
323 starttime=c.StrToDatetime(r[7])
324 starttime=starttime.strftime(
'%m/%d/%y %H:%M:%S')
325 stoptime=c.StrToDatetime(r[8])
326 stoptime=stoptime.strftime(
'%m/%d/%y %H:%M:%S')
335 print(
'Run ',
str(run),
' Fill ',fill,
' Amodetag ',amodetag,
' egev ',egev)
336 print(
'\tStart '+starttime,
' ',
' Stop ',stoptime)
337 print(
'\tL1key ',l1key,
' HLTkey ',hltkey)
def parseInputFiles(inputfilename)
def toScreenLSHlt(hltdata, iresults=[], toFile=None)
def hltpathsForRange(schema, runlist, hltpathname=None, hltpathpattern=None)
def currentDataTag(schema, lumitype='HF')
S & print(S &os, JobReport::InputFile const &f)
def toScreenConfHlt(hltconfdata, iresults=[], toFile=None)
def toScreenLSTrg(trgdata, iresults=[], irunlsdict=None, noWarning=True, toFile=None, withoutmask=False)
def hltForIds(schema, irunlsdict, dataidmap, hltpathname=None, hltpathpattern=None, withL1Pass=False, withHLTAccept=False)
OutputIterator zip(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
def beamForIds(schema, irunlsdict, dataidmap, withBeamIntensity=False, minIntensity=0.1)
def toScreenHeader(commandname, datatagname, normtag, worktag, updatetag, lumitype, toFile=None)
def trgForIds(schema, irunlsdict, dataidmap, trgbitname=None, trgbitnamepattern=None, withL1Count=False, withPrescale=False)
def toScreenLSBeam(beamdata, iresults=[], dumpIntensity=False, toFile=None)
def runsummary(schema, irunlsdict)
Lumi data management and calculation API # # Author: Zhen Xie #.
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')