Example #1
0
def LumiListForRunPeriod(rp, MIN_LUMIS=0):
	ll = LumiList(filename = rp.json)
	runs = [ run for run in map(int,ll.getRuns()) if run >= rp.firstRun and run <= rp.lastRun]

	lumis = ll.getLumis()
	nlumis = defaultdict(int)
	for r,l in lumis:
		nlumis[r]+=1
	select_runs = [run for run in runs if nlumis[run] > MIN_LUMIS]
	ll.selectRuns(select_runs)
	return ll
def load_golden_jsons(golden_json_path):
  if not os.path.isfile(golden_json_path):
    raise RuntimeError("No such file: %s" % golden_json_path)
  lumi_obj = LumiList(golden_json_path)
  lumis = lumi_obj.getLumis()
  runlumi_dict = {}
  for run, lumi in lumis:
    if run not in runlumi_dict:
      runlumi_dict[run] = []
    assert(lumi not in runlumi_dict[run])
    runlumi_dict[run].append(lumi)
  return runlumi_dict
Example #3
0
def LumiListForRunPeriod(rp, MIN_LUMIS=0):
    ll = LumiList(filename=rp.json)
    runs = [
        run for run in map(int, ll.getRuns())
        if run >= rp.firstRun and run <= rp.lastRun
    ]

    lumis = ll.getLumis()
    nlumis = defaultdict(int)
    for r, l in lumis:
        nlumis[r] += 1
    select_runs = [run for run in runs if nlumis[run] > MIN_LUMIS]
    ll.selectRuns(select_runs)
    return ll
Example #4
0
def makeLumiBlocks(in_lumi_file, outdir, chunksize=5):
    ll = LumiList(filename=in_lumi_file)
    lumis = ll.getLumis()
    nblock = 0

    blocks = []
    for lumiblock in chunks(lumis, chunksize):
        nblock += 1
        ll2 = LumiList(lumis=lumiblock)
        fn = outdir + "/block_{0}.json".format(nblock)
        of = open(fn, "w")
        of.write(str(ll2))
        of.close()
        blocks += [fn]
    return blocks
Example #5
0
from FWCore.PythonUtilities.LumiList import LumiList

# Bomb if args not specified.
if len(sys.argv) < 3 or not os.path.isfile(sys.argv[1]):
    print 'usage: prescales.py lumis.json pathsubstr'
    sys.exit(1)
json = sys.argv[1]
path = sys.argv[2]

ll = LumiList(json)

# 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()
Example #6
0
import argparse

from FWCore.PythonUtilities.LumiList import LumiList

parser = argparse.ArgumentParser()
parser.add_argument('-i',
                    '--input',
                    type=str,
                    help="file containing the list of input files",
                    required=True)
args = parser.parse_args()

goodLumis = LumiList(
    url=
    'http://opendata.cern.ch/record/1002/files/Cert_190456-208686_8TeV_22Jan2013ReReco_Collisions12_JSON.txt'
)
print "all good lumis"
print goodLumis

lumis = Lumis(args.input)
for lum in lumis:
    runsLumisDict = {}
    runList = runsLumisDict.setdefault(lum.aux().run(), [])
    runList.append(lum.aux().id().luminosityBlock())
    myLumis = LumiList(runsAndLumis=runsLumisDict)
    if myLumis.getLumis() in goodLumis.getLumis():
        print "good lumi"
        print myLumis
    else:
        print "bad lumi"
        print myLumis
from FWCore.PythonUtilities.LumiList import LumiList

# Bomb if args not specified.
if len(sys.argv) < 3 or not os.path.isfile(sys.argv[1]):
    print 'usage: prescales.py lumis.json pathsubstr'
    sys.exit(1)
json = sys.argv[1]
path = sys.argv[2]

ll = LumiList(json)

