Controller

The controller handles an actual measurement. It either starts a measurement locally and saves the data to files or it starts a server and waits for a client to connect and request a measurement. It controls the Dma objects and the Dma objects control the actual hardware.

Classes

Controller class

class Controller : public std::enable_shared_from_this<Controller>

The Controller class represents a controller for managing DMA operations and data acquisition.

The Controller class is responsible for managing DMA operations and data acquisition. It provides methods to start and stop DMA operations, set measurement settings, and manage DMA data transfer threads. It also provides methods for storing the DMA data to files. The controller can be run in local mode, where the data is stored to local files, or in network mode, where the data is sent to the clients. In network mode, it is possible to control the measurement process remotely. The controller is designed to be used in conjunction with a server object in network mode, which provides the necessary functionality for controlling the measurement process.

Public Functions

Controller(int mem, std::filesystem::path &storage_location)

Constructor for the Controller class.

This constructor initializes a new Controller object with the specified memory identifier.

Parameters:
  • mem – The memory identifier.

  • storage_location – The location where the data should be stored.

~Controller()

Destructor for the Controller class.

This destructor destroys the DMA data thread as well.

Controller() = delete
Controller(const Controller&) = delete
Controller(Controller&&) = delete
void operator=(const Controller&) = delete
Controller &operator=(Controller&&) = delete
void deactivate_all()

Deactivates all DMA channels.

This function deactivates all DMA channels. It also deletes the DMA objects.

void set_channels(Channel channels)

Sets the channels to be used for the DMA operations.

Parameters:

channels – The channels to be used for the DMA operations (0 -> first, 1 -> second, 3 -> both).

void set_invert_channels(ProcessingChannel invert_channels)

Sets the channels to be inverted.

Parameters:

invert_channels – The channels to be inverted (0 -> first, 1 -> second, 3 -> both).

void set_fir_channels(ProcessingChannel fir_channels)

Sets the channels to be filtered using an FIR filter.

Parameters:

fir_channels – The channels to be filtered (0 -> first, 1 -> second, 3 -> both).

void set_blr_channels(ProcessingChannel blr_channels)

Sets the channels to be used for baseline restoration.

Parameters:

blr_channels – The channels to be used for baseline restoration (0 -> first, 1 -> second, 3 -> both).

void set_cfd_trigger_channels(ProcessingChannel cfd_trigger_channels)

Sets the channels to be used for CFD triggering.

Parameters:

cfd_trigger_channels – The channels to be used for CFD triggering (0 -> first, 1 -> second, 3 -> both).

void set_cfd_data_channels(ProcessingChannel cfd_data_channels)

Sets the channels to be used for CFD data output.

Parameters:

cfd_data_channels – The channels to be used for CFD data output (0 -> first, 1 -> second, 3 -> both).

void set_wants_raw_data(bool wants_raw_data)

Sets wants raw data.

Parameters:

wants_raw_data – The flag to store raw data.

void set_wants_count_data(bool wants_count_data)

Sets wants count data.

Parameters:

wants_count_data – The flag to store count data.

void set_wants_charge_data(bool wants_charge_data)

Sets wants charge data.

Parameters:

wants_charge_data – The flag to store charge data.

void set_wants_fraction_data(bool wants_fraction_data)

Sets wants integral fraction data.

Parameters:

wants_fraction_data – The flag to store fraction data.

void set_wants_max_data(bool wants_max_data)

Sets wants maximum value data.

Parameters:

wants_max_data – The flag to store maximum value data.

void set_wants_risetime_data(bool wants_risetime_data)

Sets wants risetime data.

Parameters:

wants_risetime_data – The flag to store risetime data.

void run_local()

Runs the controller in local mode.

This function is responsible for executing the main logic of the controller in local mode. All data will be stored to local files. It is impossible to control measurements remotely.

void run_network(uint16_t port)

Runs the controller in network mode.

This function is responsible for executing the main logic of the controller in network mode. All data will be sent to the clients. It is possible to control measurements remotely.

Parameters:

port – The port to be used for the network communication.

std::unordered_map<uint8_t, std::shared_ptr<nexmess::components::dma::Dma>> &get_dmas()

Returns a reference to the DMAs vector.

Returns:

A reference to the DMAs vector.

std::shared_ptr<nexmess::components::dma::Dma> get_dma(uint32_t dma_id)

Returns a pointer to the DMA object with the specified dma_id.

Parameters:

dma_id – The dma_id of the DMA object.

Returns:

A reference to the DMAs vector.

uint32_t get_dma_descriptor_count(uint32_t dma_index)

Returns the number of DMA descriptors for the specified DMA.

Parameters:

dma_index – The index of the DMA.

Returns:

The number of DMA descriptors.

bool create_dma_objects()

