Ejemplo n.º 1
0
class DataWorker(QtCore.QObject):
    run_start = QtCore.pyqtSignal()
    config_data = QtCore.pyqtSignal(dict)
    interpreted_data = QtCore.pyqtSignal(dict)
    meta_data = QtCore.pyqtSignal(dict)
    finished = QtCore.pyqtSignal()

    def __init__(self):
        QtCore.QObject.__init__(self)
        self.integrate_readouts = 1
        self.n_readout = 0
        self._stop_readout = Event()
        self.setup_raw_data_analysis()

    def setup_raw_data_analysis(self):
        self.interpreter = PyDataInterpreter()
        self.histograming = PyDataHistograming()
        self.interpreter.set_warning_output(False)
        self.histograming.set_no_scan_parameter()
        self.histograming.create_occupancy_hist(True)
        self.histograming.create_rel_bcid_hist(True)
        self.histograming.create_tot_hist(True)
        self.histograming.create_tdc_hist(True)

    def connect(self, socket_addr):
        self.socket_addr = socket_addr
        self.context = zmq.Context()
        self.socket_pull = self.context.socket(zmq.PULL)
        self.socket_pull.connect(self.socket_addr)
        self.poller = zmq.Poller()  # poll needed to be able to return QThread
        self.poller.register(self.socket_pull, zmq.POLLIN)

    @pyqtSlot(float)
    def on_set_integrate_readouts(self, value):
        self.integrate_readouts = value

    def analyze_raw_data(self, raw_data):
        self.interpreter.interpret_raw_data(raw_data)
        self.histograming.add_hits(self.interpreter.get_hits())

    @pyqtSlot()
    def process_data(self):  # infinite loop via QObject.moveToThread(), does not block event loop
        while(not self._stop_readout.wait(0.001)):  # use wait(), do not block here
#             socks = dict(self.poller.poll(1))
#             if self.socket_pull in socks and socks[self.socket_pull] == zmq.POLLIN:
#                 meta_data = self.socket_pull.recv_json()
            try:
                meta_data = self.socket_pull.recv_json(flags=zmq.NOBLOCK)
            except zmq.Again:
                pass
            else:
                name = meta_data.pop('name')
                if name == 'FEI4readoutData':
                    data = self.socket_pull.recv()
                    # reconstruct numpy array
                    buf = buffer(data)
                    dtype = meta_data.pop('dtype')
                    shape = meta_data.pop('shape')
                    data_array = np.frombuffer(buf, dtype=dtype).reshape(shape)
                    # count readouts and reset
                    self.n_readout += 1
                    if self.integrate_readouts != 0 and self.n_readout % self.integrate_readouts == 0:
                        self.histograming.reset()
                        # we do not want to reset interpreter to keep the error counters
    #                         self.interpreter.reset()
                        # interpreted data
                    self.analyze_raw_data(data_array)
                    if self.integrate_readouts == 0 or self.n_readout % self.integrate_readouts == self.integrate_readouts - 1:
                        interpreted_data = {
                            'occupancy': self.histograming.get_occupancy(),
                            'tot_hist': self.histograming.get_tot_hist(),
                            'tdc_counters': self.interpreter.get_tdc_counters(),
                            'error_counters': self.interpreter.get_error_counters(),
                            'service_records_counters': self.interpreter.get_service_records_counters(),
                            'trigger_error_counters': self.interpreter.get_trigger_error_counters(),
                            'rel_bcid_hist': self.histograming.get_rel_bcid_hist()}
                        self.interpreted_data.emit(interpreted_data)
                    # meta data
                    meta_data.update({'n_hits': self.interpreter.get_n_hits(), 'n_events': self.interpreter.get_n_events()})
                    self.meta_data.emit(meta_data)
                elif name == 'RunConf':
                    # TODO: from FE config
                    try:
                        n_bcid = int(data[1]['trig_count'])
                    except KeyError:
                        n_bcid = 0
                    self.histograming.reset()
                    self.interpreter.reset()
                    self.interpreter.set_trig_count(n_bcid)
                    self.run_start.emit()
                    self.config_data.emit(meta_data)

        self.finished.emit()

