Пример #1
0
def hltpathsForRange(schema, runlist, hltpathname=None, hltpathpattern=None):
    '''
    input: runlist [run],     (required)      
           datatag: data version (optional)
    output : {runnumber,[(hltpath,l1seedexpr,l1bitname)...]}
    '''
    result = {}
    for run in runlist:
        hlttrgmap = dataDML.hlttrgMappingByrun(schema,
                                               run,
                                               hltpathname=hltpathname,
                                               hltpathpattern=hltpathpattern)
        result[run] = []
        for hltpath in sorted(hlttrgmap):
            l1seedexpr = hlttrgmap[hltpath]
            (exptype,
             l1bits) = hltTrgSeedMapper.findUniqueSeed(hltpath, l1seedexpr)
            l1bitname = 'n/a'
            if l1bits:
                if exptype:
                    l1bitname = l1seedexpr
                else:
                    l1bitname = l1bits[0]
            result[run].append((hltpath, l1seedexpr, l1bitname))
    return result
Пример #2
0
def hltpathsForRange(schema,runlist,hltpathname=None,hltpathpattern=None):
    '''
    input: runlist [run],     (required)      
           datatag: data version (optional)
    output : {runnumber,[(hltpath,l1seedexpr,l1bitname)...]}
    '''
    result={}
    for run in runlist:
        hlttrgmap=dataDML.hlttrgMappingByrun(schema,run,hltpathname=hltpathname,hltpathpattern=hltpathpattern)
        result[run]=[]
        for hltpath in sorted(hlttrgmap):
            l1seedexpr=hlttrgmap[hltpath]
            l1bitname=hltTrgSeedMapper.findUniqueSeed(hltpath,l1seedexpr)
            result[run].append((hltpath,l1seedexpr,l1bitname))
    return result
