Exemplo n.º 1
0
def main():

    # process arguments
    parser = argparse.ArgumentParser()
    parser.add_argument('-p', type=int, choices=range(0, 8), default=0,
                        help='platform (default 0)')
    parser.add_argument('-C', metavar='COLLECT_HOST', default='localhost',
                        help='collection host (default localhost)')
    parser.add_argument('-t', type=int, metavar='TIMEOUT', default=10000,
                        help='timeout msec (default 10000)')
    group = parser.add_mutually_exclusive_group()
    group.add_argument('--state', choices=DaqControl.states)
    group.add_argument('--transition', choices=DaqControl.transitions)
    group.add_argument('--monitor', action="store_true")
    group.add_argument('--config', metavar='ALIAS', help='configuration alias')
    group.add_argument('-B', action="store_true", help='shortcut for --config BEAM')
    args = parser.parse_args()

    config = None
    if args.config:
        config = args.config
    elif args.B:
        config = "BEAM"

    # instantiate DaqControl object
    control = DaqControl(host=args.C, platform=args.p, timeout=args.t)

    if args.state:
        # change the state
        rv = control.setState(args.state)
        if rv is not None:
            print('Error: %s' % rv)

    elif args.transition:
        # transition request
        rv = control.setTransition(args.transition)
        if rv is not None:
            print('Error: %s' % rv)

    elif config:
        # config alias request
        rv = control.setConfig(config)
        if rv is not None:
            print('Error: %s' % rv)

    elif args.monitor:
        # monitor the status
        while True:
            part1, part2, part3 = control.monitorStatus()
            if part1 is None:
                break
            elif part1 == 'error':
                print('error: %s' % part2)
            else:
                print('transition: %-11s  state: %-11s  config: %s' % (part1, part2, part3))

    else:
        # print current state
        transition, state, config_alias = control.getStatus()
        print('last transition: %s  state: %s  configuration alias: %s' % (transition, state, config_alias))
Exemplo n.º 2
0
    def proc():
        print('DaqControl.transitions:', DaqControl.transitions)
        print('DaqControl.states  :', DaqControl.states)

        o = DaqControl(host='localhost', platform=6, timeout=5000)  # msec
        daq_control.set_daq_control(o)

        state = daq_control().getState()
        print('DaqControl.states  :', state)
Exemplo n.º 3
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-B', metavar='PVBASE', required=True, help='PV base')
    parser.add_argument('-p', type=int, choices=range(0, 8), default=0,
                        help='platform (default 0)')
    parser.add_argument('-x', metavar='XPM', type=int, required=True, help='master XPM')
    parser.add_argument('-C', metavar='COLLECT_HOST', default='localhost',
                        help='collection host (default localhost)')
    parser.add_argument('-t', type=int, metavar='TIMEOUT', default=10000,
                        help='timeout msec (default 10000)')
    parser.add_argument('-c', type=int, metavar='READOUT_COUNT', default=1, help='# of events to aquire at each step (default 1)')
    parser.add_argument('-g', type=int, metavar='GROUP_MASK', help='bit mask of readout groups (default 1<<plaform)')
    parser.add_argument('--config', metavar='ALIAS', help='configuration alias (e.g. BEAM)')
    parser.add_argument('-v', action='store_true', help='be verbose')
    args = parser.parse_args()

    if args.g is not None:
        if args.g < 1 or args.g > 255:
            parser.error('readout group mask (-g) must be 1-255')

    if args.c < 1:
        parser.error('readout count (-c) must be >= 1')

    # instantiate DaqControl object
    control = DaqControl(host=args.C, platform=args.p, timeout=args.t)

    try:
        instrument = control.getInstrument()
    except KeyboardInterrupt:
        instrument = None

    if instrument is None:
        sys.exit('Error: failed to read instrument name (check -C <COLLECT_HOST>)')

    # configure logging handlers
    if args.v:
        level=logging.DEBUG
    else:
        level=logging.WARNING
    logger = SysLog(instrument=instrument, level=level)
    logging.info('logging initialized')

    # get initial DAQ state
    daqState = control.getState()
    logging.info('initial state: %s' % daqState)
    if daqState == 'error':
        sys.exit(1)

    # optionally set BEAM or NOBEAM
    if args.config is not None:
        # config alias request
        rv = control.setConfig(args.config)
        if rv is not None:
            logging.error('%s' % rv)

    # instantiate MyDAQ
    mydaq = MyDAQ(control, daqState=daqState, args=args)

    mydaq.stage()

    # -- begin script --------------------------------------------------------

    configure_dict = {"configure": {"reconfig_keys": ["tmoopal_0:user.start_ns", "tmoopal_0:user.gate_ns"]}}

    for start_ns in (0, 1000):
        for gate_ns in (10000, 20000):
            beginstep_dict = {"beginstep": {"reconfig_values": {"tmoopal_0:user.start_ns": start_ns, "tmoopal_0:user.gate_ns": gate_ns}}}
            # trigger
            mydaq.trigger(phase1Info = dict(configure_dict, **beginstep_dict))

    # -- end script ----------------------------------------------------------

    mydaq.unstage()

    mydaq.push_socket.send_string('shutdown') #shutdown the daq communicator thread
    mydaq.comm_thread.join()