#     @pyqtSlot()
    def stop(self):
        self._stop_readout.set()
Ejemplo n.º 2
0
class DataWorker(QtCore.QObject):
    run_start = QtCore.pyqtSignal()
    config_data = QtCore.pyqtSignal(dict)
    interpreted_data = QtCore.pyqtSignal(dict)
    meta_data = QtCore.pyqtSignal(dict)
    finished = QtCore.pyqtSignal()

    def __init__(self):
        QtCore.QObject.__init__(self)
        self.integrate_readouts = 1
        self.n_readout = 0
        self._stop_readout = Event()
        self.setup_raw_data_analysis()

    def setup_raw_data_analysis(self):
        self.interpreter = PyDataInterpreter()
        self.histograming = PyDataHistograming()
        self.interpreter.set_warning_output(False)
        self.histograming.set_no_scan_parameter()
        self.histograming.create_occupancy_hist(True)
        self.histograming.create_rel_bcid_hist(True)
        self.histograming.create_tot_hist(True)
        self.histograming.create_tdc_hist(True)

    def connect(self, socket_addr):
        self.socket_addr = socket_addr
        self.context = zmq.Context()
        self.socket_pull = self.context.socket(zmq.PULL)
        self.socket_pull.connect(self.socket_addr)
        self.poller = zmq.Poller()  # poll needed to be able to return QThread
        self.poller.register(self.socket_pull, zmq.POLLIN)

    @pyqtSlot(float)
    def on_set_integrate_readouts(self, value):
        self.integrate_readouts = value

    def analyze_raw_data(self, raw_data):
        self.interpreter.interpret_raw_data(raw_data)
        self.histograming.add_hits(self.interpreter.get_hits())

    @pyqtSlot()
    def process_data(
        self
    ):  # infinite loop via QObject.moveToThread(), does not block event loop
        while (not self._stop_readout.wait(0.001)
               ):  # use wait(), do not block here
            #             socks = dict(self.poller.poll(1))
            #             if self.socket_pull in socks and socks[self.socket_pull] == zmq.POLLIN:
            #                 meta_data = self.socket_pull.recv_json()
            try:
                meta_data = self.socket_pull.recv_json(flags=zmq.NOBLOCK)
            except zmq.Again:
                pass
            else:
                name = meta_data.pop('name')
                if name == 'FEI4readoutData':
                    data = self.socket_pull.recv()
                    # reconstruct numpy array
                    buf = buffer(data)
                    dtype = meta_data.pop('dtype')
                    shape = meta_data.pop('shape')
                    data_array = np.frombuffer(buf, dtype=dtype).reshape(shape)
                    # count readouts and reset
                    self.n_readout += 1
                    if self.integrate_readouts != 0 and self.n_readout % self.integrate_readouts == 0:
                        self.histograming.reset()
                        # we do not want to reset interpreter to keep the error counters

    #                         self.interpreter.reset()
    # interpreted data
                    self.analyze_raw_data(data_array)
                    if self.integrate_readouts == 0 or self.n_readout % self.integrate_readouts == self.integrate_readouts - 1:
                        interpreted_data = {
                            'occupancy':
                            self.histograming.get_occupancy(),
                            'tot_hist':
                            self.histograming.get_tot_hist(),
                            'tdc_counters':
                            self.interpreter.get_tdc_counters(),
                            'error_counters':
                            self.interpreter.get_error_counters(),
                            'service_records_counters':
                            self.interpreter.get_service_records_counters(),
                            'trigger_error_counters':
                            self.interpreter.get_trigger_error_counters(),
                            'rel_bcid_hist':
                            self.histograming.get_rel_bcid_hist()
                        }
                        self.interpreted_data.emit(interpreted_data)
                    # meta data
                    meta_data.update({
                        'n_hits':
                        self.interpreter.get_n_hits(),
                        'n_events':
                        self.interpreter.get_n_events()
                    })
                    self.meta_data.emit(meta_data)
                elif name == 'RunConf':
                    # TODO: from FE config
                    try:
                        n_bcid = int(data[1]['trig_count'])
                    except KeyError:
                        n_bcid = 0
                    self.histograming.reset()
                    self.interpreter.reset()
                    self.interpreter.set_trig_count(n_bcid)
                    self.run_start.emit()
                    self.config_data.emit(meta_data)

        self.finished.emit()


