Skip to content

Commit 29995b6

Browse files
committed
refactor: use std::map for deterministic ordering in SimCalorimeterHitProcessor
1 parent 7f33b79 commit 29995b6

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/algorithms/calorimetry/SimCalorimeterHitProcessor.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <stdexcept>
2424
#include <tuple>
2525
#include <unordered_map>
26+
#include <map>
2627
#include <variant>
2728
#include <vector>
2829

@@ -166,18 +167,18 @@ void SimCalorimeterHitProcessor::process(const SimCalorimeterHitProcessor::Input
166167
auto [out_hits, out_hit_contribs] = output;
167168

168169
// Map for staging output information. We have 2 levels of structure:
169-
// - top level: (MCParticle, Merged Hit CellID)
170+
// - top level: (MCParticle, Merged Hit CellID, TimeID)
170171
// - second level: (Merged Contributions)
172+
// We use std::map instead of std::unordered_map to ensure deterministic ordering
173+
// and reproducible results between single-threaded and multi-threaded execution.
171174
// Ideally we would want immediately create our output objects and modify the
172175
// contributions when needed. That could reduce the following code to a single loop
173176
// (instead of 2 consecutive loops). However, this is not possible as we may have to merge
174177
// (hence modify) contributions which is not supported for PodIO VectorMembers. Using
175178
// reasonable contribution merging, at least the intermediary structure should be
176179
// quite a bit smaller than the original hit collection.
177180
using HitIndex = std::tuple<edm4hep::MCParticle, uint64_t /* cellID */, int /* timeID */>;
178-
std::unordered_map<HitIndex,
179-
std::unordered_map<uint64_t /* cellID */, HitContributionAccumulator>>
180-
hit_map;
181+
std::map<HitIndex, std::map<uint64_t /* cellID */, HitContributionAccumulator>> hit_map;
181182

182183
for (const auto& ih : *in_hits) {
183184
// the cell ID of the new superhit we are making

0 commit comments

Comments
 (0)