gstreamer
Loading...
Searching...
No Matches
gSROFactory.cc
Go to the documentation of this file.
1#include "gSROFactory.h"
2
3#include <gemc/gfactory/gfactory.h>
5
6std::shared_ptr<GSROFactory> GSROFactory::from_options(const std::shared_ptr<GOptions>& options) {
7 std::optional<GStreamerDefinition> selected;
8 for (const auto& definition : gstreamer::getGStreamerDefinition(options)) {
9 if (definition.format != "sro") { continue; }
10 if (selected) { throw std::invalid_argument("Configure only one sro output per simulation"); }
11 selected = definition;
12 }
13 if (!selected) { return nullptr; }
14 GManager manager(options);
15 auto implementation = manager.LoadAndRegisterObjectFromLibrary<GSROImplementation>(
16 selected->implementation, options);
17 return std::make_shared<GSROFactory>(std::move(implementation), selected->rootname);
18}
19
20GSROFactory::GSROFactory(std::shared_ptr<GSROImplementation> plugin, std::string output_basename)
21 : implementation(std::move(plugin)), run_context{0, 0, std::move(output_basename)} {
22 if (!implementation) { throw std::invalid_argument("SRO requires an implementation plugin"); }
23}
24
25void GSROFactory::begin_run(int run_id, GSROEventId event_count) {
26 run_context.run_id = run_id;
27 run_context.event_count = event_count;
28 interrupted = false;
29 auto config = implementation->configure_run(run_context);
30 service.begin_run([plugin = implementation, context = run_context](GSROCrateId crate) {
31 return plugin->create_crate(crate, context);
32 }, std::move(config.timing), config.crate_limits, config.max_pending_events);
33}
34
36 service.create_crate_thread_if_needed(crate);
37}
39 service.dispatch_payload_to_crate(std::move(payload));
40}
41void GSROFactory::complete_event(GSROEventId event) { service.complete_event(event); }
42void GSROFactory::cancel_run(std::exception_ptr error) {
43 interrupted = true;
44 service.cancel_run(error);
45}
46void GSROFactory::finish_run(bool all_events_processed) {
47 const auto reason = all_events_processed && !interrupted
49 service.finish_run({reason, std::nullopt});
50}
51void GSROFactory::rethrow_if_failed() const { service.rethrow_if_failed(); }
std::shared_ptr< T > LoadAndRegisterObjectFromLibrary(std::string_view name, const std::shared_ptr< GOptions > &gopts)
void cancel_run(std::exception_ptr error)
GSROFactory(std::shared_ptr< GSROImplementation > implementation, std::string output_basename)
void rethrow_if_failed() const
void create_crate_thread_if_needed(GSROCrateId crate)
static std::shared_ptr< GSROFactory > from_options(const std::shared_ptr< GOptions > &options)
Return null when SRO is disabled. Load the selected implementation before workers are created.
Definition gSROFactory.cc:6
void finish_run(bool all_events_processed)
void complete_event(GSROEventId event)
void begin_run(int run_id, GSROEventId event_count)
void dispatch_payload_to_crate(GSROPayload payload)
std::uint32_t GSROCrateId
Definition gSROData.h:18
std::uint64_t GSROEventId
Definition gSROData.h:19
event
vector< GStreamerDefinition > getGStreamerDefinition(const std::shared_ptr< GOptions > &gopts)
Parse all configured gstreamer output definitions from the options container.
Option and configuration helpers for the gstreamer module.
One worker-produced contribution, transferred by move to its destination crate.
Definition gSROData.h:58