diff --git a/aidatlu/main/data_parser.py b/aidatlu/main/data_parser.py index 5ffa803..af4a70f 100644 --- a/aidatlu/main/data_parser.py +++ b/aidatlu/main/data_parser.py @@ -2,6 +2,7 @@ import tables as tb from aidatlu import logger import logging +import numba class DataParser(object): @@ -37,7 +38,12 @@ def parse(self, filepath_in: str, filepath_out: str) -> None: """ table = self.read_file(filepath_in) data = self.transform_data( - table["w0"], table["w1"], table["w2"], table["w3"], table["w4"], table["w5"] + table["raw"][::6], + table["raw"][1::6], + table["raw"][2::6], + table["raw"][3::6], + table["raw"][4::6], + table["raw"][5::6], ) self.write_data(filepath_out, data) @@ -52,16 +58,7 @@ def read_file(self, filepath: str) -> list: Returns: table: pytable of the raw data """ - data = np.dtype( - [ - ("w0", "u4"), - ("w1", "u4"), - ("w2", "u4"), - ("w3", "u4"), - ("w4", "u4"), - ("w5", "u4"), - ] - ) + data = np.dtype([("raw", "u4")]) with tb.open_file(filepath, "r") as file: table = file.root.raw_data raw_data = np.array(table[:], dtype=data) @@ -105,6 +102,8 @@ def transform_data( Returns: np.array: array with coloumns """ + if np.any(w5) != 0: + self.log.warning("Corrupted Data found") out_array = np.zeros(len(w3), dtype=self.features) out_array["eventnumber"] = w3 out_array["timestamp"] = (w0 & 0x0000FFFF << 32) + w1 @@ -145,7 +144,6 @@ def write_data(self, filepath: str, data: np.array) -> None: 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) config_table = h5_file.create_table( h5_file.root, @@ -153,4 +151,3 @@ def write_data(self, filepath: str, data: np.array) -> None: description=config, ) config_table.append(self.conf) - # h5_file.create_group(h5_file.root, "configuration", self.config) diff --git a/aidatlu/main/tlu.py b/aidatlu/main/tlu.py index 2ab08f4..5bad6b7 100644 --- a/aidatlu/main/tlu.py +++ b/aidatlu/main/tlu.py @@ -6,6 +6,7 @@ from datetime import datetime import zmq from pathlib import Path +import time from aidatlu.hardware.i2c import I2CCore from aidatlu.hardware.clock_controller import ClockControl @@ -263,14 +264,10 @@ def pull_fifo_event(self) -> list: list: 6 element long vector containing bitwords of the data. """ event_numb = self.get_event_fifo_fill_level() - fifo_status = self.get_event_fifo_csr() - if event_numb * 6 == 0xFEA: - self.log.warning("FIFO is full") - fifo_content = self.i2c_hw.getNode("eventBuffer.EventFifoData").readBlock( - event_numb - ) - self.i2c_hw.dispatch() - if event_numb and event_numb % 6 == 0: + # fifo_status = self.get_event_fifo_csr() + if event_numb: + if event_numb * 6 == 0xFEA: + self.log.warning("FIFO is full") fifo_content = self.i2c_hw.getNode("eventBuffer.EventFifoData").readBlock( event_numb ) @@ -291,12 +288,7 @@ def init_raw_data_table(self) -> None: """Initializes the raw data table, where the raw FIFO data is found.""" self.data = np.dtype( [ - ("w0", "u4"), - ("w1", "u4"), - ("w2", "u4"), - ("w3", "u4"), - ("w4", "u4"), - ("w5", "u4"), + ("raw", "u4"), ] ) @@ -317,9 +309,6 @@ 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 - # ) config_table = self.h5_file.create_table( self.h5_file.root, name="conf", @@ -446,18 +435,13 @@ def run(self) -> None: while run_active: try: + time.sleep(0.000001) last_time = self.get_timestamp() current_time = (last_time - start_time) * 25 / 1000000000 current_event = self.pull_fifo_event() try: - if save_data: - if np.size(current_event) > 1: - # This additional loop is needed because the event fifo can have multiple events in dependence of the trigger rate. - for event_vec in np.split( - current_event, len(current_event) / 6 - ): - # TODO Carefull if save data is active at high trigger rates than the RUN LOOP is to slow above around 24 kHz - self.data_table.append(event_vec) + if save_data and np.size(current_event) > 1: + self.data_table.append(current_event) except: if KeyboardInterrupt: run_active = False @@ -471,11 +455,11 @@ def run(self) -> None: # self.log_trigger_inputs(current_event) # self.log.warning(str(current_event)) - # This loop sents which inputs produced the trigger signal for the first event. + # # This loop sents which inputs produced the trigger signal for the first event. if ( np.size(current_event) > 1 ) and first_event: # TODO only first event? - self.log_trigger_inputs(current_event) + self.log_trigger_inputs(current_event[0:6]) first_event = False # Stops the TLU after some time in seconds. diff --git a/aidatlu/test/interpreted_data.h5 b/aidatlu/test/interpreted_data.h5 index 1932c58..f932b2a 100644 Binary files a/aidatlu/test/interpreted_data.h5 and b/aidatlu/test/interpreted_data.h5 differ diff --git a/aidatlu/test/raw_data_test.h5 b/aidatlu/test/raw_data_test.h5 index 98a6195..161a025 100644 Binary files a/aidatlu/test/raw_data_test.h5 and b/aidatlu/test/raw_data_test.h5 differ