diff --git a/strax/context.py b/strax/context.py index 8747c1a28..20955f38c 100644 --- a/strax/context.py +++ b/strax/context.py @@ -1404,14 +1404,19 @@ def _apply_function(self, data, targets): data = function(data, targets) return data - def copy_to_frontend(self, run_id, target, - target_frontend_id=None, rechunk=False): + def copy_to_frontend(self, + run_id: str, + target: str, + target_frontend_id: ty.Optional[int] = None, + target_compressor: ty.Optional[str] = None, + rechunk: bool = False): """ Copy data from one frontend to another :param run_id: run_id :param target: target datakind :param target_frontend_id: index of the frontend that the data should go to - in context.storage. If no index is specified, try all. + in context.storage. If no index is specified, try all. + :param target_compressor: if specified, recompress with this compressor. :param rechunk: allow re-chunking for saving """ if not self.is_stored(run_id, target): @@ -1440,7 +1445,7 @@ def copy_to_frontend(self, run_id, target, (not self._is_stored_in_sf(run_id, target, t_sf) and t_sf._we_take(target) and t_sf.readonly is False)] - + self.log.info(f'Copy data from {source_sf} to {target_sf}') if not len(target_sf): raise ValueError('No frontend to copy to! Perhaps you already stored ' 'it or none of the frontends is willing to take it?') @@ -1453,6 +1458,11 @@ def copy_to_frontend(self, run_id, target, s_be = source_sf._get_backend(s_be_str) md = s_be.get_metadata(s_be_key) + if target_compressor is not None: + self.log.info(f'Changing compressor from {md["compressor"]} ' + f'to {target_compressor}.') + md.update({'compressor': target_compressor}) + for t_sf in target_sf: try: # Need to load a new loader each time since it's a generator