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):
SEQUENTIAL_LOOP_USER = "sequential_loop_user"
AUTONOMOUS_LOOP_USER = "autonomous_loop_user"
dataformat_klass = dataformat.DataFormat
def __init__(self, prefix, name, dataformat_cache=None, library_cache=None):
self._name = None
......@@ -498,50 +500,40 @@ class Algorithm(object):
if dataformat_cache and type_name in dataformat_cache: # reuse
thisformat = dataformat_cache[type_name]
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
dataformat_cache[type_name] = thisformat
self.dataformats[type_name] = thisformat
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):
"""Makes sure we can load all requested formats
for group in self.groups:
for name, input_ in group["inputs"].items():
input_type = input_["type"]
self._update_dataformat_cache(input_type, dataformat_cache)
self._update_dataformat_cache_for_group(group["inputs"], dataformat_cache)
if "outputs" in group:
for name, output in group["outputs"].items():
output_type = output["type"]
self._update_dataformat_cache(output_type, dataformat_cache)
group["outputs"], dataformat_cache
if "loop" in group:
for name, entry in group["loop"].items():
entry_format = entry["type"]
self._update_dataformat_cache(entry_format, dataformat_cache)
self._update_dataformat_cache_for_group(group["loop"], dataformat_cache)
if self.results:
for name, result in self.results.items():
if result["type"].find("/") != -1:
if result["type"] in self.dataformats:
if dataformat_cache and result["type"] in dataformat_cache: # reuse
thisformat = dataformat_cache[result["type"]]
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
result_type = result["type"]
# results can only contain base types and plots therefore, only
# process plots
if result_type.find("/") != -1:
self._update_dataformat_cache(result_type, dataformat_cache)
def _convert_parameter_types(self):
"""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