Skip to content

hotfix: guard fADC pulse fitting against channels missing from /daq/fadc CCDB config#1358

Merged
c-dilks merged 1 commit into
developmentfrom
fix-fadc-fitpulses-npe-guard
Jul 23, 2026
Merged

hotfix: guard fADC pulse fitting against channels missing from /daq/fadc CCDB config#1358
c-dilks merged 1 commit into
developmentfrom
fix-fadc-fitpulses-npe-guard

Conversation

@mathieuouillon

Copy link
Copy Markdown
Collaborator

Summary

DetectorEventDecoder.fitPulses can throw NullPointerException on every decoded event when a channel is present in the translation table (/daq/tt/<det>) but has no matching row in the FADC config table (/daq/fadc/<det>). This is a regression introduced by #1323, which removed the hasEntryByHash guard that previously protected the nsa/nsb/tet/pedestal lookups. This PR restores that guard.

Regression

Before #1323, the fitter looped over fitterTables and only read parameters when the entry existed:

else if (daq.hasEntryByHash(hash) == true) {
    int nsa = daq.getIntValueByHash("nsa", hash);
    int nsb = daq.getIntValueByHash("nsb", hash);
    int tet = daq.getIntValueByHash("tet", hash);
    // ... fit ...
}

#1323 refactored this into a direct getOrDefault lookup + a dedicated fitPulses(data, cfg) helper, but the per-hash existence check was dropped, so getIntValueByHash is now always called. IndexedTable.getIntValueByHash does not null-check its map lookup:

public int getIntValueByHash(String item, long hash) {
    return entries.getItemByHash(hash).getValue(entryMap.get(item)).intValue(); // null -> NPE
}

So a hit whose (crate,slot,channel) is absent from the FADC table unboxes a null Integer and throws.

Symptom

java.lang.NullPointerException: Cannot invoke "java.lang.Integer.intValue()" because the return value of "java.util.Map.get(Object)" is null
    at org.jlab.utils.groups.IndexedTable.getIntValueByHash(IndexedTable.java:179)
    at org.jlab.detector.decode.DetectorEventDecoder.fitPulses(DetectorEventDecoder.java:210)
    at org.jlab.detector.decode.DetectorEventDecoder.fitPulses(DetectorEventDecoder.java:255)
    at org.jlab.detector.decode.CLASDecoder.initEvent(CLASDecoder.java:750)

Because decoding is the first stage of reconstruction, this aborts the whole cook. In the RG-L p0v11 production it failed 618/623 reconstruction jobs; each affected job logged the exception on ~every event, growing multi-MB logs (~16 GB for the workflow) and secondarily exhausting the farm output quota.

Root cause (real-world trigger)

RG-L data contains an LTCC ADC hit on hardware (crate 19, slot 18, channel 150). The translation table maps it, but the FADC config table has no such row:

# /daq/tt/ltcc   (crate 19 = sector 4)
19  18  150  4  1  4  0      # sector 4, layer 1, component 4  (all other sectors: channel 15)

# /daq/fadc/ltcc  (crate 19, slot 18)
19  18  {12, 13, 14, 115}    # no 150

This particular inconsistency is a data/CCDB issue that will be addressed separately by the DAQ table maintainers, but the decoder should not hard-fail on it — a channel with no fit configuration should be skipped, exactly as it was before #1323.

The fix

     private void fitPulses(DetectorDataDgtz data, IndexedTable cfg) {
         final DetectorDescriptor dd = data.getDescriptor();
         final long hash = IndexedTable.DEFAULT_GENERATOR.hashCode(dd.getCrate(), dd.getSlot(), dd.getChannel());
+        // Guard re-added (was removed in PR #1323): skip channels with no FADC config entry,
+        // otherwise getIntValueByHash returns null and NPEs (e.g. LTCC crate 19 / slot 18 / chan 150).
+        if (!cfg.hasEntryByHash(hash)) return;
         final int nsa = cfg.getIntValueByHash("nsa", hash);
         final int nsb = cfg.getIntValueByHash("nsb", hash);
         final int tet = cfg.getIntValueByHash("tet", hash);

One line + comment; behavior matches 14.1.1 (skip the channel).

Validation

Decoded 2000 events of RG-L run 23061 (clas_023061.evio.00040), variation rgl_spring2025, timestamp 07/20/2026-16:00:00:

<COATJAVA>/bin/decoder -n 2000 -c 2 -x 07/20/2026-16:00:00 -V rgl_spring2025 \
    -o out.hipo /cache/clas12/rg-l/data/clas_023061/clas_023061.evio.00040
build NullPointerException / 2000 decode output
14.1.2 (released binary) 1999 NPE on ~every event invalid
this branch, unpatched (same tree) 1999 NPE on ~every event invalid
this branch, patched 0 clean, exits 0 valid HIPO

The unpatched-vs-patched pair is the same build tree with only this one-line change differing, isolating the fix as the sole cause. The patched decoder simply skips the unconfigured LTCC channel and processes everything else normally.

Impact / risk

Alternative considered

Making IndexedTable.getIntValueByHash null-safe would harden all callers, but is a broader behavioral change; restoring the local guard is the minimal, targeted fix and matches the long-standing prior behavior. Happy to also add a null-check / warning in IndexedTable if preferred.

…/fadc config

PR #1323 replaced the per-detector `fitterTables` loop in
`DetectorEventDecoder.fitPulses` with a direct table lookup and, in doing so,
dropped the `hasEntryByHash(hash)` guard that previously protected the
`nsa`/`nsb`/`tet`/`pedestal` reads. Because `IndexedTable.getIntValueByHash`
does not null-check its internal map lookup, a decoded ADC hit whose
`(crate,slot,channel)` is present in `/daq/tt/<det>` but absent from the
corresponding `/daq/fadc/<det>` table now unboxes a null `Integer` and throws
`NullPointerException` on every such hit.

Restore the guard: skip channels that have no FADC config entry, matching the
pre-#1323 (14.1.1) behavior.

Reproduced on RG-L run 23061: `/daq/tt/ltcc` maps ADC channel
(crate 19, slot 18, chan 150) to LTCC sector 4, but `/daq/fadc/ltcc` has no
row for it, so 1999/2000 decoded events threw NPE with 14.1.2. With the guard
restored the same 2000 events decode cleanly (0 NPE).
@mathieuouillon
mathieuouillon requested a review from c-dilks July 23, 2026 15:27
@c-dilks c-dilks changed the title fix: guard fADC pulse fitting against channels missing from /daq/fadc CCDB config hotfix: guard fADC pulse fitting against channels missing from /daq/fadc CCDB config Jul 23, 2026
@c-dilks
c-dilks merged commit 5c5aa5a into development Jul 23, 2026
23 checks passed
@c-dilks
c-dilks deleted the fix-fadc-fitpulses-npe-guard branch July 23, 2026 20:58
@c-dilks c-dilks added the bug label Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants