From c6138b4b73bd73744615713b8ddad319d0d16337 Mon Sep 17 00:00:00 2001 From: Sven Augustin Date: Sat, 3 Jun 2023 13:12:30 +0200 Subject: [PATCH] added option the create several channels at once --- bstrd/bscache.py | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/bstrd/bscache.py b/bstrd/bscache.py index 441d9aa..96b1268 100644 --- a/bstrd/bscache.py +++ b/bstrd/bscache.py @@ -45,6 +45,38 @@ class BSCache: self.pt.stop() + def get_vars(self, names): + if not isinstance(names, dict): + names = {n: {} for n in names} + + new_chans = {} + for name, kwargs in names.items(): + if name not in ["pid", "toc"] and name not in self.channels: + if not is_available(name): + raise ValueError(f"channel {name} is not available") + cfg = make_channel_config(name, *kwargs) + new_chans[name] = cfg + + self.update_source_multiple(new_chans) + return {n: BSVar(n, self) for n in names} + + + def update_source_multiple(self, chans): + self.pt.stop() + print("add channels", sorted(chans)) + self.channels.update(chans) + self.pt.start() + + while self.data is None: + print("dropping empty data") + next(self) + + while not chans.keys() <= self.data.keys(): + missing = self.data.keys() - chans.keys() - {"pid", "toc"} + print("dropping data that is missing new channel(s)", sorted(missing)) + next(self) + + def get_var(self, name, modulo=None, offset=None): if name not in ["pid", "toc"] and name not in self.channels: if not is_available(name): @@ -80,7 +112,7 @@ def get_available_channels(): -def make_channel_config(name, modulo, offset): +def make_channel_config(name, modulo=None, offset=None): res = {} if modulo is not None: res["modulo"] = modulo