コード例 #1
0
def lumi_context(action, runs_lumis):
    svc = sessionManager.sessionManager('frontier://LumiCalc/CMS_LUMI_PROD')
    session = svc.openSession(isReadOnly=True, cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])
    session.transaction().start(True)

    datatagid, datatagname = revisionDML.currentDataTag(session.nominalSchema())
    dataidmap = revisionDML.dataIdsByTagId(session.nominalSchema(), datatagid, runlist=runs_lumis.keys(), withcomment=False)
    assert dataidmap

    session.transaction().commit()

    if action == 'trgbyls':
        session.transaction().start(True)
        result = lumiCalcAPI.trgForIds(session.nominalSchema(), runs_lumis, dataidmap, trgbitname=None, trgbitnamepattern='*', withL1Count=False, withPrescale=True)
        session.transaction().commit()
    elif action == 'hltbyls':
        session.transaction().start(True)
        result = lumiCalcAPI.hltForIds(session.nominalSchema(), runs_lumis, dataidmap, hltpathname=None, hltpathpattern='*', withL1Pass=False, withHLTAccept=False)
        session.transaction().commit()
    elif action == 'hltmenu':
        session.transaction().start(True)
        result = lumiCalcAPI.hltpathsForRange(session.nominalSchema(), runs_lumis, hltpathname=None, hltpathpattern='*')
        session.transaction().commit()
    del session
    del svc

    return result
コード例 #2
0
ファイル: pixelLumiLoader.py プロジェクト: jkunkle/cmssw
 options=parser.parse_args()
 svc=sessionManager.sessionManager(options.connect,
                                   authpath=options.authpath,
                                   debugON=options.debug)
 session=svc.openSession(isReadOnly=False,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])
 inputfilename=os.path.abspath(options.inputfile)
 parseresult=parseInputFile(inputfilename,options.singlerun)
 runlist=parseresult.keys()
 irunlsdict={}
 for run in runlist:
     irunlsdict[run]=None
 session.transaction().start(True)
 (pixellumibranchid,pixellumibranchparent)=revisionDML.branchInfoByName(session.nominalSchema(),'DATA')
 print 'pixellumibranchid ',pixellumibranchid,' pixellumibranchparent ',pixellumibranchparent
 pixellumibranchinfo=(pixellumibranchid,'DATA')
 (pixel_tagid,pixel_tagname)=revisionDML.currentDataTag(session.nominalSchema(),lumitype='PIXEL')
 (hf_tagid,hf_tagname)=revisionDML.currentDataTag(session.nominalSchema(),lumitype='HF')    
 hfdataidmap=revisionDML.dataIdsByTagId(session.nominalSchema(),hf_tagid,runlist,withcomment=False,lumitype='HF')
 beamstatusdata=dataDML.beamstatusByIds(session.nominalSchema(),hfdataidmap)
 #print 'beamstatusdata ',beamstatusdata
 lumirundata=dataDML.lumiRunByIds(session.nominalSchema(),hfdataidmap,lumitype='HF')#{runnum: (nominalegev(0),ncollidingbunches(1),starttime(2),stoptime(3),nls(4)}
 session.transaction().commit()
 #print 'lumirundata ', lumirundata
 alllumirundata=generateLumiRundata(inputfilename,lumirundata,runlist)
 alllumilsdata={}
 for runnum,perrundata in parseresult.items():
     pixellumidataid=0
     session.transaction().start(False)
     #session.transaction().start(True)
     hfdataidinfo=hfdataidmap[runnum]
     hflumidataid=hfdataidinfo[0]
コード例 #3
0
ファイル: specificLumi.py プロジェクト: Moanwar/cmssw
    
    print('===== Start Processing Fills',fillstoprocess)
    print('=====')
    filldata={}
    #
    # check datatag
    #
    reqfillmin=min(fillstoprocess)
    reqfillmax=max(fillstoprocess)
    session.transaction().start(True)
    runlist=lumiCalcAPI.runList(session.nominalSchema(),options.fillnum,runmin=None,runmax=None,fillmin=reqfillmin,fillmax=reqfillmax,startT=None,stopT=None,l1keyPattern=None,hltkeyPattern=None,amodetag=options.amodetag,nominalEnergy=None,energyFlut=None,requiretrg=False,requirehlt=False)
    
    datatagname=options.datatag
    if not datatagname:
        (datatagid,datatagname)=revisionDML.currentDataTag(session.nominalSchema())
        dataidmap=revisionDML.dataIdsByTagId(session.nominalSchema(),datatagid,runlist=runlist,withcomment=False)
        #{run:(lumidataid,trgdataid,hltdataid,())}
    else:
        dataidmap=revisionDML.dataIdsByTagName(session.nominalSchema(),datatagname,runlist=runlist,withcomment=False)

    #
    # check normtag and get norm values if required
    #
    normname='NONE'
    normid=0
    normvalueDict={}
    if not options.withoutNorm:
        normname=options.normtag
        if not normname:
            normmap=normDML.normIdByType(session.nominalSchema(),lumitype='HF',defaultonly=True)
コード例 #4
0
ファイル: pixelLumiCalc.py プロジェクト: Moanwar/cmssw
    ##############################################################
    # check run/ls list
    ##############################################################
    irunlsdict={}
    rruns=[]    
    session.transaction().start(True)
    filerunlist=None
    if options.inputfile:
        (irunlsdict,iresults)=parseInputFiles(options.inputfile)
        filerunlist=irunlsdict.keys()
    ##############################################################
    # check datatag
    # #############################################################
    datatagname=options.datatag
    if not datatagname:
        (datatagid,datatagname)=revisionDML.currentDataTag(session.nominalSchema(),lumitype='PIXEL')
    else:
        datatagid=revisionDML.getDataTagId(session.nominalSchema(),datatagname,lumitype='PIXEL')

    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')
    if not dataidmap:
        print('[INFO] No qualified run found, do nothing')
        sys.exit(14)
    rruns=[]
    for irun,(lid,tid,hid) in dataidmap.items():
        if not lid:
            print('[INFO] No qualified lumi data found for run, ',irun)
        if reqTrg and not tid:
            print('[INFO] No qualified trg data found for run ',irun)
        #    continue
        if reqHlt and not hid:
コード例 #5
0
                                  fillmin=reqfillmin,
                                  fillmax=reqfillmax,
                                  startT=None,
                                  stopT=None,
                                  l1keyPattern=None,
                                  hltkeyPattern=None,
                                  amodetag=options.amodetag,
                                  nominalEnergy=None,
                                  energyFlut=None,
                                  requiretrg=False,
                                  requirehlt=False)

    datatagname = options.datatag
    if not datatagname:
        (datatagid,
         datatagname) = revisionDML.currentDataTag(session.nominalSchema())
        dataidmap = revisionDML.dataIdsByTagId(session.nominalSchema(),
                                               datatagid,
                                               runlist=runlist,
                                               withcomment=False)
        #{run:(lumidataid,trgdataid,hltdataid,())}
    else:
        dataidmap = revisionDML.dataIdsByTagName(session.nominalSchema(),
                                                 datatagname,
                                                 runlist=runlist,
                                                 withcomment=False)

    #
    # check normtag and get norm values if required
    #
    normname = 'NONE'
コード例 #6
0
ファイル: csvLumiLoader.py プロジェクト: ahmad3213/cmssw
     raise
 lumirundatafromdb=[]
 lumilsdatafromdb={}
 if sourcelumiid:
     (lumirundatafromdb,lumilsdatafromdb)=lumiDataFromDB(sourcesession.nominalSchema(),sourcelumiid)
 sourcesession.transaction().commit()
 (rundat,lsdat)=generateLumidata(lumidatafromfile[0],lumidatafromfile[1],lumirundatafromdb,lumilsdatafromdb,begLS,endLS)
 print('rundat ',rundat)
 destsvc=sessionManager.sessionManager(options.deststr,authpath=options.authpath,debugON=False)
 destsession=destsvc.openSession(isReadOnly=False,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])
 destsession.transaction().start(False)
 (lumibranchid,lumibranchparent)=revisionDML.branchInfoByName(destsession.nominalSchema(),'DATA')
 branchinfo=(lumibranchid,'DATA')
 print('branchinfo ',branchinfo)
 
 (hf_tagid,hf_tagname)=revisionDML.currentDataTag(destsession.nominalSchema(),lumitype='HF')
 print('(hf_tagid,hf_tagname) ',(hf_tagid,hf_tagname))
 hfdataidmap=revisionDML.dataIdsByTagId(destsession.nominalSchema(),hf_tagid,[int(options.runnum)],withcomment=False,lumitype='HF')
 destsession.transaction().commit()
 print('dest hfdataidmap ',hfdataidmap)
 
 if int(options.runnum) in hfdataidmap:
     print('existing old hf data in destdb of run ',options.runnum,hfdataidmap[int(options.runnum)])
     destsession.transaction().start(False)
     [destlumidataid,desttrgdataid,desthltdataid]=hfdataidmap[int(options.runnum)]
     (lumirevid,lumientryid,lumidataid)=dataDML.addLumiRunDataToBranch(destsession.nominalSchema(),int(options.runnum),rundat,branchinfo,nameDealer.lumidataTableName())
     dataDML.bulkInsertLumiLSSummary(destsession,int(options.runnum),lumidataid,lsdat,nameDealer.lumisummaryv2TableName())
     destsession.transaction().commit()
     destsession.transaction().start(False)
     revisionDML.addRunToCurrentDataTag(destsession.nominalSchema(),int(options.runnum),lumidataid,desttrgdataid,desthltdataid,lumitype='HF',comment=options.comment)
     destsession.transaction().commit()
コード例 #7
0
     raise
 lumirundatafromdb=[]
 lumilsdatafromdb={}
 if sourcelumiid:
     (lumirundatafromdb,lumilsdatafromdb)=lumiDataFromDB(sourcesession.nominalSchema(),sourcelumiid)
 sourcesession.transaction().commit()
 (rundat,lsdat)=generateLumidata(lumidatafromfile[0],lumidatafromfile[1],lumirundatafromdb,lumilsdatafromdb,begLS,endLS)
 print 'rundat ',rundat
 destsvc=sessionManager.sessionManager(options.deststr,authpath=options.authpath,debugON=False)
 destsession=destsvc.openSession(isReadOnly=False,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])
 destsession.transaction().start(False)
 (lumibranchid,lumibranchparent)=revisionDML.branchInfoByName(destsession.nominalSchema(),'DATA')
 branchinfo=(lumibranchid,'DATA')
 print 'branchinfo ',branchinfo
 
 (hf_tagid,hf_tagname)=revisionDML.currentDataTag(destsession.nominalSchema(),lumitype='HF')
 print '(hf_tagid,hf_tagname) ',(hf_tagid,hf_tagname)
 hfdataidmap=revisionDML.dataIdsByTagId(destsession.nominalSchema(),hf_tagid,[int(options.runnum)],withcomment=False,lumitype='HF')
 destsession.transaction().commit()
 print 'dest hfdataidmap ',hfdataidmap
 
 if int(options.runnum) in hfdataidmap:
     print 'existing old hf data in destdb of run ',options.runnum,hfdataidmap[int(options.runnum)]
     destsession.transaction().start(False)
     [destlumidataid,desttrgdataid,desthltdataid]=hfdataidmap[int(options.runnum)]
     (lumirevid,lumientryid,lumidataid)=dataDML.addLumiRunDataToBranch(destsession.nominalSchema(),int(options.runnum),rundat,branchinfo,nameDealer.lumidataTableName())
     dataDML.bulkInsertLumiLSSummary(destsession,int(options.runnum),lumidataid,lsdat,nameDealer.lumisummaryv2TableName())
     destsession.transaction().commit()
     destsession.transaction().start(False)
     revisionDML.addRunToCurrentDataTag(destsession.nominalSchema(),int(options.runnum),lumidataid,desttrgdataid,desthltdataid,lumitype='HF',comment=options.comment)
     destsession.transaction().commit()