Creates the DMA objects.

This function creates the DMA objects.

Returns:

true if the DMA objects were created successfully, false otherwise.

void print_measurement_info() const

Prints the current measurement config.

This function is supposed to print the measurement config before starting a measurement.

uint64_t get_event_count(uint8_t channel)

Returns the event count for the specified channel.

Parameters:

channel – The channel to get the event count for.

Returns:

The event count for the specified channel.

Public Static Functions

static void set_offset_c1(int16_t offset_c1)

Sets the offset of channel 1.

Parameters:

offset_c1 – The offset of channel 1 in units of the ADC.

static void set_offset_c2(int16_t offset_c2)

Sets the offset of channel 2.

Parameters:

offset_c2 – The offset of channel 2 in units of the ADC.

static void set_measurement_time(uint32_t time)

Sets the measurement time.

The measurement time is set in ms. If it is set to 0 the measurement time is infinite.

Parameters:

time – The measurement time.

static void set_trigger_value_c1(int16_t trigger_value_c1)

Sets the trigger value of channel 1.

Parameters:

trigger_value_c1 – The trigger value of channel 1 in units of the ADC.

static void set_trigger_value_c2(int16_t trigger_value_c2)

Sets the trigger value of channel 2.

Parameters:

trigger_value_c2 – The trigger value of channel 2 in units of the ADC.

static void set_long_gate_c1(uint16_t long_gate_c1)

Sets the long gate of channel 1.

Parameters:

long_gate_c1 – The long gate of channel 1 in number of samples.

static void set_long_gate_c2(uint16_t long_gate_c2)

Sets the long gate of channel 2.

Parameters:

long_gate_c2 – The long gate of channel 2 in number of samples.

static void set_pre_gate_c1(uint16_t pre_gate_c1)

Sets the pre gate of channel 1.

Parameters:

pre_gate_c1 – The pre gate of channel 1 in number of samples.

static void set_pre_gate_c2(uint16_t pre_gate_c2)

Sets the pre gate of channel 2.

Parameters:

pre_gate_c2 – The pre gate of channel 2 in number of samples.

static void set_blr_pre_gate_c1(uint16_t blr_pre_gate_c1)

Sets the pre gate of channel 1 for baseline restoration.

Parameters:

blr_pre_gate_c1 – The pre gate for baseline restoration of channel 1 in number of samples.

static void set_blr_pre_gate_c2(uint16_t blr_pre_gate_c2)

Sets the pre gate of channel 2 for baseline restoration.

Parameters:

blr_pre_gate_c2 – The pre gate for baseline restoration of channel 2 in number of samples.

static void set_cfd_amp_c1(float cfd_amp_c1)

Sets the amplification factor for the CFD of channel 1.

Parameters:

cfd_amp_c1 – The amplification factor for the CFD of channel 1 as float value.

static void set_cfd_amp_c2(float cfd_amp_c2)

Sets the amplification factor for the CFD of channel 2.

Parameters:

cfd_amp_c2 – The amplification factor for the CFD of channel 2 as float value.

static void set_cfd_delay_c1(uint16_t cfd_delay_c1)

Sets the delay for the CFD of channel 1.

Parameters:

cfd_delay_c1 – The delay for the CFD of channel 1 in number of samples.

static void set_cfd_delay_c2(uint16_t cfd_delay_c2)

Sets the delay for the CFD of channel 2.

Parameters:

cfd_delay_c2 – The delay for the CFD of channel 2 in number of samples.

static void set_long_window_c1(uint16_t long_window_c1)

Sets the long integration window for the stilbene pulse evaluation and HPD risetime determination of channel 1.

Parameters:

long_window_c1 – The long integration window for the stilbene pulse evaluation of channel 1 in number of samples.

static void set_long_window_c2(uint16_t long_window_c2)

Sets the long integration window for the stilbene pulse evaluation and HPD risetime determination of channel 2.

Parameters:

long_window_c2 – The long integration window for the stilbene pulse evaluation of channel 2 in number of samples.

static void set_short_window_c1(uint16_t short_window_c1)

Sets the short integration window for the stilbene pulse evaluation of channel 1.

Parameters:

short_window_c1 – The short integration window for the stilbene pulse evaluation of channel 1 in number of samples.

static void set_short_window_c2(uint16_t short_window_c2)

Sets the short integration window for the stilbene pulse evaluation of channel 2.

Parameters:

short_window_c2 – The short integration window for the stilbene pulse evaluation of channel 2 in number of samples.

static void set_min_height_fraction_c1(float min_height_fraction_c1)

Sets the minimum height fraction of channel 1.

Parameters:

min_height_fraction_c1 – The minimum height fraction of channel 1 as float value.

static void set_min_height_fraction_c2(float min_height_fraction_c2)

