Search in sources :

Example 1 with MalcolmTable

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;
}
Also used : MalcolmTable(org.eclipse.scanning.api.malcolm.MalcolmTable) ScanningException(org.eclipse.scanning.api.scan.ScanningException) IMalcolmModel(org.eclipse.scanning.api.device.models.IMalcolmModel) IMalcolmDevice(org.eclipse.scanning.api.malcolm.IMalcolmDevice) URISyntaxException(java.net.URISyntaxException) ScanningException(org.eclipse.scanning.api.scan.ScanningException) EventException(org.eclipse.scanning.api.event.EventException)

Aggregations

URISyntaxException (java.net.URISyntaxException)1 IMalcolmModel (org.eclipse.scanning.api.device.models.IMalcolmModel)1 EventException (org.eclipse.scanning.api.event.EventException)1 IMalcolmDevice (org.eclipse.scanning.api.malcolm.IMalcolmDevice)1 MalcolmTable (org.eclipse.scanning.api.malcolm.MalcolmTable)1 ScanningException (org.eclipse.scanning.api.scan.ScanningException)1