Skip to content

Commit 2740eeb

Browse files
committed
started run data collection
1 parent 0575a0e commit 2740eeb

12 files changed

Lines changed: 197 additions & 50 deletions

File tree

actions/event/gEventAction.cc

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,20 @@ void GEventAction::BeginOfEventAction([[maybe_unused]] const G4Event* event) {
2828

2929
void GEventAction::EndOfEventAction([[maybe_unused]] const G4Event* event) {
3030
// End-of-event hook: collect hit collections, digitize hits, and publish the event to streamers.
31-
auto* const hcs_this_event = event->GetHCofThisEvent();
32-
if (hcs_this_event == nullptr) {
33-
return;
34-
}
35-
3631
if (run_action == nullptr) {
3732
log->error(ERR_GRUNACTION_NOT_EXISTING, FUNCTION_NAME,
3833
" run_action is null - cannot access digitization routines or streamers.");
3934
return;
4035
}
4136

37+
// Count every processed event once, independently of whether it produces any payload.
38+
run_action->increment_run_events_processed();
39+
40+
auto* const hcs_this_event = event->GetHCofThisEvent();
41+
if (hcs_this_event == nullptr) {
42+
return;
43+
}
44+
4245
const auto thread_id = G4Threading::G4GetThreadId();
4346
const auto event_id = event->GetEventID();
4447

@@ -53,6 +56,7 @@ void GEventAction::EndOfEventAction([[maybe_unused]] const G4Event* event) {
5356
}
5457

5558
bool has_event_mode_payload = false;
59+
bool has_run_mode_payload = false;
5660

5761
// Loop over all hit collections produced by sensitive detectors in this event.
5862
for (G4int hci = 0; hci < hcs_this_event->GetNumberOfCollections(); ++hci) {
@@ -103,13 +107,22 @@ void GEventAction::EndOfEventAction([[maybe_unused]] const G4Event* event) {
103107
has_event_mode_payload = true;
104108
}
105109
else if (collection_mode == CollectionMode::run) {
106-
run_action->collect_event_data_collections(
107-
hcSDName,
108-
std::move(digi_data));
110+
if (digi_data != nullptr) {
111+
run_action->collect_event_data_collections(
112+
hcSDName,
113+
std::move(digi_data));
114+
has_run_mode_payload = true;
115+
}
109116
}
110117
}
111118
}
112119

120+
// Count this event once for run-level accumulation if any run-mode payload was produced.
121+
if (has_run_mode_payload) {
122+
run_action->increment_run_events_with_payload();
123+
}
124+
125+
113126
// Publish once per event, after all event-mode collections have been processed.
114127
if (has_event_mode_payload) {
115128
publish_event_data(eventDataCollection);
@@ -137,4 +150,4 @@ void GEventAction::publish_event_data(const std::shared_ptr<GEventDataCollection
137150

138151
gstreamer->publishEventData(event_data);
139152
}
140-
}
153+
}

actions/run/gRunAction.h

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,40 @@ class GRunAction : public GBase<GRunAction>, public G4UserRunAction
125125
std::move(digi_data));
126126
}
127127

128+
void increment_run_events_processed() {
129+
if (run_data == nullptr) {
130+
log->error(ERR_GRUNACTION_NOT_EXISTING, FUNCTION_NAME,
131+
" run_data is null - cannot increment processed events.");
132+
return;
133+
}
134+
135+
auto& header = run_data->getHeader();
136+
if (header == nullptr) {
137+
log->error(ERR_GRUNACTION_NOT_EXISTING, FUNCTION_NAME,
138+
" run_data header is null - cannot increment processed events.");
139+
return;
140+
}
141+
142+
header->increment_events_processed();
143+
}
144+
145+
void increment_run_events_with_payload() {
146+
if (run_data == nullptr) {
147+
log->error(ERR_GRUNACTION_NOT_EXISTING, FUNCTION_NAME,
148+
" run_data is null - cannot increment payload events.");
149+
return;
150+
}
151+
152+
auto& header = run_data->getHeader();
153+
if (header == nullptr) {
154+
log->error(ERR_GRUNACTION_NOT_EXISTING, FUNCTION_NAME,
155+
" run_data header is null - cannot increment payload events.");
156+
return;
157+
}
158+
159+
header->increment_events_with_payload();
160+
}
161+
128162
private:
129163
using CompletedRunData = std::vector<std::unique_ptr<GRunDataCollection>>;
130164

