예제 #1
0
def watch_data(scan_node, scan_new_callback, scan_data_callback, scan_end_callback):
    scan_info = scan_node._info.get_all()
    if scan_info["type"] == "ct":
        return

    timescan = scan_info["type"] == "timescan"
    if not timescan:
        del scan_info["motors"][0]
    scan_info["labels"] = scan_info["motors"] + scan_info["counters"]
    ndata = len(scan_info["labels"])
    del scan_info["motors"]
    del scan_info["counters"]
    scan_data = dict()
    data_indexes = dict()

    scan_new_callback(scan_info)

    scan_data_iterator = DataNodeIterator(scan_node)
    for event_type, event_data in scan_data_iterator.walk_events(filter="zerod"):
        if event_type is scan_data_iterator.NEW_DATA_IN_CHANNEL_EVENT:
            zerod, channel_name = event_data
            if not timescan and channel_name == "timestamp":
                continue
            data_channel = zerod.get_channel(channel_name)
            data = data_channel.get(data_indexes.setdefault(channel_name, 0), -1)
            data_indexes[channel_name] += len(data)
            scan_data.setdefault(channel_name, []).extend(data)
            if len(scan_data) == ndata and all_equal(data_indexes.values()):
                scan_data_callback(scan_info, scan_data)
                if data_indexes[channel_name] == scan_info["npoints"]:
                    scan_end_callback(scan_info)
                scan_data = dict()
예제 #2
0
def watch_data(scan_node, scan_new_callback, scan_data_callback, scan_end_callback):
    scan_info = scan_node._info.get_all()
    if scan_info["type"] == "ct":
        return

    timescan = scan_info["type"] == "timescan"
    if not timescan:
        del scan_info["motors"][0]
    scan_info["labels"] = scan_info["motors"] + scan_info["counters"]
    ndata = len(scan_info["labels"])
    del scan_info["motors"]
    del scan_info["counters"]
    scan_data = dict()
    data_indexes = dict()

    scan_new_callback(scan_info)

    scan_data_iterator = DataNodeIterator(scan_node)
    for event_type, event_data in scan_data_iterator.walk_events(filter="zerod"):
        if event_type is scan_data_iterator.NEW_DATA_IN_CHANNEL_EVENT:
            zerod, channel_name = event_data
            if not timescan and channel_name == "timestamp":
                continue
            data_channel = zerod.get_channel(channel_name)
            data = data_channel.get(data_indexes.setdefault(channel_name, 0), -1)
            data_indexes[channel_name] += len(data)
            scan_data.setdefault(channel_name, []).extend(data)
            if len(scan_data) == ndata and all_equal(data_indexes.itervalues()):
                scan_data_callback(scan_info, scan_data)
                if data_indexes[channel_name] == scan_info["npoints"]:
                    scan_end_callback(scan_info)
                scan_data = dict()
예제 #3
0
def watch_session(session_name, scan_new_callback, scan_data_callback,
                  scan_end_callback):
    session_node = _get_or_create_node(session_name, node_type='session')
    if session_node is not None:
        data_iterator = DataNodeIterator(session_node)

        watch_data_task = None
        last = True
        for scan_node in data_iterator.walk_from_last(filter='scan'):
            if last:
                # skip the last one, we are interested in new ones only
                last = False
                continue
            if watch_data_task:
                watch_data_task.kill()
            watch_data_task = gevent.spawn(watch_data, scan_node,
                                           scan_new_callback,
                                           scan_data_callback,
                                           scan_end_callback)
예제 #4
0
def test_iterator_over_reference_with_lima(beacon, redis_data_conn, scan_tmpdir, lima_simulator):
    npoints = 5
    exp_time = 1

    session = beacon.get("lima_test_session")
    session.setup()
    setup_globals.SCAN_SAVING.base_path=str(scan_tmpdir)
    lima_sim = getattr(setup_globals, "lima_simulator")

    scan_greenlet = gevent.spawn(scans.timescan, exp_time, lima_sim, npoints=npoints)
    
    gevent.sleep(exp_time) #sleep time to let time for session creation

    session_node = get_node(session.name)
    iterator = DataNodeIterator(session_node)

    with gevent.Timeout((npoints+1)*exp_time):
        for event_type, node in iterator.walk_events(filter='lima'):
            if event_type == DataNodeIterator.NEW_DATA_IN_CHANNEL_EVENT:
                view = node.get(from_index=0, to_index=-1)
                if len(view) == npoints:
                    break

    view_iterator = iter(view)
    img0 = view_iterator.next()

    # make another scan -> this should make a new buffer on Lima server,
    # so images from previous view cannot be retrieved from server anymore
    scans.timescan(exp_time, lima_sim, npoints=1)
   
    view_iterator2 = iter(view)

    # retrieve from file
    if EdfFile is None:
        # no Edf file module => we just check data is retrieved from file, not
        # from server memory
        assert pytest.raises(RuntimeError, view_iterator2.next)
    else:
        assert view_iterator2.next() == img0
예제 #5
0
def watch_session(
    session_name, scan_new_callback, scan_data_callback, scan_end_callback
):
    session_node = _get_or_create_node(session_name, node_type="session")
    if session_node is not None:
        data_iterator = DataNodeIterator(session_node)

        watch_data_task = None
        last = True
        for scan_node in data_iterator.walk_from_last(filter="scan"):
            if last:
                # skip the last one, we are interested in new ones only
                last = False
                continue
            if watch_data_task:
                watch_data_task.kill()
            watch_data_task = gevent.spawn(
                watch_data,
                scan_node,
                scan_new_callback,
                scan_data_callback,
                scan_end_callback,
            )