use of org.eclipse.scanning.api.device.models.IDetectorModel in project gda-core by openGDA.
the class ScanningAcquisitionControllerRunRequestTest method testRunScanningAcquisition.
/**
* Submit an acquisition to the service which includes start positions
* @throws AcquisitionControllerException
* @throws GDAClientRestException
* @throws ScanningException
* @throws DeviceException
*/
@Test
public void testRunScanningAcquisition() throws AcquisitionControllerException, GDAClientRestException, ScanningException, DeviceException {
var cameraControl = mock(CameraControl.class);
doReturn("imaging_camera_control").when(cameraControl).getName();
doReturn(Optional.of(cameraControl)).when(finderService).getFindableObject("imaging_camera_control", CameraControl.class);
var iEventService = mock(IEventService.class);
var irunnableDeviceService = mock(IRunnableDeviceService.class);
IRunnableDevice<IDetectorModel> iRunnable = mock(IRunnableDevice.class);
doReturn(iEventService).when(clientRemoteService).getIEventService();
doReturn(irunnableDeviceService).when(clientRemoteService).getIRunnableDeviceService();
doReturn(iRunnable).when(irunnableDeviceService).getRunnableDevice(ArgumentMatchers.any());
doReturn(true).when(experimentClient).isExperimentInProgress();
var baseX = spy(new EpicsPositioner());
doReturn(Optional.of(baseX)).when(finderService).getFindableObject(eq(BASE_X), ArgumentMatchers.any());
doReturn("DUMMY_STATE").when(baseX).getPosition();
doReturn(BASE_X).when(baseX).getName();
var ehShutter = spy(new EpicsPositioner());
doReturn(Optional.of(ehShutter)).when(finderService).getFindableObject(eq(EH_SHUTTER), ArgumentMatchers.any());
doReturn("OPEN").when(ehShutter).getPosition();
doReturn(EH_SHUTTER).when(ehShutter).getName();
var beamSelector = spy(new EpicsPositioner());
doReturn(Optional.of(beamSelector)).when(finderService).getFindableObject(eq("beam_selector"), ArgumentMatchers.any());
doReturn("DIFF").when(beamSelector).getPosition();
doReturn("beam_selector").when(beamSelector).getName();
var responseText = "Done";
RunAcquisitionResponse mockResponse = new RunAcquisitionResponse.Builder().withMessage(responseText).withSubmitted(true).build();
ResponseEntity<RunAcquisitionResponse> mockResponseEntity = new ResponseEntity<>(mockResponse, HttpStatus.OK);
var acquisitionKeys = new AcquisitionKeys(AcquisitionPropertyType.TOMOGRAPHY, AcquisitionSubType.STANDARD, AcquisitionTemplateType.ONE_DIMENSION_LINE);
var controller = context.getAcquisitionController().orElseThrow();
controller.newScanningAcquisition(acquisitionKeys);
doReturn(mockResponseEntity).when(scanningAcquisitionServer).run(controller.getAcquisition());
controller.runAcquisition();
Assert.assertTrue(controller.getAcquisition().getAcquisitionConfiguration().getEndPosition().contains(createBaseXGTS()));
}
use of org.eclipse.scanning.api.device.models.IDetectorModel in project gda-core by openGDA.
the class ScanRequestConverterTest method testDetectorIsExcludedCorrectly.
@Test
public void testDetectorIsExcludedCorrectly() throws Exception {
// Arrange
final String displayName = "Mandelbrot Detector";
final IDetectorModel detModel = new MandelbrotModel();
mappingBean.setDetectorParameters(Arrays.asList(new DetectorModelWrapper(displayName, detModel, false)));
// Act - convert mapping bean to scan request
final ScanRequest scanRequest = scanRequestConverter.convertToScanRequest(mappingBean);
// Assert
assertThat(scanRequest.getDetectors().entrySet(), is(empty()));
// Act again - merge the scan request back into the same mapping bean
scanRequestConverter.mergeIntoMappingBean(scanRequest, mappingBean);
// Assert again - check the mapping bean is the same as the original
List<IScanModelWrapper<IDetectorModel>> newDetectorParams = mappingBean.getDetectorParameters();
assertThat(newDetectorParams.size(), is(1));
IScanModelWrapper<IDetectorModel> wrapper = newDetectorParams.get(0);
assertThat(wrapper.getName(), is(equalTo(displayName)));
// names must be same, i.e. mandlebrot
assertThat(wrapper.getModel(), is(equalTo(detModel)));
assertThat(wrapper.isIncludeInScan(), is(false));
}
use of org.eclipse.scanning.api.device.models.IDetectorModel in project gda-core by openGDA.
the class ScanRequestConverterTest method testDetectorIsIncludedCorrectly.
@Test
public void testDetectorIsIncludedCorrectly() throws Exception {
// Arrange
final String detName = "mandelbrot";
final String displayName = "Mandelbrot Detector";
final IDetectorModel detModel = new MandelbrotModel();
detModel.setName(detName);
mappingBean.setDetectorParameters(Arrays.asList(new DetectorModelWrapper(displayName, detModel, true)));
// Act - convert mapping bean to scan request
final ScanRequest scanRequest = scanRequestConverter.convertToScanRequest(mappingBean);
// Assert
assertEquals(detModel, scanRequest.getDetectors().get(detName));
// Act again - convert scan request back to mapping bean
((DetectorModelWrapper) mappingBean.getDetectorParameters().get(0)).setIncludeInScan(false);
scanRequestConverter.mergeIntoMappingBean(scanRequest, mappingBean);
// Assert - check the new mapping bean is the same as the original
List<IScanModelWrapper<IDetectorModel>> newDetectorParams = mappingBean.getDetectorParameters();
assertThat(newDetectorParams.size(), is(1));
IScanModelWrapper<IDetectorModel> wrapper = newDetectorParams.get(0);
assertThat(wrapper.getName(), is(equalTo(displayName)));
assertThat(wrapper.getModel(), is(equalTo(detModel)));
assertThat(wrapper.isIncludeInScan(), is(true));
}
use of org.eclipse.scanning.api.device.models.IDetectorModel 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.IDetectorModel in project gda-core by openGDA.
the class DetectorsSection method saveState.
@Override
public void saveState(Map<String, String> persistedState) {
final IMarshallerService marshaller = getEclipseContext().get(IMarshallerService.class);
try {
final List<String> chosenDetectorNames = visibleDetectors.stream().map(IScanModelWrapper<IDetectorModel>::getName).collect(Collectors.toList());
persistedState.put(DETECTOR_SELECTION_KEY_JSON, marshaller.marshal(chosenDetectorNames));
} catch (Exception e) {
logger.error("Error saving detector selection", e);
}
}
Aggregations