This repository was archived by the owner on Mar 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Adding Seek to AcquisitionDevice #568
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
be73203
Added step to the toString() method
gerring 2353648
Made a new abstract class to run scan tests from.
gerring d7d6507
Added extra exception for when the move is interrupted.
gerring 1854baa
Ensured that a step index is set. This should *really* come from spg!
gerring a9fb2ed
Added concept of active scanner so that Jython scripts can do a seek.
gerring f6bbbba
Set the step index
gerring 76469ce
Import clean up
gerring 0150d89
Added getPositioner/setPositioner
gerring 682d7d0
Fix to seek functionality to set position correctly.
gerring 4859507
Added NPE protection.
gerring 795cd0c
Fix to test.
gerring 7983418
Move variable responding to SonarQube advice.
gerring 10ba732
Removed Thread.sleep(...) as SonarQube requests.
gerring 775acaf
Fix to static comment from SonarQube
gerring e22153a
Respond to SonarQube rule for <?>
gerring 2522c63
Added test of new active scanner feature for jython.
gerring File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,11 +32,13 @@ public class CompoundIterator implements Iterator<IPosition> { | |
| private CompoundGenerator gen; | ||
| private IPosition pos; | ||
| private Iterator<? extends IPosition>[] iterators; | ||
| private int index; | ||
|
|
||
| public CompoundIterator(CompoundGenerator gen) throws GeneratorException { | ||
| this.gen = gen; | ||
| this.iterators = initIterators(); | ||
| this.pos = createFirstPosition(); | ||
| this.index = -1; | ||
| } | ||
|
|
||
| private IPosition createFirstPosition() throws GeneratorException { | ||
|
|
@@ -57,6 +59,9 @@ private IPosition createFirstPosition() throws GeneratorException { | |
| @Override | ||
| public boolean hasNext() { | ||
| next = getNext(); | ||
| index++; | ||
| if (next!=null) next.setStepIndex(index); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| justDidNext = true; | ||
| return next!=null; | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,6 +54,7 @@ public class CompoundSpgIterator extends AbstractScanPointIterator { | |
|
|
||
| public SerializableIterator<IPosition> pyIterator; | ||
| private IPosition currentPoint; | ||
| private int index = -1; | ||
|
|
||
| public CompoundSpgIterator(CompoundGenerator gen) throws GeneratorException { | ||
| this.gen = gen; | ||
|
|
@@ -75,7 +76,9 @@ public CompoundSpgIterator(CompoundGenerator gen) throws GeneratorException { | |
| @SuppressWarnings("unchecked") | ||
| SerializableIterator<IPosition> iterator = (SerializableIterator<IPosition>) compoundGeneratorFactory.createObject( | ||
| iterators, excluders, mutators); | ||
| pyIterator = iterator; | ||
|
|
||
| index = -1; | ||
| pyIterator = iterator; | ||
| } | ||
|
|
||
| private IPosition createFirstPosition() throws GeneratorException { | ||
|
|
@@ -106,6 +109,8 @@ public boolean hasNext() { | |
| // | ||
| // if (gen.containsPoint(x, y)) { | ||
| currentPoint = point; | ||
| index++; | ||
| if (currentPoint!=null) currentPoint.setStepIndex(index); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| return true; | ||
| // } | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,7 +74,7 @@ | |
| * @author Matthew Gerring | ||
| */ | ||
| final class AcquisitionDevice extends AbstractRunnableDevice<ScanModel> implements IPositionListener { | ||
|
|
||
| // Scanning stuff | ||
| private IPositioner positioner; | ||
| private LevelRunner<IRunnableDevice<?>> runners; | ||
|
|
@@ -199,6 +199,7 @@ public void configure(ScanModel model) throws ScanningException { | |
| @Override | ||
| public void run(IPosition parent) throws ScanningException, InterruptedException { | ||
|
|
||
|
|
||
| if (getDeviceState()!=DeviceState.READY) throw new ScanningException("The device '"+getName()+"' is not ready. It is in state "+getDeviceState()); | ||
|
|
||
| ScanModel model = getModel(); | ||
|
|
@@ -215,6 +216,7 @@ public void run(IPosition parent) throws ScanningException, InterruptedException | |
| boolean errorFound = false; | ||
| IPosition pos = null; | ||
| try { | ||
| RunnableDeviceServiceImpl.setCurrentScanningDevice(this); | ||
| if (latch!=null) latch.countDown(); | ||
| this.latch = new CountDownLatch(1); | ||
| // TODO Should we validate the position iterator that all | ||
|
|
@@ -256,7 +258,7 @@ public void run(IPosition parent) throws ScanningException, InterruptedException | |
|
|
||
| // Check if we are paused, blocks until we are not | ||
| boolean continueRunning = checkPaused(); | ||
| if (!continueRunning) return; // finally block performed | ||
| if (!continueRunning) return; // finally block performed | ||
|
|
||
| // Run to the position | ||
| manager.invoke(PointStart.class, pos); | ||
|
|
@@ -265,14 +267,13 @@ public void run(IPosition parent) throws ScanningException, InterruptedException | |
| IPosition written = writers.await(); // Wait for the previous write out to return, if any | ||
| if (written!=null) manager.invoke(WriteComplete.class, written); | ||
|
|
||
| nexusScanFileManager.flushNexusFile(); // flush the nexus file | ||
| runners.run(pos); // GDA8: collectData() / GDA9: run() for Malcolm | ||
| runners.run(pos); // GDA8: collectData() / GDA9: run() for Malcolm | ||
| writers.run(pos, false); // Do not block on the readout, move to the next position immediately. | ||
|
|
||
| // Send an event about where we are in the scan | ||
| manager.invoke(PointEnd.class, pos); | ||
| positionComplete(pos, count, size); | ||
| ++count; | ||
| count+=Math.max(innerSize, 1); | ||
| } | ||
|
|
||
| // On the last iteration we must wait for the final readout. | ||
|
|
@@ -292,6 +293,7 @@ public void run(IPosition parent) throws ScanningException, InterruptedException | |
|
|
||
| } finally { | ||
| close(errorFound, pos); | ||
| RunnableDeviceServiceImpl.setCurrentScanningDevice(null); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -561,13 +563,33 @@ public void pause() throws ScanningException { | |
| } | ||
|
|
||
| @Override | ||
| public void seek(int stepNumber) throws ScanningException { | ||
| // TODO FIXME The positioner should seek back to the previous position!! | ||
| public void seek(int stepNumber) throws ScanningException, InterruptedException { | ||
| // This is the values of all motors at this global (including malcolm) scan | ||
| // position. Therefore we do not need a subscan moderator but can run the iterator | ||
| // to the point | ||
| IPosition pos = positionForStep(stepNumber); | ||
| if (pos == null) throw new ScanningException("Seek position is invalid "+stepNumber); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| positioner.setPosition(pos); | ||
| if (getModel().getDetectors()!=null) for (IRunnableDevice<?> device : getModel().getDetectors()) { | ||
| if (device instanceof IPausableDevice) ((IPausableDevice)device).seek(stepNumber); | ||
| } | ||
| } | ||
|
|
||
| private IPosition positionForStep(int stepNumber) { | ||
| /* | ||
| * IMPORTANT We do not keep the positions in memory because there can be millions. | ||
| * Running over them is fast however. | ||
| */ | ||
| int count=0; | ||
| for (IPosition pos : model.getPositionIterable()) { | ||
| pos.setStepIndex(count); | ||
| if (count == stepNumber) return pos; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| count++; | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public void resume() throws ScanningException { | ||
|
|
||
|
|
@@ -690,4 +712,9 @@ private int getScanRank(Iterable<IPosition> gen) { | |
| return scanRank; | ||
| } | ||
|
|
||
| @Override | ||
| public IPositioner getPositioner() { | ||
| return positioner; | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.