Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions CAENBoard_GENERICLog.txt

This file was deleted.

9 changes: 9 additions & 0 deletions configs/digitiser/wd1_scope_V1730_A4818.conf
Original file line number Diff line number Diff line change
@@ -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'
57 changes: 57 additions & 0 deletions configs/recording/scope_a4818_V1730_SELFTRIG.conf
Original file line number Diff line number Diff line change
@@ -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) <EXTTRIG>
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
58 changes: 58 additions & 0 deletions configs/recording/scope_a4818_V1730_SWTRIG.conf
Original file line number Diff line number Diff line change
@@ -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) <EXTTRIG>
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
93 changes: 37 additions & 56 deletions core/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,16 @@
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

from threading import Thread, Event, Lock
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
Expand Down Expand Up @@ -79,21 +80,21 @@ def __init__(self,
self.worker.start()
logging.info("Acquisition worker thread started.")

# Multi channel writes to h5
self.ch_mapping = self.get_ch_mapping()
# 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_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([])
Expand All @@ -105,20 +106,6 @@ def __init__(self,

self.connect_digitiser()

def get_ch_mapping(self):
'''
Extract what channels are being used map them: ch -> index
'''
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):
'''
Expand All @@ -132,25 +119,23 @@ def data_handling(self):
break

try:
# you must pass wf_size and ADCs through.
wf_size, ADCs, ch = data
# you must pass wf_size and ADCs through.
wf_size, ADCs, ch, timestamp = 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
write_data = wf_size, ch, ADCs, self.event_counter, timestamp
self.writer_buffer.put(write_data)

# multi channel writing
ch = int(ch)
i = int(self.ch_mapping[ch])
self.writer_buffers[i].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}")
Expand All @@ -166,7 +151,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.
Expand All @@ -193,7 +178,7 @@ def start_acquisition(self):
'''
logging.info("Starting acquisition.")
self.cmd_buffer.put(Command(CommandType.START))

def stop_acquisition(self):
'''
Stop digitiser acquisition.
Expand All @@ -206,24 +191,22 @@ 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.")

def stop_recording(self):
'''
Stop recording data.
'''
self.recording = False
self.writer_stop_event.set()

for w in self.writers:
w.join(timeout=2)
self.writer.join(timeout=2)

logging.info("Stopping recording.")
logging.info("Writer thread stopping recording.")

def shutdown(self):
'''
Expand All @@ -238,19 +221,17 @@ 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

if self.worker.is_alive():
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.")
Expand Down
21 changes: 21 additions & 0 deletions core/functions.py
Original file line number Diff line number Diff line change
@@ -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


35 changes: 18 additions & 17 deletions core/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -123,21 +123,22 @@ def run(self):
data = self.digitiser.acquire()
if data is None:
continue

# 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(data)

# Notify controller/UI
if self.data_ready_callback:
self.data_ready_callback()
# 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()

except Exception as e:
logging.exception(f"Acquisition error: {e}")
Expand All @@ -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:
Expand Down
Loading
Loading