Search in sources :

Example 26 with ScanRequest

use of org.eclipse.scanning.api.event.scan.ScanRequest in project gda-core by openGDA.

the class ScanRequestConverter method mergeSampleMetadata.

private void mergeSampleMetadata(ScanRequest scanRequest, IMappingExperimentBean mappingBean) {
    List<ScanMetadata> scanMetadata = scanRequest.getScanMetadata();
    if (scanMetadata == null)
        return;
    Optional<ScanMetadata> sampleScanMetadataOpt = scanMetadata.stream().filter(metadata -> metadata.getType() == MetadataType.SAMPLE).findFirst();
    if (!sampleScanMetadataOpt.isPresent())
        return;
    ScanMetadata sampleScanMetadata = sampleScanMetadataOpt.get();
    SimpleSampleMetadata sampleMetadata = (SimpleSampleMetadata) mappingBean.getSampleMetadata();
    if (sampleMetadata == null) {
        sampleMetadata = new SimpleSampleMetadata();
        mappingBean.setSampleMetadata(sampleMetadata);
    }
    sampleMetadata.setSampleName((String) sampleScanMetadata.getFieldValue(FIELD_NAME_SAMPLE_NAME));
    sampleMetadata.setDescription((String) sampleScanMetadata.getFieldValue(FIELD_NAME_SAMPLE_DESCRIPTION));
}
Also used : Arrays(java.util.Arrays) IMappingExperimentBean(uk.ac.diamond.daq.mapping.api.IMappingExperimentBean) ScanRegion(org.eclipse.scanning.api.points.models.ScanRegion) LoggerFactory(org.slf4j.LoggerFactory) ScanRequest(org.eclipse.scanning.api.event.scan.ScanRequest) CompoundModel(org.eclipse.scanning.api.points.models.CompoundModel) TemplateFileWrapper(uk.ac.diamond.daq.mapping.api.TemplateFileWrapper) ScriptFiles(uk.ac.diamond.daq.mapping.impl.ScriptFiles) Map(java.util.Map) ScannableMotionUnits(gda.device.ScannableMotionUnits) Finder(gda.factory.Finder) PolygonMappingRegion(uk.ac.diamond.daq.mapping.region.PolygonMappingRegion) ConfigWrapper(uk.ac.diamond.daq.mapping.api.ConfigWrapper) Collection(java.util.Collection) Set(java.util.Set) ISampleMetadata(uk.ac.diamond.daq.mapping.api.ISampleMetadata) RectangularROI(org.eclipse.dawnsci.analysis.dataset.roi.RectangularROI) MapPosition(org.eclipse.scanning.api.points.MapPosition) Objects(java.util.Objects) List(java.util.List) IROI(org.eclipse.dawnsci.analysis.api.roi.IROI) IScanModelWrapper(uk.ac.diamond.daq.mapping.api.IScanModelWrapper) ProcessingRequest(org.eclipse.scanning.api.event.scan.ProcessingRequest) ScanMetadata(org.eclipse.scanning.api.scan.models.ScanMetadata) SimpleSampleMetadata(uk.ac.diamond.daq.mapping.impl.SimpleSampleMetadata) Optional(java.util.Optional) ScanBean(org.eclipse.scanning.api.event.scan.ScanBean) CircularMappingRegion(uk.ac.diamond.daq.mapping.region.CircularMappingRegion) IMappingScanRegion(uk.ac.diamond.daq.mapping.api.IMappingScanRegion) LinearROI(org.eclipse.dawnsci.analysis.dataset.roi.LinearROI) IScriptFiles(uk.ac.diamond.daq.mapping.api.IScriptFiles) HashMap(java.util.HashMap) RectangularMappingRegion(uk.ac.diamond.daq.mapping.region.RectangularMappingRegion) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) IDetectorModel(org.eclipse.scanning.api.device.models.IDetectorModel) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) Collectors.toCollection(java.util.stream.Collectors.toCollection) LineMappingRegion(uk.ac.diamond.daq.mapping.region.LineMappingRegion) IScanDefinition(uk.ac.diamond.daq.mapping.api.IScanDefinition) PointROI(org.eclipse.dawnsci.analysis.dataset.roi.PointROI) IGuiGeneratorService(org.eclipse.richbeans.api.generator.IGuiGeneratorService) CircularROI(org.eclipse.dawnsci.analysis.dataset.roi.CircularROI) DetectorModelWrapper(uk.ac.diamond.daq.mapping.impl.DetectorModelWrapper) PointMappingRegion(uk.ac.diamond.daq.mapping.region.PointMappingRegion) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) MetadataType(org.eclipse.scanning.api.scan.models.ScanMetadata.MetadataType) ScriptRequest(org.eclipse.scanning.api.script.ScriptRequest) File(java.io.File) IMapPathModel(org.eclipse.scanning.api.points.models.IMapPathModel) ScriptLanguage(org.eclipse.scanning.api.script.ScriptLanguage) PolygonalROI(org.eclipse.dawnsci.analysis.dataset.roi.PolygonalROI) Collections(java.util.Collections) MappingStageInfo(uk.ac.diamond.daq.mapping.impl.MappingStageInfo) ScanPathModelWrapper(uk.ac.diamond.daq.mapping.impl.ScanPathModelWrapper) IMappingScanRegionShape(uk.ac.diamond.daq.mapping.api.IMappingScanRegionShape) IScanPointGeneratorModel(org.eclipse.scanning.api.points.models.IScanPointGeneratorModel) ScanMetadata(org.eclipse.scanning.api.scan.models.ScanMetadata) SimpleSampleMetadata(uk.ac.diamond.daq.mapping.impl.SimpleSampleMetadata)

