use of org.eclipse.scanning.api.device.models.IMalcolmModel 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);
}
use of org.eclipse.scanning.api.device.models.IMalcolmModel 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();
}
}
use of org.eclipse.scanning.api.device.models.IMalcolmModel in project gda-core by openGDA.
the class ProcessingSelectionWizardPage method getDetectorDatasetNameForMalcolm.
/**
* Get the name of the dataset to use for the malcolm device with the given name. This is the
* first dataset of type 'primary' in the {@link MalcolmTable} of the {@link MalcolmConstants#ATTRIBUTE_NAME_DATASETS}
* attribute.
* @param malcolmModel
* @return
*/
private Optional<String> getDetectorDatasetNameForMalcolm(IMalcolmModel malcolmModel) {
if (malcolmDetectorDatasetNames != null && malcolmDetectorDatasetNames.containsKey(malcolmModel.getName())) {
return Optional.of(malcolmDetectorDatasetNames.get(malcolmModel.getName()));
}
Optional<String> datasetName = Optional.empty();
try {
final IRunnableDevice<IMalcolmModel> malcolmDevice = getRunnableDeviceService().getRunnableDevice(malcolmModel.getName());
if (malcolmDevice.getDeviceState() != DeviceState.READY) {
throw new ScanningException("The malcolm device is not ready. A scan may be running.");
}
try {
// configure the malcolm device, puts it in 'Armed' state
malcolmDevice.configure(malcolmModel);
if (malcolmDevice instanceof IMalcolmDevice) {
final MalcolmTable datasetsTable = ((IMalcolmDevice) malcolmDevice).getDatasets();
if (datasetsTable != null) {
datasetName = getPrimaryDatasetNameForMalcolm(datasetsTable);
}
}
if (datasetName.isPresent()) {
// if we found the dataset name, cache it
logger.debug("Got ''{}'' as dataset for processing for malcolm device ''{}''", datasetName.get(), malcolmModel.getName());
if (malcolmDetectorDatasetNames == null) {
malcolmDetectorDatasetNames = new HashMap<>(4);
}
malcolmDetectorDatasetNames.put(malcolmModel.getName(), datasetName.get());
} else {
logger.error("Could not get primary dataset for malcolm device ''{}''. The dataset for the malcolm device may not be set correctly.", malcolmModel.getName());
}
} finally {
// Reset the malcolm device back to the 'Ready' state
malcolmDevice.reset();
}
} catch (Exception e) {
logger.error("Could not get primary dataset for malcolm device: " + malcolmModel.getName(), e);
}
return datasetName;
}
use of org.eclipse.scanning.api.device.models.IMalcolmModel in project gda-core by openGDA.
the class ProcessingSelectionWizardPage method finishPage.
@Override
public void finishPage() {
if (ProcessingMode.OTHER.equals(mode)) {
String path = existingConfigText.getText();
configWrapper.setAppName(appText.getText());
configWrapper.setName(new File(path).getName());
configWrapper.setPathToConfig(path);
return;
}
final IDetectorModel detectorModel = getSelectedDetector().getModel();
final Optional<String> malcolmDetectorDatasetName = detectorModel instanceof IMalcolmModel ? getDetectorDatasetNameForMalcolm((IMalcolmModel) detectorModel) : Optional.empty();
configureProcessingModel(detectorModel, malcolmDetectorDatasetName);
if (!ProcessingMode.NEW_DAWN.equals(selectedMode())) {
return;
}
// Clone the detector model - we don't want to change the one in the mapping bean
IDetectorModel detectorModelCopy = null;
try {
detectorModelCopy = (IDetectorModel) BeanUtils.cloneBean(detectorModel);
} catch (Exception e) {
logger.error("Could not make a copy of the detector model: " + detectorModel.getName(), e);
return;
}
// setup the acquire page with the detector model for the appropriate detector and
// the name of the detector group (may be different if the detector is a malcolm detector).
AcquireDataWizardPage acquirePage = (AcquireDataWizardPage) getNextPage();
acquirePage.setAcquireDetectorModel(detectorModelCopy);
acquirePage.setDetectorDataGroupName(malcolmDetectorDatasetName.orElse(detectorModel.getName()));
// set template file on wizard, so that other pages can be created appropriately
final String templateFile = getSelectedTemplateFile().getPath();
try {
((IOperationModelWizard) getWizard()).setTemplateFile(templateFile);
} catch (Exception e) {
final String exceptionMessage = "Error setting template file on wizard. Could not create operations pages.";
final String userMessage = "Could not open template file, please contact beamline representative";
logger.error(exceptionMessage, e);
final MessageBox messageBox = new MessageBox(getShell(), SWT.ERROR);
messageBox.setMessage(userMessage);
messageBox.open();
throw new RuntimeException(exceptionMessage, e);
}
}
use of org.eclipse.scanning.api.device.models.IMalcolmModel in project gda-core by openGDA.
the class TimeSeriesScanView method createMalcolmModelEditor.
private MalcolmModelEditor createMalcolmModelEditor(Composite parent, String malcolmDeviceName) {
try {
final IRunnableDevice<?> malcolmDevice = getRunnableDeviceService().getRunnableDevice(malcolmDeviceName);
final IMalcolmModel malcolmModel = (IMalcolmModel) malcolmDevice.getModel();
final MalcolmModelEditor editor = new MalcolmModelEditor(getRunnableDeviceService(), malcolmModel);
editor.createEditorPart(parent);
return editor;
} catch (ScanningException e) {
logger.error("Could not get malcolm device: ", malcolmDeviceName, e);
return null;
}
}
Aggregations