Exemplo n.º 1
0
        normvalueDict=normDML.normValueById(session.nominalSchema(),normid) #{since:[corrector(0),{paramname:paramvalue}(1),amodetag(2),egev(3),comment(4)]}
    session.transaction().commit()
    lumiReport.toScreenHeader(thiscmmd,datatagname,normname,workingversion,updateversion,'PIXEL',toFile=options.headerfile)

    ##################
    # ls level       #
    ##################
    session.transaction().start(True)
    GrunsummaryData=lumiCalcAPI.runsummaryMap(session.nominalSchema(),irunlsdict,dataidmap,lumitype='PIXEL')
    if options.action == 'overview':
       result=lumiCalcAPI.lumiForIds(session.nominalSchema(),irunlsdict,dataidmap,runsummaryMap=GrunsummaryData,beamstatusfilter=None,timeFilter=timeFilter,normmap=normvalueDict,lumitype='PIXEL')
       lumiReport.toScreenOverview(result,iresults,options.scalefactor,irunlsdict=irunlsdict,noWarning=noWarning,toFile=options.outputfile)
    if options.action == 'lumibyls':
       if not options.hltpath:
           result=lumiCalcAPI.lumiForIds(session.nominalSchema(),irunlsdict,dataidmap,runsummaryMap=GrunsummaryData,beamstatusfilter=None,timeFilter=timeFilter,normmap=normvalueDict,lumitype='PIXEL',minbiasXsec=options.minbiasxsec)
           lumiReport.toScreenLumiByLS(result,iresults,options.scalefactor,irunlsdict=irunlsdict,noWarning=noWarning,toFile=options.outputfile)
       else:
           hltname=options.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=None,timeFilter=timeFilter,normmap=normvalueDict,hltpathname=hltname,hltpathpattern=hltpat,withBXInfo=False,bxAlgo=None,withBeamIntensity=False,lumitype='PIXEL')
           lumiReport.toScreenLSEffective(result,iresults,options.scalefactor,irunlsdict=irunlsdict,noWarning=noWarning,toFile=options.outputfile,)
    if options.action == 'recorded':#recorded actually means effective because it needs to show all the hltpaths...
       hltname=options.hltpath
       hltpat=None
       if hltname is not None:
          if hltname=='*' or hltname=='all':
Exemplo n.º 2
0
        normvalueDict=normDML.normValueById(session.nominalSchema(),normid) #{since:[corrector(0),{paramname:paramvalue}(1),amodetag(2),egev(3),comment(4)]}
    session.transaction().commit()
    lumiReport.toScreenHeader(thiscmmd,datatagname,normname,workingversion,updateversion,'PIXEL',toFile=options.headerfile)

    ##################
    # ls level       #
    ##################
    session.transaction().start(True)
    GrunsummaryData=lumiCalcAPI.runsummaryMap(session.nominalSchema(),irunlsdict,dataidmap,lumitype='PIXEL')
    if options.action == 'overview':
       result=lumiCalcAPI.lumiForIds(session.nominalSchema(),irunlsdict,dataidmap,runsummaryMap=GrunsummaryData,beamstatusfilter=None,timeFilter=timeFilter,normmap=normvalueDict,lumitype='PIXEL')
       lumiReport.toScreenOverview(result,iresults,options.scalefactor,irunlsdict=irunlsdict,noWarning=noWarning,toFile=options.outputfile)
    if options.action == 'lumibyls':
       if not options.hltpath:
           result=lumiCalcAPI.lumiForIds(session.nominalSchema(),irunlsdict,dataidmap,runsummaryMap=GrunsummaryData,beamstatusfilter=None,timeFilter=timeFilter,normmap=normvalueDict,lumitype='PIXEL',minbiasXsec=options.minbiasxsec)
           lumiReport.toScreenLumiByLS(result,iresults,options.scalefactor,irunlsdict=irunlsdict,noWarning=noWarning,toFile=options.outputfile)
       else:
           hltname=options.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=None,timeFilter=timeFilter,normmap=normvalueDict,hltpathname=hltname,hltpathpattern=hltpat,withBXInfo=False,bxAlgo=None,withBeamIntensity=False,lumitype='PIXEL')
           lumiReport.toScreenLSEffective(result,iresults,options.scalefactor,irunlsdict=irunlsdict,noWarning=noWarning,toFile=options.outputfile,)
    if options.action == 'recorded':#recorded actually means effective because it needs to show all the hltpaths...
       hltname=options.hltpath
       hltpat=None
       if hltname is not None:
          if hltname=='*' or hltname=='all':
Exemplo n.º 3
0
Arquivo: lumidb.py Projeto: 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 
Exemplo n.º 4
0
         lumiReport.toCSVTotDelivered(result,options.outputfile,iresults,options.scalefactor,options.verbose)           
 if options.action == 'overview':
    session.transaction().start(True)
    result=lumiCalcAPI.lumiForRange(session.nominalSchema(),irunlsdict,amodetag=None,egev=None,beamstatus=None,norm=1.0,finecorrections=finecorrections,driftcorrections=None,usecorrectionv2=False,lumitype='PIXEL',branchName='DATA')
    session.transaction().commit()
    if not options.outputfile:
        lumiReport.toScreenOverview(result,iresults,options.scalefactor,options.verbose)
    else:
        lumiReport.toCSVOverview(result,options.outputfile,iresults,options.scalefactor,options.verbose)
 if options.action == 'lumibyls':
    if not options.hltpath:
        session.transaction().start(True)
        result=lumiCalcAPI.lumiForRange(session.nominalSchema(),irunlsdict,amodetag=None,egev=None,beamstatus=None,norm=1.0,finecorrections=finecorrections,driftcorrections=None,usecorrectionv2=False,lumitype='PIXEL',branchName='DATA')
        session.transaction().commit()
        if not options.outputfile:
            lumiReport.toScreenLumiByLS(result,iresults,options.scalefactor,options.verbose)
        else:
            lumiReport.toCSVLumiByLS(result,options.outputfile,iresults,options.scalefactor,options.verbose)
    else:
        hltname=options.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
        session.transaction().start(True)
        result=lumiCalcAPI.effectiveLumiForRange(session.nominalSchema(),irunlsdict,hltpathname=hltname,hltpathpattern=hltpat,amodetag=None,egev=None,beamstatus=None,norm=1.0,finecorrections=finecorrections,driftcorrections=None,usecorrectionv2=False,lumitype='PIXEL',branchName='DATA')
        session.transaction().commit()
        if not options.outputfile:
            lumiReport.toScreenLSEffective(result,iresults,options.scalefactor,options.verbose)
Exemplo n.º 5
0
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