Skip to content

Commit

Permalink
Merge branch 'master' into add-injctrl
Browse files Browse the repository at this point in the history
  • Loading branch information
anacso17 committed Feb 4, 2022
2 parents b74b7dc + 1473725 commit 79aaf5a
Show file tree
Hide file tree
Showing 9 changed files with 308 additions and 83 deletions.
40 changes: 16 additions & 24 deletions siriuspy/Makefile
Original file line number Diff line number Diff line change
@@ -1,37 +1,29 @@
DISTPATH=$(shell python-sirius -c "import site; print(site.getsitepackages())" | cut -f2 -d"'")
PACKAGE:=$(shell basename $(shell pwd))
ISINST=$(shell sudo pip-sirius show $(PACKAGE) | wc -l )
EGGLINK=$(DISTPATH)/$(PACKAGE).egg-link
TMPFOLDER=/tmp/install-$(PACKAGE)
PREFIX=
PIP=pip
ifeq ($(CONDA_PREFIX),)
PREFIX=sudo -H
PIP=pip-sirius
endif

clean:
git clean -fdX

develop: uninstall
pip-sirius install --no-deps -e ./
install: clean uninstall
$(PREFIX) $(PIP) install --no-deps ./

install: uninstall
ifneq (, $(wildcard $(TMPFOLDER)))
rm -rf /tmp/install-$(PACKAGE)
endif
cp -rRL ../$(PACKAGE) /tmp/install-$(PACKAGE)
cd /tmp/install-$(PACKAGE)/; sudo -H pip-sirius install --no-deps ./
rm -rf /tmp/install-$(PACKAGE)
uninstall:
$(PREFIX) $(PIP) uninstall -y $(PACKAGE)

develop-install: clean develop-uninstall
$(PIP) install --no-deps -e ./

# known issue: It will fail to uninstall scripts
# if they were installed in develop mode
uninstall: clean
ifneq (,$(wildcard $(EGGLINK)))
rm -r $(EGGLINK)
endif
ifneq ($(ISINST),0)
pip-sirius uninstall -y $(PACKAGE)
sed -i '/$(PACKAGE)/d' $(DISTPATH)/easy-install.pth
else
echo 'already uninstalled $(PACKAGE)'
endif
develop-uninstall:
$(PIP) uninstall -y $(PACKAGE)

test:
test:
pytest tests/

dist: clean ## Build setuptools dist
Expand Down
44 changes: 30 additions & 14 deletions siriuspy/siriuspy/clientarch/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,18 @@
from . import exceptions as _exceptions


_TIMEOUT = 5.0 # [seconds]


class ClientArchiver:
"""Archiver Data Fetcher class."""

DEFAULT_TIMEOUT = 5.0 # [s]
SERVER_URL = _envars.SRVURL_ARCHIVER
ENDPOINT = '/mgmt/bpl'

def __init__(self, server_url=None):
def __init__(self, server_url=None, timeout=None):
"""Initialize."""
timeout = timeout or ClientArchiver.DEFAULT_TIMEOUT
self.session = None
self.timeout = _TIMEOUT
self._timeout = timeout
self._url = server_url or self.SERVER_URL
self._ret = None
# print('urllib3 InsecureRequestWarning disabled!')
Expand All @@ -40,12 +39,22 @@ def connected(self):
"""Connected."""
try:
status = _urllib.request.urlopen(
self._url, timeout=self.timeout,
self._url, timeout=self._timeout,
context=_ssl.SSLContext()).status
return status == 200
except _urllib.error.URLError:
return False

@property
def timeout(self):
"""Connection timeout."""
return self._timeout

@timeout.setter
def timeout(self, value):
"""Set connection timeout."""
self._timeout = float(value)

