def test_record(tmpdir):
    logger = HDF5Logger(directory=str(tmpdir), buffer_length=1)
    logger.open()

    logger.record([Packet()], timestamp=5.0)
    assert logger._buffer['raw_packet'][0] == HDF5Logger.encode(Packet(),
                                                                timestamp=5.0)
def test_close(tmpdir):
    logger = HDF5Logger(directory=str(tmpdir))
    logger.open()

    logger.close()
    assert not logger.is_enabled()
    assert not logger.is_open()
def get_baseline_selftrigger(c, chip):
    # Capture Baseline for all channels one by one

    # Turn on periodic_reset
    chip.config.enable_periodic_reset = 1
    # Reduce global threshold to get baseline data
    chip.config.threshold_global = 5
    # Extend the time for conversion as long as possible
    #chip.config.sample_cycles=150
    #chip.config.sample_cycles=1 #(set to default starting 2/21/2020)
    c.write_configuration(chip.chip_key)
    c.verify_configuration(chip.chip_key)

    subprocess.run(["rm", "testing.h5"])

    #logger declared and switched enabledc.
    c.logger = HDF5Logger("testing.h5", buffer_length=1000000)
    #c.logger = HDF5Logger("testing.h5", buffer_length=10000)
    c.logger.enable()
    c.logger.is_enabled()

    c.verify_configuration(chip.chip_key)
    print(chip.config)

    ReadChannelLoop(c, chip, 0, NumASICchannels - 1, 0)

    print("the end")

    c.logger.disable()
    #c.logger.flush()
    #c.logger.close()

    import socket_baselines
def test_disable(tmpdir):
    logger = HDF5Logger(directory=str(tmpdir))
    logger.open()

    logger.disable()
    assert not logger.is_enabled()
    logger.record([Packet()])
    assert len(logger._buffer['raw_packet']) == 0
def test_enable(tmpdir):
    logger = HDF5Logger(directory=str(tmpdir), buffer_length=1)
    logger.open()

    logger.enable()
    assert logger.is_enabled()
    logger.record([Packet()])
    assert len(logger._buffer['raw_packet']) == 1
def test_controller_write_capture(tmpdir, chip):
    controller = Controller()
    controller.logger = HDF5Logger(directory=str(tmpdir), buffer_length=1)
    controller.logger.enable()
    controller.chips[chip.chip_key] = chip
    controller.write_configuration(chip.chip_key, 0)
    packet = chip.get_configuration_packets(Packet.CONFIG_WRITE_PACKET)[0]
    assert len(controller.logger._buffer['packets']) == 1
def test_controller_read_capture(tmpdir):
    controller = Controller()
    controller.io = FakeIO()
    controller.io.queue.append(([Packet()], b'\x00\x00'))
    controller.logger = HDF5Logger(directory=str(tmpdir), buffer_length=1)
    controller.logger.enable()
    controller.run(0.1, 'test')
    assert len(controller.logger._buffer['packets']) == 1
def test_open_deprecated_3_0_0(tmpdir):
    logger = HDF5Logger(directory=str(tmpdir))
    with pytest.warns(DeprecationWarning):
        logger.open()

    assert logger.is_enabled()
    with pytest.warns(DeprecationWarning):
        assert logger.is_open()
def test_record_deprecated_3_0_0(tmpdir):
    logger = HDF5Logger(directory=str(tmpdir))
    with pytest.warns(DeprecationWarning):
        logger.open()

    logger.record([Packet()])
    assert len(logger._buffer['packets']) == 1
    logger.record([TimestampPacket(timestamp=123)])
    assert len(logger._buffer['packets']) == 2
def test_enable(tmpdir):
    logger = HDF5Logger(directory=str(tmpdir))
    assert not logger.is_enabled()
    logger.record([Packet()])
    assert len(logger._buffer['packets']) == 0
    logger.enable()
    assert logger.is_enabled()
    logger.record([Packet()])
    assert len(logger._buffer['packets']) == 1
