larpix package

larpix.larpix module

A module to control the LArPix chip.

class larpix.larpix.Chip(chip_id, io_chain)[source]

Bases: object

Represents one LArPix chip and helps with configuration and packet generation.

export_reads(only_new_reads=True)[source]

Return a dict of the packets this Chip has received.

If only_new_reads is True (default), then only the packets since the last time this method was called will be in the dict. Otherwise, all of the packets stored in self.reads will be in the dict.

get_configuration_packets(packet_type, registers=None)[source]
num_channels = 32
sync_configuration(index=-1)[source]

Adjust self.config to match whatever config read packets are in self.reads[index].

Defaults to the most recently read PacketCollection. Later packets in the list will overwrite earlier packets. The index parameter could be a slice.

class larpix.larpix.Configuration[source]

Bases: object

Represents the desired configuration state of a LArPix chip.

TEST_FIFO = 2
TEST_OFF = 0
TEST_UART = 1
adc_burst_length
adc_burst_length_address = 51
adc_burst_length_data()[source]
all_data()[source]
channel_mask
channel_mask_addresses = [52, 53, 54, 55]
channel_mask_data(chunk)[source]
compare(config)[source]

Returns a dict containing pairs of each differently valued register Pair order is (self, other)

cross_trigger_mode
csa_bypass
csa_bypass_select
csa_bypass_select_addresses = [34, 35, 36, 37]
csa_bypass_select_data(chunk)[source]
csa_gain
csa_gain_and_bypasses_address = 33
csa_gain_and_bypasses_data()[source]
csa_monitor_select
csa_monitor_select_addresses = [38, 39, 40, 41]
csa_monitor_select_data(chunk)[source]
csa_testpulse_dac_amplitude
csa_testpulse_dac_amplitude_address = 46
csa_testpulse_dac_amplitude_data()[source]
csa_testpulse_enable
csa_testpulse_enable_addresses = [42, 43, 44, 45]
csa_testpulse_enable_data(chunk)[source]
disable_analog_monitor()[source]
disable_channels(list_of_channels=None)[source]
disable_external_trigger(list_of_channels=None)[source]
disable_testpulse(list_of_channels=None)[source]
enable_analog_monitor(channel)[source]
enable_channels(list_of_channels=None)[source]
enable_external_trigger(list_of_channels=None)[source]
enable_normal_operation()[source]
enable_testpulse(list_of_channels=None)[source]
external_trigger_mask
external_trigger_mask_addresses = [56, 57, 58, 59]
external_trigger_mask_data(chunk)[source]
fifo_diagnostic
fpga_packet_size = 10
from_dict(d)[source]
from_dict_registers(d)[source]

Load in the configuration specified by a dict of (register, value) pairs.

get_nondefault_registers()[source]
global_threshold
global_threshold_address = 32
global_threshold_data()[source]
internal_bypass
load(filename)[source]
num_registers = 63
periodic_reset
pixel_trim_threshold_addresses = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]
pixel_trim_thresholds
register_names = ['pixel_trim_thresholds', 'global_threshold', 'csa_gain', 'csa_bypass', 'internal_bypass', 'csa_bypass_select', 'csa_monitor_select', 'csa_testpulse_enable', 'csa_testpulse_dac_amplitude', 'test_mode', 'cross_trigger_mode', 'periodic_reset', 'fifo_diagnostic', 'sample_cycles', 'test_burst_length', 'adc_burst_length', 'channel_mask', 'external_trigger_mask', 'reset_cycles']
reset_cycles
reset_cycles_addresses = [60, 61, 62]
reset_cycles_data(chunk)[source]
sample_cycles
sample_cycles_address = 48
sample_cycles_data()[source]
test_burst_length
test_burst_length_addresses = [49, 50]
test_burst_length_data(chunk)[source]
test_mode
test_mode_xtrig_reset_diag_address = 47
test_mode_xtrig_reset_diag_data()[source]
to_dict()[source]
trim_threshold_data(channel)[source]
write(filename, force=False, append=False)[source]
class larpix.larpix.Controller(port=None, timeout=1)[source]

Bases: object

Controls a collection of LArPix Chip objects.

