11std::string decay_key(
const DecayId& decay) {
30 std::lock_guard<std::mutex> lock(m_);
32 const std::string dk = decay_key(decay);
33 const std::string ok = observable_key(obs);
35 if (
auto it = parent_.find(ok); it != parent_.end() && !(it->second == decay)) {
36 throw std::runtime_error(
37 "Observable '" + obs.
str() +
38 "' is already linked to decay '" + it->second.str() +
"'"
42 auto& vec = graph_[dk];
43 if (std::find(vec.begin(), vec.end(), obs) == vec.end()) {
51 std::lock_guard<std::mutex> lock(m_);
53 if (
auto it = graph_.find(decay_key(decay)); it != graph_.end()) {
61 std::lock_guard<std::mutex> lock(m_);
63 if (
auto it = parent_.find(observable_key(obs)); it != parent_.end()) {
71 std::lock_guard<std::mutex> lock(m_);
73 if (
auto it = graph_.find(decay_key(decay)); it != graph_.end()) {
74 return !it->second.empty();
Thread-safe singleton storing dynamic decay-observable links.
std::optional< DecayId > parent_of(const ObservableId &obs) const
Return the dynamic parent decay of an observable, if known.
bool has_observables(const DecayId &decay) const
Check whether a decay has at least one dynamic observable.
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.
void link(const DecayId &decay, const ObservableId &obs)
Link an observable to a parent decay.
const std::string & str() const
Returns the underlying string.
Runtime graph linking decay identifiers to observable identifiers.
std::string normalize_key(std::string_view s)
Normalizes a string key in a case-insensitive manner.