Example 27 with ScanRequest

use of org.eclipse.scanning.api.event.scan.ScanRequest in project gda-core by openGDA.

the class SavuProcessingRequestHandlerTest method testSavuProcessingRequest.

@Test
public void testSavuProcessingRequest() throws Exception {
    ProcessingRequestHandler handler = new SavuProcessingRequestHandler();
    URL file1 = new URL("file:/lev1/lev2");
    URL file2 = new URL("file:/lev3/lev4");
    List<URL> paths = new ArrayList<>();
    paths.add(file1);
    paths.add(file2);
    SavuProcessingRequest request = new SavuProcessingRequest.Builder().withValue(paths).build();
    ScanRequest scanRequest = new ScanRequest();
    scanRequest.setProcessingRequest(new ProcessingRequest());
    scanRequest.getProcessingRequest().setRequest(new HashMap<>());
    handler.handle(request, scanRequest);
    Collection<Object> translated = scanRequest.getProcessingRequest().getRequest().get(request.getKey());
    Assert.assertEquals(2, translated.size());
    Assert.assertTrue(translated.contains(file1.getPath()));
    Assert.assertTrue(translated.contains(file2.getPath()));
}
Also used : ScanRequest(org.eclipse.scanning.api.event.scan.ScanRequest) ArrayList(java.util.ArrayList) SavuProcessingRequest(uk.ac.gda.api.acquisition.configuration.processing.SavuProcessingRequest) ProcessingRequest(org.eclipse.scanning.api.event.scan.ProcessingRequest) SavuProcessingRequest(uk.ac.gda.api.acquisition.configuration.processing.SavuProcessingRequest) URL(java.net.URL) Test(org.junit.Test)

Example 28 with ScanRequest

use of org.eclipse.scanning.api.event.scan.ScanRequest in project gda-core by openGDA.

the class ScanRequestConverterTest method testStageNamesAreSetCorrectly.

@Test
public void testStageNamesAreSetCorrectly() throws Exception {
    // Initially the scan path doesn't have the correct axis names
    assertThat(scanPath.getxAxisName(), is(not(equalTo(X_AXIS_NAME))));
    assertThat(scanPath.getyAxisName(), is(not(equalTo(Y_AXIS_NAME))));
    // Act - they're set according to the MappingStageInfo when the mapping bean is
    // converted to a scan request
    ScanRequest scanRequest = scanRequestConverter.convertToScanRequest(mappingBean);
    // Assert - the axis names are now set to the names of the stage
    assertThat(scanPath.getxAxisName(), is(equalTo(X_AXIS_NAME)));
    assertThat(scanPath.getyAxisName(), is(equalTo(Y_AXIS_NAME)));
    scanRequestConverter.mergeIntoMappingBean(scanRequest, newMappingBean);
}
Also used : ScanRequest(org.eclipse.scanning.api.event.scan.ScanRequest) Test(org.junit.Test)

Example 29 with ScanRequest

use of org.eclipse.scanning.api.event.scan.ScanRequest in project gda-core by openGDA.

the class ScanRequestConverterTest method testSampleMetadataSet.

