Search in sources :

Example 6 with CompoundModel

use of org.eclipse.scanning.api.points.models.CompoundModel in project gda-core by openGDA.

the class MScanSubmitterTest method trimIfStepAwkwardFitForRegionOccursOnGenerator.

@Test
public // Behaviour combined with {@link StepTest#testImperfectSequence} shows expected behaviour
void trimIfStepAwkwardFitForRegionOccursOnGenerator() throws Exception {
    final AxialStepModel expectedModel = new AxialStepModel(scannable.getName(), -1, 1, 0.3);
    expectedModel.setContinuous(false);
    Object[] arr = { scannable, RegionShape.AXIAL, -1, 1, Scanpath.AXIS_STEP, 0.3, detectorRunnableDevice };
    when(resolver.resolveScanClauses()).thenReturn(Arrays.asList(Arrays.asList(new ScannableElementProcessor(scannable), new RegionShapeElementProcessor(RegionShape.AXIAL), new NumberElementProcessor(-1), new NumberElementProcessor(1), new ScanpathElementProcessor(Scanpath.AXIS_STEP), new NumberElementProcessor(0.3)), Arrays.asList(new IRunnableDeviceDetectorElementProcessor(detectorRunnableDevice))));
    builder.buildAndSubmitBlockingScanRequest(arr);
    verify(submitter).blockingSubmit(beanCaptor.capture());
    verify(eventSubscriber).addListener(any(IScanListener.class));
    CompoundModel model = beanCaptor.getValue().getScanRequest().getCompoundModel();
    assertThat(model.getModels().get(0), is(equalTo(expectedModel)));
}
Also used : IScanListener(org.eclipse.scanning.api.event.scan.IScanListener) NumberElementProcessor(gda.mscan.processor.NumberElementProcessor) ScanpathElementProcessor(gda.mscan.processor.ScanpathElementProcessor) CompoundModel(org.eclipse.scanning.api.points.models.CompoundModel) ScannableElementProcessor(gda.mscan.processor.ScannableElementProcessor) IRunnableDeviceDetectorElementProcessor(gda.mscan.processor.IRunnableDeviceDetectorElementProcessor) AxialStepModel(org.eclipse.scanning.api.points.models.AxialStepModel) RegionShapeElementProcessor(gda.mscan.processor.RegionShapeElementProcessor) Test(org.junit.Test)

Example 7 with CompoundModel

use of org.eclipse.scanning.api.points.models.CompoundModel in project gda-core by openGDA.

the class MScanSubmitterTest method willNotAllowStaticScanWithoutDetectors.

@Test
public void willNotAllowStaticScanWithoutDetectors() throws Exception {
    // No Size, so default size=1
    Object[] arr = { Scanpath.STATIC };
    when(resolver.resolveScanClauses()).thenReturn(Arrays.asList(Arrays.asList(new ScanpathElementProcessor(Scanpath.STATIC))));
    builder.buildAndSubmitBlockingScanRequest(arr);
    verify(submitter).blockingSubmit(beanCaptor.capture());
    verify(eventSubscriber).addListener(any(IScanListener.class));
    ScanBean bean = beanCaptor.getValue();
    assertThat(bean.getScanRequest().getCompoundModel(), is(equalTo(new CompoundModel(new StaticModel()))));
}
Also used : IScanListener(org.eclipse.scanning.api.event.scan.IScanListener) ScanBean(org.eclipse.scanning.api.event.scan.ScanBean) ScanpathElementProcessor(gda.mscan.processor.ScanpathElementProcessor) CompoundModel(org.eclipse.scanning.api.points.models.CompoundModel) StaticModel(org.eclipse.scanning.api.points.models.StaticModel) Test(org.junit.Test)

Example 8 with CompoundModel

use of org.eclipse.scanning.api.points.models.CompoundModel in project gda-core by openGDA.

the class MScanSubmitter method buildAndSubmitScanRequest.

/**
 * Takes the supplied MScan array, validates it and then builds a {@link CompoundModel} that represents
 * the command. This is then submitted to the scanning queue as a blocking call. Currently supports detectors
 * based on the {@link Detector} interface with a matching {@link IRunnableDevice} representation. This has always
 * been the case as for Jython to pick up the type of a detector it must be {@link Findable} and
 * {@link IRunnableDevice} based object are not yet added to the Jython Namespace.
 *
 * @param args	The array of objects constituting the command supplied by jython. This should only contain
 * 				{@link Scannable}s, {@link Number}s and {@link IMScanElementEnum}s or their subclasses, if any
 * 				other objects are present, the validation will reject the command.
 * @param block	If true indicates that the scan submission should be a blocking call.
 *
 * @throws	IllegalArgumentException if the validation step fails or if the clause resolution is unsuccessful
 * 			ScanningException if the {@link IRunnableDevice} corresponding to a {@link Detector} cannot be found
 * 			or its {@link IDetectorModel} is null
 */
