Search in sources :

Example 1 with IRunnableDevice

use of org.eclipse.scanning.api.device.IRunnableDevice in project gda-core by openGDA.

the class ClausesContext method addDetector.

/**
 * Adds an {@link IDetectorModel} corresponding to the supplied {@link IRunnableDevice} to the map of detectors,
 * setting the exposure time if specified
 *
 * @param detector				The {@link IRunnableDevice} corresponding to the detector
 * @param exposure				The exposure time of the {@link Detector} to be set if specified
 * @throws ScanningException	If the {@link IDetectorModel} for the {@link IRunnableDevice} is null.
 */
public void addDetector(final IRunnableDevice<?> detector, final double exposure) throws ScanningException {
    nullCheck(detector, IRunnableDevice.class.getSimpleName());
    IDetectorModel model = (IDetectorModel) detector.getModel();
    if (model == null) {
        throw new ScanningException(String.format("Could not get model for detector %s", detector.getName()));
    }
    if (exposure > 0) {
        model.setExposureTime(exposure);
    }
    detectorMap.put(detector.getName(), model);
    detectorClauseSeen = true;
    clauseProcessed = true;
    LOGGER.debug("Detector added for {}", detector.getName());
}
Also used : IDetectorModel(org.eclipse.scanning.api.device.models.IDetectorModel) ScanningException(org.eclipse.scanning.api.scan.ScanningException) IRunnableDevice(org.eclipse.scanning.api.device.IRunnableDevice)

Example 2 with IRunnableDevice

use of org.eclipse.scanning.api.device.IRunnableDevice in project gda-core by openGDA.

the class MScanSubmitter method standardiseAndValidateCommand.

/**
 * After adjusting the command to be compliant with the grammar expressed in {@linkClausesContext}.
 * checks that the MScan command has valid arguments and that the first one is valid either a Scannable
 * or the Static {@link RegionShape}. Providing this is the case, the validity of the type of each arg is
 * checked by confirming that there is a corresponding {@link IClauseElementProcessBuilder} in the
 * {@link processorBuilders} static map. Assuming this is the case for all args, corresponding processors
 * are added to the {@link processors} list.
 *
 * @param args		The arguments that constitute the elements of the incoming MScan command
 * @return			A {@link ScanClauseResolver} initialised with processors that correspond to the elements
 * 					of the command if they are successfully validated.
 *
 * @throws	IllegalArgumentException if there is no processor type that matches the current arg in the command or if
 * 			the {@code args} array is empty.
 */
private ScanClausesResolver standardiseAndValidateCommand(final Object[] args) {
    if (args.length < 1 || !(args[0].equals(Action.RERUN) || args[0] instanceof Scannable || args[0].equals(Scanpath.STATIC) || onlyDetectorsAndParams(args))) {
        throw new IllegalArgumentException("You must specify at least one argument in your mscan command and your first argument must be a Scannable, the Static Scanpath, a Detector or the 'rerun' keyword");
    }
    List<Object> params = standardiseSyntax(args);
    // Iterate over the standardised command args looking for Scannable and Scannable groups. Can't just use the returned class
    // as many classes implement Scannable
    Class<?>[] hierarchy = { Detector.class, Monitor.class, ScannableGroup.class, Scannable.class };
    for (int i = 0; i < params.size(); i++) {
        Object obj = params.get(i);
        Class<?> type = obj.getClass();
        if (obj instanceof Scannable) {
            for (Class<?> cl : hierarchy) {
                if (cl.isAssignableFrom(obj.getClass())) {
                    type = cl;
                    break;
                }
            }
        } else if (obj instanceof IRunnableDevice<?>) {
            type = IRunnableDevice.class;
        } else if (i == 0 && obj instanceof Action && ((Action) obj).equals(Action.RERUN)) {
            processors.add(new ReRunFromFileElementProcessor((String) params.get(1)));
            break;
        }
        // make it and add it to the collection of processors that correspond to the command.
        if (!processorBuilders.containsKey(type)) {
            throw new IllegalArgumentException(String.format("Your command contains an invalid argument at position %d", i));
        }
        processors.add(processorBuilders.get(type).apply(params.get(i)));
    }
    return resolverFactory.getResolver(processors);
}
Also used : Action(gda.mscan.element.Action) ReRunFromFileElementProcessor(gda.mscan.processor.ReRunFromFileElementProcessor) Scannable(gda.device.Scannable) IRunnableDevice(org.eclipse.scanning.api.device.IRunnableDevice)

Aggregations

IRunnableDevice (org.eclipse.scanning.api.device.IRunnableDevice)2 Scannable (gda.device.Scannable)1 Action (gda.mscan.element.Action)1 ReRunFromFileElementProcessor (gda.mscan.processor.ReRunFromFileElementProcessor)1 IDetectorModel (org.eclipse.scanning.api.device.models.IDetectorModel)1 ScanningException (org.eclipse.scanning.api.scan.ScanningException)1