Exemplo n.º 1
0
    def on_but_play(self):
        txt = self.but_play.accessibleName()
        logger.debug('on_but_play %s' % txt)
        #ind = self.status_play.index(txt)
        #ico = icon.icon_playback_start_sym if txt==self.status_play_start else icon.icon_wait
        #icon.icon_playback_pause_sym

        ico = icon.icon_wait
        self.but_play.setIconSize(
            QSize(32, 32) if ico == icon.icon_wait else QSize(48, 48))
        self.but_play.setAccessibleName(self.s_play_wait)
        #self.but_play.setAccessibleName(self.status_play[0 if ind==1 else 1])

        self.but_play.setIcon(ico)
        self.set_tool_tips()

        daq_ctrl = daq_control()
        state = daq_ctrl.getState() if daq_ctrl is not None else 'unknown'
        logger.debug('current state is %s' % state)

        cmd = self.s_paused if txt == self.s_play_pause else self.s_running

        daq_ctrl = daq_control()
        if daq_ctrl is not None:
            daq_ctrl.setState(cmd)
            logger.debug('daq_control.setState("%s")' % cmd)
        else:
            logger.warning('daq_control() is None')

        self.set_but_play_enabled(
            False)  # lock button untill RUNNING status is received
Exemplo n.º 2
0
 def on_box_state(self, ind):
     if not ind: return
     state = self.states[ind]
     logger.info(
         'CGWMainDetector.on_box_state -> daq_control().setState %s' %
         state)
     #self.parent_ctrl.kick_zmq()
     daq_control().setState(state.lower())
     logger.debug('command daq_control().setState is committed...')
Exemplo n.º 3
0
    def on_but_select(self):
        logger.debug('on_but_select')

        dict_platf, list2d = get_platform(
        )  # list2d = [[[True,''], 'test/19670/daq-tst-dev02', 'testClient2b'], ...]

        #logger.debug('List of processes:')
        #for rec in list2d :
        #    [[state,name],alias] = rec
        #    logger.debug('%s %s is %s selected' % (name.ljust(10), alias.ljust(10), {False:'not', True:'   '}[state]))

        #parent=self,
        w = QWPopupTableCheck(tableio=list2d, title_h=self.TABTITLE_H,\
                              do_ctrl=(self.state=='UNALLOCATED'),\
                              win_title='Select partition',\
                              do_edit=False, is_visv=False, do_frame=True)

        if self.state != 'UNALLOCATED':
            w.setToolTip(
                'Processes control is only available\nin the state UNALLOCATED'
            )

        #w.move(QCursor.pos()+QPoint(20,10))
        w.move(self.mapToGlobal(self.but_select.pos()) +
               QPoint(5, 22))  # (5,22) offset for frame
        resp = w.exec_()

        logger.debug('resp: %s' % {
            QDialog.Rejected: 'Rejected',
            QDialog.Accepted: 'Accepted'
        }[resp])

        if resp != QDialog.Accepted: return

        list2d = w.table_out()

        #if self.w_display is not None :
        #    self.w_display.fill_table_model(tableio=list2d,\
        #                                    title_h=self.TABTITLE_H,\
        #                                    do_edit=False, is_visv=False, do_ctrl=False, do_frame=True)

        set_platform(dict_platf, list2d)

        # 2019-03-13 caf: If Select->Apply is successful, an Allocate transition should be triggered.
        json_data = daq_control().getJsonConfig()
        retval = daq_control().storeJsonConfig(json_data)
        if 'err_info' in retval:
            logger.error('control.storeJsonConfig: %s' % retval['err_info'])

        list2d_active = list_active_procs(list2d)

        if len(list2d_active) == 0:
            logger.warning('NO PROCESS SELECTED!')

        daq_control().setState('allocated')
Exemplo n.º 4
0
    def on_but_type(self):
        #logger.debug('on_but_type')
        inst, confdb = self.inst_configdb('on_but_type: ')
        list_of_aliases = confdb.get_aliases(hutch=inst)  # ['NOBEAM', 'BEAM']
        if not list_of_aliases:
            list_of_aliases = self.list_of_aliases  # ['NOBEAM', 'BEAM']
            logger.warning('List of configdb-s IS EMPTY... Use default: %s' %
                           str(list_of_aliases))

        selected = popup_select_item_from_list(self.but_type,
                                               list_of_aliases,
                                               dx=-46,
                                               dy=-33)  #, use_cursor_pos=True)

        msg = 'selected %s of the list %s' % (selected, str(list_of_aliases))
        logger.debug(msg)

        if selected in (None, self.type_old): return

        rv = daq_control().setConfig(selected)
        if rv is None:
            self.set_config_type(selected)
        else:
            logger.error('setConfig("%s"): %s' % (selected, rv))
            self.set_config_type('error')
