Skip to content

Commit

Permalink
Merge pull request #828 from lnls-sirius/change-timing-ioc
Browse files Browse the repository at this point in the history
Change Timing IOC
  • Loading branch information
fernandohds564 authored Aug 1, 2022
2 parents e9da73a + 5dacc5d commit 31bc77a
Show file tree
Hide file tree
Showing 16 changed files with 215 additions and 212 deletions.
2 changes: 1 addition & 1 deletion siriuspy/siriuspy/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.50.1
2.51.0
189 changes: 87 additions & 102 deletions siriuspy/siriuspy/clientconfigdb/types/global_config.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion siriuspy/siriuspy/clientweb/implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def crates_mapping(timeout=_TIMEOUT):
"""Return the crates mapping."""
url = _DIAG_FOLDER + 'microTCA-vs-BPMs-mapping/'
text = read_url(url, timeout=timeout)
pat = _re.compile('>(names.crate[a-zA-Z_0-9]*.cfg)<')
pat = _re.compile('"(names_crate[a-zA-Z_0-9]*.cfg)"')
files = pat.findall(text)
txt = ''
for fi in files:
Expand Down
6 changes: 3 additions & 3 deletions siriuspy/siriuspy/devices/injsys.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,11 +512,11 @@ def __init__(self):
def cmd_turn_off(self):
"""Turn off."""
# disable injbo
self.injboevt.mode = 'Disabled'
self.injboevt.mode = 'Disable'

# wait for injbo to be disabled
retval = self._wait_devices_propty(
self.injboevt, 'Mode-Sts', Event.MODES.index('Disabled'),
self.injboevt, 'Mode-Sts', Event.MODES.index('Disable'),
timeout=3, return_prob=True)
if not retval[0]:
text = 'Check for InjBO Event to be disabled timed '\
Expand Down Expand Up @@ -1000,7 +1000,7 @@ def _do_procedures(self, procedures):
for fun, msg in procedures:
if self._check_abort():
return False
if not fun():
if not fun(timeout=2):
self._update_status('ERR:Could not ' + msg)
return False
_time.sleep(0.5)
Expand Down
10 changes: 8 additions & 2 deletions siriuspy/siriuspy/devices/timing.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,10 @@ def mode(self, value):
@property
def mode_str(self):
"""."""
return Event.MODES[self['Mode-Sts']]
mode = self['Mode-Sts']
if mode is not None:
return Event.MODES[mode]
return None

@property
def code(self):
Expand All @@ -213,7 +216,10 @@ def delay_type(self, value):
@property
def delay_type_str(self):
"""."""
return Event.DELAYTYPES[self['DelayType-Sts']]
dlytyp = self['DelayType-Sts']
if dlytyp is not None:
return Event.DELAYTYPES[dlytyp]
return None

@property
def delay(self):
Expand Down
59 changes: 24 additions & 35 deletions siriuspy/siriuspy/optics/lattice_survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,48 +101,47 @@ def generate_bpm_static_table():
f.write('\n\n#BPMs data \n')
f.write('#-----------')

crates = _get_crates_mapping()
all_bpms = _get_all_bpms()

model = pymodels.si
acc = model.create_accelerator()
_append_bpm_data_bl(filename, acc, crates, 'Beam Lines (BL)')
_append_bpm_data(filename, model, acc, crates, 'Storage Ring (SR)', 'SI')
_append_bpm_data_bl(filename, acc, all_bpms, 'Beam Lines (BL)')
_append_bpm_data(filename, model, acc, 'Storage Ring (SR)', 'SI')

model = pymodels.bo
acc = model.create_accelerator()
_append_bpm_data(filename, model, acc, crates, 'Booster (BO)', 'BO')
_append_bpm_data(filename, model, acc, 'Booster (BO)', 'BO')

model = pymodels.tb
acc, *_ = model.create_accelerator()
_append_bpm_data(filename, model, acc, crates, 'BO Transport Line', 'TB')
_append_bpm_data(filename, model, acc, 'BO Transport Line', 'TB')

