Search in sources :

Example 26 with ScanningException

use of org.eclipse.scanning.api.scan.ScanningException in project gda-core by openGDA.

the class FrameCollectingScannable method configureAndCollect.

/**
 * This is invoked shortly before the main scan is configured
 */
@PrepareScan
public void configureAndCollect(ScanModel scanModel) throws ScanningException {
    configureCollection(scanModel);
    try {
        configureBeamline();
        frameFilePath = collectFrame();
        nexusNodePath = generateNodePath();
        restoreBeamline();
    } catch (EventException e) {
        throw new ScanningException("Problem taking snapshot", e);
    }
}
Also used : EventException(org.eclipse.scanning.api.event.EventException) ScanningException(org.eclipse.scanning.api.scan.ScanningException) PrepareScan(org.eclipse.scanning.api.annotation.scan.PrepareScan)

Example 27 with ScanningException

use of org.eclipse.scanning.api.scan.ScanningException in project gda-core by openGDA.

the class NexusSlitsWrapper method getPosition.

// implements IScannable<DeviceValueMultiPosition>
@Override
public DeviceValueMultiPosition getPosition() throws ScanningException {
    DeviceValueMultiPosition position = new DeviceValueMultiPosition();
    try {
        position.put(NXslit.NX_X_GAP, (double) x_gap.getPosition());
        position.put(NXslit.NX_Y_GAP, (double) y_gap.getPosition());
        return position;
    } catch (DeviceException e) {
        throw new ScanningException("Could not get position of scannable: " + getName(), e);
    }
}
Also used : DeviceValueMultiPosition(org.eclipse.scanning.api.event.scan.DeviceValueMultiPosition) ScanningException(org.eclipse.scanning.api.scan.ScanningException) DeviceException(gda.device.DeviceException)

Example 28 with ScanningException

use of org.eclipse.scanning.api.scan.ScanningException in project gda-core by openGDA.

the class NexusSlitsWrapper method write.

private void write(DeviceValueMultiPosition demand, DeviceValueMultiPosition actual, IPosition loc) throws ScanningException, DatasetException {
    // there are no actual values.
    if (xLzValue == null || yLzValue == null) {
        return;
    }
    if (actual != null) {
        // write actual position
        final Dataset newXPositionData = DatasetFactory.createFromObject(actual.get(NXslit.NX_X_GAP));
        final Dataset newYPositionData = DatasetFactory.createFromObject(actual.get(NXslit.NX_Y_GAP));
        IScanSlice rslice = IScanRankService.getScanRankService().createScanSlice(loc);
        SliceND xSliceND = new SliceND(xLzValue.getShape(), xLzValue.getMaxShape(), rslice.getStart(), rslice.getStop(), rslice.getStep());
        SliceND ySliceND = new SliceND(yLzValue.getShape(), yLzValue.getMaxShape(), rslice.getStart(), rslice.getStop(), rslice.getStep());
        if (isWritingOn()) {
            xLzValue.setSlice(null, newXPositionData, xSliceND);
            yLzValue.setSlice(null, newYPositionData, ySliceND);
        }
    }
    if (xLzSet == null || yLzSet == null) {
        return;
    }
    if (demand != null) {
        int index = loc.getIndex(getName());
        if (index < 0) {
            throw new ScanningException("Incorrect data index for scan for value of '" + getName() + "'. The index is " + index);
        }
        final int[] startPos = new int[] { index };
        final int[] stopPos = new int[] { index + 1 };
        // write demand position
        final Dataset newDemandPositionData = DatasetFactory.createFromObject(demand);
        if (isWritingOn()) {
            xLzSet.setSlice(null, newDemandPositionData, startPos, stopPos, null);
            yLzSet.setSlice(null, newDemandPositionData, startPos, stopPos, null);
        }
    }
}
Also used : ILazyWriteableDataset(org.eclipse.january.dataset.ILazyWriteableDataset) Dataset(org.eclipse.january.dataset.Dataset) ScanningException(org.eclipse.scanning.api.scan.ScanningException) IScanSlice(org.eclipse.scanning.api.scan.rank.IScanSlice) SliceND(org.eclipse.january.dataset.SliceND)

Example 29 with ScanningException

use of org.eclipse.scanning.api.scan.ScanningException in project gda-core by openGDA.

the class ScannableDeviceConnectorService method getScannable.