def test_disable_deprecated_3_0_0(tmpdir):
    logger = HDF5Logger(directory=str(tmpdir))
    with pytest.warns(DeprecationWarning):
        logger.open()

    logger.disable()
    assert not logger.is_enabled()
    logger.record([Packet()])
    assert len(logger._buffer['packets']) == 0
def test_controller_read_capture_deprecated_3_0_0(tmpdir):
    controller = Controller()
    controller.io = FakeIO()
    controller.io.queue.append(([Packet()], b'\x00\x00'))
    controller.logger = HDF5Logger(directory=str(tmpdir), buffer_length=1)
    with pytest.warns(DeprecationWarning):
        controller.logger.open()
    controller.run(0.1, 'test')
    assert len(controller.logger._buffer['packets']) == 1
def test_controller_write_capture_deprecated_3_0_0(tmpdir, chip):
    controller = Controller()
    controller.logger = HDF5Logger(directory=str(tmpdir), buffer_length=1)
    with pytest.warns(DeprecationWarning):
        controller.logger.open()
    controller.chips[chip.chip_key] = chip
    controller.write_configuration(chip.chip_key, 0)
    packet = chip.get_configuration_packets(Packet.CONFIG_WRITE_PACKET)[0]
    assert len(controller.logger._buffer['packets']) == 1
Esempio n. 14
0
def test_controller_write_capture(tmpdir):
    controller = Controller()
    controller.logger = HDF5Logger(directory=str(tmpdir), buffer_length=1)
    controller.logger.open()
    controller.chips[0] = Chip(2, 0)
    chip = controller.chips[0]
    controller.write_configuration(0, 0)
    packet = chip.get_configuration_packets(Packet.CONFIG_WRITE_PACKET)[0]
    assert len(controller.logger._buffer) == 1
def test_flush(tmpdir):
    logger = HDF5Logger(directory=str(tmpdir), buffer_length=5, enabled=True)
    logger.record([Packet()])
    assert len(logger._buffer['packets']) == 1
    logger.flush()
    assert len(logger._buffer['packets']) == 0
    logger.record([Packet()] * 5)
    assert len(logger._buffer['packets']) == 5
    logger.record([Packet()])
    assert len(logger._buffer['packets']) == 0
Esempio n. 16
0
def get_baseline_periodicselftrigger(c, chip):
    # Capture Baseline for all channels one by one

    # Turn on periodic_reset
    chip.config.enable_periodic_reset = 1
    #chip.config.periodic_reset_cycles = 1000000
    # Reduce global threshold to get baseline data
    chip.config.threshold_global = 250
    # Extend the time for conversion as long as possible
    #chip.config.sample_cycles=150
    #chip.config.sample_cycles=1 #(set to default starting 2/21/2020)
    # for v2 sample_cycles -> adc_hold_delay
    #chip.config.adc_hold_delay=150
    #chip.config.adc_hold_delay=1 #(set to default starting 2/21/2020)
    # enable periodic trigger
    chip.config.enable_periodic_trigger = 1
    chip.config.periodic_trigger_mask = [0] * NumASICchannels
    chip.config.enable_hit_veto = 0
    # set trigger period (100ns*period_trigger_cycles)
    chip.config.periodic_trigger_cycles = 1000  # 1k = 0.1ms
    #chip.config.periodic_trigger_cycles=10000 # 10k = 1ms
    #chip.config.periodic_trigger_cycles=20000 # 20k = 2ms
    #chip.config.periodic_trigger_cycles=100000 # 100k = 10ms
    #chip.config.periodic_trigger_cycles=1000000 # 1000k = 100ms
    c.write_configuration(chip.chip_key)
    c.verify_configuration(chip.chip_key)

    subprocess.run(["rm", "testing.h5"])

    #logger declared and switched enabledc.
    c.logger = HDF5Logger("testing.h5", buffer_length=1000000)
    #c.logger = HDF5Logger("testing.h5", buffer_length=10000)
    c.logger.enable()
    c.logger.is_enabled()

    c.verify_configuration(chip.chip_key)
    print(chip.config)
    print("Starting ReadChannelLoop...")

    ReadChannelLoop(c, chip, 0, NumASICchannels - 1, 0)

    print("the end")

    c.logger.disable()
    #c.logger.flush()
    #c.logger.close()

    # turn off periodic trigger channels
    chip.config.periodic_trigger_mask = [1] * NumASICchannels
    chip.config.enable_periodic_trigger = 0
    c.write_configuration(chip.chip_key)

    import socket_baselines
Esempio n. 17
0
def test_flush(tmpdir):
    logger = HDF5Logger(directory=str(tmpdir), buffer_length=5)
    logger.open()

    logger.record([Packet()])
    assert len(logger._buffer['raw_packet']) == 1
    logger.flush()
    assert len(logger._buffer['raw_packet']) == 0
    logger.record([Packet()] * 5)
    assert len(logger._buffer['raw_packet']) == 5
    logger.record([Packet()])
    assert len(logger._buffer['raw_packet']) == 0
def test_flush_deprecated_3_0_0(tmpdir):
    logger = HDF5Logger(directory=str(tmpdir), buffer_length=5)
    with pytest.warns(DeprecationWarning):
        logger.open()

    logger.record([Packet()])
    assert len(logger._buffer['packets']) == 1
    logger.flush()
    assert len(logger._buffer['packets']) == 0
    logger.record([Packet()] * 5)
    assert len(logger._buffer['packets']) == 5
    logger.record([Packet()])
    assert len(logger._buffer['packets']) == 0
Esempio n. 19
0
def quickcontroller(board='pcb-5',
                    interactive=False,
                    io=None,
                    logger=None,
                    log_filepath=None):
    '''Quick jump through all controller creation and config steps'''
    controller_config = 'controller/{}_chip_info.json'.format(board)
    if io is None:
        io_config = 'io/daq-srv1.json'
        io = ZMQ_IO(io_config)
    if logger is None:
        logger = HDF5Logger(filename=log_filepath)
        logger.open()
    controller = larpix.Controller()
    controller.io = io
    controller.logger = logger
    controller.load(controller_config)
    silence_chips(controller, interactive)
    set_config_physics(controller, interactive)
    return controller
Esempio n. 20
0
def get_baseline_periodicexttrigger(c, chip):
    # Capture Baseline for all channels

    # Turn on periodic_reset
    chip.config.enable_periodic_reset = 1
    # Reduce global threshold to get baseline data
    chip.config.threshold_global = 255
    # Extend the time for conversion as long as possible
    #chip.config.sample_cycles=255
    # No more sample_cycles in v2?
    #chip.config.sample_cycles=1 #(set to default starting 2/21/2020)
    c.write_configuration(chip.chip_key)
    c.verify_configuration(chip.chip_key)

    subprocess.run(["rm", "testing2.h5"])

    chip.config.channel_mask = [0] * NumASICchannels  # Turn ON all channels
    chip.config.external_trigger_mask = [
        0
    ] * NumASICchannels  # Turn ON all channels
    c.write_configuration(chip.chip_key)
    c.verify_configuration(chip.chip_key)
    print(chip.config)

    #logger declared and switched enabledc.
    c.logger = HDF5Logger("testing2.h5", buffer_length=1000000)
    #c.logger = HDF5Logger("testing.h5", buffer_length=10000)
    c.logger.enable()
    c.logger.is_enabled()

    c.run(10, 'test')
    print("read ", len(c.reads[-1]))
    print("the end")

    c.logger.disable()
    #c.logger.flush()
    #c.logger.close()

    import socket_baselines2