Exemplo n.º 4
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-p',
                        type=int,
                        choices=range(0, 8),
                        default=0,
                        help='platform (default 0)')
    parser.add_argument('-C',
                        metavar='COLLECT_HOST',
                        default='localhost',
                        help='collection host (default localhost)')
    parser.add_argument('-t',
                        type=int,
                        metavar='TIMEOUT',
                        default=10000,
                        help='timeout msec (default 10000)')
    group = parser.add_mutually_exclusive_group()
    group.add_argument('--config', metavar='ALIAS', help='configuration alias')
    group.add_argument('-B',
                       action="store_true",
                       help='shortcut for --config BEAM')
    args = parser.parse_args()

    # instantiate DaqControl object
    control = DaqControl(host=args.C, platform=args.p, timeout=args.t)

    config = None
    if args.config:
        config = args.config
    elif args.B:
        config = "BEAM"

    if config:
        # config alias request
        rv = control.setConfig(config)
        if rv is not None:
            print('Error: %s' % rv)

    RE = RunEngine({})

    # cpo thinks this is more for printout of each step
    from bluesky.callbacks.best_effort import BestEffortCallback
    bec = BestEffortCallback()

    # Send all metadata/data captured to the BestEffortCallback.
    RE.subscribe(bec)

    # Make plots update live while scans run.
    #from bluesky.utils import install_kicker
    #install_kicker()

    from ophyd.sim import det, motor
    from bluesky.plans import scan, count
    from bluesky.preprocessors import fly_during_wrapper

    mydaq = MyDAQ(control, motor)
    dets = [mydaq]  # just one in this case, but it could be more than one

    print('motor', motor.position,
          motor.name)  # in some cases we have to look at ".value"
    RE(scan(dets, motor, -1, 1, 3))
    print('motor', motor.position)
    #RE(count(dets, num=3))

    # only 1 callback! and 3 steps inside it.  doesn't feel useful for us
    #RE(fly_during_wrapper(count([det], num=3), dets))

    mydaq.push_socket.send_string('shutdown')  #shutdown the daq thread
    mydaq.comm_thread.join()
Exemplo n.º 5
0
def main():

    # process arguments
    parser = argparse.ArgumentParser()
    parser.add_argument('-p', type=int, choices=range(0, 8), default=0,
                        help='platform (default 0)')
    parser.add_argument('-P', metavar='INSTRUMENT', required=True,
                        help='instrument name (required)')
    parser.add_argument('-C', metavar='COLLECT_HOST', default='localhost',
                        help='collection host (default localhost)')
    parser.add_argument('-t', type=int, metavar='TIMEOUT', default=10000,
                        help='timeout msec (default 10000)')
    group = parser.add_mutually_exclusive_group()
    group.add_argument('--state', choices=DaqControl.states)
    group.add_argument('--transition', choices=DaqControl.transitions)
    group.add_argument('--monitor', action="store_true")
    group.add_argument('--config', metavar='ALIAS', help='configuration alias')
    group.add_argument('--record', type=int, choices=range(0, 2), help='recording flag')
    group.add_argument('--bypass', type=int, choices=range(0, 2), help='bypass active detectors file flag')
    group.add_argument('-B', action="store_true", help='shortcut for --config BEAM')
    args = parser.parse_args()

    config = None
    if args.config:
        config = args.config
    elif args.B:
        config = "BEAM"

    # instantiate DaqControl object
    control = DaqControl(host=args.C, platform=args.p, timeout=args.t)

    # verify instrument name match
    instr = control.getInstrument()
    if instr is None:
        exit('Error: failed to read instrument name')
    elif instr != args.P:
        exit('Error: instrument name \'%s\' does not match \'%s\'' %
              (args.P, instr))

    if args.state:
        # change the state
        rv = control.setState(args.state)
        if rv is not None:
            print('Error: %s' % rv)

    elif args.transition:
        # transition request
        rv = control.setTransition(args.transition)
        if rv is not None:
            print('Error: %s' % rv)

    elif config:
        # config alias request
        rv = control.setConfig(config)
        if rv is not None:
            print('Error: %s' % rv)

    elif args.record is not None:
        # recording flag request
        if args.record == 0:
            rv = control.setRecord(False)
        else:
            rv = control.setRecord(True)
        if rv is not None:
            print('Error: %s' % rv)

    elif args.bypass is not None:
        # active detectors file bypass flag request
        if args.bypass == 0:
            rv = control.setBypass(False)
        else:
            rv = control.setBypass(True)
        if rv is not None:
            print('Error: %s' % rv)

    elif args.monitor:
        # monitor the status
        while True:
            part1, part2, part3, part4 = control.monitorStatus()
            if part1 is None:
                break
            elif part1 == 'error':
                print('error: %s' % part2)
            elif part1 == 'fileReport':
                print('data file: %s' % part2)
            elif part1 == 'progress':
                print('progress: %s (%d/%d)' % (part2, part3, part4))
            else:
                print('transition: %-11s  state: %-11s  config: %s  recording: %s' % (part1, part2, part3, part4))

    else:
        # print current state
        transition, state, config_alias, recording, platform = control.getStatus()
        print('last transition: %s  state: %s  configuration alias: %s  recording: %s' % (transition, state, config_alias, recording))
Exemplo n.º 6
0
def main():

    # Process arguments
    parser = argparse.ArgumentParser()
    parser.add_argument('-p',
                        type=int,
                        choices=range(0, 8),
                        default=0,
                        help='platform (default 0)')
    parser.add_argument('-C',
                        metavar='COLLECT_HOST',
                        default='localhost',
                        help='collection host')
    parser.add_argument('-t',
                        type=int,
                        metavar='TIMEOUT',
                        default=2000,
                        help='timeout msec (default 2000)')
    parser.add_argument('-v', action='store_true', help='be verbose')
    args = parser.parse_args()
    platform = args.p

    # instantiate DaqControl object
    control = DaqControl(host=args.C, platform=args.p, timeout=args.t)

    # get instrument/hutch name
    instrument = None
    try:
        instrument = control.getInstrument()
    except Exception as ex:
        print('getInstrument() Exception: %s' % ex)
    if instrument is None:
        return

    try:
        body = control.getPlatform()
    except Exception as ex:
        print('getPlatform() Exception: %s' % ex)
    else:
        displayList = []
        try:
            for level in body:
                for k, v in body[level].items():
                    host = v['proc_info']['host']
                    if v['active'] == 1:
                        host = host + ' *'
                    alias = v['proc_info']['alias']
                    pid = v['proc_info']['pid']
                    if level == 'drp' and v['active'] == 1:
                        display_tuple = (level, alias,
                                         "%-16s %s/%s/%-16s\n%42s: %s" % \
                                         (alias, level, pid, host,       \
                                          'readout group', v['det_info']['readout']))
                    else:
                        display_tuple = (level, alias, "%-16s %s/%s/%-16s" %
                                         (alias, level, pid, host))
                    displayList.append(display_tuple)
        except Exception:
            print('----- body -----')
            pprint.pprint(body)
            raise
        else:
            if args.v:
                print('getPlatform() reply:')
                pprint.pprint(body)
            print("Partition|         Node")
            print("id/name  | alias            level/pid/host (* = active)")
            print(
                "---------+-----------------------------------------------------"
            )
            print("%s/%-8s " % (platform, instrument), end='')
            firstLine = True
            for nn in sorted(displayList, key=itemgetter(0, 1)):
                if firstLine:
                    print(nn[2])
                    firstLine = False
                else:
                    print("          ", nn[2])
            if firstLine:
                print()