@@ -231,7 +265,6 @@ class GRunAction : public GBase<GRunAction>, public G4UserRunAction
231265
static CompletedRunData completed_worker_run_data;
232266

233267
void publish_run_data(const std::shared_ptr<GRunDataCollection>& run_data) const;
234-
235268
};
236269

237270

@@ -263,4 +296,4 @@ class GRunAction : public GBase<GRunAction>, public G4UserRunAction
263296
// frameDuration = 64000;
264297
// eventDuration = gutilities::getG4Number(goptions->getScalarString("eventTimeSize"));
265298

266-
// stream = gopt->getSwitch("stream");
299+
// stream = gopt->getSwitch("stream");

examples/basic/b1/b1.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ gparticle:
77
- name: gamma
88
p: 6
99
vz: -17
10-
delta_vx: 8
11-
delta_vy: 8
10+
delta_vx: 3
11+
delta_vy: 3
1212
multiplicity: 1
1313

1414
verbosity:

gdata/run/gRunDataCollection.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void GRunDataCollection::collect_event_data_collection(const std::shared_ptr<GEv
4242

4343
void GRunDataCollection::collect_event_data_collections(const std::string& sdName,
4444
std::unique_ptr<GDigitizedData> ddata) {
45-
45+
4646
collectDetectorDigitizedData(sdName, ddata);
4747

4848
log->info(2, *gdataCollectionMap[sdName]);
@@ -52,6 +52,7 @@ void GRunDataCollection::collect_event_data_collections(const std::string&
5252
void GRunDataCollection::merge(const GRunDataCollection& other) {
5353

5454
grun_header->add_events_processed(other.get_events_processed());
55+
grun_header->add_events_with_payload(other.get_events_with_payload());
5556

5657
const auto& other_map = other.getDataCollectionMap();
5758

@@ -68,4 +69,4 @@ void GRunDataCollection::merge(const GRunDataCollection& other) {
6869
}
6970
}
7071
}
71-
}
72+
}

gdata/run/gRunDataCollection.h

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* A run collection integrates event-level data into a run summary.
99
*
1010
* It owns:
11-
* - a \ref GRunHeader describing run ID and integrated event count
11+
* - a \ref GRunHeader describing run ID and event counters
1212
* - a map from sensitive detector name to \ref GDataCollection (the per-detector accumulator)
1313
*
1414
* Integration is performed by consuming \ref GEventDataCollection objects and:
@@ -20,10 +20,10 @@
2020
* - one integrated \ref GDigitizedData entry per detector
2121
* (vector size 1), depending on how \ref GDataCollection integration is used.
2222
*
23-
* \note Event counter
24-
* This class currently does not increment \c GRunHeader::events_processed.
25-
* If you want that counter to reflect integrated events, the caller (or this class)
26-
* must call \ref GRunHeader::increment_events_processed "increment_events_processed()" once per integrated event.
23+
* \note Event counters
24+
* This class stores event counters in \ref GRunHeader:
25+
* - \c events_processed tracks total processed events
26+
* - \c events_with_payload tracks events that contributed at least one run-mode payload
2727
*/
2828

2929
#include "gRunHeader.h"
@@ -83,7 +83,7 @@ class GRunDataCollection : public GBase<GRunDataCollection>
8383
* \brief Construct a run data collection.
8484
*
8585
* \details
86-
* The header stores metadata such as run ID and (optionally) number of integrated events.
86+
* The header stores metadata such as run ID and event counters.
8787
*
8888
* Ownership:
8989
* - \p header is moved into this object and owned exclusively.
@@ -107,6 +107,8 @@ class GRunDataCollection : public GBase<GRunDataCollection>
107107
* - first hit creates the integrated entry
108108
* - subsequent hits contribute by summation of scalars
109109
*
110+
* This method increments \c events_processed once for the integrated event.
111+
*
110112
* \param edc Event-level container to integrate.
111113
*/
112114
void collect_event_data_collection(const std::shared_ptr<GEventDataCollection> edc);
@@ -139,7 +141,7 @@ class GRunDataCollection : public GBase<GRunDataCollection>
139141
[[nodiscard]] auto getRunNumber() const -> int { return grun_header->getRunID(); }
140142