Sets the minimum height fraction of channel 2.

Parameters:

min_height_fraction_c2 – The minimum height fraction of channel 2 as float value.

static void set_max_height_fraction_c1(float max_height_fraction_c1)

Sets the maximum height fraction of channel 1.

Parameters:

max_height_fraction_c1 – The maximum height fraction of channel 1 as float value.

static void set_max_height_fraction_c2(float max_height_fraction_c2)

Sets the maximum height fraction of channel 2.

Parameters:

max_height_fraction_c2 – The maximum height fraction of channel 2 as float value.

static bool get_buffer_full(dma::Dma &dma)

Checks if the DMA buffer is full.

and logs a message if it is.

Parameters:

dma – The DMA object to be checked.

Returns:

true if the buffer is full, false otherwise.

Private Functions

void handle_dma_data_local()

Handles the DMA data and stores in the set storage location if set.

This function is responsible for handling the DMA data. It performs the necessary operations on the received data. This function contains the loop which runs until the DMA is stopped the hardware or user signal

void destroy_dma_data_thread()

Destroys the DMA data thread.

This function destroys the DMA data thread. It also joins the thread to make sure it is finished.

bool create_files()

Creates the files for each DMA if a storage location is set.

Returns:

true if the files were created successfully, false otherwise.

template<typename DmaType>
bool create_and_enable_dma(uint8_t channel_id, uint8_t interrupt_id, uint8_t &dma_index, uint32_t register_base, const char *dma_device, const char *uio_device, uint32_t descriptor_offset, uint32_t descriptors_per_dma, uint32_t data_word_size, uint32_t package_size, uint32_t start_address, dma::DmaPurpose purpose, const char *type_name)

Helper to create and enable a single DMA object.

Returns:

true if DMA was created and enabled successfully, false otherwise.

template<typename Func>
void print_per_channel_value(const char *label, uint8_t channels_value, Func get_value_func) const

Prints a per-channel value for active channels.

void print_basic_measurement_params(uint8_t channels_value) const

Prints basic measurement parameters (offsets, trigger values, gates).

void print_cfd_params(uint8_t channels_value, uint8_t cfd_trigger_channels_value, uint8_t cfd_data_channels_value) const

Prints CFD-related parameters.

void print_integration_params(uint8_t channels_value) const

Prints integration window and fraction parameters.

void print_data_storage_flags() const

Prints data storage flags (what data types to store).

Private Members

int mem_

The memory identifier.

std::unique_ptr<std::thread> signal_thread_

The thread for handling the signals.

std::unordered_map<uint8_t, std::shared_ptr<nexmess::components::dma::Dma>> dmas_

unordered_map of DMA objects.

std::unordered_map<uint8_t, uint32_t> dma_descriptor_counts_

unordered_map of descriptor counts for each DMA.

std::unique_ptr<std::thread> dma_data_thread_ = nullptr

Thread for handling the DMA data.

Channel channels_ = Channel::kBoth

The channels to be used for the DMA operations (1 -> first, 2 -> second, 3 -> both).

ProcessingChannel invert_channels_ = ProcessingChannel::kBoth

The channels to be inverted (0 -> None, 1 -> first, 2 -> second, 3 -> both).

ProcessingChannel fir_channels_ = ProcessingChannel::kBoth

The channels to be filtered using an FIR filter (0 -> None, 1 -> first, 2 -> second, 3 -> both).

ProcessingChannel blr_channels_ = ProcessingChannel::kBoth

The channels to be used for baseline restoration (0 -> None, 1 -> first, 2 -> second, 3 -> both).

ProcessingChannel cfd_trigger_channels_ = ProcessingChannel::kBoth

The channels to be used for CFD triggering (0 -> None, 1 -> first, 2 -> second, 3 -> both).

ProcessingChannel cfd_data_channels_ = ProcessingChannel::kBoth

The channels to be used for CFD data output (0 -> None, 1 -> first, 2 -> second, 3 -> both).

std::filesystem::path storage_location_

The location where the data should be stored.

std::unordered_map<uint8_t, std::ofstream> files_

Vector of file streams for storing the data.

bool wants_raw_data_ = false

Flag to store raw data.

bool wants_count_data_ = false

Flag to store count data.

bool wants_charge_data_ = false

Flag to store charge data.

bool wants_fraction_data_ = false

Flag to store integral fraction data.

bool wants_max_data_ = false

Flag to store max data.

bool wants_risetime_data_ = false

Flag to store risetime data.

std::array<gpio::GpioSignalCount, 2> m_signal_count_gpios_

GPIOs for signal count.

Private Static Functions

static void print_channel_selection(uint8_t channel_value)

Prints channel selection (kChannel1, kChannel2, or kBoth).