Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 101: do not change channel order #102

Merged
merged 4 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2023-08-10 Jan Kotanski <jankotan@gmail.com>
* dont change order of channels in the MG configuration (#101)
* tagged as v3.33.0

2023-08-08 Jan Kotanski <jankotan@gmail.com>
* set MasterTimerFirst to true (#99)
* tagged as v3.32.0
Expand Down
54 changes: 50 additions & 4 deletions nxsrecconfig/ProfileManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,6 @@ def __addPreselectedComponents(self, components):
if pdss != self.__selector["DataSourcePreselection"]:
self.__selector["DataSourcePreselection"] = pdss
changed = True
# print(changed)
return changed

def fetchProfile(self):
Expand Down Expand Up @@ -626,7 +625,9 @@ def __setFromMntGrpConf(self, jconf, compdatasources=None):
self.__updatePools()
conf = json.loads(jconf)
otimers = None
ochs = None
timers = {}
idch = {}

dsg = json.loads(self.__selector["DataSourceSelection"])
hel = set(json.loads(self.__selector["UnplottedComponents"]))
Expand All @@ -644,10 +645,11 @@ def __setFromMntGrpConf(self, jconf, compdatasources=None):
(not self.masterTimer or "timer" in conf.keys()):
avtimers = PoolUtils.getTimers(self.__pools, self.timerFilters)
tangods = self.__readChannels(
conf, timers, dsg, hel, synchronizer, synchronization)
conf, timers, dsg, hel, synchronizer, synchronization, idch)
self.__readTangoChannels(
conf, tangods, dsg, hel, synchronizer, synchronization)
otimers = self.__reorderTimers(conf, timers, dsg, hel, avtimers)
ochs = self.__reorderChannels(idch)

props["synchronizer"] = synchronizer
props["synchronization"] = synchronization
Expand All @@ -672,6 +674,11 @@ def __setFromMntGrpConf(self, jconf, compdatasources=None):
if self.__selector["Timer"] != jtimers:
self.__selector["Timer"] = jtimers
changed = True
if ochs is not None:
jochs = json.dumps(ochs)
if self.__selector["OrderedChannels"] != jochs:
self.__selector["OrderedChannels"] = jochs
changed = True
if self.__selector["MntGrp"] not in \
self.__configServer.availableSelections():
changed = True
Expand Down Expand Up @@ -705,7 +712,7 @@ def __clearChannels(self, dsg, hel, compdatasources=None):
hel.remove(ch)

def __readChannels(self, conf, timers, dsg, hel, synchronizer,
synchronization):
synchronization, idch=None):
""" reads channels from mntgrp configutation

:param conf: mntgrp configuration
Expand All @@ -721,6 +728,8 @@ def __readChannels(self, conf, timers, dsg, hel, synchronizer,
:param synchronization: channel synchronization,
i.e. Trigger=0, Gate=1, Start=2
:type synchronization: :obj:`dict` <:obj:`str`, :obj:`int`>
:param idch: index channels
:type idch: :obj:`dict` <:obj:`int`, :obj:`str`>
:returns: tango datasources list with elements (name, label, source)
:rtype: :obj:`list` < [:obj:`str` , :obj:`str` , :obj:`str` ] >
"""
Expand Down Expand Up @@ -748,6 +757,8 @@ def __readChannels(self, conf, timers, dsg, hel, synchronizer,
hel.add(ch['name'])
elif ch['name'] in hel:
hel.remove(ch['name'])
if idch is not None and 'index' in ch:
idch[int(ch["index"])] = ch['name']
if 'synchronizer' in ctrl \
and ctrl['synchronizer'].lower() != 'software':
synchronizer[ch['name']] = ctrl['synchronizer']
Expand All @@ -758,7 +769,7 @@ def __readChannels(self, conf, timers, dsg, hel, synchronizer,
return tangods

def __readTangoChannels(self, conf, tangods, dsg, hel, synchronizer,
synchronization):
synchronization, idch=None):
""" reads Tango channels from mntgrp configutation

:param conf: mntgrp configuration
Expand All @@ -772,6 +783,8 @@ def __readTangoChannels(self, conf, tangods, dsg, hel, synchronizer,
:type synchronizer: :obj:`dict` <:obj:`str`, :obj:`str`>
:param synchronization: channel synchronization, i.e. Trigger=0, Gate=1
:type synchronization: :obj:`dict` <:obj:`str`, :obj:`int`>
:param idch: index channels
:type idch: :obj:`dict` <:obj:`int`, :obj:`str`>
:param hel: list of hidden elements
:type hel: :obj:`list` <:obj:`str`>
"""
Expand All @@ -795,6 +808,8 @@ def __readTangoChannels(self, conf, tangods, dsg, hel, synchronizer,
hel.add(name)
elif ch['name'] in hel:
hel.remove(name)
if idch is not None and 'index' in ch:
idch[int(ch["index"])] = ch['name']
if 'synchronizer' in ctrl and \
ctrl['synchronizer'].lower() != 'software':
synchronizer[name] = \
Expand Down Expand Up @@ -839,6 +854,37 @@ def __reorderTimers(self, conf, timers, dsg, hel, avtimers=None):
hel.remove(tm)
return otimers

def __reorderChannels(self, idch):
""" reorder ordered channels

:param idch: index channels
:type idch: :obj:`dict` <:obj:`int`, :obj:`str`>
:returns: new orderedchannels
:rtype: :obj:`list` <:obj:`str`>
"""
lindex = -1
pchannels = None
if hasattr(idch, "items"):
pchs = json.loads(self.__selector["OrderedChannels"])
pchannels = []
for ch in pchs:
if ch not in pchannels:
pchannels.append(ch)
sidch = sorted(idch.items())
for ind, name in sidch:
if name not in pchannels:
lindex += 1
pchannels.insert(lindex, name)
else:
oind = pchannels.index(name)
if oind < lindex:
pchannels.pop(oind)
pchannels.insert(lindex, name)
else:
lindex = oind

return pchannels

def __checkClientRecords(self, datasources, description):
""" checks client records

Expand Down
2 changes: 1 addition & 1 deletion nxsrecconfig/Release.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
""" NeXus Sardana Recorder Settings - Release """

#: (:obj:`str`) package version
__version__ = "3.32.0"
__version__ = "3.33.0"
Loading
Loading