Exemplo n.º 7
0
parser.add_argument('--config',
                    metavar='ALIAS',
                    default='BEAM',
                    help='configuration alias (default BEAM)')
parser.add_argument('-v', action='store_true', help='be verbose')
args = parser.parse_args()

if args.g is not None:
    if args.g < 1 or args.g > 255:
        parser.error('readout group mask (-g) must be 1-255')

if args.c < 1:
    parser.error('readout count (-c) must be >= 1')

# instantiate DaqControl object
control = DaqControl(host=args.C, platform=args.p, timeout=args.t)

# configure logging handlers
if args.v:
    print(f'Trying to connect with DAQ at host {args.C} platform {args.p}...')
instrument = control.getInstrument()
if instrument is None:
    print(f'Failed to connect with DAQ at host {args.C} platform {args.p}')
    sys.exit(1)

if args.v:
    level = logging.DEBUG
else:
    level = logging.WARNING
logger = SysLog(instrument=instrument, level=level)
logging.info('logging initialized')
Exemplo n.º 8
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-B', metavar='PVBASE', required=True, help='PV base')
    parser.add_argument('-p',
                        type=int,
                        choices=range(0, 8),
                        default=0,
                        help='platform (default 0)')
    parser.add_argument('-x',
                        metavar='XPM',
                        type=int,
                        required=True,
                        help='master XPM')
    parser.add_argument('-C',
                        metavar='COLLECT_HOST',
                        default='localhost',
                        help='collection host (default localhost)')
    parser.add_argument('-t',
                        type=int,
                        metavar='TIMEOUT',
                        default=10000,
                        help='timeout msec (default 10000)')
    parser.add_argument('-c',
                        type=int,
                        metavar='READOUT_COUNT',
                        default=1,
                        help='# of events to aquire at each step (default 1)')
    parser.add_argument('-g',
                        type=int,
                        metavar='GROUP_MASK',
                        help='bit mask of readout groups (default 1<<plaform)')
    parser.add_argument('--config',
                        metavar='ALIAS',
                        help='configuration alias (e.g. BEAM)')
    parser.add_argument('-v', action='store_true', help='be verbose')
    args = parser.parse_args()

    if args.g is not None:
        if args.g < 1 or args.g > 255:
            parser.error('readout group mask (-g) must be 1-255')

    if args.c < 1:
        parser.error('readout count (-c) must be >= 1')

    # instantiate DaqControl object
    control = DaqControl(host=args.C, platform=args.p, timeout=args.t)

    # configure logging handlers
    instrument = control.getInstrument()
    if args.v:
        level = logging.DEBUG
    else:
        level = logging.WARNING
    logger = SysLog(instrument=instrument, level=level)
    logging.info('logging initialized')

    # get initial DAQ state
    daqState = control.getState()
    logging.info('initial state: %s' % daqState)
    if daqState == 'error':
        sys.exit(1)

    # optionally set BEAM or NOBEAM
    if args.config is not None:
        # config alias request
        rv = control.setConfig(args.config)
        if rv is not None:
            logging.error('%s' % rv)

    RE = RunEngine({})

    # cpo thinks this is more for printout of each step
    from bluesky.callbacks.best_effort import BestEffortCallback
    bec = BestEffortCallback()

    # Send all metadata/data captured to the BestEffortCallback.
    RE.subscribe(bec)

    from ophyd.sim import motor1, motor2
    from bluesky.plans import scan

    # instantiate MyDAQ object
    mydaq = MyDAQ(control, daqState=daqState, args=args)
    dets = [mydaq]  # just one in this case, but it could be more than one

    # configure MyDAQ object with a set of motors
    mydaq.configure(motors=[motor1, motor2])

    # Scan motor1 from -10 to 10 and motor2 from -0.1 to 0.1, stopping
    # at 15 equally-spaced points along the way and reading dets.
    RE(scan(dets, motor1, -10, 10, motor2, -0.1, 0.1, 15))

    mydaq.push_socket.send_string('shutdown')  #shutdown the daq thread
    mydaq.comm_thread.join()