Properties and attributes:

  • chips: the Chip objects that the controller controls
  • all_chip: all possible Chip objects (considering there are a finite number of chip IDs), initialized on object construction
  • port: the path to the serial port, i.e. “/dev/(whatever)” (default: None [will attempt to auto-find correct port])
  • timeout: the timeout used for serial commands, in seconds. This can be changed between calls to the read and write commands. (default: 1)
  • reads: list of all the PacketCollections that have been sent back to this controller. PacketCollections are created by run, write_configuration, and read_configuration, but not by any of the serial_* methods.
  • use_all_chips: if True, look up chip objects in self.all_chips, else look up in self.chips (default: False)
disable(chip_id=None, channel_list=range(0, 32), io_chain=0)[source]

Update channel mask to disable specified chips/channels. If none specified, disable all chips/channels

disable_analog_monitor(chip_id=None, channel=None, io_chain=0)[source]

Disable the analog monitor for a specified chip and channel, if none are specified disable the analog monitor for all chips in self.chips and all channels

disable_testpulse(chip_id=None, channel_list=range(0, 32), io_chain=0)[source]

Disable testpulser for specified chip/channels. If none specified, disable for all chips/channels

enable(chip_id=None, channel_list=range(0, 32), io_chain=0)[source]

Update channel mask to enable specified chips/channels. If none specified, enable all chips/channels

enable_analog_monitor(chip_id, channel, io_chain=0)[source]

Enable the analog monitor on a single channel on the specified chip. Note: If monitoring a different chip, call disable_analog_monitor first to ensure that the monitor to that chip is disconnected.

enable_testpulse(chip_id, channel_list, io_chain=0, start_dac=255)[source]

Prepare chip for pulsing - enable testpulser and set a starting dac value for specified chip/channel

format_UART(chip, packet)[source]
format_bytestream(formatted_packets)[source]
get_chip(chip_id, io_chain)[source]
get_configuration_bytestreams(chip, packet_type, registers)[source]
issue_testpulse(chip_id, pulse_dac, min_dac=0, io_chain=0)[source]

Reduce the testpulser dac by pulse_dac and write_read to chip for 0.1s

load(filename)[source]

Load the data in filename into the controller.

Overwrites all data inside the controller!

multi_read_configuration(chip_reg_pairs, timeout=1, message=None)[source]

Send multiple read configuration commands at once.

chip_reg_pairs should be a list/iterable whose elements are Chip objects (to read entire configuration) or (chip, registers) tuples to read only the specified register(s). Registers could be None (i.e. all), an int for that register only, or an iterable of ``int``s.

Examples:

These first 2 are equivalent and read the full configurations

>>> controller.multi_read_configuration([chip1, chip2, ...])
>>> controller.multi_read_configuration([(chip1, None), chip2, ...])

These 2 read the specified registers for the specified chips in the specified order

>>> controller.multi_read_configuration([(chip1, 1), (chip2, 2), ...])
>>> controller.multi_read_configuration([(chip1, range(10)), chip2, ...])
multi_write_configuration(chip_reg_pairs, write_read=0, message=None)[source]

Send multiple write configuration commands at once.

chip_reg_pairs should be a list/iterable whose elements are an valid arguments to Controller.write_configuration, excluding the write_read argument. Just like in the single Controller.write_configuration, setting write_read > 0 will have the controller read data during and after it writes, for however many seconds are specified.

Examples:

These first 2 are equivalent and write the full configurations

>>> controller.multi_write_configuration([chip1, chip2, ...])
>>> controller.multi_write_configuration([(chip1, None), chip2, ...])

These 2 write the specified registers for the specified chips in the specified order

>>> controller.multi_write_configuration([(chip1, 1), (chip2, 2), ...])
>>> controller.multi_write_configuration([(chip1, range(10)), chip2, ...])
classmethod parse_input(bytestream)[source]
read_channel_pedestal(chip_id, channel, io_chain=0, run_time=0.1)[source]

Set channel threshold to 0 and report back on the recieved adcs from channel Returns mean, rms, and packet collection

read_configuration(chip, registers=None, timeout=1, message=None)[source]
run(timelimit, message)[source]
run_analog_monitor_test()[source]
run_fifo_test()[source]
run_testpulse(list_of_channels)[source]
save_output(filename, message)[source]

Save the data read by each chip to the specified file.

serial_close()[source]
serial_read(timelimit)[source]
serial_write(bytestreams)[source]
serial_write_read(bytestreams, timelimit)[source]
sort_packets(collection)[source]

Sort the packets in collection into each chip in self.all_chips (if self.use_all_chips) or self.chips (otherwise).

