Commit 611af973 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[algorithm] Improved Dataformat parsing

This will allow to reuse the code in beat/beat.core.
parent f241a438
...@@ -431,6 +431,8 @@ class Algorithm(object): ...@@ -431,6 +431,8 @@ class Algorithm(object):
SEQUENTIAL_LOOP_USER = "sequential_loop_user" SEQUENTIAL_LOOP_USER = "sequential_loop_user"
AUTONOMOUS_LOOP_USER = "autonomous_loop_user" AUTONOMOUS_LOOP_USER = "autonomous_loop_user"
dataformat_klass = dataformat.DataFormat
def __init__(self, prefix, name, dataformat_cache=None, library_cache=None): def __init__(self, prefix, name, dataformat_cache=None, library_cache=None):
self._name = None self._name = None
...@@ -498,50 +500,40 @@ class Algorithm(object): ...@@ -498,50 +500,40 @@ class Algorithm(object):
if dataformat_cache and type_name in dataformat_cache: # reuse if dataformat_cache and type_name in dataformat_cache: # reuse
thisformat = dataformat_cache[type_name] thisformat = dataformat_cache[type_name]
else: # load it else: # load it
thisformat = dataformat.DataFormat(self.prefix, type_name) thisformat = self.dataformat_klass(self.prefix, type_name)
if dataformat_cache is not None: # update it if dataformat_cache is not None: # update it
dataformat_cache[type_name] = thisformat dataformat_cache[type_name] = thisformat
self.dataformats[type_name] = thisformat self.dataformats[type_name] = thisformat
return self.dataformats[type_name] return self.dataformats[type_name]
def _update_dataformat_cache_for_group(self, group, dataformat_cache):
for _, entry in group.items():
self._update_dataformat_cache(entry["type"], dataformat_cache)
def _load_dataformats(self, dataformat_cache): def _load_dataformats(self, dataformat_cache):
"""Makes sure we can load all requested formats """Makes sure we can load all requested formats
""" """
for group in self.groups: for group in self.groups:
self._update_dataformat_cache_for_group(group["inputs"], dataformat_cache)
for name, input_ in group["inputs"].items():
input_type = input_["type"]
self._update_dataformat_cache(input_type, dataformat_cache)
if "outputs" in group: if "outputs" in group:
for name, output in group["outputs"].items(): self._update_dataformat_cache_for_group(
output_type = output["type"] group["outputs"], dataformat_cache
self._update_dataformat_cache(output_type, dataformat_cache) )
if "loop" in group: if "loop" in group:
for name, entry in group["loop"].items(): self._update_dataformat_cache_for_group(group["loop"], dataformat_cache)
entry_format = entry["type"]
self._update_dataformat_cache(entry_format, dataformat_cache)
if self.results: if self.results:
for name, result in self.results.items(): for name, result in self.results.items():
result_type = result["type"]
if result["type"].find("/") != -1: # results can only contain base types and plots therefore, only
# process plots
if result["type"] in self.dataformats: if result_type.find("/") != -1:
continue self._update_dataformat_cache(result_type, dataformat_cache)
if dataformat_cache and result["type"] in dataformat_cache: # reuse
thisformat = dataformat_cache[result["type"]]
else:
thisformat = dataformat.DataFormat(self.prefix, result["type"])
if dataformat_cache is not None: # update it
dataformat_cache[result["type"]] = thisformat
self.dataformats[result["type"]] = thisformat
def _convert_parameter_types(self): def _convert_parameter_types(self):
"""Converts types to numpy equivalents, checks defaults, ranges and choices """Converts types to numpy equivalents, checks defaults, ranges and choices
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment