From a02c8a0833f2758fa6bce2b1c92a194e0fc68ce4 Mon Sep 17 00:00:00 2001 From: jwaiton Date: Tue, 13 Jan 2026 16:07:30 +0000 Subject: [PATCH 01/23] implement multichannel plotting and cosmetics --- core/controller.py | 30 +++++++++++++++++------------- ui/oscilloscope.py | 26 ++++++++++++++++---------- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/core/controller.py b/core/controller.py index 3f971ce..be52f73 100644 --- a/core/controller.py +++ b/core/controller.py @@ -35,8 +35,8 @@ from queue import Queue, Empty class Controller: - def __init__(self, - dig_config: Optional[str] = None, + def __init__(self, + dig_config: Optional[str] = None, rec_config: Optional[str] = None): ''' Initialise controller for GUI and digitiser @@ -79,7 +79,7 @@ def __init__(self, self.worker.start() logging.info("Acquisition worker thread started.") - # Multi channel writes to h5 + # Multi channel writes to h5 self.ch_mapping = self.get_ch_mapping() self.num_ch = len(self.ch_mapping) self.h5_flush_size = self.rec_dict['h5_flush_size'] @@ -108,6 +108,10 @@ def __init__(self, def get_ch_mapping(self): ''' Extract what channels are being used map them: ch -> index + + So shape will be: + mapping = {0 : 0, 3 : 1, 5 : 2} + for the case where ch0, 3, and 5 are enabled ''' mapping = {} i = 0 @@ -132,16 +136,16 @@ def data_handling(self): break try: - # you must pass wf_size and ADCs through. + # you must pass wf_size and ADCs through. wf_size, ADCs, ch = data # update visuals - self.main_window.screen.update_ch(np.arange(0, wf_size, dtype=wf_size.dtype), ADCs) - + self.main_window.screen.update_ch(np.arange(0, wf_size, dtype=wf_size.dtype), ADCs, ch) + # ping the tracker (make this optional) self.tracker.track(ADCs.nbytes) - # push data to writer buffer + # push data to writer buffer if self.recording: write_data = wf_size, ADCs, self.event_counter @@ -149,7 +153,7 @@ def data_handling(self): ch = int(ch) i = int(self.ch_mapping[ch]) self.writer_buffers[i].put(write_data) - + self.event_counter += 1 except Exception as e: @@ -166,7 +170,7 @@ def update_fps(self): def run_app(self): self.main_window.show() return self.app.exec() - + def connect_digitiser(self): ''' Connect to the digitiser using the provided configuration file. @@ -193,7 +197,7 @@ def start_acquisition(self): ''' logging.info("Starting acquisition.") self.cmd_buffer.put(Command(CommandType.START)) - + def stop_acquisition(self): ''' Stop digitiser acquisition. @@ -212,7 +216,7 @@ def start_recording(self): logging.info(f"Writer (channel {w.ch}) thread started.") logging.info("Starting recording.") - + def stop_recording(self): ''' Stop recording data. @@ -221,7 +225,7 @@ def stop_recording(self): self.writer_stop_event.set() for w in self.writers: - w.join(timeout=2) + w.join(timeout=2) logging.info("Stopping recording.") @@ -239,7 +243,7 @@ def shutdown(self): # Writer threads self.writer_stop_event.set() for w in self.writers: - w.join(timeout=2) + w.join(timeout=2) clean_shutdown = True diff --git a/ui/oscilloscope.py b/ui/oscilloscope.py index 70d6d98..c38b1c4 100644 --- a/ui/oscilloscope.py +++ b/ui/oscilloscope.py @@ -55,7 +55,7 @@ def __init__(self, controller, parent=None): class OscilloScopeScreen(pg.PlotWidget): def __init__(self, parent = None, plotItem = None, **kwargs): super().__init__(parent=parent, background='w', plotItem=plotItem, **kwargs) - + styles = {'color': 'k', 'font-size': '12px'} self.setLabel('left', 'Voltage (ADCs)', **styles) self.setLabel('bottom', 'Time (ns)', **styles) @@ -64,15 +64,21 @@ def __init__(self, parent = None, plotItem = None, **kwargs): self.setXRange(0, 1, padding = 0.02) self.setYRange(0, 5, padding = 0.02) - self.pen_ch1 = pg.mkPen(color = "b", width = 1) - self.plot_ch([0,1], [0,0]) - + self.pen_ch = {} + self.channels = {} + # create pens for each channel, and plot the defaults + for ch in self.ch_mapping.keys(): + self.pen_ch[ch] = pg.mkPen(pg.intColor(ch), width = 1) + self.plot_ch([0,1], [0,0], ch) + + self.legend = self.addLegend() + def plot_ch(self, x, y, ch = 1): - self.data_line_ch = self.plot(x, y, pen=self.pen_ch1) + self.channels[ch] = self.plot(x, y, pen=self.pen_ch[ch], name = str(ch)) def update_ch(self, x, y, ch = 1): - self.data_line_ch.setData(x, y) + self.channels[ch].setData(x, y) class MainWindow(QMainWindow): @@ -81,12 +87,12 @@ def __init__(self, controller, *args, **kwargs): # Define interactivity through controller self.controller = controller - + self.setupUI() - + def setupUI(self): self.setWindowTitle("CAEN Acqusition and Readout Program (CARP)") - + self.screen = OscilloScopeScreen() self.control_panel = ControlPanel(self.controller) @@ -109,4 +115,4 @@ def init(): if __name__ == '__main__': - init() \ No newline at end of file + init() From 835b0c1432521dbc1769e34cb8170410fa231faa Mon Sep 17 00:00:00 2001 From: jwaiton Date: Wed, 14 Jan 2026 10:42:55 +0000 Subject: [PATCH 02/23] raise error if output path is invalid --- core/writer.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/core/writer.py b/core/writer.py index b6d5cc0..fd720ac 100644 --- a/core/writer.py +++ b/core/writer.py @@ -3,7 +3,7 @@ import logging import tables as tb -import core.df_classes as df_class +import core.df_classes as df_class import core.io as io @@ -11,11 +11,11 @@ class Writer(Thread): ''' Writes channel data to h5 file. ''' - def __init__(self, - ch : int, - flush_size : int, - write_buffer : Queue, - stop_event : Event, + def __init__(self, + ch : int, + flush_size : int, + write_buffer : Queue, + stop_event : Event, rec_config : dict, dig_config : dict, TIMESTAMP : str,): @@ -41,8 +41,12 @@ def __init__(self, else: file_path = f'{self.ch}_{TIMESTAMP}.h5' # initialise the h5, one per channel, each handled on a separate thread - self.h5file = tb.open_file(f'{file_path}', mode='a') - # configs written + try: + self.h5file = tb.open_file(f'{file_path}', mode='a') + except FileNotFoundError as e: + logging.error(f'FileNotFoundError: Cannot create output file at path {file_path}') + exit() + # configs written io.create_config_table(self.h5file, self.rec_config, 'rec_conf', 'recording config') io.create_config_table(self.h5file, self.dig_config, 'dig_conf', 'digitiser config') # raw waveform group constructed @@ -61,13 +65,13 @@ def write_h5(self): for wf_size, rwf, evt in self.local_buffer: # if we know the size of the waveforms already, don't create the class again. if self.wf_size is None: - self.wf_size = wf_size + self.wf_size = wf_size self.rwf_class = df_class.return_rwf_class(self.dig_config['dig_gen'], self.wf_size) self.rwf_table = self.h5file.create_table(self.rwf_group, 'rwf', self.rwf_class, "raw waveforms") self.rows = self.rwf_table.row - self.rows['evt_no'] = evt - self.rows['rwf'] = rwf + self.rows['evt_no'] = evt + self.rows['rwf'] = rwf self.rows.append() self.local_buffer.clear() From 3d5b41e0e2614d16445e6a490a355a409ca22623 Mon Sep 17 00:00:00 2001 From: jwaiton Date: Wed, 14 Jan 2026 10:58:19 +0000 Subject: [PATCH 03/23] remove generic log --- CAENBoard_GENERICLog.txt | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 CAENBoard_GENERICLog.txt diff --git a/CAENBoard_GENERICLog.txt b/CAENBoard_GENERICLog.txt deleted file mode 100644 index ed3a60d..0000000 --- a/CAENBoard_GENERICLog.txt +++ /dev/null @@ -1,2 +0,0 @@ -[ 0.009][EE][CAENBoard_GENERIC.c::2526]: Open digitizer failed due to a comm error: -1 -[ 0.009][EE][CAENDPPLayer.c::118]: From c_newDigitizer: Error Calling CAENDigitizer API From c07e26618e70c114066d344f2c05cbc58d67881f Mon Sep 17 00:00:00 2001 From: jwaiton Date: Wed, 14 Jan 2026 11:46:22 +0000 Subject: [PATCH 04/23] allow multi channel readout --- ui/oscilloscope.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/ui/oscilloscope.py b/ui/oscilloscope.py index c38b1c4..ee66e1e 100644 --- a/ui/oscilloscope.py +++ b/ui/oscilloscope.py @@ -53,8 +53,8 @@ def __init__(self, controller, parent=None): class OscilloScopeScreen(pg.PlotWidget): - def __init__(self, parent = None, plotItem = None, **kwargs): - super().__init__(parent=parent, background='w', plotItem=plotItem, **kwargs) + def __init__(self, controller, parent = None, plotItem = None, **kwargs): + super().__init__(parent=parent, controller=controller, background='w', plotItem=plotItem, **kwargs) styles = {'color': 'k', 'font-size': '12px'} self.setLabel('left', 'Voltage (ADCs)', **styles) @@ -64,18 +64,19 @@ def __init__(self, parent = None, plotItem = None, **kwargs): self.setXRange(0, 1, padding = 0.02) self.setYRange(0, 5, padding = 0.02) + self.legend = self.addLegend() self.pen_ch = {} self.channels = {} # create pens for each channel, and plot the defaults - for ch in self.ch_mapping.keys(): + for ch in controller.ch_mapping.keys(): self.pen_ch[ch] = pg.mkPen(pg.intColor(ch), width = 1) self.plot_ch([0,1], [0,0], ch) - self.legend = self.addLegend() + def plot_ch(self, x, y, ch = 1): - self.channels[ch] = self.plot(x, y, pen=self.pen_ch[ch], name = str(ch)) + self.channels[ch] = self.plot(x, y, pen=self.pen_ch[ch], name = f'ch {ch}') def update_ch(self, x, y, ch = 1): self.channels[ch].setData(x, y) @@ -93,7 +94,7 @@ def __init__(self, controller, *args, **kwargs): def setupUI(self): self.setWindowTitle("CAEN Acqusition and Readout Program (CARP)") - self.screen = OscilloScopeScreen() + self.screen = OscilloScopeScreen(self.controller) self.control_panel = ControlPanel(self.controller) self.content_layout = QHBoxLayout() From 745eac1d477144df56fd6a147b2e6370e1fa3168 Mon Sep 17 00:00:00 2001 From: jwaiton Date: Wed, 14 Jan 2026 17:58:29 +0000 Subject: [PATCH 05/23] disable channels by default --- felib/digitiser.py | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/felib/digitiser.py b/felib/digitiser.py index 8621172..d576e2a 100644 --- a/felib/digitiser.py +++ b/felib/digitiser.py @@ -42,12 +42,12 @@ def __init__(self, dig_dict : dict): else: logging.error("Invalid digitiser generation specified in the configuration.") #raise ValueError("Invalid digitiser generation specified in the configuration.") - + self.URI = self.generate_uri() self.isAcquiring = False self.isConnected = False self.isRecording = False - + self.data_format = [] self.endpoint = None @@ -74,15 +74,15 @@ def generate_uri(self): else: logging.error("Invalid digitiser generation specified in the configuration.") #raise ValueError("Invalid digitiser generation specified in the configuration.") - + def connect(self): ''' Connect to the digitiser using the generated URI. ''' - + logging.info(f'Attemping connection to digitiser {self.dig_name} at {self.URI}.') - + # fake connection for debugging if self.dig_name == 'debug': self.dig = None @@ -114,7 +114,7 @@ def connect(self): return None - def configure(self, + def configure(self, dig_dict : dict, rec_dict : dict): #record_length: Optional[int] = 0, @@ -122,7 +122,7 @@ def configure(self, #trigger_level: Optional[str] = 'SWTRG'): ''' Configure the digitiser with the provided settings and calibrate it. - ''' + ''' self.record_length = rec_dict.get('record_length') self.pre_trigger = rec_dict.get('pre_trigger') @@ -143,10 +143,12 @@ def configure(self, # extract channel config of interest ch_dict = rec_dict.get(f'ch{i}') - + + # disable channel if not explicitly called if ch_dict is None: + ch.par.CH_ENABLED.value = 'FALSE' continue - + ch.par.CH_ENABLED.value = 'TRUE' if ch_dict['enabled'] else 'FALSE' ch.par.CH_PRETRG.value = f'{self.pre_trigger}' @@ -157,7 +159,7 @@ def configure(self, else: # doesn't reset by default! so forcing this here ch.par.CH_SELF_TRG_ENABLE.value = 'FALSE' - + if ch_dict['polarity'] == 'positive': ch.par.CH_POLARITY.value = 'POLARITY_POSITIVE' elif ch_dict['polarity'] == 'negative': @@ -166,7 +168,7 @@ def configure(self, else: ch.par.CH_SELF_TRG_ENABLE.value = 'FALSE' # technically customisable - + # calculate the true reclen value for outputting @@ -179,12 +181,12 @@ def configure(self, self.data_format = formats.DPP(int(self.dig.par.NUMCH.value), int(self.reclen)) # setting up probe types (READ UP ON THIS) self.dig.vtrace[0].par.VTRACE_PROBE.value = 'VPROBE_INPUT' - + endpoint_path = (self.dig.par.FWTYPE.value).replace('-', '') self.endpoint = self.dig.endpoint[endpoint_path] self.data = self.endpoint.set_read_data_format(self.data_format) - + logging.info(f"Digitiser configured:\nrecord length {self.record_length}, pre-trigger {self.pre_trigger}, trigger mode {self.trigger_mode}.") except Exception as e: logging.exception(f"Failed to configure recording parameters.\n{e}") @@ -207,18 +209,18 @@ def start_acquisition(self): self.dig.cmd.ARMACQUISITION() except Exception as e: logging.exception(f"Starting acquisition failed: {e}") - + # start recording function #self.trigger_and_record() #try: #self.dig.cmd.START() - #self.collect = True + #self.collect = True #print("Digitiser acquisition started.") #except Exception as e: # raise RuntimeError(f"Failed to start digitiser acquisition.\n{e}") #self.collect = True - - + + def stop_acquisition(self): ''' Stop the digitiser acquisition. @@ -242,7 +244,7 @@ def acquire(self): return self.SELFTRIG_record() case _: logging.info(f'Trigger mode {self.trigger_mode} not currently implemented.') - self.stop_acquisition() + self.stop_acquisition() def SW_record(self): @@ -266,16 +268,16 @@ def SW_record(self): if ex.code is error.ErrorCode.STOP: logging.exception("STOP") raise ex - + # ensure the input and trigger are acceptable (I think?) #assert self.data[3].value == 1 # VPROBE INPUT? I need to understand this #assert self.data[6].value == 1 # VPROBE TRIGGER? - + #waveform_size = self.data[7].value #valid_sample_range = np.arange(0, waveform_size, dtype = waveform_size.dtype) - - + + def SELFTRIG_record(self): ''' Trigger on channels From 3eb5dc7b7dd32522bf26e7fb926750107e3938d7 Mon Sep 17 00:00:00 2001 From: jwaiton Date: Wed, 14 Jan 2026 17:58:50 +0000 Subject: [PATCH 06/23] implement `SCOPE format` --- felib/formats.py | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/felib/formats.py b/felib/formats.py index add2675..af0bae1 100644 --- a/felib/formats.py +++ b/felib/formats.py @@ -5,7 +5,7 @@ def DPP(nch, record_length): DPP-DSD format nch - number of channels ''' - + # Configure endpoint data_format = [ { @@ -52,4 +52,37 @@ def DPP(nch, record_length): } ] - return data_format \ No newline at end of file + return data_format + + +def SCOPE(nch, record_length): + ''' + SCOPE format + nch - number of channels + ''' + + # Configure endpoint + data_format = [ + { + 'name': 'EVENT_SIZE', + 'type': 'SIZE_T', + }, + { + 'name': 'TIMESTAMP', + 'type': 'U64', + }, + { + 'name': 'WAVEFORM', + 'type': 'U16', + 'dim': 2, + 'shape': [nch, record_length], + }, + { + 'name': 'WAVEFORM_SIZE', + 'type': 'SIZE_T', + 'dim': 1, + 'shape': [nch], + } + ] + + return data_format From cd8f8cb0b3a1536eca476417a09ee36964296c4c Mon Sep 17 00:00:00 2001 From: jwaiton Date: Thu, 15 Jan 2026 12:55:33 +0000 Subject: [PATCH 07/23] implement `DPP-DSD` and `SCOPE` pre-trigger `DPP-DSD` requires a `PRETRIG` value, `SCOPE` requires a `POSTTRG` value. These are output identically based on firmware type. --- felib/digitiser.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/felib/digitiser.py b/felib/digitiser.py index d576e2a..48bd62a 100644 --- a/felib/digitiser.py +++ b/felib/digitiser.py @@ -149,8 +149,10 @@ def configure(self, ch.par.CH_ENABLED.value = 'FALSE' continue - ch.par.CH_ENABLED.value = 'TRUE' if ch_dict['enabled'] else 'FALSE' - ch.par.CH_PRETRG.value = f'{self.pre_trigger}' + # normal channel management + ch.par.CH_ENABLED.value = 'TRUE' if ch_dict['enabled'] else 'FALSE' + if self.dig.par.FWTYPE.value == 'DPP-DSD' : ch.par.CH_PRETRIG.value = f{'self.pre_trigger'} + elif self.dig.par.FWTYPE.value == 'SCOPE' : ch.par.POSTTRG.value = f'{self.record_length - self.pre_trigger}' # ensure self trigger only enabled when you don't have SWTRIG enabled if ch_dict['self_trigger'] and self.trigger_mode != 'SWTRIG': From 776fef176065942c8f595aea701a89b248d18802 Mon Sep 17 00:00:00 2001 From: jwaiton Date: Thu, 15 Jan 2026 13:01:20 +0000 Subject: [PATCH 08/23] `CH_SELF_TRG_ENABLE` only for `DPP-DSD` --- felib/digitiser.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/felib/digitiser.py b/felib/digitiser.py index 48bd62a..3fc7d1c 100644 --- a/felib/digitiser.py +++ b/felib/digitiser.py @@ -156,11 +156,13 @@ def configure(self, # ensure self trigger only enabled when you don't have SWTRIG enabled if ch_dict['self_trigger'] and self.trigger_mode != 'SWTRIG': + if self.dig.par.FWTYPE.value == 'DPP-DSD' : ch.par.CH_SELF_TRG_ENABLE.value = 'TRUE' + ch.par.CH_SELF_TRG_ENABLE.value = 'TRUE' ch.par.CH_THRESHOLD.value = str(ch_dict['threshold']) else: # doesn't reset by default! so forcing this here - ch.par.CH_SELF_TRG_ENABLE.value = 'FALSE' + if self.dig.par.FWTYPE.value == 'DPP-DSD' : ch.par.CH_SELF_TRG_ENABLE.value = 'FALSE' if ch_dict['polarity'] == 'positive': ch.par.CH_POLARITY.value = 'POLARITY_POSITIVE' From 3a600b9ee56d162114c5e995f52c4646ddf90bea Mon Sep 17 00:00:00 2001 From: jwaiton Date: Thu, 15 Jan 2026 13:03:59 +0000 Subject: [PATCH 09/23] alter `DSD` to `PSD` --- felib/digitiser.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/felib/digitiser.py b/felib/digitiser.py index 3fc7d1c..01830eb 100644 --- a/felib/digitiser.py +++ b/felib/digitiser.py @@ -151,18 +151,18 @@ def configure(self, # normal channel management ch.par.CH_ENABLED.value = 'TRUE' if ch_dict['enabled'] else 'FALSE' - if self.dig.par.FWTYPE.value == 'DPP-DSD' : ch.par.CH_PRETRIG.value = f{'self.pre_trigger'} + if self.dig.par.FWTYPE.value == 'DPP-PSD' : ch.par.CH_PRETRIG.value = f{'self.pre_trigger'} elif self.dig.par.FWTYPE.value == 'SCOPE' : ch.par.POSTTRG.value = f'{self.record_length - self.pre_trigger}' # ensure self trigger only enabled when you don't have SWTRIG enabled if ch_dict['self_trigger'] and self.trigger_mode != 'SWTRIG': - if self.dig.par.FWTYPE.value == 'DPP-DSD' : ch.par.CH_SELF_TRG_ENABLE.value = 'TRUE' + if self.dig.par.FWTYPE.value == 'DPP-PSD' : ch.par.CH_SELF_TRG_ENABLE.value = 'TRUE' ch.par.CH_SELF_TRG_ENABLE.value = 'TRUE' ch.par.CH_THRESHOLD.value = str(ch_dict['threshold']) else: # doesn't reset by default! so forcing this here - if self.dig.par.FWTYPE.value == 'DPP-DSD' : ch.par.CH_SELF_TRG_ENABLE.value = 'FALSE' + if self.dig.par.FWTYPE.value == 'DPP-PSD' : ch.par.CH_SELF_TRG_ENABLE.value = 'FALSE' if ch_dict['polarity'] == 'positive': ch.par.CH_POLARITY.value = 'POLARITY_POSITIVE' From 9ef95793a82fc8cfd6d12ea9528808a4459da0fa Mon Sep 17 00:00:00 2001 From: jwaiton Date: Thu, 15 Jan 2026 13:21:07 +0000 Subject: [PATCH 10/23] implement SCOPE `data_format` --- felib/digitiser.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/felib/digitiser.py b/felib/digitiser.py index 01830eb..c089f34 100644 --- a/felib/digitiser.py +++ b/felib/digitiser.py @@ -179,12 +179,18 @@ def configure(self, reclen_ns = int(self.dig.par.RECLEN.value) self.reclen = int(reclen_ns / int(1e3 / self.dig_info['sample_rate'])) - # if DPP, need to specify that you're looking at waveforms specifically. - if self.dig.par.FWTYPE.value == 'DPP-PSD': - self.dig.par.WAVEFORMS.value = 'TRUE' - self.data_format = formats.DPP(int(self.dig.par.NUMCH.value), int(self.reclen)) - # setting up probe types (READ UP ON THIS) - self.dig.vtrace[0].par.VTRACE_PROBE.value = 'VPROBE_INPUT' + # set up data format + match self.dig.par.FWTYPE.value: + case 'DPP-PSD': + # enforce waveform formatting + self.dig.par.WAVEFORMS.value = 'TRUE' + self.data_format = formats.DPP( int(self.dig.par.NUMCH.value), int(self.reclen)) + # setting up probe types (READ UP ON THIS) + self.dig.vtrace[0].par.VTRACE_PROBE.value = 'VPROBE_INPUT' + case 'SCOPE': + self.data_format = formats.SCOPE(int(self.dig.par.NUMCH.value), int(self.reclen)) + case _: + logging.exception(f"Firmware type {self.dig.par.FWTYPE.value} not recognised.\nCurrent FWs available are DPP-DSD and SCOPE") endpoint_path = (self.dig.par.FWTYPE.value).replace('-', '') self.endpoint = self.dig.endpoint[endpoint_path] From cdccb87b834d7f027e76624e0a3ecd894f31f426 Mon Sep 17 00:00:00 2001 From: jwaiton Date: Thu, 15 Jan 2026 14:36:40 +0000 Subject: [PATCH 11/23] separate channel mapping to `functions.py` --- core/controller.py | 21 ++------------------- core/functions.py | 21 +++++++++++++++++++++ felib/digitiser.py | 4 ++++ 3 files changed, 27 insertions(+), 19 deletions(-) create mode 100644 core/functions.py diff --git a/core/controller.py b/core/controller.py index be52f73..61c275f 100644 --- a/core/controller.py +++ b/core/controller.py @@ -28,6 +28,7 @@ from core.worker import AcquisitionWorker from core.writer import Writer from core.tracker import Tracker +from core.functions import get_ch_mapping from felib.digitiser import Digitiser from ui import oscilloscope @@ -80,7 +81,7 @@ def __init__(self, logging.info("Acquisition worker thread started.") # Multi channel writes to h5 - self.ch_mapping = self.get_ch_mapping() + self.ch_mapping = get_ch_mapping(self.rec_dict) self.num_ch = len(self.ch_mapping) self.h5_flush_size = self.rec_dict['h5_flush_size'] self.writer_buffers = [Queue(maxsize=1024) for _ in range(self.num_ch)] @@ -105,24 +106,6 @@ def __init__(self, self.connect_digitiser() - def get_ch_mapping(self): - ''' - Extract what channels are being used map them: ch -> index - - So shape will be: - mapping = {0 : 0, 3 : 1, 5 : 2} - for the case where ch0, 3, and 5 are enabled - ''' - mapping = {} - i = 0 - for entry in self.rec_dict: - if 'ch' in entry: - if self.rec_dict[entry]['enabled']: - ch = int(entry[2:]) - mapping[ch] = i - i += 1 - - return mapping def data_handling(self): ''' diff --git a/core/functions.py b/core/functions.py new file mode 100644 index 0000000..bdf4ee1 --- /dev/null +++ b/core/functions.py @@ -0,0 +1,21 @@ + +def get_ch_mapping(rec_dict): + ''' + Extract what channels are being used map them: ch -> index + + So shape will be: + mapping = {0 : 0, 3 : 1, 5 : 2} + for the case where ch0, 3, and 5 are enabled + ''' + mapping = {} + i = 0 + for entry in rec_dict: + if 'ch' in entry: + if rec_dict[entry]['enabled']: + ch = int(entry[2:]) + mapping[ch] = i + i += 1 + + return mapping + + diff --git a/felib/digitiser.py b/felib/digitiser.py index c089f34..64f4428 100644 --- a/felib/digitiser.py +++ b/felib/digitiser.py @@ -8,6 +8,7 @@ from typing import Optional import time +from core.functions import get_ch_mapping from felib.dig1_utils import generate_digitiser_uri import felib.formats as formats @@ -128,6 +129,9 @@ def configure(self, self.pre_trigger = rec_dict.get('pre_trigger') self.trigger_mode = rec_dict.get('trigger_mode') + # extract channel mapping + self.ch_mapping = get_ch_mapping(rec_dict) + try: self.dig.par.RECLEN.value = f'{self.record_length}' From cb1282a7b907b4e8568fd64f1120142cd6a7f806 Mon Sep 17 00:00:00 2001 From: jwaiton Date: Thu, 15 Jan 2026 15:58:31 +0000 Subject: [PATCH 12/23] implement `SCOPE` and `DPP-PSD` readout This required multiple changes to the way the day is collected and susbsequently processed. --- core/controller.py | 4 ++-- core/worker.py | 9 ++++---- core/writer.py | 7 +++--- felib/digitiser.py | 53 ++++++++++++++++++++++++++++++++++++++-------- 4 files changed, 55 insertions(+), 18 deletions(-) diff --git a/core/controller.py b/core/controller.py index 61c275f..5747aa7 100644 --- a/core/controller.py +++ b/core/controller.py @@ -120,7 +120,7 @@ def data_handling(self): try: # you must pass wf_size and ADCs through. - wf_size, ADCs, ch = data + wf_size, ADCs, ch, timestamp = data # update visuals self.main_window.screen.update_ch(np.arange(0, wf_size, dtype=wf_size.dtype), ADCs, ch) @@ -130,7 +130,7 @@ def data_handling(self): # push data to writer buffer if self.recording: - write_data = wf_size, ADCs, self.event_counter + write_data = wf_size, ADCs, self.event_counter, timestamp # multi channel writing ch = int(ch) diff --git a/core/worker.py b/core/worker.py index 2788c0f..f994ad1 100644 --- a/core/worker.py +++ b/core/worker.py @@ -74,7 +74,7 @@ def start_acquisition(self): logging.info("Digitiser acquisition started successfully.") except Exception as e: logging.exception(f"Start acquisition failed: {e}") - + def connect_digitiser(self, dig_config, rec_config): ''' Connect to digitiser with given configs. @@ -123,7 +123,8 @@ def run(self): data = self.digitiser.acquire() if data is None: continue - + # extract each channel separately and push to buffers + for channel_data in data: # Non-blocking put to visual buffer if self.display_buffer.full(): try: @@ -133,7 +134,7 @@ def run(self): # Push to display buffer (etc.) if not self.display_buffer.full(): - self.display_buffer.put_nowait(data) + self.display_buffer.put_nowait(channel_data) # Notify controller/UI if self.data_ready_callback: @@ -154,7 +155,7 @@ def run(self): def cleanup(self): ''' - Cleans up digitiser by calling stop_acquisition and its destructor. + Cleans up digitiser by calling stop_acquisition and its destructor. ''' if self.digitiser: if self.digitiser.isAcquiring: diff --git a/core/writer.py b/core/writer.py index fd720ac..0bbc933 100644 --- a/core/writer.py +++ b/core/writer.py @@ -62,7 +62,7 @@ def write_h5(self): where ADCs is the actual raw waveform array ''' - for wf_size, rwf, evt in self.local_buffer: + for wf_size, rwf, evt, ts in self.local_buffer: # if we know the size of the waveforms already, don't create the class again. if self.wf_size is None: self.wf_size = wf_size @@ -70,8 +70,9 @@ def write_h5(self): self.rwf_table = self.h5file.create_table(self.rwf_group, 'rwf', self.rwf_class, "raw waveforms") self.rows = self.rwf_table.row - self.rows['evt_no'] = evt - self.rows['rwf'] = rwf + self.rows['evt_no'] = evt + self.rows['rwf'] = rwf + self.rows['timestamp'] = ts self.rows.append() self.local_buffer.clear() diff --git a/felib/digitiser.py b/felib/digitiser.py index 64f4428..addab4c 100644 --- a/felib/digitiser.py +++ b/felib/digitiser.py @@ -194,13 +194,30 @@ def configure(self, case 'SCOPE': self.data_format = formats.SCOPE(int(self.dig.par.NUMCH.value), int(self.reclen)) case _: - logging.exception(f"Firmware type {self.dig.par.FWTYPE.value} not recognised.\nCurrent FWs available are DPP-DSD and SCOPE") + logging.exception(f"Firmware type {self.dig.par.FWTYPE.value} not recognised.\nCurrent FWs available are DPP-PSD and SCOPE") endpoint_path = (self.dig.par.FWTYPE.value).replace('-', '') self.endpoint = self.dig.endpoint[endpoint_path] self.data = self.endpoint.set_read_data_format(self.data_format) + # generalised extraction of data parameters + match self.dig.par.FWTYPE.value: + case 'DPP-PSD': + self.channel = self.data[0].value + self.timestamp = self.data[1].value + self.waveform_size = self.data[7].value + self.waveform = self.data[3].value + case 'SCOPE': + # no channel parameter as channels are treated differently + # all channels are within the dataset, check the data format to understand the shape + self.timestamp = self.data[1].value + self.waveform_size = self.data[3].value + self.waveform = self.data[2].value + case _: + logging.exception(f"Firmware type {self.dig.par.FWTYPE.value} not recognised.\nCurrent FWs available are DPP-PSD and SCOPE") + + logging.info(f"Digitiser configured:\nrecord length {self.record_length}, pre-trigger {self.pre_trigger}, trigger mode {self.trigger_mode}.") except Exception as e: logging.exception(f"Failed to configure recording parameters.\n{e}") @@ -271,10 +288,19 @@ def SW_record(self): try: self.endpoint.has_data(check_timeout) self.endpoint.read_data(read_timeout, self.data) # timeout first number in ms - wf_size = self.data[7].value - ADCs = self.data[3].value - ch = self.data[0].value - return (wf_size, ADCs, ch) + + # SCOPE sends everything, even the disabled channels, so parse the relevant channels here + if self.dig.par.FWTYPE.value == 'SCOPE': + output = [] + # using the mapping extract the relevant channels + for ch in ch_mapping.keys(): + output.append((self.waveform_size[ch], self.waveform[ch], ch, self.timestamp)) + # DPP-PSD triggers per channel, so needs to be treated as such + elif self.dig.par.FWTYPE.value == 'DPP-PSD' + output = [(self.waveform_size, self.waveform, self.channel, self.timestamp)] + + return output + except error.Error as ex: #logging.exception("Error in readout:") if ex.code is error.ErrorCode.TIMEOUT: @@ -301,10 +327,19 @@ def SELFTRIG_record(self): try: self.endpoint.has_data(check_timeout) self.endpoint.read_data(read_timeout, self.data) - wf_size = self.data[7].value - ADCs = self.data[3].value - ch = self.data[0].value - return (wf_size, ADCs, ch) + + # SCOPE sends everything, even the disabled channels, so parse the relevant channels here + if self.dig.par.FWTYPE.value == 'SCOPE': + output = [] + # using the mapping extract the relevant channels + for ch in ch_mapping.keys(): + output.append((self.waveform_size[ch], self.waveform[ch], ch, self.timestamp)) + # DPP-PSD triggers per channel, so needs to be treated as such + elif self.dig.par.FWTYPE.value == 'DPP-PSD' + output = [(self.waveform_size, self.waveform, self.channel, self.timestamp)] + + return output + except error.Error as ex: #logging.exception("Error in readout:") if ex.code is error.ErrorCode.TIMEOUT: From d2c6e2c90ca84416526f75208cad853979aff91b Mon Sep 17 00:00:00 2001 From: jwaiton Date: Fri, 16 Jan 2026 13:09:35 +0000 Subject: [PATCH 13/23] fix indentation --- core/worker.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/core/worker.py b/core/worker.py index f994ad1..dbd7cb6 100644 --- a/core/worker.py +++ b/core/worker.py @@ -125,20 +125,20 @@ def run(self): continue # extract each channel separately and push to buffers for channel_data in data: - # Non-blocking put to visual buffer - if self.display_buffer.full(): - try: - self.display_buffer.get_nowait() # discard oldest - except Empty: - pass - - # Push to display buffer (etc.) - if not self.display_buffer.full(): - self.display_buffer.put_nowait(channel_data) - - # Notify controller/UI - if self.data_ready_callback: - self.data_ready_callback() + # Non-blocking put to visual buffer + if self.display_buffer.full(): + try: + self.display_buffer.get_nowait() # discard oldest + except Empty: + pass + + # Push to display buffer (etc.) + if not self.display_buffer.full(): + self.display_buffer.put_nowait(channel_data) + + # Notify controller/UI + if self.data_ready_callback: + self.data_ready_callback() except Exception as e: logging.exception(f"Acquisition error: {e}") From 0b842ec46c1a6a770ff81a160390c8cd8287717f Mon Sep 17 00:00:00 2001 From: jwaiton Date: Fri, 16 Jan 2026 13:10:44 +0000 Subject: [PATCH 14/23] include V1730_A4818 config --- configs/digitiser/wd1_scope_V1730_A4818.conf | 9 +++++++++ felib/digitiser.py | 10 ++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 configs/digitiser/wd1_scope_V1730_A4818.conf diff --git a/configs/digitiser/wd1_scope_V1730_A4818.conf b/configs/digitiser/wd1_scope_V1730_A4818.conf new file mode 100644 index 0000000..28d02f6 --- /dev/null +++ b/configs/digitiser/wd1_scope_V1730_A4818.conf @@ -0,0 +1,9 @@ +[required] + +dig_name = 'V1730_A4818' +dig_gen = 1 +con_type = 'usb_A4818' +link_num = 42898 +conet_node = 0 +vme_base_address = 0 +dig_authority = 'caen.internal' diff --git a/felib/digitiser.py b/felib/digitiser.py index addab4c..58e3ec9 100644 --- a/felib/digitiser.py +++ b/felib/digitiser.py @@ -155,8 +155,10 @@ def configure(self, # normal channel management ch.par.CH_ENABLED.value = 'TRUE' if ch_dict['enabled'] else 'FALSE' - if self.dig.par.FWTYPE.value == 'DPP-PSD' : ch.par.CH_PRETRIG.value = f{'self.pre_trigger'} - elif self.dig.par.FWTYPE.value == 'SCOPE' : ch.par.POSTTRG.value = f'{self.record_length - self.pre_trigger}' + # for SCOPE, this doesnt need to be set per channel, but i prefer these to be set together + # even if its a bit redundant + if self.dig.par.FWTYPE.value == 'DPP-PSD' : ch.par.CH_PRETRIG.value = f'{self.pre_trigger}' + elif self.dig.par.FWTYPE.value == 'SCOPE' : self.dig.par.POSTTRG.value = f'{self.record_length - self.pre_trigger}' # ensure self trigger only enabled when you don't have SWTRIG enabled if ch_dict['self_trigger'] and self.trigger_mode != 'SWTRIG': @@ -296,7 +298,7 @@ def SW_record(self): for ch in ch_mapping.keys(): output.append((self.waveform_size[ch], self.waveform[ch], ch, self.timestamp)) # DPP-PSD triggers per channel, so needs to be treated as such - elif self.dig.par.FWTYPE.value == 'DPP-PSD' + elif self.dig.par.FWTYPE.value == 'DPP-PSD': output = [(self.waveform_size, self.waveform, self.channel, self.timestamp)] return output @@ -335,7 +337,7 @@ def SELFTRIG_record(self): for ch in ch_mapping.keys(): output.append((self.waveform_size[ch], self.waveform[ch], ch, self.timestamp)) # DPP-PSD triggers per channel, so needs to be treated as such - elif self.dig.par.FWTYPE.value == 'DPP-PSD' + elif self.dig.par.FWTYPE.value == 'DPP-PSD': output = [(self.waveform_size, self.waveform, self.channel, self.timestamp)] return output From 3f544de0b82d27685855d1a392d9189fbba92014 Mon Sep 17 00:00:00 2001 From: jwaiton Date: Fri, 16 Jan 2026 14:24:59 +0000 Subject: [PATCH 15/23] remove `CH_SELF_TRG_ENABLE` for `SCOPE` --- felib/digitiser.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/felib/digitiser.py b/felib/digitiser.py index 58e3ec9..b0cd0a5 100644 --- a/felib/digitiser.py +++ b/felib/digitiser.py @@ -161,10 +161,10 @@ def configure(self, elif self.dig.par.FWTYPE.value == 'SCOPE' : self.dig.par.POSTTRG.value = f'{self.record_length - self.pre_trigger}' # ensure self trigger only enabled when you don't have SWTRIG enabled + # recall that this functions like so for DPP-PSD, with SCOPE, if a channel is enabled the self-trigger is also enabled if ch_dict['self_trigger'] and self.trigger_mode != 'SWTRIG': if self.dig.par.FWTYPE.value == 'DPP-PSD' : ch.par.CH_SELF_TRG_ENABLE.value = 'TRUE' - ch.par.CH_SELF_TRG_ENABLE.value = 'TRUE' ch.par.CH_THRESHOLD.value = str(ch_dict['threshold']) else: # doesn't reset by default! so forcing this here @@ -176,7 +176,7 @@ def configure(self, ch.par.CH_POLARITY.value = 'POLARITY_NEGATIVE' else: - ch.par.CH_SELF_TRG_ENABLE.value = 'FALSE' + if self.dig.par.FWTYPE.value == 'DPP-PSD' : ch.par.CH_SELF_TRG_ENABLE.value = 'FALSE' # technically customisable @@ -295,7 +295,7 @@ def SW_record(self): if self.dig.par.FWTYPE.value == 'SCOPE': output = [] # using the mapping extract the relevant channels - for ch in ch_mapping.keys(): + for ch in self.ch_mapping.keys(): output.append((self.waveform_size[ch], self.waveform[ch], ch, self.timestamp)) # DPP-PSD triggers per channel, so needs to be treated as such elif self.dig.par.FWTYPE.value == 'DPP-PSD': @@ -334,7 +334,7 @@ def SELFTRIG_record(self): if self.dig.par.FWTYPE.value == 'SCOPE': output = [] # using the mapping extract the relevant channels - for ch in ch_mapping.keys(): + for ch in self.ch_mapping.keys(): output.append((self.waveform_size[ch], self.waveform[ch], ch, self.timestamp)) # DPP-PSD triggers per channel, so needs to be treated as such elif self.dig.par.FWTYPE.value == 'DPP-PSD': From 616f43e60bc820098ff07892d46eab539d012f87 Mon Sep 17 00:00:00 2001 From: jwaiton Date: Fri, 16 Jan 2026 14:47:34 +0000 Subject: [PATCH 16/23] include channel in `Writer()` --- core/writer.py | 1 + 1 file changed, 1 insertion(+) diff --git a/core/writer.py b/core/writer.py index 0bbc933..64dcc7c 100644 --- a/core/writer.py +++ b/core/writer.py @@ -72,6 +72,7 @@ def write_h5(self): self.rows['evt_no'] = evt self.rows['rwf'] = rwf + self.rows['channel'] = self.ch self.rows['timestamp'] = ts self.rows.append() From cfff57e946ac7ce34007c0d31be41341c5bc775f Mon Sep 17 00:00:00 2001 From: jwaiton Date: Fri, 16 Jan 2026 15:31:43 +0000 Subject: [PATCH 17/23] rewrite `controller` to use one thread for writing --- core/controller.py | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/core/controller.py b/core/controller.py index 5747aa7..89561e4 100644 --- a/core/controller.py +++ b/core/controller.py @@ -84,17 +84,16 @@ def __init__(self, self.ch_mapping = get_ch_mapping(self.rec_dict) self.num_ch = len(self.ch_mapping) self.h5_flush_size = self.rec_dict['h5_flush_size'] - self.writer_buffers = [Queue(maxsize=1024) for _ in range(self.num_ch)] - self.writers = [Writer( - ch=curr_ch, - flush_size=self.h5_flush_size, - write_buffer=self.writer_buffers[i], - stop_event=self.writer_stop_event, - rec_config = read_config_file(self.rec_config), - dig_config = read_config_file(self.dig_config), - TIMESTAMP = datetime.now().strftime("%H:%M:%S") + self.writer_buffer = Queue(maxsize=1024) + self.writer = Writer( + ch_map = self.ch_mapping + flush_size = self.h5_flush_size, + write_buffer = self.writer_buffer, + stop_event = self.writer_stop_event, + rec_config = read_config_file(self.rec_config), + dig_config = read_config_file(self.dig_config), + TIMESTAMP = datetime.now().strftime("%H:%M:%S") ) - for curr_ch, i in self.ch_mapping.items()] # gui second self.app = QApplication([]) @@ -130,12 +129,8 @@ def data_handling(self): # push data to writer buffer if self.recording: - write_data = wf_size, ADCs, self.event_counter, timestamp - - # multi channel writing - ch = int(ch) - i = int(self.ch_mapping[ch]) - self.writer_buffers[i].put(write_data) + write_data = wf_size, ch, ADCs, self.event_counter, timestamp + self.writer_buffer.put(write_data) self.event_counter += 1 @@ -193,10 +188,9 @@ def start_recording(self): Start recording data. ''' self.recording = True - for w in self.writers: - if not w.is_alive(): - w.start() - logging.info(f"Writer (channel {w.ch}) thread started.") + if not self.writer.is_alive(): + self.writer.start + logging.info(f'Writer thread started.') logging.info("Starting recording.") @@ -207,10 +201,9 @@ def stop_recording(self): self.recording = False self.writer_stop_event.set() - for w in self.writers: - w.join(timeout=2) + self.writers.join(timeout=2) - logging.info("Stopping recording.") + logging.info("Writer thread stopping recording.") def shutdown(self): ''' From 1d17bb9f143560780739e0abb1e36bb7b0a26003 Mon Sep 17 00:00:00 2001 From: jwaiton Date: Fri, 16 Jan 2026 15:32:28 +0000 Subject: [PATCH 18/23] alter writer to writer per channel in singular df --- core/controller.py | 16 +++++++--------- core/writer.py | 30 +++++++++++++++--------------- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/core/controller.py b/core/controller.py index 89561e4..66341d3 100644 --- a/core/controller.py +++ b/core/controller.py @@ -86,7 +86,7 @@ def __init__(self, self.h5_flush_size = self.rec_dict['h5_flush_size'] self.writer_buffer = Queue(maxsize=1024) self.writer = Writer( - ch_map = self.ch_mapping + ch_map = self.ch_mapping, flush_size = self.h5_flush_size, write_buffer = self.writer_buffer, stop_event = self.writer_stop_event, @@ -189,7 +189,7 @@ def start_recording(self): ''' self.recording = True if not self.writer.is_alive(): - self.writer.start + self.writer.start() logging.info(f'Writer thread started.') logging.info("Starting recording.") @@ -201,7 +201,7 @@ def stop_recording(self): self.recording = False self.writer_stop_event.set() - self.writers.join(timeout=2) + self.writer.join(timeout=2) logging.info("Writer thread stopping recording.") @@ -218,8 +218,7 @@ def shutdown(self): # Writer threads self.writer_stop_event.set() - for w in self.writers: - w.join(timeout=2) + self.writer.join(timeout=2) clean_shutdown = True @@ -227,10 +226,9 @@ def shutdown(self): clean_shutdown = False logging.warning("AcquisitionWorker did not stop cleanly.") - for w in self.writers: - if w.is_alive(): - clean_shutdown = False - logging.warning(f"Writer (channel {w.ch}) did not stop cleanly.") + if self.writer.is_alive(): + clean_shutdown = False + logging.warning(f"Writer (channel {w.ch}) did not stop cleanly.") if clean_shutdown: logging.info("Controller shutdown complete.") diff --git a/core/writer.py b/core/writer.py index 64dcc7c..7cccd21 100644 --- a/core/writer.py +++ b/core/writer.py @@ -12,7 +12,7 @@ class Writer(Thread): Writes channel data to h5 file. ''' def __init__(self, - ch : int, + ch_map : dict, flush_size : int, write_buffer : Queue, stop_event : Event, @@ -25,21 +25,19 @@ def __init__(self, ''' super().__init__(daemon=True) - self.ch = ch self.flush_size = flush_size self.write_buffer = write_buffer self.stop_event = stop_event self.rec_config = rec_config self.dig_config = dig_config - self.filename = f"some_name_ch_{self.ch}" self.local_buffer = [] self.wf_size = None if 'file_name' in self.rec_config: file_path = self.rec_config['file_name'] - file_path = f'{file_path}_{self.ch}_{TIMESTAMP}.h5' + file_path = f'{file_path}_data_{TIMESTAMP}.h5' else: - file_path = f'{self.ch}_{TIMESTAMP}.h5' + file_path = f'data_{TIMESTAMP}.h5' # initialise the h5, one per channel, each handled on a separate thread try: self.h5file = tb.open_file(f'{file_path}', mode='a') @@ -50,8 +48,10 @@ def __init__(self, io.create_config_table(self.h5file, self.rec_config, 'rec_conf', 'recording config') io.create_config_table(self.h5file, self.dig_config, 'dig_conf', 'digitiser config') # raw waveform group constructed - self.rwf_group = self.h5file.create_group('/', f'ch_{ch}', 'raw waveform') - + self.rwf_group = {} + for ch in ch_map.keys(): + self.rwf_group[ch] = self.h5file.create_group('/', f'ch_{ch}', 'raw waveform') + self.rwf_table = {} def write_h5(self): ''' @@ -62,24 +62,24 @@ def write_h5(self): where ADCs is the actual raw waveform array ''' - for wf_size, rwf, evt, ts in self.local_buffer: + for wf_size, ch, rwf, evt, ts in self.local_buffer: # if we know the size of the waveforms already, don't create the class again. if self.wf_size is None: self.wf_size = wf_size self.rwf_class = df_class.return_rwf_class(self.dig_config['dig_gen'], self.wf_size) - self.rwf_table = self.h5file.create_table(self.rwf_group, 'rwf', self.rwf_class, "raw waveforms") - self.rows = self.rwf_table.row + self.rwf_table[ch] = self.h5file.create_table(self.rwf_group[ch], 'rwf', self.rwf_class, "raw waveforms") + self.rows = self.rwf_table[ch].row self.rows['evt_no'] = evt self.rows['rwf'] = rwf - self.rows['channel'] = self.ch + self.rows['channel'] = ch self.rows['timestamp'] = ts self.rows.append() self.local_buffer.clear() # flush as fast as the buffer provides - self.rwf_table.flush() + self.rwf_table[ch].flush() pass @@ -87,7 +87,7 @@ def run(self): ''' Writer hot loop. ''' - logging.info(f"Writer thread started (ch {self.ch}).") + logging.info(f"Writer thread started.") try: while not self.stop_event.is_set(): # First load data from shared buffer into local buffer @@ -105,11 +105,11 @@ def run(self): self.write_h5() except Exception as e: - logging.exception(f"Fatal error in Writer (ch {self.ch}): {e}") + logging.exception(f"Fatal error in Writer: {e}") # When stop_event() is set, call cleanup() self.cleanup() - logging.info(f"Writer thread exited cleanly (ch {self.ch}).") + logging.info(f"Writer thread exited cleanly.") def cleanup(self): ''' From 35aca6a0541f0d2302e5cfdd37443e3d164d178f Mon Sep 17 00:00:00 2001 From: jwaiton Date: Fri, 16 Jan 2026 16:18:16 +0000 Subject: [PATCH 19/23] fix bug where data isnt written to each table --- core/writer.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/core/writer.py b/core/writer.py index 7cccd21..cc4eed8 100644 --- a/core/writer.py +++ b/core/writer.py @@ -25,6 +25,7 @@ def __init__(self, ''' super().__init__(daemon=True) + self.ch_map = ch_map self.flush_size = flush_size self.write_buffer = write_buffer self.stop_event = stop_event @@ -49,7 +50,7 @@ def __init__(self, io.create_config_table(self.h5file, self.dig_config, 'dig_conf', 'digitiser config') # raw waveform group constructed self.rwf_group = {} - for ch in ch_map.keys(): + for ch in self.ch_map.keys(): self.rwf_group[ch] = self.h5file.create_group('/', f'ch_{ch}', 'raw waveform') self.rwf_table = {} @@ -67,8 +68,11 @@ def write_h5(self): if self.wf_size is None: self.wf_size = wf_size self.rwf_class = df_class.return_rwf_class(self.dig_config['dig_gen'], self.wf_size) - self.rwf_table[ch] = self.h5file.create_table(self.rwf_group[ch], 'rwf', self.rwf_class, "raw waveforms") - self.rows = self.rwf_table[ch].row + # generate all tables once + for ch in self.ch_map.keys(): + self.rwf_table[ch] = self.h5file.create_table(self.rwf_group[ch], 'rwf', self.rwf_class, "raw waveforms") + # open up the rows for the table + self.rows = self.rwf_table[ch].row self.rows['evt_no'] = evt self.rows['rwf'] = rwf From 0fe8aa2f193a9a8d64e0fbd10de834b251bfab82 Mon Sep 17 00:00:00 2001 From: jwaiton Date: Fri, 16 Jan 2026 18:14:01 +0000 Subject: [PATCH 20/23] fix event numbers being iterated per channel --- core/controller.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/controller.py b/core/controller.py index 66341d3..a36217f 100644 --- a/core/controller.py +++ b/core/controller.py @@ -83,6 +83,7 @@ def __init__(self, # Multi channel writes to h5 self.ch_mapping = get_ch_mapping(self.rec_dict) self.num_ch = len(self.ch_mapping) + self.max_ch = max(self.ch_mapping.keys()) self.h5_flush_size = self.rec_dict['h5_flush_size'] self.writer_buffer = Queue(maxsize=1024) self.writer = Writer( @@ -132,7 +133,9 @@ def data_handling(self): write_data = wf_size, ch, ADCs, self.event_counter, timestamp self.writer_buffer.put(write_data) - self.event_counter += 1 + # stupid catch to ensure event number only increases with channel + if ch == self.max_ch: + self.event_counter += 1 except Exception as e: logging.exception(f"Error updating display: {e}") From e9bfa20cc8a66a27bf071bf3f721ef71fc39cb4f Mon Sep 17 00:00:00 2001 From: jwaiton Date: Fri, 16 Jan 2026 18:14:19 +0000 Subject: [PATCH 21/23] ensure all channels are flushed at the end of local buffer call --- core/writer.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/writer.py b/core/writer.py index cc4eed8..5b2eb80 100644 --- a/core/writer.py +++ b/core/writer.py @@ -83,7 +83,8 @@ def write_h5(self): self.local_buffer.clear() # flush as fast as the buffer provides - self.rwf_table[ch].flush() + for ch_local in self.ch_map.keys(): + self.rwf_table[ch_local].flush() pass From 45a666d10fccf21dc883541b0384eeb5851c37c8 Mon Sep 17 00:00:00 2001 From: jwaiton Date: Sat, 17 Jan 2026 13:49:32 +0000 Subject: [PATCH 22/23] implement SCOPE self triggering --- felib/digitiser.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/felib/digitiser.py b/felib/digitiser.py index b0cd0a5..051779b 100644 --- a/felib/digitiser.py +++ b/felib/digitiser.py @@ -162,22 +162,21 @@ def configure(self, # ensure self trigger only enabled when you don't have SWTRIG enabled # recall that this functions like so for DPP-PSD, with SCOPE, if a channel is enabled the self-trigger is also enabled - if ch_dict['self_trigger'] and self.trigger_mode != 'SWTRIG': + if (ch_dict['self_trigger'] and self.trigger_mode != 'SWTRIG'): if self.dig.par.FWTYPE.value == 'DPP-PSD' : ch.par.CH_SELF_TRG_ENABLE.value = 'TRUE' + if self.dig.par.FWTYPE.value == 'SCOPE' : ch.par.CH_TRG_GLOBAL_GEN.value = 'TRUE' ch.par.CH_THRESHOLD.value = str(ch_dict['threshold']) else: # doesn't reset by default! so forcing this here if self.dig.par.FWTYPE.value == 'DPP-PSD' : ch.par.CH_SELF_TRG_ENABLE.value = 'FALSE' + if self.dig.par.FWTYPE.value == 'SCOPE' : ch.par.CH_TRG_GLOBAL_GEN.value = 'FALSE' if ch_dict['polarity'] == 'positive': ch.par.CH_POLARITY.value = 'POLARITY_POSITIVE' elif ch_dict['polarity'] == 'negative': ch.par.CH_POLARITY.value = 'POLARITY_NEGATIVE' - else: - if self.dig.par.FWTYPE.value == 'DPP-PSD' : ch.par.CH_SELF_TRG_ENABLE.value = 'FALSE' - # technically customisable From d1eead9e03a07d6698c3c82bbcb393b43e643c42 Mon Sep 17 00:00:00 2001 From: jwaiton Date: Sat, 17 Jan 2026 14:07:05 +0000 Subject: [PATCH 23/23] include explanatory configs --- .../recording/scope_a4818_V1730_SELFTRIG.conf | 57 ++++++++++++++++++ .../recording/scope_a4818_V1730_SWTRIG.conf | 58 +++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 configs/recording/scope_a4818_V1730_SELFTRIG.conf create mode 100644 configs/recording/scope_a4818_V1730_SWTRIG.conf diff --git a/configs/recording/scope_a4818_V1730_SELFTRIG.conf b/configs/recording/scope_a4818_V1730_SELFTRIG.conf new file mode 100644 index 0000000..7cfed9d --- /dev/null +++ b/configs/recording/scope_a4818_V1730_SELFTRIG.conf @@ -0,0 +1,57 @@ +# SELFTRIG example, where ch1 has a large signal, and both other channels are noise +# So we trigger on ch1, and not the others. All channels are collected per each trigger (unlike DPP-PSD firmware) +[required] + +record_length = 4096 # ns +pre_trigger = 512 # ns +trigger_mode = 'SELFTRIG' # look into the differing methods, trigger on channel based on threshold is an option + # SWTRIG, SELFTRIG, (not yet implemented) +software_timeout = 0 # hard software timeout between each digitiser poll (s) + +[channel_settings] + +ch0 = {'enabled' : False, + 'self_trigger': True, + 'threshold' : 0, + 'polarity' : 'positive'} # ADCs, only applies of self_trigger enabled + +ch1 = {'enabled' : True, + 'self_trigger': True, + 'threshold' : 1600, + 'polarity' : 'positive'} + +ch2 = {'enabled' : False, + 'self_trigger': False, + 'threshold' : 0, + 'polarity' : 'positive'} + +ch3 = {'enabled' : True, + 'self_trigger': False, + 'threshold' : 1, + 'polarity' : 'positive'} + +ch4 = {'enabled' : False, + 'self_trigger': False, + 'threshold' : 0, + 'polarity' : 'positive'} + +ch5 = {'enabled' : True, + 'self_trigger': False, + 'threshold' : 1, + 'polarity' : 'positive'} + +ch6 = {'enabled' : False, + 'self_trigger': False, + 'threshold' : 0, + 'polarity' : 'positive'} + +ch7 = {'enabled' : False, + 'self_trigger': False, + 'threshold' : 0, + 'polarity' : 'positive'} + +[output_settings] + +file_name = '../CARP_FILES/SCOPE_testing/a4818test' # this will always be appended with a timestamp and .h5 +overwrite = True # overwrite the file if you want +h5_flush_size = 10000 # number of values added to h5 files per write diff --git a/configs/recording/scope_a4818_V1730_SWTRIG.conf b/configs/recording/scope_a4818_V1730_SWTRIG.conf new file mode 100644 index 0000000..3de8c3d --- /dev/null +++ b/configs/recording/scope_a4818_V1730_SWTRIG.conf @@ -0,0 +1,58 @@ +# Software trigger example, where channel 1, 3 and 5 are outputting data. +# self_trigger is irrelevant here, as long as the channel is enabled, it will work + +[required] + +record_length = 4096 # ns +pre_trigger = 512 # ns +trigger_mode = 'SWTRIG' # look into the differing methods, trigger on channel based on threshold is an option + # SWTRIG, SELFTRIG, (not yet implemented) +software_timeout = 0 # hard software timeout between each digitiser poll (s) + +[channel_settings] + +ch0 = {'enabled' : False, + 'self_trigger': False, + 'threshold' : 0, + 'polarity' : 'positive'} # ADCs, only applies of self_trigger enabled + +ch1 = {'enabled' : True, + 'self_trigger': True, + 'threshold' : 0, + 'polarity' : 'positive'} + +ch2 = {'enabled' : False, + 'self_trigger': False, + 'threshold' : 600, + 'polarity' : 'positive'} + +ch3 = {'enabled' : True, + 'self_trigger': True, + 'threshold' : 0, + 'polarity' : 'positive'} + +ch4 = {'enabled' : False, + 'self_trigger': False, + 'threshold' : 0, + 'polarity' : 'positive'} + +ch5 = {'enabled' : True, + 'self_trigger': True, + 'threshold' : 0, + 'polarity' : 'positive'} + +ch6 = {'enabled' : False, + 'self_trigger': False, + 'threshold' : 0, + 'polarity' : 'positive'} + +ch7 = {'enabled' : False, + 'self_trigger': False, + 'threshold' : 0, + 'polarity' : 'positive'} + +[output_settings] + +file_name = '../CARP_FILES/SCOPE_testing/a4818test' # this will always be appended with a timestamp and .h5 +overwrite = True # overwrite the file if you want +h5_flush_size = 10000 # number of values added to h5 files per write