Пример #3
0
    def recordedLumiForRun(self,runnum,lslist=[-1]):
        '''
        lslist=[-1] means to take all in the db
        output: ['runnumber','trgtable{}','deadtable{}']
        '''
        dbsession = self._session
        c = self._c
        
        recorded=0.0
        lumidata=[] #[runnumber,trgtable,deadtable]
        trgtable={} #{hltpath:[l1seed,hltprescale,l1prescale]}
        deadtable={} #{lsnum:[deadtime,instlumi,bit_0,norbits]}
        lumidata.append(runnum)
        lumidata.append(trgtable)
        lumidata.append(deadtable)
        collectedseeds=[] #[(hltpath,l1seed)]
        try:
            dbsession.transaction().start(True)
            schema=dbsession.nominalSchema()
            query=schema.newQuery()
            query.addToTableList(nameDealer.cmsrunsummaryTableName(),'cmsrunsummary')
            query.addToTableList(nameDealer.trghltMapTableName(),'trghltmap')#small table first
            queryCondition=coral.AttributeList()
            queryCondition.extend("runnumber","unsigned int")
            queryCondition["runnumber"].setData(int(runnum))
            query.setCondition("trghltmap.HLTKEY=cmsrunsummary.HLTKEY AND cmsrunsummary.RUNNUM=:runnumber",queryCondition)
            query.addToOutputList("trghltmap.HLTPATHNAME","hltpathname")
            query.addToOutputList("trghltmap.L1SEED","l1seed")
            result=coral.AttributeList()
            result.extend("hltpathname","string")
            result.extend("l1seed","string")
            query.defineOutput(result)
            cursor=query.execute()
            while cursor.next():
                hltpathname=cursor.currentRow()["hltpathname"].data()
                l1seed=cursor.currentRow()["l1seed"].data()
                collectedseeds.append((hltpathname,l1seed))
            #print 'collectedseeds ',collectedseeds
            del query
            dbsession.transaction().commit()
            #loop over hltpath
            for (hname,sname) in collectedseeds:
                l1bitname=hltTrgSeedMapper.findUniqueSeed(hname,sname)
                #print 'found unque seed ',hname,l1bitname
                if l1bitname:
                    lumidata[1][hname]=[]
                    lumidata[1][hname].append(l1bitname.replace('\"',''))
            dbsession.transaction().start(True)
            schema=dbsession.nominalSchema()
            hltprescQuery=schema.tableHandle(nameDealer.hltTableName()).newQuery()
            hltprescQuery.addToOutputList("PATHNAME","hltpath")
            hltprescQuery.addToOutputList("PRESCALE","hltprescale")
            hltprescCondition=coral.AttributeList()
            hltprescCondition.extend('runnumber','unsigned int')
            hltprescCondition.extend('cmslsnum','unsigned int')
            hltprescCondition.extend('inf','unsigned int')
            hltprescResult=coral.AttributeList()
            hltprescResult.extend('hltpath','string')
            hltprescResult.extend('hltprescale','unsigned int')
            hltprescQuery.defineOutput(hltprescResult)
            hltprescCondition['runnumber'].setData(int(runnum))
            hltprescCondition['cmslsnum'].setData(1)
            hltprescCondition['inf'].setData(0)
            hltprescQuery.setCondition("RUNNUM =:runnumber and CMSLSNUM =:cmslsnum and PRESCALE !=:inf",hltprescCondition)
            cursor=hltprescQuery.execute()
            while cursor.next():
                hltpath=cursor.currentRow()['hltpath'].data()
                hltprescale=cursor.currentRow()['hltprescale'].data()
                if lumidata[1].has_key(hltpath):
                    lumidata[1][hltpath].append(hltprescale)
                
            cursor.close()
            del hltprescQuery
            dbsession.transaction().commit()
        
            dbsession.transaction().start(True)
            schema=dbsession.nominalSchema()
            query=schema.newQuery()
            query.addToTableList(nameDealer.trgTableName(),'trg')
            query.addToTableList(nameDealer.lumisummaryTableName(),'lumisummary')#small table first--right-most
            queryCondition=coral.AttributeList()
            queryCondition.extend("runnumber","unsigned int")
            queryCondition.extend("lumiversion","string")
            #queryCondition.extend("alive","bool")
            queryCondition["runnumber"].setData(int(runnum))
            queryCondition["lumiversion"].setData(c.LUMIVERSION)
            #queryCondition["alive"].setData(True)
            query.setCondition("lumisummary.RUNNUM=:runnumber and lumisummary.LUMIVERSION =:lumiversion AND lumisummary.CMSLSNUM=trg.CMSLSNUM and lumisummary.RUNNUM=trg.RUNNUM",queryCondition)
            #query.setCondition("trg.RUNNUM =:runnumber AND lumisummary.RUNNUM=:runnumber and lumisummary.LUMIVERSION =:lumiversion AND lumisummary.CMSLSNUM=trg.CMSLSNUM AND lumisummary.cmsalive=:alive AND trg.BITNUM=:bitnum",queryCondition)
            #query.addToOutputList("sum(lumisummary.INSTLUMI*(1-trg.DEADTIME/(lumisummary.numorbit*3564)))","recorded")
            query.addToOutputList("lumisummary.CMSLSNUM","cmsls")
            query.addToOutputList("lumisummary.INSTLUMI","instlumi")
            query.addToOutputList("lumisummary.NUMORBIT","norbits")
            query.addToOutputList("trg.TRGCOUNT","trgcount")
            query.addToOutputList("trg.BITNAME","bitname")
            query.addToOutputList("trg.DEADTIME","trgdeadtime")
            query.addToOutputList("trg.PRESCALE","trgprescale")
            query.addToOutputList("trg.BITNUM","trgbitnum")
            #query.addToOrderList("trg.BITNAME")
            #query.addToOrderList("trg.CMSLSNUM")

            result=coral.AttributeList()
            result.extend("cmsls","unsigned int")
            result.extend("instlumi","float")
            result.extend("norbits","unsigned int")
            result.extend("trgcount","unsigned int")
            result.extend("bitname","string")
            result.extend("trgdeadtime","unsigned long long")
            result.extend("trgprescale","unsigned int")
            result.extend("trgbitnum","unsigned int")
            trgprescalemap={}
            query.defineOutput(result)
            cursor=query.execute()
            while cursor.next():
                cmsls=cursor.currentRow()["cmsls"].data()
                instlumi=cursor.currentRow()["instlumi"].data()*c.NORM
                norbits=cursor.currentRow()["norbits"].data()
                trgcount=cursor.currentRow()["trgcount"].data()
                trgbitname=cursor.currentRow()["bitname"].data()
                trgdeadtime=cursor.currentRow()["trgdeadtime"].data()
                trgprescale=cursor.currentRow()["trgprescale"].data()
                trgbitnum=cursor.currentRow()["trgbitnum"].data()
                if cmsls==1:
                    if not trgprescalemap.has_key(trgbitname):
                        trgprescalemap[trgbitname]=trgprescale
                if trgbitnum==0:
                    if not deadtable.has_key(cmsls):
                        deadtable[cmsls]=[]
                        deadtable[cmsls].append(trgdeadtime)
                        deadtable[cmsls].append(instlumi)
                        deadtable[cmsls].append(trgcount)
                        deadtable[cmsls].append(norbits)
            cursor.close()
            del query
            dbsession.transaction().commit()
        
            #
            #consolidate results
            #
            #trgtable
            #print 'trgprescalemap',trgprescalemap
            #print lumidata[1]
            for hpath,trgdataseq in lumidata[1].items():   
                bitn=trgdataseq[0]
                if trgprescalemap.has_key(bitn) and len(trgdataseq)==2:
                    lumidata[1][hpath].append(trgprescalemap[bitn])                
            #filter selected cmsls
            lumidata[2]=self.filterDeadtable(deadtable,lslist)
            if not c.NOWARNING:
                for l,deaddata in lumidata[2].items():
                    if deaddata[1]==0.0:
                        print '[Warning] : run:ls has 0 instlumi ',str(runnum)+':'+str(l)
                    if deaddata[2]==0 or deaddata[0]==0:
                        print '[Warning] : run:ls has 0 deadtime and/or 0 zerobias bit counts ',str(runnum)+':'+str(l)
            #print 'lumidata[2] ',lumidata[2]
        except Exception,e:
            print str(e)
            dbsession.transaction().rollback()
            del dbsession
