JSON streamer: emit valid, correctly-nested event objects#148
Merged
Conversation
Two coupled defects in the JSON event serialization, both fixed here by reworking the shared open/close logic in endEventImpl: - gemc#116: startEventImpl opened the "header" object but nothing closed it, so "generated" and "detectors" were nested inside "header" instead of being siblings. Close the header right after its fields are written (and in the endEvent fallback when the header step is skipped), and drop the now-redundant header-closing brace from endEventImpl. - gemc#115: digitized data was written inline and the "digitized_by_detector" object was closed on every per-detector call. Because the base class interleaves publishEventTrueInfoData/publishEventDigitizedData per detector, a second digitized detector reopened/extended an already closed object, producing invalid JSON (extra braces, misplaced keys). Buffer each detector's digitized array and emit them together as one well-formed "digitized_by_detector" object in endEventImpl. The existing schema is preserved (per-detector "digitized": [] placeholder plus the "digitized_by_detector" map). Validated by running the gstreamer JSON example extended to two detectors: output now parses as valid JSON with header/generated/detectors as siblings and both detectors' digitized hits present (Geant4 11.4.1 / Qt6 dev container). Fixes gemc#115 Fixes gemc#116 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reworks the JSON event serialization so events are valid, correctly-nested JSON. Two coupled defects, fixed together because both live in the shared brace-accounting of
endEventImpl:#116 — header never closed.
startEventImplopens"header": {but nothing closed it, sogeneratedanddetectorswere emitted insideheaderinstead of as siblings. (Single-detector output still parsed, but with the wrong shape.) Fixed by closing the header right after its fields are written (and in theendEventImplfallback when the header step is skipped), and dropping the now-redundant header-closing brace fromendEventImpl.#115 — multi-detector digitized produced invalid JSON. Digitized data was written inline and
"digitized_by_detector"was closed on every per-detector call. The base class interleavespublishEventTrueInfoData/publishEventDigitizedDataper detector (gstreamer.cc:93-111), so a second digitized detector extended an already-closed object — extra braces, misplaced keys. (Note: the per-issue proposed fix of "open once, close in endEvent" does not hold under this interleaving — a later detector's true-info would land inside the still-open digitized object.) Fixed by buffering each detector's digitized array and emitting them together as one well-formed"digitized_by_detector"object inendEventImpl.The existing schema is preserved: per-detector
"digitized": []placeholder plus the"digitized_by_detector"map.Validation: ran the gstreamer JSON example extended to two detectors (ctof + ftof) in the Geant4 11.4.1 / Qt6 dev container. Before:
json.toolrejects the output (Expecting ',' delimiter). After: all worker files parse as valid JSON, withheader/generated/detectorsas siblings and both detectors' 10 digitized hits present underdigitized_by_detector.Note: filed as one PR because #115 and #116 both rewrite the same
endEventImplbrace logic and cannot be cleanly separated.Fixes #115
Fixes #116