Esempio n. 21
0
def get_leakage_data():
    # This part is not quite ready yet.
    # Still not ready 20200212 - required thresh values depend on channel
    # and you only want ot do it on channels that are good so far.

    # Turn off periodic_reset
    chip.config.enable_periodic_reset = 0  # turn off periodic reset
    chip.config.channel_mask = [1] * NumASICchannels  # Turn off all channels
    c.write_configuration(chip.chip_key)
    c.verify_configuration(chip.chip_key)

    for thresh in [25, 27, 30, 35]:
        setGlobalThresh(thresh)
        outfile = "testing" + str(thresh) + ".h5"
        print("Writing ", outfile)
        #logger declared and switched enabledc.
        c.logger = HDF5Logger(outfile, buffer_length=1000000)
        #c.logger = HDF5Logger("testing.h5", buffer_length=10000)
        c.logger.enable()
        c.logger.is_enabled()
        # Configure one channel to be on.
        for chan in range(NumASICchannels):
            print("running channel ", chan)
            if socket_baselines.mean[chan] > 240 or socket_baselines.sdev[
                    chan] < 2:
                continue
            chip.config.channel_mask = [
                1
            ] * NumASICchannels  # Turn off all channels
            chip.config.channel_mask[chan] = 0  # turn ON this channel
            c.write_configuration(chip.chip_key)
            c.verify_configuration(chip.chip_key)
            # Read some Data (this also delays a bit)
            c.run(1, 'test')
            print(c.reads[-1])
            print("the end")
        c.logger.disable()
        #c.logger.flush()
        c.logger.close()
Esempio n. 22
0
def quickcontroller(board='pcb-1',
                    interactive=False,
                    io=None,
                    logger=None,
                    log_filepath=None):
    '''Quick jump through all controller creation and config steps'''
    if io is None:
        io = ZMQ_IO('tcp://10.0.1.6')
        # io = SerialPort(baudrate=1000000,
        # timeout=0.01)
    enable_logger()
    cont = create_controller(io=io)
    if logger is None:
        cont.logger = HDF5Logger(filename=log_filepath)
    cont.logger.open()
    init_controller(cont, board)
    silence_chips(cont, interactive)
    if cont.board_info['name'] == 'unknown':
        # Find and load chip info
        settings = {'controller': cont}
        cont.chips = get_chip_ids(**settings)
    set_config_physics(cont, interactive)
    #flush_stale_data(cont)
    return cont
if not c.verify_configuration():
    print("verify configuration failed!")
    exit()

c.enable(chip_key, [5])
c.chips[chip_key].config.sample_cycles = 255
#c.enable_analog_monitor(chip_key, 26)
c.enable_testpulse(chip_key, [5], start_dac=200)
c.write_configuration(chip_key)

if not c.verify_configuration():
    print("verify configuration failed!")
    exit()

#logger declared and switched enabled
c.logger = HDF5Logger(None, True)
c.logger.enable()
c.logger.is_enabled()

c.verify_configuration(chip_key)
print(c.chips[chip_key].config)

min_dac = 110
max_count = 1000
count = 0

while (count < max_count):
    while (c.chips[chip_key].config.csa_testpulse_dac_amplitude > min_dac
           and count < max_count):
        c.issue_testpulse(chip_key, 5, min_dac=100)
        #print(c.reads[-1])
Esempio n. 24
0
def test_disable(tmpdir):
    logger = HDF5Logger(directory=str(tmpdir), enabled=True)
    logger.disable()
    assert not logger.is_enabled()
    logger.record([Packet_v2()])
    assert len(logger._buffer['packets']) == 0
def test_tutorial(capsys, tmpdir, temp_logfilename):
    from larpix.larpix import Controller, Packet

    from larpix.io.fakeio import FakeIO
    from larpix.logger.stdout_logger import StdoutLogger
    controller = Controller()
    controller.io = FakeIO()
    controller.logger = StdoutLogger(buffer_length=0)
    controller.logger.enable()

    chip_key = '1-1-5'
    chip5 = controller.add_chip(chip_key)
    chip5 = controller.get_chip(chip_key)

    from larpix.larpix import Key
    example_key = Key('1-2-3')

    assert example_key.io_group == 1
    assert example_key.io_channel == 2
    assert example_key.chip_id == 3
    example_key.to_dict()

    chip5.config.global_threshold = 35  # entire register = 1 number
    chip5.config.periodic_reset = 1  # one bit as part of a register
    chip5.config.channel_mask[20] = 1  # one bit per channel

    controller.write_configuration(chip_key)  # send all registers
    controller.write_configuration(chip_key, 32)  # send only register 32
    controller.write_configuration(chip_key,
                                   [32, 50])  # send registers 32 and 50

    global_threshold_reg = chip5.config.global_threshold_address

    packets = chip5.get_configuration_packets(Packet.CONFIG_READ_PACKET)
    bytestream = b'bytes for the config read packets'
    controller.io.queue.append((packets, bytestream))

    controller.read_configuration(chip_key)

    packets = [Packet()] * 40
    bytestream = b'bytes from the first set of packets'
    controller.io.queue.append((packets, bytestream))
    packets2 = [Packet()] * 30
    bytestream2 = b'bytes from the second set of packets'
    controller.io.queue.append((packets2, bytestream2))

    controller.start_listening()
    # Data arrives...
    packets, bytestream = controller.read()
    # More data arrives...
    packets2, bytestream2 = controller.read()
    controller.stop_listening()
    message = 'First data arrived!'
    message2 = 'More data arrived!'
    controller.store_packets(packets, bytestream, message)
    controller.store_packets(packets, bytestream2, message2)

    packets = [Packet()] * 5
    bytestream = b'[bytes from read #%d] '
    for i in range(100):
        controller.io.queue.append((packets, bytestream % i))

    duration = 0.1  # seconds
    message = '10-second data run'
    controller.run(duration, message)

    run1 = controller.reads[0]
    first_packet = run1[0]  # Packet object
    first_ten_packets = run1[0:10]  # smaller PacketCollection object

    first_packet_bits = run1[0,
                             'bits']  # string representation of bits in packet
    first_ten_packet_bits = run1[0:10, 'bits']  # list of strings

    print(run1)  # prints the contents of the packets
    print(run1[10:30])  # prints 20 packets from the middle of the run

    packet = run1[0]
    # all packets
    packet.packet_type  # unique in that it gives the bits representation
    packet.chipid  # all other properties return Python numbers
    packet.chip_key  # key for association to a unique chip
    packet.parity_bit_value
    # data packets
    packet.channel_id
    packet.dataword
    packet.timestamp
    assert packet.fifo_half_flag in (1, 0)
    assert packet.fifo_full_flag in (1, 0)
    # config packets
    packet.register_address
    packet.register_data
    # test packets
    packet.test_counter

    from larpix.logger.h5_logger import HDF5Logger
    controller.logger = HDF5Logger(
        filename=temp_logfilename, directory=str(tmpdir), buffer_length=10000
    )  # a filename of None uses the default filename formatting
    controller.logger.enable(
    )  # opens hdf5 file and starts tracking all communications

    controller.logger = HDF5Logger(filename=temp_logfilename,
                                   directory=str(tmpdir),
                                   enabled=True)

    controller.verify_configuration()
    controller.logger.flush()

    controller.logger.disable()  # stop tracking
    # any communication here is ignored
    controller.logger.enable()  # start tracking again
    controller.logger.is_enabled()  # returns True if tracking

    controller.logger.disable()

    import h5py
    datafile = h5py.File(tmpdir.join(temp_logfilename))

    assert '_header' in datafile.keys()
    assert 'packets' in datafile.keys()
    assert 'messages' in datafile.keys()
    assert list(
        datafile['_header'].attrs) == ['created', 'modified', 'version']

    raw_value = datafile['packets'][
        0]  # e.g. (b'0-246', 3, 246, 1, 1, -1, -1, -1, -1, -1, -1, 0, 0)
    raw_values = datafile['packets'][-100:]  # last 100 packets in file

    packet_repr = raw_values[0:1]
    packet_repr['chip_key']  # chip key for packet, e.g. b'1-1-246'
    packet_repr['adc_counts']  # list of ADC values for each packet
    packet_repr.dtype  # description of data type (with names of each column)

    datafile.close()
def test_record(tmpdir):
    logger = HDF5Logger(directory=str(tmpdir), enabled=True)
    logger.record([Packet()])
    assert len(logger._buffer['packets']) == 1
    logger.record([TimestampPacket(timestamp=123)])
    assert len(logger._buffer['packets']) == 2