@property
def server_url(self):
"""Return URL of the Archiver server.
Expand Down Expand Up @@ -215,23 +224,25 @@ def getData(self, pvname, timestamp_start, timestamp_stop,

pvn2resp = dict()
for pvn, idcs in pvn2idcs.items():
_ts, _vs = _np.array([]), _np.array([])
_ts, _vs = _np.array([]), list()
_st, _sv = _np.array([]), _np.array([])
for idx in idcs:
resp = resps[idx]
if not resp:
continue
data = resp[0]['data']
_ts = _np.r_[_ts, [v['secs'] + v['nanos']/1.0e9 for v in data]]
_vs = _np.r_[_vs, [v['val'] for v in data]]
for val in data:
_vs.append(val['val'])
_st = _np.r_[_st, [v['status'] for v in data]]
_sv = _np.r_[_sv, [v['severity'] for v in data]]
if not _ts.size:
timestamp, value, status, severity = [None, None, None, None]
else:
_, _tsidx = _np.unique(_ts, return_index=True)
timestamp, value, status, severity = \
_ts[_tsidx], _vs[_tsidx], _st[_tsidx], _sv[_tsidx]
timestamp, status, severity = \
_ts[_tsidx], _st[_tsidx], _sv[_tsidx]
value = [_vs[i] for i in _tsidx]

pvn2resp[pvn] = dict(
timestamp=timestamp, value=value, status=status,
Expand Down Expand Up @@ -286,18 +297,23 @@ def _run_async_event_loop(self, *args, **kwargs):

def _thread_run_async_event_loop(self, func, *args, **kwargs):
"""Get event loop."""
close = False
try:
loop = _asyncio.get_event_loop()
except RuntimeError as error:
if 'no current event loop' in str(error):
loop = _asyncio.new_event_loop()
_asyncio.set_event_loop(loop)
close = True
else:
raise error
try:
self._ret = loop.run_until_complete(func(*args, **kwargs))
except _asyncio.TimeoutError:
self._ret = None
raise _exceptions.TimeoutError

if close:
loop.close()

async def _handle_request(
self, url, return_json=False, need_login=False):
Expand All @@ -318,7 +334,7 @@ async def _get_request_response(self, url, session, return_json):
try:
if isinstance(url, list):
response = await _asyncio.gather(
*[session.get(u, ssl=False, timeout=self.timeout)
*[session.get(u, ssl=False, timeout=self._timeout)
for u in url])
if any([not r.ok for r in response]):
return None
Expand All @@ -327,7 +343,7 @@ async def _get_request_response(self, url, session, return_json):
*[r.json() for r in response])
else:
response = await session.get(
url, ssl=False, timeout=self.timeout)
url, ssl=False, timeout=self._timeout)
if not response.ok:
return None
if return_json:
Expand All @@ -341,7 +357,7 @@ async def _create_session(self, url, headers, payload, ssl):
session = _ClientSession()
async with session.post(
url, headers=headers, data=payload, ssl=ssl,
timeout=self.timeout) as response:
timeout=self._timeout) as response:
content = await response.content.read()
authenticated = b"authenticated" in content
return session, authenticated
Expand Down
10 changes: 6 additions & 4 deletions siriuspy/siriuspy/clientarch/pvarch.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,12 @@ def update(self, mean_sec=None, parallel=True):

def set_data(self, timestamp, value, status, severity):
"""Auxiliary method to set data. Used by PVDataSet."""
self._timestamp = _np.asarray(timestamp)
self._value = _np.asarray(value)
self._status = _np.asarray(status)
self._severity = _np.asarray(severity)
self._timestamp = self._value = self._status = self._severity = None
if timestamp is not None:
self._timestamp = _np.asarray(timestamp)
self._value = _np.asarray(value)
self._status = _np.asarray(status)
self._severity = _np.asarray(severity)

def to_dict(self):
"""Return dictionary with PV properties.
Expand Down
16 changes: 8 additions & 8 deletions siriuspy/siriuspy/clientconfigdb/types/as_rf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

# NOTE: absolute imports are necessary here due to how
# CONFIG_TYPES in __init__.py is built.
from siriuspy.clientconfigdb.types.global_config import _pvs_as_rf
from siriuspy.clientconfigdb.types.global_config import _pvs_as_rf, \
_pvs_li_llrf


def get_dict():
Expand All @@ -22,7 +23,6 @@ def get_dict():
# in the configuration. The second numeric parameter in the pair is the
# delay [s] the client should wait before setting the next PV.


