Beispiel #1
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)
Beispiel #2
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-p',
                        type=int,
                        choices=range(0, 8),
                        default=2,
                        help='platform (default 2)')
    parser.add_argument('-C',
                        metavar='COLLECT_HOST',
                        default='drp-neh-ctl001',
                        help='collection host (default drp-neh-ctl001)')
    parser.add_argument('-t',
                        type=int,
                        metavar='TIMEOUT',
                        default=20000,
                        help='timeout msec (default 20000)')
    parser.add_argument('-g',
                        type=int,
                        default=6,
                        metavar='GROUP_MASK',
                        help='bit mask of readout groups (default 1<<plaform)')
    parser.add_argument('--config',
                        metavar='ALIAS',
                        default='BEAM',
                        help='configuration alias (e.g. BEAM)')
    parser.add_argument('--detname',
                        default='epixhr_0',
                        help="detector name (default 'scan')")
    parser.add_argument('--scantype',
                        default='pedestal',
                        help="scan type (default 'scan')")
    parser.add_argument('-v', action='store_true', help='be verbose')

    parser.add_argument('--events',
                        type=int,
                        default=2000,
                        help='events per step (default 2000)')
    parser.add_argument('--record',
                        type=int,
                        choices=range(0, 2),
                        help='recording flag')

    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')
        group_mask = args.g
    else:
        group_mask = 1 << args.p

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

    keys = [f'{args.detname}:user.gain_mode']

    # 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
    logging.basicConfig(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)

    if 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)

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

    scan.stage()

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

    # PV scan setup
    motors = [MyFloatPv(ControlDef.STEP_VALUE)]
    scan.configure(motors=motors)

    my_config_data = {}
    for motor in scan.getMotors():
        my_config_data.update({motor.name: motor.position})
        # derive step_docstring from step_value
        if motor.name == ControlDef.STEP_VALUE:
            docstring = f'{{"detname": "{args.detname}", "scantype": "{args.scantype}", "step": {motor.position}}}'
            my_config_data.update({'step_docstring': docstring})

    data = {
        "motors": my_config_data,
        "timestamp": 0,
        "detname": "scan",
        "dettype": "scan",
        "scantype": args.scantype,
        "serial_number": "1234",
        "alg_name": "raw",
        "alg_version": [1, 0, 0]
    }

    configureBlock = scan.getBlock(transition="Configure", data=data)

    # config scan setup
    keys_dict = {
        "configure": {
            "step_keys": keys,
            "NamesBlockHex": configureBlock
        },
        "enable": {
            "readout_count": args.events,
            "group_mask": group_mask
        }
    }

    # scan loop
    def steps():
        for gain in range(5):
            yield int(gain)

    for step in steps():
        # update
        scan.update(value=scan.step_count())

        my_step_data = {}
        for motor in scan.getMotors():
            my_step_data.update({motor.name: motor.position})
            # derive step_docstring from step_value
            if motor.name == ControlDef.STEP_VALUE:
                #  Need an integer for "step" value.  Config scan analysis uses as an array index.
                docstring = f'{{"detname": "{args.detname}", "scantype": "{args.scantype}", "step": {int(motor.position)}}}'
                my_step_data.update({'step_docstring': docstring})

        data["motors"] = my_step_data

        beginStepBlock = scan.getBlock(transition="BeginStep", data=data)
        values_dict = \
          {"beginstep": {"step_values":        {f'{args.detname}:user.gain_mode': step},
                         "ShapesDataBlockHex": beginStepBlock}}
        # 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()
