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.
This commit is contained in:
2021-04-21 16:33:37 +02:00
parent f562e6ec49
commit 63820733ff
3 changed files with 28 additions and 29 deletions
+3 -5
View File
@@ -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();
};
+14 -16
View File
@@ -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()
+11 -8
View File
@@ -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();
}
}
}