コード例 #8
0
ファイル: lumidb.py プロジェクト: dmwm/cmssh
def lumidb(run_lumi_dict, action='delivered', lumi_report=False):
    "Call lumidb to get luminosity numbers"
    actions  = ['overview', 'delivered', 'recorded', 'lumibyls', 'lumibylsXing']
    if  action not in actions:
        raise Exception('Unsupported action="%s", please check from %s' % (action, actions))
    beamModeChoices = ['stable']
    amodetagChoices = ['PROTPHYS', 'IONPHYS', 'PAPHYS' ]
    xingAlgoChoices = ['OCC1', 'OCC2', 'ET']

    #
    # parse arguments
    #  
    connect='frontier://LumiCalc/CMS_LUMI_PROD'
    authpath = None
    scalefactor = 1.0
    beamfluctuation = 0.2
    minbiasxsec = 69300.0 # minbias cross-secvtion in ub
    xingMinLum = 1e-03 # Minimum perbunch luminosity to print, default=1e-03/ub
    xingAlgo = 'OCC1'
    hltpath = None
    outputfile = None
    siteconfpath = None
    withoutNorm = False
    withoutCheckforupdate = False
    fillnum = None
    nowarning = True
    debug = False
    beamenergy = None
    amodetag = None
    reqrunmin=None
    reqfillmin=None
    reqtimemin=None
    reqrunmax=None
    reqfillmax=None
    reqtimemax=None
    timeFilter=[None,None]
    pbeammode = None
    iresults=[]
    reqTrg=False
    reqHlt=False
    svc = sessionManager.sessionManager(connect, authpath, siteconfpath, debugON=debug)
    session=svc.openSession(isReadOnly=True,
            cpp2sqltype=[('unsigned int', 'NUMBER(10)'), ('unsigned long long', 'NUMBER(20)')])

    ##############################################################
    # check run/ls list
    ##############################################################
    irunlsdict={}
    rruns=[]
    session.transaction().start(True)
    irunlsdict = run_lumi_dict
    iresults = []
    runlist=lumiCalcAPI.runList(session.nominalSchema(),
            fillnum, runmin=reqrunmin, runmax=reqrunmax,
            fillmin=reqfillmin, fillmax=reqfillmax,
            startT=reqtimemin, stopT=reqtimemax,
            l1keyPattern=None, hltkeyPattern=None,
            amodetag=amodetag, nominalEnergy=beamenergy,
            energyFlut=beamfluctuation,
            requiretrg=False, requirehlt=False)
    rruns = [val for val in runlist if val in irunlsdict.keys()]
    for selectedrun in irunlsdict.keys():#if there's further filter on the runlist,clean input dict
        if selectedrun not in rruns:
            del irunlsdict[selectedrun]
    ##############################################################
    # check datatag
    # #############################################################       
    datatagid, datatagname = revisionDML.currentDataTag(session.nominalSchema())
    dataidmap=revisionDML.dataIdsByTagId(\
            session.nominalSchema(), datatagid,
            runlist=rruns, withcomment=False)
    session.transaction().commit()
    if not dataidmap:
        print_warning('No data found in LumiDB for given set run lumi section')
        return 0, '/ub' # return lumi, units
                
    normvalueDict={}
    ##################
    # ls level       #
    ##################
    session.transaction().start(True)
    GrunsummaryData=lumiCalcAPI.runsummaryMap(session.nominalSchema(),irunlsdict)
    if  action == 'delivered':
        result=lumiCalcAPI.deliveredLumiForIds(session.nominalSchema(),irunlsdict,dataidmap,runsummaryMap=GrunsummaryData,beamstatusfilter=pbeammode,timeFilter=timeFilter,normmap=normvalueDict,lumitype='HF')
        if  lumi_report:
            lumiReport.toScreenTotDelivered(result,iresults,scalefactor,irunlsdict=irunlsdict,noWarning=nowarning,toFile=outputfile)

        # result {run:[lumilsnum(0),cmslsnum(1),timestamp(2),beamstatus(3),beamenergy(4),deliveredlumi(5),calibratedlumierr(6),(bxidxlist,bxvalues,bxerrs)(7),(bxidx,b1intensities,b2intensities)(8),fillnum(9),pu(10)]}
        totlumi = 0
        for run, val in result.items():
            for llist in val:
                if  irunlsdict[run]:
                    if  llist[0] in irunlsdict[run]: # select only lumis from input run ls dict
                        totlumi += llist[5]
                else:
                    totlumi += llist[5]
        totlumival, lumiunit = CommonUtil.guessUnit(totlumi)
        return totlumival, lumiunit
    if  action == 'overview':
        result=lumiCalcAPI.lumiForIds(session.nominalSchema(),irunlsdict,dataidmap,runsummaryMap=GrunsummaryData,beamstatusfilter=pbeammode,timeFilter=timeFilter,normmap=normvalueDict,lumitype='HF')
        lumiReport.toScreenOverview(result,iresults,scalefactor,irunlsdict=irunlsdict,noWarning=nowarning,toFile=outputfile)
    if  action == 'lumibyls':
        if not hltpath:
            result=lumiCalcAPI.lumiForIds(session.nominalSchema(),irunlsdict,dataidmap,runsummaryMap=GrunsummaryData,beamstatusfilter=pbeammode,timeFilter=timeFilter,normmap=normvalueDict,lumitype='HF',minbiasXsec=minbiasxsec)
            lumiReport.toScreenLumiByLS(result,iresults,scalefactor,irunlsdict=irunlsdict,noWarning=nowarning,toFile=outputfile)            
        else:
            hltname=hltpath
            hltpat=None
            if hltname=='*' or hltname=='all':
                hltname=None
            elif 1 in [c in hltname for c in '*?[]']: #is a fnmatch pattern
                hltpat=hltname
                hltname=None
            result=lumiCalcAPI.effectiveLumiForIds(session.nominalSchema(),irunlsdict,dataidmap,runsummaryMap=GrunsummaryData,beamstatusfilter=pbeammode,timeFilter=timeFilter,normmap=normvalueDict,hltpathname=hltname,hltpathpattern=hltpat,withBXInfo=False,bxAlgo=None,xingMinLum=xingMinLum,withBeamIntensity=False,lumitype='HF')
            lumiReport.toScreenLSEffective(result,iresults,scalefactor,irunlsdict=irunlsdict,noWarning=nowarning,toFile=outputfile)
    if  action == 'recorded':#recorded actually means effective because it needs to show all the hltpaths...
        hltname=hltpath
        hltpat=None
        if hltname is not None:
            if hltname=='*' or hltname=='all':
                hltname=None
            elif 1 in [c in hltname for c in '*?[]']: #is a fnmatch pattern
                hltpat=hltname
                hltname=None
        result=lumiCalcAPI.effectiveLumiForIds(session.nominalSchema(),irunlsdict,dataidmap,runsummaryMap=GrunsummaryData,beamstatusfilter=pbeammode,timeFilter=timeFilter,normmap=normvalueDict,hltpathname=hltname,hltpathpattern=hltpat,withBXInfo=False,bxAlgo=None,xingMinLum=xingMinLum,withBeamIntensity=False,lumitype='HF')
        lumiReport.toScreenTotEffective(result,iresults,scalefactor,irunlsdict=irunlsdict,noWarning=nowarning,toFile=outputfile)
    if  action == 'lumibylsXing':
        result=lumiCalcAPI.lumiForIds(session.nominalSchema(),irunlsdict,dataidmap,runsummaryMap=GrunsummaryData,beamstatusfilter=pbeammode,timeFilter=timeFilter,normmap=normvalueDict,withBXInfo=True,bxAlgo=xingAlgo,xingMinLum=xingMinLum,withBeamIntensity=False,lumitype='HF')
        outfile=outputfile
        if  not outfile:
            print '[WARNING] no output file given. lumibylsXing writes per-bunch lumi only to default file lumibylsXing.csv'
            outfile='lumibylsXing.csv'           
        lumiReport.toCSVLumiByLSXing(result,scalefactor,outfile,irunlsdict=irunlsdict,noWarning=nowarning)
    session.transaction().commit()
    del session
    del svc 
