Skip to content

Commit

Permalink
Issue 699: improve findAttribute by adding moduleAttributeMap (#700)
Browse files Browse the repository at this point in the history
* improve findAttribute by adding moduleAttributeMap

* add tests

* apply pep8

* update manpages
  • Loading branch information
jkotan authored Jul 19, 2024
1 parent 62f0e45 commit 879d60a
Show file tree
Hide file tree
Showing 12 changed files with 165 additions and 10 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2024-07-19 Jan Kotanski <jankotan@gmail.com>
* improve findAttribute by adding moduleAttributeMap (#696)
* tagged as v4.13.0

2024-07-15 Jan Kotanski <jankotan@gmail.com>
* create output dir is does not exists (#696)
* fix ScanFileinScanNameDir name to ScanNames (#694)
Expand Down
2 changes: 1 addition & 1 deletion man/nxscollect.1
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
..
.TH "NXSCOLLECT" "1" "Jul 16, 2024" "4.12" "NXSTools"
.TH "NXSCOLLECT" "1" "Jul 18, 2024" "4.13" "NXSTools"
.SH NAME
nxscollect \- upload external images into NeXus/HDF5 file
.SH DESCRIPTION
Expand Down
2 changes: 1 addition & 1 deletion man/nxsconfig.1
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
..
.TH "NXSCONFIG" "1" "Jul 16, 2024" "4.12" "NXSTools"
.TH "NXSCONFIG" "1" "Jul 18, 2024" "4.13" "NXSTools"
.SH NAME
nxsconfig \- read NeXus Configuration Server settings
.SH DESCRIPTION
Expand Down
2 changes: 1 addition & 1 deletion man/nxscreate.1
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
..
.TH "NXSCREATE" "1" "Jul 16, 2024" "4.12" "NXSTools"
.TH "NXSCREATE" "1" "Jul 18, 2024" "4.13" "NXSTools"
.SH NAME
nxscreate \- create NeXus Configuration component
.SH DESCRIPTION
Expand Down
2 changes: 1 addition & 1 deletion man/nxsdata.1
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
..
.TH "NXSDATA" "1" "Jul 16, 2024" "4.12" "NXSTools"
.TH "NXSDATA" "1" "Jul 18, 2024" "4.13" "NXSTools"
.SH NAME
nxsdata \- run NeXus Data Writer
.SH DESCRIPTION
Expand Down
2 changes: 1 addition & 1 deletion man/nxsetup.1
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
..
.TH "NXSETUP" "1" "Jul 16, 2024" "4.12" "NXSTools"
.TH "NXSETUP" "1" "Jul 18, 2024" "4.13" "NXSTools"
.SH NAME
nxsetup \- set NeXDaTaS Tango Server environment up
.SH DESCRIPTION
Expand Down
2 changes: 1 addition & 1 deletion man/nxsfileinfo.1
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
..
.TH "NXSFILEINFO" "1" "Jul 16, 2024" "4.12" "NXSTools"
.TH "NXSFILEINFO" "1" "Jul 18, 2024" "4.13" "NXSTools"
.SH NAME
nxsfileinfo \- show metadata of the NeXus file
.SH DESCRIPTION
Expand Down
2 changes: 1 addition & 1 deletion man/nxstools.1
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
..
.TH "NXSTOOLS" "1" "Jul 16, 2024" "4.12" "NXSTools"
.TH "NXSTOOLS" "1" "Jul 18, 2024" "4.13" "NXSTools"
.SH NAME
nxstools \- nxstools Documentation
.sp
Expand Down
8 changes: 6 additions & 2 deletions nxstools/nxscreator.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

from nxstools.nxsdevicetools import (
storeDataSource, getDataSourceComponents, storeComponent,
moduleAttributes, motorModules,
moduleAttributes, moduleAttributeMap, motorModules,
generateDeviceNames, getServerTangoHost,
openServer, findClassName,
xmlPackageHandler)
Expand Down Expand Up @@ -265,9 +265,13 @@ def findAttribute(self, tangohost, clientlike=False):
self.attribute = None
spdevice = self.tdevice.split("/")
if mhost and len(spdevice) > 3:
self.attribute = spdevice[3]
self.tdevice = "/".join(spdevice[0:3])
self.hostname = mhost
if self.module in moduleAttributeMap.keys() and \
spdevice[3] in moduleAttributeMap[self.module].keys():
self.attribute = moduleAttributeMap[self.module][spdevice[3]]
else:
self.attribute = spdevice[3]
if self.module in motorModules or self.dtype == 'stepping_motor':
if self.attribute is None:
self.attribute = 'Position'
Expand Down
14 changes: 14 additions & 0 deletions nxstools/nxsdevicetools.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,20 @@ def loadXMLTemplates(self, packagename):
'xmcd': ['Value', None],
}

#: attributes of device modules to acquire with elements:
# 'module': {<device_parts[4]>, <tango_attr>}
moduleAttributeMap = {
'amptekroi': {
'1': 'CountsRoI1',
'2': 'CountsRoI2',
'3': 'CountsRoI3',
'4': 'CountsRoI4',
'5': 'CountsRoI5',
'6': 'CountsRoI6',
'7': 'CountsRoI7',
'8': 'CountsRoI8',
},
}

#: (:obj:`list` <:obj:`str`>) modules of 2d detectors
twoDModules = [
Expand Down
2 changes: 1 addition & 1 deletion nxstools/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
""" NXS tools release version"""

#: (:obj:`str`) package version
__version__ = "4.12.0"
__version__ = "4.13.0"
133 changes: 133 additions & 0 deletions test/NXSCreateOnlineDSFS_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,139 @@ def test_onlineds_stepping_motor(self):
if self.dsexists(ds):
self.deleteds(ds)

def test_onlineds_amptekroi(self):
""" test nxsccreate onlineds file system
"""
fun = sys._getframe().f_code.co_name
print("Run: %s.%s() " % (self.__class__.__name__, fun))

fname = '%s/%s%s.xml' % (
os.getcwd(), self.__class__.__name__, fun)

xml = """<?xml version="1.0"?>
<hw>
<device>
<name>amptek_roi1</name>
<type>counter</type>
<module>amptekroi</module>
<device>p03/amptekpx5/exp.01/1</device>
<control>tango</control>
<hostname>haso000:10000</hostname>
</device>
<device>
<name>amptek_roi2</name>
<type>counter</type>
<module>amptekroi</module>
<device>p03/amptekpx5/exp.01/2</device>
<control>tango</control>
<hostname>haso000:10000</hostname>
</device>
<device>
<name>amptek_roi3</name>
<type>counter</type>
<module>amptekroi</module>
<device>p03/amptekpx5/exp.01/3</device>
<control>tango</control>
<hostname>haso000:10000</hostname>
</device>
<device>
<name>amptek_roi4</name>
<type>counter</type>
<module>amptekroi</module>
<device>p03/amptekpx5/exp.01/4</device>
<control>tango</control>
<hostname>haso000:10000</hostname>
</device>
</hw>
"""

args = [
[
('nxscreate onlineds %s %s'
% (fname, self.flags)).split(),
['amptek_roi1',
'amptek_roi2',
'amptek_roi3',
'amptek_roi4'],
[
'<?xml version=\'1.0\' encoding=\'utf8\'?>\n'
'<definition>\n'
' <datasource type="TANGO" name="amptek_roi1">\n'
' <device name="p03/amptekpx5/exp.01"'
' member="attribute" hostname="haso000" '
'port="10000"/>\n'
' <record name="CountsRoI1"/>\n'
' </datasource>\n'
'</definition>\n',
'<?xml version=\'1.0\' encoding=\'utf8\'?>\n'
'<definition>\n'
' <datasource type="TANGO" name="amptek_roi2">\n'
' <device name="p03/amptekpx5/exp.01"'
' member="attribute" hostname="haso000" '
'port="10000"/>\n'
' <record name="CountsRoI2"/>\n'
' </datasource>\n'
'</definition>\n',
'<?xml version=\'1.0\' encoding=\'utf8\'?>\n'
'<definition>\n'
' <datasource type="TANGO" name="amptek_roi3">\n'
' <device name="p03/amptekpx5/exp.01"'
' member="attribute" hostname="haso000" '
'port="10000"/>\n'
' <record name="CountsRoI3"/>\n'
' </datasource>\n'
'</definition>\n',
'<?xml version=\'1.0\' encoding=\'utf8\'?>\n'
'<definition>\n'
' <datasource type="TANGO" name="amptek_roi4">\n'
' <device name="p03/amptekpx5/exp.01"'
' member="attribute" hostname="haso000" '
'port="10000"/>\n'
' <record name="CountsRoI4"/>\n'
' </datasource>\n'
'</definition>\n',
],
],
]

totest = []
if os.path.isfile(fname):
raise Exception("Test file %s exists" % fname)
with open(fname, "w") as fl:
fl.write(xml)
try:
for arg in args:
skip = False
for ds in arg[1]:
if self.dsexists(ds):
skip = True
if not skip:
for ds in arg[1]:
totest.append(ds)

vl, er = self.runtest(arg[0])

if er:
self.assertTrue(er.startswith(
"Info"))
else:
self.assertEqual('', er)
self.assertTrue(vl)

for i, ds in enumerate(arg[1]):
xml = self.getds(ds)
self.assertEqual(
arg[2][i], xml)

for ds in arg[1]:
self.deleteds(ds)
finally:
os.remove(fname)
for ds in totest:
if self.dsexists(ds):
self.deleteds(ds)

def test_onlineds_stepping_motor_noclientlike(self):
""" test nxsccreate onlineds file system
"""
Expand Down

0 comments on commit 879d60a

Please sign in to comment.