Search in sources :

Example 1 with Scannable

use of gda.device.Scannable in project gda-core by openGDA.

the class ScannableCommandsTest method testPosWithTripleConcurrentMove.

/**
 * TODO: This test is getting far too big
 * @throws Exception
 */
@Test
public void testPosWithTripleConcurrentMove() throws Exception {
    ScannableCommands.pos(lev5a, 1.3, lev6, 1.4, lev5b, 1.35, lev4, 1.2);
    InOrder inOrder = inOrder(lev4, lev5a, lev5b, lev6);
    // NOTE: The order of this four is unimportant
    inOrder.verify(lev5a).checkPositionValid(1.3);
    inOrder.verify(lev6).checkPositionValid(1.4);
    // inOrder.verify(lev5b).checkPositionValid(1.35); Not ScannableMotion so not checked
    inOrder.verify(lev4).checkPositionValid(1.2);
    inOrder.verify(lev4).atLevelStart();
    inOrder.verify(lev4).atLevelMoveStart();
    inOrder.verify(lev4).asynchronousMoveTo(1.2);
    inOrder.verify(lev4).waitWhileBusy();
    inOrder.verify(lev4).atLevelEnd();
    // NOTE: Order of any pair here is unimportant
    inOrder.verify(lev5a).atLevelStart();
    inOrder.verify(lev5b).atLevelStart();
    inOrder.verify(lev5a).atLevelMoveStart();
    inOrder.verify(lev5b).atLevelMoveStart();
    inOrder.verify(lev5a).asynchronousMoveTo(1.3);
    inOrder.verify(lev5b).asynchronousMoveTo(1.35);
    inOrder.verify(lev5a).waitWhileBusy();
    inOrder.verify(lev5b).waitWhileBusy();
    inOrder.verify(lev5a).atLevelEnd();
    inOrder.verify(lev5b).atLevelEnd();
    inOrder.verify(lev6).atLevelStart();
    inOrder.verify(lev6).atLevelMoveStart();
    inOrder.verify(lev6).asynchronousMoveTo(1.4);
    inOrder.verify(lev6).waitWhileBusy();
    inOrder.verify(lev6).atLevelEnd();
    // NOTE: getPosition() order unimportant
    inOrder.verify(lev5a).getPosition();
    inOrder.verify(lev6).getPosition();
    inOrder.verify(lev5b).getPosition();
    inOrder.verify(lev4).getPosition();
    for (Scannable scn : Arrays.asList(lev4, lev5a, lev5b, lev6)) {
        verify(scn, times(1)).atLevelStart();
        verify(scn, times(1)).atLevelMoveStart();
        verify(scn, times(1)).asynchronousMoveTo(any());
        verify(scn, times(1)).waitWhileBusy();
        verify(scn, times(1)).atLevelEnd();
    }
}
Also used : InOrder(org.mockito.InOrder) Scannable(gda.device.Scannable) Test(org.junit.Test)

Example 2 with Scannable

use of gda.device.Scannable in project gda-core by openGDA.

the class ConcurrentScanTest method testWithDetectorsSingleStartPosition.

@Test
public void testWithDetectorsSingleStartPosition() throws Exception {
    testScratchDirectoryName = TestHelpers.setUpTest(this.getClass(), "testWithDetectorsSingleStartPosition", true);
    setLocalProperties();
    Scannable scn = MockFactory.createMockScannable("scn");
    new ConcurrentScan(new Object[] { scn, 0., 2., 1., detlev9a, .1, detlev9b, .2, detlev5 }).runScan();
    verify(detlev9a).setCollectionTime(.1);
    verify(detlev9a, never()).asynchronousMoveTo(any());
    verify(detlev9b).setCollectionTime(.2);
    verify(detlev9b, never()).asynchronousMoveTo(any());
    verify(detlev5, never()).setCollectionTime(anyDouble());
    verify(detlev5, never()).asynchronousMoveTo(any());
}
Also used : DummyScannable(gda.device.scannable.DummyScannable) Scannable(gda.device.Scannable) Test(org.junit.Test)

Example 3 with Scannable

use of gda.device.Scannable in project gda-core by openGDA.

the class ConcurrentScanTest method testSrsFileWriting.

/**
 * This test is performed here as the resulting file depends on on ConcurrentScan, DataPoint and SrsDataFile.
 */
@Test
public void testSrsFileWriting() throws Exception {
    testScratchDirectoryName = TestHelpers.setUpTest(this.getClass(), "testSrsFileWriting", true);
    setLocalProperties();
    LocalProperties.set(LocalProperties.GDA_DATA_SCAN_DATAWRITER_DATAFORMAT, "SrsDataFile");
    LocalProperties.set("gda.data.scan.datawriter.dataFormat.SrsDataFile.aligncolumns", "False");
    Scannable lev7 = MockFactory.createMockScannable("lev7", 7);
    when(lev4.getInputNames()).thenReturn(new String[] { "lev4" });
    when(lev5a.getInputNames()).thenReturn(new String[] { "lev5a" });
    when(lev5b.getInputNames()).thenReturn(new String[] { "lev5b_returns_a_string" });
    when(lev6.getInputNames()).thenReturn(new String[] { "lev6" });
    when(lev7.getInputNames()).thenReturn(new String[] { "lev7" });
    when(lev4.getOutputFormat()).thenReturn(new String[] { "%f" });
    when(lev5a.getOutputFormat()).thenReturn(new String[] { "%i" });
    when(lev5b.getOutputFormat()).thenReturn(new String[] { "%s" });
    when(lev6.getOutputFormat()).thenReturn(new String[] { "% 5.5" });
    when(lev7.getOutputFormat()).thenReturn(new String[] { "%-5.5" });
    when(lev4.getPosition()).thenReturn(0.123456789);
    when(lev5a.getPosition()).thenReturn(1234);
    when(lev5b.getPosition()).thenReturn("12string34");
    when(lev6.getPosition()).thenReturn(210.123456789);
    when(lev7.getPosition()).thenReturn(-210.123456789);
    Object[] args = new Object[] { lev4, 0., 2., 1., lev5a, 1., lev5b, 2., lev6, 3., lev7 };
    ConcurrentScan scan = new ConcurrentScan(args);
    scan.runScan();
    System.out.print(scan.getDataWriter().getCurrentFileName());
    // ASCII file compare
    assertEquals(Files.readAllLines(Paths.get("testfiles/gda/scan/ConcurrentScanTest/testSrsFileWriting_expected.dat")), Files.readAllLines(Paths.get(testScratchDirectoryName + "/Data/1.dat")));
}
Also used : DummyScannable(gda.device.scannable.DummyScannable) Scannable(gda.device.Scannable) Test(org.junit.Test)

