Skip to content

Commit

Permalink
Merge pull request #606 from lnls-sirius/add-new-diags
Browse files Browse the repository at this point in the history
Add Diag classes for new IOCs
  • Loading branch information
anacso17 authored Sep 28, 2020
2 parents d0cfc6a + 14bffea commit 396ae02
Show file tree
Hide file tree
Showing 42 changed files with 1,362 additions and 256 deletions.
2 changes: 1 addition & 1 deletion siriuspy/siriuspy/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.12.1
2.13.0
9 changes: 6 additions & 3 deletions siriuspy/siriuspy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@


__all__ = [
'envars', 'util', 'csdev', 'clientweb', 'clientconfigdb',
'diagnostics', 'pwrsupply', 'magnet', 'namesys', 'timesys', 'csdevice',
'epics', 'callbacks', 'search', 'devices']
'callbacks', 'csdev', 'envars', 'thread', 'util',
'bsmp', 'clientarch', 'clientconfigdb', 'clientweb', 'currinfo',
'cycle', 'devices', 'diagbeam', 'diagsys', 'epics', 'machshift',
'magnet', 'meas', 'namesys', 'optics', 'opticscorr', 'posang',
'pwrsupply', 'ramp', 'search', 'simul', 'sofb', 'timesys'
]
2 changes: 1 addition & 1 deletion siriuspy/siriuspy/devices/bpm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as _np

from .device import Device as _Device
from ..diag.bpm.csdev import Const as _csbpm
from ..diagbeam.bpm.csdev import Const as _csbpm
from ..search import BPMSearch as _BPMSearch


Expand Down
1 change: 0 additions & 1 deletion siriuspy/siriuspy/diag/dcct/__init__.py

This file was deleted.

1 change: 0 additions & 1 deletion siriuspy/siriuspy/diag/ict/__init__.py

This file was deleted.

1 change: 0 additions & 1 deletion siriuspy/siriuspy/diag/screen/__init__.py

This file was deleted.

1 change: 0 additions & 1 deletion siriuspy/siriuspy/diag/slit/__init__.py

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
Empty file.
File renamed without changes.
Empty file.
File renamed without changes.
Empty file.
File renamed without changes.
1 change: 1 addition & 0 deletions siriuspy/siriuspy/diagsys/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""DiagSys subpackage."""
52 changes: 52 additions & 0 deletions siriuspy/siriuspy/diagsys/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/local/bin/python-sirius
"""Application module."""

import time as _time
from threading import Thread as _Thread

from ..callbacks import Callback as _Callback
from ..thread import QueueThread as _QueueThread


class App(_Callback):
"""Main application responsible for updating DB."""

SCAN_FREQUENCY = 2

def __init__(self, prefix, *args):
"""Create Computed PVs."""
super().__init__()
self._prefix = prefix
self._queue = _QueueThread()
self.pvs = list()
self.scanning = False
self.quit = False
self._create_computed_pvs(*args)

self.thread = _Thread(target=self.scan, daemon=True)
self.thread.start()

def process(self, interval):
"""Sleep."""
_time.sleep(interval)

def read(self, reason):
"""Read from IOC database."""
return None

def write(self, reason, value):
"""Write value to reason and let callback update PV database."""
return False # return True to invoke super().write of PCASDriver

def _create_computed_pvs(self):
raise NotImplementedError

def _update_pvs(self):
raise NotImplementedError

def scan(self):
"""Run as a thread scanning PVs."""
while not self.quit:
if self.scanning:
self._update_pvs()
_time.sleep(1.0/App.SCAN_FREQUENCY)
1 change: 1 addition & 0 deletions siriuspy/siriuspy/diagsys/lidiag/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Linac Diag subpackage."""
122 changes: 122 additions & 0 deletions siriuspy/siriuspy/diagsys/lidiag/csdev.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
"""Linac Diag App."""

from ... import csdev as _csdev


class ETypes(_csdev.ETypes):
"""Local enumerate types."""

DIAG_STATUS_LABELS_RF = (
'Disconnected',
'State Off',
'Trigger Off',
'Integral Off',
'Feedback Off',
'Amp-(SP|RB) are different',
'Phase-(SP|RB) are different',
'IxQ (SP|Mon) are different')

DIAG_STATUS_LABELS_EG_HVPS = (
'Disconnected',
'Swicth Status Off',
'Enable Status Off',
'Voltage (SP|Mon) are different')

DIAG_STATUS_LABELS_EG_FILA = (
'Disconnected',
'Swicth Status Off',
'Current-(SP|Mon) are different')


_et = ETypes # syntactic sugar


class Const(_csdev.Const):
"""Local constant types."""

