Commit in hps-java/src on MAIN | |||
main/java/org/lcsim/hps/monitoring/ConnectionStatusPanel.java | +53 | added 1.1 | |
/MonitoringCommands.java | +17 | added 1.1 | |
/ConnectionPanel.java | +23 | -13 | 1.7 -> 1.8 |
/MonitoringApplication.java | +72 | -37 | 1.3 -> 1.4 |
/MonitoringExample.java | +11 | -17 | 1.3 -> 1.4 |
/SensorOccupancyPlotsDriver.java | +18 | -12 | 1.7 -> 1.8 |
test/java/org/lcsim/hps/evio/Evio4FileDumpTest.java | +1 | -1 | 1.2 -> 1.3 |
+195 | -80 |
additions and fix ups to monitoring app; lcsim now resets properly on disconnect
diff -N ConnectionStatusPanel.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ConnectionStatusPanel.java 27 Mar 2012 20:31:49 -0000 1.1 @@ -0,0 +1,53 @@
+package org.lcsim.hps.monitoring; + +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; + +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; + +class ConnectionStatusPanel extends JPanel { + + JTextField statusField; + + private static final String[] statuses = { "disconnected", "connected", "connecting", "timed out", "sleeping", "disconnecting" }; + + static final class ConnectionStatus { + static final int DISCONNECTED = 0; + static final int CONNECTED = 1; + static final int CONNECTING = 2; + static final int TIMED_OUT = 3; + static final int SLEEPING = 4; + static final int DISCONNECTING = 5; + } + + ConnectionStatusPanel() { + setLayout(new GridBagLayout()); + + GridBagConstraints c = new GridBagConstraints(); + c.gridx = 0; + c.gridy = 0; + c.anchor = GridBagConstraints.WEST; + JLabel statusLabel = new JLabel("Connection Status:"); + statusLabel.setHorizontalAlignment(JLabel.LEFT); + add(statusLabel, c); + + c = new GridBagConstraints(); + c.gridx = 1; + c.gridy = 0; + c.anchor = GridBagConstraints.EAST; + statusField = new JTextField("", 12); + statusField.setHorizontalAlignment(JTextField.RIGHT); + add(statusField, c); + + setStatus(ConnectionStatus.DISCONNECTED); + } + + public void setStatus(int idx) { + if (idx < 0 || idx > (statuses.length - 1)) { + throw new IllegalArgumentException("Invalid index value. Must be between 0 and " + statuses.length + "."); + } + statusField.setText(statuses[idx].toUpperCase()); + } +}
\ No newline at end of file
diff -N MonitoringCommands.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ MonitoringCommands.java 27 Mar 2012 20:31:49 -0000 1.1 @@ -0,0 +1,17 @@
+package org.lcsim.hps.monitoring; + +/** + * These are used for ActionEvents in the MonitoringApplication. + * @author Jeremy McCormick <[log in to unmask]> + */ +final class MonitoringCommands { + static final String connectCmd = "connect"; + static final String disconnectCmd = "disconnect"; + static final String saveConnectionCmd = "saveConnection"; + static final String loadConnectionCmd = "loadConnection"; + static final String resetConnectionSettingsCmd = "resetConnectionSettings"; + static final String resetEventsCmd = "resetEvents"; + static final String savePlotsCmd = "savePlots"; + static final String resetDriversCmd = "resetDrivers"; + static final String exitCmd = "exit"; +}
diff -u -r1.7 -r1.8 --- ConnectionPanel.java 27 Mar 2012 05:02:37 -0000 1.7 +++ ConnectionPanel.java 27 Mar 2012 20:31:49 -0000 1.8 @@ -1,5 +1,12 @@
package org.lcsim.hps.monitoring;
+import static org.lcsim.hps.monitoring.MonitoringCommands.connectCmd; +import static org.lcsim.hps.monitoring.MonitoringCommands.disconnectCmd; +import static org.lcsim.hps.monitoring.MonitoringCommands.loadConnectionCmd; +import static org.lcsim.hps.monitoring.MonitoringCommands.resetConnectionSettingsCmd; +import static org.lcsim.hps.monitoring.MonitoringCommands.saveConnectionCmd; + +
import java.awt.Color; import java.awt.GridBagConstraints; import java.awt.GridBagLayout;
@@ -21,9 +28,7 @@
import javax.swing.JTextField; import org.jlab.coda.et.enums.Mode;
-import org.lcsim.hps.monitoring.ConnectionParameters.WaitMode;
-// TODO Add status field of (connected|disconnected|connecting|timed out)
class ConnectionPanel extends JPanel implements ActionListener { private JTextField etNameField;
@@ -342,15 +347,15 @@
// FIXME These strings should be changed to constants. If there are duplications // with MonitorinApplication then move to common class like MonitoringCommands. public void actionPerformed(ActionEvent e) {
- if ("connect".equals(e.getActionCommand())) {
+ if (connectCmd.equals(e.getActionCommand())) {
setConnectRequested();
- } else if ("disconnect".equals(e.getActionCommand())) {
+ } else if (disconnectCmd.equals(e.getActionCommand())) {
setDisconnectRequested();
- } else if ("saveConnection".equals(e.getActionCommand())) {
+ } else if (saveConnectionCmd.equals(e.getActionCommand())) {
save();
- } else if ("loadConnection".equals(e.getActionCommand())) {
+ } else if (loadConnectionCmd.equals(e.getActionCommand())) {
load();
- } else if ("resetConnectionSettings".equals(e.getActionCommand())) {
+ } else if (resetConnectionSettingsCmd.equals(e.getActionCommand())) {
reset(); } }
@@ -401,6 +406,16 @@
JOptionPane.showMessageDialog(this, mesg); }
+ private void setWaitMode(String waitMode) { + if ("sleep".equals(waitMode.toLowerCase())) { + waitComboBox.setSelectedIndex(0); + } else if ("wait".equals(waitMode.toLowerCase())) { + waitComboBox.setSelectedIndex(1); + } else if ("async".equals(waitMode.toLowerCase())) { + waitComboBox.setSelectedIndex(2); + } + } +
private void loadPropertiesFile(File file) { Properties prop = new Properties(); try {
@@ -414,12 +429,7 @@
qSizeField.setText(prop.getProperty("qSize")); positionField.setText(prop.getProperty("position")); ppositionField.setText(prop.getProperty("pposition"));
- String waitMode = prop.getProperty("waitMode"); - if ("sleep".equals(waitMode.toLowerCase())) { - waitComboBox.setSelectedIndex(0); - } else if ("wait".equals(waitMode.toLowerCase())) { - waitComboBox.setSelectedIndex(1); - }
+ setWaitMode(prop.getProperty("waitMode"));
waitTimeField.setText(prop.getProperty("waitTime")); } catch (FileNotFoundException e) { showErrorDialog(e.getLocalizedMessage());
diff -u -r1.3 -r1.4 --- MonitoringApplication.java 27 Mar 2012 05:02:37 -0000 1.3 +++ MonitoringApplication.java 27 Mar 2012 20:31:49 -0000 1.4 @@ -1,6 +1,17 @@
package org.lcsim.hps.monitoring;
-import java.awt.BorderLayout;
+import static org.lcsim.hps.monitoring.MonitoringCommands.connectCmd; +import static org.lcsim.hps.monitoring.MonitoringCommands.disconnectCmd; +import static org.lcsim.hps.monitoring.MonitoringCommands.exitCmd; +import static org.lcsim.hps.monitoring.MonitoringCommands.loadConnectionCmd; +import static org.lcsim.hps.monitoring.MonitoringCommands.resetConnectionSettingsCmd; +import static org.lcsim.hps.monitoring.MonitoringCommands.resetDriversCmd; +import static org.lcsim.hps.monitoring.MonitoringCommands.resetEventsCmd; +import static org.lcsim.hps.monitoring.MonitoringCommands.saveConnectionCmd; +import static org.lcsim.hps.monitoring.MonitoringCommands.savePlotsCmd; + +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout;
import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent;
@@ -15,18 +26,19 @@
import javax.swing.JPanel; import javax.swing.JTabbedPane;
+import org.lcsim.hps.monitoring.ConnectionStatusPanel.ConnectionStatus;
import org.lcsim.job.JobControlManager; import org.lcsim.util.Driver; import org.lcsim.util.aida.AIDA;
-//TODO Add connection status field = disconnected | connected | connecting
public class MonitoringApplication extends JPanel implements ActionListener { private JTabbedPane tabs; private ConnectionPanel connectionPanel;
+ private ConnectionStatusPanel connectionStatusPanel;
private EventPanel eventPanel;
- private JobPanel jobPanel;
+ private JobPanel jobPanel;
private JMenuBar menuBar;
@@ -39,32 +51,58 @@
JMenuItem resetEventsItem; JMenuItem savePlotsItem; JMenuItem resetDriversItem;
- - final String connectCmd = "connect"; - final String disconnectCmd = "disconnect"; - final String saveConnectionCmd = "saveConnection"; - final String loadConnectionCmd = "loadConnection"; - final String resetConnectionSettingsCmd = "resetConnectionSettings"; - final String resetEventsCmd = "resetEvents"; - final String savePlotsCmd = "savePlots"; - final String resetDriversCmd = "resetDrivers"; - final String exitCmd = "exit"; -
+
private JobControlManager mgr = null; public MonitoringApplication() {
- super(new BorderLayout()); -
+ //super(new BorderLayout()); + super(new GridBagLayout()); + + // Setup the menus. + createMenu(); +
//
- // Menu bar.
+ // Connection status panel, placed at top.
//
+ GridBagConstraints c = new GridBagConstraints(); + c.gridx = 0; + c.gridy = 0; + c.anchor = GridBagConstraints.NORTHWEST; + connectionStatusPanel = new ConnectionStatusPanel(); + add(connectionStatusPanel, c); + + // + // Create a tab for each sub-panel. + // + + JPanel tabsPanel = new JPanel(); + + tabs = new JTabbedPane(); + + connectionPanel = new ConnectionPanel(); + eventPanel = new EventPanel(); + jobPanel = new JobPanel(); + + tabs.addTab("Connection", connectionPanel); + tabs.addTab("Event Monitor", eventPanel); + tabs.addTab("Job Settings", jobPanel); + + tabsPanel.add(tabs); + + c = new GridBagConstraints(); + c.gridx = 0; + c.gridy = 1; + add(tabsPanel, c); + } + + private void createMenu() { +
menuBar = new JMenuBar(); JMenu connectionMenu = new JMenu("Connection");
- menuBar.add(connectionMenu); -
+ menuBar.add(connectionMenu);
connectItem = new JMenuItem("Connect"); connectItem.setMnemonic(KeyEvent.VK_C);
@@ -128,22 +166,6 @@
resetDriversItem.addActionListener(this); resetDriversItem.setEnabled(false); jobMenu.add(resetDriversItem);
- - // - // Create tabs for panels. - // - - tabs = new JTabbedPane(); - - connectionPanel = new ConnectionPanel(); - eventPanel = new EventPanel(); - jobPanel = new JobPanel(); - - tabs.addTab("Connection", connectionPanel); - tabs.addTab("Event Monitor", eventPanel); - tabs.addTab("Job Settings", jobPanel); - - add(tabs);
} public void setJobControlManager(JobControlManager mgr) {
@@ -212,6 +234,9 @@
// Re-enable the ConnectionPanel. connectionPanel.enableConnectionPanel(true);
+ // Set status. + connectionStatusPanel.setStatus(ConnectionStatus.DISCONNECTED); +
// Reset the LCSim Drivers, which should destroy Plotters. resetDrivers(); }
@@ -225,6 +250,9 @@
connectionLoadItem.setEnabled(false); savePlotsItem.setEnabled(true); resetDriversItem.setEnabled(true);
+ + // Set status. + connectionStatusPanel.setStatus(ConnectionStatus.CONNECTED);
} ConnectionPanel getConnectionPanel() {
@@ -238,15 +266,22 @@
JobPanel getJobPanel() { return jobPanel; }
+ + ConnectionStatusPanel getConnectionStatusPanel() { + return connectionStatusPanel; + }
+ /** + * Sets up the frame to run the application. + * This should be called using Runnable.run() (see MonitoringExample). + */
void start() { JFrame frame = new JFrame("HPS Monitoring"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-
this.setOpaque(true); frame.setContentPane(this); frame.setJMenuBar(menuBar);
-
+ frame.setResizable(false);
frame.pack(); frame.setVisible(true); }
diff -u -r1.3 -r1.4 --- MonitoringExample.java 27 Mar 2012 05:02:37 -0000 1.3 +++ MonitoringExample.java 27 Mar 2012 20:31:49 -0000 1.4 @@ -16,7 +16,7 @@
import org.jlab.coda.jevio.EvioReader; import org.lcsim.event.EventHeader; import org.lcsim.hps.evio.LCSimEventBuilder;
-import org.lcsim.hps.monitoring.ConnectionParameters.WaitMode;
+import org.lcsim.hps.monitoring.ConnectionStatusPanel.ConnectionStatus;
import org.lcsim.job.JobControlManager; import org.lcsim.util.DriverAdapter;
@@ -24,6 +24,8 @@
* This is an example monitoring application using the classes from the org.lcsim.hps.monitoring package. * @author Jeremy McCormick */
+// TODO Allow interrupt of sleep mode using EtWakeUpException. Probably need a separate thread to do this. To +// set connection status to "sleeping", would probably also need a separate thread that checks for this state.
public class MonitoringExample { private static final String defaultDetectorName = "HPS-Test-JLAB-v4pt0";
@@ -60,7 +62,7 @@
// GUI loop. Use 'Exit' command from GUI to quit. while (true) {
- // Wait for connection to be requested via GUI.
+ // Wait for connection request from GUI.
while (!connectionPanel.connectRequested()) { try { Thread.sleep(1000); } catch (InterruptedException e) {}; }
@@ -68,6 +70,7 @@
// This makes sure applicable menu items are enabled/disabled. gui.connect();
+ gui.getConnectionStatusPanel().setStatus(ConnectionStatus.CONNECTING);
// Try block is mostly for EtExceptions and friends. try {
@@ -108,23 +111,13 @@
Mode waitMode = cn.waitMode; int waitTime = cn.waitTime; int chunk = cn.chunk;
+ + gui.getConnectionStatusPanel().setStatus(ConnectionStatus.CONNECTED);
// EtEvent loop. while (true) { try {
- // Choose wait or sleep mode depending on connection settings. - /* - if (cn.waitMode == Mode.TIMED) { - mevs = sys.getEvents(att, Mode.TIMED, Modify.NOTHING, cn.waitTime, cn.chunk); - } else if (cn.waitMode == Mode.SLEEP) { - mevs = sys.getEvents(att, Mode.SLEEP, Modify.NOTHING, 0, cn.chunk); - } else if (cn.waitMode == Mode.ASYNC) { - mevs = sys.getEvents(att, Mode.ASYNC, Modify.NOTHING, 0, cn.chunk); - } - */ -
// Get EtEvents.
- // TODO Allow interrupt of sleep mode using EtWakeUpException. (not sure how though!)
mevs = sys.getEvents(att, waitMode, Modify.NOTHING, waitTime, chunk); // Loop over retrieved EtEvents.
@@ -165,13 +158,14 @@
// Break out of event loop if GUI wants disconnect. if (connectionPanel.disconnectRequested()) {
- System.out.println("Disconnect requested. Breaking out of event loop.");
+ gui.getConnectionStatusPanel().setStatus(ConnectionStatus.DISCONNECTING); + driverAdapter.finish(null);
gui.disconnect(); break; }
-
+ // Session timed out.
} catch (EtTimeoutException e) {
- System.out.println("ET Consumer timed out.");
+ gui.getConnectionStatusPanel().setStatus(ConnectionStatus.TIMED_OUT);
driverAdapter.finish(null); break; }
diff -u -r1.7 -r1.8 --- SensorOccupancyPlotsDriver.java 27 Mar 2012 05:02:37 -0000 1.7 +++ SensorOccupancyPlotsDriver.java 27 Mar 2012 20:31:49 -0000 1.8 @@ -69,21 +69,21 @@
protected void detectorChanged(Detector detector) { // If called multiple times then destroy plots that might be currently up.
- if (occuPlotter != null) { - occuPlotter.hide(); - occuPlotter.destroyRegions(); - }
+ //if (occuPlotter != null) { + // occuPlotter.hide(); + // occuPlotter.destroyRegions(); + //}
// Setup the plotter. Should only need to be done once per job. IAnalysisFactory fac = aida.analysisFactory();
- if (occuPlotter == null) { - occuPlotter = fac.createPlotterFactory().create(detector.getDetectorName() + " : HPS SVT Sensor Occupancy Plots"); - IPlotterStyle pstyle = occuPlotter.style(); - pstyle.dataStyle().fillStyle().setColor("green"); - pstyle.dataStyle().markerStyle().setColor("green"); - pstyle.dataStyle().errorBarStyle().setVisible(false); - pstyle.statisticsBoxStyle().setVisible(false); - }
+ //if (occuPlotter == null) { + occuPlotter = fac.createPlotterFactory().create(detector.getDetectorName() + " : HPS SVT Sensor Occupancy Plots"); + IPlotterStyle pstyle = occuPlotter.style(); + pstyle.dataStyle().fillStyle().setColor("green"); + pstyle.dataStyle().markerStyle().setColor("green"); + pstyle.dataStyle().errorBarStyle().setVisible(false); + pstyle.statisticsBoxStyle().setVisible(false); + //}
// Create regions. occuPlotter.createRegions(5, 4); // FIXME Hard-coded to 20 sensors.
@@ -156,9 +156,15 @@
} }
+ public void endOfData() { + occuPlotter.hide(); + } +
public void reset() {
+ //occuPlotter.hide();
eventCount = 0; resetOccupancyMap();
+ //resetOccupancyMap();
//detectorChanged(detector); } }
\ No newline at end of file
diff -u -r1.2 -r1.3 --- Evio4FileDumpTest.java 25 Mar 2012 07:28:17 -0000 1.2 +++ Evio4FileDumpTest.java 27 Mar 2012 20:31:50 -0000 1.3 @@ -18,7 +18,7 @@
FileCache cache = new FileCache(); cache.setCacheDirectory(new File(".testdata"));
- File evioTestData = cache.getCachedFile(new URL("http://www.lcsim.org/test/hps/hps_000246.dat"));
+ File evioTestData = cache.getCachedFile(new URL("http://www.lcsim.org/test/hps/hps_000246.dat")); // ECal data in pulse integral mode
EvioReader reader = new EvioReader(evioTestData); EvioEvent event = reader.parseNextEvent();
Use REPLY-ALL to reply to list
To unsubscribe from the LCD-CVS list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=LCD-CVS&A=1