120 void publishEventData(
const std::shared_ptr<GEventDataCollection>& event_data);
168 bufferFlushLimit = g->getScalarInt(
"ebuffer");
187 [[nodiscard]]
bool startEvent([[maybe_unused]]
const std::shared_ptr<GEventDataCollection>& event_data) {
189 if (!event_data->getHeader()) {
202 virtual bool startEventImpl([[maybe_unused]]
const std::shared_ptr<GEventDataCollection>& event_data) {
215 [[nodiscard]]
bool publishEventHeader([[maybe_unused]]
const std::unique_ptr<GEventHeader>& gevent_header) {
241 [[maybe_unused]]
const std::vector<const GTrueInfoData*>&
243 log->
debug(
NORMAL,
"GStreamer::publishEventTrueInfoData for detector ", detectorName);
254 [[maybe_unused]]
const std::vector<const GTrueInfoData*>& trueInfoData) {
270 [[maybe_unused]]
const std::vector<const GDigitizedData*>&
272 log->
debug(
NORMAL,
"GStreamer::publishEventDigitizedData for detector ", detectorName);
283 [[maybe_unused]]
const std::vector<const GDigitizedData*>&
284 digitizedData) {
return false; }
292 [[nodiscard]]
bool endEvent([[maybe_unused]]
const std::shared_ptr<GEventDataCollection>& event_data) {
302 virtual bool endEventImpl([[maybe_unused]]
const std::shared_ptr<GEventDataCollection>& event_data) {
354 [[nodiscard]]
bool publishPayload([[maybe_unused]]
const std::vector<GIntegralPayload*>* payload) {
364 virtual bool publishPayloadImpl([[maybe_unused]]
const std::vector<GIntegralPayload*>* payload) {
return false; }
406 [[nodiscard]]
virtual std::string filename()
const = 0;
409 std::vector<std::shared_ptr<GEventDataCollection>> eventBuffer;
412 size_t bufferFlushLimit = 10;
423 if (!h)
return nullptr;
424 using fptr =
GStreamer* (*)(std::shared_ptr<GOptions>);
427 auto sym = dlsym(h,
"GStreamerFactory");
428 if (!sym)
return nullptr;
430 auto func =
reinterpret_cast<fptr
>(sym);
437using gstreamersMap = std::unordered_map<std::string, std::shared_ptr<GStreamer>>;
456inline std::shared_ptr<const gstreamersMap>
gstreamersMapPtr(
const std::shared_ptr<GOptions>& gopts,
458 auto log = std::make_shared<GLogger>(gopts,
"gstreamersMap worker for thread id" + std::to_string(thread_id),
463 auto gstreamers = std::make_shared<gstreamersMap>();
467 std::string gstreamer_plugin = gstreamer_def_thread.gstreamerPluginName();
471 gstreamers->emplace(gstreamer_plugin, streamer);
std::shared_ptr< GLogger > log
void debug(debug_type type, Args &&... args) const
void error(int exit_code, Args &&... args) const
std::shared_ptr< T > LoadAndRegisterObjectFromLibrary(std::string_view name, const std::shared_ptr< GOptions > &gopts)
Abstract base class for streaming GEMC event or frame data to output media.
virtual bool publishPayloadImpl(const std::vector< GIntegralPayload * > *payload)
Implementation hook for publishing a frame payload.
bool publishFrameHeader(const GFrameHeader *gframeHeader)
Publish a frame header.
static const std::vector< std::string > & supported_formats()
Return the list of supported output formats.
virtual bool startStreamImpl(const GFrameDataCollection *frameRunData)
Implementation hook for beginning a frame stream publish sequence.
bool publishEventDigitizedData(const std::string &detectorName, const std::vector< const GDigitizedData * > &digitizedData)
Publish digitized hits for one detector.
std::string getStreamType() const
Return the semantic stream type for this streamer.
bool startStream(const GFrameDataCollection *frameRunData)
Begin a frame stream publish sequence.
virtual ~GStreamer()=default
Virtual destructor.
void publishEventData(const std::shared_ptr< GEventDataCollection > &event_data)
Buffer an event for later serialization.
virtual bool closeConnectionImpl()
Implementation hook for closing the output medium.
virtual bool publishEventTrueInfoDataImpl(const std::string &detectorName, const std::vector< const GTrueInfoData * > &trueInfoData)
Implementation hook for publishing true info hits for one detector.
virtual bool endStreamImpl(const GFrameDataCollection *frameRunData)
Implementation hook for ending a frame stream publish sequence.
void flushEventBuffer()
Flush the internal event buffer, writing all buffered events to the output medium.
static bool is_valid_format(const std::string &format)
Check whether a format token is supported.
bool endEvent(const std::shared_ptr< GEventDataCollection > &event_data)
End an event publish sequence.
bool publishEventHeader(const std::unique_ptr< GEventHeader > &gevent_header)
Publish the event header.
void define_gstreamer(const GStreamerDefinition &gstreamerDefinition, int tid=-1)
Assign the output definition used by this streamer instance.
GStreamer(const std::shared_ptr< GOptions > &g)
Construct a streamer and bind it to module logging.
GStreamerDefinition gstreamer_definitions
Output definition used by this streamer (format, base name, type, thread id).
virtual bool endEventImpl(const std::shared_ptr< GEventDataCollection > &event_data)
Implementation hook for ending an event publish sequence.
virtual bool publishFrameHeaderImpl(const GFrameHeader *gframeHeader)
Implementation hook for publishing a frame header.
bool endStream(const GFrameDataCollection *frameRunData)
End a frame stream publish sequence.
virtual bool publishEventHeaderImpl(const std::unique_ptr< GEventHeader > &gevent_header)
Implementation hook for publishing the event header.
bool startEvent(const std::shared_ptr< GEventDataCollection > &event_data)
Begin an event publish sequence.
virtual bool startEventImpl(const std::shared_ptr< GEventDataCollection > &event_data)
Implementation hook for beginning an event publish sequence.
static GStreamer * instantiate(const dlhandle h, std::shared_ptr< GOptions > g)
Instantiate a streamer plugin by resolving the GStreamerFactory symbol from a dynamic library.
virtual bool openConnection()
Open the output medium (file, socket, etc.).
bool publishPayload(const std::vector< GIntegralPayload * > *payload)
Publish a frame payload.
bool publishEventTrueInfoData(const std::string &detectorName, const std::vector< const GTrueInfoData * > &trueInfoData)
Publish true (MC) information hits for one detector.
virtual bool publishEventDigitizedDataImpl(const std::string &detectorName, const std::vector< const GDigitizedData * > &digitizedData)
Implementation hook for publishing digitized hits for one detector.
bool closeConnection()
Close the output medium after flushing any buffered events.
void set_loggers(const std::shared_ptr< GOptions > &g)
Configure streamer settings derived from options.
Shared constants and error codes for the gstreamer module.
#define ERR_PUBLISH_ERROR
Generic publish-time error (null pointers, invalid state).
Option and configuration helpers for the gstreamer module.
constexpr const char * GSTREAMER_LOGGER
Logger category name used by gstreamer components.
vector< GStreamerDefinition > getGStreamerDefinition(const std::shared_ptr< GOptions > &gopts)
Parse gstreamer output definitions from options.
std::shared_ptr< const gstreamersMap > gstreamersMapPtr(const std::shared_ptr< GOptions > &gopts, int thread_id)
Create a per-thread map of streamer instances based on configured outputs.
std::unordered_map< std::string, std::shared_ptr< GStreamer > > gstreamersMap
Utility struct describing one configured output for the gstreamer module.
std::string type
Semantic output type token (e.g. "event" or "stream").