コード例 #1
0
def main():
    vhdl_dict = VHDLConstantsParser.parse_vhdl_file("data/ugmt_constants.vhd")

    opts = parse_options()
    nMax = opts.nMax
    skip = opts.skip
    fname_dict = discover_emu_files(opts.emudirectory)
    # rankLUT = l1t.MicroGMTRankPtQualLUT()

    for pattern, fnames in fname_dict.iteritems():
        print "+" * 30, pattern, "+" * 30
        events = Events(fnames['root'])

        start = time.time()

        tower_indices = None
        if 'idebug' in fnames.keys():
            debug_fname = fnames['idebug']
            with open(debug_fname, 'r') as fobj:
                tower_indices = [[int(idx.strip()) for idx in l.split()]
                                 for l in fobj]

        out_handle = Handle('BXVector<l1t::Muon>')
        imd_bmtf_handle = Handle('BXVector<l1t::Muon>')
        imd_emtf_p_handle = Handle('BXVector<l1t::Muon>')
        imd_emtf_n_handle = Handle('BXVector<l1t::Muon>')
        imd_omtf_p_handle = Handle('BXVector<l1t::Muon>')
        imd_omtf_n_handle = Handle('BXVector<l1t::Muon>')
        bar_handle = Handle('BXVector<l1t::RegionalMuonCand>')
        fwd_handle = Handle('BXVector<l1t::RegionalMuonCand>')
        ovl_handle = Handle('BXVector<l1t::RegionalMuonCand>')
        calo_handle = Handle('BXVector<l1t::MuonCaloSum>')

        basedir_testbench = "data/patterns/testbench/"
        basedir_mp7 = "data/patterns/mp7/"

        input_buffer = PatternDumper(basedir_mp7 + pattern + ".txt", vhdl_dict,
                                     BufferWriter)
        output_buffer = PatternDumper(basedir_mp7 + pattern + "_out.txt",
                                      vhdl_dict, BufferWriter)
        input_testbench = PatternDumper(basedir_testbench + pattern + ".txt",
                                        vhdl_dict, TestbenchWriter)
        serializer_testbench = PatternDumper(
            basedir_testbench + "serializer_" + pattern + ".txt", vhdl_dict,
            TestbenchWriter)
        deserializer_testbench = PatternDumper(
            basedir_testbench + "deserializer_" + pattern + ".txt", vhdl_dict,
            TestbenchWriter)
        integration_testbench = PatternDumper(
            basedir_testbench + "integration_" + pattern + ".txt", vhdl_dict,
            TestbenchWriter)

        if opts.delay > 0:
            input_buffer.writeEmptyFrames(opts.delay)

        setup_time = time.time() - start

        avg_get_label_time = 0
        avg_conversion_time = 0
        avg_write_time = 0
        n_twrs = 0
        for i, event in enumerate(events):
            if i < skip:
                continue
            if nMax > 0 and i - skip > nMax:
                break
            evt_start = time.time()
            event_head = "#" * 80 + "\n"
            event_head += "# Event: {ievent}\n".format(ievent=i)
            event_head += "#" * 80 + "\n"
            input_testbench.addLine(event_head)
            serializer_testbench.addLine(event_head)
            deserializer_testbench.addLine(event_head)
            integration_testbench.addLine(event_head)

            event.getByLabel("simGmtStage2Digis", out_handle)
            event.getByLabel("simGmtStage2Digis", "imdMuonsBMTF",
                             imd_bmtf_handle)
            event.getByLabel("simGmtStage2Digis", "imdMuonsEMTFPos",
                             imd_emtf_p_handle)
            event.getByLabel("simGmtStage2Digis", "imdMuonsEMTFNeg",
                             imd_emtf_n_handle)
            event.getByLabel("simGmtStage2Digis", "imdMuonsOMTFPos",
                             imd_omtf_p_handle)
            event.getByLabel("simGmtStage2Digis", "imdMuonsOMTFNeg",
                             imd_omtf_n_handle)
            event.getByLabel("simBmtfDigis", "BMTF", bar_handle)
            event.getByLabel("simEmtfDigis", "EMTF", fwd_handle)
            event.getByLabel("simOmtfDigis", "OMTF", ovl_handle)
            #event.getByLabel("gmtStage2Digis", "BMTF", bar_handle)
            #event.getByLabel("gmtStage2Digis", "EMTF", fwd_handle)
            #event.getByLabel("gmtStage2Digis", "OMTF", ovl_handle)

            event.getByLabel("simGmtCaloSumDigis", "TriggerTowerSums",
                             calo_handle)
            #event.getByLabel("emptyCaloCollsProducer", "EmptyTriggerTowerSums", calo_handle)
            #event.getByLabel("simGmtCaloSumDigis", "TriggerTower2x2s", calo_handle)
            get_label_time = time.time() - evt_start
            calo_sums_raw = calo_handle.product()
            calo_sums = get_calo_list(calo_sums_raw)

            emu_out_muons = out_handle.product()
            outmuons = get_muon_list_out(emu_out_muons, "OUT", vhdl_dict)
            serializermuons = get_muon_list_out(emu_out_muons, "SER",
                                                vhdl_dict)
            imd_emtf_p_prod = imd_emtf_p_handle.product()
            imdmuons = get_muon_list_out(imd_emtf_p_prod, "IMD", vhdl_dict, 4)
            imd_omtf_p_prod = imd_omtf_p_handle.product()
            imdmuons += get_muon_list_out(imd_omtf_p_prod, "IMD", vhdl_dict, 4)
            imd_bmtf_prod = imd_bmtf_handle.product()
            imdmuons += get_muon_list_out(imd_bmtf_prod, "IMD", vhdl_dict, 8)
            imd_omtf_n_prod = imd_omtf_n_handle.product()
            imdmuons += get_muon_list_out(imd_omtf_n_prod, "IMD", vhdl_dict, 4)
            imd_emtf_n_prod = imd_emtf_n_handle.product()
            imdmuons += get_muon_list_out(imd_emtf_n_prod, "IMD", vhdl_dict, 4)

            emu_bar_muons = bar_handle.product()
            bar_muons = get_muon_list(emu_bar_muons, "BMTF", vhdl_dict, i)
            emu_ovl_muons = ovl_handle.product()
            ovlp_muons = get_muon_list(emu_ovl_muons, "OMTF_POS", vhdl_dict, i)
            ovln_muons = get_muon_list(emu_ovl_muons, "OMTF_NEG", vhdl_dict, i)
            emu_fwd_muons = fwd_handle.product()
            fwdp_muons = get_muon_list(emu_fwd_muons, "EMTF_POS", vhdl_dict, i)
            fwdn_muons = get_muon_list(emu_fwd_muons, "EMTF_NEG", vhdl_dict, i)

            conversion_time = time.time() - evt_start - get_label_time
            input_buffer.writeFrameBasedInputBX(bar_muons, fwdp_muons,
                                                fwdn_muons, ovlp_muons,
                                                ovln_muons, calo_sums)
            integration_testbench.writeFrameBasedInputBX(
                bar_muons, fwdp_muons, fwdn_muons, ovlp_muons, ovln_muons,
                calo_sums)
            deserializer_testbench.writeFrameBasedInputBX(
                bar_muons, fwdp_muons, fwdn_muons, ovlp_muons, ovln_muons,
                calo_sums)
            output_buffer.writeFrameBasedOutputBX(outmuons, imdmuons)

            input_testbench.writeMuonBasedInputBX(bar_muons,
                                                  fwdp_muons,
                                                  fwdn_muons,
                                                  ovlp_muons,
                                                  ovln_muons,
                                                  calosums=calo_sums,
                                                  addTracks=True)
            input_testbench.addLine("# Expected emulator output\n")
            input_testbench.writeMuonBasedOutputBX(outmuons, imdmuons)
            deserializer_testbench.addLine("# Expected emulator output\n")
            deserializer_testbench.writeMuonBasedInputBX(bar_muons,
                                                         fwdp_muons,
                                                         fwdn_muons,
                                                         ovlp_muons,
                                                         ovln_muons,
                                                         calosums=calo_sums,
                                                         addTracks=True)
            if tower_indices is not None:
                input_testbench.addLine("# Tower indices:\n")
                cntr = 0
                for mu in outmuons:
                    if mu.bitword != 0:
                        cntr += 1
                input_testbench.writeTowerIndices(tower_indices[n_twrs:n_twrs +
                                                                cntr])
                n_twrs += cntr

            serializer_testbench.writeMuonBasedOutputBX(
                serializermuons, imdmuons)
            serializer_testbench.addLine("# Expected emulator output\n")
            serializer_testbench.writeFrameBasedOutputBX(
                serializermuons, imdmuons)
            integration_testbench.addLine("# Expected emulator output\n")
            integration_testbench.writeFrameBasedOutputBX(outmuons, imdmuons)
            write_time = time.time() - evt_start - conversion_time
            avg_get_label_time += get_label_time
            avg_conversion_time += conversion_time
            avg_write_time += write_time
        print "total: ", time.time() - start
        print "setup: ", setup_time
        print "get_label:", "avg", avg_get_label_time / float(
            i + 1), "last", get_label_time
        print "conversion: avg", avg_conversion_time / float(
            i + 1), "last", conversion_time
        print "write: avg", avg_write_time / float(i + 1), "last", write_time
        output_buffer.dump(True)
        input_testbench.dump()
        serializer_testbench.dump()
        deserializer_testbench.dump()
        input_buffer.dump()
        integration_testbench.dump()
