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)));
}
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()))));
}
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);
}
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;
}
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;
}
Aggregations