From 55560efd1679d8a20acc32576c72b2135c154c05 Mon Sep 17 00:00:00 2001 From: Kurt Biery Date: Wed, 28 Jan 2026 13:00:57 -0600 Subject: [PATCH 1/5] Modified the generation of fake hits for TPs in SourceEmulatorModel to use the total number expected so far to determine how many to generate, as a proof-of-concept. --- .../models/SourceEmulatorModel.hpp | 5 ++--- .../models/detail/SourceEmulatorModel.hxx | 18 +++++++++--------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/include/datahandlinglibs/models/SourceEmulatorModel.hpp b/include/datahandlinglibs/models/SourceEmulatorModel.hpp index 168137d..6412cc9 100644 --- a/include/datahandlinglibs/models/SourceEmulatorModel.hpp +++ b/include/datahandlinglibs/models/SourceEmulatorModel.hpp @@ -156,9 +156,8 @@ class SourceEmulatorModel : public SourceEmulatorConcept // Pattern generator configs bool m_generate_periodic_adc_pattern; SourceEmulatorPatternGenerator m_pattern_generator; - uint64_t m_pattern_generator_previous_ts; - // Adding a hit every 9768 gives a TP rate of approx 100 Hz/wire using WIBEthernet - uint32_t m_time_to_wait = 9768; + // Adding a hit every 9766 gives a TP rate of approx 100 Hz/wire using WIBEthernet + uint32_t m_time_to_wait = 9766; }; } // namespace datahandlinglibs diff --git a/include/datahandlinglibs/models/detail/SourceEmulatorModel.hxx b/include/datahandlinglibs/models/detail/SourceEmulatorModel.hxx index da82f4f..a45f272 100644 --- a/include/datahandlinglibs/models/detail/SourceEmulatorModel.hxx +++ b/include/datahandlinglibs/models/detail/SourceEmulatorModel.hxx @@ -83,9 +83,9 @@ SourceEmulatorModel::conf(const confmodel::DetectorStream* link_con if (emu_params->get_TP_rate_per_channel() != 0) { TLOG() << "TP rate per channel multiplier (base of 100 Hz/ch): " << emu_params->get_TP_rate_per_channel(); // Define time to wait when adding an ADC above threshold - // Adding a hit every 9768 gives a total Sent TP rate of approx 100 Hz/wire with WIBEth - m_time_to_wait = m_time_to_wait / emu_params->get_TP_rate_per_channel(); - } + // Adding a hit every 9766 gives a total Sent TP rate of approx 100 Hz/wire with WIBEth + m_time_to_wait = m_time_to_wait / emu_params->get_TP_rate_per_channel(); + } } m_is_configured = true; @@ -160,6 +160,7 @@ SourceEmulatorModel::run_produce() TLOG_DEBUG(TLVL_BOOKKEEPING) << "Using first timestamp: " << ts_0; uint64_t timestamp = ts_0; // NOLINT(build/unsigned) int dropout_index = 0; + uint64_t number_pattern_hits_generated = 0; while (m_run_marker.load()) { // TLOG() << "Generating " << m_frames_per_tick << " for TS " << timestamp; @@ -192,7 +193,9 @@ SourceEmulatorModel::run_produce() payload.fake_frame_errors(&frame_errs); if (m_generate_periodic_adc_pattern) { - if (timestamp - m_pattern_generator_previous_ts > m_time_to_wait) { + uint64_t number_pattern_hits_expected = (timestamp - ts_0) / m_time_to_wait; + while (number_pattern_hits_generated < number_pattern_hits_expected) { + ++number_pattern_hits_generated; /* Reset the pattern from the beginning if it reaches the maximum m_pattern_index++; @@ -209,11 +212,8 @@ SourceEmulatorModel::run_produce() } //TLOG() << "Lift channel " << channel; - - // Update the previous timestamp of the pattern generator - m_pattern_generator_previous_ts = timestamp; - - } // timestamp difference + + } // (number_pattern_hits_expected - number_pattern_hits_generated) difference } // send it From 58065b5d1ee7c5af2a66a8b596a7ed48b497c79e Mon Sep 17 00:00:00 2001 From: Theo Yu Date: Tue, 17 Feb 2026 22:49:56 +0100 Subject: [PATCH 2/5] Implemented distribution of TPs across time samples and channels. Supports maximum of 64 channels times 32 alternating samples. --- .../models/detail/SourceEmulatorModel.hxx | 41 +++++++++++-------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/include/datahandlinglibs/models/detail/SourceEmulatorModel.hxx b/include/datahandlinglibs/models/detail/SourceEmulatorModel.hxx index a45f272..cb64c74 100644 --- a/include/datahandlinglibs/models/detail/SourceEmulatorModel.hxx +++ b/include/datahandlinglibs/models/detail/SourceEmulatorModel.hxx @@ -194,26 +194,35 @@ SourceEmulatorModel::run_produce() if (m_generate_periodic_adc_pattern) { uint64_t number_pattern_hits_expected = (timestamp - ts_0) / m_time_to_wait; - while (number_pattern_hits_generated < number_pattern_hits_expected) { - ++number_pattern_hits_generated; - /* Reset the pattern from the beginning if it reaches the maximum - m_pattern_index++; - if (m_pattern_index == m_pattern_generator.get_total_size()) { - m_pattern_index = 0; - } - */ - // Set the ADC to the uint16 maximum value + // Calculate how many TPs to generate in this frame + uint64_t tps_this_frame = 0; + if (number_pattern_hits_expected > number_pattern_hits_generated) { + tps_this_frame = number_pattern_hits_expected - number_pattern_hits_generated; + } + + // Cap at maximum TPs per frame: 64 channels x 32 even time samples = 2048 + // Each TP needs alternating ADC values (high/low), so only even time samples are used + const uint64_t max_tps_per_frame = 64 * 32; + if (tps_this_frame > max_tps_per_frame) { + tps_this_frame = max_tps_per_frame; + } + + // Distribute TPs across channels and time samples sequentially + // Channels cycle 0-63, time samples use even indices (0, 2, 4, ..., 62) + // This creates the alternating high/low ADC pattern needed for TP detection + for (uint64_t tp_idx = 0; tp_idx < tps_this_frame; ++tp_idx) { + int channel = tp_idx % 64; + int time_sample = (tp_idx / 64) * 2; + try { - payload.fake_adc_pattern(m_pattern_generator.get_channel_number()); - } - catch (std::exception & ex) { - //FIXME: should not happen + payload.fake_adc_pattern(channel, time_sample); + } catch (std::exception& ex) { + // FIXME: should not happen } + } - //TLOG() << "Lift channel " << channel; - - } // (number_pattern_hits_expected - number_pattern_hits_generated) difference + number_pattern_hits_generated += tps_this_frame; } // send it From cdd411684ab058682edd505560f6a0cd3cb9335d Mon Sep 17 00:00:00 2001 From: Theo Yu Date: Thu, 26 Feb 2026 03:44:56 +0100 Subject: [PATCH 3/5] Restore to using the pattern generator. At low TP rate, the default behaviour post fix should be nearly identical to pre-fix --- .../models/detail/SourceEmulatorModel.hxx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/include/datahandlinglibs/models/detail/SourceEmulatorModel.hxx b/include/datahandlinglibs/models/detail/SourceEmulatorModel.hxx index cb64c74..ef310cc 100644 --- a/include/datahandlinglibs/models/detail/SourceEmulatorModel.hxx +++ b/include/datahandlinglibs/models/detail/SourceEmulatorModel.hxx @@ -208,12 +208,14 @@ SourceEmulatorModel::run_produce() tps_this_frame = max_tps_per_frame; } - // Distribute TPs across channels and time samples sequentially - // Channels cycle 0-63, time samples use even indices (0, 2, 4, ..., 62) - // This creates the alternating high/low ADC pattern needed for TP detection + // Distribute TPs across channels (via pattern generator) and time samples + // Channels are pseudo-random 0-63, time samples use even indices (0, 2, 4, ..., 62) + // tp_call_counter resets per frame; time_sample advances every 64 TPs within a frame + uint64_t tp_call_counter = 0; for (uint64_t tp_idx = 0; tp_idx < tps_this_frame; ++tp_idx) { - int channel = tp_idx % 64; - int time_sample = (tp_idx / 64) * 2; + int channel = m_pattern_generator.get_channel_number(); + int time_sample = ((tp_call_counter / 64) % 32) * 2; + ++tp_call_counter; try { payload.fake_adc_pattern(channel, time_sample); From 9d336b52df8fc2e5237b596d09ea9d218033f63b Mon Sep 17 00:00:00 2001 From: xinyue Date: Thu, 30 Apr 2026 05:15:35 +0200 Subject: [PATCH 4/5] Rebase to current develop. From e1119243a2efd9f38ff147fb9d37b274d9f63fa3 Mon Sep 17 00:00:00 2001 From: xinyue Date: Thu, 30 Apr 2026 05:23:40 +0200 Subject: [PATCH 5/5] Remove redundant try catch. --- .../datahandlinglibs/models/detail/SourceEmulatorModel.hxx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/include/datahandlinglibs/models/detail/SourceEmulatorModel.hxx b/include/datahandlinglibs/models/detail/SourceEmulatorModel.hxx index ef310cc..7b11ea1 100644 --- a/include/datahandlinglibs/models/detail/SourceEmulatorModel.hxx +++ b/include/datahandlinglibs/models/detail/SourceEmulatorModel.hxx @@ -217,11 +217,7 @@ SourceEmulatorModel::run_produce() int time_sample = ((tp_call_counter / 64) % 32) * 2; ++tp_call_counter; - try { - payload.fake_adc_pattern(channel, time_sample); - } catch (std::exception& ex) { - // FIXME: should not happen - } + payload.fake_adc_pattern(channel, time_sample); } number_pattern_hits_generated += tps_this_frame;