SHB = 'LI-01:RF-SHB'
KLY1 = 'LI-01:RF-Kly-1'
KLY2 = 'LI-01:RF-Kly-2'
RF_DEVICES = [SHB, KLY1, KLY2]
HVPS = 'LI-01:EG-HVPS'
FILA = 'LI-01:EG-FilaPS'
DEV_2_LINAME = {
HVPS: 'LI-01:EG-HVPS',
FILA: 'LI-01:EG-FilaPS',
SHB: 'LA-RF:LLRF:BUN1',
KLY1: 'LA-RF:LLRF:KLY1',
KLY2: 'LA-RF:LLRF:KLY2'}
ALL_DEVICES = DEV_2_LINAME.keys()

LI_RF_AMP_TOL = 1e-2
LI_RF_PHS_TOL = 1e-2
LI_RF_IxQ_TOL = 5e-3
LI_HVPS_TOL = 1.5
LI_FILAPS_TOL = 1e-1


_c = Const # syntactic sugar


def conv_dev_2_liname(device):
"""Return Linac pvname."""
return _c.DEV_2_LINAME[device]


def get_li_diag_status_labels(device):
"""Return Diag Status Labels enum."""
if 'RF' in device:
return _et.DIAG_STATUS_LABELS_RF
if 'HVPS' in device:
return _et.DIAG_STATUS_LABELS_EG_HVPS
if 'FilaPS' in device:
return _et.DIAG_STATUS_LABELS_EG_FILA
raise ValueError('Labels not defined to '+device+'.')


def get_li_diag_propty_database(device):
"""Return property database of diagnostics for linac devices."""
enums = get_li_diag_status_labels(device)
dbase = {
'DiagVersion-Cte': {'type': 'str', 'value': 'UNDEF'},
'DiagStatus-Mon': {'type': 'int', 'value': 0,
'hilim': 1, 'hihi': 1, 'high': 1,
'low': -1, 'lolo': -1, 'lolim': -1
},
'DiagStatusLabels-Cte': {'type': 'string', 'count': len(enums),
'value': enums}
}
if 'RF' in device:
atol = _c.LI_RF_AMP_TOL
ptol = _c.LI_RF_PHS_TOL
vtol = _c.LI_RF_IxQ_TOL
dbase.update({
'DiagAmpDiff-Mon': {
'type': 'float', 'value': 0.0,
'hilim': atol, 'hihi': atol, 'high': atol,
'low': -atol, 'lolo': -atol, 'lolim': -atol},
'DiagPhaseDiff-Mon': {
'type': 'float', 'value': 0.0,
'hilim': ptol, 'hihi': ptol, 'high': ptol,
'low': -ptol, 'lolo': -ptol, 'lolim': -ptol},
'DiagIxQDiff-Mon': {
'type': 'float', 'value': 0.0,
'hilim': vtol, 'hihi': vtol, 'high': vtol,
'low': -vtol, 'lolo': -vtol, 'lolim': -vtol},
})
elif 'HVPS' in device:
dtol = _c.LI_HVPS_TOL
dbase.update({
'DiagVoltDiff-Mon': {
'type': 'float', 'value': 0.0,
'hilim': dtol, 'hihi': dtol, 'high': dtol,
'low': -dtol, 'lolo': -dtol, 'lolim': -dtol}})
elif 'FilaPS' in device:
dtol = _c.LI_FILAPS_TOL
dbase.update({
'DiagCurrentDiff-Mon': {
'type': 'float', 'value': 0.0,
'hilim': dtol, 'hihi': dtol, 'high': dtol,
'low': -dtol, 'lolo': -dtol, 'lolim': -dtol}})
dbase = _csdev.add_pvslist_cte(dbase, 'Diag')
return dbase
132 changes: 132 additions & 0 deletions siriuspy/siriuspy/diagsys/lidiag/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
#!/usr/local/bin/python-sirius
"""Driver module."""

from pcaspy import Alarm as _Alarm, Severity as _Severity

from ...namesys import SiriusPVName
from ..app import App as _App
from ..pvs import ComputedPV as _ComputedPV

from .csdev import conv_dev_2_liname, Const as _Const
from .pvs import LIScalarDiffPV as _LIScalarDiffPV, \
LIVecDiffPV as _LIVecDiffPV, \
LIRFStatusPV as _LIRFStatusPV, \
LIEGHVStatusPV as _LIEGHVStatusPV, \
LIFilaPSStatusPV as _LIFilaPSStatusPV


class LIDiagApp(_App):
"""Main application responsible for updating DB."""

def _create_computed_pvs(self, *args):
# # RF devices
for dev in _Const.RF_DEVICES:
devname = SiriusPVName(self._prefix + dev)
liname = conv_dev_2_liname(dev)

# DiagAmpDiff-Mon
pvs = [None]*2
pvs[_LIScalarDiffPV.SP] = liname + ':SET_AMP'
pvs[_LIScalarDiffPV.RB] = liname + ':GET_AMP'
pvo = _ComputedPV(
devname + ':DiagAmpDiff-Mon', _LIScalarDiffPV(),
self._queue, pvs, monitor=False)
self.pvs.append(pvo)

