From 505eeb08367e8bbe4305860f59db9b78692d45a9 Mon Sep 17 00:00:00 2001 From: Andrej Babic Date: Tue, 6 Jul 2021 15:45:58 +0200 Subject: [PATCH 01/18] Adjusted live writer to new structs --- std-det-writer/src/main.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/std-det-writer/src/main.cpp b/std-det-writer/src/main.cpp index 4af58a7..c6a7ee2 100644 --- a/std-det-writer/src/main.cpp +++ b/std-det-writer/src/main.cpp @@ -9,6 +9,7 @@ #include "WriterStats.hpp" #include "broker_format.hpp" #include "JFH5Writer.hpp" +#include "DetWriterConfig.hpp" using namespace std; using namespace buffer_config; @@ -18,14 +19,14 @@ int main (int argc, char *argv[]) { if (argc != 2) { cout << endl; - cout << "Usage: jf_live_writer [detector_json_filename]" << endl; + cout << "Usage: std-det-writer [detector_json_filename]" << endl; cout << "\tdetector_json_filename: detector config file path." << endl; cout << endl; exit(-1); } - auto const config = BufferUtils::read_json_config(string(argv[1])); + auto const config = DetWriterConfig::from_json_file(string(argv[1])); MPI_Init(nullptr, nullptr); @@ -44,7 +45,7 @@ int main (int argc, char *argv[]) RamBuffer image_buffer(config.detector_name + "_assembler", sizeof(ImageMetadata), IMAGE_N_BYTES, 1, RAM_BUFFER_N_SLOTS); - JFH5Writer writer(config); + JFH5Writer writer(config.detector_name, config.output_folder); WriterStats stats(config.detector_name); StoreStream meta = {}; @@ -72,7 +73,7 @@ int main (int argc, char *argv[]) // Fair distribution of images among writers. if (meta.i_image % n_writers == i_writer) { - char* data = ram_buffer.get_slot_data(meta.image_metadata.id); + char* data = image_buffer.get_slot_data(meta.image_metadata.id); stats.start_image_write(); writer.write_data(meta.run_id, meta.i_image, data); From 9b8a6c99de077215ccc99f8ae570671f8c020a58 Mon Sep 17 00:00:00 2001 From: Andrej Babic Date: Tue, 6 Jul 2021 15:46:20 +0200 Subject: [PATCH 02/18] Detector writer config --- .../{StdDetWriterConfig.hpp => DetWriterConfig.hpp} | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) rename std-det-writer/include/{StdDetWriterConfig.hpp => DetWriterConfig.hpp} (61%) diff --git a/std-det-writer/include/StdDetWriterConfig.hpp b/std-det-writer/include/DetWriterConfig.hpp similarity index 61% rename from std-det-writer/include/StdDetWriterConfig.hpp rename to std-det-writer/include/DetWriterConfig.hpp index 847439b..c7e335a 100644 --- a/std-det-writer/include/StdDetWriterConfig.hpp +++ b/std-det-writer/include/DetWriterConfig.hpp @@ -8,8 +8,8 @@ #include #include -struct UdpRecvConfig { - static UdpRecvConfig from_json_file(const std::string& filename) { +struct DetWriterConfig { + static DetWriterConfig from_json_file(const std::string& filename) { std::ifstream ifs(filename); rapidjson::IStreamWrapper isw(ifs); rapidjson::Document config_parameters; @@ -17,16 +17,12 @@ struct UdpRecvConfig { return { config_parameters["detector_name"].GetString(), - config_parameters["detector_type"].GetString(), - config_parameters["n_modules"].GetInt(), - config_parameters["start_udp_port"].GetInt(), + config_parameters["output_folder"].GetString() }; } const std::string detector_name; - const std::string detector_type; - const int n_modules; - const int start_udp_port; + const std::string output_folder; }; From 51b1cd2d160502fac7fc188953dc0a86fc1040be Mon Sep 17 00:00:00 2001 From: Andrej Babic Date: Tue, 6 Jul 2021 15:52:40 +0200 Subject: [PATCH 03/18] Passing the output file as a string --- std-det-writer/include/DetWriterConfig.hpp | 2 -- std-det-writer/include/JFH5Writer.hpp | 23 +++++++++++----------- std-det-writer/src/JFH5Writer.cpp | 14 +++++-------- std-det-writer/src/main.cpp | 2 +- 4 files changed, 17 insertions(+), 24 deletions(-) diff --git a/std-det-writer/include/DetWriterConfig.hpp b/std-det-writer/include/DetWriterConfig.hpp index c7e335a..96aefe3 100644 --- a/std-det-writer/include/DetWriterConfig.hpp +++ b/std-det-writer/include/DetWriterConfig.hpp @@ -17,12 +17,10 @@ struct DetWriterConfig { return { config_parameters["detector_name"].GetString(), - config_parameters["output_folder"].GetString() }; } const std::string detector_name; - const std::string output_folder; }; diff --git a/std-det-writer/include/JFH5Writer.hpp b/std-det-writer/include/JFH5Writer.hpp index b979285..95e05ee 100644 --- a/std-det-writer/include/JFH5Writer.hpp +++ b/std-det-writer/include/JFH5Writer.hpp @@ -13,7 +13,6 @@ extern "C" { class JFH5Writer { const std::string detector_name_; - const std::string root_folder_; static const int64_t NO_RUN_ID = -1; @@ -35,23 +34,23 @@ class JFH5Writer { void close_file(); public: - explicit JFH5Writer( - const std::string detector_name, const std::string root_folder); + JFH5Writer(std::string detector_name); ~JFH5Writer(); - void open_run(int64_t run_id, - uint32_t n_images, - uint32_t image_y_size, - uint32_t image_x_size, - uint32_t bits_per_pixel); + void open_run(const std::string& output_file, + const int64_t run_id, + const uint32_t n_images, + const uint32_t image_y_size, + const uint32_t image_x_size, + const uint32_t bits_per_pixel); void close_run(); - void write_data(int64_t run_id, - uint32_t index, + void write_data(const int64_t run_id, + const uint32_t index, const char* data); - void write_meta(int64_t run_id, - uint32_t index, + void write_meta(const int64_t run_id, + const uint32_t index, const ImageMetadata& meta); }; diff --git a/std-det-writer/src/JFH5Writer.cpp b/std-det-writer/src/JFH5Writer.cpp index 3e58a1d..2af43ad 100644 --- a/std-det-writer/src/JFH5Writer.cpp +++ b/std-det-writer/src/JFH5Writer.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "JFH5Writer.hpp" #include "live_writer_config.hpp" @@ -15,10 +16,8 @@ using namespace std; using namespace buffer_config; using namespace live_writer_config; -JFH5Writer::JFH5Writer( - const std::string detector_name, const std::string root_folder): - detector_name_(detector_name), - root_folder_(root_folder) +JFH5Writer::JFH5Writer(std::string detector_name): + detector_name_(std::move(detector_name)) { } @@ -42,7 +41,8 @@ hid_t JFH5Writer::get_datatype(const int bits_per_pixel) } } -void JFH5Writer::open_run(const int64_t run_id, +void JFH5Writer::open_run(const string& output_file, + const int64_t run_id, const uint32_t n_images, const uint32_t image_y_size, const uint32_t image_x_size, @@ -50,10 +50,6 @@ void JFH5Writer::open_run(const int64_t run_id, { close_run(); - const string output_folder = root_folder_ + "/" + OUTPUT_FOLDER_SYMLINK; - // TODO: Maybe add leading zeros to filename? - const string output_file = output_folder + to_string(run_id) + ".h5"; - current_run_id_ = run_id; image_y_size_ = image_y_size; image_x_size_ = image_x_size; diff --git a/std-det-writer/src/main.cpp b/std-det-writer/src/main.cpp index c6a7ee2..2212e7f 100644 --- a/std-det-writer/src/main.cpp +++ b/std-det-writer/src/main.cpp @@ -45,7 +45,7 @@ int main (int argc, char *argv[]) RamBuffer image_buffer(config.detector_name + "_assembler", sizeof(ImageMetadata), IMAGE_N_BYTES, 1, RAM_BUFFER_N_SLOTS); - JFH5Writer writer(config.detector_name, config.output_folder); + JFH5Writer writer(config.detector_name); WriterStats stats(config.detector_name); StoreStream meta = {}; From 32de4886d4237de6d684e070d8100f36c4d2cc21 Mon Sep 17 00:00:00 2001 From: Andrej Babic Date: Tue, 6 Jul 2021 16:02:29 +0200 Subject: [PATCH 04/18] Fix IPC base and URL --- core-buffer/include/buffer_config.hpp | 2 +- core-buffer/src/BufferUtils.cpp | 4 ++-- std-det-writer/src/main.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core-buffer/include/buffer_config.hpp b/core-buffer/include/buffer_config.hpp index c6f64be..ad5b12b 100644 --- a/core-buffer/include/buffer_config.hpp +++ b/core-buffer/include/buffer_config.hpp @@ -36,7 +36,7 @@ namespace buffer_config { // HWM for live stream from buffer. const int BUFFER_ZMQ_RCVHWM = 100; // IPC address of the live stream. - const std::string BUFFER_LIVE_IPC_URL = "ipc:///tmp/sf-live-"; + const std::string IPC_URL_BASE = "ipc:///tmp/std-daq-"; // Number of image slots in ram buffer - 10 seconds should be enough const int RAM_BUFFER_N_SLOTS = 100 * 10; } diff --git a/core-buffer/src/BufferUtils.cpp b/core-buffer/src/BufferUtils.cpp index abe0a3d..2809341 100644 --- a/core-buffer/src/BufferUtils.cpp +++ b/core-buffer/src/BufferUtils.cpp @@ -94,7 +94,7 @@ 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_config::BUFFER_LIVE_IPC_URL + + string ipc_address = buffer_config::IPC_URL_BASE + detector_name + "-" + stream_name; @@ -127,7 +127,7 @@ void* BufferUtils::connect_socket( void* BufferUtils::bind_socket( void* ctx, const string& detector_name, const string& stream_name) { - string ipc_address = BUFFER_LIVE_IPC_URL + + string ipc_address = IPC_URL_BASE + detector_name + "-" + stream_name; diff --git a/std-det-writer/src/main.cpp b/std-det-writer/src/main.cpp index 2212e7f..d77e64e 100644 --- a/std-det-writer/src/main.cpp +++ b/std-det-writer/src/main.cpp @@ -39,7 +39,7 @@ int main (int argc, char *argv[]) auto ctx = zmq_ctx_new(); zmq_ctx_set(ctx, ZMQ_IO_THREADS, LIVE_ZMQ_IO_THREADS); auto receiver = BufferUtils::connect_socket( - ctx, config.detector_name, "writer-agent"); + ctx, config.detector_name, "writer_agent"); const size_t IMAGE_N_BYTES = 12; RamBuffer image_buffer(config.detector_name + "_assembler", From 2fbead8c2ff44786b8ef86d94602801477c50f41 Mon Sep 17 00:00:00 2001 From: Andrej Babic Date: Tue, 6 Jul 2021 16:21:11 +0200 Subject: [PATCH 05/18] Remove unused values from StoreStream --- std-det-writer/include/broker_format.hpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/std-det-writer/include/broker_format.hpp b/std-det-writer/include/broker_format.hpp index dd45175..417d299 100644 --- a/std-det-writer/include/broker_format.hpp +++ b/std-det-writer/include/broker_format.hpp @@ -7,14 +7,11 @@ #pragma pack(push) #pragma pack(1) struct StoreStream { - ImageMetadata image_metadata; - + std::string output_file; int64_t run_id; + uint64_t image_id; uint32_t i_image; uint32_t n_images; - uint32_t image_y_size; - uint32_t image_x_size; - uint32_t bits_per_pixel; }; #pragma pack(pop) #endif //SF_DAQ_BUFFER_BROKER_FORMAT_HPP From 9a5aaf4efd939734c34d3c26d1abb6d91e322ea2 Mon Sep 17 00:00:00 2001 From: Andrej Babic Date: Tue, 6 Jul 2021 16:21:42 +0200 Subject: [PATCH 06/18] Prepare interfaces for JSON decoding --- std-det-writer/include/JFH5Writer.hpp | 12 ++++++------ std-det-writer/src/JFH5Writer.cpp | 16 ++++++++-------- std-det-writer/src/main.cpp | 18 ++++++++++++------ 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/std-det-writer/include/JFH5Writer.hpp b/std-det-writer/include/JFH5Writer.hpp index 95e05ee..2702f4e 100644 --- a/std-det-writer/include/JFH5Writer.hpp +++ b/std-det-writer/include/JFH5Writer.hpp @@ -38,11 +38,11 @@ public: ~JFH5Writer(); void open_run(const std::string& output_file, - const int64_t run_id, - const uint32_t n_images, - const uint32_t image_y_size, - const uint32_t image_x_size, - const uint32_t bits_per_pixel); + const int run_id, + const int n_images, + const int image_y_size, + const int image_x_size, + const int bits_per_pixel); void close_run(); void write_data(const int64_t run_id, @@ -51,7 +51,7 @@ public: void write_meta(const int64_t run_id, const uint32_t index, - const ImageMetadata& meta); + const ImageMetadata* meta); }; #endif //JF_LIVE_WRITER_HPP diff --git a/std-det-writer/src/JFH5Writer.cpp b/std-det-writer/src/JFH5Writer.cpp index 2af43ad..21879bd 100644 --- a/std-det-writer/src/JFH5Writer.cpp +++ b/std-det-writer/src/JFH5Writer.cpp @@ -42,11 +42,11 @@ hid_t JFH5Writer::get_datatype(const int bits_per_pixel) } void JFH5Writer::open_run(const string& output_file, - const int64_t run_id, - const uint32_t n_images, - const uint32_t image_y_size, - const uint32_t image_x_size, - const uint32_t bits_per_pixel) + const int run_id, + const int n_images, + const int image_y_size, + const int image_x_size, + const int dtype) { close_run(); @@ -233,7 +233,7 @@ void JFH5Writer::write_data( } void JFH5Writer::write_meta( - const int64_t run_id, const uint32_t index, const ImageMetadata& meta) + const int64_t run_id, const uint32_t index, const ImageMetadata* meta) { if (run_id != current_run_id_) { throw runtime_error("Invalid run_id."); @@ -260,12 +260,12 @@ void JFH5Writer::write_meta( } if (H5Dwrite(image_id_dataset_, H5T_NATIVE_UINT64, - ram_ds, file_ds, H5P_DEFAULT, &(meta.id)) < 0) { + ram_ds, file_ds, H5P_DEFAULT, &(meta->id)) < 0) { throw runtime_error("Cannot write data to pulse_id dataset."); } if (H5Dwrite(status_dataset_, H5T_NATIVE_UINT64, - ram_ds, file_ds, H5P_DEFAULT, &(meta.status)) < 0) { + ram_ds, file_ds, H5P_DEFAULT, &(meta->status)) < 0) { throw runtime_error("Cannot write data to is_good_image dataset."); } diff --git a/std-det-writer/src/main.cpp b/std-det-writer/src/main.cpp index d77e64e..b9a39e9 100644 --- a/std-det-writer/src/main.cpp +++ b/std-det-writer/src/main.cpp @@ -54,11 +54,15 @@ int main (int argc, char *argv[]) // i_image == 0 -> we have a new run. if (meta.i_image == 0) { - writer.open_run(meta.run_id, + auto image_meta = (ImageMetadata*) + image_buffer.get_slot_meta(meta.image_id); + + writer.open_run(meta.output_file, + meta.run_id, meta.n_images, - meta.image_y_size, - meta.image_x_size, - meta.bits_per_pixel); + image_meta->height, + image_meta->width, + image_meta->dtype); stats.start_run(meta); } @@ -73,7 +77,7 @@ int main (int argc, char *argv[]) // Fair distribution of images among writers. if (meta.i_image % n_writers == i_writer) { - char* data = image_buffer.get_slot_data(meta.image_metadata.id); + char* data = image_buffer.get_slot_data(meta.image_id); stats.start_image_write(); writer.write_data(meta.run_id, meta.i_image, data); @@ -82,7 +86,9 @@ int main (int argc, char *argv[]) // Only the first instance writes metadata. if (i_writer == 0) { - writer.write_meta(meta.run_id, meta.i_image, meta.image_metadata); + auto image_meta = (ImageMetadata*) + image_buffer.get_slot_meta(meta.image_id); + writer.write_meta(meta.run_id, meta.i_image, image_meta); } } From b4e19d620d058cb4ec4725b9d031478755d7492f Mon Sep 17 00:00:00 2001 From: Andrej Babic Date: Tue, 6 Jul 2021 16:33:35 +0200 Subject: [PATCH 07/18] Adjust ImageMetadata to common standard --- core-buffer/include/formats.hpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/core-buffer/include/formats.hpp b/core-buffer/include/formats.hpp index 3fc1c6b..c9e5e25 100644 --- a/core-buffer/include/formats.hpp +++ b/core-buffer/include/formats.hpp @@ -26,13 +26,14 @@ struct ModuleFrame { #pragma pack(push) #pragma pack(1) struct ImageMetadata { + uint64_t version; uint64_t id; uint64_t height; uint64_t width; - uint64_t dtype; - uint64_t encoding; - uint64_t source_id; - uint64_t status; + uint16_t dtype; + uint16_t encoding; + uint16_t source_id; + uint16_t status; uint64_t user_1; uint64_t user_2; }; From fcafeff6c535eaa4d8079e55a37352bbd891dc88 Mon Sep 17 00:00:00 2001 From: Andrej Babic Date: Tue, 6 Jul 2021 17:50:01 +0200 Subject: [PATCH 08/18] Change writer to JSON consuming --- std-det-writer/include/WriterStats.hpp | 6 +-- std-det-writer/include/broker_format.hpp | 17 ------- std-det-writer/src/WriterStats.cpp | 12 ++--- std-det-writer/src/main.cpp | 58 ++++++++++++++---------- 4 files changed, 41 insertions(+), 52 deletions(-) delete mode 100644 std-det-writer/include/broker_format.hpp diff --git a/std-det-writer/include/WriterStats.hpp b/std-det-writer/include/WriterStats.hpp index ba48a18..705c682 100644 --- a/std-det-writer/include/WriterStats.hpp +++ b/std-det-writer/include/WriterStats.hpp @@ -1,7 +1,7 @@ #include #include #include -#include "broker_format.hpp" +#include "store_format.hpp" #ifndef SF_DAQ_BUFFER_FRAMESTATS_HPP #define SF_DAQ_BUFFER_FRAMESTATS_HPP @@ -23,8 +23,8 @@ class WriterStats { void print_stats(); public: - explicit WriterStats(std::string detector_name); - void start_run(const StoreStream& meta); + explicit WriterStats(std::string detector_name, + const uint64_t image_n_bytes); void end_run(); void start_image_write(); void end_image_write(); diff --git a/std-det-writer/include/broker_format.hpp b/std-det-writer/include/broker_format.hpp deleted file mode 100644 index 417d299..0000000 --- a/std-det-writer/include/broker_format.hpp +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef SF_DAQ_BUFFER_BROKER_FORMAT_HPP -#define SF_DAQ_BUFFER_BROKER_FORMAT_HPP - -#include "formats.hpp" - - -#pragma pack(push) -#pragma pack(1) -struct StoreStream { - std::string output_file; - int64_t run_id; - uint64_t image_id; - uint32_t i_image; - uint32_t n_images; -}; -#pragma pack(pop) -#endif //SF_DAQ_BUFFER_BROKER_FORMAT_HPP diff --git a/std-det-writer/src/WriterStats.cpp b/std-det-writer/src/WriterStats.cpp index 87f2800..83ce848 100644 --- a/std-det-writer/src/WriterStats.cpp +++ b/std-det-writer/src/WriterStats.cpp @@ -5,8 +5,9 @@ using namespace std; using namespace chrono; -WriterStats::WriterStats(string detector_name) : - detector_name_(std::move(detector_name)) +WriterStats::WriterStats(string detector_name, size_t image_n_bytes) : + detector_name_(std::move(detector_name)), + image_n_bytes_(image_n_bytes) { reset_counters(); } @@ -36,13 +37,6 @@ void WriterStats::end_image_write() max_buffer_write_us_ = max(max_buffer_write_us_, write_us_duration); } -void WriterStats::start_run(const StoreStream& meta) -{ - image_n_bytes_ = (meta.image_y_size * - meta.image_x_size * - meta.bits_per_pixel) / 8; -} - void WriterStats::end_run() { print_stats(); diff --git a/std-det-writer/src/main.cpp b/std-det-writer/src/main.cpp index b9a39e9..451d530 100644 --- a/std-det-writer/src/main.cpp +++ b/std-det-writer/src/main.cpp @@ -7,10 +7,12 @@ #include "BufferUtils.hpp" #include "live_writer_config.hpp" #include "WriterStats.hpp" -#include "broker_format.hpp" +#include "store_format.hpp" #include "JFH5Writer.hpp" #include "DetWriterConfig.hpp" +#include "rapidjson/document.h" + using namespace std; using namespace buffer_config; using namespace live_writer_config; @@ -46,49 +48,59 @@ int main (int argc, char *argv[]) sizeof(ImageMetadata), IMAGE_N_BYTES, 1, RAM_BUFFER_N_SLOTS); JFH5Writer writer(config.detector_name); - WriterStats stats(config.detector_name); + WriterStats stats(config.detector_name, IMAGE_N_BYTES); - StoreStream meta = {}; + char recv_buffer[8192]; while (true) { - zmq_recv(receiver, &meta, sizeof(meta), 0); + zmq_recv(receiver, &recv_buffer, sizeof(recv_buffer), 0); - // i_image == 0 -> we have a new run. - if (meta.i_image == 0) { - auto image_meta = (ImageMetadata*) - image_buffer.get_slot_meta(meta.image_id); - - writer.open_run(meta.output_file, - meta.run_id, - meta.n_images, - image_meta->height, - image_meta->width, - image_meta->dtype); - - stats.start_run(meta); + rapidjson::Document document; + if (document.Parse(recv_buffer).HasParseError()) { + continue; } + const string output_file = document["output_file"].GetString(); + const uint64_t image_id = document["image_id"].GetUint64(); + const int run_id = document["run_id"].GetInt(); + const int i_image = document["i_image"].GetInt(); + const int n_images = document["n_images"].GetInt(); + // i_image == n_images -> end of run. - if (meta.i_image == meta.n_images) { + if (i_image == n_images) { writer.close_run(); stats.end_run(); continue; } + // i_image == 0 -> we have a new run. + if (i_image == 0) { + auto image_meta = (ImageMetadata*) + image_buffer.get_slot_meta(image_id); + + writer.open_run(output_file, + run_id, + n_images, + image_meta->height, + image_meta->width, + image_meta->dtype); + } + + // Fair distribution of images among writers. - if (meta.i_image % n_writers == i_writer) { - char* data = image_buffer.get_slot_data(meta.image_id); + if (i_image % n_writers == i_writer) { + char* data = image_buffer.get_slot_data(image_id); stats.start_image_write(); - writer.write_data(meta.run_id, meta.i_image, data); + writer.write_data(run_id, i_image, data); stats.end_image_write(); } // Only the first instance writes metadata. if (i_writer == 0) { auto image_meta = (ImageMetadata*) - image_buffer.get_slot_meta(meta.image_id); - writer.write_meta(meta.run_id, meta.i_image, image_meta); + image_buffer.get_slot_meta(image_id); + writer.write_meta(run_id, i_image, image_meta); } } From 30b33fed36303d44f502904941f0da41732bb2d6 Mon Sep 17 00:00:00 2001 From: Andrej Babic Date: Tue, 6 Jul 2021 17:51:36 +0200 Subject: [PATCH 09/18] Small fixes --- core-buffer/include/formats.hpp | 2 +- std-det-writer/src/main.cpp | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/core-buffer/include/formats.hpp b/core-buffer/include/formats.hpp index c9e5e25..1d0f0f8 100644 --- a/core-buffer/include/formats.hpp +++ b/core-buffer/include/formats.hpp @@ -30,7 +30,7 @@ struct ImageMetadata { uint64_t id; uint64_t height; uint64_t width; - uint16_t dtype; + uint16_t dtype; uint16_t encoding; uint16_t source_id; uint16_t status; diff --git a/std-det-writer/src/main.cpp b/std-det-writer/src/main.cpp index 451d530..cb3fcb9 100644 --- a/std-det-writer/src/main.cpp +++ b/std-det-writer/src/main.cpp @@ -7,7 +7,6 @@ #include "BufferUtils.hpp" #include "live_writer_config.hpp" #include "WriterStats.hpp" -#include "store_format.hpp" #include "JFH5Writer.hpp" #include "DetWriterConfig.hpp" From be01036ddea40a890188eb102f401b58bd0f2be5 Mon Sep 17 00:00:00 2001 From: Andrej Babic Date: Wed, 7 Jul 2021 11:31:07 +0200 Subject: [PATCH 10/18] Calculate bits per pixel from dtype --- std-det-writer/src/JFH5Writer.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/std-det-writer/src/JFH5Writer.cpp b/std-det-writer/src/JFH5Writer.cpp index 21879bd..cdb5deb 100644 --- a/std-det-writer/src/JFH5Writer.cpp +++ b/std-det-writer/src/JFH5Writer.cpp @@ -53,7 +53,8 @@ void JFH5Writer::open_run(const string& output_file, current_run_id_ = run_id; image_y_size_ = image_y_size; image_x_size_ = image_x_size; - bits_per_pixel_ = bits_per_pixel; + // The last digit in the enum value represents the number of bytes/pixel. + bits_per_pixel_ = (dtype % 10) * 8; image_n_bytes_ = (image_y_size_ * image_x_size_ * bits_per_pixel_) / 8; #ifdef DEBUG_OUTPUT From ad8d3630bfc3d3b05a0a2f8a04ba9d46f84ffdd1 Mon Sep 17 00:00:00 2001 From: Andrej Babic Date: Wed, 7 Jul 2021 12:05:27 +0200 Subject: [PATCH 11/18] Cleanup writer --- std-det-writer/include/WriterStats.hpp | 1 - std-det-writer/test/CMakeLists.txt | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/std-det-writer/include/WriterStats.hpp b/std-det-writer/include/WriterStats.hpp index 705c682..cacf89d 100644 --- a/std-det-writer/include/WriterStats.hpp +++ b/std-det-writer/include/WriterStats.hpp @@ -1,7 +1,6 @@ #include #include #include -#include "store_format.hpp" #ifndef SF_DAQ_BUFFER_FRAMESTATS_HPP #define SF_DAQ_BUFFER_FRAMESTATS_HPP diff --git a/std-det-writer/test/CMakeLists.txt b/std-det-writer/test/CMakeLists.txt index 8f806b0..8afe069 100644 --- a/std-det-writer/test/CMakeLists.txt +++ b/std-det-writer/test/CMakeLists.txt @@ -1,7 +1,7 @@ -add_executable(jf-live-writer-tests main.cpp) +add_executable(std-det-writer-tests main.cpp) -target_link_libraries(jf-live-writer-tests - jf-live-writer-lib +target_link_libraries(std-det-writer-tests + std-det-writer-lib zmq rt gtest From 16a84d6344959af1660e3e881bb1832c540c8c7d Mon Sep 17 00:00:00 2001 From: Andrej Babic Date: Wed, 7 Jul 2021 13:25:28 +0200 Subject: [PATCH 12/18] Created debug docker container for project --- .dockerignore | 7 ++++++- std-det-writer/debug.Dockerfile => debug.Dockerfile | 8 +++++++- 2 files changed, 13 insertions(+), 2 deletions(-) rename std-det-writer/debug.Dockerfile => debug.Dockerfile (55%) diff --git a/.dockerignore b/.dockerignore index e98d44a..197f5fd 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,4 +1,9 @@ cmake-build-*/ docker/ docs/ -scripts/ \ No newline at end of file +scripts/ + +debug.Dockerfile + +# Include files: +!docker/example_detector.json diff --git a/std-det-writer/debug.Dockerfile b/debug.Dockerfile similarity index 55% rename from std-det-writer/debug.Dockerfile rename to debug.Dockerfile index eb0f094..d5cf175 100644 --- a/std-det-writer/debug.Dockerfile +++ b/debug.Dockerfile @@ -4,7 +4,13 @@ COPY . /sf_daq_buffer/ RUN mkdir /sf_daq_buffer/build && \ cd /sf_daq_buffer/build && \ + # Build the project cmake3 .. && \ - make std-det-writer + make && \ + # Deploy the test config. + mkdir /config && \ + cp /sf_daq_buffer/docker/example_detector.json /config + + WORKDIR /sf_daq_buffer/build From b9bde97b0e176feb7cad7ccbf7e289533f57cb94 Mon Sep 17 00:00:00 2001 From: Andrej Babic Date: Wed, 7 Jul 2021 13:25:40 +0200 Subject: [PATCH 13/18] Example JSON file to use in debug container --- docker/example_detector.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 docker/example_detector.json diff --git a/docker/example_detector.json b/docker/example_detector.json new file mode 100644 index 0000000..02b0012 --- /dev/null +++ b/docker/example_detector.json @@ -0,0 +1,7 @@ +{ + "detector_name": "cSAXS.EG01V01", + "detector_type": "eiger", + "n_modules": 4, + "image_n_pixels": 123456, + "start_udp_port": 50000 +} \ No newline at end of file From 76a53a7dd8a3daca7add5275f386c49a512697a9 Mon Sep 17 00:00:00 2001 From: Andrej Babic Date: Wed, 7 Jul 2021 13:25:59 +0200 Subject: [PATCH 14/18] Put stream_address as an input parameter for the streamer --- std-stream-send/include/StreamSendConfig.hpp | 2 -- std-stream-send/src/main.cpp | 6 ++++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/std-stream-send/include/StreamSendConfig.hpp b/std-stream-send/include/StreamSendConfig.hpp index 5bf5531..9709aa8 100644 --- a/std-stream-send/include/StreamSendConfig.hpp +++ b/std-stream-send/include/StreamSendConfig.hpp @@ -19,14 +19,12 @@ struct StreamSendConfig { config_parameters["detector_name"].GetString(), config_parameters["n_modules"].GetInt(), config_parameters["image_n_pixels"].GetInt(), - config_parameters["stream_address"].GetString() }; } const std::string detector_name; const int n_modules; const int image_n_pixels; - const std::string stream_address; }; diff --git a/std-stream-send/src/main.cpp b/std-stream-send/src/main.cpp index 2418c87..4f21a43 100644 --- a/std-stream-send/src/main.cpp +++ b/std-stream-send/src/main.cpp @@ -16,9 +16,10 @@ int main (int argc, char *argv[]) if (argc != 3) { cout << endl; cout << "Usage: std_stream_send [detector_json_filename]" - " [bit_depth]" << endl; + " [bit_depth] [stream_address]" << endl; cout << "\tdetector_json_filename: detector config file path." << endl; cout << "\tbit_depth: bit depth of the incoming udp packets." << endl; + cout << "\tstream_address: address to bind the output stream." << endl; cout << endl; exit(-1); @@ -26,6 +27,7 @@ int main (int argc, char *argv[]) const auto config = StreamSendConfig::from_json_file(string(argv[1])); const int bit_depth = atoi(argv[2]); + const string stream_address = string(argv[3]); auto ctx = zmq_ctx_new(); zmq_ctx_set(ctx, ZMQ_IO_THREADS, STREAM_ZMQ_IO_THREADS); @@ -43,7 +45,7 @@ int main (int argc, char *argv[]) throw runtime_error(zmq_strerror(errno)); } - if (zmq_bind(sender, config.stream_address.c_str()) != 0) { + if (zmq_bind(sender, stream_address.c_str()) != 0) { throw runtime_error(zmq_strerror(errno)); } From 35761daca283574de44e40a366052f6bf791083e Mon Sep 17 00:00:00 2001 From: Andrej Babic Date: Wed, 7 Jul 2021 13:30:17 +0200 Subject: [PATCH 15/18] Add bit_depth and image_n_pixels to writer --- std-det-writer/include/DetWriterConfig.hpp | 2 ++ std-det-writer/src/main.cpp | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/std-det-writer/include/DetWriterConfig.hpp b/std-det-writer/include/DetWriterConfig.hpp index 96aefe3..31e983a 100644 --- a/std-det-writer/include/DetWriterConfig.hpp +++ b/std-det-writer/include/DetWriterConfig.hpp @@ -17,10 +17,12 @@ struct DetWriterConfig { return { config_parameters["detector_name"].GetString(), + config_parameters["image_n_pixels"].GetInt(), }; } const std::string detector_name; + const int image_n_pixels; }; diff --git a/std-det-writer/src/main.cpp b/std-det-writer/src/main.cpp index cb3fcb9..c836d64 100644 --- a/std-det-writer/src/main.cpp +++ b/std-det-writer/src/main.cpp @@ -20,14 +20,17 @@ int main (int argc, char *argv[]) { if (argc != 2) { cout << endl; - cout << "Usage: std-det-writer [detector_json_filename]" << endl; + cout << "Usage: std-det-writer [detector_json_filename]" + " [bit_depth]" << endl; cout << "\tdetector_json_filename: detector config file path." << endl; + cout << "\tbit_depth: bit depth of the incoming udp packets." << endl; cout << endl; exit(-1); } auto const config = DetWriterConfig::from_json_file(string(argv[1])); + const int bit_depth = atoi(argv[2]); MPI_Init(nullptr, nullptr); @@ -42,7 +45,7 @@ int main (int argc, char *argv[]) auto receiver = BufferUtils::connect_socket( ctx, config.detector_name, "writer_agent"); - const size_t IMAGE_N_BYTES = 12; + const size_t IMAGE_N_BYTES = config.image_n_pixels * bit_depth / 8; RamBuffer image_buffer(config.detector_name + "_assembler", sizeof(ImageMetadata), IMAGE_N_BYTES, 1, RAM_BUFFER_N_SLOTS); From d63e8db83e3d5b2106433a634d4f4d14619b50cd Mon Sep 17 00:00:00 2001 From: Andrej Babic Date: Wed, 7 Jul 2021 13:54:30 +0200 Subject: [PATCH 16/18] Moved config file to file with bins --- debug.Dockerfile | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/debug.Dockerfile b/debug.Dockerfile index d5cf175..db064af 100644 --- a/debug.Dockerfile +++ b/debug.Dockerfile @@ -8,9 +8,6 @@ RUN mkdir /sf_daq_buffer/build && \ cmake3 .. && \ make && \ # Deploy the test config. - mkdir /config && \ - cp /sf_daq_buffer/docker/example_detector.json /config - - + cp /sf_daq_buffer/docker/example_detector.json . WORKDIR /sf_daq_buffer/build From 01e5cb9202f105ab8b8b974abcb8eece98699024 Mon Sep 17 00:00:00 2001 From: Andrej Babic Date: Wed, 7 Jul 2021 13:55:18 +0200 Subject: [PATCH 17/18] Corrected n_arguments parameter in main scripts --- std-det-writer/src/main.cpp | 2 +- std-stream-send/src/main.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/std-det-writer/src/main.cpp b/std-det-writer/src/main.cpp index c836d64..f6cacc9 100644 --- a/std-det-writer/src/main.cpp +++ b/std-det-writer/src/main.cpp @@ -18,7 +18,7 @@ using namespace live_writer_config; int main (int argc, char *argv[]) { - if (argc != 2) { + if (argc != 3) { cout << endl; cout << "Usage: std-det-writer [detector_json_filename]" " [bit_depth]" << endl; diff --git a/std-stream-send/src/main.cpp b/std-stream-send/src/main.cpp index 4f21a43..e1894f7 100644 --- a/std-stream-send/src/main.cpp +++ b/std-stream-send/src/main.cpp @@ -13,7 +13,7 @@ using namespace buffer_config; int main (int argc, char *argv[]) { - if (argc != 3) { + if (argc != 4) { cout << endl; cout << "Usage: std_stream_send [detector_json_filename]" " [bit_depth] [stream_address]" << endl; From 63f3294b715313d143d4c3d46282f88f9c39b969 Mon Sep 17 00:00:00 2001 From: Andrej Babic Date: Wed, 7 Jul 2021 13:55:59 +0200 Subject: [PATCH 18/18] Make eiger the default build for the debug container --- debug.Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debug.Dockerfile b/debug.Dockerfile index db064af..7225593 100644 --- a/debug.Dockerfile +++ b/debug.Dockerfile @@ -5,7 +5,7 @@ COPY . /sf_daq_buffer/ RUN mkdir /sf_daq_buffer/build && \ cd /sf_daq_buffer/build && \ # Build the project - cmake3 .. && \ + cmake3 .. -DUSE_EIGER=1&& \ make && \ # Deploy the test config. cp /sf_daq_buffer/docker/example_detector.json .