Skip to content

Commit

Permalink
Issue 96: add pilc component template (#661)
Browse files Browse the repository at this point in the history
* add pilc component template

* improve pilc template

* pilctimeid

* update tests

* remove arm from templates

* fixes for pilc links

* update Changelog
  • Loading branch information
jkotan authored Jul 2, 2024
1 parent 9ebe3f8 commit caf91ea
Show file tree
Hide file tree
Showing 16 changed files with 389 additions and 21 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2024-07-02 Jan Kotanski <jankotan@gmail.com>
* add pilc component template (#661)
* tagged as v4.6.0

2024-06-27 Jan Kotanski <jankotan@gmail.com>
* improve fix for enlarge waiting time for the server in nxsetup (#659)
* tagged as v4.5.1
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" "Jun 27, 2024" "4.5" "NXSTools"
.TH "NXSCOLLECT" "1" "Jul 02, 2024" "4.6" "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" "Jun 27, 2024" "4.5" "NXSTools"
.TH "NXSCONFIG" "1" "Jul 02, 2024" "4.6" "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" "Jun 27, 2024" "4.5" "NXSTools"
.TH "NXSCREATE" "1" "Jul 02, 2024" "4.6" "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" "Jun 27, 2024" "4.5" "NXSTools"
.TH "NXSDATA" "1" "Jul 02, 2024" "4.6" "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" "Jun 27, 2024" "4.5" "NXSTools"
.TH "NXSETUP" "1" "Jul 02, 2024" "4.6" "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" "Jun 27, 2024" "4.5" "NXSTools"
.TH "NXSFILEINFO" "1" "Jul 02, 2024" "4.6" "NXSTools"
.SH NAME
nxsfileinfo \- show metadata of the NeXus file
.SH DESCRIPTION
Expand Down
14 changes: 7 additions & 7 deletions man/nxstools.1

Large diffs are not rendered by default.

155 changes: 155 additions & 0 deletions nxstools/pyeval/pilc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
#!/usr/bin/env python
# This file is part of nexdatas - Tango Server for NeXus data writer
#
# Copyright (C) 2012-2018 DESY, Jan Kotanski <jkotan@mail.desy.de>
#
# nexdatas is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# nexdatas is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with nexdatas. If not, see <http://www.gnu.org/licenses/>.
#

""" pyeval helper functions for pilc """

# import json
try:
import tango
except Exception:
import PyTango as tango


def triggermode_cb(commonblock, name, triggermode,
nbtriggers, triggersperfile,
hostname, device,
filename, entryname,
insname, pilcfileprefix, pilcfiledir,
timeid=False):
""" code for triggermode_cb datasource
:param commonblock: commonblock of nxswriter
:type commonblock: :obj:`dict`<:obj:`str`, `any`>
:param name: component name
:type name: :obj:`str`
:param triggermode: trigger mode
:type triggermode: :obj:`int` or :obj:`str`
:param nbtriggers: a number of triggers
:type nbtriggers: :obj:`int`
:param triggersperfile: a number of triggers per file
:type triggersperfile: :obj:`int`
:param hostname: tango host name
:type hostname: :obj:`str`
:param device: tango device name
:type device: :obj:`str`
:param filename: master file name
:type filename: :obj:`str`
:param entryname: entry name
:type entryname: :obj:`str`
:param insname: instrument name
:type insname: :obj:`str`
:param pilcfileprefix: pilc file name prefix
:type pilcfileprefix :obj:`str`
:param pilcfiledir: pilc file name directory
:type pilcfiledir :obj:`str`
:param timeid: file id with timestamp
:type timeid: :obj:`bool`
:returns: triggermode
:rtype: :obj:`str` or :obj:`int`
"""

dp = tango.DeviceProxy('%s/%s' % (hostname, device))
fpattern = pilcfileprefix.split("/")[-1]
if triggersperfile >= 1:
nbfiles = (nbtriggers + triggersperfile - 1) // triggersperfile
else:
nbfiles = 1
fields = ["counter", "time", "trigger",
"encoder_1", "encoder_2",
"encoder_3", "encoder_4", "encoder_5"]
nbstart = 0
filepostfix = ".nxs"
try:
pilcfilename = str(dp.FileName)
if pilcfilename.startswith(fpattern + "_") and \
pilcfilename.endswith(filepostfix):
nblast = int(pilcfilename[
len(fpattern) + 1: - len(filepostfix)])
nbstart = max(0, nblast - nbfiles + 1)
except Exception:
pilcfilename = None
nblist = [nb for nb in range(nbstart, nbstart + nbfiles)]

if filename:
path = (filename).split("/")[-1].split(".")[0] + "/"
else:
path = ""
path += '%s/%s_' % (name, fpattern)
result = triggermode

spf = 0
cfid = 0
if "__root__" in commonblock.keys():
root = commonblock["__root__"]
if hasattr(root, "currentfileid") and hasattr(root, "stepsperfile"):
spf = root.stepsperfile
cfid = root.currentfileid
if root.h5object.__class__.__name__ == "File":
import nxstools.h5pywriter as nxw
else:
import nxstools.h5cppwriter as nxw
else:
raise Exception("Writer cannot be found")

en = root.open(entryname)
dt = en.open("data")
ins = en.open(insname)
pilc = ins.open(name)
pilcdata = pilc.open("data")
col = pilc.open("collection")

if timeid and pilcfilename and "filenames" in col.names():
try:
filenames = list(col.open("filenames").read())
if filenames:
filenames.append(str(pilcfilename))
nlist = []
for fname in filenames:
fname = str(fname)
if fname.startswith(fpattern + "_") and \
fname.endswith(filepostfix):
nlist.append(int(fname[
len(fpattern) + 1: - len(filepostfix)]))
nblist = nlist
except Exception:
pass
for nbf in nblist:
# nnbf = "%05i" % (nbf)
for field in fields:
fnbf = "%s_%05i" % (field, nbf)
if spf > 0 and cfid > 0:
if cfid == nbf:
nxw.link(
"%s_%05i%s://entry/data/%s"
% (path, nbf, filepostfix, field),
pilcdata, field)
nxw.link("/%s/%s/%s/data/%s"
% (entryname, insname, name, field),
dt, "%s_%s" % (name, field))
nxw.link("%s_%05i%s://entry/data/%s"
% (path, nbf, filepostfix, field),
pilcdata, "%s" % (fnbf))
else:
nxw.link("%s_%05i%s://entry/data/%s"
% (path, nbf, filepostfix, field),
pilcdata, "%s" % (fnbf))
nxw.link("/%s/%s/%s/data/%s" %
(entryname, insname, name, fnbf), dt,
"%s_%s" % (name, fnbf))
return result
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.5.1"
__version__ = "4.6.0"
44 changes: 44 additions & 0 deletions nxstools/xmltemplates/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1741,6 +1741,10 @@
'mythen': ['mythen.xml',
'mythen_postrun.ds.xml',
'mythen_filestartnumber.ds.xml'],
'pilc': ['pilc.xml',
'pilc_triggermode_cb.ds.xml'],
'pilctimeid': ['pilctimeid.xml',
'pilctimeid_triggermode_cb.ds.xml'],
'pilatus100k': ['pilatus.xml',
'pilatus_postrun.ds.xml',
'pilatus100k_description.ds.xml',
Expand Down Expand Up @@ -1993,6 +1997,46 @@
'ThrottleEnable'],
'maiainterlock': ['BiasPeltierInterlock', 'BiasPeltierInterlockUptime',
'Pressure'],
'pilc': [
'PositionTriggerStart', 'PositionTriggerStepSize',
'PositionTriggerStop',
'NbTriggers', 'TriggerPulseLength', 'Arm', 'TriggerMode',
'TimeTriggerStart', 'TimeTriggerStepSize',
'FilePrefix', 'FileDir', 'FileName',
'TriggerCounter', 'EncoderTrigger', 'RemainingTriggers',
'EncoderTriggering', 'BufferLoad',
'Position1Conversion', 'Position2Conversion', 'Position3Conversion',
'Position4Conversion', 'Position5Conversion',
'CurrentPosition1', 'CurrentPosition2', 'CurrentPosition3',
'CurrentPosition4', 'CurrentPosition5', 'MaskDataToWrite',
'Metadata1', 'Metadata2', 'Metadata3', 'Metadata4', 'Metadata5',
'TriggersPerFile', 'SoftwareInhibit', 'HardwareInhibit',
'CounterConfig',
# 'CounterData',
# 'Encoder1Data', 'Position1Data',
# 'Encoder2Data', 'Encoder3Data', 'Encoder4Data', 'Encoder5Data',
# 'Position2Data', 'Position3Data', 'Position4Data', 'Position5Data'
],
'pilctimeid': [
'PositionTriggerStart', 'PositionTriggerStepSize',
'PositionTriggerStop',
'NbTriggers', 'TriggerPulseLength', 'Arm', 'TriggerMode',
'TimeTriggerStart', 'TimeTriggerStepSize',
'FilePrefix', 'FileDir', 'FileName',
'TriggerCounter', 'EncoderTrigger', 'RemainingTriggers',
'EncoderTriggering', 'BufferLoad',
'Position1Conversion', 'Position2Conversion', 'Position3Conversion',
'Position4Conversion', 'Position5Conversion',
'CurrentPosition1', 'CurrentPosition2', 'CurrentPosition3',
'CurrentPosition4', 'CurrentPosition5', 'MaskDataToWrite',
'Metadata1', 'Metadata2', 'Metadata3', 'Metadata4', 'Metadata5',
'TriggersPerFile', 'SoftwareInhibit', 'HardwareInhibit',
'CounterConfig',
# 'CounterData',
# 'Encoder1Data', 'Position1Data',
# 'Encoder2Data', 'Encoder3Data', 'Encoder4Data', 'Encoder5Data',
# 'Position2Data', 'Position3Data', 'Position4Data', 'Position5Data'
],
'pilatus100k': [
'DelayTime', 'ExposurePeriod', 'ExposureTime', 'FileDir',
'FilePostfix', 'FilePrefix', 'FileStartNum', 'LastImageTaken',
Expand Down
65 changes: 65 additions & 0 deletions nxstools/xmltemplates/pilc.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version='1.0'?>
<definition>
<group type="NXentry" name="$var.entryname#'$(__entryname__)'$var.serialno">
<group type="NXinstrument" name="$(__insname__)">
<group type="NXcollection" name="$(name)">
<group type="NXcollection" name="collection">
<field type="NX_FLOAT64" name="position_trigger_start">
<strategy mode="FINAL"/>$datasources.$(name)_positiontriggerstart</field>
<field type="NX_FLOAT64" name="position_trigger_step_size">
<strategy mode="FINAL"/>$datasources.$(name)_positiontriggerstepsize</field>
<field units="s" type="NX_FLOAT64" name="position_trigger_stop">
<strategy mode="FINAL"/>$datasources.$(name)_positiontriggerstop</field>
<field type="NX_INT32" name="nb_triggers">
<strategy mode="FINAL"/>$datasources.$(name)_nbtriggers</field>
<field units="s" type="NX_FLOAT64" name="trigger_pulse_length">
<strategy mode="FINAL"/>$datasources.$(name)_triggerpulselength</field>
<field type="NX_INT32" name="trigger_mode">
<strategy mode="FINAL"/>$datasources.$(name)_triggermode_cb</field>
<field units="s" type="NX_FLOAT64" name="time_trigger_start">
<strategy mode="FINAL"/>$datasources.$(name)_timetriggerstart</field>
<field units="s" type="NX_FLOAT64" name="time_trigger_step_size">
<strategy mode="FINAL"/>$datasources.$(name)_timetriggerstepsize</field>
<field type="NX_CHAR" name="file_prefix">
<strategy mode="FINAL"/>$datasources.$(name)_fileprefix</field>
<field type="NX_CHAR" name="file_dir">
<strategy mode="FINAL"/>$datasources.$(name)_filedir</field>
<field type="NX_CHAR" name="last_file_name">
<strategy mode="FINAL"/>$datasources.$(name)_filename</field>
<field type="NX_INT32" name="trigger_counter">
<strategy mode="FINAL"/>$datasources.$(name)_triggercounter</field>
<field type="NX_INT32" name="encoder_trigger">
<strategy mode="FINAL"/>$datasources.$(name)_encodertrigger</field>
<field type="NX_INT32" name="encoder_triggering">
<strategy mode="FINAL"/>$datasources.$(name)_encodertriggering</field>
<field type="NX_INT32" name="remaining_triggers">
<strategy mode="FINAL"/>$datasources.$(name)_remainingtriggers</field>
<field type="NX_INT32" name="buffer_load">
<strategy mode="FINAL"/>$datasources.$(name)_bufferload</field>
<field type="NX_INT32" name="software_inhibit">
<strategy mode="FINAL"/>$datasources.$(name)_softwareinhibit</field>
<field type="NX_FLOAT64" name="hardware_inhibit">
<strategy mode="FINAL"/>$datasources.$(name)_hardwareinhibit</field>
<field type="NX_FLOAT64" name="mask_data_to_write">
<strategy mode="FINAL"/>$datasources.$(name)_maskdatatowrite</field>
<field type="NX_INT32" name="triggers_per_file">
<strategy mode="FINAL"/>$datasources.$(name)_triggersperfile</field>
<field type="NX_INT32" name="counter_config">
<strategy mode="FINAL"/>$datasources.$(name)_counterconfig</field>
<field units="steps/unit" type="NX_FLOAT64" name="position1_conversion">
<strategy mode="FINAL"/>$datasources.$(name)_position1conversion</field>
<field units="steps/unit" type="NX_FLOAT64" name="position2_conversion">
<strategy mode="FINAL"/>$datasources.$(name)_position2conversion</field>
<field units="steps/unit" type="NX_FLOAT64" name="position3_conversion">
<strategy mode="FINAL"/>$datasources.$(name)_position3conversion</field>
<field units="steps/unit" type="NX_FLOAT64" name="position4_conversion">
<strategy mode="FINAL"/>$datasources.$(name)_position4conversion</field>
<field units="steps/unit" type="NX_FLOAT64" name="position5_conversion">
<strategy mode="FINAL"/>$datasources.$(name)_position5conversion</field>
</group>
<group type="NXdata" name="data">
</group>
</group>
</group>
</group>
</definition>
14 changes: 14 additions & 0 deletions nxstools/xmltemplates/pilc_triggermode_cb.ds.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version='1.0'?>
<definition>
<datasource type="PYEVAL" name="$(name)_triggermode_cb">
<result name="result">
from nxstools.pyeval import pilc
ds.result = pilc.triggermode_cb(commonblock, "$(name)", ds.$(name)_triggermode, ds.$(name)_nbtriggers, ds.$(name)_triggersperfile, "$(hostname)", "$(device)", "$var.filename", "$var.entryname#'$(__entryname__)'$var.serialno", "$(__insname__)", ds.$(name)_fileprefix, ds.$(name)_filedir)
</result>
$datasources.$(name)_triggermode
$datasources.$(name)_nbtriggers
$datasources.$(name)_triggersperfile
$datasources.$(name)_fileprefix
$datasources.$(name)_filedir
</datasource>
</definition>
Loading

0 comments on commit caf91ea

Please sign in to comment.