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);
}
}
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);
}
}
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);
}
}
}
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;
}
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);
}
Aggregations