gstreamer
Loading...
Searching...
No Matches
publishTrueInfo.cc
Go to the documentation of this file.
1// gstreamer
4
5// c++
6#include <sstream>
7
8// Implementation summary:
9// Append one detector true-information block to the current JSON event object.
10
11bool GstreamerJsonFactory::publishEventTrueInfoDataImpl(const std::string& detectorName,
12 const std::vector<const GTrueInfoData*>& trueInfoData) {
13 if (!is_building_event) {
15 "publishEventTrueInfoDataImpl called without an active event in GstreamerJsonFactory");
16 return false;
17 }
18
19 // Lazily open the "detectors" object on the first detector encountered.
20 if (!current_event_has_any_detector) {
21 current_event << ", \"detectors\": {";
22 current_event_has_any_detector = true;
23 } else {
24 current_event << ", ";
25 }
26
27 current_event << "\"" << jsonEscape(detectorName) << "\": {";
28
29 // True-information hits are serialized as an array of objects.
30 current_event << "\"true_info\": [";
31
32 bool wrote_first_hit = false;
33 for (const auto* hit : trueInfoData) {
34 if (!hit) continue;
35
36 if (wrote_first_hit) current_event << ", ";
37 wrote_first_hit = true;
38
39 current_event << "{";
40
41 auto addr = getIdentityString(hit->getIdentity());
42
43 current_event << "\"address\": \"" << jsonEscape(addr) << "\"";
44
45 current_event << ", \"vars\": {";
46
47 bool wrote_first_var = false;
48
49 for (const auto& [name, value] : hit->getDoubleVariablesMap()) {
50 if (wrote_first_var) current_event << ", ";
51 wrote_first_var = true;
52 current_event << "\"" << jsonEscape(name) << "\": " << value;
53 }
54
55 for (const auto& [name, value] : hit->getStringVariablesMap()) {
56 if (wrote_first_var) current_event << ", ";
57 wrote_first_var = true;
58 current_event << "\"" << jsonEscape(name) << "\": \"" << jsonEscape(value) << "\"";
59 }
60
61 current_event << "}";
62 current_event << "}";
63 }
64
65 current_event << "]";
66
67 // Keep a stable schema even before digitized content is appended for this detector.
68 current_event << ", \"digitized\": ";
69 current_event << "[]";
70
71 current_event << "}";
72
73 return true;
74}
std::shared_ptr< GLogger > log
std::string getIdentityString(std::vector< GIdentifier > gidentity)
Shared constants and error codes for the gstreamer module.
JSON streamer plugin declarations.
constexpr int ERR_PUBLISH_ERROR
Publish sequence encountered invalid state or invalid input data.