model = pymodels.ts
acc, *_ = model.create_accelerator()
_append_bpm_data(filename, model, acc, crates, 'SR Transport Line', 'TS')
_append_bpm_data(filename, model, acc, 'SR Transport Line', 'TS')


def _append_bpm_data(filename, model, acc, crates, label, section):
def _append_bpm_data(filename, model, acc, label, section):
fam_data = model.get_family_data(acc)
pos = pyaccel.lattice.find_spos(acc)

inds = [i[0] for i in fam_data['BPM']['index']]
subs = fam_data['BPM']['subsection']
insts = fam_data['BPM']['instance']
bpms, tims, bpos = [], [], []
bpms, bpos = [], []
for ind, inst, sub in zip(inds, insts, subs):
name = _join_name(sec=section, dis='DI', dev='BPM', sub=sub, idx=inst)
bpms.append(name)
tims.append(crates[name])
bpos.append(pos[ind])
_write_to_file(filename, bpms, bpos, tims, label)
_write_to_file(filename, bpms, bpos, label)


def _append_bpm_data_bl(filename, acc, crates, label):
def _append_bpm_data_bl(filename, acc, all_bpms, label):
pos = pyaccel.lattice.find_spos(acc)

mcs = pyaccel.lattice.find_indices(acc, 'fam_name', 'mc')

bpms_bc = [bpm for bpm in crates if bpm.sub.endswith('BCFE')]
bpms_bc = [bpm for bpm in all_bpms if bpm.sub.endswith('BCFE')]
secs = [int(bpm.sub[:2]) for bpm in bpms_bc]
bpos_bc = [pos[mcs[ss-1]] for ss in secs]

Expand All @@ -152,47 +151,37 @@ def _append_bpm_data_bl(filename, acc, crates, label):
mis = sorted(mia + mib + mip)

end = ('SAFE', 'SBFE', 'SPFE')
bpms_mi = sorted([bpm for bpm in crates if bpm.sub.endswith(end)])
bpms_mi = sorted([bpm for bpm in all_bpms if bpm.sub.endswith(end)])
secs = [int(bpm.sub[:2]) for bpm in bpms_mi]
bpos_mi = [pos[mis[ss-1]] for ss in secs]

bpms = bpms_mi + bpms_bc
bpos = bpos_mi + bpos_bc
data = sorted(zip(bpos, bpms))
bpos, bpms = list(zip(*data))
tims = [crates[b] for b in bpms]
_write_to_file(filename, bpms, bpos, tims, label)
_write_to_file(filename, bpms, bpos, label)


def _get_crates_mapping():
def _get_all_bpms():
data = _crates_mapping()
crates = dict()
mapping = dict()
bpms = set()
for line in data.splitlines():
line = line.strip()
if not line or line[0] == '#':
continue # empty line
crate, dev, *_ = line.split()
_, dev, *_ = line.split()
dev = _PVName(dev)
if crate not in mapping and dev.dev == 'AMCFPGAEVR':
crates[crate] = dev
mapping[crates[crate]] = list()
else:
mapping[crates[crate]].append(dev)
if dev.dev in ('BPM', 'PBPM'):
bpms.add(dev)
return bpms

inv_mapping = dict()
for k, values in mapping.items():
for value in values:
inv_mapping[value] = k
return inv_mapping


def _write_to_file(fname, bpms, pos, tims, label):
def _write_to_file(fname, bpms, pos, label):
with open(fname, 'a') as fil:
fil.write('\n\n\n# '+label+'\n')
fil.write('#'+57*'-' + '\n')
fil.write("#{bpm:20s} {pos:^15s} {timing:20s}\n".format(
bpm='Name', pos='Position [m]', timing='Timing'))
fil.write("#{bpm:20s} {pos:^15s}\n".format(
bpm='Name', pos='Position [m]'))
fil.write('#'+57*'-' + '\n')
for bpm, p, t in zip(bpms, pos, tims):
fil.write(f"{bpm:20s} {p:^15.4f} {t:20s}\n")
for bpm, p in zip(bpms, pos):
fil.write(f"{bpm:20s} {p:^15.4f}\n")
10 changes: 0 additions & 10 deletions siriuspy/siriuspy/ramp/conn.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,6 @@ class Const(_csdev.Const):
'EvtInjBO': Const.EVG + ':InjBO',
'EvtInjSI': Const.EVG + ':InjSI',
'EvtRmpBO': Const.EVG + ':RmpBO',
'EvtDigLI': Const.EVG + ':DigLI',
'EvtDigTB': Const.EVG + ':DigTB',
'EvtDigBO': Const.EVG + ':DigBO',
'EvtDigTS': Const.EVG + ':DigTS',
'EvtDigSI': Const.EVG + ':DigSI',
'EvtStudy': Const.EVG + ':Study'}

