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(
12 gstreamer::ERR_CANTOPENOUTPUT, "%1Error: can't access %2", SFUNCTION_NAME, filename_true_info());
13 }
14
15 // Emit the header row from the first non-empty detector collection so column names
16 // reflect the actual variable schema.
17 if (!is_first_event_with_truedata) {
18 if (trueInfoData.size() > 0) {
19 ofile_true_info << "evn, timestamp, thread_id, detector, ";
20 auto first_hit = trueInfoData[0];
21
22 const auto& smap = first_hit->getStringVariablesMap();
23 const auto& dmap = first_hit->getDoubleVariablesMap();
24
25 size_t total = dmap.size();
26 size_t i = 0;
27
28 log->debug(
29 NORMAL, "%1Writing header for event %2 with %3 variables", SFUNCTION_NAME, event_number, total);
30
31 for (const auto& [name, value] : getIdentityMap(first_hit->getIdentity())) { ofile_true_info << name << ", "; }
32 for (const auto& [name, value] : smap) { ofile_true_info << name << ", "; }
33
34 for (const auto& [name, value] : dmap) {
35 ofile_true_info << name;
36 if (++i < total) ofile_true_info << ", ";
37 }
38
39 ofile_true_info << "\n";
40
41 is_first_event_with_truedata = true;
42 }
43 }
44
45 // Write one row per true-information hit.
46 if (is_first_event_with_truedata) {
47 for (auto trueInfoHit : trueInfoData) {
48 const auto& smap = trueInfoHit->getStringVariablesMap();
49 const auto& dmap = trueInfoHit->getDoubleVariablesMap();
50
51 size_t total = dmap.size();
52 size_t i = 0;
53
54 ofile_true_info << event_number << ", " << timestamp << ", " << thread_id << ", " << detectorName << ", ";
55
56 for (const auto& [name, value] : getIdentityMap(trueInfoHit->getIdentity())) { ofile_true_info << value << ", "; }
57 for (const auto& [variableName, value] : smap) { ofile_true_info << value << ", "; }
58 for (const auto& [variableName, value] : dmap) {
59 ofile_true_info << value;
60 if (++i < total) ofile_true_info << ", ";
61 }
62 ofile_true_info << "\n";
63 }
64 }
65
66 return true;
67}
std::shared_ptr< GLogger > log
std::map< std::string, int > getIdentityMap(std::vector< GIdentifier > gidentity)
CSV streamer plugin declarations.
Shared constants and error codes for the gstreamer module.
constexpr int ERR_CANTOPENOUTPUT
Output medium could not be opened successfully.