Ejemplo n.º 1
0
def main():
    parser = argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]),description="list lumi data availability")
    # add required arguments
    parser.add_argument('-c',dest='connect',action='store',required=True,help='connect string to lumiDB')
    # add optional arguments
    parser.add_argument('-P',dest='authpath',action='store',help='path to authentication file')
    parser.add_argument('-siteconfpath',dest='siteconfpath',action='store',
			default=None,
                        required=False,
			help='specific path to site-local-config.xml file, optional. If path undefined, fallback to cern proxy&server')
    parser.add_argument('action',choices=['listrun'],help='command actions')
    parser.add_argument('--minrun',
			dest='minrun',
			action='store',
			type=int,
			help='min run number')
    parser.add_argument('--maxrun',
			dest='maxrun',
			action='store',
			type=int,
			help='max run number')
    parser.add_argument('--minfill',
			dest='minfill',
			type=int,
			action='store',
			help='min fill number')
    parser.add_argument('--maxfill',
			dest='maxfill',
			type=int,
			action='store',
			help='max fill number')
    parser.add_argument('--verbose',
			dest='verbose',
			action='store_true',
			help='verbose mode for printing' )
    parser.add_argument('--debug',dest='debug',action='store_true',help='debug')
    # parse arguments
    options=parser.parse_args()
    if options.authpath:
        os.environ['CORAL_AUTH_PATH'] = options.authpath
    svc=sessionManager.sessionManager(options.connect,authpath=options.authpath,debugON=options.debug)
    session=svc.openSession(isReadOnly=True,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])
    reqTrg=True
    reqHLT=False
    session.transaction().start(True)
    schema=session.nominalSchema()
    runlist=lumiCalcAPI.runList(schema,None,runmin=options.minrun,runmax=options.maxrun,startT=None,stopT=None,l1keyPattern=None,hltkeyPattern=None,amodetag=None,nominalEnergy=None,energyFlut=None,requiretrg=reqTrg,requirehlt=reqHLT)
    session.transaction().commit()
    if options.action == 'listrun':
	    if not runlist:
	        print '[]'
		sys.exit(0)
	    singlelist=listRemoveDuplicate(runlist)
	    singlelist.sort()
	    print singlelist
    del session
    del svc
Ejemplo n.º 2
0
 schema=session.nominalSchema()
 if options.action=='perday' or options.action=='instpeakperday':
     maxDrawnDay=int(lut.StrToDatetime(begtime,customfm='%m/%d/%y %H:%M:%S').date().toordinal())
     if resultlines:
         for drawnDay in [ int(t[0]) for t in resultlines]:
             if drawnDay>maxDrawnDay:
                 maxDrawnDay=drawnDay
     #print maxDrawnDay
     newFirstDay=maxDrawnDay+1
     if options.lastpointfromdb:
         newFirstDay=maxDrawnDay
     midnight=datetime.time()
     begT=datetime.datetime.combine(datetime.date.fromordinal(newFirstDay),midnight)
     begTStr=lut.DatetimeToStr(begT,customfm='%m/%d/%y %H:%M:%S')
     #find runs not in old plot
     runsnotdrawn=lumiCalcAPI.runList(schema,options.fillnum,runmin=None,runmax=None,startT=begTStr,stopT=endtime,l1keyPattern=None,hltkeyPattern=None,amodetag=options.amodetag,nominalEnergy=options.beamenergy,energyFlut=options.beamfluctuation,requiretrg=reqTrg,requirehlt=reqHlt)
     
 if options.action=='run' or options.action=='time':
     lastDrawnRun=132000
     if resultlines:#if there's old plot, start to count runs only after that
         lastDrawnRun=max([int(t[0]) for t in resultlines])
     newFirstRun=lastDrawnRun+1
     if options.lastpointfromdb:
         newFirstRun=lastDrawnRun
     runsnotdrawn=lumiCalcAPI.runList(schema,options.fillnum,runmin=newFirstRun,runmax=None,startT=begtime,stopT=endtime,l1keyPattern=None,hltkeyPattern=None,amodetag=options.amodetag,nominalEnergy=options.beamenergy,energyFlut=options.beamfluctuation,requiretrg=reqTrg,requirehlt=reqHlt)
     
 if options.action=='fill':
     lastDrawnFill=1000
     lastDrawnRun=132000
     if resultlines:
         lastDrawnFill=max([int(t[0]) for t in resultlines])        
Ejemplo n.º 3
0
    print('fills to process : ',fillstoprocess)
    if len(fillstoprocess)==0:
        print('no fill to process, exit ')
        exit(0)

    
    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={}
