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_coincidence(ProcessingChannel coincidence_channels)

Sets the channels participating in coincidence filtering.

Parameters:

coincidence_channels – Channel bitmask (0 = none). On ZCU102 each bit selects that channel; on ZC706 a nonzero mask enables coincidence.

void set_untrigger_channels(ProcessingChannel untrigger_channels)

Sets the channels for which the signals have to fall below a specific threshold before triggering is re-enabled.

Parameters:

untrigger_channels – The channels for trigger fallback checks (0 -> None, 1 -> 1, 2 -> 2, 3 -> both).

void set_moving_average_channels(ProcessingChannel moving_average_channels)

Sets the channels for moving-average (baseline restoration).

Parameters:

moving_average_channels – The channels to enable moving-average on.

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 snapshot of the DMA map.

The copy holds shared_ptrs so DMA objects stay alive after the map is cleared on another thread.

Returns:

A copy of the DMA map.

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.

void print_event_counts()

Prints the event counts for each channel.

This function is responsible for printing the event counts for each channel.

Public Static Functions

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 bool calibrate_offset_corr(bool store, Channel channels)

Captures ADS54J60 interleaving-core offsets on AC.

ZCU102 with FMC-ADC500-CD only. On ZC706 this is a no-op that returns true. Capture at least once so /var/lib/adc500cd/offset-corr exists before using DC coupling.

Parameters:
  • store – Write the profile to /var/lib/adc500cd/offset-corr.

  • channels – ADC-channel bitmask.

Returns:

false if capture or store failed.

static void set_coincidence_window(uint32_t coincidence_window)

Sets the coincidence window.

Parameters:

coincidence_window – The coincidence window in number of samples.

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, uint8_t untrigger_channels_value) const

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

void print_moving_average_params(uint8_t channels_value, uint8_t moving_average_channels_value) const

Prints parameters related to moving average filters.

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_evaluation_params(uint8_t channels_value) const

Prints evaluation parameters for stilbene detectors and HPDs.

void print_coincidence_params(uint8_t coincidence_channels_value) const

Prints parameters for measurement of coincident events.

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::mutex dmas_mutex_

Guards dmas_ and dma_descriptor_counts_.

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).

ProcessingChannel moving_average_channels_ = ProcessingChannel::kNoChannel

Channels for moving-average filtering.

ProcessingChannel untrigger_channels_ = ProcessingChannel::kNoChannel

The channels for checking signal falls below threshold before re-enabling triggering (0 -> None, 1 -> first, 2 -> second, 3 -> both).

ProcessingChannel coincidence_channels_ = ProcessingChannel::kNoChannel

Channels participating in coincidence filtering.

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<std::unique_ptr<gpio::GpioSignalCount>, kDmaCount> 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).

Channel masks

Internal C++ bitmasks (bit 0 is channel 1). The JSON protocol uses boolean arrays; see nexmess::components::network::MessageType.

enum class nexmess::components::controller::Channel : uint8_t

Bitmask of measurement DMA channels.

Bit 0 is channel 1, bit 1 is channel 2, and so on up to kDmaCount. kNone is the empty mask. A valid selection is nonzero and less than (1 << kDmaCount).

Values:

enumerator kNone
enumerator kChannel1
enumerator kChannel2
enumerator kBoth
enumerator kChannel3
enumerator kChannel4
enumerator kAll
enum class nexmess::components::controller::ProcessingChannel : uint8_t

Bitmask of processing options per ADC channel.

Bit 0 is channel 1, bit 1 is channel 2, and so on up to kDmaCount. kNoChannel is the empty mask and is valid. A valid mask is less than 1 << kDmaCount.

Values:

enumerator kNoChannel
enumerator kChannel1
enumerator kChannel2
enumerator kBoth
enumerator kChannel3
enumerator kChannel4
enumerator kAll
enum class nexmess::components::controller::Coincidence : uint8_t

Network / ZC706 on-off flag for coincident-event filtering.

On ZCU102 the GPIO field is a per-channel mask; kEnabled maps to every channel. Local CLI on that board sets the mask directly.

Values:

enumerator kDisabled

Measurement of coincident events disabled.

enumerator kEnabled

Measurement of coincident events enabled.

enumerator kNone

Invalid coincidence setting.