# 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
Example #8
0
    inGoldenButNotCMS3 = goldenLumis - cms3Lumis
    inGoldenButNotCMS3IntLumi = getLumiFromLL(inGoldenButNotCMS3)

    # cms3LumisIntLumi = getLumiFromLL(cms3Lumis - (cms3Lumis - goldenLumis))
    cms3LumisIntLumi = getLumiFromLL(cms3Lumis & goldenLumis)
    print "We have %.2f/pb in CMS3" % (getLumiFromLL(cms3Lumis))
    print "We have %.2f/pb in Golden&CMS3 (%.1f%% of golden)" % (cms3LumisIntLumi, 100.0*cms3LumisIntLumi/goldenIntLumi)
    print "This is what is in the Golden JSON, but not the CMS3 merged (%.2f/pb):" % getLumiFromLL(inGoldenButNotCMS3)
    print inGoldenButNotCMS3
    print

    for file in fileLumis.keys():
        fileLumi = LumiList(compactList=fileLumis[file])
        # Only care about stuff in the file that is in the golden JSON
        fileLumi = fileLumi - (fileLumi - goldenLumis)
        nLumisInFile = len(fileLumi.getLumis())

        lumisWeDontHave = fileLumi - cms3Lumis
        nLumisWeDontHave = len(lumisWeDontHave.getLumis())

        # If we don't have ANY of the lumis in a file, it could be that we didn't run over the file
        # (I am thus implicitly assuming that if we have any lumis in cms3 corresponding to a file
        #  that we actually ran over the whole file and maybe didn't store some lumis due to triggers)
        if nLumisInFile == nLumisWeDontHave and nLumisInFile > 0: 
            # maybe we didn't run over this file
            print " "*5,file
            print " "*10,"File has lumis ", fileLumi,"and CMS3 is missing all of them"

    print "\n"*2

Example #9
0
#!/usr/bin/env python

import sys
from FWCore.PythonUtilities.LumiList import LumiList

ll = LumiList(filename=sys.argv[1])
print len(ll.getLumis())

Example #10
0
         help='base for output filenames')
   parser.add_option ('--outend', dest='outend', type='string', default = [],
         help='ending for output filenames')

   # required parameters
   (options, args) = parser.parse_args()
   if len (args) != 1:
      raise RuntimeError, "Must provide exactly one input file"

   if options.sec < 2:
      raise RuntimeError, "Need at least 2 sections."

   commaRE = re.compile (r',')
   
   alphaList = LumiList (filename = args[0]) # Read in first JSON file
   allLumis = alphaList.getLumis()

   count_lumis = 0
   for (run, lumi) in allLumis:
      count_lumis += 1

   lumis_per_sec = count_lumis/options.sec
   print 'Found %s lumis in file.' % count_lumis
   print 'Splitting into %s sections with %s lumis each.' % (options.sec, lumis_per_sec)

   count_lumis = 0
   for sec in range(options.sec):
      
      ibegin = sec*lumis_per_sec
      iend = ibegin + lumis_per_sec
      if sec == options.sec - 1:
Example #11
0
from FWCore.PythonUtilities.LumiList import LumiList
import sys

ll = LumiList(filename=sys.argv[1])
lumis = ll.getLumis()
nblock = 0


def chunks(l, n):
    """Yield successive n-sized chunks from l."""
    for i in xrange(0, len(l), n):
        yield l[i:i + n]


for lumiblock in chunks(lumis, 5):
    print lumiblock
    nblock += 1
    ll2 = LumiList(lumis=lumiblock)
    of = open(sys.argv[2] + "/block_{0}.json".format(nblock), "w")
    of.write(str(ll2))
    of.close()
Example #12
0
from FWCore.PythonUtilities.LumiList import LumiList
import sys

ll = LumiList(filename=sys.argv[1])
lumis = ll.getLumis()
nblock = 0

def chunks(l, n):
    """Yield successive n-sized chunks from l."""
    for i in xrange(0, len(l), n):
        yield l[i:i+n]

for lumiblock in chunks(lumis, 5):
    print lumiblock
    nblock += 1
    ll2 = LumiList(lumis=lumiblock)
    of = open(sys.argv[2] + "/block_{0}.json".format(nblock), "w")
    of.write(str(ll2))
    of.close()