Exemplo n.º 9
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-B', metavar='PVBASE', required=True, help='PV base')
    parser.add_argument('-p',
                        type=int,
                        choices=range(0, 8),
                        default=0,
                        help='platform (default 0)')
    parser.add_argument('-x',
                        metavar='XPM',
                        type=int,
                        required=True,
                        help='master XPM')
    parser.add_argument('-C',
                        metavar='COLLECT_HOST',
                        default='localhost',
                        help='collection host (default localhost)')
    parser.add_argument('-t',
                        type=int,
                        metavar='TIMEOUT',
                        default=10000,
                        help='timeout msec (default 10000)')
    parser.add_argument('-c',
                        type=int,
                        metavar='READOUT_COUNT',
                        default=1,
                        help='# of events to aquire at each step (default 1)')
    parser.add_argument('-g',
                        type=int,
                        metavar='GROUP_MASK',
                        help='bit mask of readout groups (default 1<<plaform)')
    parser.add_argument('--config',
                        metavar='ALIAS',
                        help='configuration alias (e.g. BEAM)')
    parser.add_argument('-v', action='store_true', help='be verbose')
    args = parser.parse_args()

    if args.g is not None:
        if args.g < 1 or args.g > 255:
            parser.error('readout group mask (-g) must be 1-255')

    if args.c < 1:
        parser.error('readout count (-c) must be >= 1')

    # instantiate DaqControl object
    control = DaqControl(host=args.C, platform=args.p, timeout=args.t)

    try:
        instrument = control.getInstrument()
    except KeyboardInterrupt:
        instrument = None

    if instrument is None:
        sys.exit(
            'Error: failed to read instrument name (check -C <COLLECT_HOST>)')

    # configure logging handlers
    if args.v:
        level = logging.DEBUG
    else:
        level = logging.WARNING
    logger = SysLog(instrument=instrument, level=level)
    logging.info('logging initialized')

    # get initial DAQ state
    daqState = control.getState()
    logging.info('initial state: %s' % daqState)
    if daqState == 'error':
        sys.exit(1)

    # optionally set BEAM or NOBEAM
    if args.config is not None:
        # config alias request
        rv = control.setConfig(args.config)
        if rv is not None:
            logging.error('%s' % rv)

    # instantiate ConfigurationScan
    scan = ConfigurationScan(control, daqState=daqState, args=args)

    scan.stage()

    # -- begin script --------------------------------------------------------

    # PV scan setup
    motors = [
        MyFloatPv("tmoopal_step_value"),
        MyStringPv("tmoopal_step_docstring")
    ]
    scan.configure(motors=motors)

    # configuration scan setup
    keys_dict = {
        "configure": {
            "step_keys": ["tmoopal_0:user.black_level"],
            "NamesBlockHex":
            scan.getBlock(transitionid=DaqControl.transitionId['Configure'],
                          add_names=True,
                          add_shapes_data=False).hex()
        }
    }
    # scan loop
    for black_level in [15, 31, 47]:
        # update
        scan.update(value=scan.step_count())
        values_dict = \
          {"beginstep": {"step_values":        {"tmoopal_0:user.black_level": black_level},
                         "ShapesDataBlockHex": scan.getBlock(transitionid=DaqControl.transitionId['BeginStep'],
                                                             add_names=False, add_shapes_data=True).hex()}}
        # trigger
        scan.trigger(phase1Info={**keys_dict, **values_dict})

    # -- end script ----------------------------------------------------------

    scan.unstage()

    scan.push_socket.send_string(
        'shutdown')  #shutdown the daq communicator thread
    scan.comm_thread.join()
Exemplo n.º 10
0
# Set up the lcls2 daq stuff
import logging

from psdaq.control.control import DaqControl
from psdaq.control.DaqScan import DaqScan
from types import SimpleNamespace

