def get_unique_id(ts=None, crate=None, slot=None, control_hub=None, port=ngfec.port_default, script=False): # Reads the unique ID of a given set of crates and slots. # INFO: "get HF1-1-UniqueID # '1 0x5f000000 0x9b46ce70'" # Arguments: ## Parse "crate" and "slot" fe = meta.parse_args_crate_slot(ts=ts, crate=crate, slot=slot, crate_type="fe") if fe: # cmds = [] results = {} # Get the unique ID for each crate, slot for crate, slots in fe.iteritems(): for slot in slots: # cmds=.append("get HF{0}-{1}-UniqueID".format(crate, slot)) output = ngfec.send_commands(ts=ts, cmds=["get HF{0}-{1}-UniqueID".format(crate, slot)], control_hub=control_hub, port=port, script=script) if output: crate_slot = (crate, slot) result = output[0]["result"] if "ERROR" not in result: results[crate_slot] = result.split()[1:3] # The first element doesn't matter. else: results[crate_slot] = False else: return False return results else: return False
def set_unique_id(ts=None, crate=None, slot=None, control_hub=None, port=ngfec.port_default): # Saves the unique ID of the QIE card in crate, slot to IGLOO registers. #Arguments: ## Parse "crate" and "slot" fe = meta.parse_args_crate_slot(ts=ts, crate=crate, slot=slot, crate_type="fe") if fe: unique_ids = get_unique_id(ts=ts, crate=crate, slot=slot, control_hub=control_hub, port=port) if unique_ids: cmds = [] for crate_slot, unique_id in unique_ids.iteritems(): if unique_id: cmds.extend([ "put HF{0}-{1}-iTop_UniqueID {2} {3}".format(crate_slot[0], crate_slot[1], unique_id[0], unique_id[1]), "put HF{0}-{1}-iBot_UniqueID {2} {3}".format(crate_slot[0], crate_slot[1], unique_id[0], unique_id[1]) ]) else: print "ERROR (set_unique_id): The unique ID for the card in FE Crate {0}, Slot {1} could not be fetched. Therefore, it can't be set.".format(crate_slot[0], crate_slot[1]) return False output = ngfec.send_commands(ts=ts, cmds=cmds, control_hub=control_hub, port=port) if output: return unique_ids else: return False else: return False else: return False
def get_status(ts=None, crate=None): # Perform basic checks of the FE crate backplanes: # Arguments: log = "" crates = meta.parse_args_crate(ts=ts, crate=crate, crate_type="fe") if crates: statuses = {} # Status each crate: for fe_crate in crates: # Initialize status object s = status(ts=ts, crate=fe_crate) # Enable, reset, and check the BKP power: if fe_crate in ts.fe_crates: ngfec_output = ngfec.send_commands(ts=ts, cmds=["get HF{0}-bkp_pwr_bad".format(fe_crate)]) if "ERROR" not in ngfec_output[0]["result"]: try: good = not int(ngfec_output[0]["result"]) s.pwr = int(good) s.status.append(int(good)) except Exception as ex: print ex s.status.append(0) else: s.status.append(0) else: print "ERROR (bkp.get_status): The crate you want ({0}) is not in the teststand object you supplied. It has the following crates:\n\t{1}".format(fe_crate, ts.fe_crates) return False s.update() statuses[fe_crate] = s return statuses else: return False
def set_ci(ts=None, crate=None, slot=None, enable=False, control_hub=None, script=False): # Parse "crate" and "slot": fe = meta.parse_args_crate_slot(ts=ts, crate=crate, slot=slot) if fe: # Parse enable: if enable: enable_cmd = 1 else: enable_cmd = 0 # Build command list: cmds = [] for crate, slots in fe.iteritems(): for slot in slots: cmds.extend([ "put HF{0}-{1}-iTop_CntrReg_CImode 0x{2}".format(crate, slot, enable_cmd), "put HF{0}-{1}-iBot_CntrReg_CImode 0x{2}".format(crate, slot, enable_cmd), ]) # Send commands: output = ngfec.send_commands(ts=ts, cmds=cmds, control_hub=control_hub, script=script) results = ["ERROR" not in j for j in [i["result"] for i in output]] if sum(results) == len(results): return output else: print "ERROR (qie.set_ci): Setting the mode resulted in the following:" for thing in output: print "\t{0} -> {1}".format(thing["cmd"], thing["result"]) return False else: print "ERROR (qie.set_ci): The crate, slot arguments were not good." return False
def set_cal_mode_all(ts, crate, slot, enable=False): commands = [] value = 1 if enable else 0 for qie in range(1, 25): commands.append("put HF{0}-{1}-QIE{2}_CalMode {3}".format(crate, slot, qie, value)) raw_output = ngfec.send_commands(ts=ts, cmds=cmds) return raw_output
def read( self ) : output = ngfec.send_commands( self.ts, ["get {0}".format(self.name)], script=False) if self.verbosity >= 1 : print "REGISTER::READ() --" print output return output
def read(self): output = ngfec.send_commands(self.ts, ["get {0}".format(self.name)], script=False) if self.verbosity >= 1: print "REGISTER::READ() --" print output return output
def write( self , value = '') : output = ngfec.send_commands(self.ts, ["put {0} {1}".format(self.name,value)], script=False) if self.verbosity >= 1 : print "REGISTER::WRITE() --" print output if output.find("ERROR!") != -1 : return False else : return True
def write(self, value=''): output = ngfec.send_commands(self.ts, ["put {0} {1}".format(self.name, value)], script=False) if self.verbosity >= 1: print "REGISTER::WRITE() --" print output if output.find("ERROR!") != -1: return False else: return True
def read_counter_qie_bridge(ts, crate, slot): log = "" count = -1 cmd = "get HF{0}-{1}-B_RESQIECOUNTER".format(crate, slot) output = ngfec.send_commands(ts=ts, cmds=cmds) try: count = int(output[0]["result"], 16) except Exception as ex: log += output[0]["cmd"] + " -> " + output[0]["result"] + "\n" return { "count": count, "log": log, }
def get_temps(ts=False): # It's more flexible to not have the input be a teststand object. I should make it accept both. output = {} if ts: for crate, slots in ts.fe.iteritems(): output[crate] = [] for slot in slots: cmds = [ "get HE{0}-{1}-bkp_temp_f".format(crate, slot), # The temperature sensor on the QIE card, near the bottom, labeled "U40". ] output[crate] += ngfec.send_commands(ts=ts, cmds=cmds) return output else: return output
def set_mode(ts=None, crate=None, slot=None, mode=0, control_hub=None, port=ngfec.port_default, verbose=False): # 0: normal mode, 1: link test mode A (test mode string), 2: link test mode B (IGLOO register) # Parse "crate" and "slot": fe = meta.parse_args_crate_slot(ts=ts, crate=crate, slot=slot) if fe: # Parse "mode": if mode == 0: n = 0 elif mode == 1: n = 1 elif mode == 2: n = 7 else: print "ERROR (qie.set_mode): I don't understand mode = {0}.".format(mode) return False # Build command list: cmds = [] for crate, slots in fe.iteritems(): for slot in slots: cmds.extend([ "put HF{0}-{1}-iTop_LinkTestMode 0x{2}".format(crate, slot, n), "put HF{0}-{1}-iBot_LinkTestMode 0x{2}".format(crate, slot, n), "get HF{0}-{1}-iTop_LinkTestMode".format(crate, slot), "get HF{0}-{1}-iBot_LinkTestMode".format(crate, slot), ]) # Send commands: output = ngfec.send_commands(ts=ts, cmds=cmds, control_hub=control_hub, port=port) results = ["ERROR" not in j for j in [i["result"] for i in output]] if sum(results) == len(results): if verbose: for thing in output: print "\t{0} -> {1}".format(thing["cmd"], thing["result"]) if uhtr.setup(ts=ts): # This initializes all uHTRs' links. This is necessary after changing modes. return True else: print "ERROR (qie.set_mode): Reinitializing the uHTR links failed." return False else: print "ERROR (qie.set_mode): Setting the mode resulted in the following:" for thing in output: print "\t{0} -> {1}".format(thing["cmd"], thing["result"]) return False else: print "ERROR (qie.set_mode): The crate, slot arguments were not good." return False
def check_unique_id(ts=None, crate=None, slot=None, control_hub=None, port=ngfec.port_default, verbose=False): #Arguments: ## Parse "crate" and "slot" fe = meta.parse_args_crate_slot(ts=ts, crate=crate, slot=slot, crate_type="fe") if fe: # Get the unique ID values: cmds = [] for fe_crate, fe_slots in fe.iteritems(): for fe_slot in fe_slots: cmds.extend([ "get HF{0}-{1}-iTop_UniqueID".format(fe_crate, fe_slot), "get HF{0}-{1}-iBot_UniqueID".format(fe_crate, fe_slot), ]) results = ngfec.send_commands(ts=ts, cmds=cmds, control_hub=control_hub, port=port) # Check the unique ID values: if results: good = [] values_previous = [] for i, result in enumerate(results): values = [int(j, 16) for j in result["result"].split()] # values = [int(j, 16) for j in "0 0xbad".split()] # print values if len(values) == 2 and 0 not in values: if i%2 == 1: if values == values_previous: good.append(True) else: # print values, values_previous good.append(False) else: good.append(True) else: good.append(False) values_previous = values if sum(good) == len(good) and len(good) > 0: if verbose: print "[OK] The unique IDs were all set properly:\n{0}".format(results) return True else: if verbose: print "[!!] The unique IDs were not all set properly:\n{0}".format(results) return False else: return False else: return False
def set_clk_phase(ts=False, crate=None, slot=None, i_qie=None, phase=0, control_hub=None, port=ngfec.port_default, script=True): # Parse "crate" and "slot": fe = meta.parse_args_crate_slot(ts=ts, crate=crate, slot=slot) if fe: # Parse "i_qie": i_qie = meta.parse_args_qie(i_qie=i_qie) # The default is range(1, 25) if i_qie: # Parse "phase": if isinstance(phase, int): phase = int(phase) if phase not in range(16): print "ERROR (qie.set_clk_phase): The clock phase you selected with \"phase\" must be an element of [0, 1, ..., 15]." return False else: print "ERROR (qie.set_clk_phase): The clock phase you selected with \"phase\" must be an integer (between 0 and 15)." return False # Build list of commands: cmds = [] for crate, slots in fe.iteritems(): for slot in slots: for i in i_qie: cmds.extend([ "put HF{0}-{1}-Qie{2}_ck_ph {3}".format(crate, slot, i, phase), "get HF{0}-{1}-Qie{2}_ck_ph".format(crate, slot, i), ]) # Send commands: output = ngfec.send_commands(ts=ts, cmds=cmds, control_hub=control_hub, port=port, script=script) results = ["ERROR" not in j for j in [i["result"] for i in output]] if sum(results) == len(results): # for thing in output: # print "\t{0} -> {1}".format(thing["cmd"], thing["result"]) return True else: print "ERROR (qie.set_clk_phase): Setting QIE clock phase mode resulted in the following:" for thing in output: print "\t{0} -> {1}".format(thing["cmd"], thing["result"]) return False else: print "ERROR (qie.set_clk_phase): The \"i_qie\" argument was not good." return False else: print "ERROR (qie.set_clk_phase): The crate, slot arguments were not good." return False
def read_counter_qie_igloo(ts, crate, slot): log = "" counts = [-1, -1] times = [-1, -1] cmds = [ "get HF{0}-{1}-iTop_RST_QIE_count".format(crate, slot), "get HF{0}-{1}-iBot_RST_QIE_count".format(crate, slot), ] output = ngfec.send_commands(ts=ts, cmds=cmds) for i in range(2): try: counts[i] = int(output[i]["result"], 16) times[i] = output[i]["times"][0] except Exception as ex: log += output[i][0] + " -> " + output[i][1] + "\n" + ex + "\n" return { "counts": counts, "times": times, "log": log, }
def setup(self, ts=None, verbose=False): if ts: cmds = [ "put HF{0}-bkp_pwr_enable 1".format(self.crate), "put HF{0}-bkp_pwr_enable 0".format(self.crate), "put HF{0}-bkp_pwr_enable 1".format(self.crate), "put HF{0}-bkp_reset 0".format(self.crate), "put HF{0}-bkp_reset 1".format(self.crate), "put HF{0}-bkp_reset 0".format(self.crate), "get HF{0}-bkp_pwr_bad".format(self.crate), ] ngfec_output = ngfec.send_commands(ts=ts, cmds=cmds) if verbose: print ngfec_output for cmd in ngfec_output[:-1]: if "OK" not in cmd["result"]: return False if ngfec_output[-1]["result"] == "1": return False return True else: return False
def get_temp(ts, crate, icrate): # It's more flexible to not have the input be a teststand object. I should make it accept both. commands = [] for slot in ts.qie_slots[icrate]: commands.append("get HE{0}-{1}-temperature_f".format(crate,slot)) #commands.append("wait") raw_output = ngfec.send_commands(ts=ts, cmds=commands, script=True) temp = [] log = [] for i,slot in enumerate(ts.qie_slots[icrate]): temp.append("") log.append("") try: #match = search("get HE{0}-{1}-temperature_f # ([\d\.]+)".format(crate, slot), raw_output) temp[i] = float(raw_output[i]["result"]) except Exception as ex: log[i] += 'Trying to find the temperature of Crate {0} with "{1}" resulted in: {2}\n'.format(crate, commands[i], ex) match = search("\n(.*ERROR!!.*)\n", raw_output[i]["result"]) if match: log[i] += 'The data string was "{0}".'.format(match.group(0).strip()) return { "temp": temp, "log": log, }
def set_cal_mode(ts, crate, slot, qie, enable=False): value = 1 if enable else 0 commands = ["put HF{0}-{1}-QIE{2}_CalMode {3}".format(crate, slot, qie, value)] raw_output = ngfec.send_commands(ts=ts, cmds=cmds) return raw_output
def get_info(ts=None, crate=None, slot=None, control_hub=None, port=ngfec.port_default, script=True): # Arguments and variables output = [] raw_output = "" ## Parse crate, slot: fe = meta.parse_args_crate_slot(ts=ts, crate=crate, slot=slot, crate_type="fe") if fe: # Prepare: data = {} results = {} for crate, slots in fe.iteritems(): for slot in slots: data[(crate, slot)] = [] ## Prepare bridge info: data[(crate, slot)].append([ "fw_bridge_major", 'get HF{0}-{1}-B_FIRMVERSION_MAJOR'.format(crate, slot), ]) data[(crate, slot)].append([ "fw_bridge_minor", 'get HF{0}-{1}-B_FIRMVERSION_MINOR'.format(crate, slot), ]) data[(crate, slot)].append([ "fw_bridge_svn", 'get HF{0}-{1}-B_FIRMVERSION_SVN'.format(crate, slot), ]) ## Prepare IGLOO info: data[(crate, slot)].append([ "fw_igloo_top_major", 'get HF{0}-{1}-iTop_FPGA_MAJOR_VERSION'.format(crate, slot), ]) data[(crate, slot)].append([ "fw_igloo_top_minor", 'get HF{0}-{1}-iTop_FPGA_MINOR_VERSION'.format(crate, slot), ]) data[(crate, slot)].append([ "fw_igloo_bot_major", 'get HF{0}-{1}-iBot_FPGA_MAJOR_VERSION'.format(crate, slot), ]) data[(crate, slot)].append([ "fw_igloo_bot_minor", 'get HF{0}-{1}-iBot_FPGA_MINOR_VERSION'.format(crate, slot), ]) data[(crate, slot)].append([ "id_igloo_top", 'get HF{0}-{1}-iTop_UniqueID'.format(crate, slot), ]) data[(crate, slot)].append([ "id_igloo_bot", 'get HF{0}-{1}-iBot_UniqueID'.format(crate, slot), ]) # Compile list of commands to send: cmds = [d[1] for crate_slot, ds in data.iteritems() for d in ds] # print cmds # Send commands: ngfec_out = ngfec.send_commands(ts=ts, cmds=cmds, control_hub=control_hub, port=port, script=script) # Understand results: for crate_slot, ds in data.iteritems(): results[crate_slot] = {} for i, d in enumerate(ds): key = d[0] cmd = d[1] for result in ngfec_out: if result["cmd"] == cmd: if "ERROR" not in result["result"]: if "UniqueID" not in cmd: results[crate_slot].update({ key: int(result["result"], 16) }) else: results[crate_slot].update({ key: result["result"].split() }) else: results[crate_slot].update({ key: False }) results[crate_slot]["fws"] = [ "{0:02d}.{1:02d}".format(results[crate_slot]["fw_igloo_top_major"], results[crate_slot]["fw_igloo_top_minor"]), "{0:02d}.{1:02d}".format(results[crate_slot]["fw_igloo_bot_major"], results[crate_slot]["fw_igloo_bot_minor"]), "{0:02d}.{1:02d}.{2:04d}".format(results[crate_slot]["fw_bridge_major"], results[crate_slot]["fw_bridge_minor"], results[crate_slot]["fw_bridge_svn"]), ] # Return results: return results else: return False
def set_fixed_range(ts=False, crate=None, slot=None, i_qie=None, enable=None, r=None, control_hub=None, port=ngfec.port_default): # Turn fixed range mode on or off for a given QIE. # Parse "crate" and "slot": fe = meta.parse_args_crate_slot(ts=ts, crate=crate, slot=slot) if fe: # Parse "i_qie": i_qie = meta.parse_args_qie(i_qie=i_qie) # The default is range(1, 25) if i_qie: # Parse "r" and "enable": if enable == None: if r == None: r = 0 enable = False else: if isinstance(r, int): r = int(r) if r in range(4): enable = True else: print "ERROR (qie.set_fixed_range): The range you select with \"r\" must be an element of [0, 1, 2, 3]." return False else: print "ERROR (qie.set_fixed_range): You need to make sure to input an integer value for \"r\"." return False else: enable = bool(enable) # Build list of commands: cmds = [] for crate, slots in fe.iteritems(): for slot in slots: for i in i_qie: if enable: cmds.extend([ "put HF{0}-{1}-QIE{2}_FixRange 1".format(crate, slot, i), "put HF{0}-{1}-QIE{2}_RangeSet {3}".format(crate, slot, i, r), "get HF{0}-{1}-QIE{2}_FixRange".format(crate, slot, i), "get HF{0}-{1}-QIE{2}_RangeSet".format(crate, slot, i), ]) else : cmds.extend([ "put HF{0}-{1}-QIE{2}_FixRange 0".format(crate, slot, i), "put HF{0}-{1}-QIE{2}_RangeSet 0".format(crate, slot, i), "get HF{0}-{1}-QIE{2}_FixRange".format(crate, slot, i), "get HF{0}-{1}-QIE{2}_RangeSet".format(crate, slot, i), ]) # Send commands: output = ngfec.send_commands(ts=ts, cmds=cmds, control_hub=control_hub, port=port) results = ["ERROR" not in j for j in [i["result"] for i in output]] if sum(results) == len(results): # for thing in output: # print "\t{0} -> {1}".format(thing["cmd"], thing["result"]) return True else: print "ERROR (qie.set_fixed_range): Setting fixed-range mode resulted in the following:" for thing in output: print "\t{0} -> {1}".format(thing["cmd"], thing["result"]) return False else: print "ERROR (qie.set_fixed_range): The \"i_qie\" argument was not good." return False else: print "ERROR (qie.set_fixed_range): The crate, slot arguments were not good." return False
def set_ped(ts=False, crate=None, slot=None, i_qie=None, dac=None, dac_cid=None, i_cid=set(range(4)), control_hub=None, port=ngfec.port_default): # Set the pedestal of QIE "i_qie" to DAC value "dac" and CID DAC value of "dac_cid". # Parse "crate" and "slot": fe = meta.parse_args_crate_slot(ts=ts, crate=crate, slot=slot) if fe: # Parse "i_qie": i_qie = meta.parse_args_qie(i_qie=i_qie) # The default is range(1, 25) if i_qie: # Parse "i_cid": i_cid_original = i_cid if isinstance(i_cid, int): i_cid = [i_cid] elif not (isinstance(i_cid, list) or isinstance(i_cid, set)): print "ERROR (qie.set_ped): You must enter an integer or a list of integers for \"i_cid\". The pedestals have not be changed." return False i_cid = set(i_cid) if not i_cid.issubset(set(range(4))): print "ERROR (qie.set_ped): \"i_cid\" can only contain elements of [0, 1, 2, 3], but you tried to set it to {0}. The pedestals have not be changed.".format(i_cid_original) return False # Parse "dac" and "dac_cid": if dac == None and dac_cid == None: print "WARNING (qie.set_ped): You didn't supply a \"dac\" or \"dac_cid\", so \"dac\" will be set to 6, the default, and \"dac_cid\" will be set to 0, the default, for all \"i_cid\" in {0} and all \"i_qie\" in {1}.".format(i_cid, i_qie) dac = 6 dac_cid = 0 ## Parse "dac": if dac != None: if abs(dac) > 31: print "ERROR (qie.set_ped): You must enter a decimal integer for \"dac\" between -31 and 31. You tried to set it to {0}. The pedestals have not been changed.".format(dac) return False else: if dac <= 0: dac = abs(dac) else: dac = dac + 32 dac_str = "{0:#04x}".format(dac) # The "#" prints the "0x". The number of digits to pad with 0s must include these "0x", hence "4" instead of "2". else: dac_str = False ## Parse "dac_cid": if dac_cid != None: if abs(dac_cid) > 7: print "ERROR (qie.set_ped): You must enter a decimal integer for \"dac_cid\" between -7 and 7. You tried to set it to {0}. The pedestals have not been changed.".format(dac_cid) return False else: if dac_cid <= 0: dac_cid = abs(dac_cid) else: dac_cid = dac_cid + 8 dac_cid_str = "{0:#04x}".format(dac_cid) # The "#" prints the "0x". The number of digits to pad with 0s must include these "0x", hence "4" instead of "2". else: dac_cid_str = False # See where things stand: if not dac_str and not dac_cid_str: print "ERROR (qie.set_ped): You intended to set pedestals, but it turns out none will be changed." return False if not fe: print "ERROR (qie.set_ped): The crate/slot configuration is all jacked up." return False # Build command list: cmds = [] for crate, slots in fe.iteritems(): for slot in slots: for i in i_qie: if dac_str: cmds.extend([ "put HF{0}-{1}-QIE{2}_PedestalDAC {3}".format(crate, slot, i, dac_str), "get HF{0}-{1}-QIE{2}_PedestalDAC".format(crate, slot, i), ]) if dac_cid_str: for j in i_cid: cmds.extend([ "put HF{0}-{1}-QIE{2}_CapID{3}pedestal {4}".format(crate, slot, i, j, dac_cid_str), "get HF{0}-{1}-QIE{2}_CapID{3}pedestal".format(crate, slot, i, j), ]) # Send commands: output = ngfec.send_commands(ts=ts, cmds=cmds, control_hub=control_hub, port=port) results = ["ERROR" not in j for j in [i["result"] for i in output]] if sum(results) == len(results): # for thing in output: # print "\t{0} -> {1}".format(thing["cmd"], thing["result"]) return True else: print "ERROR (qie.set_ped): Setting pedestals resulted in the following:" for thing in output: print "\t{0} -> {1}".format(thing["cmd"], thing["result"]) return False else: print "ERROR (qie.set_ped): The \"i_qie\" argument was not good." return False else: print "ERROR (qie.set_ped): The crate, slot arguments were not good." return False
def testCache( self ) : errors = 0 executeErrors = 0 totalTests = 0 output = ngfec.send_commands(ts = self.ts, cmds= self.commandCache, script=False) # print output if self.verbosity >= 2 : print "------------COMMANDS------------" print output print if len( output ) % 2 != 0 : print "ERROR, register::testCach() - the wrong number of commands were executed" return -999 for i in range( len( output ) / 2 ) : if output[i*2]["cmd"].find("put ") == -1 : print "ERROR, register::testCach() - commands executed in wrong order??" return -999 else : value = output[i*2]["cmd"].split()[2:] # valueNum = [] # for v in value : # valueNum.append( int(v,16) ) if output[i*2+1]["cmd"].find("get ") == -1 : print "ERROR, register::testCach() - commands executed in wrong order??" return -999 else : #check = output[i*2+1]["result"].split("'")[1].split() check = output[i*2+1]["result"].split() for i, name in enumerate(value) : if len(name) == 3 and name[2].isdigit() : value[i] = name[2] if output[i*2]["result"] != "OK" : executeErrors = executeErrors + 1 continue elif value != check : self.elist.append([value, check]) errors = errors + 1 totalTests = totalTests + 1 # if self.verbosity >= 1 : # print "check:",check # checkNum = [] # for c in check[::-1] : # checkNum.append( int(c,16) ) ### valueNum and checkNum are compared so that ### leading zeroes will be conveniently ignored # for i, name in enumerate(value) : # if len(name) == 3 and name[2].isdigit() : # value[i] = name[2] # if self.verbosity >= 1 : # print "value:",value # if self.verbosity >= 1 : # print "check:",check # if value != check: # self.elist.append([value, check]) # errors = errors + 1 if self.verbosity >= 1: print print "--------------------------------" print "REGISTER:",self.name print "--------------------------------" print "errors:",errors print "execution errors:",executeErrors # if bool(totalTests): print "Success rate:", 100. * ( 1. - ( float( errors ) ) / float( totalTests ) ),"%" # else: # print "Execution error - No tests performed" print "Execution error rate:", 100. * float( executeErrors ) / ( float( executeErrors ) + float( totalTests ) ),"%" print self.tex = {self.name: [totalTests, errors, executeErrors]}
def testCache(self): errors = 0 executeErrors = 0 totalTests = 0 output = ngfec.send_commands(ts=self.ts, cmds=self.commandCache, script=False) # print output if self.verbosity >= 2: print "------------COMMANDS------------" print output print if len(output) % 2 != 0: print "ERROR, register::testCach() - the wrong number of commands were executed" return -999 for i in range(len(output) / 2): if output[i * 2]["cmd"].find("put ") == -1: print "ERROR, register::testCach() - commands executed in wrong order??" return -999 else: value = output[i * 2]["cmd"].split()[2:] # valueNum = [] # for v in value : # valueNum.append( int(v,16) ) if output[i * 2 + 1]["cmd"].find("get ") == -1: print "ERROR, register::testCach() - commands executed in wrong order??" return -999 else: #check = output[i*2+1]["result"].split("'")[1].split() check = output[i * 2 + 1]["result"].split() for i, name in enumerate(value): if len(name) == 3 and name[2].isdigit(): value[i] = name[2] if output[i * 2]["result"] != "OK": executeErrors = executeErrors + 1 continue elif value != check: self.elist.append([value, check]) errors = errors + 1 totalTests = totalTests + 1 # if self.verbosity >= 1 : # print "check:",check # checkNum = [] # for c in check[::-1] : # checkNum.append( int(c,16) ) ### valueNum and checkNum are compared so that ### leading zeroes will be conveniently ignored # for i, name in enumerate(value) : # if len(name) == 3 and name[2].isdigit() : # value[i] = name[2] # if self.verbosity >= 1 : # print "value:",value # if self.verbosity >= 1 : # print "check:",check # if value != check: # self.elist.append([value, check]) # errors = errors + 1 if self.verbosity >= 1: print print "--------------------------------" print "REGISTER:", self.name print "--------------------------------" print "errors:", errors print "execution errors:", executeErrors # if bool(totalTests): print "Success rate:", 100. * ( 1. - (float(errors)) / float(totalTests)), "%" # else: # print "Execution error - No tests performed" print "Execution error rate:", 100. * float(executeErrors) / ( float(executeErrors) + float(totalTests)), "%" print self.tex = {self.name: [totalTests, errors, executeErrors]}
def setup(ts=None, crate=None, slot=None, i_qie=None, control_hub=None, port=None, verbose=False): # Set up any number of QIE cards. Specify a group of QIE cards by the crates and slots. If you specify the ts and nothing else, it will set up all of them. # Arguments: cmds = [] ## Parse "crate" and "slot" fe = meta.parse_args_crate_slot(ts=ts, crate=crate, slot=slot, crate_type="fe") if fe: ## Parse "i_qie": is_qie = meta.parse_args_qie(i_qie=i_qie) # The default is range(1, 25) if is_qie: # Define setup commands: for fe_crate, slots in fe.iteritems(): for fe_slot in slots: # print fe_crate, fe_slot for i_qie in is_qie: ## Put all QIE program register values to default: cmds.extend([ "put HF{0}-{1}-QIE{2}_Lvds 0x1".format(fe_crate, fe_slot, i_qie), # 1 bit "put HF{0}-{1}-QIE{2}_Trim 0x2".format(fe_crate, fe_slot, i_qie), # 2 bits "put HF{0}-{1}-QIE{2}_DiscOn 0x0".format(fe_crate, fe_slot, i_qie), # 1 bit "put HF{0}-{1}-QIE{2}_TGain 0x0".format(fe_crate, fe_slot, i_qie), # 1 bit "put HF{0}-{1}-QIE{2}_TimingThresholdDAC 0xff".format(fe_crate, fe_slot, i_qie), # 8 bits "put HF{0}-{1}-QIE{2}_TimingIref 0x0".format(fe_crate, fe_slot, i_qie), # 3 bits "put HF{0}-{1}-QIE{2}_PedestalDAC 0x26".format(fe_crate, fe_slot, i_qie), # 6 bits "put HF{0}-{1}-QIE{2}_CapID0pedestal 0x0".format(fe_crate, fe_slot, i_qie), # 4 bits "put HF{0}-{1}-QIE{2}_CapID1pedestal 0x0".format(fe_crate, fe_slot, i_qie), # 4 bits "put HF{0}-{1}-QIE{2}_CapID2pedestal 0x0".format(fe_crate, fe_slot, i_qie), # 4 bits "put HF{0}-{1}-QIE{2}_CapID3pedestal 0x0".format(fe_crate, fe_slot, i_qie), # 4 bits "put HF{0}-{1}-QIE{2}_FixRange 0x0".format(fe_crate, fe_slot, i_qie), # 1 bit "put HF{0}-{1}-QIE{2}_RangeSet 0x0".format(fe_crate, fe_slot, i_qie), # 2 bits "put HF{0}-{1}-QIE{2}_ChargeInjectDAC 0x0".format(fe_crate, fe_slot, i_qie), # 3 bits "put HF{0}-{1}-QIE{2}_RinSel 0x4".format(fe_crate, fe_slot, i_qie), # 4 bits "put HF{0}-{1}-QIE{2}_Idcset 0x0".format(fe_crate, fe_slot, i_qie), # 5 bits "put HF{0}-{1}-QIE{2}_CalMode 0x0".format(fe_crate, fe_slot, i_qie), # 1 bit "put HF{0}-{1}-QIE{2}_CkOutEn 0x0".format(fe_crate, fe_slot, i_qie), # 1 bit "put HF{0}-{1}-QIE{2}_TDCMode 0x0".format(fe_crate, fe_slot, i_qie), # 1 bit ]) ## Other QIE-specific things: cmds.extend([ 'put HF{0}-{1}-Qie{2}_ck_ph 0x0'.format(fe_crate, fe_slot, i_qie), # Set the clock phase to 0. ]) ## Put all other QIE card values to default values: cmds.extend([ "put HF{0}-{1}-iTop_CntrReg_CImode 0x0".format(fe_crate, fe_slot), "put HF{0}-{1}-iBot_CntrReg_CImode 0x0".format(fe_crate, fe_slot), # "put HF{0}-{1}-iTop_LinkTestMode 0x0".format(fe_crate, fe_slot), # "put HF{0}-{1}-iBot_LinkTestMode 0x0".format(fe_crate, fe_slot), "put HF{0}-{1}-iTop_UniqueID 0x0 0x0".format(fe_crate, fe_slot), "put HF{0}-{1}-iBot_UniqueID 0x0 0x0".format(fe_crate, fe_slot), ]) if verbose: print "\tSetting all QIE chips and cards to default values ..." output = ngfec.send_commands(ts=ts, cmds=cmds, control_hub=control_hub, port=port, script=True) if output: if verbose: print "\tSetting QIE card IDs in the IGLOO registers ..." result = set_unique_id(ts=ts, crate=crate, slot=slot, control_hub=control_hub, port=port) if result: return { "output": output, "fe": fe, "ids": result, } else: if verbose: print "\tERROR (qie.setup): Failed to set up the QIE card IDs." return False else: return False else: return False else: return False