mirror of
https://github.com/paulscherrerinstitute/sf_daq_buffer.git
synced 2026-05-02 21:54:14 +02:00
Implement external slot_id book keeping
This commit is contained in:
@@ -15,20 +15,18 @@ class ImageAssembler {
|
||||
ImageMetadataBlock* metadata_buffer_;
|
||||
std::atomic_int* buffer_status_;
|
||||
|
||||
int read_slot_id_;
|
||||
std::atomic_int write_slot_id_;
|
||||
|
||||
public:
|
||||
ImageAssembler(const size_t n_modules);
|
||||
|
||||
virtual ~ImageAssembler();
|
||||
|
||||
int get_free_slot();
|
||||
void process(const int slot_id,
|
||||
bool is_slot_free(const int slot_id);
|
||||
bool is_slot_full(const int slot_id);
|
||||
|
||||
void process(int slot_id,
|
||||
const int i_module,
|
||||
const BufferBinaryBlock* block_buffer);
|
||||
|
||||
int get_full_slot();
|
||||
void free_slot(const int slot_id);
|
||||
|
||||
ImageMetadataBlock* get_metadata_buffer(const int slot_id);
|
||||
|
||||
@@ -15,9 +15,6 @@ ImageAssembler::ImageAssembler(const size_t n_modules) :
|
||||
for (size_t i=0; i<IA_N_SLOTS; i++) {
|
||||
free_slot(i);
|
||||
}
|
||||
|
||||
read_slot_id_ = 0;
|
||||
write_slot_id_ = 0;
|
||||
}
|
||||
|
||||
ImageAssembler::~ImageAssembler()
|
||||
@@ -26,20 +23,23 @@ ImageAssembler::~ImageAssembler()
|
||||
delete[] metadata_buffer_;
|
||||
}
|
||||
|
||||
int ImageAssembler::get_free_slot()
|
||||
bool ImageAssembler::is_slot_free(const int slot_id)
|
||||
{
|
||||
if (buffer_status_[write_slot_id_] > 0) {
|
||||
return write_slot_id_;
|
||||
}
|
||||
return buffer_status_[slot_id % IA_N_SLOTS] > 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
bool ImageAssembler::is_slot_full(const int slot_id)
|
||||
{
|
||||
return buffer_status_[slot_id % IA_N_SLOTS] == 0;
|
||||
}
|
||||
|
||||
void ImageAssembler::process(
|
||||
const int slot_id,
|
||||
int slot_id,
|
||||
const int i_module,
|
||||
const BufferBinaryBlock* block_buffer)
|
||||
{
|
||||
slot_id %= IA_N_SLOTS;
|
||||
|
||||
// TODO: Temp workaround. Make proper initialization.
|
||||
if (i_module == 0) {
|
||||
metadata_buffer_[slot_id].block_first_pulse_id =
|
||||
@@ -72,37 +72,21 @@ void ImageAssembler::process(
|
||||
}
|
||||
}
|
||||
|
||||
auto previous_status = buffer_status_[slot_id].fetch_sub(1);
|
||||
|
||||
// 1 because fetch is done before subtraction.
|
||||
if (previous_status == 1) {
|
||||
auto next_write_slot_id = (int)((write_slot_id_+1) % IA_N_SLOTS);
|
||||
write_slot_id_ = next_write_slot_id;
|
||||
}
|
||||
}
|
||||
|
||||
int ImageAssembler::get_full_slot()
|
||||
{
|
||||
if (buffer_status_[read_slot_id_] == 0) {
|
||||
return read_slot_id_;
|
||||
}
|
||||
|
||||
return -1;
|
||||
buffer_status_[slot_id]--;
|
||||
}
|
||||
|
||||
void ImageAssembler::free_slot(const int slot_id)
|
||||
{
|
||||
buffer_status_[slot_id] = n_modules_;
|
||||
|
||||
read_slot_id_ = (int)((read_slot_id_+1) % IA_N_SLOTS);
|
||||
buffer_status_[slot_id % IA_N_SLOTS] = n_modules_;
|
||||
}
|
||||
|
||||
ImageMetadataBlock* ImageAssembler::get_metadata_buffer(const int slot_id)
|
||||
{
|
||||
return &(metadata_buffer_[slot_id]);
|
||||
return &(metadata_buffer_[slot_id % IA_N_SLOTS]);
|
||||
}
|
||||
|
||||
char* ImageAssembler::get_data_buffer(const int slot_id)
|
||||
{
|
||||
return image_buffer_ + (slot_id * image_buffer_slot_n_bytes_);
|
||||
return image_buffer_ +
|
||||
((slot_id % IA_N_SLOTS) * image_buffer_slot_n_bytes_);
|
||||
}
|
||||
|
||||
@@ -26,10 +26,10 @@ void read_buffer(
|
||||
BufferBinaryReader block_reader(device, channel_name);
|
||||
auto block_buffer = new BufferBinaryBlock();
|
||||
|
||||
int slot_id = 0;
|
||||
for (uint64_t block_id:buffer_blocks) {
|
||||
|
||||
int slot_id;
|
||||
while((slot_id = image_assembler.get_free_slot()) == -1) {
|
||||
while(!image_assembler.is_slot_free(slot_id)) {
|
||||
this_thread::sleep_for(chrono::milliseconds(
|
||||
WRITER_IMAGE_ASSEMBLER_RETRY_MS));
|
||||
}
|
||||
@@ -45,6 +45,7 @@ void read_buffer(
|
||||
start_time = steady_clock::now();
|
||||
|
||||
image_assembler.process(slot_id, i_module, block_buffer);
|
||||
slot_id++;
|
||||
|
||||
end_time = steady_clock::now();
|
||||
uint64_t compose_us_duration = duration_cast<microseconds>(
|
||||
@@ -116,10 +117,10 @@ int main (int argc, char *argv[])
|
||||
|
||||
JFH5Writer writer(output_file, start_pulse_id, stop_pulse_id, n_modules);
|
||||
|
||||
int slot_id = 0;
|
||||
for (uint64_t block_id:buffer_blocks) {
|
||||
|
||||
int slot_id;
|
||||
while((slot_id = image_assembler.get_full_slot()) == -1) {
|
||||
while(!image_assembler.is_slot_full(slot_id)) {
|
||||
this_thread::sleep_for(chrono::milliseconds(
|
||||
WRITER_IMAGE_ASSEMBLER_RETRY_MS));
|
||||
}
|
||||
@@ -136,6 +137,7 @@ int main (int argc, char *argv[])
|
||||
end_time-start_time).count();
|
||||
|
||||
image_assembler.free_slot(slot_id);
|
||||
slot_id++;
|
||||
|
||||
cout << "sf_writer:avg_write_us ";
|
||||
cout << write_us_duration / BUFFER_BLOCK_SIZE << endl;
|
||||
|
||||
Reference in New Issue
Block a user