From 63820733ffb226278abeae45810097467f559ea0 Mon Sep 17 00:00:00 2001 From: Andrej Babic Date: Wed, 21 Apr 2021 16:33:37 +0200 Subject: [PATCH] Rework the state machine interpretation We do not have separate messages for the state machine anymore but derive all the information from the stream itself. This also causes the statistics to change -> it is now run oriented instead of statistics modulo. --- jf-live-writer/include/WriterStats.hpp | 8 +++---- jf-live-writer/src/WriterStats.cpp | 30 ++++++++++++-------------- jf-live-writer/src/main.cpp | 19 +++++++++------- 3 files changed, 28 insertions(+), 29 deletions(-) diff --git a/jf-live-writer/include/WriterStats.hpp b/jf-live-writer/include/WriterStats.hpp index a648058..ba48a18 100644 --- a/jf-live-writer/include/WriterStats.hpp +++ b/jf-live-writer/include/WriterStats.hpp @@ -9,7 +9,6 @@ class WriterStats { const std::string detector_name_; - const size_t stats_modulo_; uint32_t image_n_bytes_{}; @@ -24,10 +23,9 @@ class WriterStats { void print_stats(); public: - WriterStats( - std::string detector_name, - const size_t stats_modulo); - void setup_run(const StoreStream& meta); + explicit WriterStats(std::string detector_name); + void start_run(const StoreStream& meta); + void end_run(); void start_image_write(); void end_image_write(); }; diff --git a/jf-live-writer/src/WriterStats.cpp b/jf-live-writer/src/WriterStats.cpp index 6e901d0..87f2800 100644 --- a/jf-live-writer/src/WriterStats.cpp +++ b/jf-live-writer/src/WriterStats.cpp @@ -5,11 +5,8 @@ using namespace std; using namespace chrono; -WriterStats::WriterStats( - string detector_name, - const size_t stats_modulo) : - detector_name_(std::move(detector_name)), - stats_modulo_(stats_modulo) +WriterStats::WriterStats(string detector_name) : + detector_name_(std::move(detector_name)) { reset_counters(); } @@ -27,13 +24,6 @@ void WriterStats::start_image_write() stats_interval_start_ = steady_clock::now(); } -void WriterStats::setup_run(const StoreStream& meta) -{ - image_n_bytes_ = (meta.image_y_size * - meta.image_x_size * - meta.bits_per_pixel) / 8; -} - void WriterStats::end_image_write() { image_counter_++; @@ -44,11 +34,19 @@ void WriterStats::end_image_write() total_buffer_write_us_ += write_us_duration; max_buffer_write_us_ = max(max_buffer_write_us_, write_us_duration); +} - if (image_counter_ == stats_modulo_) { - print_stats(); - reset_counters(); - } +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(); + reset_counters(); } void WriterStats::print_stats() diff --git a/jf-live-writer/src/main.cpp b/jf-live-writer/src/main.cpp index d130dbc..179e3aa 100644 --- a/jf-live-writer/src/main.cpp +++ b/jf-live-writer/src/main.cpp @@ -43,25 +43,21 @@ int main (int argc, char *argv[]) RamBuffer ram_buffer(config.detector_name, config.n_modules); JFH5Writer writer(config); - WriterStats stats(config.detector_name, STATS_MODULO); + WriterStats stats(config.detector_name); StoreStream meta = {}; while (true) { zmq_recv(receiver, &meta, sizeof(meta), 0); - if (meta.op_code == OP_END) { - writer.close_run(); - continue; - } - - if (meta.op_code == OP_START) { + // i_image == 0 -> we have a new run. + if (meta.i_image == 0) { writer.open_run(meta.run_id, meta.n_images, meta.image_y_size, meta.image_x_size, meta.bits_per_pixel); - stats.setup_run(meta); + stats.start_run(meta); } // Fair distribution of images among writers. @@ -77,5 +73,12 @@ int main (int argc, char *argv[]) if (i_writer == 0) { writer.write_meta(meta.run_id, meta.i_image, meta.image_metadata); } + + // i_image + 1 == meta.n_images -> we received the last image. + if (meta.i_image+1 == meta.n_images) { + writer.close_run(); + + stats.end_run(); + } } }