gstreamer
Loading...
Searching...
No Matches
publishDigitized.cc
Go to the documentation of this file.
1// gstreamer
4
5// c++
6#include <sstream>
7
8// Implementation summary:
9// Append digitized detector content to the current JSON event object.
10// This implementation keeps the JSON valid without performing in-place string editing.
11
12bool GstreamerJsonFactory::publishEventDigitizedDataImpl(const std::string& detectorName,
13 const std::vector<const GDigitizedData*>& digitizedData) {
14 if (!is_building_event) {
15 log->error(
17 "publishEventDigitizedDataImpl called without an active event in GstreamerJsonFactory");
18 return false;
19 }
20
21 // Build this detector's digitized array into a standalone entry and buffer it.
22 // endEventImpl emits all buffered entries together as the "digitized_by_detector"
23 // object, which keeps the JSON valid regardless of how true-info and digitized
24 // publish calls interleave across detectors.
25 if (digitizedData.empty()) return true;
26
27 std::ostringstream entry;
28 entry << "\"" << jsonEscape(detectorName) << "\": [";
29
30 bool wrote_first_hit = false;
31 for (const auto* hit : digitizedData) {
32 if (!hit) continue;
33
34 if (wrote_first_hit) entry << ", ";
35 wrote_first_hit = true;
36
37 entry << "{";
38
39 auto addr = getIdentityString(hit->getIdentity());
40
41 entry << "\"address\": \"" << jsonEscape(addr) << "\"";
42
43 entry << ", \"vars\": {";
44
45 bool wrote_first_var = false;
46
47 // Integer observables:
48 // the argument 0 means "do not include SRO variables".
49 for (const auto& [name, value] : hit->getIntObservablesMap(0)) {
50 if (wrote_first_var) entry << ", ";
51 wrote_first_var = true;
52 entry << "\"" << jsonEscape(name) << "\": " << value;
53 }
54
55 // Floating-point observables.
56 for (const auto& [name, value] : hit->getDblObservablesMap(0)) {
57 if (wrote_first_var) entry << ", ";
58 wrote_first_var = true;
59 entry << "\"" << jsonEscape(name) << "\": " << value;
60 }
61
62 entry << "}";
63 entry << "}";
64 }
65
66 entry << "]";
67
68 current_event_digitized_entries.push_back(entry.str());
69
70 return true;
71}
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.