コード例 #2
0
def main():
    vhdl_dict = VHDLConstantsParser.parse_vhdl_file("data/ugmt_constants.vhd")

    opts = parse_options()
    fname_dict = discover_emu_files(opts.emudirectory)
    # rankLUT = l1t.MicroGMTRankPtQualLUT()

    for pattern, fnames in fname_dict.iteritems():
        print "+"*30, pattern, "+"*30
        events = Events(fnames['root'])

        start = time.time()

        tower_indices = None
        if 'idebug' in fnames.keys():
            debug_fname = fnames['idebug']
            with open(debug_fname, 'r') as fobj:
                tower_indices = [[int(idx.strip()) for idx in l.split()] for l in fobj]

        out_handle = Handle('BXVector<l1t::Muon>')
        imd_bmtf_handle = Handle('BXVector<l1t::Muon>')
        imd_emtf_p_handle = Handle('BXVector<l1t::Muon>')
        imd_emtf_n_handle = Handle('BXVector<l1t::Muon>')
        imd_omtf_p_handle = Handle('BXVector<l1t::Muon>')
        imd_omtf_n_handle = Handle('BXVector<l1t::Muon>')
        bar_handle = Handle('std::vector<l1t::L1TRegionalMuonCandidate>')
        fwd_handle = Handle('std::vector<l1t::L1TRegionalMuonCandidate>')
        ovl_handle = Handle('std::vector<l1t::L1TRegionalMuonCandidate>')
        calo_handle = Handle('std::vector<l1t::L1TGMTInputCaloSum>')

        basedir_testbench = "data/patterns/testbench/"
        basedir_mp7 = "data/patterns/mp7/"

        input_buffer = PatternDumper(basedir_mp7+pattern+".txt", vhdl_dict, BufferWriter)
        output_buffer = PatternDumper(basedir_mp7+pattern+"_out.txt", vhdl_dict, BufferWriter)
        input_testbench = PatternDumper(basedir_testbench+pattern+".txt", vhdl_dict, TestbenchWriter)
        serializer_testbench = PatternDumper(basedir_testbench+"serializer_"+pattern+".txt", vhdl_dict, TestbenchWriter)
        deserializer_testbench = PatternDumper(basedir_testbench+"deserializer_"+pattern+".txt", vhdl_dict, TestbenchWriter)
        integration_testbench = PatternDumper(basedir_testbench+"integration_"+pattern+".txt", vhdl_dict, TestbenchWriter)

        if opts.delay > 0:
            input_buffer.writeEmptyFrames(opts.delay)

        setup_time = time.time() - start

        avg_get_label_time = 0
        avg_conversion_time = 0
        avg_write_time = 0
        n_twrs = 0
        for i, event in enumerate(events):
            evt_start = time.time()
            event_head = "#"*80+"\n"
            event_head += "# Event: {ievent}\n".format(ievent=i)
            event_head += "#"*80+"\n"
            input_testbench.addLine(event_head)
            serializer_testbench.addLine(event_head)
            deserializer_testbench.addLine(event_head)
            integration_testbench.addLine(event_head)

            event.getByLabel("microGMTEmulator", out_handle)
            event.getByLabel("microGMTEmulator", "imdMuonsBMTF", imd_bmtf_handle)
            event.getByLabel("microGMTEmulator", "imdMuonsEMTFPos", imd_emtf_p_handle)
            event.getByLabel("microGMTEmulator", "imdMuonsEMTFNeg", imd_emtf_n_handle)
            event.getByLabel("microGMTEmulator", "imdMuonsOMTFPos", imd_omtf_p_handle)
            event.getByLabel("microGMTEmulator", "imdMuonsOMTFNeg", imd_omtf_n_handle)
            event.getByLabel("uGMTInputProducer", "BarrelTFMuons", bar_handle)
            event.getByLabel("uGMTInputProducer", "ForwardTFMuons", fwd_handle)
            event.getByLabel("uGMTInputProducer", "OverlapTFMuons", ovl_handle)

            event.getByLabel("uGMTInputProducer", "TriggerTowerSums", calo_handle)
            get_label_time = time.time() - evt_start
            calo_sums_raw = calo_handle.product()
            calo_sums = get_calo_list(calo_sums_raw)

            emu_out_muons = out_handle.product()
            outmuons = get_muon_list_out(emu_out_muons, "OUT", vhdl_dict)
            imd_emtf_p_prod = imd_emtf_p_handle.product()
            imdmuons = get_muon_list_out(imd_emtf_p_prod, "IMD", vhdl_dict, 4)
            imd_omtf_p_prod = imd_omtf_p_handle.product()
            imdmuons += get_muon_list_out(imd_omtf_p_prod, "IMD", vhdl_dict, 4)
            imd_bmtf_prod = imd_bmtf_handle.product()
            imdmuons += get_muon_list_out(imd_bmtf_prod, "IMD", vhdl_dict, 8)
            imd_omtf_n_prod = imd_omtf_n_handle.product()
            imdmuons += get_muon_list_out(imd_omtf_n_prod, "IMD", vhdl_dict, 4)
            imd_emtf_n_prod = imd_emtf_n_handle.product()
            imdmuons += get_muon_list_out(imd_emtf_n_prod, "IMD", vhdl_dict, 4)

            emu_bar_muons = bar_handle.product()
            bar_muons = get_muon_list(emu_bar_muons, "BMTF", vhdl_dict, i)
            emu_ovl_muons = ovl_handle.product()
            ovlp_muons = get_muon_list(emu_ovl_muons, "OMTF_POS", vhdl_dict, i)
            ovln_muons = get_muon_list(emu_ovl_muons, "OMTF_NEG", vhdl_dict, i)
            emu_fwd_muons = fwd_handle.product()
            fwdp_muons = get_muon_list(emu_fwd_muons, "EMTF_POS", vhdl_dict, i)
            fwdn_muons = get_muon_list(emu_fwd_muons, "EMTF_NEG", vhdl_dict, i)

            conversion_time = time.time() - evt_start - get_label_time
            input_buffer.writeFrameBasedInputBX(bar_muons, fwdp_muons, fwdn_muons, ovlp_muons, ovln_muons, calo_sums)
            integration_testbench.writeFrameBasedInputBX(bar_muons, fwdp_muons, fwdn_muons, ovlp_muons, ovln_muons, calo_sums)
            deserializer_testbench.writeFrameBasedInputBX(bar_muons, fwdp_muons, fwdn_muons, ovlp_muons, ovln_muons, calo_sums)
            output_buffer.writeFrameBasedOutputBX(outmuons, imdmuons)

            input_testbench.writeMuonBasedInputBX(bar_muons, fwdp_muons, fwdn_muons, ovlp_muons, ovln_muons, calosums=calo_sums, addTracks=True)
            input_testbench.addLine("# Expected emulator output\n")
            input_testbench.writeMuonBasedOutputBX(outmuons, imdmuons)
            deserializer_testbench.addLine("# Expected emulator output\n")
            deserializer_testbench.writeMuonBasedInputBX(bar_muons, fwdp_muons, fwdn_muons, ovlp_muons, ovln_muons, calosums=calo_sums, addTracks=True)
            if tower_indices is not None:
                input_testbench.addLine("# Tower indices:\n")
                cntr = 0
                for mu in outmuons:
                    if mu.bitword != 0:
                        cntr += 1
                input_testbench.writeTowerIndices(tower_indices[n_twrs:n_twrs+cntr])
                n_twrs += cntr

            serializer_testbench.writeMuonBasedOutputBX(outmuons, imdmuons)
            serializer_testbench.addLine("# Expected emulator output\n")
            serializer_testbench.writeFrameBasedOutputBX(outmuons, imdmuons)
            integration_testbench.addLine("# Expected emulator output\n")
            integration_testbench.writeFrameBasedOutputBX(outmuons, imdmuons)
            write_time = time.time() - evt_start - conversion_time
            avg_get_label_time += get_label_time
            avg_conversion_time += conversion_time
            avg_write_time += write_time
        print "total: ", time.time() - start
        print "setup: ", setup_time
        print "get_label:", "avg", avg_get_label_time/float(i+1), "last", get_label_time
        print "conversion: avg", avg_conversion_time/float(i+1), "last", conversion_time
        print "write: avg", avg_write_time/float(i+1), "last", write_time
        output_buffer.dump(True)
        input_testbench.dump()
        serializer_testbench.dump()
        deserializer_testbench.dump()
        input_buffer.dump()
        integration_testbench.dump()
