Skip to content

Micromegas decoder update#4297

Draft
hupereir wants to merge 13 commits into
sPHENIX-Collaboration:masterfrom
hupereir:micromegas-decoder-update
Draft

Micromegas decoder update#4297
hupereir wants to merge 13 commits into
sPHENIX-Collaboration:masterfrom
hupereir:micromegas-decoder-update

Conversation

@hupereir

@hupereir hupereir commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

This is TPOT fix for overlapping time frames, similar to #4292
TPOT decoder still uses taggers (GTM and enddat) to associate FEE data to 40bits gtm BCO, unlike the TPC, but this is really an orthogonal change.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work for users)
  • Requiring change in macros repository (Please provide links to the macros pull request in the last section)
  • I am a member of GitHub organization of sPHENIX Collaboration, EIC, or ECCE (contact Chris Pinkenburg to join)

What kind of change does this PR introduce? (Bug fix, feature, ...)

TODOs (if applicable)

Links to other PRs in macros and calibration repositories (if applicable)

Micromegas Decoder Update: Overlapping Time Frames Fix

Motivation / context

Fix overlapping time-frame handling in the Micromegas (TPOT) decoder so FEE data aligned to GTM 40-bit BCOs are correctly associated and truncated/overlapping waveforms are recovered. Change mirrors approach used in the recent TPC time-frame work (PR 4292) while keeping the existing GTM/enddat tagging behavior for mapping FEE data to GTM BCOs.

Key changes

  • Introduced signed/unsigned BCO difference utilities with explicit GTM/FEE rollover handling and set m_max_fee_sync_time = 1024*32.
  • Reworked BCO reference representation to a matched pair (fee_bco, gtm_bco) and added accessor get_bco_matching_reference().
  • Overhauled BCO matching logic and multiplier adjustment to use signed GTM diffs and unsigned fee-diff comparisons.
  • Changed FillPool API to accept a target BCO (FillPool(uint64_t target_bco)); removed GetSomeMoreEvents() and made SetBcoPoolSize() a no-op.
  • Refactored per-FEE state: raw-hit storage moved to per-FEE maps/arrays; per-FEE packet-ID mapping made explicit; removed older global BCO/stack containers.
  • Added recover_truncated_waveforms(target_bco) to detect and recover truncated/overlapping waveforms by creating shifted copies of hits and re-registering them; FillPool now drives reading by is_more_data_required(target_bco) and calls the recovery step.
  • MicromegasRawHitv3: added const accessor get_adc_waveforms() that exposes waveform pairs; fixed a warning-message typo.
  • Minor API/implementation cleanups: deprecated ClearCurrentEvent behavior, simplified Print(), used unique_ptr when creating recovered hits, and various formatting/lint fixes.

Potential risk areas

  • Reconstruction behavior: Core BCO-matching algorithm and multiplier logic changed — verification with Run-3/representative data is required to ensure no mis-associations.
  • IO / object exposure: MicromegasRawHitv3 now exposes waveform pair structure (start_time, samples) — downstream code expecting different views may need updates.
  • Performance: recover_truncated_waveforms() performs per-FEE scans and may add CPU overhead for high-occupancy events.
  • Thread-safety / concurrency: Per-FEE fixed arrays and internal maps change ownership/layout; concurrent access patterns must be reviewed if these objects are used from multiple threads.
  • Integration: Changes touch streaming input manager, BCO matching class, and raw-hit formats — potential cascading effects across decoding and reconstruction stages.

Possible future improvements

  • Consolidate and simplify recover_truncated_waveforms() implementation and reduce code duplication.
  • Benchmark and optimize waveform-recovery scanning for high-rate conditions.
  • Consider exposing a stable, small API for waveform access to avoid breaking callers that expect flat sample arrays.
  • Generalize BCO-difference utilities for reuse across other detector decoders.

Note: AI-generated summaries can be incorrect or incomplete. Review the changed files (particularly BCO matching, FillPool/recovery logic, and the raw-hit interface) carefully before approving for production.

hupereir added 10 commits June 11, 2026 15:15
check the difference between the requested BCO and the last BCO found in the TPOT data stream, including some extra delay corresponding to how much time it takes for TPOT to send all the data for said trigger.
- also store per FEE packet id.
- do not save hits for which there is no waveforms.
@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@hupereir, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 41 minutes and 25 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more credits in the billing tab to continue.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 06b4e612-7e8b-4540-8485-42313eaa4ede

📥 Commits

Reviewing files that changed from the base of the PR and between ad81fd1 and 820ad8a.

📒 Files selected for processing (1)
  • offline/framework/fun4allraw/MicromegasBcoMatchingInformation_v2.cc
📝 Walkthrough

Walkthrough

This PR refactors Micromegas BCO matching and raw-hit processing to use rollover-aware signed/unsigned clock-difference utilities, restructure internal state from separate "first" fields to a paired reference type, and change FillPool from event-count-based to target-BCO-driven control flow with per-FEE waveform recovery.

Changes

BCO Matching and Raw-Hit Refactor

