Commit 13596f96 authored by Matias Guijarro's avatar Matias Guijarro

Merge branch 'SetParameters_new' into 'master'

Set parameters new

See merge request !27
parents e6c21c0a 29d181bf
......@@ -156,11 +156,20 @@ class MetadataManager (tango.LatestDeviceImpl):
self.dataRootEventId = None
self.dataRoot = ''
self.datasetParentLocation = ''
self.datasetParamMap = dict()
# Priority of dataset metadata keys
# (highest number is highest priority)
# 1. parameters(local): from attributes of this device
# 2. labels: from device property
# 3. parameters(local): from attributes of other devices
# 4. custom: added with SetParameters
# 5. sample:
# 6. globals: proposal, beamline, etc.
self.datasetParamMap = dict() # priority (local:1, remote:3)
self.parameterDefinitionMap = dict()
self.sampleParamMap = dict()
self.attributeProxyMap = dict()
self.labels_map = dict()
self.labels_map = dict() # priority (2)
self.customParamMap = dict() # priority (4)
self.sampleParamMap = dict() # priority (5)
self.attr_datafileList_read = []
self.attr_datasetNameList_read = []
self.msgList = deque(maxlen=20)
......@@ -351,8 +360,6 @@ class MetadataManager (tango.LatestDeviceImpl):
reader = ICATParameterReader(self.get_name(), self.authenticationPlugin, self.username, self.password, self.server, self.port)
return str(reader.compare(self.parameters, self.labels))
# returns the sample parameters set by the SetSampleParameters command as key value pairs
# the list is dynamically created on each call
# returns "None" if list is empty
......@@ -511,8 +518,6 @@ class MetadataManager (tango.LatestDeviceImpl):
tomo = tomodbFile(self.attr_proposal_read, self.beamlineID.lower(), argin)
self.client.sendObject(tomo)
#----- PROTECTED REGION END -----# // MetadataManager.IngestTomodbXML
def is_IngestTomodbXML_allowed(self):
self.debug("In is_IngestTomodbXML_allowed()")
......@@ -587,6 +592,7 @@ class MetadataManager (tango.LatestDeviceImpl):
for datasetParam in self.datasetParamMap:
self.datasetParamMap[datasetParam] = ''
self.customParamMap = dict()
except:
traceback.print_exc(file=sys.stdout)
......@@ -678,7 +684,6 @@ class MetadataManager (tango.LatestDeviceImpl):
sys.excepthook(*sys.exc_info())
pass
def notifyInfo(self, message):
self.sendNotification("notification", "info", message)
......@@ -832,11 +837,29 @@ class MetadataManager (tango.LatestDeviceImpl):
traceback.print_exc(file=sys.stdout)
self.warn_stream("Error retrieving poll value: %s" %e)
beat = 0
def SetParameters(self, json_string):
"""This will overwrite ICAT key-value pairs defined
by the "parameters" and "labels" device properties,
but not the sample parameters.
"""
self.customParamMap = json.loads(json_string)
original = set(self.parameters) | set(self.labels)
new = set(self.customParamMap.keys())
overwritten = len(original & new)
original = len(original) + len(self.sampleParamMap) - overwritten
new = len(new) - overwritten
self.info(f"Add parameters ({new} new, {overwritten} overwritten, {original} original)")
# Gets the parameters defined on the parameters list in the tango device
# Return List<Parameter>
def getParameters(self):
"""Remote and custom parameters.
:returns list(parameter):
"""
try:
notallowed = self.notallowed_parameters
parameters = []
# add the linked parameters (need to get the value)
# async reads of every proxy
......@@ -861,17 +884,35 @@ class MetadataManager (tango.LatestDeviceImpl):
for n, d in self.parameterDefinitionMap.items():
if d.isRemote():
v = d.buildValue(self.attributeProxyMap, values)
if v:
if v and n not in notallowed:
parameters.append(parameter(n, v))
except:
traceback.print_exc(file=sys.stdout)
#return dts
traceback.print_exc(file=sys.stdout)
notallowed = self.notallowed_custom
parameters += list(parameter(n, v) for n, v in self.customParamMap.items()
if n not in notallowed)
return parameters
@property
def notallowed_parameters(self):
return set(self.labels_map.keys()) | set(self.customParamMap.keys()) | set(self.sampleParamMap.keys())
@property
def notallowed_labels(self):
return set(self.customParamMap.keys()) | set(self.sampleParamMap.keys())
@property
def notallowed_custom(self):
return set(self.sampleParamMap.keys())
def CreateDataset(self, complete=True):
# Avoid name collisions:
notallowed = self.notallowed_parameters
datasetParamMap = {k:v for k,v in self.datasetParamMap.items()
if k not in notallowed}
notallowed = self.notallowed_labels
labels_map = {k:v for k,v in self.labels_map.items()
if k not in notallowed}
return self.metadataWorker.createDataset(
complete,
self.attr_proposal_read,
......@@ -880,8 +921,8 @@ class MetadataManager (tango.LatestDeviceImpl):
self.attr_dataFolder_read,
self.startDate,
self.endDate,
self.labels_map,
self.datasetParamMap,
labels_map,
datasetParamMap,
self.attr_sampleName_read,
self.sampleParamMap,
self.attr_datafileList_read)
......@@ -1146,8 +1187,11 @@ class MetadataManagerClass(tango.DeviceClass):
[tango.DevVoid, "none"]],
'userComment':
[[tango.DevString, "Message"],
[tango.DevVoid, "none"]]
[tango.DevVoid, "none"]],
"SetParameters": [
[tango.DevString, "JSON-representation of a parameter dictionary (overwrites)"],
[tango.DevVoid, "none"],
],
}
# Attribute definitions
......
......@@ -102,6 +102,13 @@ class MetadataWorker():
def toDictionary(self, dataset, sampleParamMap, initial=None):
d = dict()
# add parameters and labels
for p in dataset.get_parameter():
d[p.get_name()] = p.get_value()
# add parameters from sample
for key in sampleParamMap:
d[key] = sampleParamMap[key]
# add main proposal/sample/dataset parameters
d['proposal'] = dataset.get_investigation()
d['beamlineID'] = dataset.get_instrument()
d['datasetName'] = dataset.get_name()
......@@ -109,13 +116,6 @@ class MetadataWorker():
d['startDate'] = dataset.get_startDate()
d['endDate'] = dataset.get_endDate()
d['sampleName'] = dataset.get_sample().get_name()
for p in dataset.get_parameter():
d[p.get_name()] = p.get_value()
# add parameters from sample
for key in sampleParamMap:
d[key] = sampleParamMap[key]
return d
def addParametersToDataSet(self, dataset, parameters):
......
Markdown is supported
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