mirror of
https://github.com/paulscherrerinstitute/sf_daq_buffer.git
synced 2026-04-28 01:22:23 +02:00
bit depth parameter infrastructure. partial eiger assemble image routine.
This commit is contained in:
@@ -94,13 +94,9 @@ void BufferUtils::create_destination_folder(const string& output_file)
|
||||
void* BufferUtils::connect_socket(
|
||||
void* ctx, const string& detector_name, const string& stream_name)
|
||||
{
|
||||
string ipc_address = BUFFER_LIVE_IPC_URL +
|
||||
string ipc_address = buffer_config::BUFFER_LIVE_IPC_URL +
|
||||
detector_name + "-" +
|
||||
stream_name;
|
||||
#ifdef DEBUG_OUTPUT
|
||||
cout << "[BufferUtils::connect_socket]";
|
||||
cout << " IPC address: " << ipc_address << endl;
|
||||
#endif
|
||||
|
||||
void* socket = zmq_socket(ctx, ZMQ_SUB);
|
||||
if (socket == nullptr) {
|
||||
@@ -171,6 +167,7 @@ BufferUtils::DetectorConfig BufferUtils::read_json_config(
|
||||
config_parameters["gain_file"].GetString(),
|
||||
config_parameters["detector_name"].GetString(),
|
||||
config_parameters["n_modules"].GetInt(),
|
||||
config_parameters["n_submodules"].GetInt(),
|
||||
config_parameters["start_udp_port"].GetInt(),
|
||||
config_parameters["buffer_folder"].GetString(),
|
||||
};
|
||||
|
||||
+117
-10
@@ -17,14 +17,30 @@ using namespace buffer_config;
|
||||
RamBuffer::RamBuffer(
|
||||
const string &detector_name,
|
||||
const int n_modules,
|
||||
const int n_slots) :
|
||||
const int n_submodules,
|
||||
const int bit_depth) :
|
||||
detector_name_(detector_name),
|
||||
n_modules_(n_modules),
|
||||
n_slots_(n_slots),
|
||||
n_submodules_(n_submodules_),
|
||||
bit_depth_(bit_depth),
|
||||
n_slots_(buffer_config::RAM_BUFFER_N_SLOTS),
|
||||
meta_bytes_(sizeof(ModuleFrame) * n_modules_),
|
||||
n_packets_per_frame_(bit_depth_ * MODULE_N_PIXELS / 8 / DATA_BYTES_PER_PACKET / n_modules * n_submodules),
|
||||
data_bytes_per_frame_(n_packets_per_frame_ * DATA_BYTES_PER_PACKET),
|
||||
image_bytes_(MODULE_N_BYTES * n_modules_),
|
||||
buffer_bytes_((meta_bytes_ + image_bytes_) * n_slots_)
|
||||
{
|
||||
|
||||
#ifdef DEBUG_OUTPUT
|
||||
using namespace date;
|
||||
cout << " [" << std::chrono::system_clock::now();
|
||||
cout << "] [RamBuffer::Constructor] :";
|
||||
cout << " || bit_depth_ " << bit_depth_;
|
||||
cout << " || n_packets_per_frame_ " << n_packets_per_frame_;
|
||||
cout << " || image_bytes_ " << image_bytes_;
|
||||
cout << " || data_bytes_per_frame_ " << data_bytes_per_frame_;
|
||||
cout << endl;
|
||||
#endif
|
||||
shm_fd_ = shm_open(detector_name_.c_str(), O_RDWR | O_CREAT, 0777);
|
||||
if (shm_fd_ < 0) {
|
||||
throw runtime_error(strerror(errno));
|
||||
@@ -66,7 +82,7 @@ void RamBuffer::write_frame(
|
||||
|
||||
char *dst_data = image_buffer_ +
|
||||
(image_bytes_ * slot_n) +
|
||||
(MODULE_N_BYTES * src_meta.module_id);
|
||||
(data_bytes_per_frame_ * src_meta.module_id);
|
||||
|
||||
#ifdef DEBUG_OUTPUT
|
||||
using namespace date;
|
||||
@@ -81,7 +97,7 @@ void RamBuffer::write_frame(
|
||||
#endif
|
||||
|
||||
memcpy(dst_meta, &src_meta, sizeof(ModuleFrame));
|
||||
memcpy(dst_data, src_data, MODULE_N_BYTES);
|
||||
memcpy(dst_data, src_data, data_bytes_per_frame_);
|
||||
}
|
||||
|
||||
void RamBuffer::read_frame(
|
||||
@@ -106,21 +122,30 @@ void RamBuffer::assemble_image(
|
||||
const uint64_t pulse_id, ImageMetadata &image_meta) const
|
||||
{
|
||||
const size_t slot_n = pulse_id % n_slots_;
|
||||
|
||||
ModuleFrame *src_meta = meta_buffer_ + (n_modules_ * slot_n);
|
||||
#ifdef DEBUG_OUTPUT
|
||||
using namespace date;
|
||||
cout << " [" << std::chrono::system_clock::now();
|
||||
cout << "] [RamBuffer::assemble_image] :";
|
||||
cout << " pulse_id : " << pulse_id;
|
||||
cout << endl;
|
||||
#endif
|
||||
|
||||
auto is_pulse_init = false;
|
||||
auto is_good_image = true;
|
||||
|
||||
|
||||
// for each module it collects the metadata from each frame
|
||||
for (int i_module=0; i_module < n_modules_; i_module++) {
|
||||
// and verifies if is a good frame
|
||||
for (int i_module=0; i_module < n_modules_; i_module++) {
|
||||
ModuleFrame *frame_meta = src_meta + i_module;
|
||||
|
||||
#ifdef DEBUG_OUTPUT
|
||||
using namespace date;
|
||||
cout << " [" << std::chrono::system_clock::now();
|
||||
cout << "] [RamBuffer::assemble_image] :";
|
||||
cout << "module_id: " << i_module;
|
||||
cout << "] module_id: " << i_module;
|
||||
cout << " || frame index: " << frame_meta->frame_index;
|
||||
cout << " || pulse index: " << frame_meta->pulse_id;
|
||||
cout << " || row: " << frame_meta->row;
|
||||
cout << " || column: " << frame_meta->column;
|
||||
cout << " || n_recv_packets: " << frame_meta->n_recv_packets;
|
||||
@@ -128,7 +153,7 @@ void RamBuffer::assemble_image(
|
||||
#endif
|
||||
|
||||
auto is_good_frame =
|
||||
frame_meta->n_recv_packets == N_PACKETS_PER_FRAME;
|
||||
frame_meta->n_recv_packets == n_packets_per_frame_;
|
||||
|
||||
if (!is_good_frame) {
|
||||
is_good_image = false;
|
||||
@@ -137,7 +162,7 @@ void RamBuffer::assemble_image(
|
||||
cout << " [" << std::chrono::system_clock::now();
|
||||
cout << "] [RamBuffer::assemble_image] ";
|
||||
cout << " not a good frame " << is_good_frame;
|
||||
cout << "n_recv_packets != N_PACKETS_PER_FRAME";
|
||||
cout << "n_recv_packets != n_packets_per_frame_";
|
||||
cout << endl;
|
||||
#endif
|
||||
continue;
|
||||
@@ -217,6 +242,13 @@ void RamBuffer::assemble_image(
|
||||
|
||||
image_meta.is_good_image = is_good_image;
|
||||
|
||||
// bad practice, what'd be the nicest way to do this?
|
||||
#ifdef USE_EIGER
|
||||
if (is_good_image){
|
||||
assemble_eiger_image(image_meta, bit_depth_, slot_n);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!is_pulse_init) {
|
||||
image_meta.pulse_id = 0;
|
||||
image_meta.frame_index = 0;
|
||||
@@ -231,3 +263,78 @@ char* RamBuffer::read_image(const uint64_t pulse_id) const
|
||||
|
||||
return src_data;
|
||||
}
|
||||
|
||||
void RamBuffer::assemble_eiger_image(ImageMetadata &image_meta, const int bit_depth, const size_t slot_n) const
|
||||
{
|
||||
|
||||
const uint32_t n_bytes_per_module_line = N_BYTES_PER_MODULE_LINE(bit_depth);
|
||||
const uint32_t n_bytes_per_gap = GAP_X_MODULE_PIXELS * bit_depth / 8;
|
||||
const uint32_t n_bytes_per_image_line = n_bytes_per_module_line * 2 + n_bytes_per_gap;
|
||||
const int n_lines_per_frame = DATA_BYTES_PER_PACKET / n_bytes_per_module_line * n_packets_per_frame_;
|
||||
|
||||
#ifdef DEBUG_OUTPUT
|
||||
using namespace date;
|
||||
cout << " [" << std::chrono::system_clock::now();
|
||||
cout << "] [RamBuffer::is_good_image] ";
|
||||
cout << " image_meta.frame_index" << image_meta.frame_index;
|
||||
cout << " Verification: " << endl;
|
||||
cout << " || n_bytes_per_module_line " << n_bytes_per_module_line << endl;
|
||||
cout << " || n_bytes_per_gap " << n_bytes_per_gap << endl;
|
||||
cout << " || n_bytes_per_image_line " << n_bytes_per_image_line;
|
||||
cout << " || n_lines_per_frame " << n_lines_per_frame << endl;;
|
||||
#endif
|
||||
for (int i_module=0; i_module < n_modules_; i_module++) {
|
||||
// defines from which eiger module this submodule is part
|
||||
const int eiger_module_index = i_module / n_submodules_;
|
||||
// module frame metadata
|
||||
ModuleFrame *frame_meta = meta_buffer_ + (n_modules_ * slot_n) + i_module;
|
||||
// module frame data
|
||||
char *frame_data = image_buffer_ + (image_bytes_ * slot_n) + (data_bytes_per_frame_ * i_module);
|
||||
// top
|
||||
uint32_t source_offset = 0;
|
||||
uint32_t reverse_factor = 0;
|
||||
uint32_t bottom_offset = 0;
|
||||
uint32_t line_number = 0;
|
||||
uint32_t dest_line_offset=0;
|
||||
|
||||
// If bottom -> reversed
|
||||
const auto reverse = IS_BOTTOM(frame_meta->row);
|
||||
if (reverse == -1){
|
||||
line_number = MODULE_Y_SIZE + GAP_Y_MODULE_PIXELS;
|
||||
reverse_factor = MODULE_Y_SIZE - 1;
|
||||
dest_line_offset += n_bytes_per_image_line * (MODULE_Y_SIZE + GAP_Y_MODULE_PIXELS);
|
||||
}
|
||||
|
||||
const auto i_module_row = frame_meta->row;
|
||||
const auto i_module_column = frame_meta->column;
|
||||
|
||||
uint32_t dest_module_line = line_number;
|
||||
|
||||
if (i_module_column == 1){
|
||||
source_offset += MODULE_X_SIZE + GAP_X_MODULE_PIXELS;
|
||||
dest_line_offset += n_bytes_per_module_line + n_bytes_per_gap;
|
||||
}
|
||||
|
||||
for (uint32_t frame_line=0; frame_line < n_lines_per_frame; frame_line++)
|
||||
{
|
||||
// Copy each chip line individually, to allow a gap of n_bytes_per_chip_gap in the destination memory.
|
||||
memcpy (
|
||||
(char*)(image_buffer_ + (image_bytes_ * slot_n)) + dest_line_offset,
|
||||
(char*) frame_data + source_offset,
|
||||
n_bytes_per_module_line
|
||||
);
|
||||
|
||||
memcpy (
|
||||
(char*)(image_buffer_ + (image_bytes_ * slot_n)) + dest_line_offset + n_bytes_per_module_line,
|
||||
(char*) frame_data + source_offset + n_bytes_per_module_line,
|
||||
n_bytes_per_module_line
|
||||
);
|
||||
|
||||
source_offset += n_bytes_per_module_line;
|
||||
dest_line_offset += reverse * n_bytes_per_image_line;
|
||||
}
|
||||
line_number += n_lines_per_frame;
|
||||
dest_module_line = line_number + n_lines_per_frame - 1;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user