public void buildAndSubmitScanRequest(final Object[] args, final boolean block) throws Exception {
    throwIf(args == null, "The scan request array is null");
    LOGGER.info("MScan command received {}", Arrays.toString(args));
    final ScanClausesResolver resolver = standardiseAndValidateCommand(args);
    // First check for run from Nexus option
    IClauseElementProcessor initialProc = withNullProcessorCheck(processors.get(0));
    if (initialProc instanceof ReRunFromFileElementProcessor) {
        initialProc.process(null, processors, 0);
        try {
            final String filepath = initialProc.getElementValue();
            printToJython(Map.of("Loading scan from ", Paths.get(filepath).getFileName()));
            final Optional<ScanRequest> scanRequest = ScanRequestBuilder.buildFromNexusFile(filepath);
            submitFromFile(scanRequest.orElseThrow(), block);
        } catch (Exception e) {
            printToJython(Map.of("Exception: ", e.getMessage()));
        }
        return;
    }
    final CompoundModel scanModel = new CompoundModel();
    // Find the distinct clauses within the MScan command and return a list of the list of
    // typed processors for each clause.
    final List<List<IClauseElementProcessor>> processorsByClause = resolver.resolveScanClauses();
    throwIf(processorsByClause.isEmpty() || processorsByClause.contains(null), "clause resolution returned an empty or invalid list of processors by clause");
    final ClausesContext context = new ClausesContext(runnableDeviceService);
    // {@link Detectors} and {@link Monitors} or {@link IRunnableDevice}s
    for (final List<IClauseElementProcessor> clauseProcessors : processorsByClause) {
        throwIf(clauseProcessors.isEmpty() || clauseProcessors.contains(null), "clause resolution returned an empty or invalid processor list for a clause");
        context.wipe();
        initialProc = withNullProcessorCheck(clauseProcessors.get(0));
        // and so that processor must be switched.
        for (int index = 0; index < clauseProcessors.size(); index++) {
            if (context.isClauseProcessed()) {
                break;
            }
            // Handle single element Detector or Monitor clauses
            if (clauseProcessors.size() == 1) {
                throwIf(!context.isScanPathSeen() && !clauseProcessors.get(0).isStatic(), "No scan path defined - SPEC style scans not yet supported");
                if (initialProc instanceof ScannableElementProcessor) {
                    clauseProcessors.set(0, new ScannableReadoutElementProcessor((Scannable) initialProc.getElement()));
                }
            }
            clauseProcessors.get(index).process(context, clauseProcessors, index);
        }
        // this needs to be added to the CompoundModel for the entire mscan
        if (!context.isDetectorClauseSeen()) {
            context.addPathDefinitionToCompoundModel(scanModel);
        }
    }
    // Populate the {@link ScanRequest} with the assembled objects
    ScanRequest scanRequest = new ScanRequest();
    scanRequest.setCompoundModel(scanModel);
    scanRequest.setDetectors(context.getDetectorMap());
    scanRequest.setMonitorNamesPerPoint(context.getMonitorsPerPoint());
    scanRequest.setTemplateFilePaths(context.getTemplates());
    scanRequest.setMonitorNamesPerScan(context.getPerScanMonitors());
    scanRequest.setProcessingRequest(context.getProcessorRequest());
    if (context.getSampleMetadata() != null) {
        scanRequest.addScanMetadata(context.getSampleMetadata());
    }
    submit(scanRequest, block, null);
}
Also used : IClauseElementProcessor(gda.mscan.processor.IClauseElementProcessor) ScanRequest(org.eclipse.scanning.api.event.scan.ScanRequest) CompoundModel(org.eclipse.scanning.api.points.models.CompoundModel) ReRunFromFileElementProcessor(gda.mscan.processor.ReRunFromFileElementProcessor) ScannableElementProcessor(gda.mscan.processor.ScannableElementProcessor) ScannableReadoutElementProcessor(gda.mscan.processor.ScannableReadoutElementProcessor) List(java.util.List) ArrayList(java.util.ArrayList) Scannable(gda.device.Scannable)

Example 9 with CompoundModel

use of org.eclipse.scanning.api.points.models.CompoundModel in project gda-core by openGDA.

the class QueuePreventingScanSubmitterTest method getTestScanBean.

