gstreamer
Loading...
Searching...
No Matches
event.cc
Go to the documentation of this file.
1// gstreamer
4
5// c++
6#include <sstream>
7
8bool GstreamerJsonFactory::startEventImpl(const std::shared_ptr<GEventDataCollection>& event_data) {
9 if (!ofile.is_open()) { log->error(ERR_CANTOPENOUTPUT, SFUNCTION_NAME, "Error: can't access ", filename()); }
10 if (!event_data) {
11 log->error(ERR_PUBLISH_ERROR, "event_data is null in GstreamerJsonFactory::startEventImpl");
12 return false;
13 }
14 if (!event_data->getHeader()) {
15 log->error(ERR_PUBLISH_ERROR, "event header is null in GstreamerJsonFactory::startEventImpl");
16 return false;
17 }
18
19 ensureFileInitializedForType("event");
20
21 // Reset per-event assembly.
22 is_building_event = true;
23 current_event.str(std::string());
24 current_event.clear();
25 current_event_has_header = false;
26 current_event_has_any_detector = false;
27
28 // Cache a few commonly used fields for convenience / diagnostics.
29 event_number = event_data->getHeader()->getG4LocalEvn();
30
31 // Build the event object incrementally.
32 current_event << "{";
33 current_event << "\"event_number\": " << event_number;
34
35 // Header and detectors will be appended by subsequent publish calls.
36 current_event << ", \"header\": {";
37 // Header fields will be inserted by publishEventHeaderImpl; keep the object open for now.
38 return true;
39}
40
41bool GstreamerJsonFactory::endEventImpl(const std::shared_ptr<GEventDataCollection>& event_data) {
42 if (!is_building_event) {
43 log->error(ERR_PUBLISH_ERROR, "endEventImpl called without an active event in GstreamerJsonFactory");
44 return false;
45 }
46
47 // Close header object if it was never completed (should not happen in normal flow).
48 if (!current_event_has_header) {
49 // Emit a minimal header block so the JSON remains valid.
50 current_event << "\"timestamp\": \"\", \"thread_id\": -1";
51 }
52 current_event << "}"; // close "header"
53
54 // Ensure detectors object exists even if empty (predictable schema).
55 if (!current_event_has_any_detector) {
56 current_event << ", \"detectors\": {}";
57 }
58
59 current_event << "}"; // close event object
60
61 // Write to file.
62 writeTopLevelEntry(current_event.str());
63
64 // Reset state.
65 is_building_event = false;
66
67 // event_data is intentionally unused (kept for signature consistency and future diagnostics).
68 (void)event_data;
69
70 return true;
71}
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
Generic publish-time error (null pointers, invalid state).
#define ERR_CANTOPENOUTPUT
Output medium could not be opened (file/device not accessible).