10#include "G4UserRunAction.hh"
13#include <gemc/gbase/gbase.h>
14#include <gemc/ganalysis/gAnalysisAccumulator.h>
15#include <gemc/gdynamicDigitization/gdynamicdigitization.h>
16#include <gemc/gstreamer/gstreamer.h>
17#include <gemc/gstreamer/factories/SRO/gSROFactory.h>
18#include <gemc/gdata/run/gRunDataCollection.h>
81 explicit GRunAction(std::shared_ptr<GOptions> gopts,
82 std::shared_ptr<gdynamicdigitization::dRoutinesMap> digi_map,
83 std::shared_ptr<GAnalysisAccumulator> analysis_accumulator =
nullptr,
84 std::shared_ptr<GSROFactory> sro_factory =
nullptr);
88 [[nodiscard]]
const std::shared_ptr<GSROFactory>&
get_sro_factory()
const {
return sro_factory; }
107 return digitization_routines_map;
120 -> std::shared_ptr<const
gstreamer::gstreamersMap> {
121 if (!gstreamer_threads_map) {
124 return gstreamer_threads_map;
128 return gstreamer_threads_map !=
nullptr;
136 if (analysis_shard !=
nullptr) {
137 analysis_shard->recordDigitized(requiredAnalysisRunNumber(), detector, data);
143 if (analysis_shard !=
nullptr) {
144 analysis_shard->recordTrueInformation(requiredAnalysisRunNumber(), detector, data);
159 std::unique_ptr<GDigitizedData> digi_data) {
160 if (run_data ==
nullptr) {
162 " run_data is null - cannot collect run-level payload for collection ", hcSDName);
165 run_data->collect_event_data_collections(
167 std::move(digi_data));
177 if (run_data ==
nullptr) {
179 " run_data is null - cannot increment processed events.");
182 auto& header = run_data->getHeader();
183 if (header ==
nullptr) {
185 " run_data header is null - cannot increment processed events.");
188 header->increment_events_processed();
198 if (run_data ==
nullptr) {
200 " run_data is null - cannot increment payload events.");
203 auto& header = run_data->getHeader();
204 if (header ==
nullptr) {
206 " run_data header is null - cannot increment payload events.");
209 header->increment_events_with_payload();
213 using CompletedRunData = std::vector<std::unique_ptr<GRunDataCollection>>;
221 void stash_worker_run_data();
231 [[nodiscard]] CompletedRunData take_completed_worker_run_data();
241 G4Run* GenerateRun()
override;
262 void BeginOfRunAction(
const G4Run*
run)
override;
278 void EndOfRunAction(
const G4Run*
run)
override;
285 void publish_run_data(
const std::shared_ptr<GRunDataCollection>& run_data)
const;
295 std::shared_ptr<gdynamicdigitization::dRoutinesMap> digitization_routines_map;
298 std::shared_ptr<GAnalysisAccumulator> analysis_accumulator;
301 std::shared_ptr<GSROFactory> sro_factory;
304 std::unique_ptr<GAnalysisShard> analysis_shard;
307 std::optional<int> analysis_run_number;
309 [[nodiscard]]
int requiredAnalysisRunNumber()
const {
310 if (!analysis_run_number) {
311 throw std::logic_error(
"Analyzer data recorded before the simulation run number was published");
313 return *analysis_run_number;
319 std::shared_ptr<const gstreamer::gstreamersMap> gstreamer_threads_map;
324 std::shared_ptr<const gstreamer::gstreamersMap> gstreamer_run_map;
332 std::unique_ptr<GRunDataCollection> run_data;
337 bool need_a_thread_streamer =
false;
342 bool need_a_run_streamer =
false;
347 static std::mutex completed_run_data_mutex;
355 static CompletedRunData completed_worker_run_data;
375 void normalize_run_data(
const std::shared_ptr<GRunDataCollection>& run_data)
const;
378 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.
GRunAction(std::shared_ptr< GOptions > gopts, std::shared_ptr< gdynamicdigitization::dRoutinesMap > digi_map, std::shared_ptr< GAnalysisAccumulator > analysis_accumulator=nullptr, std::shared_ptr< GSROFactory > sro_factory=nullptr)
Constructs the run action.
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
const std::shared_ptr< GSROFactory > & get_sro_factory() const
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.
constexpr int ERR_STREAMERMAP_NOT_EXISTING
constexpr int ERR_GRUNACTION_NOT_EXISTING
Namespace containing helpers related to run-action configuration.
GOptions defineOptions()
Returns the options associated with the run-action logger scope.