Exemplo n.º 5
0
 def on_but_roll_call(self):
     """Equivalent to CLI: daqstate -p6 --transition plat
        https://github.com/slac-lcls/lcls2/blob/collection_front/psdaq/psdaq/control/daqstate.py
     """
     logger.debug('on_but_roll_call - command to set transition "rollcall"')
     rv = daq_control().setTransition('rollcall')
     if rv is not None: logger.error('Error: %s' % rv)
Exemplo n.º 6
0
    def hbox_buttons(self):
        hbox = QHBoxLayout()

        daq_ctrl = daq_control()
        state = daq_ctrl.getState() if daq_ctrl is not None else 'unknown'
        logger.debug('current state is "%s"' % state)
        is_running = state == self.s_running

        self.but_play   = QPushButton(icon.icon_playback_pause_sym if is_running else\
                                      icon.icon_playback_start_sym, '')
        self.but_record = QPushButton(icon.icon_record_sym,
                                      '')  # icon.icon_record

        self.but_play  .setAccessibleName(self.s_play_pause if is_running else\
                                          self.s_play_start)
        self.but_record.setAccessibleName(self.status_record[0])

        self.but_play.clicked.connect(self.on_but_play)
        self.but_record.clicked.connect(self.on_but_record)

        hbox.addWidget(self.but_play)
        hbox.addWidget(self.but_record)

        #self.but_play.setStyleSheet('QPushButton{border: 0px solid;}')
        #self.but_record.setStyleSheet("background-image: url('image.jpg'); border: none;")
        return hbox
Exemplo n.º 7
0
    def onApply(self):
        logger.debug('onApply')
        self.list2d_out = self.wtab.fill_output_object()
        #self.accept()

        dict_platf, list2d = get_platform(
        )  # [[[True,''], 'test/19670/daq-tst-dev02', 'testClient2b'], ...]
        set_platform(dict_platf, self.list2d_out)

        ## 2019-03-13 caf: If Select->Apply is successful, an Allocate transition should be triggered.
        ## 2020-07-29 caf: The Allocate transition will update the active detectors file, if necessary.

        list2d_active = list_active_procs(self.list2d_out)

        if len(list2d_active) == 0:
            logger.warning('NO PROCESS SELECTED!')
        else:
            daq_control().setState('allocated')
Exemplo n.º 8
0
def set_platform(dict_platf, list2d):
    """ Converts list2d (table presentation) to dict_platf; sets processes active/inactive etc.
    """
    #print('dict_platf: ',dict_platf)
    #print('list2d:',list2d)

    try:
        s = ''
        for pname in dict_platf:
            #print("proc_name: %s" % str(pname))
            for k, v in dict_platf[pname].items():
                display = _display_name(pname, v)  # 'pname/pid/host alias'
                proc_pid_host = display.split(' ')[0]
                # find record/row in the table
                rec = None
                for rec in list2d:
                    if rec[2][1] == proc_pid_host: break
                if rec is None:
                    logger.error(
                        'proc/pid/host "%s" is not found in the table' %
                        proc_pid_host)
                    continue

                status = rec[0][0]  # bool
                int_active = {True: 1, False: 0}[status]
                dict_platf[pname][k]['active'] = int_active
                if pname == 'drp':
                    val = rec[1][1]
                    if isinstance(val, str) and val.isdigit():
                        dict_platf[pname][k]['det_info']['readout'] = int(val)
                    else:
                        logger.error('set_platform WRONG drp "group readout" value "%s" for "%s"'%\
                                     (str(val), display))

                s += '%s   int_active: %d\n' % (display, int_active)

        sj = json.dumps(dict_platf, indent=2, sort_keys=False)
        logger.debug('control.setPlatform() json:\n%s' % str(sj))
        logger.debug('summary:\n%s' % s)
        daq_control().selectPlatform(dict_platf)

    except Exception as ex:
        logger.error('Exception in parsing dict_platf (4): %s' % ex)
Exemplo n.º 9
0
 def check_transition(self):
     """Uses getStatus() to get last transition and set the info button status.
     """
     logger.debug('CGWMainDetector.check_transition')
     #t0_sec = time() # takes 0.001s
     transition, state, config_alias = daq_control().getStatus(
     )  # submits request to check transition, state and config_alias
     logger.debug(
         'CGWMainDetector.check_transition transition:%s state:%s config_alias:%s'
         % (str(transition), str(state), str(config_alias)))
     self.but_transition.setText(
         transition.upper())  # + ' since %s' % self.ts)
