File indexing completed on 2025-09-17 08:21:12
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include <memory>
0010 #include <string>
0011 #include <unordered_map>
0012 #include <vector>
0013
0014 #include "corecel/Types.hh"
0015 #include "corecel/io/Logger.hh"
0016 #include "geocel/BoundingBox.hh"
0017 #include "celeritas/Types.hh"
0018 #include "celeritas/phys/Primary.hh"
0019
0020 class G4Track;
0021 class G4EventManager;
0022
0023 namespace celeritas
0024 {
0025
0026 namespace detail
0027 {
0028 class HitProcessor;
0029 class OffloadWriter;
0030 }
0031
0032 struct SetupOptions;
0033 class SharedParams;
0034 class ParticleParams;
0035 class CoreStateInterface;
0036 class StepperInterface;
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054 class LocalTransporter
0055 {
0056 public:
0057
0058
0059 using MapStrReal = std::unordered_map<std::string, real_type>;
0060
0061
0062 public:
0063
0064 LocalTransporter() = default;
0065
0066
0067 LocalTransporter(SetupOptions const& options, SharedParams& params);
0068
0069
0070 inline void Initialize(SetupOptions const& options, SharedParams& params);
0071
0072
0073 [[deprecated]] void SetEventId(int id) { this->InitializeEvent(id); }
0074
0075
0076 void InitializeEvent(int);
0077
0078
0079 void Push(G4Track const&);
0080
0081
0082 void Flush();
0083
0084
0085 void Finalize();
0086
0087
0088 MapStrReal GetActionTime() const;
0089
0090
0091 size_type GetBufferSize() const { return buffer_.size(); }
0092
0093
0094 CoreStateInterface const& GetState() const;
0095
0096
0097 CoreStateInterface& GetState();
0098
0099
0100 explicit operator bool() const { return static_cast<bool>(step_); }
0101
0102 private:
0103
0104
0105 using SPOffloadWriter = std::shared_ptr<detail::OffloadWriter>;
0106 using BBox = BoundingBox<double>;
0107
0108 struct BufferAccum
0109 {
0110 double energy{0};
0111 double lost_energy{0};
0112 std::size_t lost_primaries{0};
0113 };
0114
0115 struct RunAccum
0116 {
0117 std::size_t events{0};
0118 std::size_t primaries{0};
0119 std::size_t steps{0};
0120 std::size_t lost_primaries{0};
0121 std::size_t hits{0};
0122 };
0123
0124
0125
0126 std::shared_ptr<ParticleParams const> particles_;
0127 BBox bbox_;
0128
0129
0130 std::shared_ptr<StepperInterface> step_;
0131 std::vector<Primary> buffer_;
0132 std::shared_ptr<detail::HitProcessor> hit_processor_;
0133
0134
0135 UniqueEventId event_id_;
0136 G4EventManager* event_manager_{nullptr};
0137
0138 size_type auto_flush_{};
0139 size_type max_step_iters_{};
0140
0141 BufferAccum buffer_accum_;
0142 RunAccum run_accum_;
0143
0144
0145 SPOffloadWriter dump_primaries_;
0146 };
0147
0148
0149
0150
0151
0152
0153
0154
0155 void LocalTransporter::Initialize(SetupOptions const& options,
0156 SharedParams& params)
0157 {
0158 *this = LocalTransporter(options, params);
0159 }
0160
0161
0162 }