#     @pyqtSlot()

    def stop(self):
        self._stop_readout.set()
Ejemplo n.º 3
0
class DataWorker(QtCore.QObject):
    run_start = QtCore.pyqtSignal()
    run_config_data = QtCore.pyqtSignal(dict)
    global_config_data = QtCore.pyqtSignal(dict)
    filename = QtCore.pyqtSignal(dict)
    interpreted_data = QtCore.pyqtSignal(dict)
    meta_data = QtCore.pyqtSignal(dict)
    finished = QtCore.pyqtSignal()

    def __init__(self):
        QtCore.QObject.__init__(self)
        self.integrate_readouts = 1
        self.n_readout = 0
        self._stop_readout = Event()
        self.setup_raw_data_analysis()
        self.reset_lock = Lock()

    def setup_raw_data_analysis(self):
        self.interpreter = PyDataInterpreter()
        self.histograming = PyDataHistograming()
        self.interpreter.set_warning_output(False)
        self.histograming.set_no_scan_parameter()
        self.histograming.create_occupancy_hist(True)
        self.histograming.create_rel_bcid_hist(True)
        self.histograming.create_tot_hist(True)
        self.histograming.create_tdc_hist(True)

    def connect(self, socket_addr):
        self.socket_addr = socket_addr
        self.context = zmq.Context()
        self.socket_pull = self.context.socket(zmq.SUB)  # subscriber
        self.socket_pull.setsockopt(zmq.SUBSCRIBE, "")  # do not filter any data
        self.socket_pull.connect(self.socket_addr)

    @pyqtSlot(float)
    def on_set_integrate_readouts(self, value):
        self.integrate_readouts = value

    #     @pyqtSlot()
    def reset(self):
        with self.reset_lock:
            self.histograming.reset()
            self.interpreter.reset()
            self.n_readout = 0

    def analyze_raw_data(self, raw_data):
        self.interpreter.interpret_raw_data(raw_data)
        self.histograming.add_hits(self.interpreter.get_hits())

    @pyqtSlot()
    def process_data(self):  # infinite loop via QObject.moveToThread(), does not block event loop
        while not self._stop_readout.wait(0.01):  # use wait(), do not block here
            with self.reset_lock:
                try:
                    meta_data = self.socket_pull.recv_json(flags=zmq.NOBLOCK)
                except zmq.Again:
                    pass
                else:
                    name = meta_data.pop("name")
                    if name == "ReadoutData":
                        data = self.socket_pull.recv()
                        # reconstruct numpy array
                        buf = buffer(data)
                        dtype = meta_data.pop("dtype")
                        shape = meta_data.pop("shape")
                        data_array = np.frombuffer(buf, dtype=dtype).reshape(shape)
                        # count readouts and reset
                        self.n_readout += 1
                        if self.integrate_readouts != 0 and self.n_readout % self.integrate_readouts == 0:
                            self.histograming.reset()
                            # we do not want to reset interpreter to keep the error counters
                        #                         self.interpreter.reset()
                        # interpreted data
                        self.analyze_raw_data(data_array)
                        if (
                            self.integrate_readouts == 0
                            or self.n_readout % self.integrate_readouts == self.integrate_readouts - 1
                        ):
                            interpreted_data = {
                                "occupancy": self.histograming.get_occupancy(),
                                "tot_hist": self.histograming.get_tot_hist(),
                                "tdc_counters": self.interpreter.get_tdc_counters(),
                                "error_counters": self.interpreter.get_error_counters(),
                                "service_records_counters": self.interpreter.get_service_records_counters(),
                                "trigger_error_counters": self.interpreter.get_trigger_error_counters(),
                                "rel_bcid_hist": self.histograming.get_rel_bcid_hist(),
                            }
                            self.interpreted_data.emit(interpreted_data)
                        # meta data
                        meta_data.update(
                            {"n_hits": self.interpreter.get_n_hits(), "n_events": self.interpreter.get_n_events()}
                        )
                        self.meta_data.emit(meta_data)
                    elif name == "RunConf":
                        self.run_config_data.emit(meta_data)
                    elif name == "GlobalRegisterConf":
                        trig_count = int(meta_data["conf"]["Trig_Count"])
                        self.interpreter.set_trig_count(trig_count)
                        self.global_config_data.emit(meta_data)
                    elif name == "Reset":
                        self.histograming.reset()
                        self.interpreter.reset()
                        self.run_start.emit()
                    elif name == "Filename":
                        self.filename.emit(meta_data)
        self.finished.emit()

    #     @pyqtSlot()
    def stop(self):
        self._stop_readout.set()
