Exemple #1
0
def recordedInvMicrobarns(json) :
    pars = lumiQueryAPI.ParametersObject()
    pars.noWarnings  = True
    pars.norm        = 1.0
    pars.lumiversion = '0001'
    pars.beammode    = 'STABLE BEAMS'

    session,svc =  lumiQueryAPI.setupSession( connectString = 'frontier://LumiCalc/CMS_LUMI_PROD',
                                              parameters = pars, siteconfpath = None, debug = False)
    lumidata =  lumiQueryAPI.recordedLumiForRange (session, pars, jsonToIFP(json))    
    return sum(lumiQueryAPI.calculateTotalRecorded(dataperRun[2]) for dataperRun in lumidata if dataperRun[1])
        os.environ["CORAL_AUTH_PATH"] = options.authpath

    ## Save what we need in the parameters object
    parameters.verbose = True
    parameters.noWarnings = options.nowarning
    parameters.lumiXing = True
    parameters.lumiversion = options.lumiversion
    if options.beammode == "stable":
        parameters.beammode = "STABLE BEAMS"
    parameters.xingMinLum = options.xingMinLum
    parameters.minBiasXsec = options.minBiasXsec
    parameters.pileupHistName = options.histName
    parameters.maxPileupBin = options.maxPileupBin

    session, svc = LumiQueryAPI.setupSession(
        options.connect or "frontier://LumiCalc/CMS_LUMI_PROD", options.siteconfpath, parameters, options.debug
    )

    ## Let's start the fun
    if not options.inputfile and not options.runnumber and not options.csvInput:
        raise "must specify either a run (-r), an input run selection file (-i), or an input CSV file (--csvInput)"
    pileupHist = ROOT.TH1D(parameters.pileupHistName, parameters.pileupHistName, 1001, 0.0, 25.0)
    histList = []
    if options.csvInput:
        # we're going to read in the CSV file and use this as not only
        # the selection of which run/events to use, but also the
        # source of the lumi information.
        sepRE = re.compile(r"[\s,;:]+")
        runLumiDict = {}
        events = open(options.csvInput, "r")
        csvDict = {}
Exemple #3
0
# Why doesn't LumiList have a getRunsAndLumis method? It can be
# constructed from a dict of runsAndLumis... Anyway we'll use sets for
# faster searching later.
runs_and_lumis = defaultdict(set)
for r, l in ll.getLumis():
    runs_and_lumis[r].add(l)
runs = runs_and_lumis.keys()
runs.sort()

# The path to look for: e.g. HLT_Mu30_v*. Should only find one per
# run, i.e. v4 and v5 do not exist simultaneously.
path_re = re.compile(r'HLT_%s_v\d+' % path)

# Magic.
parameters = lumiQueryAPI.ParametersObject()
session, svc = lumiQueryAPI.setupSession('frontier://LumiCalc/CMS_LUMI_PROD',
                                         None, parameters, False)
session.transaction().start(True)
schema = session.nominalSchema()

# Loop over all the requested runs, using the selected lumis, and get
# the prescales.
l1_prescales = {}
hlt_prescales = {}
for run in runs:
    lumis = runs_and_lumis[run]

    # Find the trigger path requested, including its L1 seed. If we
    # don't find exactly one satisfying the RE, then raise an
    # error. If the L1 seed is the AND or OR of any triggers, also
    # raise an error.
    q = schema.newQuery()
    ## Save what we need in the parameters object
    parameters.verbose        = True
    parameters.noWarnings     = options.nowarning
    parameters.lumiXing       = True
    parameters.lumiversion    = options.lumiversion
    if options.beammode=='stable':
        parameters.beammode    = 'STABLE BEAMS'
    parameters.xingMinLum     = options.xingMinLum
    parameters.minBiasXsec    = options.minBiasXsec
    parameters.pileupHistName = options.histName
    parameters.maxPileupBin   = options.maxPileupBin

    session, svc =  \
             LumiQueryAPI.setupSession (options.connect or \
                                        'frontier://LumiCalc/CMS_LUMI_PROD',
                                        options.siteconfpath, parameters,options.debug)

    ## Let's start the fun
    if not options.inputfile and not options.runnumber and not options.csvInput:
        raise "must specify either a run (-r), an input run selection file (-i), or an input CSV file (--csvInput)"
    pileupHist = ROOT.TH1D(parameters.pileupHistName, parameters.pileupHistName,
                      1001,
                      0.0, 25.)
    histList = []
    if options.csvInput:
        # we're going to read in the CSV file and use this as not only
        # the selection of which run/events to use, but also the
        # source of the lumi information.
        sepRE = re.compile (r'[\s,;:]+')
        runLumiDict = {}    
# Why doesn't LumiList have a getRunsAndLumis method? It can be
# constructed from a dict of runsAndLumis... Anyway we'll use sets for
# faster searching later.
runs_and_lumis = defaultdict(set)
for r,l in ll.getLumis():
    runs_and_lumis[r].add(l)
runs = runs_and_lumis.keys()
runs.sort()

# The path to look for: e.g. HLT_Mu30_v*. Should only find one per
# run, i.e. v4 and v5 do not exist simultaneously.
path_re = re.compile(r'HLT_%s_v\d+' % path)

