Skip to content

Make CRTChannelMapService and CRTGeoService thread-safe SHARED services - #990

Open
jzennamo wants to merge 2 commits into
developfrom
feature/jaz_crt_services_thread_safe
Open

jzennamo wants to merge 2 commits into
developfrom
feature/jaz_crt_services_thread_safe

Conversation

@jzennamo

Copy link
Copy Markdown
Contributor

Makes SBND::CRTChannelMapService and sbnd::crt::CRTGeoService thread-safe SHARED art services. Both were declared LEGACY, so art refused to run any job that loads them with more than one thread or schedule.

CRTChannelMapService (first commit)

  • The maps are filled once in the constructor and only read afterwards; every lookup is now const.
  • GetTimingChainFromOfflineModuleID and GetTimingChainFromMAC5 used unordered_map::operator[], which inserts an entry when the key is missing: a write from a lookup, and a data race once two threads ask at the same time. They now use find() and still return 0 for a missing module.

CRTGeoService (second commit)

  • Every lookup only reads the tagger, module, strip, and SiPM maps; the 15 that were not yet const now are.
  • The only writer is the preBeginRun callback, which on data refreshes the calibration constants from the (already SHARED) CRT calibration database. art processes run transitions with no events in flight, so that write cannot overlap an event-time read.

The const changes alter member-function signatures, so every library that uses either service has to be rebuilt with it (24 libraries in sbndcode, which happens automatically in a release).

Testing (sbndcode v10_26_00 on sbndbuild03, MC BNB + cosmics, 10 events):

  • All 24 libraries that include either header build cleanly.
  • CRT reconstruction (crtstrips, crtclustering, crtspacepoints, crttracks): identical products to the release. All 18 leaves uproot can read are identical; the others have identical byte counts.
  • With --nthreads 4 --nschedules 4: the release stops at job setup ("CRTChannelMapService is a legacy service"); with this PR the job runs all 10 events, and its CRT products are identical to the single-threaded release run.
  • Not tested: the data path (preBeginRun with the calibration database) and the CRT decoder, since I ran MC only.

🤖 Generated with Claude Code

jzennamo and others added 2 commits November 13, 2026 09:32
The channel and timing-chain maps are filled once in the constructor and
only read afterwards, but the service was declared LEGACY, so art ran every
module that uses it (CRT decoder, strip-hit producer, CRTGeoService users)
one at a time.

- Every lookup is now const.
- GetTimingChainFromOfflineModuleID and GetTimingChainFromMAC5 used
  unordered_map::operator[], which inserts an entry on a miss: a write from
  a lookup, and a data race once two threads ask at once. They now use
  find() and return 0 on a miss, the same value operator[] returned.
- DECLARE_ART_SERVICE(..., SHARED) instead of LEGACY.
- Include the cetlib headers the constructor uses.

No change in output.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every lookup only reads the tagger, module, strip, and SiPM maps filled in
the constructor. The only writer is the preBeginRun callback, which on data
refreshes the calibration constants from the CRT calibration database (a
SHARED service). art processes run transitions with no events in flight, so
that write cannot overlap a read from another thread.

- The 15 lookups that were not yet const are now const (StripHit3DPos,
  StripWorldToLocalPos, FEBWorldPos, FEBChannel0WorldPos, CheckOverlap,
  AdjacentStrips, DifferentOrientations, WhichTagger,
  GlobalConstrainedCoordinates, IsPointInsideCRTLimits, StripArea,
  StripAverageY).
- DECLARE_ART_SERVICE(..., SHARED) instead of LEGACY.

Together with the CRTChannelMapService change, CRT jobs can now run with
more than one thread. No change in output.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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