iqm.cpc.core.observation.observation_loading_rules.resolve_rules#
- iqm.cpc.core.observation.observation_loading_rules.resolve_rules(observation_name, rules, rule_cache=None)#
Resolves the rules related to loading and fall back one by one.
If an observation is loaded successfully from the DB, the rule resolving is terminated. Returns the loaded observation and the rule that ended up producing it.
If global observation loading rules has been set with
set_global_default_observation_loading_rules(), then those rules will override anything given inrules. Global observation rules can be set to an empty list, in that case no rules will be used, i.e. observation will not be loaded at all. If global observations rules are set to None, then those will be ignored and original rules given as a parameter will be used.- Parameters:
observation_name (str) – the name of the observation to search for in the database.
rules (list[Callable[[str], ObservationBase | None]]) – the list of rules to be resolved in loading the observation.
rule_cache (RuleCache | None) – cache of preloaded observations for certain load rules. Loading from the rule cache takes precedence over the normal rule execution.
- Returns:
The observation that was loaded (None if no rule successfully fetched an observation).
The name of the rule class that produced the above observation (None if no rule successfully fetched an observation).
- Raises:
ValueError – in case a rule could not be applied and a ValueError was thrown.
- Return type:
tuple[ObservationBase, str] | tuple[None, None]