# Magic.
parameters = lumiQueryAPI.ParametersObject()
session, svc = lumiQueryAPI.setupSession('frontier://LumiCalc/CMS_LUMI_PROD', None, parameters, False)
session.transaction().start(True)
schema = session.nominalSchema()

# Loop over all the requested runs, using the selected lumis, and get
# the prescales.
l1_prescales = {}
hlt_prescales = {}
for run in runs:
    lumis = runs_and_lumis[run]

    # Find the trigger path requested, including its L1 seed. If we
    # don't find exactly one satisfying the RE, then raise an
    # error. If the L1 seed is the AND or OR of any triggers, also
    # raise an error.
    q = schema.newQuery()
Exemple #6
0
def main():
    parser = argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]),description="Dump Prescale info for selected hltpath and trg path",formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('-c',dest='connect',action='store',help='connect string to lumiDB,optional',default='frontier://LumiCalc/CMS_LUMI_PROD')
    parser.add_argument('-P',dest='authpath',action='store',help='path to authentication file')
    parser.add_argument('-r',dest='runnumber',action='store',help='run number')
    parser.add_argument('-hltpath',dest='hltpath',action='store',required=True,help='hltpath')
    parser.add_argument('-trgbits',dest='trgbits',action='store',help='trgbits',default='all')
    parser.add_argument('-siteconfpath',dest='siteconfpath',action='store',help='specific path to site-local-config.xml file, optional. If path undefined, fallback to cern proxy&server')
    parser.add_argument('--debug',dest='debug',action='store_true',help='debug')
    args=parser.parse_args()
    runnumber=args.runnumber
    if args.authpath and len(args.authpath)!=0:
        os.environ['CORAL_AUTH_PATH']=args.authpath
    parameters = lumiQueryAPI.ParametersObject()
    session,svc =  lumiQueryAPI.setupSession (args.connect or \
                                              'frontier://LumiCalc/CMS_LUMI_PROD',
                                               args.siteconfpath,parameters,args.debug)
    session.transaction().start(True)
    schema=session.nominalSchema()
    runlist=[]
    if args.debug:
        msg=coral.MessageStream('')
        msg.setMsgVerbosity(coral.message_Level_Debug)
    if args.runnumber:
        runlist.append(int(args.runnumber))
    else:
        runlist=lumiQueryAPI.allruns(schema,True,True,True,True)
    runlist.sort()
    bitlist=[]
    hltpathStr=re.sub('\s','',args.hltpath)
    #print bitlistStr
    if args.trgbits and args.trgbits!='all':
        bitlistStr=args.trgbits
        bitlistStr=bitlistStr.strip()
        bitlistStr=re.sub('\s','',bitlistStr)
        bitlist=bitlistStr.split(',')
    result={}#{run:{hltpath:prescle},{trgname:prescale}}
    trgdict={}#{run:[(trgname,trgprescale),()]}
    hltdict={}#{run:{hltname:hltprescale}}
    for runnum in runlist:
        q=schema.newQuery()
        hltdump=lumiQueryAPI.hltBypathByrun(q,runnum,hltpathStr)
        del q
        if len(hltdump)>0:
            hltdict[runnum]=hltdump[1][-1]
        else:
            print 'run ',runnum,' hltpath ','"'+hltpathStr+'"','not found'
            continue
        if not args.trgbits or args.trgbits=='all':
            q=schema.newQuery()
            l1seeds = lumiQueryAPI.hlttrgMappingByrun(q,runnum)
            del q
            if len(l1seeds)==0 or not l1seeds.has_key(hltpathStr):
                print 'hlt path',hltpathStr,'has no l1 seed'
                continue
            l1seed=l1seeds[hltpathStr]
            rmQuotes=l1seed.replace('\"','')
            rmOR=rmQuotes.replace(' OR','')
            rmNOT=rmOR.replace(' NOT','')
            rmAND=rmOR.replace(' AND','')
            bitlist=rmAND.split(' ')
        if not trgdict.has_key(runnum):
            trgdict[runnum]=[]
        for bitname in bitlist:
            q=schema.newQuery()
            trgbitdump=lumiQueryAPI.trgBybitnameByrun(q,runnum,bitname)
            del q
            if len(trgbitdump)>0:
                trgprescale=trgbitdump[1][-1]
                trgdict[runnum].append((bitname,trgprescale))
            else:
                print 'run ',runnum,' bit ','"'+bitname+'"',' not found'
                continue
    session.transaction().commit()
    del session
    del svc
    if len(hltdict)<1:
        print 'no result found for',hltpathStr
        sys.exit(-1)
    runs=hltdict.keys()
    runs.sort()
    for r in runs:
        if not hltdict.has_key(r): continue
        hltprescale=hltdict[r]
        toprint=[str(r),hltpathStr,str(hltprescale)]
        if trgdict.has_key(r):
            trgbitsinfo=trgdict[r]
            for trgbitinfo in trgbitsinfo:
                trgname=trgbitinfo[0]
                toprint.append(trgname)
                trgprescale=trgbitinfo[1]
                toprint.append(str(trgprescale))
        print ' '.join(toprint)