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(
16 ERR_PUBLISH_ERROR, "publishEventDigitizedDataImpl called without an active event in GstreamerJsonFactory");
17 return false;
18 }
19
20 // Build this detector's digitized array into a standalone entry and buffer it.
21 // endEventImpl emits all buffered entries together as the "digitized_by_detector"
22 // object, which keeps the JSON valid regardless of how true-info and digitized
23 // publish calls interleave across detectors.
24 if (digitizedData.empty()) return true;
25
26 std::ostringstream entry;
27 entry << "\"" << jsonEscape(detectorName) << "\": [";
28
29 bool wrote_first_hit = false;
30 for (const auto* hit : digitizedData) {
31 if (!hit) continue;
32
33 if (wrote_first_hit) entry << ", ";
34 wrote_first_hit = true;
35
36 entry << "{";
37
38 auto addr = getIdentityString(hit->getIdentity());
39
40 entry << "\"address\": \"" << jsonEscape(addr) << "\"";
41
42 entry << ", \"vars\": {";
43
44 bool wrote_first_var = false;
45
46 // Integer observables:
47 // the argument 0 means "do not include SRO variables".
48 for (const auto& [name, value] : hit->getIntObservablesMap(0)) {
49 if (wrote_first_var) entry << ", ";
50 wrote_first_var = true;
51 entry << "\"" << jsonEscape(name) << "\": " << value;
52 }
53
54 // Floating-point observables.
55 for (const auto& [name, value] : hit->getDblObservablesMap(0)) {
56 if (wrote_first_var) entry << ", ";
57 wrote_first_var = true;
58 entry << "\"" << jsonEscape(name) << "\": " << value;
59 }
60
61 entry << "}";
62 entry << "}";
63 }
64
65 entry << "]";
66
67 current_event_digitized_entries.push_back(entry.str());
68
69 return true;
70}
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.