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 const std::string addr = hit->getIdentityString();
41 current_event << "\"address\": \"" << jsonEscape(addr) << "\"";
42
43 current_event << ", \"vars\": {";
44
45 bool wrote_first_var = false;
46
47 for (const auto& [name, value] : hit->getDoubleVariablesMap()) {
48 if (wrote_first_var) current_event << ", ";
49 wrote_first_var = true;
50 current_event << "\"" << jsonEscape(name) << "\": " << value;
51 }
52
53 for (const auto& [name, value] : hit->getStringVariablesMap()) {
54 if (wrote_first_var) current_event << ", ";
55 wrote_first_var = true;
56 current_event << "\"" << jsonEscape(name) << "\": \"" << jsonEscape(value) << "\"";
57 }
58
59 current_event << "}";
60 current_event << "}";
61 }
62
63 current_event << "]";
64
65 // Keep a stable schema even before digitized content is appended for this detector.
66 current_event << ", \"digitized\": ";
67 current_event << "[]";
68
69 current_event << "}";
70
71 return true;
72}
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
Publish sequence encountered invalid state or invalid input data.
JSON streamer plugin declarations.