Search in sources :

Example 11 with IDetectorModel

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()));
}
Also used : AcquisitionKeys(uk.ac.gda.client.properties.acquisition.AcquisitionKeys) ResponseEntity(org.springframework.http.ResponseEntity) IDetectorModel(org.eclipse.scanning.api.device.models.IDetectorModel) RunAcquisitionResponse(uk.ac.gda.api.acquisition.response.RunAcquisitionResponse) EpicsPositioner(gda.device.enumpositioner.EpicsPositioner) Test(org.junit.Test)

Example 12 with IDetectorModel

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));
}
Also used : ScanRequest(org.eclipse.scanning.api.event.scan.ScanRequest) IDetectorModel(org.eclipse.scanning.api.device.models.IDetectorModel) IScanModelWrapper(uk.ac.diamond.daq.mapping.api.IScanModelWrapper) DetectorModelWrapper(uk.ac.diamond.daq.mapping.impl.DetectorModelWrapper) MandelbrotModel(org.eclipse.scanning.example.detector.MandelbrotModel) Test(org.junit.Test)

Example 13 with IDetectorModel

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));
}
Also used : ScanRequest(org.eclipse.scanning.api.event.scan.ScanRequest) IDetectorModel(org.eclipse.scanning.api.device.models.IDetectorModel) IScanModelWrapper(uk.ac.diamond.daq.mapping.api.IScanModelWrapper) DetectorModelWrapper(uk.ac.diamond.daq.mapping.impl.DetectorModelWrapper) MandelbrotModel(org.eclipse.scanning.example.detector.MandelbrotModel) Test(org.junit.Test)

Example 14 with IDetectorModel

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);
}
Also used : IDetectorModel(org.eclipse.scanning.api.device.models.IDetectorModel) HashMap(java.util.HashMap) ScanningException(org.eclipse.scanning.api.scan.ScanningException) IMalcolmModel(org.eclipse.scanning.api.device.models.IMalcolmModel)

Example 15 with IDetectorModel

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);
    }
}
Also used : IMarshallerService(org.eclipse.dawnsci.analysis.api.persistence.IMarshallerService) IDetectorModel(org.eclipse.scanning.api.device.models.IDetectorModel) ScanningException(org.eclipse.scanning.api.scan.ScanningException)

Aggregations

IDetectorModel (org.eclipse.scanning.api.device.models.IDetectorModel)20 IScanModelWrapper (uk.ac.diamond.daq.mapping.api.IScanModelWrapper)9 ScanRequest (org.eclipse.scanning.api.event.scan.ScanRequest)7 Test (org.junit.Test)6 ScanningException (org.eclipse.scanning.api.scan.ScanningException)5 IMalcolmModel (org.eclipse.scanning.api.device.models.IMalcolmModel)4 CompoundModel (org.eclipse.scanning.api.points.models.CompoundModel)4 DetectorModelWrapper (uk.ac.diamond.daq.mapping.impl.DetectorModelWrapper)4 HashMap (java.util.HashMap)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 IScanPointGeneratorModel (org.eclipse.scanning.api.points.models.IScanPointGeneratorModel)3 ScanRegion (org.eclipse.scanning.api.points.models.ScanRegion)3 MandelbrotModel (org.eclipse.scanning.example.detector.MandelbrotModel)3 Composite (org.eclipse.swt.widgets.Composite)3 File (java.io.File)2 ComboViewer (org.eclipse.jface.viewers.ComboViewer)2 LabelProvider (org.eclipse.jface.viewers.LabelProvider)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 AxialStepModel (org.eclipse.scanning.api.points.models.AxialStepModel)2 IMapPathModel (org.eclipse.scanning.api.points.models.IMapPathModel)2