8#include "G4UserRunAction.hh"
11#include <gemc/gbase/gbase.h>
12#include <gemc/ganalysis/gAnalysisAccumulator.h>
13#include <gemc/gdynamicDigitization/gdynamicdigitization.h>
14#include <gemc/gstreamer/gstreamer.h>
15#include <gemc/gdata/run/gRunDataCollection.h>
77 explicit GRunAction(std::shared_ptr<GOptions> gopts,
78 std::shared_ptr<gdynamicdigitization::dRoutinesMap> digi_map,
79 std::shared_ptr<GAnalysisAccumulator> analysis_accumulator =
nullptr);
100 return digitization_routines_map;
113 -> std::shared_ptr<const
gstreamer::gstreamersMap> {
114 if (!gstreamer_threads_map) {
117 return gstreamer_threads_map;
121 return gstreamer_threads_map !=
nullptr;
129 if (analysis_shard !=
nullptr) {
130 analysis_shard->recordDigitized(analysis_run_number, detector, data);
136 if (analysis_shard !=
nullptr) {
137 analysis_shard->recordTrueInformation(analysis_run_number, detector, data);
152 std::unique_ptr<GDigitizedData> digi_data) {
153 if (run_data ==
nullptr) {
155 " run_data is null - cannot collect run-level payload for collection ", hcSDName);
158 run_data->collect_event_data_collections(
160 std::move(digi_data));
170 if (run_data ==
nullptr) {
172 " run_data is null - cannot increment processed events.");
175 auto& header = run_data->getHeader();
176 if (header ==
nullptr) {
178 " run_data header is null - cannot increment processed events.");
181 header->increment_events_processed();
191 if (run_data ==
nullptr) {
193 " run_data is null - cannot increment payload events.");
196 auto& header = run_data->getHeader();
197 if (header ==
nullptr) {
199 " run_data header is null - cannot increment payload events.");
202 header->increment_events_with_payload();
206 using CompletedRunData = std::vector<std::unique_ptr<GRunDataCollection>>;
214 void stash_worker_run_data();
224 [[nodiscard]] CompletedRunData take_completed_worker_run_data();
234 G4Run* GenerateRun()
override;
255 void BeginOfRunAction(
const G4Run*
run)
override;
271 void EndOfRunAction(
const G4Run*
run)
override;
278 void publish_run_data(
const std::shared_ptr<GRunDataCollection>& run_data)
const;
288 std::shared_ptr<gdynamicdigitization::dRoutinesMap> digitization_routines_map;
291 std::shared_ptr<GAnalysisAccumulator> analysis_accumulator;
294 std::unique_ptr<GAnalysisShard> analysis_shard;
297 int analysis_run_number = -1;
302 std::shared_ptr<const gstreamer::gstreamersMap> gstreamer_threads_map;
307 std::shared_ptr<const gstreamer::gstreamersMap> gstreamer_run_map;
315 std::unique_ptr<GRunDataCollection> run_data;
320 bool need_a_thread_streamer =
false;
325 bool need_a_run_streamer =
false;
330 static std::mutex completed_run_data_mutex;
338 static CompletedRunData completed_worker_run_data;
358 void normalize_run_data(
const std::shared_ptr<GRunDataCollection>& run_data)
const;
361 std::unordered_map<std::string, std::vector<std::string>> to_normalize;
GBase(const std::shared_ptr< GOptions > &gopt, std::string logger_name="")
std::shared_ptr< GLogger > log
GRunAction & operator=(GRunAction &&)=delete
void record_analysis_digitized(const std::string &detector, const GDigitizedData &data)
Discover digitized variables in one accepted record and add them to this thread's shard.
void increment_run_events_with_payload()
Increments the number of events that produced run-mode payload.
void increment_run_events_processed()
Increments the number of events processed by the current thread for this run.
GRunAction(GRunAction &&)=delete
auto get_digitization_routines_map() const -> std::shared_ptr< gdynamicdigitization::dRoutinesMap >
Returns the shared digitization-routine map used by this run action.
bool has_streamer_threads_map() const
bool analysis_enabled() const
Return whether this run action has a GUI Analyzer shard.
void record_analysis_true(const std::string &detector, const GTrueInfoData &data)
Discover true-information variables in one record and add them to this thread's shard.
GRunAction & operator=(const GRunAction &)=delete
GRunAction(std::shared_ptr< GOptions > gopts, std::shared_ptr< gdynamicdigitization::dRoutinesMap > digi_map, std::shared_ptr< GAnalysisAccumulator > analysis_accumulator=nullptr)
Constructs the run action.
GRunAction(const GRunAction &)=delete
void collect_event_data_collections(const std::string &hcSDName, std::unique_ptr< GDigitizedData > digi_data)
Adds one run-mode digitized payload to the current thread run-data collection.
~GRunAction() override=default
auto get_streamer_threads_map() const -> std::shared_ptr< const gstreamer::gstreamersMap >
Returns the worker-thread streamer map, if it has been instantiated.
constexpr const char * GRUNACTION_LOGGER
Defines error codes used by the GEMC actions module.
#define ERR_GRUNACTION_NOT_EXISTING
#define ERR_STREAMERMAP_NOT_EXISTING
Namespace containing helpers related to run-action configuration.
GOptions defineOptions()
Returns the options associated with the run-action logger scope.