10#include <unordered_map>
11#include <unordered_set>
51 static const std::map<Decays, LhaID> empty{};
65 std::optional<LhaID>
ext = std::nullopt;
86 decay_external_mapping
118 std::vector<std::string> aliases = {},
119 std::optional<LhaID> ext = std::nullopt) =
delete;
140 std::vector<ObservableId> out;
142 out.reserve(obs_enums.size());
144 for (
auto obs : obs_enums) {
166 std::vector<ObservableId> out;
167 std::unordered_set<ObservableId> seen;
170 if (seen.insert(obs).second) {
179 if (
auto builtin =
enum_of(d); builtin) {
186 throw std::runtime_error(
"Decay has no observable: " + d.str());
215 if (
auto builtin =
enum_of(d); builtin) {
232 throw std::runtime_error(
"Decay must have at least one observable: " + d.str());
257 std::vector<std::string> aliases,
258 std::vector<CustomObservableSpec> observables)
260 if (observables.empty()) {
261 throw std::invalid_argument(
262 "Cannot register custom decay '" + canonical +
"' without observables"
273 for (
auto& obs : observables) {
276 std::move(obs.aliases),
295 if (std::find(vec.begin(), vec.end(), obs) != vec.end()) {
299 throw std::runtime_error(
"Observable not mapped to any decay");
308 static std::unordered_map<ObservableId, DecayId> cache;
309 static std::once_flag init;
311 std::call_once(init, [] {
339 if (
auto it = m.find(obs); it != m.end()) {
364 throw std::runtime_error(
"Observable not mapped to any decay: " + obs.
str());
Lightweight representation of LHAPDF / SLHA-style identifiers.
const std::map< Decays, std::string > & decays_mapping()
Returns the mapping between Decays and their string names.
const std::map< Decays, std::vector< Observables > > & decay_observable_mapping()
Returns the mapping between Decays and the list of Observables associated with each decay channel.
Static mappings between enum classes and string (or FLHA) identifiers.
static DecayGraph & instance()
Return the unique global graph instance.
std::vector< ObservableId > observables_of(const DecayId &decay) const
Return all dynamically linked observables for a decay.
Mapper for decay names, dynamic ids and observable membership.
static std::vector< ObservableId > get_observables(std::string_view d)
Dynamic lookup of observables attached to a decay resolved by name.
static DecayId get_decay_id_or_throw(const ObservableId &obs)
Throwing variant of get_decay_id().
static bool register_custom_with_observables(std::string canonical, std::vector< std::string > aliases, std::vector< CustomObservableSpec > observables)
Register a custom decay and its custom observables in one call.
static Decays get_decay(Observables obs)
Legacy static lookup of the builtin decay owning a builtin observable.
static std::optional< DecayId > get_decay_id(const ObservableId &obs)
Return the parent decay id of an observable id.
static void require_observables(const DecayId &d)
Throw if a decay has no observable.
static const std::unordered_map< ObservableId, DecayId > & observable_to_decay()
Static cache mapping builtin observable ids to builtin decay ids.
static std::vector< ObservableId > get_observable_ids(Decays d)
Convert builtin observables of a builtin decay to dynamic ids.
static bool has_observables(const DecayId &d)
Test whether a decay has at least one observable.
static std::optional< DecayId > get_decay_id(Observables obs)
Return the parent decay id of a builtin observable enum.
static std::vector< ObservableId > get_observables(const DecayId &d)
Dynamic lookup of observables attached to a decay id.
static bool register_custom(std::string canonical, std::vector< std::string > aliases={}, std::optional< LhaID > ext=std::nullopt)=delete
Disabled low-level decay registration.
static std::vector< Observables > get_observables(Decays d)
Legacy static lookup of builtin observables for a builtin decay.
Generic enum↔string mapper with external keys and dynamic aliases.
static void init_builtins()
Explicitly initializes builtin entries.
static bool register_custom(std::string canonical, std::vector< std::string > aliases={}, std::optional< LhaID > ext=std::nullopt)
Registers a custom entry with optional external key.
static std::vector< IdOf< DecayTag > > list_all()
Lists all distinct identifiers currently registered.
static std::optional< LhaID > external_of(const IdOf< DecayTag > &id)
Returns the external key associated with a given identifier.
static std::optional< Decays > enum_of(const IdOf< DecayTag > &id)
Attempts to recover the enum value associated with an identifier.
static IdOf< DecayTag > enum_elt(std::string_view s)
Alias for id_of(), kept for compatibility.
static std::optional< IdOf< DecayTag > > from_external(const LhaID &k)
Resolves an external key into an identifier.
static IdOf< DecayTag > to_id(Decays e)
Converts an enum value to an IdOf<Tag>.
static bool set_external(const IdOf< DecayTag > &id, const LhaID &k)
Sets or updates the external key of an existing identifier.
static IdOf< DecayTag > id_of(std::string_view s)
Resolves a string into an IdOf<Tag> via the registry.
static std::string str(const IdOf< DecayTag > &id)
Returns the string representation of an identifier.
static bool register_custom(const std::string &canonical, std::vector< std::string > aliases, std::optional< LhaID > ext, const DecayId &parent_decay)
Register a custom observable and attach it to a parent decay.
const std::string & str() const
Returns the underlying string.
const std::map< Decays, LhaID > & decay_external_mapping()
Placeholder external mapping for decays.
Generic enum↔string (and optional external key) mappers built on DynamicRegistry.
Mapper for builtin and runtime observable identifiers.
Small value object used to register a custom decay with observables.
std::vector< std::string > aliases
Optional aliases.
std::optional< LhaID > ext
Optional FLHA id.
std::string canonical
Canonical observable name.
Tag type for decay identifiers.
Represents an identifier of a LHA element, possibly containing several sub-ids.