Esempio n. 1
0
def getWeightIDs(edm_file_name):
    if "/store/" in edm_file_name:
        #edm_file_name = "/".join(["root://cmsxrootd.fnal.gov/",
        edm_file_name = "/".join(
            ["root://cms-xrd-global.cern.ch/", edm_file_name])
    elif not os.path.isfile(edm_file_name):
        raise FileNotFoundException("File %s was not found." % edm_file_name)
    runs = Runs(edm_file_name)
    runInfoHandle = Handle("LHERunInfoProduct")
    lheLabel = WeightTools.getLHEInfoTag(runs, runInfoHandle)
    run = runs.__iter__().next()
    run.getByLabel(lheLabel, runInfoHandle)
    lheStuff = runInfoHandle.product()

    # id number of PDF used
    pdfidx = lheStuff.heprup().PDFSUP.first
    print '%% Id number of PDF used: ' + str(pdfidx)

    lines = []
    for i, h in enumerate(lheStuff.headers_begin()):
        if i == lheStuff.headers_size():
            break
        hlines = []
        isWeights = False
        for line in h.lines():
            hlines.append(line)
            if 'weightgroup' in line:
                isWeights = True
        if isWeights:
            lines.extend(hlines)
    #        break
    return ''.join(lines).rstrip("<")
Esempio n. 2
0
def readHeader(edm_file_name, tag):
    if "/store/" in edm_file_name[:7]:
        edm_file_name = "/".join(
            ["root://cms-xrd-global.cern.ch/", edm_file_name])
    elif not os.path.isfile(edm_file_name):
        raise FileNotFoundException("File %s was not found." % edm_file_name)

    full_header = not tag

    runs = Runs(edm_file_name)
    runInfoHandle = Handle("LHERunInfoProduct")
    lheLabel = getLHEInfoTag(runs, runInfoHandle)
    run = runs.__iter__().next()
    run.getByLabel(lheLabel, runInfoHandle)
    lheStuff = runInfoHandle.product()
    lines = []
    for i, h in enumerate(lheStuff.headers_begin()):
        if i == lheStuff.headers_size():
            break
        hlines = []
        toStore = False
        for line in h.lines():
            hlines.append(line)
            if tag in line or full_header:
                toStore = True
        if toStore:
            lines.extend(hlines)
            if not full_header:
                break
    return ''.join(lines).rstrip("<")
def getWeightIDs(edm_file_name) :
    if "/store/" in edm_file_name :
        edm_file_name = "/".join(["root://cmsxrootd.fnal.gov/",
            edm_file_name])
    elif not os.path.isfile(edm_file_name) :
        raise FileNotFoundException("File %s was not found." % edm_file_name)
    runs = Runs(edm_file_name)
    runInfoHandle = Handle("LHERunInfoProduct")
    lheLabel = WeightTools.getLHEInfoTag(runs, runInfoHandle)
    run = runs.__iter__().next()
    run.getByLabel(lheLabel, runInfoHandle)
    lheStuff = runInfoHandle.product()
    lines = []
    for i, h in enumerate(lheStuff.headers_begin()) :
        if i == lheStuff.headers_size() :
            break
        hlines = []
        isWeights = False
        for line in h.lines() :
            hlines.append(line)
            if 'weightgroup' in line :
                isWeights = True
        if isWeights :
            lines.extend(hlines)
            break
    return ''.join(lines).rstrip("<")
def writeHeader(outfile_name, edmfile, onlyWeights=True):
    with open(outfile_name, "w") as outfile:
        outfile.write("# ---> From file %s" % edmfile)

        source = "externalLHEProducer"
        #source = "source"
        runs = Runs(edmfile)
        run = runs.__iter__().next()
        runInfoHandle = Handle("LHERunInfoProduct")
        run.getByLabel(source, runInfoHandle)
        runInfo = runInfoHandle.product()
        foundrwgt = False
        IPython.embed()
        for i, h in enumerate(runInfo.headers_begin()):
            print i, h, runInfo.headers_size()
            if i == runInfo.headers_size() or i > 20:
                break
            # For some of the 7_1_X samples, the header is added for each LHE file, read only the first copy
            if "initrwgt" in str(h.tag()):
                if foundrwgt:
                    break
                foundrwgt = True
            if not foundrwgt and onlyWeights:
                continue
            for line in h.lines():
                outfile.write(line)
Esempio n. 5
0
    print ' LHE Info for dataset: '
    print '    ' + key
    print '#################################'
    #    print EDMWeightInfo.getWeightIDs(samples[key])

    edm_file_name = samples[key]

    if "/store/" in edm_file_name:
        #edm_file_name = "/".join(["root://cmsxrootd.fnal.gov/",
        edm_file_name = "/".join(
            ["root://cms-xrd-global.cern.ch/", edm_file_name])
    elif not os.path.isfile(edm_file_name):
        raise FileNotFoundException("File %s was not found." % edm_file_name)
    runs = Runs(edm_file_name)
    runInfoHandle = Handle("LHERunInfoProduct")
    run = runs.__iter__().next()
    run.getByLabel('externalLHEProducer', runInfoHandle)
    lheStuff = runInfoHandle.product()

    # id number of PDF used
    pdfidx = lheStuff.heprup().PDFSUP.first
    pdfname = LHAID[
        str(pdfidx
            )] if pdfidx != -1 else ' undefined, please check the LHE header.'

    print '## Id number of PDF used: ' + str(pdfidx)
    print '## PDF set name: ' + pdfname
    print '####'

    lines = []
    for i, h in enumerate(lheStuff.headers_begin()):
    print ' LHE Info for dataset: '
    print '    '+key
    print '#################################'
#    print EDMWeightInfo.getWeightIDs(samples[key])

    edm_file_name = samples[key]

    if "/store/" in edm_file_name :
        #edm_file_name = "/".join(["root://cmsxrootd.fnal.gov/",
        edm_file_name = "/".join(["root://cms-xrd-global.cern.ch/",
            edm_file_name])
    elif not os.path.isfile(edm_file_name) :
        raise FileNotFoundException("File %s was not found." % edm_file_name)
    runs = Runs(edm_file_name)
    runInfoHandle = Handle("LHERunInfoProduct")
    run = runs.__iter__().next()
    run.getByLabel('externalLHEProducer', runInfoHandle)
    lheStuff = runInfoHandle.product()

    # id number of PDF used
    pdfidx = lheStuff.heprup().PDFSUP.first
    pdfname = LHAID[str(pdfidx)] if pdfidx!=-1 else ' undefined, please check the LHE header.'

    print '## Id number of PDF used: '+str(pdfidx)
    print '## PDF set name: '+pdfname
    print '####'

    lines = []
    for i, h in enumerate(lheStuff.headers_begin()) :
        if i == lheStuff.headers_size() :
            break
Esempio n. 7
0
pick = False
if args.pick:
   pick = tuple([int(i) for i in args.pick.split(':')])

import ROOT
import pprint
from DataFormats.FWLite import Events, Handle, Runs
from pdb import set_trace
ROOT.gROOT.SetBatch()

fname = args.file
if fname.startswith('/store/'):
   fname = 'root://cmsxrootd-site.fnal.gov/%s' % fname

events = Runs(fname) if args.inrun else Events(fname)
iterator = events.__iter__()
handle = Handle(args.handle)
keep_going = True
loop = 0

while keep_going:
   evt = iterator.next()
   loop += 1
   get_result = evt.getByLabel(args.label, handle)
   obj = handle.product()
   if pick:
      evtid = (evt.eventAuxiliary().run(), evt.eventAuxiliary().luminosityBlock(), evt.eventAuxiliary().event())
      if evtid == pick:
         keep_going = False
   else:
      print 'loop %d' % loop