Пример #4
0
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):
    '''
    delivered/recorded/eff lumi in selected hlt path  (including calibration,time integral)
    input:
           irunlsdict: {run:[lsnum]}, where [lsnum]==None means all ; [lsnum]==[] means selected ls
           dataidmap : {run:(lumiid,trgid,hltid)}
           runsummaryMap: {run:[l1key(0),amodetag(1),egev(2),hltkey(3),fillnum(4),fillscheme(5),starttime(6),stoptime(7)]}
           beamstatusfilter: LS filter on beamstatus
           normmap: {since:[corrector(0),{paramname:paramvalue}(1),amodetag(2),egev(3),comment(4)]} if normmap empty, means without-correction , if notnormmap means without-correction
           hltpathname: selected hltpathname
           hltpathpattern: regex select hltpaths           
           withBXInfo: get per bunch info (optional)
           bxAlgo: algoname for bx values (optional) ['OCC1','OCC2','ET']
           xingMinLum: cut on bx lumi value (optional)
           withBeamIntensity: get beam intensity info (optional)
           lumitype: luminosity source
    output:
           result {run:[lumilsnum(0),cmslsnum(1),timestamp(2),beamstatus(3),beamenergy(4),deliveredlumi(5),recordedlumi(6),calibratedlumierror(7),{hltpath:[l1name,l1prescale,hltprescale,efflumi]}(8),bxdata(9),beamdata(10),fillnum(11),ncollidingbunches(12)]}
           {run:None}  None means no run in lumiDB, 
           {run:[]} [] means no lumi for this run in lumiDB
           {run:[....deliveredlumi(5),recorded(6)==None,]} means no trigger in lumiDB
           {run:[....deliveredlumi(5),recorded(6),calibratedlumierror(7)==None]} means no hlt in lumiDB
           
           lumi unit: 1/ub
    '''
    deliveredresult=deliveredLumiForIds(schema,irunlsdict,dataidmap,runsummaryMap,beamstatusfilter=beamstatusfilter,timeFilter=timeFilter,normmap=normmap,withBXInfo=withBXInfo,bxAlgo=bxAlgo,xingMinLum=xingMinLum,withBeamIntensity=withBeamIntensity,lumitype=lumitype,minbiasXsec=minbiasXsec)
    trgresult=trgForIds(schema,irunlsdict,dataidmap,withPrescale=True) #{run:[cmslsnum,deadfrac,deadtimecount,bitzero_count,bitzero_prescale,[(bitname,prescale,counts,mask)]]}
    hltresult=hltForIds(schema,irunlsdict,dataidmap,hltpathname=hltpathname,hltpathpattern=hltpathpattern,withL1Pass=False,withHLTAccept=False) #{runnumber:[(cmslsnum,[(hltpath,hltprescale,l1pass,hltaccept),...]),(cmslsnum,[])})}
    for run in deliveredresult.keys(): #loop over delivered
        perrundata=deliveredresult[run]
        if perrundata is None or len(perrundata)==0:#pass through 
            continue
        alltrgls=[]
        if run in trgresult and trgresult[run]:
            alltrgls=[x[0] for x in trgresult[run]]
        allhltls=[]
        if run in hltresult and hltresult[run]:
            allhltls=[x[0] for x in hltresult[run]]            
        l1bitinfo=[]
        hltpathinfo=[]
        hlttrgmap=dataDML.hlttrgMappingByrun(schema,run,hltpathname=hltpathname,hltpathpattern=hltpathpattern)
        
        for perlsdata in perrundata: #loop over ls
            if not perlsdata: continue #no lumi for this ls
            perlsdata.insert(6,None)
            perlsdata.insert(8,None)
            if not alltrgls: continue  #no trg for this run
            cmslsnum=perlsdata[1]
            recordedlumi=0.0
            if cmslsnum==0:#if not a cmsls or not selected by cms list, set recordedlumi,efflumi to 0
                continue
            else:
                try:
                    trglsidx=alltrgls.index(cmslsnum)
                    deadfrac=trgresult[run][trglsidx][1]
                    l1bitinfo=trgresult[run][trglsidx][5]
                    if deadfrac<0 or deadfrac>1.0:deadfrac=1.0
                    deliveredlumi=perlsdata[5]
                    recordedlumi=(1.0-deadfrac)*deliveredlumi
                except ValueError:
                    #print '[WARNING] no trigger for LS=',cmslsnum
                    continue #do not go further
            perlsdata[6]=recordedlumi
            if not allhltls: continue #no hlt for this run
            try:
                hltlsidx=allhltls.index(cmslsnum)
            except ValueError:
                #print '[WARNING] no hlt for LS=',cmslsnum
                continue #do not go further
            trgprescalemap={} #{bitname:l1prescale} for this lumi section
            if l1bitinfo:
                for thisbitinfo in l1bitinfo:
                    thisbitname=thisbitinfo[0]
                    thisbitprescale=thisbitinfo[2]
                    trgprescalemap['"'+thisbitname+'"']=thisbitprescale
            else:
                continue
            hltpathdata=hltresult[run][hltlsidx][1]
            efflumidict={}#{pathname:[[l1bitname,l1prescale,hltprescale,efflumi]]}       
            for pathidx,thispathinfo in enumerate(hltpathdata):
                thispathname=thispathinfo[0]
                thisprescale=thispathinfo[1]
                thisl1seed=None
                l1bitname=None
                l1prescale=None
                try:
                    thisl1seed=hlttrgmap[thispathname]
                except KeyError:
                    thisl1seed=None
                if thisl1seed:
                    try:
                        (exptype,l1bits)=hltTrgSeedMapper.findUniqueSeed(thispathname,thisl1seed)
                        if l1bits:
                            if not exptype:
                                l1bitname=l1bits[0]
                                l1prescale=trgprescalemap[l1bits[0]]#need to match double quoted string!                                
                            else:
                                pmin=99999999
                                pmax=0                                
                                for bit in l1bits:
                                    l1p=trgprescalemap[bit]
                                    if exptype=='OR':
                                        if l1p!=0 and l1p<pmin:
                                            pmin=l1p
                                            l1prescale=l1p
                                            l1bitname=bit
                                    if exptype=='AND':
                                        if l1p!=0 and l1p>pmax:
                                            pmax=l1p
                                            l1prescale=l1p
                                            l1bitname=bit
                        else:
                            l1prescale=None
                    except KeyError:
                        l1prescale=None
            
                efflumi=0.0
                if l1prescale and thisprescale:#normal both prescaled
                    efflumi=recordedlumi/(float(l1prescale)*float(thisprescale))
                    efflumidict[thispathname]=[l1bitname,l1prescale,thisprescale,efflumi]
                elif l1prescale and thisprescale==0: #hltpath in menu but masked
                    efflumidict[thispathname]=[l1bitname,l1prescale,thisprescale,efflumi]
                else:
                    efflumidict[thispathname]=[None,0,thisprescale,efflumi]
            perlsdata[8]=efflumidict
    return deliveredresult