コード例 #3
0
def main():
    vhdl_dict = VHDLConstantsParser.parse_vhdl_file(
        "../data/ugmt_constants.vhd")

    opts = parse_options()
    nSkip = opts.skip
    fname_dict = discover_emu_files(opts.emudirectory)
    # rankLUT = l1t.MicroGMTRankPtQualLUT()

    ALGODELAY = opts.delay + 27  #first frame with valid = 1

    max_events = int((1024 - ALGODELAY) / 6)

    for pattern, fnames in fname_dict.iteritems():
        print "+" * 30, pattern, "+" * 30
        events = Events(fnames['root'])

        start = time.time()

        out_handle = Handle('BXVector<l1t::Muon>')
        imd_bmtf_handle = Handle('BXVector<l1t::Muon>')
        imd_emtf_p_handle = Handle('BXVector<l1t::Muon>')
        imd_emtf_n_handle = Handle('BXVector<l1t::Muon>')
        imd_omtf_p_handle = Handle('BXVector<l1t::Muon>')
        imd_omtf_n_handle = Handle('BXVector<l1t::Muon>')
        bar_handle = Handle('BXVector<l1t::RegionalMuonCand>')
        fwd_handle = Handle('BXVector<l1t::RegionalMuonCand>')
        ovl_handle = Handle('BXVector<l1t::RegionalMuonCand>')
        calo_handle = Handle('BXVector<l1t::MuonCaloSum>')

        basedir_mp7 = "../data/patterns/compressed/"
        path = '{path}/{pattern}/'.format(path=basedir_mp7, pattern=pattern)

        input_buffer = PatternDumper(path + pattern + ".txt", vhdl_dict,
                                     BufferWriter)
        output_buffer = PatternDumper(path + pattern + "_out.txt", vhdl_dict,
                                      BufferWriter)

        if opts.delay > 0:
            input_buffer.writeEmptyFrames(opts.delay)

        setup_time = time.time() - start

        avg_get_label_time = 0
        avg_conversion_time = 0
        avg_write_time = 0

        output_buffer.writeEmptyFrames(ALGODELAY)
        cntr = 0
        for i, event in enumerate(events):
            if i < nSkip:
                continue

            #print 'event: {evt} {evNr}'.format(evt=i, evNr=event.eventAuxiliary().event())

            evt_start = time.time()
            event.getByLabel("simGmtStage2Digis", out_handle)
            event.getByLabel("simGmtStage2Digis", "imdMuonsBMTF",
                             imd_bmtf_handle)
            event.getByLabel("simGmtStage2Digis", "imdMuonsEMTFPos",
                             imd_emtf_p_handle)
            event.getByLabel("simGmtStage2Digis", "imdMuonsEMTFNeg",
                             imd_emtf_n_handle)
            event.getByLabel("simGmtStage2Digis", "imdMuonsOMTFPos",
                             imd_omtf_p_handle)
            event.getByLabel("simGmtStage2Digis", "imdMuonsOMTFNeg",
                             imd_omtf_n_handle)
            event.getByLabel("simBmtfDigis", "BMTF", bar_handle)
            event.getByLabel("simEmtfDigis", "EMTF", fwd_handle)
            event.getByLabel("simOmtfDigis", "OMTF", ovl_handle)
            #event.getByLabel("gmtStage2Digis", "BMTF", bar_handle)
            #event.getByLabel("gmtStage2Digis", "EMTF", fwd_handle)
            #event.getByLabel("gmtStage2Digis", "OMTF", ovl_handle)

            event.getByLabel("simGmtCaloSumDigis", "TriggerTowerSums",
                             calo_handle)
            #event.getByLabel("emptyCaloCollsProducer", "EmptyTriggerTowerSums", calo_handle)
            #event.getByLabel("simGmtCaloSumDigis", "TriggerTower2x2s", calo_handle)
            get_label_time = time.time() - evt_start
            calo_sums_raw = calo_handle.product()
            calo_sums = get_calo_list(calo_sums_raw)

            emu_out_muons = out_handle.product()
            outmuons = get_muon_list_out(emu_out_muons, "OUT", vhdl_dict)
            imd_emtf_p_prod = imd_emtf_p_handle.product()
            imdmuons = get_muon_list_out(imd_emtf_p_prod, "IMD", vhdl_dict, 4)
            imd_omtf_p_prod = imd_omtf_p_handle.product()
            imdmuons += get_muon_list_out(imd_omtf_p_prod, "IMD", vhdl_dict, 4)
            imd_bmtf_prod = imd_bmtf_handle.product()
            imdmuons += get_muon_list_out(imd_bmtf_prod, "IMD", vhdl_dict, 8)
            imd_omtf_n_prod = imd_omtf_n_handle.product()
            imdmuons += get_muon_list_out(imd_omtf_n_prod, "IMD", vhdl_dict, 4)
            imd_emtf_n_prod = imd_emtf_n_handle.product()
            imdmuons += get_muon_list_out(imd_emtf_n_prod, "IMD", vhdl_dict, 4)

            emu_bar_muons = bar_handle.product()
            bar_muons = get_muon_list(emu_bar_muons, "BMTF", vhdl_dict, i)
            emu_ovl_muons = ovl_handle.product()
            ovlp_muons = get_muon_list(emu_ovl_muons, "OMTF_POS", vhdl_dict, i)
            ovln_muons = get_muon_list(emu_ovl_muons, "OMTF_NEG", vhdl_dict, i)
            emu_fwd_muons = fwd_handle.product()
            fwdp_muons = get_muon_list(emu_fwd_muons, "EMTF_POS", vhdl_dict, i)
            fwdn_muons = get_muon_list(emu_fwd_muons, "EMTF_NEG", vhdl_dict, i)

            conversion_time = time.time() - evt_start - get_label_time

            for mu in outmuons:
                if mu.bitword != 0:
                    cntr += 1
            input_buffer.writeFrameBasedInputBX(bar_muons, fwdp_muons,
                                                fwdn_muons, ovlp_muons,
                                                ovln_muons, calo_sums)
            output_buffer.writeFrameBasedOutputBX(outmuons, imdmuons)

            if i % (max_events - 1) == 0 and i != 0:  # dump every max_events
                ifile = i / max_events
                print "Writing file {pattern}_{ifile}.zip for event {i}".format(
                    pattern=pattern, ifile=ifile, i=i)
                dump_files(path, pattern, ifile, input_buffer, output_buffer,
                           opts.delay, ALGODELAY)

            if (i + 1) % 1000 == 0:
                print "  processing the {i}th event".format(i=i + 1)

            write_time = time.time() - evt_start - conversion_time
            avg_get_label_time += get_label_time
            avg_conversion_time += conversion_time
            avg_write_time += write_time
        print "total: ", time.time() - start
        print "setup: ", setup_time
        print "get_label:", "avg", avg_get_label_time / float(
            i + 1), "last", get_label_time
        print "conversion: avg", avg_conversion_time / float(
            i + 1), "last", conversion_time
        print "write: avg", avg_write_time / float(i + 1), "last", write_time
        print 'n final muons: ', cntr
        if i % (max_events - 1) != 0:
            ifile = i / max_events
            dump_files(path, pattern, ifile, input_buffer, output_buffer,
                       opts.delay, ALGODELAY)

        print(i + 1) / max_events
