mirror of
https://github.com/paulscherrerinstitute/sf_daq_buffer.git
synced 2026-05-06 03:54:12 +02:00
Finish slot_id calculation
This commit is contained in:
@@ -12,7 +12,8 @@ class ImageAssembler {
|
||||
const size_t image_buffer_slot_n_bytes_;
|
||||
|
||||
char* image_buffer_;
|
||||
ImageMetadataBlock* metadata_buffer_;
|
||||
ImageMetadataBlock* image_metadata_buffer_;
|
||||
ModuleFrame* frame_metadata_buffer_;
|
||||
std::atomic_int* buffer_status_;
|
||||
|
||||
public:
|
||||
|
||||
@@ -9,7 +9,9 @@ ImageAssembler::ImageAssembler(const size_t n_modules) :
|
||||
image_buffer_slot_n_bytes_(BUFFER_BLOCK_SIZE * MODULE_N_BYTES * n_modules_)
|
||||
{
|
||||
image_buffer_ = new char[IA_N_SLOTS * image_buffer_slot_n_bytes_];
|
||||
metadata_buffer_ = new ImageMetadataBlock[IA_N_SLOTS];
|
||||
image_metadata_buffer_ = new ImageMetadataBlock[IA_N_SLOTS];
|
||||
frame_metadata_buffer_ =
|
||||
new ModuleFrame[IA_N_SLOTS * BUFFER_BLOCK_SIZE * n_modules];
|
||||
buffer_status_ = new atomic_int[IA_N_SLOTS];
|
||||
|
||||
for (size_t i=0; i<IA_N_SLOTS; i++) {
|
||||
@@ -20,17 +22,19 @@ ImageAssembler::ImageAssembler(const size_t n_modules) :
|
||||
ImageAssembler::~ImageAssembler()
|
||||
{
|
||||
delete[] image_buffer_;
|
||||
delete[] metadata_buffer_;
|
||||
delete[] image_metadata_buffer_;
|
||||
}
|
||||
|
||||
bool ImageAssembler::is_slot_free(const int bunch_id)
|
||||
{
|
||||
return buffer_status_[bunch_id % IA_N_SLOTS].load() > 0;
|
||||
auto slot_id = bunch_id % IA_N_SLOTS;
|
||||
return buffer_status_[slot_id].load() > 0;
|
||||
}
|
||||
|
||||
bool ImageAssembler::is_slot_full(const int bunch_id)
|
||||
{
|
||||
return buffer_status_[bunch_id % IA_N_SLOTS].load() == 0;
|
||||
auto slot_id = bunch_id % IA_N_SLOTS;
|
||||
return buffer_status_[slot_id].load() == 0;
|
||||
}
|
||||
|
||||
void ImageAssembler::process(
|
||||
@@ -38,17 +42,20 @@ void ImageAssembler::process(
|
||||
const int i_module,
|
||||
const BufferBinaryBlock* block_buffer)
|
||||
{
|
||||
bunch_id %= IA_N_SLOTS;
|
||||
auto slot_id = bunch_id % IA_N_SLOTS;
|
||||
|
||||
// TODO: Temp workaround. Make proper initialization.
|
||||
if (i_module == 0) {
|
||||
metadata_buffer_[bunch_id].block_start_pulse_id =
|
||||
image_metadata_buffer_[slot_id].block_start_pulse_id =
|
||||
block_buffer->frame[0].metadata.pulse_id;
|
||||
metadata_buffer_[bunch_id].block_stop_pulse_id =
|
||||
image_metadata_buffer_[slot_id].block_stop_pulse_id =
|
||||
block_buffer->frame[BUFFER_BLOCK_SIZE-1].metadata.pulse_id;
|
||||
}
|
||||
|
||||
size_t slot_offset = bunch_id * image_buffer_slot_n_bytes_;
|
||||
auto metadata_offset =
|
||||
frame_metadata_buffer_[metadata_offset] = 0;
|
||||
|
||||
size_t slot_offset = slot_id * image_buffer_slot_n_bytes_;
|
||||
size_t module_image_offset = i_module * MODULE_N_BYTES;
|
||||
|
||||
for (size_t i_pulse=0; i_pulse < BUFFER_BLOCK_SIZE; i_pulse++) {
|
||||
@@ -61,32 +68,34 @@ void ImageAssembler::process(
|
||||
|
||||
// TODO: Temp workaround. We need to synchronize this access.
|
||||
if (i_module == 0) {
|
||||
metadata_buffer_[bunch_id].pulse_id[i_pulse] =
|
||||
image_metadata_buffer_[slot_id].pulse_id[i_pulse] =
|
||||
block_buffer->frame[i_pulse].metadata.pulse_id;
|
||||
metadata_buffer_[bunch_id].frame_index[i_pulse] =
|
||||
image_metadata_buffer_[slot_id].frame_index[i_pulse] =
|
||||
block_buffer->frame[i_pulse].metadata.frame_index;
|
||||
metadata_buffer_[bunch_id].daq_rec[i_pulse] =
|
||||
image_metadata_buffer_[slot_id].daq_rec[i_pulse] =
|
||||
block_buffer->frame[i_pulse].metadata.daq_rec;
|
||||
// metadata_buffer_[slot_id].is_good_image[i_pulse] =
|
||||
// block_buffer->frame[i_pulse].is_good_image.pulse_id;
|
||||
}
|
||||
}
|
||||
|
||||
buffer_status_[bunch_id].fetch_sub(1);
|
||||
buffer_status_[slot_id].fetch_sub(1);
|
||||
}
|
||||
|
||||
void ImageAssembler::free_slot(const int bunch_id)
|
||||
{
|
||||
buffer_status_[bunch_id % IA_N_SLOTS].store(n_modules_);
|
||||
auto slot_id = bunch_id % IA_N_SLOTS;
|
||||
buffer_status_[slot_id].store(n_modules_);
|
||||
}
|
||||
|
||||
ImageMetadataBlock* ImageAssembler::get_metadata_buffer(const int bunch_id)
|
||||
{
|
||||
return &(metadata_buffer_[bunch_id % IA_N_SLOTS]);
|
||||
auto slot_id = bunch_id % IA_N_SLOTS;
|
||||
return &(image_metadata_buffer_[slot_id]);
|
||||
}
|
||||
|
||||
char* ImageAssembler::get_data_buffer(const int bunch_id)
|
||||
{
|
||||
return image_buffer_ +
|
||||
((bunch_id % IA_N_SLOTS) * image_buffer_slot_n_bytes_);
|
||||
auto slot_id = bunch_id % IA_N_SLOTS;
|
||||
return image_buffer_ + (slot_id * image_buffer_slot_n_bytes_);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user