Пример #5
0
def effectiveLumiForRange(schema,inputRange,hltpathname=None,hltpathpattern=None,amodetag=None,beamstatus=None,egev=None,withBXInfo=False,xingMinLum=0.0,bxAlgo=None,withBeamIntensity=False,norm=None,finecorrections=None,driftcorrections=None,usecorrectionv2=False,lumitype='HF',branchName=None):
    '''
    input:
           inputRange  {run:[cmsls]} (required)
           hltpathname: selected hltpathname
           hltpathpattern: regex select hltpaths           
           amodetag: amodetag for  picking norm(optional)
           egev: beamenergy for picking norm(optional)
           withBXInfo: get per bunch info (optional)
           bxAlgo: algoname for bx values (optional) ['OCC1','OCC2','ET']
           xingMinLum: cut on bx lumi value (optional)
           withBeamIntensity: get beam intensity info (optional)
           normname: norm factor name to use (optional)
           branchName: data version
    output:
    result {run:[lumilsnum(0),cmslsnum(1),timestamp(2),beamstatus(3),beamenergy(4),deliveredlumi(5),recordedlumi(6),calibratedlumierror(7),{hltpath:[l1name,l1prescale,hltprescale,efflumi]},bxdata,beamdata,fillnum]}
           lumi unit: 1/ub
    '''
    if lumitype not in ['HF','PIXEL']:
        raise ValueError('unknown lumitype '+lumitype)
    if branchName is None:
        branchName='DATA'
    lumitableName=''
    lumilstableName=''
    if lumitype=='HF':
        lumitableName=nameDealer.lumidataTableName()
        lumilstableName=nameDealer.lumisummaryv2TableName()
    else:
        lumitableName=nameDealer.pixellumidataTableName()
        lumilstableName=nameDealer.pixellumisummaryv2TableName()
    numbx=3564
    result = {}
    normval=None
    perbunchnormval=None
    if norm:
        normval=_getnorm(schema,norm)
        perbunchnormval=float(normval)/float(1000)
    elif amodetag and egev:
        normval=_decidenormFromContext(schema,amodetag,egev)
        perbunchnormval=float(normval)/float(1000)
    c=lumiTime.lumiTime()
    lumip=lumiParameters.ParametersObject()
    for run in inputRange.keys():
        lslist=inputRange[run]
        if lslist is not None and len(lslist)==0:#no selected ls, do nothing for this run
            result[run]=[]
            continue
        cmsrunsummary=dataDML.runsummary(schema,run)
        if len(cmsrunsummary)==0:#non existing run
            result[run]=None
            continue
        startTimeStr=cmsrunsummary[6]
        fillnum=cmsrunsummary[4]
        lumidataid=None
        trgdataid=None
        hltdataid=None
        lumidataid=dataDML.guessLumiDataIdByRun(schema,run,lumitableName)
        trgdataid=dataDML.guessTrgDataIdByRun(schema,run)
        hltdataid=dataDML.guessHltDataIdByRun(schema,run)
        if lumidataid is None or trgdataid is None or hltdataid is None:
            result[run]=None
            continue
        (lumirunnum,lumidata)=dataDML.lumiLSById(schema,lumidataid,beamstatus,tableName=lumilstableName)
        (trgrunnum,trgdata)=dataDML.trgLSById(schema,trgdataid,withPrescale=True)
        (hltrunnum,hltdata)=dataDML.hltLSById(schema,hltdataid,hltpathname=hltpathname,hltpathpattern=hltpathpattern)
        hlttrgmap=dataDML.hlttrgMappingByrun(schema,run)
        if not normval:#if norm cannot be decided , look for it according to context per run
            normval=_decidenormForRun(schema,run)
            perbunchnormval=float(normval)/float(1000)
        if not normval:#still not found? resort to global default (should never come here)
            normval=6370
            perbunchnormval=6.37
            print '[Warning] using default normalization '+str(normval)

        perrunresult=[]
        for lumilsnum,perlsdata in lumidata.items():
            cmslsnum=perlsdata[0]            
            triggeredls=perlsdata[0] 
            if lslist is not None and cmslsnum not in lslist:
                #cmslsnum=0
                triggeredls=0
                recordedlumi=0.0
            instlumi=perlsdata[1]
            instlumierror=perlsdata[2]
            avglumi=instlumi*normval
            calibratedlumi=avglumi 
            if lumitype=='HF' and finecorrections and finecorrections[run]:
                if usecorrectionv2:
                    if driftcorrections and driftcorrections[run]:
                        calibratedlumi=lumiCorrections.applyfinecorrectionV2(avglumi,finecorrections[run][0],finecorrections[run][1],finecorrections[run][2],finecorrections[run][3],finecorrections[run][4],driftcorrections[run])
                    else:
                        calibratedlumi=lumiCorrections.applyfinecorrectionV2(avglumi,finecorrections[run][0],finecorrections[run][1],finecorrections[run][2],finecorrections[run][3],finecorrections[run][4],1.0)
                else:
                    calibratedlumi=lumiCorrections.applyfinecorrection(avglumi,finecorrections[run][0],finecorrections[run][1],finecorrections[run][2])
            if lumitype=='PIXEL' and finecorrections is not None:
                calibratedlumi=finecorrections[run]*avglumi
            calibratedlumierror=instlumierror*normval
            bstatus=perlsdata[4]
            begev=perlsdata[5]
            numorbit=perlsdata[6]
            startorbit=perlsdata[7]
            timestamp=c.OrbitToTime(startTimeStr,startorbit,0)
            lslen=lumip.lslengthsec()
            deliveredlumi=calibratedlumi*lslen
            recordedlumi=0.0
            trgprescalemap={}#trgprescalemap for this ls
            efflumidict={}
            if triggeredls!=0:
                if not trgdata.has_key(cmslsnum):
                    #triggeredls=0 #if no trigger, set back to non-cms-active ls
                    recordedlumi=0.0 # no trigger->nobeam recordedlumi=None
                else:
                    deadcount=trgdata[cmslsnum][0] ##subject to change !!
                    bitzerocount=trgdata[cmslsnum][1]
                    bitzeroprescale=trgdata[cmslsnum][2]
                    deadfrac=trgdata[cmslsnum][3]
                    if deadfrac<0 or deadfrac>1.0:
                        deadfrac=1.0
                    #if float(bitzerocount)*float(bitzeroprescale)==0.0:
                    #    deadfrac=1.0
                    #else:
                    #    deadfrac=float(deadcount)/(float(bitzerocount)*float(bitzeroprescale))
                    #if deadfrac>1.0:
                    #    deadfrac=1.0  #artificial correction in case of deadfrac>1
                    recordedlumi=deliveredlumi*(1.0-deadfrac)
                    l1bitinfo=trgdata[cmslsnum][4]
                    if l1bitinfo:
                        for thisbitinfo in l1bitinfo:
                            thisbitname=thisbitinfo[0]
                            thisbitprescale=thisbitinfo[2]
                            #trgprescalemap['"'+thisbitname+'"']=thisbitprescale#note:need to double quote bit name!
                            trgprescalemap['"'+thisbitname+'"']=thisbitprescale

                    del trgdata[cmslsnum][:]
                if hltdata.has_key(cmslsnum):                
                    hltpathdata=hltdata[cmslsnum]
                    #print 'hltpathdata ',hltpathdata
                    for pathidx,thispathinfo in enumerate(hltpathdata):
                        efflumi=0.0                    
                        thispathname=thispathinfo[0]
                        thisprescale=thispathinfo[1]
                        thisl1seed=None
                        l1bitname=None
                        l1prescale=None
                        try:
                            thisl1seed=hlttrgmap[thispathname]
                        except KeyError:
                            thisl1seed=None
                            # print 'hltpath, l1seed, hltprescale ',thispathname,thisl1seed,thisprescale
                        if thisl1seed:                            
                            try:
                                l1bitname=hltTrgSeedMapper.findUniqueSeed(thispathname,thisl1seed)
                                if l1bitname :
                                    l1prescale=trgprescalemap[l1bitname]#need to match double quoted string!
                                else:
                                    l1prescale=None
                            except KeyError:
                                l1prescale=None                           
                        if l1prescale and thisprescale :#normal both prescaled
                            efflumi=recordedlumi/(float(l1prescale)*float(thisprescale))
                            efflumidict[thispathname]=[l1bitname,l1prescale,thisprescale,efflumi]
                        elif l1prescale and thisprescale==0: #hltpath in menu but masked
                            efflumi=0.0
                            efflumidict[thispathname]=[l1bitname,l1prescale,thisprescale,efflumi]
                        else:
                            efflumi=0.0
                            efflumidict[thispathname]=[None,0,thisprescale,efflumi]
                
            bxvaluelist=[]
            bxerrorlist=[]
            bxdata=None
            beamdata=None
            if withBXInfo:
                bxinfo=lumidata[8]
                bxvalueArray=None
                bxerrArray=None
                if bxinfo:
                    bxvalueArray=bxinfo[0]
                    bxerrArray=bxinfo[1]
                    for idx,bxval in enumerate(bxvalueArray):
                        if finecorrections and finecorrections[run]:
                            if usecorrectionv2:
                                if driftcorrections and driftcorrections[run]:
                                    mybxval=lumiCorrections.applyfinecorrectionBXV2(bxval,avglumi,perbunchnormval,finecorrections[run][0],finecorrections[run][1],finecorrections[run][2],finecorrections[run][3],finecorrections[run][4],driftcorrections[run])
                                else:
                                    mybxval=lumiCorrections.applyfinecorrectionBXV2(bxval,avglumi,perbunchnormval,finecorrections[run][0],finecorrections[run][1],finecorrections[run][2],finecorrections[run][3],finecorrections[run][4],1.0)
                            else:
                                mybxval=lumiCorrections.applyfinecorrectionBX(bxval,avglumi,perbunchnormval,finecorrections[run][0],finecorrections[run][1],finecorrections[run][2])
                        else:
                            mybxval=bxval*perbunchnormval
                        if mybxval>xingMinLum:
                            bxidxlist.append(idx)
                            bxvaluelist.append(bxval)
                            bxerrorlist.append(bxerrArray[idx])
                    del bxvalueArray[:]
                    del bxerrArray[:]
                bxdata=(bxidxlist,bxvaluelist,bxerrorlist)    
            if withBeamIntensity:
                beaminfo=perlsdata[9]
                bxindexlist=[]
                b1intensitylist=[]
                b2intensitylist=[]
                if beaminfo:
                    bxindexarray=beaminfo[0]
                    beam1intensityarray=beaminfo[1]
                    beam2intensityarray=beaminfo[2]                    
                    bxindexlist=bxindexarray.tolist()
                    b1intensitylist=beam1intensityarray.tolist()
                    b2intensitylist=beam2intensityarray.tolist()
                    del bxindexarray[:]
                    del beam1intensityarray[:]
                    del beam2intensityarray[:]
                beamdata=(bxindexlist,b1intensitylist,b2intensitylist)
