Closedown
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
* Copyright (c) 2014-2017 Paul Scherrer Institute. All rights reserved.
|
||||
*/
|
||||
|
||||
import ch.psi.jcae.ChannelException;
|
||||
import ch.psi.pshell.device.DescStatsDouble;
|
||||
import ch.psi.pshell.epics.Epics;
|
||||
import ch.psi.pshell.plot.LinePlotErrorSeries;
|
||||
import ch.psi.pshell.plot.LinePlotJFree;
|
||||
import ch.psi.pshell.plot.Plot;
|
||||
@@ -11,22 +13,34 @@ import ch.psi.pshell.scan.ScanListener;
|
||||
import ch.psi.pshell.scan.ScanRecord;
|
||||
import ch.psi.pshell.ui.Panel;
|
||||
import ch.psi.utils.State;
|
||||
import ch.psi.utils.swing.SwingUtils;
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class GunScan extends Panel {
|
||||
LinePlotErrorSeries series = new LinePlotErrorSeries("Values");
|
||||
|
||||
LinePlotErrorSeries seriesEnergy = new LinePlotErrorSeries("Energy");
|
||||
LinePlotErrorSeries seriesEnergySpread = new LinePlotErrorSeries("Energy Spread");
|
||||
double dispersion;
|
||||
double energy0;
|
||||
|
||||
public GunScan() {
|
||||
initComponents();
|
||||
initComponents();
|
||||
plot.setStyle(LinePlotJFree.Style.ErrorY);
|
||||
plot.addSeries(series);
|
||||
plot.addSeries(seriesEnergy);
|
||||
plot.addSeries(seriesEnergySpread);
|
||||
plot.getAxis(Plot.AxisId.X).setLabel("Gun Phase");
|
||||
plot.getAxis(Plot.AxisId.Y).setLabel("MeV");
|
||||
plot.setLegendVisible(true);
|
||||
}
|
||||
|
||||
//Overridable callbacks
|
||||
//Overridable callbacks
|
||||
@Override
|
||||
public void onInitialize(int runCount) {
|
||||
}
|
||||
@@ -46,38 +60,58 @@ public class GunScan extends Panel {
|
||||
public void onExecutedFile(String fileName, Object result) {
|
||||
}
|
||||
|
||||
|
||||
//Callback to perform update - in event thread
|
||||
@Override
|
||||
protected void doUpdate() {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
getContext().addScanListener(scanListener);
|
||||
try {
|
||||
spinnerDispersion.setValue(Epics.get("SINBD01-DSCR010:DISPERSION-SIM", Double.class));
|
||||
spinnerEnergy.setValue(Epics.get("SINBD01-DSCR010:ENERGY-SIM", Double.class));
|
||||
} catch (Exception ex) {
|
||||
showException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
public void onStop() {
|
||||
getContext().removeScanListener(scanListener);
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
|
||||
ScanListener scanListener = new ScanListener() {
|
||||
@Override
|
||||
public void onScanStarted(Scan scan, String plotTitle) {
|
||||
if ("GunScan".equals(getContext().getExecutionPars().getName())){
|
||||
series.clear();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onNewRecord(Scan scan, ScanRecord record) {
|
||||
if ("GunScan".equals(getContext().getExecutionPars().getName())){
|
||||
series.appendData((Double)record.getPositions()[0], ((DescStatsDouble)record.getValues()[0]).getMean(),
|
||||
((DescStatsDouble)record.getValues()[0]).getStdev());
|
||||
public void onScanStarted(Scan scan, String plotTitle) {
|
||||
if ("GunScan".equals(getContext().getExecutionPars().getName())) {
|
||||
seriesEnergy.clear();
|
||||
seriesEnergySpread.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNewRecord(Scan scan, ScanRecord record) {
|
||||
if ("GunScan".equals(getContext().getExecutionPars().getName())) {
|
||||
double phase = (Double) record.getPositions()[0];
|
||||
double energy_mean = ((DescStatsDouble) record.getValues()[0]).getMean();
|
||||
double energy_std = ((DescStatsDouble) record.getValues()[0]).getStdev();
|
||||
double energy_sp_mean = ((DescStatsDouble) record.getValues()[1]).getMean();
|
||||
double energy_sp_std = ((DescStatsDouble) record.getValues()[1]).getStdev();
|
||||
seriesEnergy.appendData(phase,
|
||||
energy0 * (1 +energy_mean / 1e6 / dispersion),
|
||||
0
|
||||
);
|
||||
|
||||
seriesEnergySpread.appendData(phase,
|
||||
energy0 * (energy_sp_mean / 1e6 / dispersion),
|
||||
0
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScanEnded(Scan scan, Exception ex) {
|
||||
}
|
||||
@@ -133,7 +167,7 @@ public class GunScan extends Panel {
|
||||
spinnerLatency.setModel(new javax.swing.SpinnerNumberModel(0.1d, 0.0d, 5.0d, 0.01d));
|
||||
spinnerLatency.setPreferredSize(new java.awt.Dimension(64, 20));
|
||||
|
||||
spinnerStop.setModel(new javax.swing.SpinnerNumberModel(360.0d, -180.0d, 360.0d, 1.0d));
|
||||
spinnerStop.setModel(new javax.swing.SpinnerNumberModel(180.0d, -180.0d, 360.0d, 1.0d));
|
||||
spinnerStop.setMinimumSize(new java.awt.Dimension(53, 20));
|
||||
spinnerStop.setPreferredSize(new java.awt.Dimension(64, 20));
|
||||
|
||||
@@ -238,8 +272,18 @@ public class GunScan extends Panel {
|
||||
plot.setTitle("");
|
||||
|
||||
buttonStart.setText("Start");
|
||||
buttonStart.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
buttonStartActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
buttonAbort.setText("Abort");
|
||||
buttonAbort.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
buttonAbortActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
|
||||
this.setLayout(layout);
|
||||
@@ -262,8 +306,8 @@ public class GunScan extends Panel {
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
|
||||
.addComponent(plot, javax.swing.GroupLayout.PREFERRED_SIZE, 419, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(plot, javax.swing.GroupLayout.DEFAULT_SIZE, 419, Short.MAX_VALUE)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
@@ -278,6 +322,39 @@ public class GunScan extends Panel {
|
||||
jPanel1.getAccessibleContext().setAccessibleDescription("");
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void buttonStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStartActionPerformed
|
||||
ArrayList parameters = new ArrayList();
|
||||
dispersion = (Double)spinnerDispersion.getValue();
|
||||
energy0 = (Double)spinnerEnergy.getValue();
|
||||
parameters.add(spinnerStart.getValue());
|
||||
parameters.add(spinnerStop.getValue());
|
||||
parameters.add(spinnerStep.getValue());
|
||||
parameters.add(spinnerSamples.getValue());
|
||||
parameters.add(spinnerLatency.getValue());
|
||||
parameters.add(dispersion);
|
||||
parameters.add(energy0);
|
||||
try {
|
||||
runAsync("RFscan/GunScan", parameters).handle((ret, ex) -> {
|
||||
if (ex != null) {
|
||||
getLogger().info("Exception executing scan: " + ex);
|
||||
} else {
|
||||
|
||||
}
|
||||
return ret;
|
||||
});
|
||||
} catch (Exception ex) {
|
||||
showException(ex);
|
||||
}
|
||||
}//GEN-LAST:event_buttonStartActionPerformed
|
||||
|
||||
private void buttonAbortActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAbortActionPerformed
|
||||
try {
|
||||
abort();
|
||||
} catch (Exception ex) {
|
||||
showException(ex);
|
||||
}
|
||||
}//GEN-LAST:event_buttonAbortActionPerformed
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JButton buttonAbort;
|
||||
private javax.swing.JButton buttonStart;
|
||||
|
||||
Reference in New Issue
Block a user