@SuppressWarnings("unchecked")
@Override
public <T> IScannable<T> getScannable(String name) throws ScanningException {
    boolean jythonScannable = false;
    if (scannables == null)
        scannables = new HashMap<>();
    // first check whether an existing IScannable with this name in the cache, if so return it
    if (scannables.containsKey(name)) {
        IScannable<T> scannable = (IScannable<T>) scannables.get(name);
        if (scannable == null)
            throw new ScanningException("Cannot find scannable with name " + name);
        return scannable;
    }
    // if not, see if we can find a gda.device.Scannable with this name using the Finder mechanism
    Optional<Scannable> found = Finder.findOptionalOfType(name, Scannable.class);
    Scannable scannable = found.filter(s -> !(s instanceof Detector)).orElse(null);
    if (scannable == null) {
        // if not, see if we can find a gda.device.Scannable with this name in the jython namespace
        Object jythonObject = InterfaceProvider.getJythonNamespace().getFromJythonNamespace(name);
        if (jythonObject instanceof Scannable && !(jythonObject instanceof Detector)) {
            scannable = (Scannable) jythonObject;
            jythonScannable = true;
        }
    }
    // if we still haven't found the scannable, throw a ScanningException
    if (scannable == null) {
        throw new ScanningException("Cannot find scannable with name " + name);
    }
    // create a ScannableNexusWrapper wrapping the gda.device.Scannable
    IScannable<T> iscannable = createScannableWrapper(name, scannable, jythonScannable);
    // cache the IScannable for future use
    scannables.put(name, iscannable);
    return iscannable;
}
Also used : IScannable(org.eclipse.scanning.api.IScannable) Findable(gda.factory.Findable) InterfaceProvider(gda.jython.InterfaceProvider) LoggerFactory(org.slf4j.LoggerFactory) ScannableWriter(gda.data.scan.datawriter.scannablewriter.ScannableWriter) JythonServer(gda.jython.JythonServer) HashMap(java.util.HashMap) IScannable(org.eclipse.scanning.api.IScannable) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Detector(gda.device.Detector) Map(java.util.Map) DeviceException(gda.device.DeviceException) Finder(gda.factory.Finder) IScannableDeviceService(org.eclipse.scanning.api.device.IScannableDeviceService) Logger(org.slf4j.Logger) Collection(java.util.Collection) Set(java.util.Set) ScanningException(org.eclipse.scanning.api.scan.ScanningException) Collectors(java.util.stream.Collectors) AbstractScannable(org.eclipse.scanning.api.AbstractScannable) ServiceHolder(gda.data.ServiceHolder) Scannable(gda.device.Scannable) List(java.util.List) IPosition(org.eclipse.scanning.api.points.IPosition) Optional(java.util.Optional) Collections(java.util.Collections) Detector(gda.device.Detector) HashMap(java.util.HashMap) ScanningException(org.eclipse.scanning.api.scan.ScanningException) IScannable(org.eclipse.scanning.api.IScannable) AbstractScannable(org.eclipse.scanning.api.AbstractScannable) Scannable(gda.device.Scannable)

Example 30 with ScanningException

use of org.eclipse.scanning.api.scan.ScanningException in project gda-core by openGDA.

the class ScanRequestFactory method prepareMalcolmAcquisitionEngine.

private void prepareMalcolmAcquisitionEngine(ScanRequest scanRequest, IRunnableDeviceService runnableDeviceService) throws ScanningException {
    final Map<String, IDetectorModel> ret = new HashMap<>();
    scanRequest.setDetectors(ret);
    String id = Optional.ofNullable(getAcquisitionEngine()).map(AcquisitionEngineReader::getId).orElseThrow(() -> new ScanningException("The AcquisitionEngine section does not contain the device id"));
    IRunnableDevice<IDetectorModel> detector = runnableDeviceService.getRunnableDevice(id);
    IDetectorModel imodel = Optional.ofNullable(detector.getModel()).orElseThrow(() -> new ScanningException(String.format("Could not get model for detector %s", detector.getName())));
    if (!(imodel instanceof IMalcolmModel))
        throw new ScanningException(String.format("Detector model is not an instance of of type %s", IMalcolmModel.class));
    final IMalcolmModel model = IMalcolmModel.class.cast(imodel);
    setDetectorsExposures(model);
    ret.put(detector.getName(), model);
}
Also used : IDetectorModel(org.eclipse.scanning.api.device.models.IDetectorModel) HashMap(java.util.HashMap) ScanningException(org.eclipse.scanning.api.scan.ScanningException) IMalcolmModel(org.eclipse.scanning.api.device.models.IMalcolmModel)

Aggregations

ScanningException (org.eclipse.scanning.api.scan.ScanningException)41 DeviceException (gda.device.DeviceException)13 NexusException (org.eclipse.dawnsci.nexus.NexusException)7 IMalcolmModel (org.eclipse.scanning.api.device.models.IMalcolmModel)4 EventException (org.eclipse.scanning.api.event.EventException)4 Scannable (gda.device.Scannable)3 CAException (gov.aps.jca.CAException)3 TimeoutException (gov.aps.jca.TimeoutException)3 DatasetException (org.eclipse.january.DatasetException)3 Dataset (org.eclipse.january.dataset.Dataset)3 ILazyWriteableDataset (org.eclipse.january.dataset.ILazyWriteableDataset)3 SliceND (org.eclipse.january.dataset.SliceND)3 IScanSlice (org.eclipse.scanning.api.scan.rank.IScanSlice)3 Composite (org.eclipse.swt.widgets.Composite)3 File (java.io.File)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 AbstractScannable (org.eclipse.scanning.api.AbstractScannable)2