コード例 #4
0
def main():
    vhdl_dict = VHDLConstantsParser.parse_vhdl_file("../data/ugmt_constants.vhd")

    opts = parse_options()
    fname_dict = discover_emu_files(opts.emudirectory)
    # rankLUT = l1t.MicroGMTRankPtQualLUT()

    ALGODELAY = opts.delay + 25 #first frame with valid = 1

    max_events = int((1024-ALGODELAY)/6)

    for pattern, fnames in fname_dict.iteritems():
        print "+"*30, pattern, "+"*30
        events = Events(fnames['root'])

        start = time.time()

        out_handle = Handle('BXVector<l1t::Muon>')
        imd_bmtf_handle = Handle('BXVector<l1t::Muon>')
        imd_emtf_p_handle = Handle('BXVector<l1t::Muon>')
        imd_emtf_n_handle = Handle('BXVector<l1t::Muon>')
        imd_omtf_p_handle = Handle('BXVector<l1t::Muon>')
        imd_omtf_n_handle = Handle('BXVector<l1t::Muon>')
        bar_handle = Handle('BXVector<l1t::RegionalMuonCand>')
        fwd_handle = Handle('BXVector<l1t::RegionalMuonCand>')
        ovl_handle = Handle('BXVector<l1t::RegionalMuonCand>')
        calo_handle = Handle('BXVector<l1t::MuonCaloSum>')

        basedir_mp7 = "../data/patterns/compressed/"
        path = '{path}/{pattern}/'.format(path=basedir_mp7, pattern=pattern)

        input_buffer = PatternDumper(basedir_mp7+pattern+".txt", vhdl_dict, BufferWriter)
        output_buffer = PatternDumper(basedir_mp7+pattern+"_out.txt", vhdl_dict, BufferWriter)

        if opts.delay > 0:
            input_buffer.writeEmptyFrames(opts.delay)

        setup_time = time.time() - start

        avg_get_label_time = 0
        avg_conversion_time = 0
        avg_write_time = 0

        output_buffer.writeEmptyFrames(ALGODELAY)
        cntr = 0
        for i, event in enumerate(events):
            evt_start = time.time()
            event.getByLabel("simGmtStage2Digis", out_handle)
            event.getByLabel("simGmtStage2Digis", "imdMuonsBMTF", imd_bmtf_handle)
            event.getByLabel("simGmtStage2Digis", "imdMuonsEMTFPos", imd_emtf_p_handle)
            event.getByLabel("simGmtStage2Digis", "imdMuonsEMTFNeg", imd_emtf_n_handle)
            event.getByLabel("simGmtStage2Digis", "imdMuonsOMTFPos", imd_omtf_p_handle)
            event.getByLabel("simGmtStage2Digis", "imdMuonsOMTFNeg", imd_omtf_n_handle)
            #event.getByLabel("simBmtfDigis", "BMTF", bar_handle)
            #event.getByLabel("simEmtfDigis", "EMTF", fwd_handle)
            #event.getByLabel("simOmtfDigis", "OMTF", ovl_handle)
            event.getByLabel("gmtStage2Digis", "BMTF", bar_handle)
            event.getByLabel("gmtStage2Digis", "EMTF", fwd_handle)
            event.getByLabel("gmtStage2Digis", "OMTF", ovl_handle)

            #event.getByLabel("simGmtCaloSumDigis", "TriggerTowerSums", calo_handle)
            event.getByLabel("emptyCaloCollsProducer", "EmptyTriggerTowerSums", calo_handle)
            #event.getByLabel("simGmtCaloSumDigis", "TriggerTower2x2s", calo_handle)
            get_label_time = time.time() - evt_start
            calo_sums_raw = calo_handle.product()
            calo_sums = get_calo_list(calo_sums_raw)

            emu_out_muons = out_handle.product()
            outmuons = get_muon_list_out(emu_out_muons, "OUT", vhdl_dict)
            imd_emtf_p_prod = imd_emtf_p_handle.product()
            imdmuons = get_muon_list_out(imd_emtf_p_prod, "IMD", vhdl_dict, 4)
            imd_omtf_p_prod = imd_omtf_p_handle.product()
            imdmuons += get_muon_list_out(imd_omtf_p_prod, "IMD", vhdl_dict, 4)
            imd_bmtf_prod = imd_bmtf_handle.product()
            imdmuons += get_muon_list_out(imd_bmtf_prod, "IMD", vhdl_dict, 8)
            imd_omtf_n_prod = imd_omtf_n_handle.product()
            imdmuons += get_muon_list_out(imd_omtf_n_prod, "IMD", vhdl_dict, 4)
            imd_emtf_n_prod = imd_emtf_n_handle.product()
            imdmuons += get_muon_list_out(imd_emtf_n_prod, "IMD", vhdl_dict, 4)

            emu_bar_muons = bar_handle.product()
            bar_muons = get_muon_list(emu_bar_muons, "BMTF", vhdl_dict, i)
            emu_ovl_muons = ovl_handle.product()
            ovlp_muons = get_muon_list(emu_ovl_muons, "OMTF_POS", vhdl_dict, i)
            ovln_muons = get_muon_list(emu_ovl_muons, "OMTF_NEG", vhdl_dict, i)
            emu_fwd_muons = fwd_handle.product()
            fwdp_muons = get_muon_list(emu_fwd_muons, "EMTF_POS", vhdl_dict, i)
            fwdn_muons = get_muon_list(emu_fwd_muons, "EMTF_NEG", vhdl_dict, i)

            conversion_time = time.time() - evt_start - get_label_time

            for mu in outmuons:
                if mu.bitword != 0:
                    cntr += 1
            input_buffer.writeFrameBasedInputBX(bar_muons, fwdp_muons, fwdn_muons, ovlp_muons, ovln_muons, calo_sums)
            output_buffer.writeFrameBasedOutputBX(outmuons, imdmuons)

            if i%(max_events-1) == 0 and i != 0: # dump every max_events
                ifile = i/max_events
                print "Writing file {pattern}_{ifile}.zip for event {i}".format(pattern=pattern, ifile=ifile, i=i)
                dump_files(path, pattern, ifile, input_buffer, output_buffer, opts.delay, ALGODELAY)


            if (i+1)%1000 == 0:
                print "  processing the {i}th event".format(i=i+1)

            write_time = time.time() - evt_start - conversion_time
            avg_get_label_time += get_label_time
            avg_conversion_time += conversion_time
            avg_write_time += write_time
        print "total: ", time.time() - start
        print "setup: ", setup_time
        print "get_label:", "avg", avg_get_label_time/float(i+1), "last", get_label_time
        print "conversion: avg", avg_conversion_time/float(i+1), "last", conversion_time
        print "write: avg", avg_write_time/float(i+1), "last", write_time
        print 'n final muons: ', cntr
        if i%(max_events-1) != 0:
            ifile = i/max_events
            dump_files(path, pattern, ifile, input_buffer, output_buffer, opts.delay, ALGODELAY)

        print (i+1)/max_events
