File indexing completed on 2026-11-05 10:28:00
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include <memory>
0010 #include <string>
0011 #include <unordered_map>
0012 #include <utility>
0013 #include <vector>
0014
0015 #include "corecel/Assert.hh"
0016 #include "corecel/data/ParamsDataInterface.hh"
0017 #include "corecel/data/ParamsDataStore.hh"
0018 #include "celeritas/Quantities.hh"
0019 #include "celeritas/Types.hh"
0020 #include "celeritas/inp/Particle.hh"
0021
0022 #include "PDGNumber.hh"
0023 #include "ParticleData.hh"
0024 #include "ParticleView.hh"
0025
0026 namespace celeritas
0027 {
0028 struct ImportData;
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044 class ParticleParams final : public ParamsDataInterface<ParticleParamsData>
0045 {
0046 public:
0047
0048 using Input = std::vector<inp::Particle>;
0049
0050 public:
0051
0052 static std::shared_ptr<ParticleParams> from_import(ImportData const& data);
0053
0054
0055 explicit ParticleParams(Input const& defs);
0056
0057
0058
0059
0060 ParticleId::size_type size() const { return md_.size(); }
0061
0062
0063 inline std::string const& id_to_label(ParticleId id) const;
0064
0065
0066 inline PDGNumber id_to_pdg(ParticleId id) const;
0067
0068
0069 inline ParticleId find(std::string const& name) const;
0070
0071
0072 inline ParticleId find(PDGNumber pdg_code) const;
0073
0074
0075 ParticleView get(ParticleId id) const;
0076
0077
0078 HostRef const& host_ref() const final { return data_.host_ref(); }
0079
0080
0081 DeviceRef const& device_ref() const final { return data_.device_ref(); }
0082
0083 private:
0084
0085 std::vector<std::pair<std::string, PDGNumber>> md_;
0086
0087
0088 std::unordered_map<std::string, ParticleId> name_to_id_;
0089
0090
0091 std::unordered_map<PDGNumber, ParticleId> pdg_to_id_;
0092
0093
0094 ParamsDataStore<ParticleParamsData> data_;
0095 };
0096
0097
0098
0099
0100
0101
0102
0103 std::string const& ParticleParams::id_to_label(ParticleId id) const
0104 {
0105 CELER_EXPECT(id < this->size());
0106 return md_[id.get()].first;
0107 }
0108
0109
0110
0111
0112
0113 PDGNumber ParticleParams::id_to_pdg(ParticleId id) const
0114 {
0115 CELER_EXPECT(id < this->size());
0116 return md_[id.get()].second;
0117 }
0118
0119
0120
0121
0122
0123 ParticleId ParticleParams::find(std::string const& name) const
0124 {
0125 auto iter = name_to_id_.find(name);
0126 if (iter == name_to_id_.end())
0127 {
0128 return ParticleId{};
0129 }
0130 return iter->second;
0131 }
0132
0133
0134
0135
0136
0137
0138
0139
0140 ParticleId ParticleParams::find(PDGNumber pdg_code) const
0141 {
0142 auto iter = pdg_to_id_.find(pdg_code);
0143 if (iter == pdg_to_id_.end())
0144 {
0145 return ParticleId{};
0146 }
0147 return iter->second;
0148 }
0149
0150
0151 }