eventDispenser
Loading...
Searching...
No Matches
eventDispenser.h
Go to the documentation of this file.
1#pragma once
2
3#include <gemc/gbase/gbase.h>
4#include <gemc/ganalysis/gAnalysisAccumulator.h>
5#include <gemc/gdynamicDigitization/gdynamicdigitization.h>
6
7#include <chrono>
8#include <map>
9#include <memory>
10#include <optional>
11#include <stdexcept>
12#include <vector>
13
18
36class EventDispenser : public GBase<EventDispenser>
37{
38public:
53 EventDispenser(const std::shared_ptr<GOptions>& gopt,
54 const std::shared_ptr<const gdynamicdigitization::dRoutinesMap>& gdynamicDigitizationMap,
55 std::shared_ptr<GAnalysisAccumulator> analysisAccumulator = nullptr);
56
57private:
62
64 int neventsToProcess;
65
67 int userRunno;
68
70 bool offscreen_screenshots = false;
71
73 std::optional<int> currentRunno;
74
76
81
83 std::map<int, double> runWeights;
84
86 std::map<int, int> runEvents;
87
89 std::vector<int> listOfRuns;
90
92 int currentRunIndex{};
93
95 std::optional<std::chrono::steady_clock::time_point> beamOnTime;
96
98
113 void distributeEvents(int nevents_to_process);
114
121 void setNextRun() { currentRunIndex++; }
122
132 std::shared_ptr<const gdynamicdigitization::dRoutinesMap> gDigitizationMap;
133
135 std::shared_ptr<GAnalysisAccumulator> analysisAccumulator;
136
137public:
147 std::map<int, int> getRunEvents() { return runEvents; }
148
161 [[nodiscard]] int getCurrentRun() const { return listOfRuns[currentRunIndex]; }
162
173 [[nodiscard]] int getTotalNumberOfEvents() const;
174
187 int processEvents();
188
194 [[nodiscard]] bool beamOnIssued() const { return beamOnTime.has_value(); }
195
203 [[nodiscard]] std::chrono::steady_clock::time_point beamOnStartTime() const {
204 if (!beamOnTime) {
205 throw std::logic_error("beamOnStartTime() called before the first /run/beamOn");
206 }
207 return *beamOnTime;
208 }
209
219 void setNumberOfEvents(int nevts);
220
228 void resetRunContext();
229};
void resetRunContext()
Force per-run digitization setup to run again on the next event batch.
bool beamOnIssued() const
Returns whether at least one /run/beamOn has been issued.
int processEvents()
Processes all runs by initializing digitization routines and dispatching events.
std::chrono::steady_clock::time_point beamOnStartTime() const
Returns the wall-clock time of the first /run/beamOn.
int getCurrentRun() const
Returns the current run number from the internally stored run list.
EventDispenser(const std::shared_ptr< GOptions > &gopt, const std::shared_ptr< const gdynamicdigitization::dRoutinesMap > &gdynamicDigitizationMap, std::shared_ptr< GAnalysisAccumulator > analysisAccumulator=nullptr)
Constructs an EventDispenser and prepares the run event distribution.
void setNumberOfEvents(int nevts)
Sets the total number of events to process in single-run mode.
int getTotalNumberOfEvents() const
Computes the total number of events across all runs.
std::map< int, int > getRunEvents()
Returns the computed run-to-event allocation.
GBase(const std::shared_ptr< GOptions > &gopt, std::string logger_name="")