File indexing completed on 2025-12-16 09:41:11
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include <memory>
0010 #include <string>
0011 #include <vector>
0012
0013 #include "corecel/Assert.hh"
0014 #include "geocel/BoundingBox.hh"
0015
0016 #include "Types.hh"
0017
0018 class G4ParticleDefinition;
0019 class G4VPhysicalVolume;
0020
0021 namespace celeritas
0022 {
0023
0024 namespace detail
0025 {
0026 class OffloadWriter;
0027 }
0028
0029 class CoreParams;
0030 class CoreStateInterface;
0031 struct Primary;
0032 struct SetupOptions;
0033 class StepCollector;
0034 class GeantGeoParams;
0035 class OutputRegistry;
0036 class TimeOutput;
0037 class GeantSd;
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059 class SharedParams
0060 {
0061 public:
0062
0063
0064 using SPParams = std::shared_ptr<CoreParams>;
0065 using SPConstParams = std::shared_ptr<CoreParams const>;
0066 using VecG4ParticleDef = std::vector<G4ParticleDefinition*>;
0067 using Mode = OffloadMode;
0068
0069
0070 public:
0071
0072
0073
0074
0075 static Mode GetMode();
0076
0077
0078
0079 [[deprecated]]
0080 static bool CeleritasDisabled();
0081
0082
0083
0084 [[deprecated]]
0085 static bool KillOffloadTracks();
0086
0087
0088
0089
0090
0091
0092 SharedParams() = default;
0093
0094
0095 explicit SharedParams(SetupOptions const& options);
0096
0097
0098 inline void Initialize(SetupOptions const& options);
0099
0100
0101 void InitializeWorker(SetupOptions const& options);
0102
0103
0104 void Finalize();
0105
0106
0107
0108
0109
0110
0111 inline SPParams const& Params();
0112
0113
0114 inline SPConstParams Params() const;
0115
0116
0117 inline VecG4ParticleDef const& OffloadParticles() const;
0118
0119
0120 explicit operator bool() const { return mode_ != Mode::uninitialized; }
0121
0122
0123
0124
0125
0126 using SPGeantSd = std::shared_ptr<GeantSd>;
0127 using SPOffloadWriter = std::shared_ptr<detail::OffloadWriter>;
0128 using SPOutputRegistry = std::shared_ptr<OutputRegistry>;
0129 using SPTimeOutput = std::shared_ptr<TimeOutput>;
0130 using SPState = std::shared_ptr<CoreStateInterface>;
0131 using SPConstGeantGeoParams = std::shared_ptr<GeantGeoParams const>;
0132 using BBox = BoundingBox<double>;
0133
0134
0135 Mode mode() const { return mode_; }
0136
0137
0138 inline SPGeantSd const& hit_manager() const;
0139
0140
0141 inline SPOffloadWriter const& offload_writer() const;
0142
0143
0144 inline SPOutputRegistry const& output_reg() const;
0145
0146
0147 inline SPTimeOutput const& timer() const;
0148
0149
0150 void set_state(unsigned int stream_id, SPState&&);
0151
0152
0153 unsigned int num_streams() const;
0154
0155
0156 SPConstGeantGeoParams const& geant_geo_params() const;
0157
0158
0159 BBox const& bbox() const { return bbox_; }
0160
0161
0162 private:
0163
0164
0165
0166 Mode mode_{Mode::uninitialized};
0167 std::shared_ptr<CoreParams> params_;
0168 std::shared_ptr<GeantSd> geant_sd_;
0169 std::shared_ptr<StepCollector> step_collector_;
0170 VecG4ParticleDef particles_;
0171 std::string output_filename_;
0172 G4VPhysicalVolume const* world_{nullptr};
0173 SPOffloadWriter offload_writer_;
0174 std::vector<std::shared_ptr<CoreStateInterface>> states_;
0175 SPOutputRegistry output_reg_;
0176 SPTimeOutput timer_;
0177 BBox bbox_;
0178
0179
0180 SPConstGeantGeoParams geant_geo_;
0181
0182
0183
0184 void set_num_streams(unsigned int num_streams);
0185 void try_output() const;
0186 };
0187
0188
0189
0190
0191
0192 void SharedParams::Initialize(SetupOptions const& options)
0193 {
0194 *this = SharedParams(options);
0195 }
0196
0197
0198
0199
0200
0201
0202
0203 auto SharedParams::Params() -> SPParams const&
0204 {
0205 CELER_EXPECT(mode_ == Mode::enabled);
0206 CELER_ENSURE(params_);
0207 return params_;
0208 }
0209
0210
0211
0212
0213
0214
0215
0216 auto SharedParams::Params() const -> SPConstParams
0217 {
0218 CELER_EXPECT(mode_ == Mode::enabled);
0219 CELER_ENSURE(params_);
0220 return params_;
0221 }
0222
0223
0224
0225
0226
0227 auto SharedParams::OffloadParticles() const -> VecG4ParticleDef const&
0228 {
0229 CELER_EXPECT(*this);
0230 return particles_;
0231 }
0232
0233
0234
0235
0236
0237
0238
0239 auto SharedParams::hit_manager() const -> SPGeantSd const&
0240 {
0241 CELER_EXPECT(*this);
0242 return geant_sd_;
0243 }
0244
0245
0246
0247
0248
0249 auto SharedParams::offload_writer() const -> SPOffloadWriter const&
0250 {
0251 CELER_EXPECT(*this);
0252 return offload_writer_;
0253 }
0254
0255
0256
0257
0258
0259 auto SharedParams::output_reg() const -> SPOutputRegistry const&
0260 {
0261 CELER_EXPECT(*this);
0262 return output_reg_;
0263 }
0264
0265
0266
0267
0268
0269 auto SharedParams::timer() const -> SPTimeOutput const&
0270 {
0271 CELER_EXPECT(*this);
0272 CELER_EXPECT(timer_);
0273 return timer_;
0274 }
0275
0276
0277 }