_pvs_bo_llrf = [
['BR-RF-DLLRF-01:ILK:REVSSA1:S', 0.0, 0.0], # Interlock disable
['BR-RF-DLLRF-01:ILK:REVSSA2:S', 0, 0.0],
Expand Down Expand Up @@ -134,7 +134,7 @@ def get_dict():
['BR-RF-DLLRF-01:TUNE:FILT:S', 0, 0.0],
['BR-RF-DLLRF-01:TUNE:TRIG:S', 0, 0.0],
['BR-RF-DLLRF-01:TUNE:TOPRAMP:S', 0, 0.0],
['BR-RF-DLLRF-01:FF:POS:S', 0, 0.0], # Field Flatness loop config
['BR-RF-DLLRF-01:FF:POS:S', 0, 0.0], # Field Flatness loop config
['BR-RF-DLLRF-01:FF:DEADBAND:S', 0, 0.0], # [%]
['BR-RF-DLLRF-01:FF:GAIN:CELL2:S', 0, 0.0],
['BR-RF-DLLRF-01:FF:GAIN:CELL4:S', 0, 0.0],
Expand Down Expand Up @@ -438,10 +438,10 @@ def get_dict():
['SR-RF-DLLRF-01:RmpTs2-SP', 0, 0.0], # [ms]
['SR-RF-DLLRF-01:RmpTs3-SP', 0, 0.0], # [ms]
['SR-RF-DLLRF-01:RmpTs4-SP', 0, 0.0], # [ms]
['SR-RF-DLLRF-01:mV:RAMP:AMP:BOT-SP', 0, 0.0], # [mV]
['SR-RF-DLLRF-01:RmpPhsBot-SP', 0, 0.0], # [°]
['SR-RF-DLLRF-01:mV:RAMP:AMP:TOP-SP', 0, 0.0], # [mV]
['SR-RF-DLLRF-01:RmpPhsTop-SP', 0, 0.0], # [°]
['SR-RF-DLLRF-01:mV:RAMP:AMP:BOT-SP', 0, 0.0], # [mV]
['SR-RF-DLLRF-01:RmpPhsBot-SP', 0, 0.0], # [°]
['SR-RF-DLLRF-01:RmpIncTs-SP', 0, 0.0], # [min]
['SR-RF-DLLRF-01:DisableRampDown:S', 0, 0.0],
['SR-RF-DLLRF-01:FDL:FrameQty-SP', 0, 0.0],
Expand All @@ -452,7 +452,7 @@ def get_dict():


_pvs_si_rfssa = [
['RA-ToSIA01:OffsetConfig:UpperIncidentPower', 0, 0.0], # Offsets SSA Twr 1
['RA-ToSIA01:OffsetConfig:UpperIncidentPower', 0, 0.0], # Offsets SSA Twr1
['RA-ToSIA01:OffsetConfig:UpperReflectedPower', 0, 0.0],
['RA-ToSIA01:OffsetConfig:LowerIncidentPower', 0, 0.0],
['RA-ToSIA01:OffsetConfig:LowerReflectedPower', 0, 0.0],
Expand All @@ -474,7 +474,7 @@ def get_dict():
['RA-ToSIA01:AlarmConfig:CurrentLimHigh', 0, 0.0],
['RA-ToSIA01:AlarmConfig:CurrentLimLow', 0, 0.0],
['RA-ToSIA01:AlarmConfig:CurrentLimLoLo', 0, 0.0],
['RA-ToSIA02:OffsetConfig:UpperIncidentPower', 0, 0.0], # Offsets SSA Twr 2
['RA-ToSIA02:OffsetConfig:UpperIncidentPower', 0, 0.0], # Offsets SSA Twr2
['RA-ToSIA02:OffsetConfig:UpperReflectedPower', 0, 0.0],
['RA-ToSIA02:OffsetConfig:LowerIncidentPower', 0, 0.0],
['RA-ToSIA02:OffsetConfig:LowerReflectedPower', 0, 0.0],
Expand Down Expand Up @@ -652,6 +652,6 @@ def get_dict():
_template_dict = {
'pvs':
_pvs_as_rf +
_pvs_bo_llrf + _pvs_bo_rfssa + _pvs_bo_rfcal +
_pvs_li_llrf + _pvs_bo_llrf + _pvs_bo_rfssa + _pvs_bo_rfcal +
_pvs_si_llrf + _pvs_si_rfssa + _pvs_si_rfcav + _pvs_si_rfcal
}
4 changes: 2 additions & 2 deletions siriuspy/siriuspy/clientconfigdb/types/global_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1040,10 +1040,10 @@ def get_dict():
['BR-RF-DLLRF-01:RmpTs2-SP', 0, 0.0], # ms
['BR-RF-DLLRF-01:RmpTs3-SP', 0, 0.0], # ms
['BR-RF-DLLRF-01:RmpTs4-SP', 0, 0.0], # ms
['BR-RF-DLLRF-01:RmpPhsBot-SP', 0, 0.0], # Deg
['BR-RF-DLLRF-01:RmpPhsTop-SP', 0, 0.0], # Deg
['BR-RF-DLLRF-01:mV:RAMP:AMP:BOT-SP', 0, 0.0], # mV
['BR-RF-DLLRF-01:RmpPhsBot-SP', 0, 0.0], # Deg
['BR-RF-DLLRF-01:mV:RAMP:AMP:TOP-SP', 0, 0.0], # mV
['BR-RF-DLLRF-01:mV:RAMP:AMP:BOT-SP', 0, 0.0], # mV
]


Expand Down
Loading

0 comments on commit 79aaf5a

Please sign in to comment.