start_byte = b's'
stop_byte = b'q'
store_packets(packets, data, message)[source]

Store the packets in self and in self.chips

verify_configuration(chip_id=None, io_chain=0)[source]

Read chip configuration from specified chip and return a bool that is True if the read chip configuration matches the current configuration stored in chip instance Also returns a dict containing the values of registers that are different (read register, stored register)

write_configuration(chip, registers=None, write_read=0, message=None)[source]
class larpix.larpix.Packet(bytestream=None)[source]

Bases: object

A single 54-bit LArPix UART data packet.

CONFIG_READ_PACKET = bitarray('11')
CONFIG_WRITE_PACKET = bitarray('10')
DATA_PACKET = bitarray('00')
TEST_PACKET = bitarray('01')
assign_parity()[source]
bytes()[source]
channel_id
channel_id_bits = slice(37, 44, None)
chipid
chipid_bits = slice(44, 52, None)
compute_parity()[source]
config_unused_bits = slice(1, 28, None)
dataword
dataword_bits = slice(3, 13, None)
export()[source]

Return a dict representation of this Packet.

fifo_full_bit = 1
fifo_full_flag
fifo_half_bit = 2
fifo_half_flag
has_valid_parity()[source]
num_bytes = 7
packet_type
packet_type_bits = slice(52, 54, None)
parity_bit = 0
parity_bit_value
parity_calc_bits = slice(1, 54, None)
register_address
register_address_bits = slice(36, 44, None)
register_data
register_data_bits = slice(28, 36, None)
size = 54
test_counter
test_counter_bits_11_0 = slice(1, 13, None)
test_counter_bits_15_12 = slice(40, 44, None)
timestamp
timestamp_bits = slice(13, 37, None)
class larpix.larpix.PacketCollection(packets, bytestream=None, message='', read_id=None, skipped=None)[source]

Bases: object

Represents a group of packets that were sent to or received from LArPix.

Index into the PacketCollection as if it were a list:

>>> collection[0]
Packet(b'')
>>> first_ten = collection[:10]
>>> len(first_ten)
10
>>> type(first_ten)
larpix.larpix.PacketCollection
>>> first_ten.message
'my packets | subset slice(None, 10, None)'

To view the bits representation, add ‘bits’ to the index:

>>> collection[0, 'bits']
'00000000 00000000 00000000 00000000 00000000 00000000 000111'
>>> bits_format_first_10 = collection[:10, 'bits']
>>> type(bits_format_first_10[0])
str
by_chipid()[source]

Return a dict of { chipid: PacketCollection }.

extract(attr, **selection)[source]

Extract the given attribute from packets specified by selection and return a list.

Any key used in Packet.export is a valid attribute or selection:

  • all packets:
    • bits
    • type (data, test, config read, config write)
    • chipid
    • parity
    • valid_parity
  • data packets:
    • channel
    • timestamp
    • adc_count
    • fifo_half
    • fifo_full
  • test packets:
    • counter
  • config packets:
    • register
    • value

Usage:

>>> # Return a list of adc counts from any data packets
>>> adc_data = collection.extract('adc_counts')
>>> # Return a list of timestamps from chip 2 data
>>> timestamps = collection.extract('timestamp', chipid=2)
>>> # Return the most recently read global threshold from chip 5
>>> threshold = collection.extract('value', register=32, type='config read', chip=5)[-1]
from_dict(d)[source]

Load the information in the dict into this PacketCollection.

origin()[source]

Return the original PacketCollection that this PacketCollection derives from.

to_dict()[source]

Export the information in this PacketCollection to a dict.

with_chipid(chipid)[source]

Return packets with the specified chip ID.

class larpix.larpix.SerialPort(port=None, baudrate=9600, timeout=None)[source]

Bases: object

Wrapper for various serial port interfaces across platforms

close()[source]

Close the port

classmethod guess_port()[source]

Guess at correct port name based on platform

open()[source]

Open the port

read(nbytes)[source]

Read data from serial port

write(data)[source]

Write data to serial port

class larpix.larpix.Smart_List(values, low, high)[source]

Bases: list

larpix.larpix.disable_logger()[source]

Disable serial data logger

larpix.larpix.enable_logger(filename=None)[source]

Enable serial data logger

larpix.larpix.flush_logger()[source]

Flush serial data logger data to output file