12bool GstreamerJsonFactory::publishEventDigitizedDataImpl(
const std::string& detectorName,
13 const std::vector<const GDigitizedData*>& digitizedData) {
14 if (!is_building_event) {
16 ERR_PUBLISH_ERROR,
"publishEventDigitizedDataImpl called without an active event in GstreamerJsonFactory");
22 if (digitizedData.empty())
return true;
24 static const char* marker =
"\"digitized_by_detector\": {";
25 const std::string assembled = current_event.str();
27 const bool has_digitized_container = (assembled.find(marker) != std::string::npos);
29 if (!has_digitized_container) {
32 if (!current_event_has_any_detector) {
33 current_event <<
", \"detectors\": {";
34 current_event_has_any_detector =
true;
37 current_event <<
", ";
40 current_event <<
"\"digitized_by_detector\": {";
45 const std::string updated = current_event.str();
46 if (!updated.empty()) {
47 char last = updated.back();
48 if (last !=
'{') current_event <<
", ";
51 current_event <<
"\"" << jsonEscape(detectorName) <<
"\": [";
53 bool wrote_first_hit =
false;
54 for (
const auto* hit : digitizedData) {
57 if (wrote_first_hit) current_event <<
", ";
58 wrote_first_hit =
true;
62 const std::string addr = hit->getIdentityString();
63 current_event <<
"\"address\": \"" << jsonEscape(addr) <<
"\"";
65 current_event <<
", \"vars\": {";
67 bool wrote_first_var =
false;
71 for (
const auto& [name, value] : hit->getIntObservablesMap(0)) {
72 if (wrote_first_var) current_event <<
", ";
73 wrote_first_var =
true;
74 current_event <<
"\"" << jsonEscape(name) <<
"\": " << value;
78 for (
const auto& [name, value] : hit->getDblObservablesMap(0)) {
79 if (wrote_first_var) current_event <<
", ";
80 wrote_first_var =
true;
81 current_event <<
"\"" << jsonEscape(name) <<
"\": " << value;
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.