コード例 #9
0
                           cpp2sqltype=[('unsigned int', 'NUMBER(10)'),
                                        ('unsigned long long', 'NUMBER(20)')
                                        ])
 inputfilename = os.path.abspath(options.inputfile)
 parseresult = parseInputFile(inputfilename, options.singlerun)
 runlist = parseresult.keys()
 irunlsdict = {}
 for run in runlist:
     irunlsdict[run] = None
 session.transaction().start(True)
 (pixellumibranchid, pixellumibranchparent) = revisionDML.branchInfoByName(
     session.nominalSchema(), 'DATA')
 print 'pixellumibranchid ', pixellumibranchid, ' pixellumibranchparent ', pixellumibranchparent
 pixellumibranchinfo = (pixellumibranchid, 'DATA')
 (pixel_tagid,
  pixel_tagname) = revisionDML.currentDataTag(session.nominalSchema(),
                                              lumitype='PIXEL')
 (hf_tagid,
  hf_tagname) = revisionDML.currentDataTag(session.nominalSchema(),
                                           lumitype='HF')
 hfdataidmap = revisionDML.dataIdsByTagId(session.nominalSchema(),
                                          hf_tagid,
                                          runlist,
                                          withcomment=False,
                                          lumitype='HF')
 beamstatusdata = dataDML.beamstatusByIds(session.nominalSchema(),
                                          hfdataidmap)
 #print 'beamstatusdata ',beamstatusdata
 lumirundata = dataDML.lumiRunByIds(
     session.nominalSchema(), hfdataidmap, lumitype='HF'
 )  #{runnum: (nominalegev(0),ncollidingbunches(1),starttime(2),stoptime(3),nls(4)}
 session.transaction().commit()