Ejemplo n.º 4
0
class DataWorker(QtCore.QObject):
    connected = QtCore.pyqtSignal(bool)
    data_ready = QtCore.pyqtSignal(tuple, list)

    def __init__(self):
        QtCore.QObject.__init__(self)
        self.integrate_readouts = 0
        self.n_readout = 0
        self.setup_raw_data_analysis()

    def setup_raw_data_analysis(self):
        self.interpreter = PyDataInterpreter()
        self.histograming = PyDataHistograming()
        self.interpreter.set_warning_output(False)
        self.histograming.set_no_scan_parameter()
        self.histograming.create_occupancy_hist(True)
        self.histograming.create_rel_bcid_hist(True)
        self.histograming.create_tot_hist(True)
        self.histograming.create_tdc_hist(True)

    def connect(self, socket_addr):
        self.socket_addr = socket_addr
        self.context = zmq.Context()
        self.socket = self.context.socket(zmq.PULL)
        self.socket.connect(self.socket_addr)
        self.poller = zmq.Poller()  # poll needed to be able to return QThread
        self.poller.register(self.socket, zmq.POLLIN)
        self.connected.emit(True)

    def set_integrate_readouts(self, value):
        self.integrate_readouts = value

    def recv_data(self, flags=0, copy=True, track=False):
        if self.poller.poll(10):
            meta_data = self.socket.recv_json(flags=flags)
            msg = self.socket.recv(flags=flags, copy=copy, track=track)
            array = np.fromstring(msg, dtype=meta_data['dtype'])
            return array.reshape(meta_data['shape']), meta_data['timestamp_start'], meta_data['timestamp_stop'], meta_data['readout_error'], re.sub(r'\bOrderedDict\b|[()\[\],\']', '', meta_data['scan_parameters'])
        else:
            return None, None, None, None, None

    def analyze_raw_data(self, raw_data):
        self.interpreter.interpret_raw_data(raw_data)
        self.histograming.add_hits(self.interpreter.get_hits())

    def process_data(self):
        data = self.recv_data()  # poll on ZMQ queue for data
        if data[1]:  # identify non empty data by existing time stamp
            self.n_readout += 1
            if self.integrate_readouts and self.n_readout % self.integrate_readouts == 0:
                self.histograming.reset()
            self.analyze_raw_data(data[0])
            interpreted_data = self.histograming.get_occupancy(), self.histograming.get_tot_hist(), self.interpreter.get_tdc_counters(), self.interpreter.get_error_counters(), self.interpreter.get_service_records_counters(), self.interpreter.get_trigger_error_counters(), self.histograming.get_rel_bcid_hist()
            self.data_ready.emit(interpreted_data, [data[1], data[2], data[3], data[4]])
        QtCore.QTimer.singleShot(0.0001, self.process_data)

    def __del__(self):
        self.socket.close()
        self.context.term()