Exemplo n.º 10
0
    def set_config_type(self, config_type):

        cfgtype = config_type
        if config_type in ('error', 'init'):
            transition, state, cfgtype = daq_control().getStatus()

        if cfgtype == self.type_old: return

        if not (cfgtype in self.list_of_aliases): return

        self.set_but_type_text(cfgtype)
        self.type_old = cfgtype
        self.set_buts_enabled()
Exemplo n.º 11
0
def dict_platform():
    """ returns control.getPlatform() or None
    """
    dict_platf = None
    try:
        dict_platf = daq_control().getPlatform()  # returns dict

    except Exception as ex:
        logger.error('Exception in daq_control.getPlatform(): %s' % ex)
        print('failed on request control.getPlatform()')

    sj = json.dumps(dict_platf, indent=2, sort_keys=False)
    logger.debug('control.getPlatform() json(type:%s):\n%s' %
                 (type(dict_platf), str(sj)))

    return dict_platf
Exemplo n.º 12
0
    def __init__(self, parser=None):

        self.proc_parser(parser)

        if __name__ != "__main__":
            daq_control.set_daq_control(
                DaqControl(host=self.host,
                           platform=self.platform,
                           timeout=self.timeout))
            QWZMQListener.__init__(self,
                                   host=self.host,
                                   platform=self.platform,
                                   timeout=self.timeout)
        else:  # emulator mode for TEST ONLY
            QWZMQListener.__init__(self, is_normal=False)

        self.wlogr = QWLoggerStd(log_level=self.loglevel,
                                 show_buttons=False,
                                 log_prefix=self.logdir)

        #instrument = self.expname[:3].upper()
        instrument = daq_control().getInstrument()
        logger.debug('daq_control().getInstrument(): %s' % instrument)
        self.inst = 'TMO' if instrument in ('TST', None) else instrument

        cp.cgwmain = self

        self.main_win_width = cp.main_win_width
        self.main_win_height = cp.main_win_height
        self.main_win_pos_x = cp.main_win_pos_x
        self.main_win_pos_y = cp.main_win_pos_y

        #icon.set_icons()

        self.wconf = CGWMainConfiguration(parent_ctrl=self)
        self.wtabs = CGWMainTabs(parent_ctrl=self)

        self.vspl = QSplitter(Qt.Vertical)
        self.vspl.addWidget(self.wconf)
        self.vspl.addWidget(self.wtabs)
        self.vspl.addWidget(self.wlogr)

        self.mbox = QHBoxLayout()
        self.mbox.addWidget(self.vspl)
        self.setLayout(self.mbox)

        self.set_style()
Exemplo n.º 13
0
    def process_zmq_message(self, msg):
        #print('==== msg: %s' % str(msg))
        try:
            for rec in msg:
                jo = json.loads(rec)
                #  jo['header'] # {'key': 'status', 'msg_id': '0918505109-317821000', 'sender_id': None}
                #  jo['body']   # {'state': 'allocated', 'transition': 'alloc'}

                if jo['header']['key'] == 'status':
                    body = jo['body']
                    s_state = body['state']
                    s_transition = body['transition']
                    s_config_alias = body['config_alias']
                    #====self.wdetr.set_but_state (s_state)
                    self.wctrl.set_but_ctrls(s_state)
                    self.wctrl.set_transition(s_transition)
                    self.wconf.set_config_type(s_config_alias)

                    self.wcoll.update_table()
                    logger.info('received state msg: %s and transition: %s' %
                                (s_state, s_transition))

                elif jo['header']['key'] == 'error':
                    body = jo['body']
                    logger.error('received error msg: %s' % body['err_info'])

                    # grab state directly (not from error message)
                    state = daq_control().getState()

                    self.wctrl.set_but_ctrls(state)  # ('error')
                    self.wconf.set_config_type(state)  # ('error')

                else:
                    sj = json.dumps(jo, indent=2, sort_keys=False)
                    logger.debug('received jason:\n%s' % sj)

        except KeyError as ex:
            logger.warning('CGWMain.process_zmq_message: %s\nError: %s' %
                           (str(msg), ex))

        except Exception as ex:
            logger.warning('CGWMain.process_zmq_message: %s\nError: %s' %
                           (str(msg), ex))
Exemplo n.º 14
0
 def check_state(self):
     #logger.debug('CGWMainDetector.check_state -> daq_control().getState()')
     state = daq_control().getState()
     if state is None: return
     if state == self.state: return
     self.set_but_ctrls(state)