コード例 #5
0
def main():
    vhdl_dict = VHDLConstantsParser.parse_vhdl_file("../data/ugmt_constants.vhd")

    opts = parse_options()
    fname_dict = discover_emu_files(opts.emudirectory)

    ALGODELAY = 60 #first frame with valid = 1

    max_events = int((1024-ALGODELAY)/6)

    for pattern, fnames in fname_dict.iteritems():

        print "+"*30, pattern, "+"*30
        events = Events(fnames['root'])

        out_handle = Handle('BXVector<l1t::Muon>')
        imd_handle = Handle('BXVector<l1t::Muon>')
        bar_handle = Handle('std::vector<l1t::L1TRegionalMuonCandidate>')
        fwd_handle = Handle('std::vector<l1t::L1TRegionalMuonCandidate>')
        ovl_handle = Handle('std::vector<l1t::L1TRegionalMuonCandidate>')

        calo_handle = Handle('std::vector<l1t::L1TGMTInputCaloSum>')

        basedir_mp7 = "patterns/compressed/"
        path = '{path}/{pattern}/'.format(path=basedir_mp7, pattern=pattern)

        input_buffer = PatternDumper(basedir_mp7+pattern+".txt", vhdl_dict, BufferWriter)
        output_buffer = PatternDumper(basedir_mp7+pattern+"_out.txt", vhdl_dict, BufferWriter)

        if opts.delay > 0:
            input_buffer.writeEmptyFrames(opts.delay)

        output_buffer.writeEmptyFrames(ALGODELAY)
        cntr = 0
        for i, event in enumerate(events):
            event.getByLabel("microGMTEmulator", out_handle)
            event.getByLabel("microGMTEmulator", "intermediateMuons", imd_handle)
            event.getByLabel("uGMTInputProducer", "BarrelTFMuons", bar_handle)
            event.getByLabel("uGMTInputProducer", "ForwardTFMuons", fwd_handle)
            event.getByLabel("uGMTInputProducer", "OverlapTFMuons", ovl_handle)

            event.getByLabel("uGMTInputProducer", "TriggerTowerSums", calo_handle)

            calo_sums_raw = calo_handle.product()
            calo_sums = get_calo_list(calo_sums_raw)

            emu_out_muons = out_handle.product()
            outmuons = get_muon_list_out(emu_out_muons, "OUT", vhdl_dict)
            imd_prod = imd_handle.product()
            imdmuons = get_muon_list_out(imd_prod, "IMD", vhdl_dict)
            emu_bar_muons = bar_handle.product()
            bar_muons = get_muon_list(emu_bar_muons, "BMTF", vhdl_dict)
            emu_ovl_muons = ovl_handle.product()
            ovlp_muons = get_muon_list(emu_ovl_muons, "OMTF_POS", vhdl_dict)
            ovln_muons = get_muon_list(emu_ovl_muons, "OMTF_NEG", vhdl_dict)
            emu_fwd_muons = fwd_handle.product()
            fwdp_muons = get_muon_list(emu_fwd_muons, "EMTF_POS", vhdl_dict)
            fwdn_muons = get_muon_list(emu_fwd_muons, "EMTF_NEG", vhdl_dict)
            for mu in outmuons:
                if mu.bitword != 0: cntr += 1
            input_buffer.writeFrameBasedInputBX(bar_muons, fwdp_muons, fwdn_muons, ovlp_muons, ovln_muons, calo_sums)
            output_buffer.writeFrameBasedOutputBX(outmuons, imdmuons)

            if i%(max_events-1) == 0 and i != 0: # dump every max_events
                ifile = i/max_events
                print "Writing file {pattern}_{ifile}.zip for event {i}".format(pattern=pattern, ifile=ifile, i=i)
                dump_files(path, pattern, ifile, input_buffer, output_buffer, opts.delay, ALGODELAY)


            if (i+1)%1000 == 0:
                print "  processing the {i}th event".format(i=i+1)
        print 'n final muons: ', cntr
        if i%(max_events-1) != 0:
            ifile = i/max_events
            dump_files(path, pattern, ifile, input_buffer, output_buffer, opts.delay, ALGODELAY)

        print (i+1)/max_events