Ejemplo n.º 5
0
class DataWorker(QtCore.QObject):
    run_start = QtCore.pyqtSignal()
    run_config_data = QtCore.pyqtSignal(dict)
    global_config_data = QtCore.pyqtSignal(dict)
    filename = QtCore.pyqtSignal(dict)
    interpreted_data = QtCore.pyqtSignal(dict)
    meta_data = QtCore.pyqtSignal(dict)
    finished = QtCore.pyqtSignal()

    def __init__(self):
        QtCore.QObject.__init__(self)
        self.integrate_readouts = 1
        self.n_readout = 0
        self._stop_readout = Event()
        self.setup_raw_data_analysis()
        self.reset_lock = Lock()

    def setup_raw_data_analysis(self):
        self.interpreter = PyDataInterpreter()
        self.histograming = PyDataHistograming()
        self.interpreter.set_warning_output(False)
        self.histograming.set_no_scan_parameter()
        self.histograming.create_occupancy_hist(True)
        self.histograming.create_rel_bcid_hist(True)
        self.histograming.create_tot_hist(True)
        self.histograming.create_tdc_hist(True)

    def connect(self, socket_addr):
        self.socket_addr = socket_addr
        self.context = zmq.Context()
        self.socket_pull = self.context.socket(zmq.SUB)  # subscriber
        self.socket_pull.setsockopt(zmq.SUBSCRIBE,
                                    '')  # do not filter any data
        self.socket_pull.connect(self.socket_addr)

    @pyqtSlot(float)
    def on_set_integrate_readouts(self, value):
        self.integrate_readouts = value

#     @pyqtSlot()

    def reset(self):
        with self.reset_lock:
            self.histograming.reset()
            self.interpreter.reset()
            self.n_readout = 0

    def analyze_raw_data(self, raw_data):
        self.interpreter.interpret_raw_data(raw_data)
        self.histograming.add_hits(self.interpreter.get_hits())

    @pyqtSlot()
    def process_data(
        self
    ):  # infinite loop via QObject.moveToThread(), does not block event loop
        while (not self._stop_readout.wait(0.01)
               ):  # use wait(), do not block here
            with self.reset_lock:
                try:
                    meta_data = self.socket_pull.recv_json(flags=zmq.NOBLOCK)
                except zmq.Again:
                    pass
                else:
                    name = meta_data.pop('name')
                    if name == 'ReadoutData':
                        data = self.socket_pull.recv()
                        # reconstruct numpy array
                        buf = buffer(data)
                        dtype = meta_data.pop('dtype')
                        shape = meta_data.pop('shape')
                        data_array = np.frombuffer(buf,
                                                   dtype=dtype).reshape(shape)
                        # count readouts and reset
                        self.n_readout += 1
                        if self.integrate_readouts != 0 and self.n_readout % self.integrate_readouts == 0:
                            self.histograming.reset()
                            # we do not want to reset interpreter to keep the error counters
        #                         self.interpreter.reset()
        # interpreted data
                        self.analyze_raw_data(data_array)
                        if self.integrate_readouts == 0 or self.n_readout % self.integrate_readouts == self.integrate_readouts - 1:
                            interpreted_data = {
                                'occupancy':
                                self.histograming.get_occupancy(),
                                'tot_hist':
                                self.histograming.get_tot_hist(),
                                'tdc_counters':
                                self.interpreter.get_tdc_counters(),
                                'error_counters':
                                self.interpreter.get_error_counters(),
                                'service_records_counters':
                                self.interpreter.get_service_records_counters(
                                ),
                                'trigger_error_counters':
                                self.interpreter.get_trigger_error_counters(),
                                'rel_bcid_hist':
                                self.histograming.get_rel_bcid_hist()
                            }
                            self.interpreted_data.emit(interpreted_data)
                        # meta data
                        meta_data.update({
                            'n_hits':
                            self.interpreter.get_n_hits(),
                            'n_events':
                            self.interpreter.get_n_events()
                        })
                        self.meta_data.emit(meta_data)
                    elif name == 'RunConf':
                        self.run_config_data.emit(meta_data)
                    elif name == 'GlobalRegisterConf':
                        trig_count = int(meta_data['conf']['Trig_Count'])
                        self.interpreter.set_trig_count(trig_count)
                        self.global_config_data.emit(meta_data)
                    elif name == 'Reset':
                        self.histograming.reset()
                        self.interpreter.reset()
                        self.run_start.emit()
                    elif name == 'Filename':
                        self.filename.emit(meta_data)
        self.finished.emit()


#     @pyqtSlot()

    def stop(self):
        self._stop_readout.set()