logger = logging.getLogger(__name__)

_control = DaqControl(
    host='drp-neh-ctl001',
    platform=2,
    timeout=1000,
)

_instr = _control.getInstrument()
if _instr is None:
    err = 'Failed to connect to LCLS-II DAQ'
    logger.error(err)

_state = _control.getState()
if _state == 'error':
    err = 'Daq is in error state'
    logger.error(err)

# Construct the args that DaqScan is looking for
args = SimpleNamespace(
    v=True,  # Verbosity
    B='DAQ:NEH',  # PV Base
    detname='scan',  # Detector name
    scantype='scan',  # scan type
Exemplo n.º 11
0
def main():

    # Process arguments
    parser = argparse.ArgumentParser(
        epilog='For multisegment detector, specify drp alias without _N suffix.'
    )
    parser.add_argument('-p',
                        metavar='PLATFORM',
                        type=int,
                        choices=range(0, 8),
                        default=0,
                        help='platform (default 0)')
    parser.add_argument('-C',
                        metavar='COLLECT_HOST',
                        default='localhost',
                        help='collection host (default localhost)')
    parser.add_argument('-t',
                        type=int,
                        metavar='TIMEOUT',
                        default=2000,
                        help='timeout msec (default 2000)')
    parser.add_argument('-R',
                        metavar='READOUT_GROUP',
                        type=int,
                        choices=range(0, 8),
                        help='readout group (0-7, default platform)')
    parser.add_argument('-s',
                        metavar='SELECT',
                        action='append',
                        help='select one alias (may be repeated)')
    parser.add_argument('--select-all',
                        action='store_true',
                        help='select all',
                        dest='select_all')
    parser.add_argument('-u',
                        metavar='UNSELECT',
                        action='append',
                        help='unselect one alias (may be repeated)')
    args = parser.parse_args()

    platform = args.p
    if args.R is None:
        readout = platform
    else:
        readout = args.R

    # instantiate DaqControl object
    control = DaqControl(host=args.C, platform=args.p, timeout=args.t)

    try:
        body = control.getPlatform()
    except Exception as ex:
        print('getPlatform(): %s' % ex)
    except KeyboardInterrupt:
        pass
    else:
        changed = False
        try:
            for level in body:
                for k, v in body[level].items():
                    alias = v['proc_info']['alias']

                    # select ...
                    if level == 'drp':
                        if args.select_all or drp_match(alias, args.s):
                            if v['active'] != 1 or v['det_info'][
                                    'readout'] != readout:
                                changed = True
                                v['active'] = 1
                                v['det_info']['readout'] = readout
                    else:
                        if args.select_all or common_match(alias, args.s):
                            if v['active'] != 1:
                                changed = True
                                v['active'] = 1

                    # unselect ...
                    match = False
                    if level == 'drp':
                        if drp_match(alias, args.u):
                            match = True
                    else:
                        if common_match(alias, args.u):
                            match = True
                    if match:
                        if v['active'] != 0:
                            changed = True
                            v['active'] = 0
        except Exception:
            pprint.pprint(body)
            raise
        else:
            if changed:
                try:
                    retval = control.selectPlatform(body)
                except Exception as ex:
                    print('selectPlatform(): %s' % ex)
                except KeyboardInterrupt:
                    pass
                else:
                    if 'err_info' in retval:
                        print('Error: %s' % retval['err_info'])
Exemplo n.º 12
0
# Set up the lcls2 daq stuff
import logging

from psdaq.control.control import DaqControl
from psdaq.control.DaqScan import DaqScan
from types import SimpleNamespace


logger = logging.getLogger(__name__)

_control = DaqControl(
    host='drp-ued-cmp002',
    platform=0,
    timeout=1000,
    )

_instr = _control.getInstrument()
if _instr is None:
    err = 'Failed to connect to LCLS-II DAQ'
    logger.error(err)

_state = _control.getState()
if _state == 'error':
    err = 'Daq is in error state'
    logger.error(err)

# Construct the args that DaqScan is looking for
args = SimpleNamespace(
    v=True,             # Verbosity
    B='DAQ:UED',        # PV Base
    detname='scan',     # Detector name