Newer
Older
# -*- coding: utf-8 -*-
#
# This file is part of the DG_PY_FOFBTool project
#
#
#
# Distributed under the terms of the GPL license.
# See LICENSE.txt for more info.
"""
"""
# PyTango imports
import tango
from tango import DebugIt
from tango.server import run
from tango.server import Device
from tango.server import attribute, command
from tango.server import device_property
from tango import AttrQuality, DispLevel, DevState
from tango import AttrWriteType, PipeWriteType
# Additional import
#----- PROTECTED REGION ID(DG_PY_FOFBTool.additionnal_import) ENABLED START -----#
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import FofbTool.Operation
import FofbTool.Configuration
import logging
#----- PROTECTED REGION END -----# // DG_PY_FOFBTool.additionnal_import
__all__ = ["DG_PY_FOFBTool", "main"]
class DG_PY_FOFBTool(Device):
"""
**Properties:**
- Device Property
combpm_bpmfilter
- Each line gives the BPM id allowed in the combpm engine of the cellnode.\nOne line per cellnode, in the order of the cellnodepath property.
- Type:'DevVarStringArray'
tangopath_cellnode
- Tango path of the cellnodes
- Type:'DevVarStringArray'
comcorr_pscid
- Line by line PSCID to program on cellnode interface.\nOne line by cellnode
- Type:'DevVarStringArray'
tangopath_watcher
- Tango path of FofbWatcher
- Type:'DevString'
corr_pscid
- PSCID of the inv matrix lines
- Type:'DevString'
ccn_npsc
- Number of PSC ID to send in centralnode frames.\nIdentical for all interfaces
- Type:'DevULong'
ccn_nbpm
- Number of BPMID to pack in each cellnode.\nOne valeu per cellnode
- Type:'DevVarLongArray'
logfilepath
- Type:'DevString'
tangopath_centraltiming
- Type:'DevString'
tangopath_centralnode
- Type:'DevString'
"""
# PROTECTED REGION ID(DG_PY_FOFBTool.class_variable) ENABLED START #
d_status = {}
"""
def dev_status(self):
return my_status()
"""
def my_status(self):
try:
return "\n\n".join([str(v) for v in self.d_status.values()])+"\n"
except Exception:
self.debug_stream(str(self.d_status))
return "Status failure\n"
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# PROTECTED REGION END # // DG_PY_FOFBTool.class_variable
# -----------------
# Device Properties
# -----------------
combpm_bpmfilter = device_property(
dtype='DevVarStringArray',
mandatory=True
)
tangopath_cellnode = device_property(
dtype='DevVarStringArray',
mandatory=True
)
comcorr_pscid = device_property(
dtype='DevVarStringArray',
mandatory=True
)
tangopath_watcher = device_property(
dtype='DevString',
mandatory=True
)
corr_pscid = device_property(
dtype='DevString',
mandatory=True
)
ccn_npsc = device_property(
dtype='DevULong',
mandatory=True
)
ccn_nbpm = device_property(
dtype='DevVarLongArray',
mandatory=True
)
logfilepath = device_property(
dtype='DevString',
mandatory=True
)
tangopath_centraltiming = device_property(
dtype='DevString',
)
tangopath_centralnode = device_property(
dtype='DevString',
mandatory=True
)
# ----------
# Attributes
# ----------
includeLBP = attribute(
dtype='DevBoolean',
access=AttrWriteType.READ_WRITE,
)
FofbToolVersion = attribute(
dtype='DevString',
)
# ---------------
# General methods
# ---------------
def init_device(self):
"""Initialises the attributes and properties of the DG_PY_FOFBTool."""
Device.init_device(self)
#----- PROTECTED REGION ID(DG_PY_FOFBTool.init_device) ENABLED START -----#
self.info_stream("FofbTool {}".format(FofbTool.__version__))
logger = logging.getLogger("FofbTool")
try:
fh=logging.FileHandler(self.logfilepath)
except FileNotFoundError:
logger.warning("Not logging to file, could not open location {}".format(self.logfilepath))
else:
fh.setLevel(logging.DEBUG)
fh.setFormatter(logging.Formatter("{levelname:8}: {message}", style='{'))
logger.addHandler(fh)
logger.setLevel(logging.DEBUG)
#----- PROTECTED REGION END -----# // DG_PY_FOFBTool.init_device
def always_executed_hook(self):
"""Method always executed before any TANGO command is executed."""
#----- PROTECTED REGION ID(DG_PY_FOFBTool.always_executed_hook) ENABLED START -----#
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#----- PROTECTED REGION END -----# // DG_PY_FOFBTool.always_executed_hook
def delete_device(self):
"""Hook to delete resources allocated in init_device.
This method allows for any memory or other resources allocated in the
init_device method to be released. This method is called by the device
destructor and by the device Init command.
"""
#----- PROTECTED REGION ID(DG_PY_FOFBTool.delete_device) ENABLED START -----#
#----- PROTECTED REGION END -----# // DG_PY_FOFBTool.delete_device
# ------------------
# Attributes methods
# ------------------
def read_includeLBP(self):
# PROTECTED REGION ID(DG_PY_FOFBTool.includeLBP_read) ENABLED START #
"""Return the includeLBP attribute."""
return self._include_lbp
# PROTECTED REGION END # // DG_PY_FOFBTool.includeLBP_read
def write_includeLBP(self, value):
# PROTECTED REGION ID(DG_PY_FOFBTool.includeLBP_write) ENABLED START #
"""Set the includeLBP attribute."""
pass
# PROTECTED REGION END # // DG_PY_FOFBTool.includeLBP_write
def read_FofbToolVersion(self):
# PROTECTED REGION ID(DG_PY_FOFBTool.FofbToolVersion_read) ENABLED START #
"""Return the FofbToolVersion attribute."""
return FofbTool.__version__
# PROTECTED REGION END # // DG_PY_FOFBTool.FofbToolVersion_read
# --------
# Commands
# --------
@command(
)
@DebugIt()
def configure(self):
# PROTECTED REGION ID(DG_PY_FOFBTool.configure) ENABLED START #
"""
:return:None
"""
success=True
self.d_status["configure"]="Configure: pending"
for cn, bpm in zip(self.tangopath_cellnode, self.combpm_bpmfilter):
bpmid = [int(b) for b in bpm.split()]
self.debug_stream("Set {} to {}".format(cn, bpmid))
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
s=FofbTool.Configuration.cellnode_configure_combpm(cn, bpmid)
success = success and s
if not s:
self.error_stream("Failed to configure COMBPM on {}".format(cn))
self.info_stream("Configure COMCORR")
for cn, psc in zip(self.tangopath_cellnode, self.comcorr_pscid):
pscid = [int(b) for b in psc.split()]
self.debug_stream("Set {} to {}".format(cn, pscid))
s=FofbTool.Configuration.cellnode_configure_comcorr(cn, pscid, True)
success = success and s
if not s:
self.error_stream("Failed to configure COMCORR on {}".format(cn))
self.info_stream("Configure CCN")
for cn, nbpm in zip(self.tangopath_cellnode, self.ccn_nbpm):
self.debug_stream("Set {} to {} bpm and {} psc".format(cn, nbpm, self.ccn_npsc))
FofbTool.Configuration.cellnode_configure_ccn(cn, nbpm, self.ccn_npsc)
success = success and s
if not s:
self.error_stream("Failed to configure CCN on {}".format(cn))
s=FofbTool.Configuration.centralnode_configure_ccn(self.tangopath_centralnode, self.ccn_nbpm, self.ccn_npsc)
if success:
self.d_status["configure"]="Configure: success"
else:
self.d_status["configure"]="Configure: failed"
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
# PROTECTED REGION END # // DG_PY_FOFBTool.configure
@command(
)
@DebugIt()
def stop(self):
# PROTECTED REGION ID(DG_PY_FOFBTool.stop) ENABLED START #
"""
:return:None
"""
pass
# PROTECTED REGION END # // DG_PY_FOFBTool.stop
@command(
)
@DebugIt()
def start(self):
# PROTECTED REGION ID(DG_PY_FOFBTool.start) ENABLED START #
"""
:return:None
"""
pass
# PROTECTED REGION END # // DG_PY_FOFBTool.start
@command(
)
@DebugIt()
def sync(self):
# PROTECTED REGION ID(DG_PY_FOFBTool.sync) ENABLED START #
"""
:return:None
"""
db = tango.Database()
self.debug_stream("Building list form FREE PROPERTIES")
bpmidlist = [(int(n.split(':')[0]), n.split(':')[2]) for n in db.get_property("FOFB", "bpmlist")['bpmlist'] if 'LIBERA' in n]
tlocal = [n.split(':')[2] for n in db.get_property("FOFB", 'TimingBoardList')['TimingBoardList'] if "LOCAL" in n]
lbpevrx = db.get_property("FOFB", 'LBPEVRX')['LBPEVRX']
# This will timeout
FofbTool.Operation.sync_bpm(bpmidlist, lbpevrx, tlocal, self.tangopath_centraltiming)
# PROTECTED REGION END # // DG_PY_FOFBTool.sync
# ----------
# Run server
# ----------
def main(args=None, **kwargs):
"""Main function of the DG_PY_FOFBTool module."""
# PROTECTED REGION ID(DG_PY_FOFBTool.main) ENABLED START #
return run((DG_PY_FOFBTool,), args=args, **kwargs)
# PROTECTED REGION END # // DG_PY_FOFBTool.main
if __name__ == '__main__':
main()