Skip to content

Multi channel h5 writing - #28

Merged
jwaiton merged 15 commits into
nu-ZOO:mainfrom
mmillns2:threaded-h5-template
Jan 13, 2026
Merged

jwaiton merged 15 commits into
nu-ZOO:mainfrom
mmillns2:threaded-h5-template

Conversation

@mmillns2

Copy link
Copy Markdown
Member

This PR implements writing raw data to h5 files.

A new Writer class has been added which inherits from threading.Thread. This class runs on its own thread by overriding Thread.run() and continuously reads data from a shared thread safe buffer (queue.Queue).

The acquisition worker class, which also runs on its own thread, continuously polls the digitiser and pushes acquired data to a thread safe buffer shared between the acquisition worker class and the controller class (running on the main thread). The controller class then pushes the data to the writer buffer. The writer class and writer buffer are member variables of the controller class.

To extend this to multi channel writing, controller now has a list of write buffers and a list of writer threads, one for each channel. This also means that each channel of data writes to its own h5 file. A new member function called get_ch_mapping() has been added to controller which returns a dictionary that maps channel number to the index of the lists that contain the writer threads/buffers. Now, when acquisition worker provides data, the appropriate writer buffer can be written to.

As previously said, each channel writes to its own h5 file. Each h5 file also contains the config files provided at the start of the program.

A new section called output settings has been added to the recording config file. This section introduces three new config parameters: file_name, overwrite, and h5_flush_size. file_name is simply the file path of the h5 files. overwrite is a boolean which overwrites the file path provided if set to true. h5_flush_size is the number of values that is added to a h5 file per write.

Additionally, a new config parameter called software_timeout has been added to the required section of the recording config file. This timeout adds a hard timeout between each digitiser poll in the acquisition worker thread's hot loop. This is useful when testing high sample rate digitisers with many triggers as the buffers on the digitisers can fill very quickly.

Currently, the code is only functional with the DPP-DSD firmware. DPP-DSD on the digitiser in use only allows for individual channel readout, so triggering on channel 2 and receiving both channel 1 and 2 is not feasible. This will be implemented when moving over to the SCOPE firmware.

@jwaiton jwaiton left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good! Needs some minor changes but other than that its ready to go!

Comment thread core/writer.py Resolved
Comment thread core/controller.py Resolved
Comment thread core/writer.py Resolved
Comment thread core/io.py
Comment on lines +64 to +69
# single nest only! any more and you've made the config too complicated
for key_2, value_2 in values.items():
print(key_2)
config_details['key'] = f'{key}/{key_2}'
config_details['value'] = value_2
config_details.append()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning should be added here for overly deep configs. I'll add this as an issue once this PR has been merged

Comment thread felib/digitiser.py
Comment on lines +258 to +260
wf_size = self.data[7].value
ADCs = self.data[3].value
ch = self.data[0].value

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be reformatted to work with the SCOPE digitiser system.

Comment thread CAENBoard_GENERICLog.txt Resolved
Comment thread core/controller.py Resolved
Comment thread core/controller.py
Comment on lines +147 to +154
if self.recording:
write_data = wf_size, ADCs, self.event_counter
#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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also resolve the "recording data to the buffer while not recording to h5" issue in this commit. Would be best to separate them, but I'm not too picky. Add it to the commit description at the least though :)

Comment thread core/df_classes.py Resolved
Comment thread core/writer.py Resolved
Add software timeout in acquisition hot loop.
df_classes() parameter bug fix.
Recording data to the buffer while not recording to h5 bug fix.
@mmillns2
mmillns2 force-pushed the threaded-h5-template branch from 9c8b88d to 19bb851 Compare January 13, 2026 13:23
@jwaiton
jwaiton self-requested a review January 13, 2026 13:36

@jwaiton jwaiton left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR introduces multiple significant changes to CARP, but most significantly allows for multiple channels to be written to h5 files! Great work :)

@jwaiton
jwaiton merged commit 1daa683 into nu-ZOO:main Jan 13, 2026
4 of 6 checks passed
jwaiton added a commit that referenced this pull request Jan 17, 2026
#28

This PR introduces the SCOPE digitiser firmware into CARP, allowing for any compatible Dig 1 SCOPE digitisers to be used with CARP.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants