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) {
14 log->error(
16 "publishEventTrueInfoDataImpl called without an active event in GstreamerJsonFactory");
17 return false;
18 }
19
20 // Lazily open the "detectors" object on the first detector encountered.
21 if (!current_event_has_any_detector) {
22 current_event << ", \"detectors\": {";
23 current_event_has_any_detector = true;
24 } else {
25 current_event << ", ";
26 }
27
28 current_event << "\"" << jsonEscape(detectorName) << "\": {";
29
30 // True-information hits are serialized as an array of objects.
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 auto addr = getIdentityString(hit->getIdentity());
43
44 current_event << "\"address\": \"" << jsonEscape(addr) << "\"";
45
46 current_event << ", \"vars\": {";
47
48 bool wrote_first_var = false;
49
50 for (const auto& [name, value] : hit->getDoubleVariablesMap()) {
51 if (wrote_first_var) current_event << ", ";
52 wrote_first_var = true;
53 current_event << "\"" << jsonEscape(name) << "\": " << value;
54 }
55
56 for (const auto& [name, value] : hit->getStringVariablesMap()) {
57 if (wrote_first_var) current_event << ", ";
58 wrote_first_var = true;
59 current_event << "\"" << jsonEscape(name) << "\": \"" << jsonEscape(value) << "\"";
60 }
61
62 current_event << "}";
63 current_event << "}";
64 }
65
66 current_event << "]";
67
68 // Keep a stable schema even before digitized content is appended for this detector.
69 current_event << ", \"digitized\": ";
70 current_event << "[]";
71
72 current_event << "}";
73
74 return true;
75}
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.