141143
/**
142-
* \brief Number of events integrated into this run summary.
144+
* \brief Total number of processed events associated with this run summary.
143145
*
144146
* \details
145147
* This value is stored in \ref GRunHeader and incremented by
@@ -149,6 +151,17 @@ class GRunDataCollection : public GBase<GRunDataCollection>
149151
*/
150152
[[nodiscard]] auto get_events_processed() const -> int { return grun_header->get_events_processed(); }
151153

154+
/**
155+
* \brief Number of processed events that contributed run-mode payload.
156+
*
157+
* \details
158+
* This value is stored in \ref GRunHeader and incremented by
159+
* \ref GRunHeader::increment_events_with_payload "increment_events_with_payload()".
160+
*
161+
* \return Count stored in the header.
162+
*/
163+
[[nodiscard]] auto get_events_with_payload() const -> int { return grun_header->get_events_with_payload(); }
164+
152165
/**
153166
* \brief Merge another run-level accumulator into this one.
154167
*
@@ -160,6 +173,10 @@ class GRunDataCollection : public GBase<GRunDataCollection>
160173
* Detector entries are merged by detector name. For each detector:
161174
* - digitized integrated data are accumulated into this object
162175
*
176+
* Event counters are also merged:
177+
* - total processed events
178+
* - events with payload
179+
*
163180
* \param other Source run accumulator to merge into this object.
164181
*/
165182
void merge(const GRunDataCollection& other);
@@ -181,4 +198,4 @@ class GRunDataCollection : public GBase<GRunDataCollection>
181198
* \param data Digitized-hit object to integrate (not owned; deep-copied internally).
182199
*/
183200
void collectDetectorDigitizedData(const std::string& sdName, const std::unique_ptr<GDigitizedData>& data);
184-
};
201+
};

gdata/run/gRunHeader.h

Lines changed: 59 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
* A run header is a minimal metadata object associated with a \ref GRunDataCollection.
1515
*
1616
* It records:
17-
* - \c runID : run identifier (application-defined)
18-
* - \c events_processed : number of events integrated into this run summary so far
17+
* - \c runID : run identifier (application-defined)
18+
* - \c events_processed : total number of events seen by the run action
19+
* - \c events_with_payload : number of events that contributed at least one run-mode payload
1920
*
2021
* The constructor emits a brief log summary. In multi-threaded contexts, an optional
2122
* thread ID can be attached for diagnostics and provenance.
@@ -43,20 +44,25 @@ inline auto defineOptions() -> GOptions {
4344
} // namespace grun_header
4445

4546
/**
46-
* \brief Minimal run metadata: run ID and integrated-event counter.
47+
* \brief Minimal run metadata: run ID and run-level event counters.
4748
*
4849
* \details
4950
* This object is typically owned by \ref GRunDataCollection as a \c std::unique_ptr.
5051
* It provides:
5152
* - stable access to run identifier
52-
* - a simple counter tracking how many events were integrated
53+
* - a simple counter tracking how many events were processed
54+
* - a simple counter tracking how many events contributed run-mode payload
5355
*
54-
* The counter is incremented via \ref GRunHeader::increment_events_processed "increment_events_processed()".
56+
* The counters are incremented via:
57+
* - \ref GRunHeader::increment_events_processed "increment_events_processed()"
58+
* - \ref GRunHeader::increment_events_with_payload "increment_events_with_payload()"
5559
*
5660
* \note
57-
* \ref GRunDataCollection does not automatically increment this counter in the current implementation.
58-
* If you want the value to reflect integrated events, ensure the caller (or the run collection)
59-
* invokes \ref GRunHeader::increment_events_processed "increment_events_processed()" once per event.
61+
* \ref GRunDataCollection does not automatically decide which events contributed payload.
62+
* The caller (or higher-level run/event action code) must invoke:
63+
* - \ref GRunHeader::increment_events_processed "increment_events_processed()" once per processed event
64+
* - \ref GRunHeader::increment_events_with_payload "increment_events_with_payload()" once per event
65+
* that produced at least one run-mode payload
6066
*/
6167
class GRunHeader : public GBase<GRunHeader>
6268
{
@@ -67,7 +73,8 @@ class GRunHeader : public GBase<GRunHeader>
6773
* \details
6874
* The constructor logs:
6975
* - run ID
70-
* - initial event count (usually 0)
76+
* - initial total processed-event count (usually 0)
77+
* - initial payload-event count (usually 0)
7178
* - optional thread ID if provided
7279
*
7380
* \param gopts Shared options object used to configure logging and behavior.
@@ -80,13 +87,15 @@ class GRunHeader : public GBase<GRunHeader>
8087
if (tid != -1) {
8188
log->info(1, "\n",
8289
TPOINTITEM, " Run ID: ", rid, "\n",
83-
TPOINTITEM, " Number of events collected: ", events_processed,
90+
TPOINTITEM, " Number of events processed: ", events_processed, "\n",
91+
TPOINTITEM, " Number of events with payload: ", events_with_payload, "\n",
8492
TPOINTITEM, " Thread ID: ", tid);
8593
}
8694
else {
8795
log->info(1, "\n",
8896
TPOINTITEM, " Run ID: ", rid, "\n",
89-
TPOINTITEM, " Number of events collected: ", events_processed);
97+
TPOINTITEM, " Number of events processed: ", events_processed, "\n",
98+
TPOINTITEM, " Number of events with payload: ", events_with_payload);
9099
}
91100
}
92101

