From 08a4b891a68f9f8e27fafdd65858c2abd6ccdb67 Mon Sep 17 00:00:00 2001 From: Andrej Babic Date: Mon, 8 Jun 2020 17:28:03 +0200 Subject: [PATCH] Add sync limit --- sf-stream/include/stream_config.hpp | 2 ++ sf-stream/src/LiveRecvModule.cpp | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/sf-stream/include/stream_config.hpp b/sf-stream/include/stream_config.hpp index 6d0d1e4..beea625 100644 --- a/sf-stream/include/stream_config.hpp +++ b/sf-stream/include/stream_config.hpp @@ -6,4 +6,6 @@ namespace stream_config const size_t STREAM_RCVHWM = 100; // Size of buffer between the receiving and sending part. const int STREAM_FASTQUEUE_SLOTS = 5; + // If the modules are offset more than 1000 pulses, crush. + const uint64_t PULSE_OFFSET_LIMIT = 1000; } diff --git a/sf-stream/src/LiveRecvModule.cpp b/sf-stream/src/LiveRecvModule.cpp index 2dd082a..0a7993e 100644 --- a/sf-stream/src/LiveRecvModule.cpp +++ b/sf-stream/src/LiveRecvModule.cpp @@ -105,6 +105,24 @@ uint64_t LiveRecvModule::align_modules( max_pulse_id = max(max_pulse_id, module_meta.pulse_id); } + auto max_diff = max_pulse_id - min_pulse_id; + if (max_diff > PULSE_OFFSET_LIMIT) { + stringstream err_msg; + + err_msg << "[LiveRecvModule::align_modules]"; + err_msg << " PULSE_OFFSET_LIMIT exceeded."; + err_msg << " Modules out of sync for " << max_diff << " pulses."; + + for (auto& module_meta : meta->module) { + err_msg << " (" << module_meta.module_id << ", "; + err_msg << module_meta.pulse_id << "),"; + } + + err_msg << endl; + + throw runtime_error(err_msg.str()); + } + // Second pass - align all receivers to max_pulse_id. for (size_t i_module = 0; i_module < n_modules_; i_module++) { auto& module_meta = meta->module[i_module];