Example 4 with Scannable

use of gda.device.Scannable in project gda-core by openGDA.

the class ConcurrentScanTest method testScan.

/**
 * Verify the appropriate bits on a scannable are called in a scan for command: scan smoved 0 10 1 sread
 *
 * @throws InterruptedException
 * @throws Exception
 */
@Test
public void testScan() throws InterruptedException, Exception {
    testScratchDirectoryName = TestHelpers.setUpTest(this.getClass(), "testScan", true);
    setLocalProperties();
    Scannable smoved = MockFactory.createMockScannable("smoved");
    Scannable sread = MockFactory.createMockScannable("sread");
    Object[] args = new Object[] { smoved, 0., 10., 1., sread, detlev9a, 2. };
    ConcurrentScan scan = new ConcurrentScan(args);
    scan.runScan();
    verify(smoved, times(11)).getPosition();
    verify(smoved, times(11)).atPointStart();
    verify(smoved, times(11)).atPointEnd();
    verify(smoved, times(1)).atScanLineStart();
    verify(smoved, times(1)).atScanEnd();
    verify(smoved, times(1)).atScanLineStart();
    verify(smoved, times(1)).atScanLineEnd();
    verify(sread, times(11)).getPosition();
    verify(sread, never()).asynchronousMoveTo(any());
    verify(sread, never()).asynchronousMoveTo(any());
    verify(sread, times(11)).atPointStart();
    verify(sread, times(11)).atPointEnd();
    verify(sread, times(1)).atScanLineStart();
    verify(sread, times(1)).atScanEnd();
    verify(sread, times(1)).atScanLineStart();
    verify(sread, times(1)).atScanLineEnd();
    verify(detlev9a, times(11)).readout();
    verify(detlev9a, never()).asynchronousMoveTo(any());
    verify(detlev9a, never()).asynchronousMoveTo(any());
    verify(detlev9a, times(11)).atPointStart();
    verify(detlev9a, times(11)).atPointEnd();
    verify(detlev9a, times(1)).atScanLineStart();
    verify(detlev9a, times(1)).atScanEnd();
    verify(detlev9a, times(1)).atScanLineStart();
    verify(detlev9a, times(1)).atScanLineEnd();
    InOrder inOrder = inOrder(smoved);
    inOrder.verify(smoved).asynchronousMoveTo(0.);
    inOrder.verify(smoved).asynchronousMoveTo(1.);
    inOrder.verify(smoved).asynchronousMoveTo(2.);
    inOrder.verify(smoved).asynchronousMoveTo(3.);
    inOrder.verify(smoved).asynchronousMoveTo(4.);
    inOrder.verify(smoved).asynchronousMoveTo(5.);
    inOrder.verify(smoved).asynchronousMoveTo(6.);
    inOrder.verify(smoved).asynchronousMoveTo(7.);
    inOrder.verify(smoved).asynchronousMoveTo(8.);
    inOrder.verify(smoved).asynchronousMoveTo(9.);
    inOrder.verify(smoved).asynchronousMoveTo(10.);
}
Also used : InOrder(org.mockito.InOrder) DummyScannable(gda.device.scannable.DummyScannable) Scannable(gda.device.Scannable) Test(org.junit.Test)

Example 5 with Scannable

use of gda.device.Scannable 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)

Aggregations

Scannable (gda.device.Scannable)192 Test (org.junit.Test)82 DeviceException (gda.device.DeviceException)43 DummyScannable (gda.device.scannable.DummyScannable)34 Detector (gda.device.Detector)31 ArrayList (java.util.ArrayList)22 ScannableGroup (gda.device.scannable.scannablegroup.ScannableGroup)18 HashMap (java.util.HashMap)12 File (java.io.File)11 ConcurrentScan (gda.scan.ConcurrentScan)10 ContinuouslyScannable (gda.device.scannable.ContinuouslyScannable)9 IScannableGroup (gda.device.scannable.scannablegroup.IScannableGroup)9 Map (java.util.Map)9 ScannableSnapshot (gda.device.scannable.ScannableSnapshot)8 GdaJythonBuiltin (gda.jython.GdaJythonBuiltin)8 List (java.util.List)8 DataNode (org.eclipse.dawnsci.analysis.api.tree.DataNode)8 ScannableMotionUnits (gda.device.ScannableMotionUnits)6 DummyMultiFieldUnitsScannable (gda.device.scannable.DummyMultiFieldUnitsScannable)6 FactoryException (gda.factory.FactoryException)6