gstreamer
Loading...
Searching...
No Matches
publishTrueInfo.cc
Go to the documentation of this file.
1// gstreamer
4
5// using \n instead of endl so flushing isn't forced at each line
6// Non-Doxygen implementation file: behavior is documented in the header.
7bool GstreamerCsvFactory::publishEventTrueInfoDataImpl(const std::string& detectorName,
8 const std::vector<const GTrueInfoData*>& trueInfoData) {
9 if (!ofile_true_info.is_open()) {
10 log->error(ERR_CANTOPENOUTPUT, SFUNCTION_NAME, "Error: can't access ", filename_true_info());
11 }
12
13 // First non-empty event: print header from the first hit so columns match the hit variable maps.
14 if (!is_first_event_with_truedata) {
15 if (trueInfoData.size() > 0) {
16 ofile_true_info << "evn, timestamp, thread_id, detector, ";
17 auto first_hit = trueInfoData[0];
18
19 const auto& smap = first_hit->getStringVariablesMap();
20 const auto& dmap = first_hit->getDoubleVariablesMap();
21
22 size_t total = dmap.size();
23 size_t i = 0;
24
25 log->debug(NORMAL, SFUNCTION_NAME, "Writing header for event ", event_number, " with ", total,
26 " variables");
27
28 for (const auto& [name, value] : smap) { ofile_true_info << name << ", "; }
29
30 for (const auto& [name, value] : dmap) {
31 ofile_true_info << name;
32 if (++i < total) ofile_true_info << ", "; // not last, write comma
33 }
34
35 ofile_true_info << "\n";
36
37 is_first_event_with_truedata = true;
38 }
39 }
40
41 // If we emitted a header, we have a stable column set and can write rows.
42 if (is_first_event_with_truedata) {
43 for (auto trueInfoHit : trueInfoData) {
44 const auto& smap = trueInfoHit->getStringVariablesMap();
45 const auto& dmap = trueInfoHit->getDoubleVariablesMap();
46
47 size_t total = dmap.size();
48 size_t i = 0;
49
50 ofile_true_info << event_number << ", " << timestamp << ", " << thread_id << ", " << detectorName << ", ";
51
52 for (const auto& [variableName, value] : smap) { ofile_true_info << value << ", "; }
53 for (const auto& [variableName, value] : dmap) {
54 ofile_true_info << value;
55 if (++i < total) ofile_true_info << ", "; // not last, write comma
56 else ofile_true_info << "\n";
57 }
58 }
59 }
60
61 return true;
62}
std::shared_ptr< GLogger > log
void debug(debug_type type, Args &&... args) const
void error(int exit_code, Args &&... args) const
Shared constants and error codes for the gstreamer module.
#define ERR_CANTOPENOUTPUT
Output medium could not be opened (file/device not accessible).