gstreamer
Loading...
Searching...
No Matches
gstreamer.cc
Go to the documentation of this file.
1// gstreamer
2#include "gstreamer.h"
3
4// gemc
5#include "gutilities.h"
6
7
8const std::vector<std::string>& GStreamer::supported_formats() {
9 // Note: keep this list in sync with the available gstreamer_<format>_plugin factories.
10 static const std::vector<std::string> formats = {"jlabsro", "root", "ascii", "csv", "json"};
11 return formats;
12}
13
14bool GStreamer::is_valid_format(const std::string& format) {
15 const auto& supported = GStreamer::supported_formats();
16 const auto f = gutilities::convertToLowercase(format);
17 return std::find(supported.begin(), supported.end(), f) != supported.end();
18}
19
20
21// pragma todo: pass someting like map<string, bitset> to each detector to decide which data to publish
22void GStreamer::publishEventData(const std::shared_ptr<GEventDataCollection>& event_data) {
23 // event_data and its header must not be null
24 if (!event_data) { log->error(ERR_PUBLISH_ERROR, "event data is null in GStreamer::publishEventData"); }
25 if (!event_data->getHeader()) { log->error(ERR_PUBLISH_ERROR, "event header is null in GStreamer::publishEventData"); }
26
27 // add to the buffer
28 eventBuffer.emplace_back(event_data);
29
30 // flush if the buffer is full
31 if (eventBuffer.size() >= bufferFlushLimit) { flushEventBuffer(); }
32}
33
35 log->info(2, "GStreamer::flushEventBuffer -> flushing ", eventBuffer.size(), " events to file");
36
37 // events are read only by the streamer
38 for (const auto& eventData : eventBuffer) {
39
40 log->info(2, "GStreamer::publishEventData->startEvent: ",
42
43 log->info(2, "GStreamer::publishEventData->publishEventHeader -> ",
44 gutilities::success_or_fail(publishEventHeader(eventData->getHeader())));
45
46 // possibly can filter out writing event data based on sdname
47 for (const auto& [sdname, gDataCollection] : eventData->getDataCollectionMap()) {
48 const GDataCollection* tdptr = gDataCollection.get();
49
50 // extract the vector of raw pointers to publish
51 std::vector<const GTrueInfoData*> trueInfoPtrs;
52 std::vector<const GDigitizedData*> digitizedPtrs;
53 trueInfoPtrs.reserve(tdptr->getTrueInfoData().size());
54 digitizedPtrs.reserve(tdptr->getDigitizedData().size());
55
56 for (const auto& hit : tdptr->getTrueInfoData()) { trueInfoPtrs.push_back(hit.get()); }
57 for (const auto& hit : tdptr->getDigitizedData()) { digitizedPtrs.push_back(hit.get()); }
58
59 log->info(2, "GStreamer::publishEventData->publishEventTrueInfoData for detector -> ", sdname,
61
62 log->info(2, "GStreamer::publishEventData->publishEventDigitizedData for detector -> ", sdname,
64 }
65
66 log->info(2, "GStreamer::endEvent -> ", gutilities::success_or_fail(endEvent(eventData)));
67 }
68
69 eventBuffer.clear();
70}
71
72// stream an individual frame
73// void GStreamer::publishFrameRunData(const std::shared_ptr<GFrameDataCollection>& frameRunData) {
74 // TODO: add more infor like frame number or number of entries in paylod
75
76 // log->info(2, "GStreamer::publishFrameRunData: ",
77 // gutilities::success_or_fail(startStream(frameRunData)));
78 // log->info(2, "GStreamer::publishFrameHeader: ",
79 // gutilities::success_or_fail(publishFrameHeader(frameRunData->getHeader())));
80 // log->info(2, "GStreamer::publishPayload: ",
81 // gutilities::success_or_fail(publishPayload(frameRunData->getIntegralPayload())));
82 // log->info(2, "GStreamer::endStream: ",
83 // gutilities::success_or_fail(endStream(frameRunData)));
84// }
std::shared_ptr< GLogger > log
auto getDigitizedData() const -> const std::vector< std::unique_ptr< GDigitizedData > > &
auto getTrueInfoData() const -> const std::vector< std::unique_ptr< GTrueInfoData > > &
void info(int level, Args &&... args) const
void error(int exit_code, Args &&... args) const
static const std::vector< std::string > & supported_formats()
Return the list of supported output formats.
Definition gstreamer.cc:8
bool publishEventDigitizedData(const std::string &detectorName, const std::vector< const GDigitizedData * > &digitizedData)
Publish digitized hits for one detector.
Definition gstreamer.h:269
void publishEventData(const std::shared_ptr< GEventDataCollection > &event_data)
Buffer an event for later serialization.
Definition gstreamer.cc:22
void flushEventBuffer()
Flush the internal event buffer, writing all buffered events to the output medium.
Definition gstreamer.cc:34
static bool is_valid_format(const std::string &format)
Check whether a format token is supported.
Definition gstreamer.cc:14
bool endEvent(const std::shared_ptr< GEventDataCollection > &event_data)
End an event publish sequence.
Definition gstreamer.h:292
bool publishEventHeader(const std::unique_ptr< GEventHeader > &gevent_header)
Publish the event header.
Definition gstreamer.h:215
bool startEvent(const std::shared_ptr< GEventDataCollection > &event_data)
Begin an event publish sequence.
Definition gstreamer.h:187
bool publishEventTrueInfoData(const std::string &detectorName, const std::vector< const GTrueInfoData * > &trueInfoData)
Publish true (MC) information hits for one detector.
Definition gstreamer.h:240
#define ERR_PUBLISH_ERROR
Generic publish-time error (null pointers, invalid state).
Core streaming interface for gstreamer output plugins.
std::string success_or_fail(bool condition)
string convertToLowercase(const string &str)