private ScanBean getTestScanBean() throws UnknownHostException {
    IScanPointGeneratorModel model = mock(IScanPointGeneratorModel.class);
    CompoundModel compoundModel = mock(CompoundModel.class);
    when(compoundModel.getModels()).thenReturn(Arrays.asList(model));
    ScanRequest scanRequest = mock(ScanRequest.class);
    doReturn(compoundModel).when(scanRequest).getCompoundModel();
    ScanBean bean = new ScanBean(scanRequest);
    bean.setName("test scan");
    return bean;
}
Also used : ScanRequest(org.eclipse.scanning.api.event.scan.ScanRequest) ScanBean(org.eclipse.scanning.api.event.scan.ScanBean) CompoundModel(org.eclipse.scanning.api.points.models.CompoundModel) IScanPointGeneratorModel(org.eclipse.scanning.api.points.models.IScanPointGeneratorModel)

Example 10 with CompoundModel

use of org.eclipse.scanning.api.points.models.CompoundModel in project gda-core by openGDA.

the class TimeSeriesScanView method createScanBean.

private ScanBean createScanBean() {
    final IMalcolmModel malcolmModel = malcolmModelEditor.getModel();
    final String malcolmDeviceName = malcolmModel.getName();
    final ScanRequest scanRequest = new ScanRequest();
    // add the malcolm model to the scan request
    final Map<String, IDetectorModel> detectors = new HashMap<>();
    detectors.put(malcolmDeviceName, malcolmModel);
    scanRequest.setDetectors(detectors);
    // extract the models from the outer scannables
    final List<IScanPointGeneratorModel> pointsModels = outerScannablesBlock.getOuterScannables().stream().filter(IScanModelWrapper<IScanPointGeneratorModel>::isIncludeInScan).map(IScanModelWrapper<IScanPointGeneratorModel>::getModel).collect(toCollection(ArrayList::new));
    final int numSteps = numStepsSpinner.getSelection();
    pointsModels.add(new StaticModel(numSteps));
    scanRequest.setCompoundModel(new CompoundModel(pointsModels));
    final ScanBean scanBean = new ScanBean(scanRequest);
    scanBean.setName(String.format("%s - Time Series", malcolmDeviceName));
    return scanBean;
}
Also used : HashMap(java.util.HashMap) StaticModel(org.eclipse.scanning.api.points.models.StaticModel) ScanRequest(org.eclipse.scanning.api.event.scan.ScanRequest) IDetectorModel(org.eclipse.scanning.api.device.models.IDetectorModel) ScanBean(org.eclipse.scanning.api.event.scan.ScanBean) IScanModelWrapper(uk.ac.diamond.daq.mapping.api.IScanModelWrapper) CompoundModel(org.eclipse.scanning.api.points.models.CompoundModel) IMalcolmModel(org.eclipse.scanning.api.device.models.IMalcolmModel) IScanPointGeneratorModel(org.eclipse.scanning.api.points.models.IScanPointGeneratorModel)

Aggregations

CompoundModel (org.eclipse.scanning.api.points.models.CompoundModel)21 Test (org.junit.Test)10 ScanpathElementProcessor (gda.mscan.processor.ScanpathElementProcessor)8 IScanListener (org.eclipse.scanning.api.event.scan.IScanListener)8 ScanBean (org.eclipse.scanning.api.event.scan.ScanBean)8 ScanRequest (org.eclipse.scanning.api.event.scan.ScanRequest)7 StaticModel (org.eclipse.scanning.api.points.models.StaticModel)7 IRunnableDeviceDetectorElementProcessor (gda.mscan.processor.IRunnableDeviceDetectorElementProcessor)6 ArrayList (java.util.ArrayList)6 IScanPointGeneratorModel (org.eclipse.scanning.api.points.models.IScanPointGeneratorModel)6 NumberElementProcessor (gda.mscan.processor.NumberElementProcessor)5 AxialStepModel (org.eclipse.scanning.api.points.models.AxialStepModel)5 IDetectorModel (org.eclipse.scanning.api.device.models.IDetectorModel)4 ScanRegion (org.eclipse.scanning.api.points.models.ScanRegion)4 ScannableElementProcessor (gda.mscan.processor.ScannableElementProcessor)3 IMapPathModel (org.eclipse.scanning.api.points.models.IMapPathModel)3 RegionShapeElementProcessor (gda.mscan.processor.RegionShapeElementProcessor)2 File (java.io.File)2 HashMap (java.util.HashMap)2 IPosition (org.eclipse.scanning.api.points.IPosition)2