#            print cmslsnum,deliveredlumi,recordedlumi,efflumidict
            perrunresult.append([lumilsnum,triggeredls,timestamp,bstatus,begev,deliveredlumi,recordedlumi,calibratedlumierror,efflumidict,bxdata,beamdata,fillnum])
            del perlsdata[:]
        result[run]=perrunresult
    #print result
    return result
Пример #6
0
def getLumiInfoForRuns(dbsession,c,runList,selectionDict,hltpath='',beamstatus=None,beamenergy=None,beamfluctuation=0.0,finecorrections=None):
    '''
    input: runList[runnum], selectionDict{runnum:[ls]}
    output:{runnumber:[delivered,recorded,recordedinpath] }
    '''
    t=lumiTime.lumiTime()
    result={}#runnumber:[lumisumoverlumils,lumisumovercmsls-deadtimecorrected,lumisumovercmsls-deadtimecorrected*hltcorrection_hltpath]
    #print 'selectionDict seen ',selectionDict
    dbsession.transaction().start(True)
    for runnum in runList:
        totallumi=0.0
        delivered=0.0
        recorded=0.0 
        recordedinpath=0.0
        if len(selectionDict)!=0 and not selectionDict.has_key(runnum):
            if runnum<max(selectionDict.keys()):
                result[runnum]=[0.0,0.0,0.0]
            continue
        q=dbsession.nominalSchema().newQuery()
        if finecorrections and finecorrections[runnum]:
            totallumi=lumiQueryAPI.lumisumByrun(q,runnum,c.LUMIVERSION,beamstatus,beamenergy,beamfluctuation,finecorrections=finecorrections[runnum]) #q1
        else:
            totallumi=lumiQueryAPI.lumisumByrun(q,runnum,c.LUMIVERSION,beamstatus,beamenergy,beamfluctuation)
        del q
        if not totallumi:
            result[runnum]=[0.0,0.0,0.0]
            if c.VERBOSE: print 'run ',runnum,' does not exist or has no lumi, skip'
            continue
        lumitrginfo={}
        hltinfo={}
        hlttrgmap={}
        q=dbsession.nominalSchema().newQuery()
        if finecorrections and finecorrections[runnum]:
            lumitrginfo=lumiQueryAPI.lumisummarytrgbitzeroByrun(q,runnum,c.LUMIVERSION,beamstatus,beamenergy,beamfluctuation,finecorrections=finecorrections[runnum]) #q2
        else:
            lumitrginfo=lumiQueryAPI.lumisummarytrgbitzeroByrun(q,runnum,c.LUMIVERSION,beamstatus,beamenergy,beamfluctuation)
        del q
        if len(lumitrginfo)==0:
            q=dbsession.nominalSchema().newQuery()
            if finecorrections and finecorrections[runnum]:
                lumiinfobyrun=lumiQueryAPI.lumisummaryByrun(q,runnum,c.LUMIVERSION,beamstatus,beamenergy,beamfluctuation,finecorrections=finecorrections[runnum]) #q3
            else:
                lumiinfobyrun=lumiQueryAPI.lumisummaryByrun(q,runnum,c.LUMIVERSION,beamstatus,beamenergy,beamfluctuation)
            del q
            if len(lumiinfobyrun)!=0:
                print 'warning request run ',runnum,' has no trigger data, calculate delivered only'
            for perlsdata in lumiinfobyrun:
                cmslsnum=perlsdata[0]
                instlumi=perlsdata[1]
                norbit=perlsdata[2]
                lslength=t.bunchspace_s*t.nbx*norbit
                delivered+=instlumi*lslength
            result[runnum]=[delivered,0.0,0.0]
            #result[runnum]=[0.0,0.0,0.0]
            #if c.VERBOSE: print 'request run ',runnum,' has no trigger, skip'
        else:
            norbits=lumitrginfo.values()[0][1]
            lslength=t.bunchspace_s*t.nbx*norbits
            delivered=totallumi*lslength
            hlttrgmap={}
            trgbitinfo={}
            if len(hltpath)!=0 and hltpath!='all':
                q=dbsession.nominalSchema().newQuery() #optional q3, initiated only if you ask for a hltpath
                hlttrgmap=lumiQueryAPI.hlttrgMappingByrun(q,runnum)
                del q
                if hlttrgmap.has_key(hltpath):
                    l1bitname=hltTrgSeedMapper.findUniqueSeed(hltpath,hlttrgmap[hltpath])
                    q=dbsession.nominalSchema().newQuery() #optional q4, initiated only if you ask for a hltpath and it exists 
                    hltinfo=lumiQueryAPI.hltBypathByrun(q,runnum,hltpath)
                    del q
                    q=dbsession.nominalSchema().newQuery()
                    trgbitinfo=lumiQueryAPI.trgBybitnameByrun(q,runnum,l1bitname) #optional q5, initiated only if you ask for a hltpath and it has a unique l1bit
                    del q
        #done all possible queries. process result
            for cmslsnum,valuelist in lumitrginfo.items():
                if len(selectionDict)!=0 and not (cmslsnum in selectionDict[runnum]):
                    #if there's a selection list but cmslsnum is not selected,skip
                    continue
                if valuelist[5]==0:#bitzero==0 means no beam,do nothing
                    continue
                trgprescale=valuelist[8]            
                deadfrac=float(valuelist[6])/float(float(valuelist[5])*float(trgprescale))
                if(deadfrac<1.0):
                    recorded=recorded+valuelist[0]*(1.0-deadfrac)*lslength
                    if hlttrgmap.has_key(hltpath) and hltinfo.has_key(cmslsnum):
                        hltprescale=hltinfo[cmslsnum][2]
                        trgprescale=trgbitinfo[cmslsnum][3]
                        recordedinpath=recordedinpath+valuelist[0]*(1.0-deadfrac)*lslength*hltprescale*trgprescale
                else:
                    if deadfrac<0.0:
                        print 'warning deadfraction negative in run',runnum,' ls ',cmslsnum
                if c.VERBOSE:
                    print runnum,cmslsnum,valuelist[0]*lslength,valuelist[0]*(1.0-deadfrac)*lslength,lslength,deadfrac
            result[runnum]=[delivered,recorded,recordedinpath]
    dbsession.transaction().commit()
    #if c.VERBOSE:
    #    print result
    return result