Skip to content

Commit

Permalink
ENH: better configuration display in h5 files
Browse files Browse the repository at this point in the history
  • Loading branch information
rpartzsch committed Jul 3, 2024
1 parent 6c7143f commit 0bf74b1
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 8 deletions.
1 change: 1 addition & 0 deletions aidatlu/hardware/trigger_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from aidatlu.hardware.utils import _pack_bits
from aidatlu import logger


class TriggerLogic(object):
def __init__(self, i2c: I2CCore) -> None:
self.log = logger.setup_derived_logger("Trigger Controller")
Expand Down
49 changes: 49 additions & 0 deletions aidatlu/main/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,55 @@ def configure(self) -> None:
self.tlu.set_enable_record_data(1)
self.log.success("TLU configured")

def get_configuration_table(self) -> list:
"""Creates the configuration list to save in the data files
Returns:
list: configuration list
"""
conf = [
(
"internal_trigger_rate",
self.conf["internal_trigger"]["internal_trigger_rate"],
),
("DUT_1", self.conf["dut_module"]["dut_1"]["mode"]),
("DUT_2", self.conf["dut_module"]["dut_2"]["mode"]),
("DUT_3", self.conf["dut_module"]["dut_3"]["mode"]),
("DUT_4", self.conf["dut_module"]["dut_4"]["mode"]),
("threshold_1", self.conf["trigger_inputs"]["threshold"]["threshold_1"]),
("threshold_2", self.conf["trigger_inputs"]["threshold"]["threshold_2"]),
("threshold_3", self.conf["trigger_inputs"]["threshold"]["threshold_3"]),
("threshold_4", self.conf["trigger_inputs"]["threshold"]["threshold_4"]),
("threshold_5", self.conf["trigger_inputs"]["threshold"]["threshold_3"]),
("threshold_6", self.conf["trigger_inputs"]["threshold"]["threshold_4"]),
(
"trigger_inputs_logic",
"%s" % (self.conf["trigger_inputs"]["trigger_inputs_logic"]),
),
(
"trigger_signal_shape_stretch",
"%s"
% str(self.conf["trigger_inputs"]["trigger_signal_shape"]["stretch"]),
),
(
"trigger_signal_shape_delay",
"%s"
% str(self.conf["trigger_inputs"]["trigger_signal_shape"]["delay"]),
),
(
"enable_clock_lemo_output",
self.conf["clock_lemo"]["enable_clock_lemo_output"],
),
("pmt_control_1", self.conf["pmt_control"]["pmt_1"]),
("pmt_control_2", self.conf["pmt_control"]["pmt_2"]),
("pmt_control_3", self.conf["pmt_control"]["pmt_3"]),
("pmt_control_4", self.conf["pmt_control"]["pmt_4"]),
("save_data", self.conf["save_data"]),
("output_data_path", self.conf["output_data_path"]),
("zmq_connection", self.conf["zmq_connection"]),
]
return conf

def get_data_handling(self) -> tuple:
"""Information about data handling.
Expand Down
16 changes: 14 additions & 2 deletions aidatlu/main/data_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def read_file(self, filepath: str) -> list:
with tb.open_file(filepath, "r") as file:
table = file.root.raw_data
raw_data = np.array(table[:], dtype=data)
self.config = str(file.root.configuration).split(" ", 2)[2]
self.conf = np.array(file.root.conf[:])
return raw_data

def _create_table(self, out_file, name, title, dtype):
Expand Down Expand Up @@ -135,10 +135,22 @@ def write_data(self, filepath: str, data: np.array) -> None:
data (table): raw data
"""
# filter_data = tb.Filters(complib='blosc', complevel=5)
config = np.dtype(
[
("attribute", "S32"),
("value", "S32"),
]
)
with tb.open_file(filepath, mode="w", title="TLU_interpreted") as h5_file:
data_table = self._create_table(
h5_file, name="interpreted_data", title="data", dtype=self.features
)
# data_table = h5_file.create_table(h5_file.root, name='interpreted_data', description=features , title='data', filters=filter_data)
data_table.append(data)
h5_file.create_group(h5_file.root, "configuration", self.config)
config_table = h5_file.create_table(
h5_file.root,
name="conf",
description=config,
)
config_table.append(self.conf)
# h5_file.create_group(h5_file.root, "configuration", self.config)
22 changes: 20 additions & 2 deletions aidatlu/main/tlu.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def __init__(self, hw, config_path, clock_config_path) -> None:
def configure(self) -> None:
"""loads the conf.yaml and configures the TLU accordingly."""
self.config_parser.configure()
self.conf_list = self.config_parser.get_configuration_table()
self.get_event_fifo_fill_level()
self.get_event_fifo_csr()
self.get_scalar()
Expand Down Expand Up @@ -297,6 +298,14 @@ def init_raw_data_table(self) -> None:
("w5", "u4"),
]
)

config = np.dtype(
[
("attribute", "S32"),
("value", "S32"),
]
)

self.filter_data = tb.Filters(complib="blosc", complevel=5)
self.h5_file = tb.open_file(self.raw_data_path, mode="w", title="TLU")
self.data_table = self.h5_file.create_table(
Expand All @@ -306,10 +315,17 @@ def init_raw_data_table(self) -> None:
title="data",
filters=self.filter_data,
)
self.h5_file.create_group(
self.h5_file.root, "configuration", self.config_parser.conf
# self.h5_file.create_group(
# self.h5_file.root, "configuration", self.config_parser.conf
# )
config_table = self.h5_file.create_table(
self.h5_file.root,
name="conf",
description=config,
filters=self.filter_data,
)
self.buffer = []
config_table.append(self.conf_list)

def log_sent_status(self, time: int) -> None:
"""Logs the status of the TLU run with trigger number, runtime usw.
Expand Down Expand Up @@ -411,6 +427,8 @@ def run(self) -> None:
self.path = self.config_parser.get_output_data_path()
if self.path == None:
self.path = "tlu_data/"
if __name__ == "__main__":
self.path = "../tlu_data/"
self.raw_data_path = self.path + "tlu_raw_run%s_%s.h5" % (
self.run_number,
datetime.now().strftime("%Y_%m_%d_%H_%M_%S"),
Expand Down
2 changes: 0 additions & 2 deletions aidatlu/test/hardware_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from aidatlu.main.tlu import AidaTLU
from aidatlu.hardware.i2c import I2CCore
from aidatlu.hardware.ioexpander_controller import IOControl
Expand All @@ -11,7 +10,6 @@
import uhal
import time
import numpy as np
import uhal


class Test_IOCControl:
Expand Down
Binary file modified aidatlu/test/interpreted_data.h5
Binary file not shown.
Binary file modified aidatlu/test/raw_data_test.h5
Binary file not shown.
1 change: 0 additions & 1 deletion aidatlu/test/software_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import yaml
import numpy as np
import tables as tb
Expand Down
1 change: 0 additions & 1 deletion aidatlu/test/test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from aidatlu.main.tlu import AidaTLU
from aidatlu.hardware.i2c import I2CCore
from aidatlu.hardware.utils import _set_bit
Expand Down

0 comments on commit 0bf74b1

Please sign in to comment.