gstreamer
Loading...
Searching...
No Matches
publishDigitized.cc
Go to the documentation of this file.
1// gstreamer
4
5// Implementation summary:
6// Flatten run-level digitized detector data into one CSV row per hit.
7
8bool GstreamerCsvFactory::publishRunDigitizedDataImpl(const std::string& detectorName,
9 const std::vector<const GDigitizedData*>& digitizedData) {
10 if (!ofile_digitized.is_open()) {
11 log->error(ERR_CANTOPENOUTPUT, SFUNCTION_NAME, "Error: can't access ", filename_digitized());
12 }
13
14 // Emit the header row from the first non-empty collection so column names match
15 // the detector schema observed in the data.
16 if (!is_first_event_with_digidata) {
17 if (digitizedData.size() > 0) {
18 ofile_digitized << "evn, timestamp, thread_id, detector, ";
19 auto first_hit = digitizedData[0];
20
21 const auto& imap = first_hit->getIntObservablesMap(0);
22 const auto& dmap = first_hit->getDblObservablesMap(0);
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] : getIdentityMap(first_hit->getIdentity())) { ofile_digitized << name << ", "; }
31 for (const auto& [name, value] : imap) { ofile_digitized << name << ", "; }
32
33 for (const auto& [name, value] : dmap) {
34 ofile_digitized << name;
35 if (++i < total) ofile_digitized << ", ";
36 }
37
38 ofile_digitized << "\n";
39
40 is_first_event_with_digidata = true;
41 }
42 }
43
44 // Once the header exists, every hit becomes one flattened row.
45 if (is_first_event_with_digidata) {
46 for (auto digi_hit : digitizedData) {
47 const auto& imap = digi_hit->getIntObservablesMap(0);
48 const auto& dmap = digi_hit->getDblObservablesMap(0);
49
50 size_t total = dmap.size();
51 size_t i = 0;
52
53 ofile_digitized << event_number << ", " << timestamp << ", " << thread_id << ", " << detectorName << ", ";
54
55 for (const auto& [name, value] : getIdentityMap(digi_hit->getIdentity())) { ofile_digitized << value << ", "; }
56 for (const auto& [variableName, value] : imap) { ofile_digitized << value << ", "; }
57 for (const auto& [variableName, value] : dmap) {
58 ofile_digitized << value;
59 if (++i < total) ofile_digitized << ", ";
60 }
61 ofile_digitized << "\n";
62 }
63 }
64
65 return true;
66}
std::shared_ptr< GLogger > log
void debug(debug_type type, Args &&... args) const
void error(int exit_code, Args &&... args) const
std::map< std::string, int > getIdentityMap(std::vector< GIdentifier > gidentity)
CSV streamer plugin declarations.
Shared constants and error codes for the gstreamer module.
#define ERR_CANTOPENOUTPUT
Output medium could not be opened successfully.