Skip to content
Snippets Groups Projects
Commit 778a5362 authored by Lauri Himanen's avatar Lauri Himanen
Browse files

Some renamings in CacheService, better warnings when trying to use the wrong...

Some renamings in CacheService, better warnings when trying to use the wrong backend function for arrays.
parent 5fac7db8
Branches
Tags
No related merge requests found
......@@ -272,11 +272,11 @@ class RegexService(object):
Stores basic regex definitions that can be reused on multiple parsers.
"""
def __init__(self):
self.regex_f = "-?\d+\.\d+(?:E(?:\+|-)\d+)?" # Regex for a floating point value
self.regex_i = "-?\d+" # Regex for an integer
self.regex_word = "[\S]+" # Regex for a single word. Can contain anything else but whitespace
self.regex_letter = "[^\W\d_]" # Regex for a single alphabetical letter
self.regex_eol = "[^\n]+" # Regex for a single alphabetical letter
self.float = "-?\d+\.\d+(?:E(?:\+|-)\d+)?" # Regex for a floating point value
self.int = "-?\d+" # Regex for an integer
self.word = "[\S]+" # Regex for a single word. Can contain anything else but whitespace
self.letter = "[^\W\d_]" # Regex for a single alphabetical letter
self.eol = "[^\n]+" # Regex for a single alphabetical letter
#===============================================================================
......@@ -580,43 +580,56 @@ class CacheService(object):
if cache_object.update:
if not cache_object._updated:
raise LookupError("Could not push value '{}' to backend because it was not updated since last push.".format(cache_object.name))
# logger.warning("Could not push value '{}' to backend because it was not updated since last push.".format(cache_object.name))
return False
return True
def push_value(self, name, metaname=None):
"""Pushes the scalar value stored with the given name to the backend.
If the name cannot be found, nothing is pushed. If the metaname
property is not defined the value is pushed with the name that was used
as key.
def addValue(self, metaname, name=None):
"""Pushes the value stored in the cache with the given name to
the backend.
If the name cannot be found in the dictionary, or the value associated
with the name is None, nothing is pushed. This allows one to use the
cache with a simple syntax without having to worry about the actual
availability of the data.
If the metaname property is not defined the value is pushed with the
name that was used as key.
"""
if name is None:
name = metaname
cache_object = self.get_cache_object(name)
if cache_object is None or cache_object._value is None:
logger.warning("The value for metaname '{}' was not set in the CacheService, and could not be pushed".format(name))
return
if self.check_push_allowed(cache_object):
if metaname is None:
metaname = name
self.backend.addValue(metaname, cache_object.value)
cache_object._pushed = True
cache_object._updated = False
def push_real_value(self, name, unit=None, metaname=None):
"""Pushes the scalar value stored with the given name to the backend.
If the name cannot be found, nothing is pushed. If the metaname
property is not defined the value is pushed with the name that was used
as key.
def addRealValue(self, metaname, name=None, unit=None):
"""Pushes the real value stored in the cache with the given name to
the backend. A unit conversion will be made if units are specified.
If the name cannot be found in the dictionary, or the value associated
with the name is None, nothing is pushed. This allows one to use the
cache with a simple syntax without having to worry about the actual
availability of the data.
If the metaname property is not defined the value is pushed with the
name that was used as key.
"""
if name is None:
name = metaname
cache_object = self.get_cache_object(name)
if cache_object is None or cache_object._value is None:
logger.warning("The value for metaname '{}' was not set in the CacheService, and could not be pushed".format(name))
return
if self.check_push_allowed(cache_object):
if metaname is None:
metaname = name
if cache_object.value is not None:
self.backend.addRealValue(metaname, cache_object.value, unit=unit)
......@@ -625,20 +638,27 @@ class CacheService(object):
else:
logger.warning("The value for metaname '{}' was not set in the CacheService, and could not be pushed".format(name))
def push_array_values(self, name, unit=None, metaname=None):
"""Pushes the scalar value stored with the given name to the backend.
If the name cannot be found, nothing is pushed. If the metaname
property is not defined the value is pushed with the name that was used
as key.
def addArrayValues(self, metaname, name=None, unit=None):
"""Pushes the array value stored in the cache with the given name to
the backend. A unit conversion will be made if units are specified.
If the name cannot be found in the dictionary, or the value associated
with the name is None, nothing is pushed. This allows one to use the
cache with a simple syntax without having to worry about the actual
availability of the data.
If the metaname property is not defined the value is pushed with the
name that was used as key.
"""
if name is None:
name = metaname
cache_object = self.get_cache_object(name)
if cache_object is None or cache_object._value is None:
logger.warning("The value for metaname '{}' was not set in the CacheService, and could not be pushed".format(name))
return
if self.check_push_allowed(cache_object):
if metaname is None:
metaname = name
if cache_object.value is not None:
self.backend.addArrayValues(metaname, np.array(cache_object.value), unit=unit)
......
......@@ -86,7 +86,7 @@ class LocalBackend(object):
# Check that the value is actually of scalar type
value_type = type(value)
if value_type not in [float, int, bool, type(b""), type(u""), str, np.float64]:
raise TypeError("The value '{}' with type '{}' for metainfo '{}' is not of scalar nature.".format(value, value_type, metaName))
raise TypeError("Could not use function 'addValue' to push value '{}' with type '{}' for metainfo '{}'.".format(value, value_type, metaName))
# Check that the metainfo should be scalar
metainfo_shape = dataManager.metaInfo.shape
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment