added option the create several channels at once
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user