gstreamer
Loading...
Searching...
No Matches
event.cc
Go to the documentation of this file.
1// gstreamer
4
5// c++
6#include <sstream>
7
8// Implementation summary:
9// Start and finalize one JSON event object using the ordered event publish sequence.
10
11bool GstreamerJsonFactory::startEventImpl(const std::shared_ptr<GEventDataCollection>& event_data) {
12 if (!ofile.is_open()) { log->error(ERR_CANTOPENOUTPUT, SFUNCTION_NAME, "Error: can't access ", filename()); }
13 if (!event_data) {
14 log->error(ERR_PUBLISH_ERROR, "event_data is null in GstreamerJsonFactory::startEventImpl");
15 return false;
16 }
17 if (!event_data->getHeader()) {
18 log->error(ERR_PUBLISH_ERROR, "event header is null in GstreamerJsonFactory::startEventImpl");
19 return false;
20 }
21
22 // Ensure the top-level JSON document is initialized for event output.
23 ensureFileInitializedForType("event");
24
25 // Reset all per-event assembly state.
26 is_building_event = true;
27 current_event.str(std::string());
28 current_event.clear();
29 current_event_has_header = false;
30 current_event_has_any_detector = false;
31
32 // Cache the event number early so it is available to the root event object.
33 event_number = event_data->getHeader()->getG4LocalEvn();
34
35 current_event << "{";
36 current_event << "\"event_number\": " << event_number;
37
38 // Open the header object now. publishEventHeaderImpl() fills its contents.
39 current_event << ", \"header\": {";
40 return true;
41}
42
43bool GstreamerJsonFactory::endEventImpl(const std::shared_ptr<GEventDataCollection>& event_data) {
44 if (!is_building_event) {
45 log->error(ERR_PUBLISH_ERROR, "endEventImpl called without an active event in GstreamerJsonFactory");
46 return false;
47 }
48
49 // If the caller skipped the header step, emit a minimal fallback so the JSON remains valid.
50 if (!current_event_has_header) {
51 current_event << "\"timestamp\": \"\", \"thread_id\": -1";
52 }
53 current_event << "}";
54
55 // Keep the event schema predictable even when no detector banks were published.
56 if (!current_event_has_any_detector) {
57 current_event << ", \"detectors\": {}";
58 }
59
60 current_event << "}";
61
62 writeTopLevelEntry(current_event.str());
63
64 is_building_event = false;
65
66 (void)event_data;
67 return true;
68}
std::shared_ptr< GLogger > log
void error(int exit_code, Args &&... args) const
Shared constants and error codes for the gstreamer module.
#define ERR_PUBLISH_ERROR
Publish sequence encountered invalid state or invalid input data.
#define ERR_CANTOPENOUTPUT
Output medium could not be opened successfully.
JSON streamer plugin declarations.