gstreamer
Loading...
Searching...
No Matches
publishTrueInfo.cc
Go to the documentation of this file.
1// gstreamer
4
5// c++
6#include <sstream>
7
8bool GstreamerJsonFactory::publishEventTrueInfoDataImpl(const std::string& detectorName,
9 const std::vector<const GTrueInfoData*>& trueInfoData) {
10 if (!is_building_event) {
11 log->error(ERR_PUBLISH_ERROR, "publishEventTrueInfoDataImpl called without an active event in GstreamerJsonFactory");
12 return false;
13 }
14
15 // Lazily open the detectors object the first time we receive detector data.
16 if (!current_event_has_any_detector) {
17 current_event << ", \"detectors\": {";
18 current_event_has_any_detector = true;
19 } else {
20 // This function is called once per detector; separator between detector blocks
21 // is handled by checking whether the detector already exists is not possible here
22 // without tracking. Instead, we always append blocks as they arrive and rely on
23 // the gstreamer core ordering: each detector appears once per event.
24 current_event << ", ";
25 }
26
27 // Create detector object with "true_info" and a placeholder for "digitized".
28 current_event << "\"" << jsonEscape(detectorName) << "\": {";
29
30 // True info array
31 current_event << "\"true_info\": [";
32
33 bool wrote_first_hit = false;
34 for (const auto* hit : trueInfoData) {
35 if (!hit) continue;
36
37 if (wrote_first_hit) current_event << ", ";
38 wrote_first_hit = true;
39
40 current_event << "{";
41
42 // Address / identity string
43 const std::string addr = hit->getIdentityString();
44 current_event << "\"address\": \"" << jsonEscape(addr) << "\"";
45
46 // Variables object
47 current_event << ", \"vars\": {";
48
49 bool wrote_first_var = false;
50
51 // Double variables
52 for (const auto& [name, value] : hit->getDoubleVariablesMap()) {
53 if (wrote_first_var) current_event << ", ";
54 wrote_first_var = true;
55 current_event << "\"" << jsonEscape(name) << "\": " << value;
56 }
57
58 // String variables
59 for (const auto& [name, value] : hit->getStringVariablesMap()) {
60 if (wrote_first_var) current_event << ", ";
61 wrote_first_var = true;
62 current_event << "\"" << jsonEscape(name) << "\": \"" << jsonEscape(value) << "\"";
63 }
64
65 current_event << "}"; // close vars
66 current_event << "}"; // close hit
67 }
68
69 current_event << "]"; // close true_info array
70
71 // Digitized array will be appended by publishEventDigitizedDataImpl for the same detector.
72 current_event << ", \"digitized\": ";
73
74 // We do not know digitized content here; a sentinel is written and replaced immediately
75 // by the next call because the core calls digitized publishing right after true info.
76 // To avoid string replacement complexity, we write an empty array here and let
77 // publishEventDigitizedDataImpl append a second "digitized" field ONLY if it has data.
78 //
79 // Practically: keep the schema stable even if digitized is empty.
80 current_event << "[]";
81
82 current_event << "}"; // close detector object
83
84 return true;
85}
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).