Skip to content
Snippets Groups Projects
Commit 44c49345 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[algorithm] Improve dataformat loading code

This reduces code duplication and will also
help clean up beat/beat.core> a bit.
parent 8aca5dd6
No related branches found
No related tags found
1 merge request!54Implement loop output
......@@ -491,53 +491,39 @@ class Algorithm(object):
self._convert_parameter_types()
self._load_libraries(library_cache)
def _update_dataformat_cache(self, type_name, dataformat_cache):
"""Update the data format cache based on the type name"""
if type_name not in self.dataformats:
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)
if dataformat_cache is not None: # update it
dataformat_cache[type_name] = thisformat
self.dataformats[type_name] = thisformat
return self.dataformats[type_name]
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():
if input["type"] in self.dataformats:
continue
if dataformat_cache and input["type"] in dataformat_cache: # reuse
thisformat = dataformat_cache[input["type"]]
else: # load it
thisformat = dataformat.DataFormat(self.prefix, input["type"])
if dataformat_cache is not None: # update it
dataformat_cache[input["type"]] = thisformat
self.dataformats[input["type"]] = thisformat
for name, input_ in group["inputs"].items():
input_type = input_["type"]
self._update_dataformat_cache(input_type, dataformat_cache)
if "outputs" in group:
for name, output in group["outputs"].items():
if output["type"] in self.dataformats:
continue
if dataformat_cache and output["type"] in dataformat_cache: # reuse
thisformat = dataformat_cache[output["type"]]
else: # load it
thisformat = dataformat.DataFormat(self.prefix, output["type"])
if dataformat_cache is not None: # update it
dataformat_cache[output["type"]] = thisformat
self.dataformats[output["type"]] = thisformat
output_type = output["type"]
self._update_dataformat_cache(output_type, dataformat_cache)
if "loop" in group:
for name, entry in group["loop"].items():
entry_format = entry["type"]
if entry_format in self.dataformats:
continue
if dataformat_cache and entry_format in dataformat_cache:
thisformat = dataformat_cache[entry_format]
else:
thisformat = dataformat.DataFormat(self.prefix, entry_format)
if dataformat_cache is not None:
dataformat_cache[entry_format] = thisformat
self.dataformats[entry_format] = thisformat
self._update_dataformat_cache(entry_format, dataformat_cache)
if self.results:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment