use of org.eclipse.scanning.api.malcolm.MalcolmTable 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;
}
Aggregations