8bool GstreamerJsonFactory::publishEventDigitizedDataImpl(
const std::string& detectorName,
9 const std::vector<const GDigitizedData*>& digitizedData) {
10 if (!is_building_event) {
12 ERR_PUBLISH_ERROR,
"publishEventDigitizedDataImpl called without an active event in GstreamerJsonFactory");
26 if (digitizedData.empty())
return true;
31 static const char* marker =
"\"digitized_by_detector\": {";
32 const std::string assembled = current_event.str();
34 const bool has_digitized_container = (assembled.find(marker) != std::string::npos);
36 if (!has_digitized_container) {
43 if (!current_event_has_any_detector) {
44 current_event <<
", \"detectors\": {";
45 current_event_has_any_detector =
true;
48 current_event <<
", ";
51 current_event <<
"\"digitized_by_detector\": {";
56 const std::string updated = current_event.str();
57 const bool digitized_has_any_detector =
58 (updated.find(
"\"digitized_by_detector\": {") != std::string::npos) &&
59 (updated.find(
"\"digitized_by_detector\": {") < updated.size() - 1) &&
60 (updated.find(
"\"digitized_by_detector\": {") != std::string::npos);
65 if (!updated.empty()) {
66 char last = updated.back();
67 if (last !=
'{') current_event <<
", ";
70 current_event <<
"\"" << jsonEscape(detectorName) <<
"\": [";
72 bool wrote_first_hit =
false;
73 for (
const auto* hit : digitizedData) {
76 if (wrote_first_hit) current_event <<
", ";
77 wrote_first_hit =
true;
81 const std::string addr = hit->getIdentityString();
82 current_event <<
"\"address\": \"" << jsonEscape(addr) <<
"\"";
84 current_event <<
", \"vars\": {";
86 bool wrote_first_var =
false;
89 for (
const auto& [name, value] : hit->getIntObservablesMap(0)) {
90 if (wrote_first_var) current_event <<
", ";
91 wrote_first_var =
true;
92 current_event <<
"\"" << jsonEscape(name) <<
"\": " << value;
96 for (
const auto& [name, value] : hit->getDblObservablesMap(0)) {
97 if (wrote_first_var) current_event <<
", ";
98 wrote_first_var =
true;
99 current_event <<
"\"" << jsonEscape(name) <<
"\": " << value;
102 current_event <<
"}";
103 current_event <<
"}";
106 current_event <<
"]";
126 current_event <<
"}";
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
Generic publish-time error (null pointers, invalid state).