10 from RecoLuminosity.LumiDB
import sessionManager,lumiTime,inputFilesetParser,csvSelectionParser,selectionParser,csvReporter,argparse,CommonUtil,lumiCalcAPI,revisionDML,normDML,lumiReport,lumiCorrections,RegexValidator
14 output ({run:[cmsls,cmsls,...]},[[resultlines]])
19 runlsbyfile=p.runsandls()
20 selectedProcessedRuns=p.selectedRunsWithresult()
21 selectedNonProcessedRuns=p.selectedRunsWithoutresult()
22 resultlines=p.resultlines()
23 for runinfile
in selectedNonProcessedRuns:
24 selectedrunlsInDB[runinfile]=runlsbyfile[runinfile]
25 return (selectedrunlsInDB,resultlines)
35 if __name__ ==
'__main__':
37 allowedActions = [
'overview',
'recorded',
'lumibyls']
44 parser.add_argument(
'action',choices=allowedActions,
45 help=
'command actions')
46 parser.add_argument(
'-c',dest=
'connect',action=
'store',
48 help=
'connect string to lumiDB,optional',
49 default=
'frontier://LumiCalc/CMS_LUMI_PROD')
50 parser.add_argument(
'-P',dest=
'authpath',action=
'store',
52 help=
'path to authentication file (optional)')
53 parser.add_argument(
'-r',dest=
'runnumber',action=
'store',
56 help=
'run number (optional)')
57 parser.add_argument(
'-o',dest=
'outputfile',action=
'store',
59 help=
'output to csv file (optional)')
63 parser.add_argument(
'-i',dest=
'inputfile',action=
'store',
65 help=
'lumi range selection file (optional)')
69 parser.add_argument(
'--hltpath',dest=
'hltpath',action=
'store',
70 default=
None,required=
False,
71 help=
'specific hltpath or hltpath pattern to calculate the effectived luminosity (optional)')
75 parser.add_argument(
'--normtag',dest=
'normtag',action=
'store',
77 help=
'version of lumi norm/correction')
78 parser.add_argument(
'--datatag',dest=
'datatag',action=
'store',
80 help=
'version of lumi/trg/hlt data')
84 parser.add_argument(
'-f',
'--fill',dest=
'fillnum',action=
'store',
85 default=
None,required=
False,
86 help=
'fill number (optional) ')
88 parser.add_argument(
'--begin',dest=
'begin',action=
'store',
92 help=
'min run start time (mm/dd/yy hh:mm:ss),min fill or min run'
94 parser.add_argument(
'--end',dest=
'end',action=
'store',
97 help=
'max run start time (mm/dd/yy hh:mm:ss),max fill or max run'
99 parser.add_argument(
'--minBiasXsec',dest=
'minbiasxsec',action=
'store',
103 help=
'minbias cross-section in ub'
108 parser.add_argument(
'-n',dest=
'scalefactor',action=
'store',
112 help=
'user defined global scaling factor on displayed lumi values,optional')
116 parser.add_argument(
'--siteconfpath',dest=
'siteconfpath',action=
'store',
119 help=
'specific path to site-local-config.xml file, optional. If path undefined, fallback to cern proxy&server')
121 parser.add_argument(
'--headerfile',dest=
'headerfile',action=
'store',
124 help=
'write command header output to specified file'
130 parser.add_argument(
'--without-correction',
133 help=
'without afterglow correction'
135 parser.add_argument(
'--without-checkforupdate',
136 dest=
'withoutCheckforupdate',
138 help=
'without check for update'
143 parser.add_argument(
'--nowarning',
146 help=
'suppress bad for lumi warnings' )
147 parser.add_argument(
'--debug',dest=
'debug',
151 options=parser.parse_args()
152 if not options.runnumber
and not options.inputfile
and not options.fillnum
and not options.begin:
153 raise RuntimeError(
'at least one run selection argument in [-r,-f,-i,--begin] is required')
163 timeFilter=[
None,
None]
164 noWarning=options.nowarning
168 if options.action==
'overview' or options.action==
'lumibyls':
170 if options.action==
'recorded':
173 if options.runnumber:
174 reqrunmax=options.runnumber
175 reqrunmin=options.runnumber
177 reqfillmin=options.fillnum
178 reqfillmax=options.fillnum
192 reqtimeminT=lute.StrToDatetime(reqtimemin,customfm=
'%m/%d/%y %H:%M:%S')
193 timeFilter[0]=reqtimeminT
206 reqtimemaxT=lute.StrToDatetime(reqtimemax,customfm=
'%m/%d/%y %H:%M:%S')
207 timeFilter[1]=reqtimemaxT
208 if options.inputfile
and (reqtimemax
or reqtimemin):
215 workingversion=
'UNKNOWN'
218 if not options.withoutCheckforupdate:
219 from RecoLuminosity.LumiDB
import checkforupdate
220 cmsswWorkingBase=os.environ[
'CMSSW_BASE']
221 if not cmsswWorkingBase:
222 print 'Please check out RecoLuminosity/LumiDB from CVS,scram b,cmsenv'
225 workingversion=c.runningVersion(cmsswWorkingBase,
'pixelLumiCalc.py',isverbose=
False)
227 updateversionList=c.checkforupdate(workingversion,isverbose=
False)
228 if updateversionList:
229 updateversion=updateversionList[-1][0]
234 os.environ[
'CORAL_AUTH_PATH'] = options.authpath
238 if options.action==
'recorded':
239 if not options.hltpath:
240 raise RuntimeError(
'argument --hltpath pathname is required for recorded action')
242 authpath=options.authpath,
243 siteconfpath=options.siteconfpath,
244 debugON=options.debug)
246 session=svc.openSession(isReadOnly=
True,cpp2sqltype=[(
'unsigned int',
'NUMBER(10)'),(
'unsigned long long',
'NUMBER(20)')])
252 session.transaction().
start(
True)
254 if options.inputfile:
256 filerunlist=irunlsdict.keys()
260 datatagname=options.datatag
266 dataidmap=
lumiCalcAPI.runList(session.nominalSchema(),datatagid,runmin=reqrunmin,runmax=reqrunmax,fillmin=reqfillmin,fillmax=reqfillmax,startT=reqtimemin,stopT=reqtimemax,l1keyPattern=
None,hltkeyPattern=
None,amodetag=
None,nominalEnergy=
None,energyFlut=
None,requiretrg=reqTrg,requirehlt=reqHlt,preselectedruns=filerunlist,lumitype=
'PIXEL')
268 print '[INFO] No qualified run found, do nothing'
271 for irun,(lid,tid,hid)
in dataidmap.items():
273 print '[INFO] No qualified lumi data found for run, ',irun
274 if reqTrg
and not tid:
275 print '[INFO] No qualified trg data found for run ',irun
277 if reqHlt
and not hid:
278 print '[INFO] No qualified hlt data found for run ',irun
282 irunlsdict=
dict(zip(rruns,[
None]*len(rruns)))
284 for selectedrun
in irunlsdict.keys():
285 if selectedrun
not in rruns:
286 del irunlsdict[selectedrun]
288 print '[INFO] No qualified run found, do nothing'
296 if not options.withoutNorm:
297 normname=options.normtag
301 normname=normmap.keys()[0]
302 normid=normmap[normname]
306 raise RuntimeError(
'[ERROR] cannot resolve norm/correction')
309 session.transaction().commit()
315 session.transaction().
start(
True)
317 if options.action ==
'overview':
318 result=
lumiCalcAPI.lumiForIds(session.nominalSchema(),irunlsdict,dataidmap,runsummaryMap=GrunsummaryData,beamstatusfilter=
None,timeFilter=timeFilter,normmap=normvalueDict,lumitype=
'PIXEL')
319 lumiReport.toScreenOverview(result,iresults,options.scalefactor,irunlsdict=irunlsdict,noWarning=noWarning,toFile=options.outputfile)
320 if options.action ==
'lumibyls':
321 if not options.hltpath:
322 result=
lumiCalcAPI.lumiForIds(session.nominalSchema(),irunlsdict,dataidmap,runsummaryMap=GrunsummaryData,beamstatusfilter=
None,timeFilter=timeFilter,normmap=normvalueDict,lumitype=
'PIXEL',minbiasXsec=options.minbiasxsec)
323 lumiReport.toScreenLumiByLS(result,iresults,options.scalefactor,irunlsdict=irunlsdict,noWarning=noWarning,toFile=options.outputfile)
325 hltname=options.hltpath
327 if hltname==
'*' or hltname==
'all':
329 elif 1
in [c
in hltname
for c
in '*?[]']:
332 result=
lumiCalcAPI.effectiveLumiForIds(session.nominalSchema(),irunlsdict,dataidmap,runsummaryMap=GrunsummaryData,beamstatusfilter=
None,timeFilter=timeFilter,normmap=normvalueDict,hltpathname=hltname,hltpathpattern=hltpat,withBXInfo=
False,bxAlgo=
None,withBeamIntensity=
False,lumitype=
'PIXEL')
334 if options.action ==
'recorded':
335 hltname=options.hltpath
337 if hltname
is not None:
338 if hltname==
'*' or hltname==
'all':
340 elif 1
in [c
in hltname
for c
in '*?[]']:
343 result=
lumiCalcAPI.effectiveLumiForIds(session.nominalSchema(),irunlsdict,dataidmap,runsummaryMap=GrunsummaryData,beamstatusfilter=
None,normmap=normvalueDict,hltpathname=hltname,hltpathpattern=hltpat,withBXInfo=
False,bxAlgo=
None,withBeamIntensity=
False,lumitype=
'PIXEL')
345 session.transaction().commit()