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