Beispiel #3
0
parser.add_argument('--config', metavar='ALIAS', default='BEAM', help='configuration alias (default BEAM)')
parser.add_argument('--detname', default='scan', help="detector name (default 'scan')")
parser.add_argument('--scantype', default='scan', help="scan type (default 'scan')")
parser.add_argument('--record', action='store_true', help='enable recording of data')
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
logging.basicConfig(level=level)
logging.info('logging initialized')
Beispiel #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)')
    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<<platform)')
    parser.add_argument('--config',
                        metavar='ALIAS',
                        help='configuration alias (e.g. BEAM)')
    parser.add_argument('--detname',
                        default='scan',
                        help="detector name (default 'scan')")
    parser.add_argument('--scantype',
                        default='scan',
                        help="scan type (default 'scan')")
    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')
        group_mask = args.g
    else:
        group_mask = 1 << args.p

    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
    logging.basicConfig(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 ConfigScan
    scan = ConfigScan(control, daqState=daqState, args=args)

    scan.stage()

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

    # PV scan setup
    motors = [MyFloatPv(ControlDef.STEP_VALUE)]
    scan.configure(motors=motors)

    my_config_data = {}
    for motor in scan.getMotors():
        my_config_data.update({motor.name: motor.position})
        # derive step_docstring from step_value
        if motor.name == ControlDef.STEP_VALUE:
            docstring = f'{{"detname": "{args.detname}", "scantype": "{args.scantype}", "step": {motor.position}}}'
            my_config_data.update({'step_docstring': docstring})

    data = {
        "motors": my_config_data,
        "timestamp": 0,
        "detname": args.detname,
        "dettype": "scan",
        "scantype": args.scantype,
        "serial_number": "1234",
        "alg_name": "raw",
        "alg_version": [1, 0, 0]
    }

    configureBlock = scan.getBlock(transition="Configure", data=data)

    # config scan setup
    keys_dict = {
        "configure": {
            "step_keys": ["tstts_0:expert.group0.inhibit0.interval"],
            "NamesBlockHex": configureBlock
        },
        "enable": {
            "readout_count": args.c,
            "group_mask": group_mask
        }
    }
    # scan loop
    for interval in [10, 20, 30]:
        # update
        scan.update(value=scan.step_count())

        my_step_data = {}
        for motor in scan.getMotors():
            my_step_data.update({motor.name: motor.position})
            # derive step_docstring from step_value
            if motor.name == ControlDef.STEP_VALUE:
                docstring = f'{{"detname": "{args.detname}", "scantype": "{args.scantype}", "step": {motor.position}}}'
                my_step_data.update({'step_docstring': docstring})

        data["motors"] = my_step_data

        beginStepBlock = scan.getBlock(transition="BeginStep", data=data)
        values_dict = \
          {"beginstep": {"step_values":        {"tstts_0:expert.group0.inhibit0.interval": interval},
                         "ShapesDataBlockHex": beginStepBlock}}
        # 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()
Beispiel #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)')
    parser.add_argument('--phase1',
                        metavar='JSON',
                        default=None,
                        help='phase1Info (only use with --state)')
    group = parser.add_mutually_exclusive_group()
    group.add_argument('--state', choices=ControlDef.states)
    group.add_argument('--transition', choices=ControlDef.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
    try:
        instr = control.getInstrument()
    except KeyboardInterrupt:
        instr = None

    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
        if args.phase1 is None:
            rv = control.setState(args.state)
        else:
            try:
                phase1 = json.loads(args.phase1)
            except Exception as ex:
                exit('Error: failed to parse JSON: %s' % ex)
            rv = control.setState(args.state, phase1)
        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, part5, part6, part7, part8 = control.monitorStatus(
            )
            if part1 is None:
                break
            elif part1 == 'error':
                print('error: %s' % part2)
            elif part1 == 'warning':
                print('warning: %s' % part2)
            elif part1 == 'fileReport':
                print('data file: %s' % part2)
            elif part1 == 'step':
                print('step_done: %d' % part2)
            elif part1 == 'progress':
                print('progress: %s (%d/%d)' % (part2, part3, part4))
            elif part1 in ControlDef.transitions:
                print('transition: %-11s  state: %-11s  config: %s  recording: %s  bypass_activedet: %s  experiment_name: %s  run_number: %d  last_run_number: %d' %\
                      (part1, part2, part3, part4, part5, part6, part7, part8))
            else:
                print('unknown status: %s' % part1)

    else:
        # print current state
        transition, state, config_alias, recording, platform, bypass_activedet, \
            experiment_name, run_number, last_run_number = control.getStatus()
        print('last transition: %s  state: %s  configuration alias: %s  recording: %s  bypass_activedet: %s  experiment_name: %s  run_number: %d  last_run_number: %d' %\
              (transition, state, config_alias, recording, bypass_activedet, experiment_name, run_number, last_run_number))
Beispiel #6
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-p',
                        type=int,
                        choices=range(0, 8),
                        default=1,
                        help='platform (default 1)')
    parser.add_argument('-C',
                        metavar='COLLECT_HOST',
                        default='daq-tst-dev03',
                        help='collection host (default daq-tst-dev03)')
    parser.add_argument('-t',
                        type=int,
                        metavar='TIMEOUT',
                        default=10000,
                        help='timeout msec (default 10000)')
    parser.add_argument('-v', action='store_true', help='be verbose')
    parser.add_argument('--duration',
                        type=int,
                        default=10,
                        help='run duration seconds (default 10)')
    args = parser.parse_args()

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

    # configure logging handlers
    if args.v:
        level = logging.DEBUG
    else:
        level = logging.WARNING
    logging.basicConfig(level=level)
    logging.info('logging initialized')

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

    # instantiate TimedRun
    run = TimedRun(control, daqState=daqState, args=args)

    run.stage()

    try:

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

        # run daq for the specified time duration
        run.set_running_state()
        run.sleep(args.duration)

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

    except KeyboardInterrupt:
        run.push_socket.send_string(
            'shutdown')  #shutdown the daq communicator thread
        sys.exit('interrupted')

    run.unstage()

    run.push_socket.send_string(
        'shutdown')  #shutdown the daq communicator thread