Пример #1
0
def inner_count(detectors, preset, temporary=False, threaded=False):
    """Inner counting function for normal counts with single-point dataset.

    If *temporary* is true, use a dataset without data sinks.
    If *threaded* is true, do a non-blocking acquisition.

    """
    # stop previous inner_count / acquisition thread if available
    stop_acquire_thread()

    dataman = session.experiment.data

    if session.experiment.forcescandata:
        dataman.beginScan(info=preset.get(
            'info',
            'count(%s)' % ', '.join('%s=%s' % kv for kv in preset.items())),
                          npoints=1,
                          environment=session.experiment.sampleenv,
                          detectors=detectors,
                          preset=preset)

    # start counting
    args = dict(detectors=detectors,
                environment=session.experiment.sampleenv,
                preset=preset)
    if temporary:
        point = dataman.beginTemporaryPoint(**args)
    else:
        point = dataman.beginPoint(**args)
    read_environment(session.experiment.sampleenv)

    def _acquire_func():
        try:
            acquire(point, preset)
        finally:
            dataman.finishPoint()
            if session.experiment.forcescandata:
                dataman.finishScan()

    if threaded:
        session._thd_acquire = createThread("acquire", _acquire_func)
        return None
    else:
        _acquire_func()

    result, msg = CountResult.from_point(point)
    if not session.experiment.forcescandata:
        for filename in point.filenames:
            msg.append('file = %s' % filename)
        session.log.info('count: %s', ', '.join(msg))

    return result
Пример #2
0
    def run(self):
        if not self._subscan and getattr(session, '_currentscan', None):
            raise NicosError('cannot start scan while another scan is running')
        # stop previous inner_count / acquisition thread if available
        stop_acquire_thread()

        session._currentscan = self
        # XXX(dataapi): this is too early, dataset has no number yet
        session.beginActionScope(self.shortDesc())
        try:
            self._inner_run()
        finally:
            session.endActionScope()
            session._currentscan = None
        return self.dataset