Ejemplo n.º 4
0
    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:
            print '[INFO] No qualified hlt data found for run ',irun
        #    continue
        rruns.append(irun)
    if not irunlsdict: #no file
Ejemplo n.º 5
0
 session=svc.openSession(isReadOnly=True,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])
 
 irunlsdict={}
 iresults=[]
 if options.runnumber: # if runnumber specified, do not go through other run selection criteria
     irunlsdict[options.runnumber]=None
 else:
     reqTrg=False
     reqHlt=False
     if options.action=='trgbyls':
         reqTrg=True
     if options.action=='hltbyls':
         reqHlt=True
     session.transaction().start(True)
     schema=session.nominalSchema()
     runlist=lumiCalcAPI.runList(schema,options.fillnum,runmin=None,runmax=None,startT=options.begin,stopT=options.end,l1keyPattern=None,hltkeyPattern=None,amodetag=options.amodetag,nominalEnergy=options.beamenergy,energyFlut=options.beamfluctuation,requiretrg=reqTrg,requirehlt=reqHlt)
     session.transaction().commit()
     if options.inputfile:
         (irunlsdict,iresults)=parseInputFiles(options.inputfile,runlist,options.action)
     else:
         for run in runlist:
             irunlsdict[run]=None
 if options.verbose:  
     print 'Selected run:ls'
     for run in sorted(irunlsdict):
         if irunlsdict[run] is not None:
             print '\t%d : %s'%(run,','.join([str(ls) for ls in irunlsdict[run]]))
         else:
             print '\t%d : all'%run
 if options.action == 'trgbyls':
     session.transaction().start(True)
Ejemplo n.º 6
0
 ##############################################################
 irunlsdict = {}
 rruns = []
 session.transaction().start(True)
 if options.runnumber:  # if runnumber specified, do not go through other run selection criteria
     irunlsdict[options.runnumber] = None
     rruns = irunlsdict.keys()
 else:
     runlist = lumiCalcAPI.runList(session.nominalSchema(),
                                   options.fillnum,
                                   runmin=reqrunmin,
                                   runmax=reqrunmax,
                                   fillmin=reqfillmin,
                                   fillmax=reqfillmax,
                                   startT=reqtimemin,
                                   stopT=reqtimemax,
                                   l1keyPattern=None,
                                   hltkeyPattern=None,
                                   amodetag=options.amodetag,
                                   nominalEnergy=options.beamenergy,
                                   energyFlut=options.beamfluctuation,
                                   requiretrg=False,
                                   requirehlt=False)
     if options.inputfile:
         (irunlsdict, iresults) = parseInputFiles(options.inputfile)
         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]
     else:
