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(
12 gstreamer::ERR_CANTOPENOUTPUT, "%1Error: can't access %2", SFUNCTION_NAME, filename_digitized());
13 }
14
15 // Emit the header row from the first non-empty collection so column names match
16 // the detector schema observed in the data.
17 if (!is_first_event_with_digidata) {
18 if (digitizedData.size() > 0) {
19 ofile_digitized << "evn, timestamp, thread_id, detector, ";
20 auto first_hit = digitizedData[0];
21
22 const auto& imap = first_hit->getIntObservablesMap(0);
23 const auto& dmap = first_hit->getDblObservablesMap(0);
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_digitized << name << ", "; }
32 for (const auto& [name, value] : imap) { ofile_digitized << name << ", "; }
33
34 for (const auto& [name, value] : dmap) {
35 ofile_digitized << name;
36 if (++i < total) ofile_digitized << ", ";
37 }
38
39 ofile_digitized << "\n";
40
41 is_first_event_with_digidata = true;
42 }
43 }
44
45 // Once the header exists, every hit becomes one flattened row.
46 if (is_first_event_with_digidata) {
47 for (auto digi_hit : digitizedData) {
48 const auto& imap = digi_hit->getIntObservablesMap(0);
49 const auto& dmap = digi_hit->getDblObservablesMap(0);
50
51 size_t total = dmap.size();
52 size_t i = 0;
53
54 ofile_digitized << event_number << ", " << timestamp << ", " << thread_id << ", " << detectorName << ", ";
55
56 for (const auto& [name, value] : getIdentityMap(digi_hit->getIdentity())) { ofile_digitized << value << ", "; }
57 for (const auto& [variableName, value] : imap) { ofile_digitized << value << ", "; }
58 for (const auto& [variableName, value] : dmap) {
59 ofile_digitized << value;
60 if (++i < total) ofile_digitized << ", ";
61 }
62 ofile_digitized << "\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.