made detectors more flexible (allow: one dict or list of strings and/or dicts)

This commit is contained in:
2021-03-09 13:57:08 +01:00
parent 9b0c8e21b2
commit 54bad0d5d9
+32 -2
View File
@@ -130,8 +130,7 @@ class BrokerConfig:
detectors = self.detectors
if detectors:
if isinstance(detectors, list):
detectors = {d: {} for d in detectors} # currently the dicts are empty, thus allow giving just a list as argument
detectors = flatten_detectors(detectors)
config["detectors"] = detectors
if self.channels:
@@ -164,6 +163,37 @@ def split_channels(channels):
def flatten_detectors(dets):
if isinstance(dets, dict):
return harmonize_detector_dict(dets)
if isinstance(dets, (list, tuple)):
res = {}
for d in dets:
if isinstance(d, dict):
d = harmonize_detector_dict(d)
res.update(d)
elif isinstance(d, str):
res[d] = {} # defaults via empty dict
else:
raise ValueError(f"Cannot interpret \"{d}\" as detector")
return res
raise ValueError(f"Cannot interpret \"{dets}\" as detector(s)")
def harmonize_detector_dict(d):
if "name" in d:
name = d["name"]
d = {
name: {
k: v for k, v in d.items() if k != "name"
}
}
return d
def aligned_pids(start, n, rm):
"""
return start/stop pids aligned to rep rate