gstreamer
Loading...
Searching...
No Matches
publishTrueInfo.cc
Go to the documentation of this file.
1// gstreamer
4
5// Implementation summary:
6// Flatten event-level true-information detector data into one CSV row per hit.
7
8bool GstreamerCsvFactory::publishEventTrueInfoDataImpl(const std::string& detectorName,
9 const std::vector<const GTrueInfoData*>& trueInfoData) {
10 if (!ofile_true_info.is_open()) {
11 log->error(ERR_CANTOPENOUTPUT, SFUNCTION_NAME, "Error: can't access ", filename_true_info());
12 }
13
14 // Emit the header row from the first non-empty detector collection so column names
15 // reflect the actual variable schema.
16 if (!is_first_event_with_truedata) {
17 if (trueInfoData.size() > 0) {
18 ofile_true_info << "evn, timestamp, thread_id, detector, ";
19 auto first_hit = trueInfoData[0];
20
21 const auto& smap = first_hit->getStringVariablesMap();
22 const auto& dmap = first_hit->getDoubleVariablesMap();
23
24 size_t total = dmap.size();
25 size_t i = 0;
26
27 log->debug(NORMAL, SFUNCTION_NAME, "Writing header for event ", event_number, " with ", total,
28 " variables");
29
30 for (const auto& [name, value] : smap) { ofile_true_info << name << ", "; }
31
32 for (const auto& [name, value] : dmap) {
33 ofile_true_info << name;
34 if (++i < total) ofile_true_info << ", ";
35 }
36
37 ofile_true_info << "\n";
38
39 is_first_event_with_truedata = true;
40 }
41 }
42
43 // Write one row per true-information hit.
44 if (is_first_event_with_truedata) {
45 for (auto trueInfoHit : trueInfoData) {
46 const auto& smap = trueInfoHit->getStringVariablesMap();
47 const auto& dmap = trueInfoHit->getDoubleVariablesMap();
48
49 size_t total = dmap.size();
50 size_t i = 0;
51
52 ofile_true_info << event_number << ", " << timestamp << ", " << thread_id << ", " << detectorName << ", ";
53
54 for (const auto& [variableName, value] : smap) { ofile_true_info << value << ", "; }
55 for (const auto& [variableName, value] : dmap) {
56 ofile_true_info << value;
57 if (++i < total) ofile_true_info << ", ";
58 else ofile_true_info << "\n";
59 }
60 }
61 }
62
63 return true;
64}
std::shared_ptr< GLogger > log
void debug(debug_type type, Args &&... args) const
void error(int exit_code, Args &&... args) const
CSV streamer plugin declarations.
Shared constants and error codes for the gstreamer module.
#define ERR_CANTOPENOUTPUT
Output medium could not be opened successfully.