diff --git a/strax/context.py b/strax/context.py index 03299fa7..5a3ae2f0 100644 --- a/strax/context.py +++ b/strax/context.py @@ -1981,7 +1981,7 @@ def run_defaults(self, run_id): self._run_defaults_cache[run_id] = defs return defs - def is_stored(self, run_id, target, **kwargs): + def is_stored(self, run_id, target, detailed=True, **kwargs): """Return whether data type target has been saved for run_id through any of the registered storage frontends. @@ -2003,6 +2003,31 @@ def is_stored(self, run_id, target, **kwargs): if self._is_stored_in_sf(run_id, target, sf): return True # None of the frontends has the data + + # Before returning False, check if the data can be made trivially + plugin = self._plugin_class_registry[target] + save_when = plugin.save_when + + # Mutli-target plugins provide a save_when per target + if isinstance(save_when, immutabledict): + save_when = save_when[target] + + if save_when < strax.SaveWhen.ALWAYS and detailed: + msg = ( + f"{target} is not set to always be saved. " + "This is probably because it can be trivially made from other data. " + ) + + try: + components = self.get_components(run_id, target) + targets_plugin_made_from = tuple(components.loaders.keys()) + msg += f"{target} can be made from: {targets_plugin_made_from}." + except strax.DataNotAvailable as e: + # Warn that data cannot be made + msg += str(e) + + warnings.warn(msg) + return False def _check_forbidden(self): diff --git a/tests/test_superruns.py b/tests/test_superruns.py index 22af0d09..475a560b 100644 --- a/tests/test_superruns.py +++ b/tests/test_superruns.py @@ -251,17 +251,17 @@ def test_superrun_triggers_subrun_processing(self): def test_superruns_and_save_when(self): """Tests if only the highest level for save_when.EXPLICIT plugins is stored.""" - assert not self.context.is_stored(self.superrun_name, "peaks") - assert not self.context.is_stored(self.subrun_ids[0], "peaks") - assert not self.context.is_stored(self.subrun_ids[0], "peaks_extension") - assert not self.context.is_stored(self.superrun_name, "peaks_extension") + assert not self.context.is_stored(self.superrun_name, "peaks", detailed=False) + assert not self.context.is_stored(self.subrun_ids[0], "peaks", detailed=False) + assert not self.context.is_stored(self.subrun_ids[0], "peaks_extension", detailed=False) + assert not self.context.is_stored(self.superrun_name, "peaks_extension", detailed=False) self.context._plugin_class_registry["peaks"].save_when = strax.SaveWhen.EXPLICIT self.context.make(self.superrun_name, "peaks_extension", save=("peaks_extension",)) - assert not self.context.is_stored(self.superrun_name, "peaks") - assert not self.context.is_stored(self.subrun_ids[0], "peaks") - assert self.context.is_stored(self.superrun_name, "peaks_extension") - assert self.context.is_stored(self.subrun_ids[0], "peaks_extension") + assert not self.context.is_stored(self.superrun_name, "peaks", detailed=False) + assert not self.context.is_stored(self.subrun_ids[0], "peaks", detailed=False) + assert self.context.is_stored(self.superrun_name, "peaks_extension", detailed=False) + assert self.context.is_stored(self.subrun_ids[0], "peaks_extension", detailed=False) def test_storing_with_second_sf(self): """Tests if only superrun is written to new sf if subruns already exist in different sf."""