evt_propties = ('Mode-Sel', 'DelayType-Sel', 'Delay-SP')
Expand Down Expand Up @@ -339,11 +334,6 @@ def _define_properties(self, prefix, connection_callback, callback):
c.EvtInjBO_Delay: None, # [us]
c.EvtRmpBO_Delay: None, # [us]
c.EvtInjSI_Delay: None, # [us]
c.EvtDigLI_Delay: None, # [us]
c.EvtDigTB_Delay: None, # [us]
c.EvtDigBO_Delay: None, # [us]
c.EvtDigTS_Delay: None, # [us]
c.EvtDigSI_Delay: None, # [us]
c.EvtStudy_Delay: None, # [us]
c.TrgInjKckr_Delay: None, # [us]
# Mags trigger
Expand Down
3 changes: 1 addition & 2 deletions siriuspy/siriuspy/ramp/reconst_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,8 +685,7 @@ class BOTIRampFactory:
}
_events = {
_EVG+':Linac', _EVG+':InjBO', _EVG+':RmpBO', _EVG+':InjSI',
_EVG+':DigLI', _EVG+':DigTB', _EVG+':DigBO', _EVG+':DigTS',
_EVG+':DigSI', _EVG+':Study',
_EVG+':Study',
}
_PVs = dict()

Expand Down
24 changes: 2 additions & 22 deletions siriuspy/siriuspy/search/bpms_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class BPMSearch:
"""

_mapping = None
_timing_mapping = None

_lock = _Lock()

Expand Down Expand Up @@ -88,12 +87,6 @@ def get_positions(cls, names=None, filters=None, sorting=None):
names = cls.get_names(filters=filters, sorting=sorting)
return [cls._mapping[k]['position'] for k in names]

@classmethod
def get_timing_mapping(cls):
"""Return a dictionary with the power supply to beaglebone mapping."""
cls._get_data()
return _dcopy(cls._timing_mapping)

@classmethod
def _get_data(cls):
with cls._lock:
Expand All @@ -103,7 +96,6 @@ def _get_data(cls):
raise Exception('could not read data from web server!')
text = _web.bpms_data(timeout=_timeout)
cls._build_mapping(text)
cls._build_timing_to_bpm_mapping()

@classmethod
def _build_mapping(cls, text):
Expand All @@ -113,23 +105,11 @@ def _build_mapping(cls, text):
line = line.strip()
if not line or line[0] == '#':
continue # empty line
key, pos, timing, *_ = line.split()
key, pos, *_ = line.split()
key = _PVName(key)
timing = _PVName(timing)
if key in mapping.keys():
raise Exception('BPM {0:s} double entry.'.format(key))
else:
mapping[key] = {'position': float(pos), 'timing': timing}
mapping[key] = {'position': float(pos)}
cls._mapping = mapping
cls._names = sorted(cls._mapping.keys())

@classmethod
def _build_timing_to_bpm_mapping(cls):
timing_mapping = dict()
for k, v in cls._mapping.items():
k2 = v['timing']
if k2 in timing_mapping.keys():
timing_mapping[k2] += (k, )
else:
timing_mapping[k2] = (k, )
cls._timing_mapping = timing_mapping
5 changes: 3 additions & 2 deletions siriuspy/siriuspy/search/hl_time_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class HLTimeSearch:

_hl_triggers = dict()
_hl_events = dict()
COMMOM_EVTS = ('Dsbld', 'RmpBO', 'Linac', 'Study')

_lock = _Lock()

Expand Down Expand Up @@ -43,8 +44,8 @@ def get_hl_trigger_predef_db(cls, hl_trigger):
"""Return the default database of the high level trigger."""
cls._init()
dic_ = _dcopy(cls._hl_triggers[hl_trigger]['database'])
dic_['Src']['enums'] = ('Dsbl', ) + dic_['Src']['enums']
dic_['Src']['value'] += 1
src = dic_['Src']
src['enums'] = cls.COMMOM_EVTS + src['enums']
return dic_

@classmethod
Expand Down
45 changes: 43 additions & 2 deletions siriuspy/siriuspy/search/ll_time_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from .. import clientweb as _web
from ..namesys import SiriusPVName as _PVName, Filter as _Filter

from .bpms_search import BPMSearch as _BPMSearch
from .ps_search import PSSearch as _PSSearch

_TIMEOUT = 1.0
Expand Down Expand Up @@ -280,6 +279,18 @@ def get_relations_twds_evg(cls):

@classmethod
def has_clock(cls, ll_trigger):
"""Check whether a low level trigger has access to EVG clocks.
Args:
ll_trigger (SiriusPVName): Trigger name.
Raises:
Exception: When trigger receiver is not recognized.
Returns:
bool: True or False.
"""
name = _PVName(ll_trigger)
if name.dev == 'AMCFPGAEVR':
return True
Expand All @@ -290,25 +301,37 @@ def has_clock(cls, ll_trigger):

@classmethod
def has_delay_type(cls, ll_trigger):
"""Check whether a low level trigger has delay type.
Args:
ll_trigger (SiriusPVName): Trigger name.
Returns:
bool: True or False.
"""
name = _PVName(ll_trigger)
return name.dev in {'EVR', 'EVE'} and name.propty.startswith('OUT')

@classmethod
def get_trigger_name(cls, channel):
"""Get name of the trigger associated with channel."""
chan_tree = cls.get_device_tree(channel)
for up_chan in chan_tree:
if up_chan.device_name in cls._trig_src_devs:
return up_chan

@classmethod
def get_fout_channel(cls, channel):
"""Get name of the FOUT channel associated with channel."""
chan_tree = cls.get_device_tree(channel)
for up_chan in chan_tree:
if up_chan.device_name in cls._fout_devs:
return up_chan

@classmethod
def get_evg_channel(cls, channel):
"""Get name of the EVG channel associated with channel."""
chan_tree = cls.get_device_tree(channel)
for up_chan in chan_tree:
if up_chan.device_name in cls._evg_devs:
Expand Down Expand Up @@ -377,7 +400,7 @@ def _add_crates_info(cls):
conns = tuple(cls.In2OutMap['AMCFPGAEVR'].values())[0]
conns = [v for v in conns if not v.startswith('FMC')]

conn_dict = _BPMSearch.get_timing_mapping()
conn_dict = cls._get_crates_mapping()
used = set()
twds_evg = _dcopy(cls._conn_twds_evg)
for chan in twds_evg.keys():
Expand All @@ -395,6 +418,24 @@ def _add_crates_info(cls):
ele1=bpm, ele2=chan.device_name)
# print(conn_dict.keys() - used)

@classmethod
def _get_crates_mapping(cls):
data = _web.crates_mapping()
crates = dict()
mapping = dict()
for line in data.splitlines():
line = line.strip()
if not line or line[0] == '#':
continue # empty line
crate, dev, *_ = line.split()
dev = _PVName(dev)
if crate not in mapping and dev.dev == 'AMCFPGAEVR':
crates[crate] = dev
mapping[crates[crate]] = list()
else:
mapping[crates[crate]].append(dev)
return mapping

@classmethod
def _add_udc_info(cls):
"""Add the information of bbb to PS to timing map."""
Expand Down
Loading

0 comments on commit 31bc77a

Please sign in to comment.