Layer / File(s) Summary
Raw hit waveform accessor and typo fix
offline/framework/ffarawobjects/MicromegasRawHitv3.cc, offline/framework/ffarawobjects/MicromegasRawHitv3.h
New public get_adc_waveforms() const accessor exposes the internal waveform vector, and a constructor warning message typo ("moethod" → "method") is corrected.
BCO clock difference utilities and matching pair type
offline/framework/fun4allraw/MicromegasBcoMatchingInformation_v2.h, offline/framework/fun4allraw/MicromegasBcoMatchingInformation_v2.cc
Adds public type alias m_bco_matching_pair_t, static methods for signed/unsigned GTM/FEE BCO differences with ±half-range rollover handling, configuration setter for m_max_fee_sync_time (1024*32), and internal clock-bit/mask constants used for diff calculations.
BCO matching computation refactor using new diff utilities
offline/framework/fun4allraw/MicromegasBcoMatchingInformation_v2.cc
Predicted fee BCO now uses get_signed_gtm_bco_diff; is_more_data_required compares signed differences against sync-time bounds; reference init and verification switch from separate "first" fields to pair assignments; find_gtm_bco and update_multiplier_adjustment use new signed/unsigned fee-difference helpers for matching and tolerance checks throughout.
SingleMicromegasPoolInput header restructuring
offline/framework/fun4allraw/SingleMicromegasPoolInput_v2.h
FillPool signature changes from nevents count to target_bco parameter; GetSomeMoreEvents() removed; SetBcoPoolSize becomes obsolete no-op; constants expanded with MAX_FEECHANNELCOUNT; fee data buffer changes to fixed std::array; raw-hit storage refactored to per-FEE maps; prior FEE/BCO tracking state (m_FEEBclkMap, m_BclkStack) removed.
SingleMicromegasPoolInput implementation refactor
offline/framework/fun4allraw/SingleMicromegasPoolInput_v2.cc
FillPool loop now terminates on is_more_data_required(target_bco) predicate and invokes recover_truncated_waveforms; Print and CleanupUsedPackets simplified for per-FEE storage; ClearCurrentEvent replaced with deprecation notice; FEE decoding records packet IDs and uses matching-reference accessor; process_fee_data uses new raw-hit map storage; new recover_truncated_waveforms method finds matching/overlapping BCOs and restores truncated waveforms via shifted hit copies with moved ADC samples.
Streaming manager integration with target BCO
offline/framework/fun4allraw/Fun4AllStreamingInputManager.cc
FillMicromegasPool() computes ref_bco_minus_range from reference BCO and negative BCO range, passes it to each input's FillPool(target_bco) call; includes minor formatting adjustments in INTT and MVTX methods.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@hupereir

Copy link
Copy Markdown
Contributor Author
Screenshot_20260611_152259

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
offline/framework/fun4allraw/SingleMicromegasPoolInput_v2.cc (1)

964-990: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Do not publish zero-waveform hits.

This path always allocates and registers a MicromegasRawHit, even if waveform extraction produced no ADC segments. That creates hits with no payload in both the streaming manager and the per-FEE cache, which is the same invalid state the recovery path already filters out.

Suggested fix
-    // create new hit
+    if (payload.waveforms.empty())
+    {
+      continue;
+    }
+
+    // create new hit
     auto newhit = std::make_unique<MicromegasRawHit_impl>();

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a6bf1576-7fe2-427d-814d-4c545b5f1eaf

📥 Commits

Reviewing files that changed from the base of the PR and between 0ffd526 and a2a8dfb.

📒 Files selected for processing (7)
  • offline/framework/ffarawobjects/MicromegasRawHitv3.cc
  • offline/framework/ffarawobjects/MicromegasRawHitv3.h
  • offline/framework/fun4allraw/Fun4AllStreamingInputManager.cc
  • offline/framework/fun4allraw/MicromegasBcoMatchingInformation_v2.cc
  • offline/framework/fun4allraw/MicromegasBcoMatchingInformation_v2.h
  • offline/framework/fun4allraw/SingleMicromegasPoolInput_v2.cc
  • offline/framework/fun4allraw/SingleMicromegasPoolInput_v2.h

Comment thread offline/framework/fun4allraw/Fun4AllStreamingInputManager.cc
Comment thread offline/framework/fun4allraw/MicromegasBcoMatchingInformation_v2.cc
Comment thread offline/framework/fun4allraw/MicromegasBcoMatchingInformation_v2.h
Comment thread offline/framework/fun4allraw/SingleMicromegasPoolInput_v2.cc
Comment thread offline/framework/fun4allraw/SingleMicromegasPoolInput_v2.h
@hupereir hupereir marked this pull request as draft June 12, 2026 00:14
@sphenix-jenkins-ci

Copy link
Copy Markdown

Build & test report

Report for commit a2a8dfbcd55646e696c2446241acc63d192faa92:
Jenkins on fire


Automatically generated by sPHENIX Jenkins continuous integration
sPHENIX             jenkins.io

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant