mirror of
https://github.com/paulscherrerinstitute/sf_daq_buffer.git
synced 2026-05-04 17:34:15 +02:00
Move to using block_id instead of slot_id
This commit is contained in:
@@ -20,14 +20,14 @@ public:
|
||||
|
||||
virtual ~ImageAssembler();
|
||||
|
||||
bool is_slot_free(const int slot_id);
|
||||
bool is_slot_full(const int slot_id);
|
||||
bool is_slot_free(const int bunch_id);
|
||||
bool is_slot_full(const int bunch_id);
|
||||
|
||||
void process(int slot_id,
|
||||
void process(int bunch_id,
|
||||
const int i_module,
|
||||
const BufferBinaryBlock* block_buffer);
|
||||
|
||||
void free_slot(const int slot_id);
|
||||
void free_slot(const int bunch_id);
|
||||
|
||||
ImageMetadataBlock* get_metadata_buffer(const int slot_id);
|
||||
char* get_data_buffer(const int slot_id);
|
||||
|
||||
@@ -23,32 +23,32 @@ ImageAssembler::~ImageAssembler()
|
||||
delete[] metadata_buffer_;
|
||||
}
|
||||
|
||||
bool ImageAssembler::is_slot_free(const int slot_id)
|
||||
bool ImageAssembler::is_slot_free(const int bunch_id)
|
||||
{
|
||||
return buffer_status_[slot_id % IA_N_SLOTS] > 0;
|
||||
return buffer_status_[bunch_id % IA_N_SLOTS] > 0;
|
||||
}
|
||||
|
||||
bool ImageAssembler::is_slot_full(const int slot_id)
|
||||
bool ImageAssembler::is_slot_full(const int bunch_id)
|
||||
{
|
||||
return buffer_status_[slot_id % IA_N_SLOTS] == 0;
|
||||
return buffer_status_[bunch_id % IA_N_SLOTS] == 0;
|
||||
}
|
||||
|
||||
void ImageAssembler::process(
|
||||
int slot_id,
|
||||
int bunch_id,
|
||||
const int i_module,
|
||||
const BufferBinaryBlock* block_buffer)
|
||||
{
|
||||
slot_id %= IA_N_SLOTS;
|
||||
bunch_id %= IA_N_SLOTS;
|
||||
|
||||
// TODO: Temp workaround. Make proper initialization.
|
||||
if (i_module == 0) {
|
||||
metadata_buffer_[slot_id].block_start_pulse_id =
|
||||
metadata_buffer_[bunch_id].block_start_pulse_id =
|
||||
block_buffer->frame[0].metadata.pulse_id;
|
||||
metadata_buffer_[slot_id].block_stop_pulse_id =
|
||||
metadata_buffer_[bunch_id].block_stop_pulse_id =
|
||||
block_buffer->frame[BUFFER_BLOCK_SIZE-1].metadata.pulse_id;
|
||||
}
|
||||
|
||||
size_t slot_offset = slot_id * image_buffer_slot_n_bytes_;
|
||||
size_t slot_offset = bunch_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,23 +61,23 @@ void ImageAssembler::process(
|
||||
|
||||
// TODO: Temp workaround. We need to synchronize this access.
|
||||
if (i_module == 0) {
|
||||
metadata_buffer_[slot_id].pulse_id[i_pulse] =
|
||||
metadata_buffer_[bunch_id].pulse_id[i_pulse] =
|
||||
block_buffer->frame[i_pulse].metadata.pulse_id;
|
||||
metadata_buffer_[slot_id].frame_index[i_pulse] =
|
||||
metadata_buffer_[bunch_id].frame_index[i_pulse] =
|
||||
block_buffer->frame[i_pulse].metadata.frame_index;
|
||||
metadata_buffer_[slot_id].daq_rec[i_pulse] =
|
||||
metadata_buffer_[bunch_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_[slot_id]--;
|
||||
buffer_status_[bunch_id]--;
|
||||
}
|
||||
|
||||
void ImageAssembler::free_slot(const int slot_id)
|
||||
void ImageAssembler::free_slot(const int bunch_id)
|
||||
{
|
||||
buffer_status_[slot_id % IA_N_SLOTS] = n_modules_;
|
||||
buffer_status_[bunch_id % IA_N_SLOTS] = n_modules_;
|
||||
}
|
||||
|
||||
ImageMetadataBlock* ImageAssembler::get_metadata_buffer(const int slot_id)
|
||||
|
||||
+6
-10
@@ -26,10 +26,9 @@ 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) {
|
||||
|
||||
while(!image_assembler.is_slot_free(slot_id)) {
|
||||
while(!image_assembler.is_slot_free(block_id)) {
|
||||
this_thread::sleep_for(chrono::milliseconds(
|
||||
WRITER_IMAGE_ASSEMBLER_RETRY_MS));
|
||||
}
|
||||
@@ -44,8 +43,7 @@ void read_buffer(
|
||||
|
||||
start_time = steady_clock::now();
|
||||
|
||||
image_assembler.process(slot_id, i_module, block_buffer);
|
||||
slot_id++;
|
||||
image_assembler.process(block_id, i_module, block_buffer);
|
||||
|
||||
end_time = steady_clock::now();
|
||||
uint64_t compose_us_duration = duration_cast<microseconds>(
|
||||
@@ -117,16 +115,15 @@ 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) {
|
||||
|
||||
while(!image_assembler.is_slot_full(slot_id)) {
|
||||
while(!image_assembler.is_slot_full(block_id)) {
|
||||
this_thread::sleep_for(chrono::milliseconds(
|
||||
WRITER_IMAGE_ASSEMBLER_RETRY_MS));
|
||||
}
|
||||
|
||||
auto metadata = image_assembler.get_metadata_buffer(slot_id);
|
||||
auto data = image_assembler.get_data_buffer(slot_id);
|
||||
auto metadata = image_assembler.get_metadata_buffer(block_id);
|
||||
auto data = image_assembler.get_data_buffer(block_id);
|
||||
|
||||
auto start_time = steady_clock::now();
|
||||
|
||||
@@ -136,8 +133,7 @@ int main (int argc, char *argv[])
|
||||
auto write_us_duration = chrono::duration_cast<chrono::microseconds>(
|
||||
end_time-start_time).count();
|
||||
|
||||
image_assembler.free_slot(slot_id);
|
||||
slot_id++;
|
||||
image_assembler.free_slot(block_id);
|
||||
|
||||
cout << "sf_writer:avg_write_us ";
|
||||
cout << write_us_duration / BUFFER_BLOCK_SIZE << endl;
|
||||
|
||||
Reference in New Issue
Block a user