def _connect_buttons(self, widget): w = widget.findChild(QPushButton, 'dclink_button') if w: psname = self._psname[0] dclinks = PSSearch.conv_psname_2_dclink(psname) if dclinks: dclink_type = PSSearch.conv_psname_2_psmodel(dclinks[0]) if dclink_type != 'REGATRON_DCLink': connect_window(w, PSDetailWindow, self, psname=dclinks) else: if len(dclinks) > 1: menu = QMenu(w) for dcl in dclinks: act = QAction(dcl, menu) connect_newprocess(act, [ 'sirius-hla-as-ps-regatron-individual', '-dev', dcl ], parent=self, is_pydm=True) menu.addAction(act) w.setMenu(menu) else: connect_newprocess(w, [ 'sirius-hla-as-ps-regatron-individual', '-dev', dclinks[0] ], parent=self, is_pydm=True) else: w.setHidden(True)
def __init__(self, parent, psnames): super().__init__(parent) self._psnames = psnames self._choose_sec = ['TB', 'BO', 'TS', 'SI'] self._choose_sub = ['All', ] self._choose_sub.extend(['{0:02d}.*'.format(i+1) for i in range(20)]) self._choose_sub.extend(['.*M1', '.*M2', '.*C1', '.*C2', '.*C3', '.*C4', '.*SA', '.*SB', '.*SP']) self._choose_dev = { sec: ['CH', 'CV', 'C(H|V)'] for sec in self._choose_sec} self._choose_dev['SI'].extend( ['QS', 'QFA', 'QFB', 'QFP', 'QF.*', 'QDA', 'QDB1', 'QDB2', 'QDP1', 'QDP2', 'QD.*', 'Q1', 'Q2', 'Q3', 'Q4', 'Q[1-4]', 'Q(D|F).*', 'Q(F|D|[1-4]).*', 'FCH', 'FCV', 'FC(H|V)']) self.magfunc = _PSSearch.conv_psname_2_magfunc(self._psnames[0]) self.pytype = _PSSearch.conv_psname_2_pstype(self._psnames[0]) self._setupUi()
def __init__(self, parent=None, adv_mode=False): """Constructor.""" super().__init__(parent) self.setWindowTitle('PS/PU Test') self.setObjectName('ASApp') cor = get_appropriate_color(section='AS') self.setWindowIcon(qta.icon('mdi.test-tube', color=cor)) # auxiliar data for initializing SI Fam PS self._is_adv_mode = adv_mode self._si_fam_psnames = PSSearch.get_psnames(filters={ 'sec': 'SI', 'sub': 'Fam', 'dis': 'PS' }) # auxiliary data for SI fast correctors self._si_fastcorrs = PSSearch.get_psnames(filters={ 'sec': 'SI', 'dis': 'PS', 'dev': 'FC.*' }) self._needs_update_setup = False self._setup_ui() self._update_setup_timer = QTimer(self) self._update_setup_timer.timeout.connect(self._update_setup) self._update_setup_timer.setInterval(250) self._update_setup_timer.start()
def _create_objects(section): """.""" dipnames = DIPNAMES[section] psnames = _PSSearch.get_psnames({'sec': section}) kckrs = [ _SiriusPVName('BO-01D:PU-InjKckr'), _SiriusPVName('BO-48D:PU-EjeKckr'), _SiriusPVName('SI-01SA:PU-InjDpKckr'), _SiriusPVName('SI-01SA:PU-InjNLKckr') ] # Add Kickers to TLs: if section == 'TS': psnames.extend(kckrs[1:]) psnames = sorted(psnames) elif section == 'TB': psnames.append(kckrs[0]) psnames = sorted(psnames) else: psnames = sorted(set(psnames) - set(kckrs)) magnets = [] dipoles = [] for psname in psnames: if psname.dev.startswith('FC'): continue mfunc = _PSSearch.conv_psname_2_magfunc(psname) if mfunc == 'dipole': dipoles.append({'psname': psname, 'mafunc': mfunc}) continue magnets.append({'psname': psname, 'mafunc': mfunc}) return dipoles, magnets
def test_get_pstype_dict(self): """Test get_pstype_dict.""" d = PSSearch.get_pstype_dict() self.assertIsInstance(d, dict) pstypes_d = sorted(list(d.keys())) pstypes = sorted(PSSearch.get_pstype_names()) self.assertEqual(pstypes_d, pstypes)
def get_all_psnames(): """.""" pss = PSSearch() # psn = pss.get_psnames() + li_psnames psn = pss.get_psnames() psnames = [SiriusPVName(psname) for psname in psn] return psnames
def setupui(self): chs = PSSearch.get_psnames({'sec': 'BO', 'dev': 'CH'}) cvs = PSSearch.get_psnames({'sec': 'BO', 'dev': 'CV'}) quads = PSSearch.get_psnames({'sec': 'BO', 'dev': 'Q(F|D)'}) sexts = PSSearch.get_psnames({'sec': 'BO', 'dev': 'S.*'}) dips = PSSearch.get_psnames({'sec': 'BO', 'dev': 'B'}) wid = QWidget(self) self.setCentralWidget(wid) chwid = GraphWidget(wid, chs, name='CHs', delta=0.05, idxini=25, idxfin=606, legend=False) cvwid = GraphWidget(wid, cvs, name='CVs', delta=0.05, idxini=25, idxfin=606, legend=False) dipwid = GraphWidget(wid, dips, name='Dipoles', delta=0.0, idxini=110, idxfin=2440, legend=True) quadwid = GraphWidget(wid, quads, name='Quadrupoles', delta=0.0, idxini=110, idxfin=2440, legend=True) sextwid = GraphWidget(wid, sexts, name='Sextupoles', delta=0.0, idxini=110, idxfin=2440, legend=True) wid.setLayout(QGridLayout()) wid.layout().addWidget(chwid, 0, 0) wid.layout().addWidget(cvwid, 0, 1) wid.layout().addWidget(quadwid, 1, 0) wid.layout().addWidget(sextwid, 1, 1) wid.layout().addWidget(dipwid, 2, 0, 1, 2)
def _get_PSNames(self, pstype=None): psnames = list() if pstype == 'corrs': psnames = _PSSearch.get_psnames({'sec': 'BO', 'dev': 'C(V|H)'}) elif pstype == 'quads': psnames = ['BO-Fam:PS-QF', 'BO-Fam:PS-QD'] elif pstype == 'sexts': psnames = ['BO-Fam:PS-SF', 'BO-Fam:PS-SD'] else: psnames = _PSSearch.get_psnames({'sec': 'BO', 'sub': 'Fam'}) psnames.extend(_PSSearch.get_psnames({'sec': 'BO', 'dev': 'QS'})) psnames.extend(_PSSearch.get_psnames({'sec': 'BO', 'dev': 'CH'})) psnames.extend(_PSSearch.get_psnames({'sec': 'BO', 'dev': 'CV'})) return psnames
def __init__(self, parent=None, prefix=_vaca_prefix, filters=''): super().__init__(parent) self.setWindowTitle('Power Supplies Graph Monitor') self._prefix = prefix self._filters = filters if not filters: self.setObjectName('ASApp') filters = {'sec': 'SI', 'dis': 'PS', 'dev': 'CH'} else: self.setObjectName(filters['sec']+'App') self._psnames = _PSSearch.get_psnames(filters) self._magfunc = _PSSearch.conv_psname_2_magfunc(self._psnames[0]) self._pstype = _PSSearch.conv_psname_2_pstype(self._psnames[0]) self._setupUi()
def test_get_splims(self): """Test get_splims.""" l1 = PSSearch.get_splims(pstype='si-quadrupole-q30-trim', label='lolo') l2 = PSSearch.get_splims(pstype='si-quadrupole-q30-trim', label='hihi') self.assertGreater(l2, l1) # exceptions self.assertRaises(KeyError, PSSearch.get_splims, pstype='dummy', label='low') self.assertRaises(KeyError, PSSearch.get_splims, pstype='bo-corrector-ch', label='dummy')
def create_udc(bbbname=BBBNAME, udc_index=None): """Create UDC.""" pru = PRU(bbbname=bbbname) if udc_index is not None: udc_list = PSSearch.conv_bbbname_2_udc(bbbname) udcname = udc_list[udc_index] bsmps = PSSearch.conv_udc_2_bsmps(udcname) else: bsmps = PSSearch.conv_bbbname_2_bsmps(bbbname) psnames, device_ids = zip(*bsmps) for psname, dev_id in bsmps: print('psname: {:<15} dev_id: {}'.format(psname, dev_id)) psmodel = PSSearch.conv_psname_2_psmodel(psnames[0]) udc = UDC(pru=pru, psmodel=psmodel, device_ids=device_ids) return udc
def __init__(self, name, visible_props, parent=None): """Build UI with dclink name.""" super().__init__(parent) self._name = PVName(name) self._psmodel = PSSearch.conv_psname_2_psmodel(name) self._pstype = PSSearch.conv_psname_2_pstype(name) self.visible_props = sort_propties(visible_props) self.filled_widgets = set() self._prefixed_name = self._name.substitute(prefix=VACA_PREFIX) self._analog_name = get_analog_name(self._name) self._strength_name = get_strength_name(self._name) self._is_pulsed = IsPulsed.match(self._name) self._is_linac = IsLinac.match(self._name) self._li_has_not_strength = LIQuadHasNotStrength.match(self._name) self._is_fofb = FastCorrector.match(self._name) self._is_dclink = IsDCLink.match(self._name) self._is_regatron = self._psmodel == 'REGATRON_DCLink' self._is_reg_slave = self._pstype == 'as-dclink-regatron-slave' self._bbb_name = '' self._udc_name = '' if not self._is_pulsed and not self._is_linac and \ not self._is_regatron and not self._is_fofb: self._bbb_name = PSSearch.conv_psname_2_bbbname(self._name) self._udc_name = PSSearch.conv_psname_2_udc(self._name) self._has_opmode = not self._is_linac and not self._is_pulsed\ and not self._is_fofb self._has_ctrlmode = not self._is_regatron and not self._is_linac\ and not self._is_fofb self._has_pwrstate = not self._is_reg_slave self._has_reset = not self._is_linac and not self._is_fofb\ and not self._is_reg_slave self._has_ctrlloop = not self._is_linac and not self._is_pulsed\ and not self._is_regatron self._has_parmupdt = not self._is_linac and not self._is_regatron\ and not self._is_fofb self._has_wfmupdt = self._has_parmupdt and not self._is_dclink self._has_analsp = not self._is_reg_slave self._has_analrb = not self._is_regatron self._has_analmon = not self._is_fofb self._has_strength = bool(self._strength_name and not self._li_has_not_strength) self._has_strength_mon = self._has_strength and not self._is_fofb self._has_trim = HasTrim.match(self._name) self._create_pvs() self._setup_ui()
def _get_pu_tree_names(self): punames = PSSearch.get_psnames({ 'sec': '(TB|BO|TS|SI)', 'dis': 'PU', 'dev': '.*(Kckr|Sept).*' }) return punames
def _set_check_dclinks_capvolt(self): self.ok_ps.clear() self.nok_ps.clear() pwrsupplies = self._get_selected_ps() if not pwrsupplies: return devices = self._get_related_dclinks(pwrsupplies, include_regatrons=True) dev_exc_regatrons = { dev for dev in devices if PSSearch.conv_psname_2_psmodel(dev) != 'REGATRON_DCLink' } if not devices: return task0 = CreateTesters(devices, parent=self) task1 = SetCapBankVolt(dev_exc_regatrons, parent=self) task2 = CheckCapBankVolt(devices, parent=self) task2.itemDone.connect(self._log) labels = [ 'Connecting to devices...', 'Setting capacitor bank voltage...', 'Checking capacitor bank voltage...' ] tasks = [task0, task1, task2] dlg = ProgressDialog(labels, tasks, self) dlg.exec_()
def get_pvs(accelerator, pattern): """.""" regexp = re.compile(pattern) if accelerator: psnames = PSSearch.get_psnames({'sec': accelerator}) else: psnames = PSSearch.get_psnames() pvslist = [] for psname in psnames: psdata = PSData(psname) dbase = psdata.propty_database for prop in dbase: pvname = psname + ':' + prop if regexp.match(pvname): pvslist.append(pvname) return pvslist
def test_conv_psname_2_pstypes(self): """Test conv_psname_2_pstype.""" for psname, pstype in TestPSSearch.sample.items(): self.assertEqual(PSSearch.conv_psname_2_pstype(psname), pstype) # exceptions self.assertRaises(KeyError, PSSearch.conv_psname_2_pstype, psname='dummy')
def test_get_polarities(self): """Test get_polarities.""" polarities = PSSearch.get_polarities() self.assertIsInstance(polarities, list) for p in polarities: self.assertIsInstance(p, str) self.assertIn('bipolar', polarities) self.assertIn('monopolar', polarities)
def test_conv_pstype_2_magfunc(self): """Test conv_pstype_2_polarity.""" for pstype, magfunc in TestPSSearch.pstype2magfunc.items(): self.assertEqual(PSSearch.conv_pstype_2_magfunc(pstype), magfunc) # Non existent pstype raises KeyError self.assertRaises(KeyError, PSSearch.conv_pstype_2_magfunc, pstype='dummy')
def test_conv_pstype_2_polarity(self): """Test conv_pstype_2_polarity.""" for pstype, polarity in TestPSSearch.pstype2polarity.items(): self.assertEqual(PSSearch.conv_pstype_2_polarity(pstype), polarity) # Non existent pstype raises KeyError self.assertRaises(KeyError, PSSearch.conv_pstype_2_polarity, pstype='dummy')
def _set_psnames(self): sec = self.cb_sec.currentText() if sec == 'SI': sub = self.cb_sub.currentText() sub = sub if sub != 'All' else '.*' else: sub = '.*' dev = self.cb_dev[sec].currentText() self._psnames = _PSSearch.get_psnames( {'sec': sec, 'sub': '(?!Fam)'+sub, 'dis': 'PS', 'dev': dev}) if self._psnames and self.sender() == self.cb_dev[sec]: self.magfunc = _PSSearch.conv_psname_2_magfunc(self._psnames[0]) self.pytype = _PSSearch.conv_psname_2_pstype(self._psnames[0]) self.matype_changed.emit(self.magfunc, self.pytype) self.psnames_changed.emit(self._psnames)
def _make_sec_widget(self, sec): widget = QWidget(self) lay = QVBoxLayout(widget) if sec in {'TB', 'BO', 'TS', 'SI'}: devices = PSSearch.get_psnames({'sec': sec, 'dis': 'PU'}) elif sec == 'InjBO': devices = PSSearch.get_psnames({ 'sec': '(TB|BO)', 'dis': 'PU', 'dev': 'Inj' }) elif sec == 'EjeBO': devices = PSSearch.get_psnames({ 'sec': '(BO|TS)', 'dis': 'PU', 'dev': 'Eje' }) elif sec == 'InjSI': devices = PSSearch.get_psnames({ 'sec': '(TS|SI)', 'dis': 'PU', 'dev': 'Inj' }) elif sec == 'PingSI': devices = PSSearch.get_psnames({ 'sec': 'SI', 'dis': 'PU', 'dev': 'Ping' }) visible_props = sort_propties([ 'detail', 'state', 'reset', 'intlk', 'setpoint', 'monitor', 'pulse', 'strength_sp', 'strength_mon' ]) lay.addWidget(SummaryHeader(devices[0], visible_props, self)) for device in devices: ma_widget = SummaryWidget(device, visible_props, self) lay.addWidget(ma_widget) self.pu_widgets_dict[device] = ma_widget lay.addStretch() return widget
def test_conv_pstype_2_splims(self): """Test conv_pstype_2_polarity.""" pstypes = tuple(TestPSSearch.pstype2polarity.keys()) for pstype in pstypes: splims = PSSearch.conv_pstype_2_splims(pstype) self.assertIsInstance(splims, dict) # Non existent pstype return None self.assertRaises(KeyError, PSSearch.conv_pstype_2_splims, pstype='dummy')
def test_conv_bbbname_2_psnames(self): """Test conv_bbbname_2_psnames.""" self.assertRaises(TypeError, PSSearch.conv_bbbname_2_psnames) self.assertRaises(KeyError, PSSearch.conv_bbbname_2_psnames, '') bsmps = PSSearch.conv_bbbname_2_psnames( bbbname='PA-RaPSF05:CO-PSCtrl-BO') self.assertIsInstance(bsmps, list) self.assertGreater(len(bsmps), 0) self.assertIsInstance(bsmps[0], tuple) self.assertIsInstance(bsmps[0][0], str) self.assertIsInstance(bsmps[0][1], int)
def _get_related_dclinks(self, psnames, include_regatrons=False): if isinstance(psnames, str): psnames = [ psnames, ] alldclinks = set() for name in psnames: if 'LI' in name: continue dclinks = PSSearch.conv_psname_2_dclink(name) if dclinks: dclink_model = PSSearch.conv_psname_2_psmodel(dclinks[0]) if dclink_model != 'REGATRON_DCLink': alldclinks.update(dclinks) elif include_regatrons: for dcl in dclinks: dcl_typ = PSSearch.conv_psname_2_pstype(dcl) if dcl_typ == 'as-dclink-regatron-master': alldclinks.add(dcl) alldclinks = [PVName(dev) for dev in alldclinks] return alldclinks
def get_pvs_bo(): """.""" psnames = PSSearch.get_psnames() pvs = dict() for psname in psnames: if psname[:2] in ('TB', 'TS', 'SI') and \ 'FCH' not in psname and \ 'FCV' not in psname and \ 'PU' not in psname: print(psname) pvs[psname] = epics.PV(psname + ':WfmUpdateAuto-Sel') return pvs
def _set_check_pwrstate_dclinks(self, state, devices=list(), ps2check=list()): self.ok_ps.clear() self.nok_ps.clear() if not devices: pwrsupplies = self._get_selected_ps() if not pwrsupplies: return devices = self._get_related_dclinks(pwrsupplies, include_regatrons=True) ps2check = set() for dev in devices: ps2check.update(PSSearch.conv_dclink_2_psname(dev)) if not devices: return if state == 'off': self.ok_ps_aux_list.clear() self.nok_ps_aux_list.clear() self._check_pwrstate(ps2check, state='offintlk', show=False) if len(self.nok_ps_aux_list) > 0: for dev in self.ok_ps_aux_list: self._log(dev, True) for dev in self.nok_ps_aux_list: self._log(dev, False) QMessageBox.critical( self, 'Message', 'Make sure all related power supplies\n' 'are turned off before turning DCLinks off!') return task0 = CreateTesters(devices, parent=self) task1 = SetPwrState(devices, state=state, parent=self) task2 = CheckPwrState(devices, state=state, is_test=True, parent=self) tasks = [task0, task1, task2] labels = [ 'Connecting to DCLinks...', 'Turning DCLinks ' + state + '...', 'Checking DCLinks powered ' + state + '...' ] if state == 'on': task3 = CheckInitOk(devices, parent=self) task3.itemDone.connect(self._log) tasks.append(task3) labels.append('Wait DCLinks initialize...') else: task2.itemDone.connect(self._log) dlg = ProgressDialog(labels, tasks, self) dlg.exec_()