def printTable(rbxes={}, header="", zero=" ", onlyDet=None, excludeDet=None): if header: header = "| %s |" % header print "-" * len(header) print header print "-" * len(header) rbxList = conf.rbxes() boxes = sorted(list(set([rbx[-2:] for rbx in rbxList]))) dets = sorted(list(set([rbx[:-2] for rbx in rbxList]))) nSpaces = 5 header = " ".join(["RBX".ljust(nSpaces)] + boxes) print header print "-" * len(header) for det in dets: if onlyDet and (onlyDet not in det): continue if excludeDet and (excludeDet in det): continue row = [] for box in boxes: key = det + box nFibers = rbxes.get(key) if nFibers is None: row.append(zero) else: row.append("%2d" % nFibers) print " ".join([det.ljust(nSpaces)] + row) print
def printTable(rbxes={}, header="", zero=" "): if header: header = "| %s |" % header print "-"*len(header) print header print "-"*len(header) rbxList = conf.rbxes() boxes = sorted(list(set([rbx[-2:] for rbx in rbxList]))) dets = sorted(list(set([rbx[:-2] for rbx in rbxList]))) nSpaces = 5 header = " ".join(["RBX".ljust(nSpaces)] + boxes) print header print "-" * len(header) for det in dets: row = [] for box in boxes: key = det + box nFibers = rbxes.get(key) if nFibers is None: row.append(zero) else: row.append("%2d" % nFibers) print " ".join([det.ljust(nSpaces)] + row) print
def ngReformMap(iMapfile="", ofile="", oFileOpenMode="w", rbx_whitelist=None, h_rbx="rbx", h_rmFi="rm_fi"): valid_rbxes = rbx_whitelist if rbx_whitelist else rbxes() output = open(ofile, oFileOpenMode) #opens & write the file lines = open(iMapfile, "r").readlines() columns = lines[0].split() # BE iCrate = columns.index("crate") iSlot = columns.index("uhtr") iUf = columns.index("uhtr_fib") iFc = columns.index("fib_ch") # FE iRbx = columns.index(h_rbx) iRm = columns.index("rm") iRf = columns.index(h_rmFi) for iLine, line in enumerate(lines): if not iLine or line[0] == "#": continue fields = line.split() if fields[1] == "N/C": print "hacking line %d" % (1 + iLine) fields = fields[:3] + ["8"] + fields[3:] if len(fields) != len(columns): print "problem on line %d: %d fields vs. %d columns" % ( 1 + iLine, len(fields), len(columns)) print columns print fields for i in range(min(len(fields), len(columns))): print i, columns[i], fields[i] sys.exit() # BE crate = int(fields[iCrate]) slot = int(fields[iSlot]) uhtr_fib = int(fields[iUf]) # FE rbx = fields[iRbx] rm = int(fields[iRm]) rm_fib = int(fields[iRf]) if rbx in valid_rbxes: if fields[iFc] == "0": output.writelines( "%su%2d %02d %02d: %s %1d %1d\n" % (lineStart, crate, slot, uhtr_fib, rbx, rm, rm_fib)) output.close()
def ngHFMap(iMapfile="", ofile="", oFileOpenMode="w"): valid_rbxes = rbxes() output = open(ofile, oFileOpenMode) #opens & write the file lines = open(iMapfile, "r").readlines() columns = lines[0].split() # BE iCrate = columns.index("Crate") iSlot = columns.index("uHTR") iUf = columns.index("uHTR_FI") iFc = columns.index("FI_CH") # FE iRbx = columns.index("ngRBX") iRm = columns.index("QIE10") iTb = columns.index("QIETB") iQf = columns.index("QIEFI") for iLine, line in enumerate(lines): if not iLine or line[0] == "#": continue fields = line.split() if len(fields) != 1 + len(columns): print "problem on line %d: %d fields vs. %d columns" % ( 1 + iLine, len(fields), len(columns)) print columns print fields for i in range(min(len(fields), len(columns))): print i, columns[i], fields[i] sys.exit() # BE crate = int(fields[iCrate]) slot = int(fields[iSlot]) uhtr_fib = int(fields[iUf]) # FE rbx = fields[iRbx] rm = int(fields[iRm]) rm_fib = int(fields[iQf]) - 4 if rbx in valid_rbxes: if fields[iFc] == "0": output.writelines( "%su%2d %02d %02d: %s %1d %1d\n" % (lineStart, crate, slot, uhtr_fib, rbx, rm, rm_fib)) output.close()
def ReformMap(iMapfile="", ofile="", oFileOpenMode="w"): lines = open(iMapfile, "r").readlines() #opens & read the file output = open(ofile, oFileOpenMode) #opens & write the file RBXnameRange = rbxes() rmRange = ['1', '2', '3', '4'] if "CALIB" in iMapfile: rmRange = ['4', '5'] keyPosition = getKeyPosition(iMapfile) for i in range(0, len(lines)): #loop through Map file if "## file created" in lines[i]: continue #over pass un_needed lines if "# side eta phi dphi" in lines[i]: continue current_line = lines[i] RBXname = WordStrip(current_line, keyPosition["RBXname"]) rm = str(WordStrip(current_line, keyPosition["rm"])) rm_fib = str(WordStrip(current_line, keyPosition["rm_fib"])) fi_ch = str(WordStrip(current_line, keyPosition["fi_ch"])) htr_fib = str(WordStrip(current_line, keyPosition["htr_fib"])) if 'uHTR' in iMapfile: fedid = 'u' + str(WordStrip(current_line, keyPosition["crate"])) spigo = str(WordStrip(current_line, keyPosition["slot"])) else: fedid = str(WordStrip(current_line, keyPosition["fedid"])) spigo = str(WordStrip(current_line, keyPosition["spigo"])) spigo = WordSpace(spigo, 2) htr_fib = WordSpace(htr_fib, 2) if RBXname in RBXnameRange: if rm in rmRange and fi_ch == "0": #save only once per 3 channels output.writelines("%s%3s %02d %02d: %s %1d %1d\n" % (lineStart, fedid, int(spigo), int(htr_fib), RBXname, int(rm), int(rm_fib))) output.close()
def ReformMap(iMapfile = "", ofile = "", oFileOpenMode = "w"): lines = open(iMapfile, "r").readlines() #opens & read the file output = open(ofile, oFileOpenMode) #opens & write the file RBXnameRange = rbxes() rmRange = ['1','2','3','4'] if "CALIB" in iMapfile: rmRange = ['4','5'] keyPosition = getKeyPosition(iMapfile) for i in range(0, len(lines)): #loop through Map file if "## file created" in lines[i]: continue #over pass un_needed lines if "# side eta phi dphi" in lines[i]: continue current_line = lines[i] RBXname = WordStrip(current_line, keyPosition["RBXname"]) rm = str(WordStrip(current_line, keyPosition["rm"])) rm_fib = str(WordStrip(current_line, keyPosition["rm_fib"])) fi_ch = str(WordStrip(current_line, keyPosition["fi_ch"])) htr_fib = str(WordStrip(current_line, keyPosition["htr_fib"])) if 'uHTR' in iMapfile: fedid = 'u' + str(WordStrip(current_line, keyPosition["crate"])) spigo = str(WordStrip(current_line, keyPosition["slot"])) else: fedid = str(WordStrip(current_line, keyPosition["fedid"])) spigo = str(WordStrip(current_line, keyPosition["spigo"])) spigo = WordSpace(spigo,2) htr_fib = WordSpace(htr_fib,2) if RBXname in RBXnameRange: if rm in rmRange and fi_ch == "0": #save only once per 3 channels output.writelines("%s%3s %02d %02d: %s %1d %1d\n" % (lineStart, fedid, int(spigo), int(htr_fib), RBXname, int(rm), int(rm_fib))) output.close()