def main(): _log = log.init_logging("main") vhdl_dict = VHDLConstantsParser.parse_vhdl_file("data/ugmt_constants.vhd") basedir_testbench = "data/patterns/emu/" rankLUT = l1t.MicroGMTRankPtQualLUT() options = parse_options() file_dict = discover_files(options) for pattern, fnames in file_dict.iteritems(): _log.info("{patt:+^90}".format(patt=pattern)) _log.info("{info:>90}".format(info="HW PARSING")) # Reading and processing the hardware data input_parser = InputBufferParser(fnames["rx"], vhdl_dict) in_muons = input_parser.get_input_muons() input_testbench = PatternDumper(basedir_testbench + pattern + ".txt", vhdl_dict, TestbenchWriter) offset = 36 fwdp_range = range(offset + vhdl_dict["FWD_POS_LOW"], offset + vhdl_dict["FWD_POS_HIGH"]) fwdn_range = range(offset + vhdl_dict["FWD_NEG_LOW"], offset + vhdl_dict["FWD_NEG_HIGH"]) bar_range = range(offset + vhdl_dict["BARREL_LOW"], offset + vhdl_dict["BARREL_HIGH"]) ovlp_range = range(offset + vhdl_dict["OVL_POS_LOW"], offset + vhdl_dict["OVL_POS_HIGH"]) ovln_range = range(offset + vhdl_dict["OVL_NEG_LOW"], offset + vhdl_dict["OVL_NEG_HIGH"]) while len(in_muons) > 0: bar_muons = [] ovlp_muons = [] ovln_muons = [] fwdp_muons = [] fwdn_muons = [] for i in range(108): mu = in_muons[0] if mu.link in fwdp_range: fwdp_muons.append(mu) if mu.link in fwdn_range: fwdn_muons.append(mu) if mu.link in ovlp_range: ovlp_muons.append(mu) if mu.link in ovln_range: ovln_muons.append(mu) if mu.link in bar_range: bar_muons.append(mu) del in_muons[0] input_testbench.writeMuonBasedInputBX(bar_muons, fwdp_muons, fwdn_muons, ovlp_muons, ovln_muons, [], rankLUT, False, True) input_testbench.dump()
print '-'*40 print 'MP7 muon input conversion script' print '-'*40 #test(8); test(9); test(2); test(10) frames = [] for i in xrange(72): frames.append([]) # convert this to commandline option together with out file infile = open(opts.infile, "r") outfile = open(opts.outfile, "w") cfg = VHDLConstantsParser.parse_vhdl_file(opts.config) print cfg newEvt = False evts = 0 counters_tot = { "brl" : 0, "fwd_pos" : 0, "fwd_neg" : 0, "ovl_pos" : 0, "ovl_neg" : 0, "calo": 0 } counters = counters_tot.copy() frames_string = "" cur_frames = {}
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()
def main(): opts = parse_options() file_list_rx = [] file_list_tx = [] pattern_name = "" for root, dirs, files in os.walk(opts.directory): for fname in files: if fname.startswith('tx_') and fname.endswith('.zip'): # strip leading tx_ and _<i>.zip pattern_name = fname[3:-6] file_list_tx.append(root + fname) if fname.startswith('rx_') and fname.endswith('.zip'): file_list_rx.append(root + fname) known_responses = [] if opts.testpath != '': for root, dirs, files in os.walk(opts.testpath): for fname in files: if fname.startswith('tx_'): known_responses.append(root + fname) # this should make them synchronised file_list_rx.sort() file_list_tx.sort() known_responses.sort() if len(file_list_rx) != len(file_list_tx): print "Number of RX and TX files not the same!" return print "-" * 30, pattern_name, "-" * 30 print "Starting test: A total of {i} files will be fed into the algorithm".format( i=len(file_list_rx)) log = open('{pattern}.log'.format(pattern=pattern_name), 'w') vhdl_cfg = VHDLConstantsParser.parse_vhdl_file("data/ugmt_constants.vhd") analyser = Analyser('tx_tmp.txt', 'tmp/tx_summary.txt', vhdl_cfg) for i in range(len(file_list_rx)): cmp_rx = file_list_rx[i] cmp_tx = file_list_tx[i] rx_tmp_name = 'rx_tmp.txt' tx_tmp_name = 'tx_tmp.txt' decompress(rx_tmp_name, cmp_rx) decompress(tx_tmp_name, cmp_tx) cap_lines = [] if opts.testpath == '': butler_out = '' if opts.p5: butlerError = subprocess.call([ 'mp7butler.py', '-c', opts.connections_file, 'buffers', opts.boardname, 'algoPlay', '--inject', 'file://{fname}'.format(fname=rx_tmp_name), '-e', '36-71' ]) butlerError += subprocess.call([ 'mp7butler.py', '-c', opts.connections_file, 'buffers', opts.boardname, 'algoPlay', '--inject', 'file://{fname}'.format(fname=rx_tmp_name), '-e', '0-35', '--play', '{delay}'.format(delay=opts.en_delay) ]) if butlerError != 0: print " errors in mp7_butler: " + str(butlerError) return else: try: subprocess.check_output([ 'mp7butler.py', '-c', opts.connections_file, 'buffers', opts.boardname, 'algoPlay', '--inject', 'file://{fname}'.format(fname=rx_tmp_name), '-e', '36-71' ]) subprocess.check_output([ 'mp7butler.py', '-c', opts.connections_file, 'buffers', opts.boardname, 'algoPlay', '--inject', 'file://{fname}'.format(fname=rx_tmp_name), '-e', '0-35', '--play', '{delay}'.format(delay=opts.en_delay) ]) except subprocess.CalledProcessError as e: print " errors in mp7_butler: " + str(e) return log.write(butler_out) time.sleep(1) if opts.p5: butlerError = subprocess.call([ 'mp7butler.py', '-c', opts.connections_file, 'capture', opts.boardname, '--outputpath', 'tmp' ]) if butlerError != 0: print " errors in mp7_butler: " + str(e) return else: try: subprocess.check_output([ 'mp7butler.py', '-c', opts.connections_file, 'capture', opts.boardname, '--outputpath', 'tmp' ]) except subprocess.CalledProcessError as e: print " errors in mp7_butler: " + str(e) return log.write(butler_out) cap_lines = [] with open('tmp/tx_summary.txt', 'r') as cap: cap_lines = cap.readlines() # if opts.dump: # with open(opts.outpath+'/tx_summary_{x}.txt'.format(x=i), 'w') as ofile: # for lin in cap_lines: # ofile.write(lin) # if opts.dump: # with open('tmp/rx_summary.txt', 'r') as cap: # with open(opts.outpath+'/rx_summary_{x}.txt'.format(x=i), 'w') as ofile: # ofile.write(cap.read()) else: with open(known_responses[i], 'r') as cap: cap_lines = cap.readlines() analyser.hwfname = known_responses[i] # quick analysis whether the tx buffers are the same emu_lines = [] with open(tx_tmp_name, 'r') as emu: emu_lines = emu.readlines() diff = difflib.context_diff(emu_lines, cap_lines) have_errors = False for d in diff: if d.startswith("***************"): have_errors = True break # if they are not: do detailed analysis if have_errors: analyser.analyse(i) # print summary and write details to log analyser.print_out(pattern_name, log) log.close()
instance_string = instance_string + '" AREA_GROUP=quad_' instance_string = instance_string + str(area_group) instance_string = instance_string + ';' return instance_string _log = log.init_logging("ucf_serdes_constraints_generator") if __name__ == "__main__": # initialize command line input opts, args = parse_options() # set verbosity according to option log.set_level(opts.verbosity) _log.debug("*" * 40) _log.info(" UCF Serdes constraints generator") _log.info("*" * 40) _log.info("Paste the following into your ucf file:") config_dict = VHDLConstantsParser.parse_vhdl_file(opts.files[0]) quad_dict = get_quad_areagroup_mapping(opts.files[1]) for key in sorted(config_dict): if "MU_QUAD_ASSIGNMENT" in key: for i in range(len(config_dict[key])): print generate_instance_string( "MU", i, quad_dict[str(config_dict[key][i])]) if "ENERGY_QUAD_ASSIGNMENT" in key: for i in range(len(config_dict[key])): print generate_instance_string( "CALO", i, quad_dict[str(config_dict[key][i])])
def main(): opts = parse_options() file_list_rx = [] file_list_tx = [] pattern_name = "" for root, dirs, files in os.walk(opts.directory): for fname in files: if fname.startswith('tx_') and fname.endswith('.zip'): # strip leading tx_ and _<i>.zip pattern_name = fname[3:-6] file_list_tx.append(root+fname) if fname.startswith('rx_') and fname.endswith('.zip'): file_list_rx.append(root+fname) known_responses = [] if opts.testpath != '': for root, dirs, files in os.walk(opts.testpath): for fname in files: if fname.startswith('tx_'): known_responses.append(root+fname) # this should make them synchronised file_list_rx.sort(); file_list_tx.sort(); known_responses.sort() if len(file_list_rx) != len(file_list_tx): print "Number of RX and TX files not the same!" return print "-"*30, pattern_name, "-"*30 print "Starting test: A total of {i} files will be fed into the algorithm".format(i=len(file_list_rx)) log = open('{pattern}.log'.format(pattern=pattern_name), 'w') vhdl_cfg = VHDLConstantsParser.parse_vhdl_file("data/ugmt_constants.vhd") analyser = Analyser('tx_tmp.txt', 'tmp/tx_summary.txt', vhdl_cfg) for i in range(len(file_list_rx)): cmp_rx = file_list_rx[i] cmp_tx = file_list_tx[i] rx_tmp_name = 'rx_tmp.txt' tx_tmp_name = 'tx_tmp.txt' decompress(rx_tmp_name, cmp_rx) decompress(tx_tmp_name, cmp_tx) cap_lines = [] if opts.testpath == '': butler_out = '' butlerError = subprocess.call(['mp7butler.py', 'buffers', opts.boardname, 'algoPlay', '--inject', 'file://{fname}'.format(fname=rx_tmp_name), '-e 36-71']) butlerError = subprocess.call(['mp7butler.py', 'buffers', opts.boardname, 'algoPlay', '--inject', 'file://{fname}'.format(fname=rx_tmp_name), '-e 0-35', '--play {delay}'.format(delay=opts.en_delay)]) if butlerError != 0: print " errors in mp7_butler: "+str(butlerError) return log.write(butler_out) time.sleep(1) butlerError = subprocess.call(['mp7butler.py', 'capture', opts.boardname, '--outputpath', 'tmp']) if butlerError != 0: print " errors in mp7_butler: "+str(e) return log.write(butler_out) cap_lines = [] with open('tmp/tx_summary.txt', 'r') as cap: cap_lines = cap.readlines() # if opts.dump: # with open(opts.outpath+'/tx_summary_{x}.txt'.format(x=i), 'w') as ofile: # for lin in cap_lines: # ofile.write(lin) # if opts.dump: # with open('tmp/rx_summary.txt', 'r') as cap: # with open(opts.outpath+'/rx_summary_{x}.txt'.format(x=i), 'w') as ofile: # ofile.write(cap.read()) else: with open(known_responses[i], 'r') as cap: cap_lines = cap.readlines() analyser.hwfname = known_responses[i] # quick analysis whether the tx buffers are the same emu_lines = [] with open(tx_tmp_name, 'r') as emu: emu_lines = emu.readlines() diff = difflib.context_diff(emu_lines, cap_lines) have_errors = False for d in diff: if d.startswith("***************"): have_errors = True break # if they are not: do detailed analysis if have_errors: analyser.analyse(i) # print summary and write details to log analyser.print_out(pattern_name, log) log.close()
in_match_dict[mu_out] = [0, None] for mu_in in inmus: relation = calculate_relation(mu_in, mu_out) if in_match_dict[mu_out][0] < relation: in_match_dict[mu_out] = [relation, mu_in] imd_match_dict[mu_out] = [0, None] for idx, mu_imd in enumerate(imdmus): relation = calculate_relation(mu_imd, mu_out) #if relation isn't just random, put it in the dict if imd_match_dict[mu_out][0] < relation and relation > 19: imd_match_dict[mu_out] = [relation, mu_imd] return in_match_dict, imd_match_dict if __name__ == "__main__": vhdl_dict = VHDLConstantsParser.parse_vhdl_file("data/ugmt_constants.vhd") options = parse_options() file_dict = discover_files(options) for pattern, fnames in file_dict.iteritems(): version = Version.from_filename(fnames['rx']) print "+"*30, pattern, "+"*30 # Reading and processing the hardware data input_parser = InputBufferParser(fnames['rx'], vhdl_dict) output_parser = OutputBufferParser(fnames['tx'], vhdl_dict, version) in_muons = input_parser.get_input_muons() out_muons = output_parser.get_output_muons() imd_muons = output_parser.get_intermediate_muons()
for mu_in in inmus: relation = calculate_relation(mu_in, mu_out) if in_match_dict[mu_out][0] < relation: in_match_dict[mu_out] = [relation, mu_in] imd_match_dict[mu_out] = [0, None] for idx, mu_imd in enumerate(imdmus): relation = calculate_relation(mu_imd, mu_out) #if relation isn't just random, put it in the dict if imd_match_dict[mu_out][0] < relation and relation > 19: imd_match_dict[mu_out] = [relation, mu_imd] return in_match_dict, imd_match_dict if __name__ == "__main__": vhdl_dict = VHDLConstantsParser.parse_vhdl_file("data/ugmt_constants.vhd") options = parse_options() file_dict = discover_files(options) for pattern, fnames in file_dict.iteritems(): version = Version.from_filename(fnames['rx']) print "+" * 30, pattern, "+" * 30 # Reading and processing the hardware data input_parser = InputBufferParser(fnames['rx'], vhdl_dict) output_parser = OutputBufferParser(fnames['tx'], vhdl_dict, version) in_muons = input_parser.get_input_muons() out_muons = output_parser.get_output_muons() imd_muons = output_parser.get_intermediate_muons()
instance_string = instance_string + '" AREA_GROUP=quad_' instance_string = instance_string + str(area_group) instance_string = instance_string + ';' return instance_string _log = log.init_logging("ucf_serdes_constraints_generator") if __name__ == "__main__": # initialize command line input opts, args = parse_options() # set verbosity according to option log.set_level(opts.verbosity) _log.debug ("*"*40) _log.info (" UCF Serdes constraints generator") _log.info ("*"*40) _log.info ("Paste the following into your ucf file:") config_dict = VHDLConstantsParser.parse_vhdl_file(opts.files[0]) quad_dict = get_quad_areagroup_mapping(opts.files[1]) for key in sorted(config_dict): if "MU_QUAD_ASSIGNMENT" in key: for i in range(len(config_dict[key])): print generate_instance_string("MU", i, quad_dict[str(config_dict[key][i])]) if "ENERGY_QUAD_ASSIGNMENT" in key: for i in range(len(config_dict[key])): print generate_instance_string("CALO", i, quad_dict[str(config_dict[key][i])])
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()
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
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
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