@Test
public void testSampleMetadataSet() throws Exception {
    // Arrange
    final String sampleName = "testSample";
    final String sampleDescription = "This is a description of the test sample.";
    mappingBean.getSampleMetadata().setSampleName(sampleName);
    mappingBean.getSampleMetadata().setDescription(sampleDescription);
    // Act - convert mapping bean to scan request
    ScanRequest scanRequest = scanRequestConverter.convertToScanRequest(mappingBean);
    // Assert
    List<ScanMetadata> scanMetadataList = scanRequest.getScanMetadata();
    assertEquals(1, scanMetadataList.size());
    ScanMetadata scanMetadata = scanMetadataList.get(0);
    assertEquals(MetadataType.SAMPLE, scanMetadata.getType());
    assertEquals(sampleName, scanMetadata.getFieldValue("name"));
    assertEquals(sampleDescription, scanMetadata.getFieldValue("description"));
    // Act again - merge scan request back into new mapping bean
    scanRequestConverter.mergeIntoMappingBean(scanRequest, newMappingBean);
    // Assert again - check the new mapping bean is the same as the old one
    SimpleSampleMetadata sampleMetadata = newMappingBean.getSampleMetadata();
    assertEquals(sampleName, sampleMetadata.getSampleName());
    assertEquals(sampleDescription, sampleMetadata.getDescription());
}
Also used : ScanRequest(org.eclipse.scanning.api.event.scan.ScanRequest) ScanMetadata(org.eclipse.scanning.api.scan.models.ScanMetadata) SimpleSampleMetadata(uk.ac.diamond.daq.mapping.impl.SimpleSampleMetadata) Test(org.junit.Test)

Example 30 with ScanRequest

use of org.eclipse.scanning.api.event.scan.ScanRequest in project gda-core by openGDA.

the class ScanRequestConverterTest method testProcessingRequestIncludedCorrectly.

@Test
public void testProcessingRequestIncludedCorrectly() throws Exception {
    ConfigWrapper wrapper = new ConfigWrapper();
    String appName = "test";
    String pathToConfig = "/path/to/config";
    wrapper.setAppName(appName);
    wrapper.setPathToConfig(pathToConfig);
    wrapper.setActive(true);
    mappingBean.addProcessingRequest(wrapper);
    // Act - convert mapping bean to scan request
    final ScanRequest scanRequest = scanRequestConverter.convertToScanRequest(mappingBean);
    // Assert
    ProcessingRequest processingRequest = scanRequest.getProcessingRequest();
    testProcessingRequest(appName, pathToConfig, processingRequest);
    // Act again - merge scan request into new mapping bean
    scanRequestConverter.mergeIntoMappingBean(scanRequest, newMappingBean);
    // Assert again - check the new mapping bean is the same as the old one
    ProcessingRequest r = new ProcessingRequest();
    r.setRequest(newMappingBean.getProcessingRequest());
    testProcessingRequest(appName, pathToConfig, r);
}
Also used : ScanRequest(org.eclipse.scanning.api.event.scan.ScanRequest) ConfigWrapper(uk.ac.diamond.daq.mapping.api.ConfigWrapper) ProcessingRequest(org.eclipse.scanning.api.event.scan.ProcessingRequest) Test(org.junit.Test)

Aggregations

ScanRequest (org.eclipse.scanning.api.event.scan.ScanRequest)42 Test (org.junit.Test)25 IDetectorModel (org.eclipse.scanning.api.device.models.IDetectorModel)8 ScanBean (org.eclipse.scanning.api.event.scan.ScanBean)8 CompoundModel (org.eclipse.scanning.api.points.models.CompoundModel)8 IScanPointGeneratorModel (org.eclipse.scanning.api.points.models.IScanPointGeneratorModel)8 ArrayList (java.util.ArrayList)7 ProcessingRequest (org.eclipse.scanning.api.event.scan.ProcessingRequest)7 IScanModelWrapper (uk.ac.diamond.daq.mapping.api.IScanModelWrapper)7 IMarshallerService (org.eclipse.dawnsci.analysis.api.persistence.IMarshallerService)5 ScanRegion (org.eclipse.scanning.api.points.models.ScanRegion)5 IScriptService (org.eclipse.scanning.api.script.IScriptService)5 IMappingExperimentBean (uk.ac.diamond.daq.mapping.api.IMappingExperimentBean)5 HashMap (java.util.HashMap)4 AxialStepModel (org.eclipse.scanning.api.points.models.AxialStepModel)4 IMappingScanRegion (uk.ac.diamond.daq.mapping.api.IMappingScanRegion)4 TemplateFileWrapper (uk.ac.diamond.daq.mapping.api.TemplateFileWrapper)4 DetectorModelWrapper (uk.ac.diamond.daq.mapping.impl.DetectorModelWrapper)4 IMalcolmModel (org.eclipse.scanning.api.device.models.IMalcolmModel)3 IMapPathModel (org.eclipse.scanning.api.points.models.IMapPathModel)3