gstreamer
Loading...
Searching...
No Matches
publishDigitized.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::publishEventDigitizedDataImpl(const std::string& detectorName,
8 const std::vector<const GDigitizedData*>& digitizedData) {
9 if (!ofile_digitized.is_open()) {
10 log->error(ERR_CANTOPENOUTPUT, SFUNCTION_NAME, "Error: can't access ", filename_digitized());
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_digidata) {
15 if (digitizedData.size() > 0) {
16 ofile_digitized << "evn, timestamp, thread_id, detector, ";
17 auto first_hit = digitizedData[0];
18
19 // Argument passed to getter: 0 = do not get sro vars.
20 const auto& imap = first_hit->getIntObservablesMap(0);
21 const auto& dmap = first_hit->getDblObservablesMap(0);
22
23 size_t total = dmap.size();
24 size_t i = 0;
25
26 log->debug(NORMAL, SFUNCTION_NAME, "Writing header for event ", event_number, " with ", total,
27 " variables");
28
29 for (const auto& [name, value] : imap) { ofile_digitized << name << ", "; }
30
31 for (const auto& [name, value] : dmap) {
32 ofile_digitized << name;
33 if (++i < total) ofile_digitized << ", "; // not last, write comma
34 }
35
36 ofile_digitized << "\n";
37
38 is_first_event_with_digidata = true;
39 }
40 }
41
42 // If we emitted a header, we have a stable column set and can write rows.
43 if (is_first_event_with_digidata) {
44 for (auto digi_hit : digitizedData) {
45 // Argument passed to getter: 0 = do not get sro vars.
46 const auto& imap = digi_hit->getIntObservablesMap(0);
47 const auto& dmap = digi_hit->getDblObservablesMap(0);
48
49 size_t total = dmap.size();
50 size_t i = 0;
51
52 ofile_digitized << event_number << ", " << timestamp << ", " << thread_id << ", " << detectorName << ", ";
53
54 for (const auto& [variableName, value] : imap) { ofile_digitized << value << ", "; }
55 for (const auto& [variableName, value] : dmap) {
56 ofile_digitized << value;
57 if (++i < total) ofile_digitized << ", "; // not last, write comma
58 else ofile_digitized << "\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
Shared constants and error codes for the gstreamer module.
#define ERR_CANTOPENOUTPUT
Output medium could not be opened (file/device not accessible).