use of org.eclipse.scanning.api.scan.ScanningException in project gda-core by openGDA.
the class ScanRequestFactory method createScanRequest.
public ScanRequest createScanRequest(IRunnableDeviceService runnableDeviceService) throws ScanningException {
// Populate the {@link ScanRequest} with the assembled objects
var scanRequest = new ScanRequest();
scanRequest.setTemplateFilePaths(new HashSet<>());
prepareScanRequestAccordingToScanType(scanRequest);
Optional.ofNullable(getAcquisition().getAcquisitionLocation()).map(URL::getPath).ifPresent(scanRequest::setFilePath);
try {
scanRequest.setCompoundModel(createCompoundModel());
} catch (GDAException e) {
throw new ScanningException("Cannot create compound model", e);
}
parseAcquisitionEngine(scanRequest, runnableDeviceService);
addPosition(createStartPosition(), scanRequest::setStartPosition);
addPosition(createEndPosition(), scanRequest::setEnd);
scanRequest.setMonitorNamesPerPoint(parseMonitorNamesPerPoint());
scanRequest.setProcessingRequest(new ProcessingRequest());
scanRequest.getProcessingRequest().setRequest(new HashMap<>());
for (ProcessingRequestPair<?> request : getAcquisitionConfiguration().getProcessingRequest()) {
getProcessingRequestHandlerService().handle(request, scanRequest);
}
return scanRequest;
}
use of org.eclipse.scanning.api.scan.ScanningException in project gda-core by openGDA.
the class FrameCaptureRequestHandler method internalHandling.
private boolean internalHandling(FrameCaptureRequest frameCaptureRequest, ScanRequest scanRequest) {
List<FrameRequestDocument> detectorDocuments = frameCaptureRequest.getValue();
String monitorName = serverProperties.getProcessingRequests().getFrameCaptureDecorator();
if (monitorName == null) {
logger.error("Frame capture decorator not defined");
return false;
}
try {
FrameCollectingScannable scn = (FrameCollectingScannable) ScannableDeviceConnectorService.getInstance().getScannable(monitorName);
scn.setFrameRequestDocument(detectorDocuments.iterator().next());
} catch (ScanningException e) {
logger.error("Error retrieving {} '{}'", FrameCollectingScannable.class.getName(), monitorName, e);
return false;
}
List<String> monitors = new ArrayList<>(scanRequest.getMonitorNamesPerScan());
monitors.add(monitorName);
scanRequest.setMonitorNamesPerScan(monitors);
var script = LocalProperties.get(CAMERA_STREAM_SCRIPT_PROPERTY);
if (script != null) {
var scriptRequest = new ScriptRequest(script);
scanRequest.setAfterScript(scriptRequest);
}
return true;
}
use of org.eclipse.scanning.api.scan.ScanningException in project gda-core by openGDA.
the class ScannableNexusWrapperScanTest method createGridScan.
private IRunnableDevice<ScanModel> createGridScan(final IRunnableDevice<? extends IDetectorModel> detector, String outerScannableName, int... size) throws Exception {
// Create scan points for a grid and make a generator
final TwoAxisGridPointsModel gridModel = new TwoAxisGridPointsModel();
gridModel.setxAxisName("salong");
gridModel.setxAxisPoints(size[size.length - 1]);
gridModel.setyAxisName("saperp");
gridModel.setyAxisPoints(size[size.length - 2]);
gridModel.setBoundingBox(new BoundingBox(0, 0, 3, 3));
final CompoundModel compoundModel = new CompoundModel();
// We add the outer scans, if any
if (outerScannableName != null) {
for (int dim = 0; dim < size.length - 2; dim++) {
if (size[dim] > 1) {
// TODO outer scannable name(s)? could use cryostat temperature as an outer scan
compoundModel.addModel(new AxialStepModel(outerScannableName, 10000, 20000, 9999.99d / (size[dim] - 1)));
} else {
// Will generate one value at 10
compoundModel.addModel(new AxialStepModel(outerScannableName + (dim + 1), 10, 20, 30));
}
}
}
compoundModel.addModel(gridModel);
final IPointGenerator<CompoundModel> pointGen = pointGenService.createCompoundGenerator(compoundModel);
// Create the model for a scan
final ScanModel scanModel = new ScanModel();
scanModel.setPointGenerator(pointGen);
scanModel.setScanPathModel(compoundModel);
scanModel.setDetector(detector);
final IScannable<?> attributeScannable = scannableDeviceService.getScannable("attributes");
final IScannable<?> beamSizeScannable = scannableDeviceService.getScannable("beam");
scanModel.setMonitorsPerScan(attributeScannable, beamSizeScannable);
// Create a file to scan into
final File output = File.createTempFile("test_legacy_nexus", ".nxs");
output.deleteOnExit();
scanModel.setFilePath(output.getAbsolutePath());
System.out.println("File writing to " + scanModel.getFilePath());
// Create a scan and run it without publishing events
final IRunnableDevice<ScanModel> scanner = scanService.createScanDevice(scanModel);
final IPointGenerator<?> fgen = pointGen;
((IRunnableEventDevice<ScanModel>) scanner).addRunListener(new IRunListener() {
@Override
public void runWillPerform(RunEvent evt) throws ScanningException {
System.out.println("Running acquisition scan of size " + fgen.size());
}
});
return scanner;
}
use of org.eclipse.scanning.api.scan.ScanningException in project gda-core by openGDA.
the class DetectorsSection method updateMappingStage.
/**
* Update the mapping stage scannable names based on the given detector.
* This method will only make any changes if the given detector is a malcolm device,
* and the value of the {@code axesToMove} attribute of that malcolm device is
* a {@link StringArrayAttribute} with a length of 2 or greater.
* In this case the fast and slow axes will be changed to the
* first and second elements of that array, and if the array is of length 3 or greater,
* the associated axis is set to the third element.
*
* @param wrapper detector model wrapper of the selected detector
*/
private void updateMappingStage(IScanModelWrapper<IDetectorModel> wrapper) {
final String deviceName = wrapper.getModel().getName();
try {
// get the axesToMove from the malcolm device
final MappingStageInfo stageInfo = getEclipseContext().get(MappingStageInfo.class);
final List<String> malcolmAxes = getMalcolmDevice(deviceName).getAvailableAxes();
// only update the mapping stage if the malcolm device is configured to move at least two axes.
if (malcolmAxes.size() < 2)
return;
// if the current fast and slow axes are contained in the malcolm axes, then the mapping stage
// is already set correctly for the malcolm device, no update is required
// note if new (2018) malcolm, malcolmAxes will contain all
boolean updatedFastAndSlowAxes = false;
if (!malcolmAxes.contains(stageInfo.getPlotXAxisName()) || !malcolmAxes.contains(stageInfo.getPlotYAxisName())) {
// we assume the order is fast-axis, slow-axes. Malcolm devices must be configured to have this order
stageInfo.setPlotXAxisName(malcolmAxes.get(0));
stageInfo.setPlotYAxisName(malcolmAxes.get(1));
updatedFastAndSlowAxes = true;
}
boolean updatedAssociatedAxes = false;
if (malcolmAxes.size() > 2 && !malcolmAxes.contains(stageInfo.getAssociatedAxis())) {
// for a 3+ dimension malcolm device, we can set the z-axis as well
stageInfo.setAssociatedAxis(malcolmAxes.get(2));
updatedAssociatedAxes = true;
}
if (updatedFastAndSlowAxes || updatedAssociatedAxes) {
// show a dialog to inform the user of the change (unless overridden in the preferences)
final IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
if (prefs.getBoolean(PREFERENCE_KEY_SHOW_MAPPING_STAGE_CHANGED_DIALOG, true)) {
String message = "";
if (updatedFastAndSlowAxes) {
message += MessageFormat.format("The active fast scan axis for mapping scans has been updated to ''{0}'' and the active slow scan axis to ''{1}''.", stageInfo.getPlotXAxisName(), stageInfo.getPlotYAxisName());
}
if (updatedAssociatedAxes) {
message += MessageFormat.format(" The associated axis has been updated to ''{0}''.", stageInfo.getAssociatedAxis());
} else {
message += MessageFormat.format(" The associated axis is ''{0}'' and has not been changed.", stageInfo.getAssociatedAxis());
}
final MessageDialogWithToggle dialog = MessageDialogWithToggle.openInformation(getShell(), "Mapping Stage", message, "Don't show this dialog again", false, null, null);
prefs.putBoolean(PREFERENCE_KEY_SHOW_MAPPING_STAGE_CHANGED_DIALOG, !dialog.getToggleState());
}
// Region and path composites need updating to reflect this change.
getMappingView().redrawRegionAndPathComposites();
}
} catch (ScanningException e) {
logger.error("Could not get axes of malcolm device: {}", deviceName, e);
}
}
use of org.eclipse.scanning.api.scan.ScanningException in project gda-core by openGDA.
the class DetectorsSection method editDetectorParameters.
private void editDetectorParameters(final IScanModelWrapper<IDetectorModel> detectorParameters) {
try {
if (detectorParameters.getModel() instanceof IMalcolmModel && getRunnableDeviceService().getRunnableDevice(detectorParameters.getModel().getName()).getDeviceState() == DeviceState.OFFLINE) {
MessageDialog.openError(getShell(), "Malcolm Device " + detectorParameters.getModel().getName(), "Cannot edit malcolm device " + detectorParameters.getModel().getName() + " as it is offline.");
return;
}
} catch (ScanningException e) {
logger.error("Cannot get malcolm device", e);
}
final Dialog editModelDialog = new EditDetectorModelDialog(getShell(), getRunnableDeviceService(), detectorParameters.getModel(), detectorParameters.getName());
editModelDialog.create();
if (editModelDialog.open() == Window.OK) {
dataBindingContext.updateTargets();
}
}
Aggregations