# DiagPhaseDiff-Mon
pvs = [None]*2
pvs[_LIScalarDiffPV.SP] = liname + ':SET_PHASE'
pvs[_LIScalarDiffPV.RB] = liname + ':GET_PHASE'
pvo = _ComputedPV(
devname + ':DiagPhaseDiff-Mon', _LIScalarDiffPV(),
self._queue, pvs, monitor=False)
self.pvs.append(pvo)

# DiagIxQDiff-Mon
pvs = [None]*4
pvs[_LIVecDiffPV.I_SETT] = liname + ':GET_CH1_SETTING_I'
pvs[_LIVecDiffPV.Q_SETT] = liname + ':GET_CH1_SETTING_Q'
pvs[_LIVecDiffPV.I_DATA] = liname + ':GET_CH1_I'
pvs[_LIVecDiffPV.Q_DATA] = liname + ':GET_CH1_Q'
pvo = _ComputedPV(
devname + ':DiagIxQDiff-Mon', _LIVecDiffPV(),
self._queue, pvs, monitor=False)
self.pvs.append(pvo)

# DiagStatus-Mon
pvs = [None]*7
pvs[_LIRFStatusPV.PV_STREAM] = liname + ':GET_STREAM'
pvs[_LIRFStatusPV.PV_EXTTRG] = \
liname + ':GET_EXTERNAL_TRIGGER_ENABLE'
pvs[_LIRFStatusPV.PV_INTEGR] = liname + ':GET_INTEGRAL_ENABLE'
pvs[_LIRFStatusPV.PV_FBMODE] = liname + ':GET_FB_MODE'
pvs[_LIRFStatusPV.PV_AMPDIF] = devname + ':DiagAmpDiff-Mon'
pvs[_LIRFStatusPV.PV_PHSDIF] = devname + ':DiagPhaseDiff-Mon'
pvs[_LIRFStatusPV.PV_IXQDIF] = devname + ':DiagIxQDiff-Mon'
pvo = _ComputedPV(
devname + ':DiagStatus-Mon', _LIRFStatusPV(),
self._queue, pvs, monitor=False)
self.pvs.append(pvo)

# # Egun devices
# HVPS
devname = SiriusPVName(self._prefix + _Const.HVPS)
liname = conv_dev_2_liname(devname)
# DiagVoltDiff-Mon
pvs = [None]*2
pvs[_LIScalarDiffPV.SP] = liname + ':voltoutsoft'
pvs[_LIScalarDiffPV.RB] = liname + ':voltinsoft'
pvo = _ComputedPV(
devname + ':DiagVoltDiff-Mon', _LIScalarDiffPV(),
self._queue, pvs, monitor=False)
self.pvs.append(pvo)
# DiagStatus-Mon
pvs = [None]*3
pvs[_LIEGHVStatusPV.PV_SWITCH] = liname + ':swstatus'
pvs[_LIEGHVStatusPV.PV_ENABLE] = liname + ':enstatus'
pvs[_LIEGHVStatusPV.PV_VLTDIF] = devname + ':DiagVoltDiff-Mon'
pvo = _ComputedPV(
devname + ':DiagStatus-Mon', _LIEGHVStatusPV(),
self._queue, pvs, monitor=False)
self.pvs.append(pvo)

# FilaPS
devname = SiriusPVName(self._prefix + _Const.FILA)
liname = conv_dev_2_liname(devname)
# DiagCurrentDiff-Mon
pvs = [None]*2
pvs[_LIScalarDiffPV.SP] = liname + ':currentoutsoft'
pvs[_LIScalarDiffPV.RB] = liname + ':currentinsoft'
pvo = _ComputedPV(
devname + ':DiagCurrentDiff-Mon', _LIScalarDiffPV(),
self._queue, pvs, monitor=False)
self.pvs.append(pvo)
# DiagStatus-Mon
pvs = [None]*2
pvs[_LIFilaPSStatusPV.PV_SWITCH] = liname + ':swstatus'
pvs[_LIFilaPSStatusPV.PV_CURDIF] = devname + ':DiagCurrentDiff-Mon'
pvo = _ComputedPV(
devname + ':DiagStatus-Mon', _LIFilaPSStatusPV(),
self._queue, pvs, monitor=False)
self.pvs.append(pvo)

self._pvs_connected = {pv: False for pv in self.pvs}

def _update_pvs(self):
for pvo in self.pvs:
if not pvo.connected:
if self._pvs_connected[pvo]:
self.run_callbacks(
pvo.pvname, alarm=_Alarm.TIMEOUT_ALARM,
severity=_Severity.INVALID_ALARM,
field='status')
self._pvs_connected[pvo] = False
if 'DiagStatus' in pvo.pvname:
self.run_callbacks(pvo.pvname, value=pvo.value)
else:
if not self._pvs_connected[pvo]:
self.run_callbacks(
pvo.pvname, alarm=_Alarm.NO_ALARM,
severity=_Severity.NO_ALARM, field='status')
self._pvs_connected[pvo] = True
self.run_callbacks(pvo.pvname, value=pvo.value)
Loading

0 comments on commit 396ae02

Please sign in to comment.