@@ -97,32 +106,61 @@ class GRunHeader : public GBase<GRunHeader>
97106
[[nodiscard]] auto getRunID() const -> int { return runID; }
98107

99108
/**
100-
* \brief Get the number of events integrated into this run summary so far.
109+
* \brief Get the total number of events processed in this run summary so far.
101110
*
102111
* \details
103112
* This value is incremented by \ref GRunHeader::increment_events_processed "increment_events_processed()".
104-
* Typical usage is "once per event integrated into the run accumulator".
113+
* Typical usage is "once per processed event reaching end-of-event handling".
105114
*
106115
* \return Number of processed events.
107116
*/
108117
[[nodiscard]] auto get_events_processed() const -> int { return events_processed; }
109118

119+
/**
120+
* \brief Get the number of events that contributed run-mode payload in this run summary so far.
121+
*
122+
* \details
123+
* This value is incremented by
124+
* \ref GRunHeader::increment_events_with_payload "increment_events_with_payload()".
125+
* Typical usage is "once per event that contributed at least one run-mode payload".
126+
*
127+
* \return Number of payload-producing events.
128+
*/
129+
[[nodiscard]] auto get_events_with_payload() const -> int { return events_with_payload; }
130+
110131
/**
111132
* \brief Increment the number of processed events.
112133
*
113134
* \details
114-
* Intended to be called once per event integrated into the run accumulator.
135+
* Intended to be called once per processed event.
115136
*/
116137
void increment_events_processed() { events_processed++; }
117138

118139
/**
119-
* \brief Add a number of processed events to the counter.
120-
*
121-
* \param count Number of processed events to add.
122-
*/
140+
* \brief Increment the number of events that produced run-mode payload.
141+
*
142+
* \details
143+
* Intended to be called once per event that contributed at least one run-mode payload
144+
* to the run accumulator.
145+
*/
146+
void increment_events_with_payload() { events_with_payload++; }
147+
148+
/**
149+
* \brief Add a number of processed events to the counter.
150+
*
151+
* \param count Number of processed events to add.
152+
*/
123153
void add_events_processed(int count) { events_processed += count; }
124154

155+
/**
156+
* \brief Add a number of payload-producing events to the counter.
157+
*
158+
* \param count Number of payload-producing events to add.
159+
*/
160+
void add_events_with_payload(int count) { events_with_payload += count; }
161+
125162
private:
126-
int events_processed{0}; ///< Number of events integrated into the run summary.
127-
int runID; ///< Run identifier.
128-
};
163+
int events_processed{0}; ///< Total number of processed events in the run summary.
164+
int events_with_payload{0}; ///< Number of processed events that contributed run-mode payload.
165+
int runID; ///< Run identifier.
166+
};

0 commit comments

Comments
 (0)