예제 #1
0
	def get_data(self, n_bx=50, i_qie=None, from_map=True, method=0):		# Method 0 is for uHTR SPY. Nothing else is implemented, yet.
		# Arguments and variables:
		i_qie = meta.parse_args_qie(i_qie=i_qie)
		
		# Get the link objects corresponding to this QIE:
		if from_map:
			links = uhtr.get_links_from_map(ts=self.ts, crate=self.crate, slot=self.slot, end="fe")
			if links:
				links = [i for i in links[self.crate_slot] if i.on]		# Save only the active links.
			else:
				return False
		else:
			print "ERROR (qie.qie.get_data): Getting the links straight from the uHTR (from_map = {0}) isn't implemented, yet.".format(from_map)
			return False
		
		# Read data off of each link:
		data = {}		# Will be indexed by QIE number
		for link in links:
#			print link
			if method == 0:
				if set(link.qies) & set(i_qie):		# If the two sets intersect (have any common elements) ...
					result = link.get_data_spy(n_bx=n_bx)
					if result:
						for i, data_temp in zip(link.qies, result):
							if i in i_qie:
								data[i] = data_temp
					else:
						print "ERROR (qie.qie.get_data): Unable to get data from the links."
						return False
			else:
				print "ERROR (qie.qie.get_data): Could not get data because method value {0} wasn't recognized.".format(method)
				return False
		return data
예제 #2
0
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
예제 #3
0
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
예제 #4
0
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
예제 #5
0
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