Ejemplo n.º 7
0
         for drawnDay in [int(t[0]) for t in resultlines]:
             if drawnDay > maxDrawnDay:  #all required days are already drawn
                 maxDrawnDay = drawnDay
     newFirstDay = maxDrawnDay
     midnight = datetime.time()
     begT = datetime.datetime.combine(
         datetime.date.fromordinal(newFirstDay), midnight)
     begTStr = lut.DatetimeToStr(begT, customfm='%m/%d/%y %H:%M:%S')
     #find runs not in old plot
     runlist = lumiCalcAPI.runList(session.nominalSchema(),
                                   options.fillnum,
                                   runmin=None,
                                   runmax=None,
                                   startT=begTStr,
                                   stopT=endtime,
                                   l1keyPattern=None,
                                   hltkeyPattern=None,
                                   amodetag=options.amodetag,
                                   nominalEnergy=options.beamenergy,
                                   energyFlut=options.beamfluctuation,
                                   requiretrg=reqTrg,
                                   requirehlt=reqHlt)
 if options.action == 'run' or options.action == 'time':
     lastDrawnRun = 132000
     if resultlines:  #if there's old plot, start to count runs only after that
         lastDrawnRun = max([int(t[0]) for t in resultlines])
     newFirstRun = lastDrawnRun + 1
     if options.lastpointfromdb:
         newFirstRun = lastDrawnRun
     runlist = lumiCalcAPI.runList(session.nominalSchema(),
                                   options.fillnum,
Ejemplo n.º 8
0
    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:
            print('[INFO] No qualified hlt data found for run ',irun)
        #    continue
        rruns.append(irun)
    if not irunlsdict: #no file
Ejemplo n.º 9
0
    datatagname = options.datatag
    if not datatagname:
        (datatagid,
         datatagname) = revisionDML.currentDataTag(session.nominalSchema())
    else:
        datatagid = revisionDML.getDataTagId(session.nominalSchema(),
                                             datatagname)

    dataidmap = lumiCalcAPI.runList(session.nominalSchema(),
                                    datatagid,
                                    runmin=reqrunmin,
                                    runmax=reqrunmax,
                                    fillmin=reqfillmin,
                                    fillmax=reqfillmax,
                                    startT=reqtimemin,
                                    stopT=reqtimemax,
                                    l1keyPattern=None,
                                    hltkeyPattern=None,
                                    amodetag=options.amodetag,
                                    nominalEnergy=options.beamenergy,
                                    energyFlut=options.beamfluctuation,
                                    requiretrg=reqTrg,
                                    requirehlt=reqHlt,
                                    preselectedruns=filerunlist)
    if not dataidmap:
        print('[INFO] No qualified run found, do nothing')
        sys.exit(14)
    rruns = []
    #crosscheck dataid value
    for irun, (lid, tid, hid) in dataidmap.items():
        if not lid:
            print('[INFO] No qualified lumi data found for run, ', irun)
Ejemplo n.º 10
0
    #    irunlsdict=dict(zip(rruns,[None]*len(rruns)))
    #else:
    #    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
    # #############################################################       
    datatagname=options.datatag
    if not datatagname:
        (datatagid,datatagname)=revisionDML.currentDataTag(session.nominalSchema())
    else:
        datatagid=revisionDML.getDataTagId(session.nominalSchema(),datatagname)

    dataidmap=lumiCalcAPI.runList(session.nominalSchema(),datatagid,runmin=reqrunmin,runmax=reqrunmax,fillmin=reqfillmin,fillmax=reqfillmax,startT=reqtimemin,stopT=reqtimemax,l1keyPattern=None,hltkeyPattern=None,amodetag=options.amodetag,nominalEnergy=options.beamenergy,energyFlut=options.beamfluctuation,requiretrg=reqTrg,requirehlt=reqHlt,preselectedruns=filerunlist)
    if not dataidmap:
        print('[INFO] No qualified run found, do nothing')
        sys.exit(14)
    rruns=[]
    #crosscheck dataid value
    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:
            print('[INFO] No qualified hlt data found for run ',irun)
        #    continue
        rruns.append(irun)
Ejemplo n.º 11
0
                                   debugON=options.debug)
 session=svc.openSession(isReadOnly=True,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])
 
 irunlsdict={}
 iresults=[]
 if options.runnumber: # if runnumber specified, do not go through other run selection criteria
     irunlsdict[options.runnumber]=None
 else:
     reqTrg=False
     reqHlt=False
     if options.action=='recorded':
         reqTrg=True
         reqHlt=True
     session.transaction().start(True)
     schema=session.nominalSchema()
     runlist=lumiCalcAPI.runList(schema,options.fillnum,runmin=None,runmax=None,startT=options.begin,stopT=options.end,l1keyPattern=None,hltkeyPattern=None,amodetag=None,nominalEnergy=None,energyFlut=None,requiretrg=reqTrg,requirehlt=reqHlt,lumitype='PIXEL')
     session.transaction().commit()
     if options.inputfile:
         (irunlsdict,iresults)=parseInputFiles(options.inputfile,runlist,options.action)
     else:
         for run in runlist:
             irunlsdict[run]=None
 if options.verbose:
     print 'Selected run:ls'
     for run in sorted(irunlsdict):
         if irunlsdict[run] is not None:
             print '\t%d : %s'%(run,','.join([str(ls) for ls in irunlsdict[run]]))
         else:
             print '\t%d : all'%run
 finecorrections=None
 if not options.withoutCorrection:
Ejemplo n.º 12
0
    rruns = []
    iresults = []

    session.transaction().start(True)
    if options.runnumber:  # if runnumber specified, do not go through other run selection criteria
        irunlsdict[options.runnumber] = None
        rruns = irunlsdict.keys()
    else:
        runlist = lumiCalcAPI.runList(session.nominalSchema(),
                                      options.fillnum,
                                      runmin=reqrunmin,
                                      runmax=reqrunmax,
                                      fillmin=reqfillmin,
                                      fillmax=reqfillmax,
                                      startT=reqtimemin,
                                      stopT=reqtimemax,
                                      l1keyPattern=None,
                                      hltkeyPattern=None,
                                      amodetag=None,
                                      nominalEnergy=None,
                                      energyFlut=None,
                                      requiretrg=False,
                                      requirehlt=False,
                                      lumitype='PIXEL')
        if options.inputfile:
            (irunlsdict, iresults) = parseInputFiles(options.inputfile)
            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]
        else:
Ejemplo n.º 13
0
Archivo: lumidb.py Proyecto: 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 
Ejemplo n.º 14
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