コード例 #10
0
ファイル: lumidb.py プロジェクト: vkuznet/cmssh
def lumidb(run_lumi_dict, action='delivered', lumi_report=False):
    "Call lumidb to get luminosity numbers"
    actions = ['overview', 'delivered', 'recorded', 'lumibyls', 'lumibylsXing']
    if action not in actions:
        raise Exception('Unsupported action="%s", please check from %s' %
                        (action, actions))
    beamModeChoices = ['stable']
    amodetagChoices = ['PROTPHYS', 'IONPHYS', 'PAPHYS']
    xingAlgoChoices = ['OCC1', 'OCC2', 'ET']

    #
    # parse arguments
    #
    connect = 'frontier://LumiCalc/CMS_LUMI_PROD'
    authpath = None
    scalefactor = 1.0
    beamfluctuation = 0.2
    minbiasxsec = 69300.0  # minbias cross-secvtion in ub
    xingMinLum = 1e-03  # Minimum perbunch luminosity to print, default=1e-03/ub
    xingAlgo = 'OCC1'
    hltpath = None
    outputfile = None
    siteconfpath = None
    withoutNorm = False
    withoutCheckforupdate = False
    fillnum = None
    nowarning = True
    debug = False
    beamenergy = None
    amodetag = None
    reqrunmin = None
    reqfillmin = None
    reqtimemin = None
    reqrunmax = None
    reqfillmax = None
    reqtimemax = None
    timeFilter = [None, None]
    pbeammode = None
    iresults = []
    reqTrg = False
    reqHlt = False
    svc = sessionManager.sessionManager(connect,
                                        authpath,
                                        siteconfpath,
                                        debugON=debug)
    session = svc.openSession(isReadOnly=True,
                              cpp2sqltype=[('unsigned int', 'NUMBER(10)'),
                                           ('unsigned long long', 'NUMBER(20)')
                                           ])

    ##############################################################
    # check run/ls list
    ##############################################################
    irunlsdict = {}
    rruns = []
    session.transaction().start(True)
    irunlsdict = run_lumi_dict
    iresults = []
    runlist = lumiCalcAPI.runList(session.nominalSchema(),
                                  fillnum,
                                  runmin=reqrunmin,
                                  runmax=reqrunmax,
                                  fillmin=reqfillmin,
                                  fillmax=reqfillmax,
                                  startT=reqtimemin,
                                  stopT=reqtimemax,
                                  l1keyPattern=None,
                                  hltkeyPattern=None,
                                  amodetag=amodetag,
                                  nominalEnergy=beamenergy,
                                  energyFlut=beamfluctuation,
                                  requiretrg=False,
                                  requirehlt=False)
    rruns = [val for val in runlist if val in irunlsdict.keys()]
    for selectedrun in irunlsdict.keys(
    ):  #if there's further filter on the runlist,clean input dict
        if selectedrun not in rruns:
            del irunlsdict[selectedrun]
    ##############################################################
    # check datatag
    # #############################################################
    datatagid, datatagname = revisionDML.currentDataTag(
        session.nominalSchema())
    dataidmap=revisionDML.dataIdsByTagId(\
            session.nominalSchema(), datatagid,
            runlist=rruns, withcomment=False)
    session.transaction().commit()
    if not dataidmap:
        print_warning('No data found in LumiDB for given set run lumi section')
        return 0, '/ub'  # return lumi, units

    normvalueDict = {}
    ##################
    # ls level       #
    ##################
    session.transaction().start(True)
    GrunsummaryData = lumiCalcAPI.runsummaryMap(session.nominalSchema(),
                                                irunlsdict)
    if action == 'delivered':
        result = lumiCalcAPI.deliveredLumiForIds(session.nominalSchema(),
                                                 irunlsdict,
                                                 dataidmap,
                                                 runsummaryMap=GrunsummaryData,
                                                 beamstatusfilter=pbeammode,
                                                 timeFilter=timeFilter,
                                                 normmap=normvalueDict,
                                                 lumitype='HF')
        if lumi_report:
            lumiReport.toScreenTotDelivered(result,
                                            iresults,
                                            scalefactor,
                                            irunlsdict=irunlsdict,
                                            noWarning=nowarning,
                                            toFile=outputfile)

        # result {run:[lumilsnum(0),cmslsnum(1),timestamp(2),beamstatus(3),beamenergy(4),deliveredlumi(5),calibratedlumierr(6),(bxidxlist,bxvalues,bxerrs)(7),(bxidx,b1intensities,b2intensities)(8),fillnum(9),pu(10)]}
        totlumi = 0
        for run, val in result.items():
            for llist in val:
                if irunlsdict[run]:
                    if llist[0] in irunlsdict[
                            run]:  # select only lumis from input run ls dict
                        totlumi += llist[5]
                else:
                    totlumi += llist[5]
        totlumival, lumiunit = CommonUtil.guessUnit(totlumi)
        return totlumival, lumiunit
    if action == 'overview':
        result = lumiCalcAPI.lumiForIds(session.nominalSchema(),
                                        irunlsdict,
                                        dataidmap,
                                        runsummaryMap=GrunsummaryData,
                                        beamstatusfilter=pbeammode,
                                        timeFilter=timeFilter,
                                        normmap=normvalueDict,
                                        lumitype='HF')
        lumiReport.toScreenOverview(result,
                                    iresults,
                                    scalefactor,
                                    irunlsdict=irunlsdict,
                                    noWarning=nowarning,
                                    toFile=outputfile)
    if action == 'lumibyls':
        if not hltpath:
            result = lumiCalcAPI.lumiForIds(session.nominalSchema(),
                                            irunlsdict,
                                            dataidmap,
                                            runsummaryMap=GrunsummaryData,
                                            beamstatusfilter=pbeammode,
                                            timeFilter=timeFilter,
                                            normmap=normvalueDict,
                                            lumitype='HF',
                                            minbiasXsec=minbiasxsec)
            lumiReport.toScreenLumiByLS(result,
                                        iresults,
                                        scalefactor,
                                        irunlsdict=irunlsdict,
                                        noWarning=nowarning,
                                        toFile=outputfile)
        else:
            hltname = hltpath
            hltpat = None
            if hltname == '*' or hltname == 'all':
                hltname = None
            elif 1 in [c in hltname for c in '*?[]']:  #is a fnmatch pattern
                hltpat = hltname
                hltname = None
            result = lumiCalcAPI.effectiveLumiForIds(
                session.nominalSchema(),
                irunlsdict,
                dataidmap,
                runsummaryMap=GrunsummaryData,
                beamstatusfilter=pbeammode,
                timeFilter=timeFilter,
                normmap=normvalueDict,
                hltpathname=hltname,
                hltpathpattern=hltpat,
                withBXInfo=False,
                bxAlgo=None,
                xingMinLum=xingMinLum,
                withBeamIntensity=False,
                lumitype='HF')
            lumiReport.toScreenLSEffective(result,
                                           iresults,
                                           scalefactor,
                                           irunlsdict=irunlsdict,
                                           noWarning=nowarning,
                                           toFile=outputfile)
    if action == 'recorded':  #recorded actually means effective because it needs to show all the hltpaths...
        hltname = hltpath
        hltpat = None
        if hltname is not None:
            if hltname == '*' or hltname == 'all':
                hltname = None
            elif 1 in [c in hltname for c in '*?[]']:  #is a fnmatch pattern
                hltpat = hltname
                hltname = None
        result = lumiCalcAPI.effectiveLumiForIds(session.nominalSchema(),
                                                 irunlsdict,
                                                 dataidmap,
                                                 runsummaryMap=GrunsummaryData,
                                                 beamstatusfilter=pbeammode,
                                                 timeFilter=timeFilter,
                                                 normmap=normvalueDict,
                                                 hltpathname=hltname,
                                                 hltpathpattern=hltpat,
                                                 withBXInfo=False,
                                                 bxAlgo=None,
                                                 xingMinLum=xingMinLum,
                                                 withBeamIntensity=False,
                                                 lumitype='HF')
        lumiReport.toScreenTotEffective(result,
                                        iresults,
                                        scalefactor,
                                        irunlsdict=irunlsdict,
                                        noWarning=nowarning,
                                        toFile=outputfile)
    if action == 'lumibylsXing':
        result = lumiCalcAPI.lumiForIds(session.nominalSchema(),
                                        irunlsdict,
                                        dataidmap,
                                        runsummaryMap=GrunsummaryData,
                                        beamstatusfilter=pbeammode,
                                        timeFilter=timeFilter,
                                        normmap=normvalueDict,
                                        withBXInfo=True,
                                        bxAlgo=xingAlgo,
                                        xingMinLum=xingMinLum,
                                        withBeamIntensity=False,
                                        lumitype='HF')
        outfile = outputfile
        if not outfile:
            print '[WARNING] no output file given. lumibylsXing writes per-bunch lumi only to default file lumibylsXing.csv'
            outfile = 'lumibylsXing.csv'
        lumiReport.toCSVLumiByLSXing(result,
                                     scalefactor,
                                     outfile,
                                     irunlsdict=irunlsdict,
                                     noWarning=nowarning)
    session.transaction().commit()
    del session
    del svc