Commit in hps-java on MAIN | |||
scripts/et_monitoring_app.sh | +2 | -1 | 1.2 -> 1.3 |
src/main/java/org/lcsim/hps/monitoring/EtConnection.java | +58 | added 1.1 | |
/EventPanel.java | +334 | added 1.1 | |
/ConnectionPanel.java | +262 | -40 | 1.3 -> 1.4 |
/ConnectionParameters.java | +27 | -2 | 1.3 -> 1.4 |
/MonitoringConsumer.java | +31 | -60 | 1.3 -> 1.4 |
/MonitoringGui.java | -304 | 1.3 removed | |
+714 | -407 |
diff -u -r1.2 -r1.3 --- et_monitoring_app.sh 25 Mar 2012 07:28:50 -0000 1.2 +++ et_monitoring_app.sh 26 Mar 2012 21:08:20 -0000 1.3 @@ -19,6 +19,7 @@
classpath=`pwd`/target/hps-java-1.1-SNAPSHOT-bin.jar # Run it.
-prod="java -classpath $classpath org.lcsim.hps.monitoring.MonitoringConsumer -c 100"
+prod="java -classpath "$classpath" org.lcsim.hps.monitoring.MonitoringConsumer" +# -c 100"
echo $prod exec $prod
diff -N EtConnection.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ EtConnection.java 26 Mar 2012 21:08:20 -0000 1.1 @@ -0,0 +1,58 @@
+package org.lcsim.hps.monitoring; + +import org.jlab.coda.et.EtAttachment; +import org.jlab.coda.et.EtConstants; +import org.jlab.coda.et.EtStation; +import org.jlab.coda.et.EtStationConfig; +import org.jlab.coda.et.EtSystem; +import org.jlab.coda.et.EtSystemOpenConfig; + +/** + * Create an EtSystem and EtAttachment from ConnectionParameters. + * @author Jeremy McCormick <[log in to unmask]> + */ +public class EtConnection { + + private EtSystem sys; + private EtAttachment att; + + public EtConnection(EtSystem sys, EtAttachment att) { + this.sys = sys; + this.att = att; + } + + public EtSystem getEtSystem() { + return sys; + } + + public EtAttachment getEtAttachment() { + return att; + } + + public static EtConnection makeEtConnection(ConnectionParameters cn) throws Exception { + // make a direct connection to ET system's tcp server + EtSystemOpenConfig config = new EtSystemOpenConfig(cn.etName, cn.host, cn.port); + + // create ET system object with verbose debugging output + EtSystem sys = new EtSystem(config, EtConstants.debugInfo); + sys.open(); + + // configuration of a new station + EtStationConfig statConfig = new EtStationConfig(); + statConfig.setFlowMode(cn.flowMode); + if (!cn.blocking) { + statConfig.setBlockMode(EtConstants.stationNonBlocking); + if (cn.qSize > 0) { + statConfig.setCue(cn.qSize); + } + } + + // create station + EtStation stat = sys.createStation(statConfig, cn.statName, cn.position, cn.pposition); + + // attach to new station + EtAttachment att = sys.attach(stat); + + return new EtConnection(sys, att); + } +}
\ No newline at end of file
diff -N EventPanel.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ EventPanel.java 26 Mar 2012 21:08:20 -0000 1.1 @@ -0,0 +1,334 @@
+package org.lcsim.hps.monitoring; + +import java.awt.Color; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.File; +import java.io.IOException; +import java.text.DecimalFormat; + +import javax.swing.JButton; +import javax.swing.JFileChooser; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; + +import org.lcsim.job.JobControlManager; +import org.lcsim.util.Driver; +import org.lcsim.util.aida.AIDA; + +public class EventPanel extends JPanel implements ActionListener { + + private JTextField eventCounterField; + private JTextField elapsedTimeField; + private JTextField avgEventRateField; + private JTextField refreshField; + private JTextField badEventsField; + private DecimalFormat rateFormat = new DecimalFormat("#.##"); + + private JButton resetButton; + private JButton saveButton; + private JButton quitButton; + + private static JobControlManager jobMgr; + private static EventPanel monitoringGui; + + // Refresh every 1000 events by default. + private int eventRefresh = 1000; + + private long jobStartTime; + private int eventCount; + private int badEventCount; + + EventPanel() { + + setLayout(new GridBagLayout()); + + GridBagConstraints c = new GridBagConstraints(); + + // Panel for labels and values. + c.gridx = 0; + c.gridy = 0; + JPanel fieldsPanel = new JPanel(); + fieldsPanel.setLayout(new GridBagLayout()); + add(fieldsPanel, c); + + // Panel for control buttons. + c = new GridBagConstraints(); + c.gridx = 0; + c.gridy = 1; + JPanel buttonsPanel = new JPanel(); + buttonsPanel.setLayout(new GridBagLayout()); + add(buttonsPanel, c); + + c = new GridBagConstraints(); + c.gridx = 0; + c.gridy = 0; + c.anchor = GridBagConstraints.WEST; + JLabel eventLabel = new JLabel("Events Processed: "); + eventLabel.setHorizontalAlignment(JLabel.LEFT); + fieldsPanel.add(eventLabel, c); + + c = new GridBagConstraints(); + c.gridx = 1; + c.gridy = 0; + c.anchor = GridBagConstraints.EAST; + eventCounterField = new JTextField("0", 6); + eventCounterField.setHorizontalAlignment(JTextField.RIGHT); + eventCounterField.setEditable(false); + eventCounterField.setBackground(Color.WHITE); + fieldsPanel.add(eventCounterField, c); + + c = new GridBagConstraints(); + c.gridx = 0; + c.gridy = 1; + c.anchor = GridBagConstraints.WEST; + JLabel timeLabel = new JLabel("Elapsed Time [ms]:"); + timeLabel.setHorizontalAlignment(JLabel.LEFT); + fieldsPanel.add(timeLabel, c); + + c = new GridBagConstraints(); + c.gridx = 1; + c.gridy = 1; + c.anchor = GridBagConstraints.EAST; + elapsedTimeField = new JTextField("0", 10); + elapsedTimeField.setHorizontalAlignment(JTextField.RIGHT); + elapsedTimeField.setEditable(false); + elapsedTimeField.setBackground(Color.WHITE); + fieldsPanel.add(elapsedTimeField, c); + + c = new GridBagConstraints(); + c.gridx = 0; + c.gridy = 2; + c.anchor = GridBagConstraints.WEST; + JLabel avgRateLabel = new JLabel("Average Event Rate [Hz]:"); + avgRateLabel.setHorizontalAlignment(JLabel.LEFT); + fieldsPanel.add(avgRateLabel, c); + + c = new GridBagConstraints(); + c.gridx = 1; + c.gridy = 2; + c.anchor = GridBagConstraints.EAST; + avgEventRateField = new JTextField("0", 6); + avgEventRateField.setHorizontalAlignment(JTextField.RIGHT); + avgEventRateField.setEditable(false); + avgEventRateField.setBackground(Color.WHITE); + fieldsPanel.add(avgEventRateField, c); + + c = new GridBagConstraints(); + c.gridx = 0; + c.gridy = 3; + c.anchor = GridBagConstraints.WEST; + JLabel refreshLabel = new JLabel("Event Refresh:"); + refreshLabel.setHorizontalAlignment(JLabel.LEFT); + fieldsPanel.add(refreshLabel, c); + + c = new GridBagConstraints(); + c.gridx = 1; + c.gridy = 3; + c.anchor = GridBagConstraints.EAST; + refreshField = new JTextField(Integer.toString(eventRefresh), 4); + refreshField.setHorizontalAlignment(JTextField.RIGHT); + fieldsPanel.add(refreshField, c); + + c = new GridBagConstraints(); + c.gridx = 0; + c.gridy = 4; + c.anchor = GridBagConstraints.WEST; + JLabel badEventsLabel = new JLabel("Bad Events:"); + badEventsLabel.setHorizontalAlignment(JLabel.LEFT); + fieldsPanel.add(badEventsLabel, c); + + c = new GridBagConstraints(); + c.gridx = 1; + c.gridy = 4; + c.anchor = GridBagConstraints.EAST; + badEventsField = new JTextField("0", 4); + badEventsField.setHorizontalAlignment(JTextField.RIGHT); + badEventsField.setEditable(false); + badEventsField.setBackground(Color.WHITE); + fieldsPanel.add(badEventsField, c); + + // Button padding. + Insets buttonInsets = new Insets(1, 1, 1, 1); + + c = new GridBagConstraints(); + c.gridx = 0; + c.gridy = 0; + c.fill = GridBagConstraints.BOTH; + c.insets = buttonInsets; + resetButton = new JButton("Reset"); + resetButton.setActionCommand("reset"); + resetButton.addActionListener(this); + resetButton.setToolTipText("Reset the GUI and the plots."); + buttonsPanel.add(resetButton, c); + + c = new GridBagConstraints(); + c.gridx = 1; + c.gridy = 0; + c.fill = GridBagConstraints.BOTH; + c.insets = buttonInsets; + saveButton = new JButton("Save Plots"); + saveButton.setActionCommand("save"); + saveButton.addActionListener(this); + saveButton.setToolTipText("Save the plots to an AIDA file."); + buttonsPanel.add(saveButton, c); + + c = new GridBagConstraints(); + c.gridx = 2; + c.gridy = 0; + c.fill = GridBagConstraints.BOTH; + c.insets = buttonInsets; + quitButton = new JButton("Quit"); + quitButton.setActionCommand("quit"); + quitButton.addActionListener(this); + quitButton.setToolTipText("Quit the job."); + buttonsPanel.add(quitButton, c); + } + + public static EventPanel getMonitoringGui() { + return EventPanel.monitoringGui; + } + + public void setJobControlManager(JobControlManager jobMgr) { + EventPanel.jobMgr = jobMgr; + } + + public int getEventCount() { + return eventCount; + } + + public int getEventRefresh() { + return Integer.parseInt(refreshField.getText()); + } + + public void updateEventCount() { + ++eventCount; + if (updateEvent()) { + eventCounterField.setText(Integer.toString(eventCount)); + } + } + + public void updateBadEventCount() { + ++badEventCount; + badEventsField.setText(Integer.toString(badEventCount)); + } + + public void updateJobStartTime() { + this.jobStartTime = System.currentTimeMillis(); + } + + public boolean updateEvent() { + return (eventCount % getEventRefresh()) == 0; + } + + public void updateAverageEventRate() { + if (updateEvent()) { + double jobTime = System.currentTimeMillis() - jobStartTime; + if (jobTime > 0) { + double jobSeconds = jobTime / 1000; + double eventsPerSecond = eventCount / jobSeconds; + avgEventRateField.setText(rateFormat.format(eventsPerSecond)); + } + } + } + + public void updateElapsedTime() { + if (updateEvent()) { + this.elapsedTimeField.setText(Long.toString(System.currentTimeMillis() - jobStartTime)); + } + } + + private void resetEventCount() { + eventCount = 0; + eventCounterField.setText("0"); + } + + private void resetElapsedTime() { + elapsedTimeField.setText("0"); + } + + private void resetDrivers() { + for (Driver driver : jobMgr.getDriverExecList()) { + if (driver instanceof Resettable) { + ((Resettable) driver).reset(); + } + } + } + + private void resetJobStartTime() { + jobStartTime = System.currentTimeMillis(); + } + + private void resetAverageEventRate() { + avgEventRateField.setText("0"); + } + + private void resetBadEventCount() { + this.badEventCount = 0; + this.badEventsField.setText("0"); + } + + public static void createAndShow() { + JFrame frame = new JFrame("HPS Monitoring GUI"); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + monitoringGui = new EventPanel(); + monitoringGui.setOpaque(true); + frame.setContentPane(monitoringGui); + + frame.pack(); + frame.setVisible(true); + } + + public void actionPerformed(ActionEvent e) { + String cmd = e.getActionCommand(); + if ("reset".equals(cmd)) { + reset(); + } else if ("save".equals(cmd)) { + save(); + } else if ("quit".equals(cmd)) { + quit(); + } + } + + private void reset() { + resetDrivers(); + resetEventCount(); + resetBadEventCount(); + resetAverageEventRate(); + resetElapsedTime(); + resetJobStartTime(); + } + + private void save() { + JFileChooser fc = new JFileChooser(); + int r = fc.showSaveDialog(EventPanel.this); + if (r == JFileChooser.APPROVE_OPTION) { + File fileName = fc.getSelectedFile(); + try { + AIDA.defaultInstance().saveAs(fileName); + } catch (IOException e) { + e.printStackTrace(); + } + } else { + System.out.println("Save operation was cancelled."); + } + } + + private void quit() { + System.exit(0); + } + + public static void main(String[] args) { + javax.swing.SwingUtilities.invokeLater(new Runnable() { + public void run() { + createAndShow(); + } + }); + } +}
\ No newline at end of file
diff -u -r1.3 -r1.4 --- ConnectionPanel.java 25 Mar 2012 08:55:11 -0000 1.3 +++ ConnectionPanel.java 26 Mar 2012 21:08:20 -0000 1.4 @@ -2,31 +2,54 @@
import java.awt.GridBagConstraints; import java.awt.GridBagLayout;
+import java.awt.Insets;
import java.awt.event.ActionEvent; import java.awt.event.ActionListener;
+import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Properties;
+import javax.swing.JButton;
import javax.swing.JCheckBox;
+import javax.swing.JFileChooser;
import javax.swing.JFrame; import javax.swing.JLabel;
+import javax.swing.JOptionPane;
import javax.swing.JPanel; import javax.swing.JTextField;
+import org.lcsim.util.aida.AIDA; +
public class ConnectionPanel extends JPanel implements ActionListener {
- JTextField etNameField; - JTextField hostField; - JTextField portField; - JCheckBox blockingField; - JCheckBox verboseField; - JTextField statNameField; - JTextField chunkField; - JTextField qSizeField; - JTextField positionField; - JTextField ppositionField;
+ private JPanel fieldsPanel; + private JPanel buttonsPanel; + + private JTextField etNameField; + private JTextField hostField; + private JTextField portField; + private JCheckBox blockingField; + private JCheckBox verboseField; + private JTextField statNameField; + private JTextField chunkField; + private JTextField qSizeField; + private JTextField positionField; + private JTextField ppositionField; + + private JButton connectButton; + private JButton disconnectButton; + private JButton saveButton; + private JButton loadButton; + private JButton resetButton; + + private ConnectionParameters connectionParameters;
- ConnectionParameters connectionParameters;
+ private static ConnectionPanel connectionPanel;
- boolean userWantsConnect;
+ private boolean connectPressed = false;
ConnectionPanel() {
@@ -34,15 +57,98 @@
connectionParameters = new ConnectionParameters(); setLayout(new GridBagLayout());
-
+ + // Panel for labels and values.
GridBagConstraints c = new GridBagConstraints();
+ c.gridx = 0; + c.gridy = 0; + JPanel fieldsPanel = new JPanel(); + fieldsPanel.setLayout(new GridBagLayout()); + add(fieldsPanel, c);
+ // Panel for control buttons. + c = new GridBagConstraints(); + c.gridx = 0; + c.gridy = 1; + JPanel buttonsPanel = new JPanel(); + buttonsPanel.setLayout(new GridBagLayout()); + add(buttonsPanel, c); + + // + // Define the buttons. + // + + // Button padding. + Insets buttonInsets = new Insets(1, 1, 1, 1); + + c = new GridBagConstraints(); + c.gridx = 0; + c.gridy = 0; + c.fill = GridBagConstraints.BOTH; + c.insets = buttonInsets; + connectButton = new JButton("Connect"); + connectButton.setActionCommand("connect"); + connectButton.addActionListener(this); + connectButton.setToolTipText("Connect to ET System using current parameters."); + buttonsPanel.add(connectButton, c); + + c = new GridBagConstraints(); + c.gridx = 1; + c.gridy = 0; + c.fill = GridBagConstraints.BOTH; + c.insets = buttonInsets; + disconnectButton = new JButton("Disconnect"); + disconnectButton.setActionCommand("disconnect"); + disconnectButton.addActionListener(this); + disconnectButton.setToolTipText("Disconnect from current ET session."); + disconnectButton.setEnabled(false); + buttonsPanel.add(disconnectButton, c); + + c = new GridBagConstraints(); + c.gridx = 2; + c.gridy = 0; + c.fill = GridBagConstraints.BOTH; + c.insets = buttonInsets; + saveButton = new JButton("Save"); + saveButton.setActionCommand("save"); + saveButton.addActionListener(this); + saveButton.setToolTipText("Save connection settings to properties file."); + saveButton.setEnabled(true); + buttonsPanel.add(saveButton, c); + + c = new GridBagConstraints(); + c.gridx = 3; + c.gridy = 0; + c.fill = GridBagConstraints.BOTH; + c.insets = buttonInsets; + loadButton = new JButton("Load"); + loadButton.setActionCommand("load"); + loadButton.addActionListener(this); + loadButton.setToolTipText("Load connection settings from properties file."); + buttonsPanel.add(loadButton, c); + + c = new GridBagConstraints(); + c.gridx = 4; + c.gridy = 0; + c.fill = GridBagConstraints.BOTH; + c.insets = buttonInsets; + resetButton = new JButton("Reset"); + resetButton.setActionCommand("reset"); + resetButton.addActionListener(this); + resetButton.setToolTipText("Resect connection settings to defaults."); + buttonsPanel.add(resetButton, c); + + // + // Define the fields. + // + + c = new GridBagConstraints();
c.gridx = 0; c.gridy = 0; c.anchor = GridBagConstraints.WEST; JLabel etNameLabel = new JLabel("ET Name:"); etNameLabel.setHorizontalAlignment(JLabel.LEFT);
- add(etNameLabel, c);
+ fieldsPanel.add(etNameLabel, c);
c = new GridBagConstraints(); c.gridx = 1;
@@ -51,7 +157,7 @@
etNameField = new JTextField("", 20); etNameField.setText(connectionParameters.etName); etNameField.setHorizontalAlignment(JTextField.RIGHT);
- add(etNameField, c);
+ fieldsPanel.add(etNameField, c);
c = new GridBagConstraints(); c.gridx = 0;
@@ -59,7 +165,7 @@
c.anchor = GridBagConstraints.WEST; JLabel hostLabel = new JLabel("Host:"); hostLabel.setHorizontalAlignment(JLabel.LEFT);
- add(hostLabel, c);
+ fieldsPanel.add(hostLabel, c);
c = new GridBagConstraints(); c.gridx = 1;
@@ -68,7 +174,7 @@
hostField = new JTextField("", 20); hostField.setText(connectionParameters.host); hostField.setHorizontalAlignment(JTextField.RIGHT);
- add(hostField, c);
+ fieldsPanel.add(hostField, c);
c = new GridBagConstraints(); c.gridx = 0;
@@ -76,7 +182,7 @@
c.anchor = GridBagConstraints.WEST; JLabel portLabel = new JLabel("Port:"); portLabel.setHorizontalAlignment(JLabel.LEFT);
- add(portLabel, c);
+ fieldsPanel.add(portLabel, c);
c = new GridBagConstraints(); c.gridx = 1;
@@ -84,7 +190,7 @@
c.anchor = GridBagConstraints.EAST; portField = new JTextField(Integer.toString(connectionParameters.port), 5); portField.setHorizontalAlignment(JTextField.RIGHT);
- add(portField, c);
+ fieldsPanel.add(portField, c);
c = new GridBagConstraints(); c.gridx = 0;
@@ -92,7 +198,7 @@
c.anchor = GridBagConstraints.WEST; JLabel blockingLabel = new JLabel("Blocking:"); blockingLabel.setHorizontalAlignment(JLabel.LEFT);
- add(blockingLabel, c);
+ fieldsPanel.add(blockingLabel, c);
c = new GridBagConstraints(); c.gridx = 1;
@@ -100,7 +206,7 @@
c.anchor = GridBagConstraints.EAST; blockingField = new JCheckBox(); blockingField.setSelected(connectionParameters.blocking);
- add(blockingField, c);
+ fieldsPanel.add(blockingField, c);
c = new GridBagConstraints(); c.gridx = 0;
@@ -108,7 +214,7 @@
c.anchor = GridBagConstraints.WEST; JLabel verboseLabel = new JLabel("Verbose:"); verboseLabel.setHorizontalAlignment(JLabel.LEFT);
- add(verboseLabel, c);
+ fieldsPanel.add(verboseLabel, c);
c = new GridBagConstraints(); c.gridx = 1;
@@ -116,7 +222,7 @@
c.anchor = GridBagConstraints.EAST; verboseField = new JCheckBox(); verboseField.setSelected(connectionParameters.verbose);
- add(verboseField, c);
+ fieldsPanel.add(verboseField, c);
c = new GridBagConstraints(); c.gridx = 0;
@@ -124,7 +230,7 @@
c.anchor = GridBagConstraints.WEST; JLabel statNameLabel = new JLabel("Station Name:"); statNameLabel.setHorizontalAlignment(JLabel.LEFT);
- add(statNameLabel, c);
+ fieldsPanel.add(statNameLabel, c);
c = new GridBagConstraints(); c.gridx = 1;
@@ -132,7 +238,7 @@
c.anchor = GridBagConstraints.EAST; statNameField = new JTextField(connectionParameters.statName, 10); statNameField.setHorizontalAlignment(JTextField.RIGHT);
- add(statNameField, c);
+ fieldsPanel.add(statNameField, c);
c = new GridBagConstraints(); c.gridx = 0;
@@ -141,7 +247,7 @@
JLabel chunkLabel = new JLabel("Chunk Size:"); chunkLabel.setToolTipText("Number of events returned in array."); chunkLabel.setHorizontalAlignment(JLabel.LEFT);
- add(chunkLabel, c);
+ fieldsPanel.add(chunkLabel, c);
c = new GridBagConstraints(); c.gridx = 1;
@@ -149,7 +255,7 @@
c.anchor = GridBagConstraints.EAST; chunkField = new JTextField(Integer.toString(connectionParameters.chunk), 3); chunkField.setHorizontalAlignment(JTextField.RIGHT);
- add(chunkField, c);
+ fieldsPanel.add(chunkField, c);
c = new GridBagConstraints(); c.gridx = 0;
@@ -157,7 +263,7 @@
c.anchor = GridBagConstraints.WEST; JLabel qSizeLabel = new JLabel("Queue Size:"); qSizeLabel.setHorizontalAlignment(JLabel.LEFT);
- add(qSizeLabel, c);
+ fieldsPanel.add(qSizeLabel, c);
c = new GridBagConstraints(); c.gridx = 1;
@@ -165,7 +271,7 @@
c.anchor = GridBagConstraints.EAST; qSizeField = new JTextField(Integer.toString(connectionParameters.qSize), 3); qSizeField.setHorizontalAlignment(JTextField.RIGHT);
- add(qSizeField, c);
+ fieldsPanel.add(qSizeField, c);
c = new GridBagConstraints(); c.gridx = 0;
@@ -173,7 +279,7 @@
c.anchor = GridBagConstraints.WEST; JLabel positionLabel = new JLabel("Station Position:"); positionLabel.setHorizontalAlignment(JLabel.LEFT);
- add(positionLabel, c);
+ fieldsPanel.add(positionLabel, c);
c = new GridBagConstraints(); c.gridx = 1;
@@ -181,7 +287,7 @@
c.anchor = GridBagConstraints.EAST; positionField = new JTextField(Integer.toString(connectionParameters.position), 3); positionField.setHorizontalAlignment(JLabel.RIGHT);
- add(positionField, c);
+ fieldsPanel.add(positionField, c);
c = new GridBagConstraints(); c.gridx = 0;
@@ -189,7 +295,7 @@
c.anchor = GridBagConstraints.WEST; JLabel ppositionLabel = new JLabel("Station Parallel Position:"); ppositionLabel.setHorizontalAlignment(JLabel.LEFT);
- add(ppositionLabel, c);
+ fieldsPanel.add(ppositionLabel, c);
c = new GridBagConstraints(); c.gridx = 1;
@@ -197,10 +303,12 @@
c.anchor = GridBagConstraints.EAST; ppositionField = new JTextField(Integer.toString(connectionParameters.pposition), 3); ppositionField.setHorizontalAlignment(JLabel.RIGHT);
- add(ppositionField, c);
+ fieldsPanel.add(ppositionField, c); + + // TODO Add connection status field = disconnected | connected | connecting
}
- ConnectionParameters getConnectionParameters() {
+ public ConnectionParameters getConnectionParameters() {
connectionParameters = new ConnectionParameters(); connectionParameters.etName = etNameField.getText(); connectionParameters.host = hostField.getText();
@@ -214,18 +322,132 @@
connectionParameters.pposition = Integer.parseInt(ppositionField.getText()); return connectionParameters; }
-
+ + public void setConnectionParameters(ConnectionParameters cn) { + etNameField.setText(cn.etName); + hostField.setText(cn.host); + portField.setText(Integer.toString(cn.port)); + blockingField.setSelected(cn.blocking); + verboseField.setSelected(cn.verbose); + statNameField.setText(cn.statName); + chunkField.setText(Integer.toString(cn.chunk)); + qSizeField.setText(Integer.toString(cn.qSize)); + positionField.setText(Integer.toString(cn.position)); + ppositionField.setText(Integer.toString(cn.pposition)); + this.connectionParameters = cn; + } +
public void actionPerformed(ActionEvent e) {
- // TODO Auto-generated method stub
+ if ("connect".equals(e.getActionCommand())) { + connect(); + } else if ("disconnect".equals(e.getActionCommand())) { + disconnect(); + } else if ("save".equals(e.getActionCommand())) { + save(); + } else if ("load".equals(e.getActionCommand())) { + load(); + } else if ("reset".equals(e.getActionCommand())) { + reset(); + } +
}
-
+ + private void connect() { + connectPressed = true; + connectButton.setEnabled(false); + disconnectButton.setEnabled(true); + loadButton.setEnabled(false); + resetButton.setEnabled(false); + } + + private void disconnect() { + connectPressed = false; + connectButton.setEnabled(true); + disconnectButton.setEnabled(false); + loadButton.setEnabled(true); + resetButton.setEnabled(true); + } + + private void save() { + JFileChooser fc = new JFileChooser(); + int r = fc.showSaveDialog(ConnectionPanel.this); + if (r == JFileChooser.APPROVE_OPTION) { + File file = fc.getSelectedFile(); + writePropertiesFile(file); + } + } + + private void load() { + JFileChooser fc = new JFileChooser(); + int r = fc.showOpenDialog(ConnectionPanel.this); + if (r == JFileChooser.APPROVE_OPTION) { + File file = fc.getSelectedFile(); + loadPropertiesFile(file); + } + } + + private void reset() { + this.setConnectionParameters(new ConnectionParameters()); + } + + public boolean connectPressed() { + return this.connectPressed; + } + + public static ConnectionPanel getConnectionPanel() { + return connectionPanel; + } + + private void writePropertiesFile(File file) { + Properties prop = new Properties(); + prop.setProperty("host", hostField.getText()); + prop.setProperty("port", portField.getText()); + prop.setProperty("blocking", blockingField.getText()); + prop.setProperty("verbose", verboseField.getText()); + prop.setProperty("statName", statNameField.getText()); + prop.setProperty("chunk", chunkField.getText()); + prop.setProperty("qSize", qSizeField.getText()); + prop.setProperty("position", positionField.getText()); + prop.setProperty("pposition", ppositionField.getText()); + try { + prop.store(new FileOutputStream(file), null); + } catch (Exception e) { + showErrorDialog(e.getLocalizedMessage()); + } + } + + public void showErrorDialog(String mesg) { + JOptionPane.showMessageDialog(this, mesg); + } + + private void loadPropertiesFile(File file) { + Properties prop = new Properties(); + try { + prop.load(new FileInputStream(file)); + hostField.setText(prop.getProperty("host")); + portField.setText(prop.getProperty("port")); + blockingField.setText(prop.getProperty("blocking")); + verboseField.setText(prop.getProperty("verbose")); + statNameField.setText(prop.getProperty("statName")); + chunkField.setText(prop.getProperty("chunk")); + qSizeField.setText(prop.getProperty("qSize")); + positionField.setText(prop.getProperty("position")); + ppositionField.setText(prop.getProperty("pposition")); + } catch (FileNotFoundException e) { + showErrorDialog(e.getLocalizedMessage()); + } catch (IOException e) { + showErrorDialog(e.getLocalizedMessage()); + } + this.connectionParameters = getConnectionParameters(); + } +
public static void createAndShow() { JFrame frame = new JFrame("ET Connection Dialog"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- JPanel c = new ConnectionPanel(); - c.setOpaque(true); - frame.setContentPane(c);
+ connectionPanel = new ConnectionPanel(); + connectionPanel.setOpaque(true); + frame.setContentPane(connectionPanel);
frame.pack(); frame.setVisible(true);
diff -u -r1.3 -r1.4 --- ConnectionParameters.java 25 Mar 2012 08:55:11 -0000 1.3 +++ ConnectionParameters.java 26 Mar 2012 21:08:20 -0000 1.4 @@ -1,9 +1,15 @@
package org.lcsim.hps.monitoring;
+import java.io.File;
import java.net.InetAddress; import java.net.UnknownHostException;
+import org.jlab.coda.et.EtAttachment;
import org.jlab.coda.et.EtConstants;
+import org.jlab.coda.et.EtStation; +import org.jlab.coda.et.EtStationConfig; +import org.jlab.coda.et.EtSystem; +import org.jlab.coda.et.EtSystemOpenConfig;
/** * Connection parameters for ET system consumer.
@@ -21,7 +27,7 @@
public int position = 1; public int pposition = 0; public int flowMode = EtConstants.stationSerial;
-
+
public ConnectionParameters() { // Set the default host. try {
@@ -50,7 +56,10 @@
" This consumer works by making a direct connection\n" + " to the ET system's tcp server port.\n"); }
-
+ + public void loadPropertiesFile(File propFile) { + } +
/** * Setup this ConnectionParameters object from command line arguments. *
@@ -137,4 +146,20 @@
super(msg); } }
+ + public String toString() { + StringBuffer buf = new StringBuffer(); + buf.append("etName: " + etName + '\n'); + buf.append("host: " + host + '\n'); + buf.append("port: " + port + '\n'); + buf.append("blocking: " + blocking + '\n'); + buf.append("verbose: " + verbose + '\n'); + buf.append("statName: " + statName + '\n'); + buf.append("chunk: " + chunk + '\n'); + buf.append("qSize: " + qSize + '\n'); + buf.append("position: " + position + '\n'); + buf.append("pposition: " + pposition + '\n'); + buf.append("flowMode: " + flowMode + '\n'); + return buf.toString(); + }
}
\ No newline at end of file
diff -u -r1.3 -r1.4 --- MonitoringConsumer.java 25 Mar 2012 08:55:11 -0000 1.3 +++ MonitoringConsumer.java 26 Mar 2012 21:08:20 -0000 1.4 @@ -6,12 +6,8 @@
import org.freehep.record.loop.event.RecordSuppliedEvent; import org.jlab.coda.et.EtAttachment;
-import org.jlab.coda.et.EtConstants;
import org.jlab.coda.et.EtEvent;
-import org.jlab.coda.et.EtStation; -import org.jlab.coda.et.EtStationConfig;
import org.jlab.coda.et.EtSystem;
-import org.jlab.coda.et.EtSystemOpenConfig;
import org.jlab.coda.et.enums.Mode; import org.jlab.coda.et.enums.Modify; import org.jlab.coda.et.exception.EtTimeoutException;
@@ -19,7 +15,6 @@
import org.jlab.coda.jevio.EvioReader; import org.lcsim.event.EventHeader; import org.lcsim.hps.evio.LCSimEventBuilder;
-import org.lcsim.hps.monitoring.ConnectionParameters.ConnectionParametersException;
import org.lcsim.job.JobControlManager; import org.lcsim.util.Driver; import org.lcsim.util.DriverAdapter;
@@ -40,57 +35,44 @@
//private static final String lcsimXml = "/org/lcsim/hps/steering/EtTest.lcsim"; private static final String lcsimXml = "/org/lcsim/hps/steering/EtSensorOccupancy.lcsim";
- private MonitoringGui gui;
+ private EventPanel gui;
//private int eventCount; private JobControlManager jobMgr;
-
+
public MonitoringConsumer() {} public static void main(String [] args) { MonitoringConsumer app = new MonitoringConsumer();
- app.run(args);
+ //app.run(args);
+ app.run();
}
- public void run(String[] args) { - - boolean debug = false;
+ public void run() { + + // Wait for connection settings via GUI. + ConnectionPanel.main(new String[]{}); + try { Thread.sleep(1000); } catch (InterruptedException e) {} + ConnectionPanel connectionPanel = ConnectionPanel.getConnectionPanel(); + while (!connectionPanel.connectPressed()) { + try { Thread.sleep(1000); } catch (InterruptedException e) {}; + } + ConnectionParameters cn = connectionPanel.getConnectionParameters();
- // Create ET system connection parameters. - ConnectionParameters cn = new ConnectionParameters(); - try { - cn.setup(args); - } catch (ConnectionParametersException e) { - e.printStackTrace(); - ConnectionParameters.usage(); - System.exit(1); - } - - try { - // make a direct connection to ET system's tcp server - EtSystemOpenConfig config = new EtSystemOpenConfig(cn.etName, cn.host, cn.port); - - // create ET system object with verbose debugging output - EtSystem sys = new EtSystem(config, EtConstants.debugInfo); - sys.open(); - - // configuration of a new station - EtStationConfig statConfig = new EtStationConfig(); - statConfig.setFlowMode(cn.flowMode); - if (!cn.blocking) { - statConfig.setBlockMode(EtConstants.stationNonBlocking); - if (cn.qSize > 0) { - statConfig.setCue(cn.qSize); - } - } - - // create station - EtStation stat = sys.createStation(statConfig, cn.statName, cn.position, cn.pposition); - - // attach to new station - EtAttachment att = sys.attach(stat); -
+ try { + + // Setup connection to ET system. + EtConnection et = EtConnection.makeEtConnection(cn); + EtSystem sys = et.getEtSystem(); + EtAttachment att = et.getEtAttachment(); + + // Show monitoring GUI. + EventPanel.main(new String[]{}); + Thread.sleep(2000); + gui = EventPanel.getMonitoringGui(); + gui.setJobControlManager(jobMgr); +
// Job manager to run LCSim. jobMgr = new JobControlManager(); jobMgr.checkInputFiles(false);
@@ -113,15 +95,7 @@
// Make the builder for creating LCSim events from EVIO data. LCSimEventBuilder eventBuilder = new LCSimEventBuilder(detectorName); eventBuilder.setDebug(false);
- - // Show GUI. - MonitoringGui.main(new String[]{}); - Thread.sleep(2000); - gui = MonitoringGui.getMonitoringGui(); - gui.setJobControlManager(jobMgr); - - //ConnectionPanel.main(new String[]{}); -
+
// Start job timer. gui.updateJobStartTime();
@@ -160,13 +134,10 @@
try { evioEvent = reader.parseNextEvent(); } catch (java.nio.BufferUnderflowException e) {
- // if (debug) - System.err.println("Caught underflow!");
+ // Error will be caught by subsequent check on null event.
}
- // We silently skip bad events (for now).
if (evioEvent == null) {
- //if (debug) - System.err.println("Failed to build EVIO event. Skipping this EtEvent!");
+ gui.updateBadEventCount();
continue; }
@@ -193,5 +164,5 @@
System.out.println("Error using ET system as consumer."); ex.printStackTrace(); }
- }
+ }
}
\ No newline at end of file
diff -N MonitoringGui.java --- MonitoringGui.java 25 Mar 2012 08:55:11 -0000 1.3 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,304 +0,0 @@
-package org.lcsim.hps.monitoring; - -import java.awt.Color; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Insets; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.io.File; -import java.io.IOException; -import java.text.DecimalFormat; - -import javax.swing.JButton; -import javax.swing.JFileChooser; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JTextField; - -import org.lcsim.job.JobControlManager; -import org.lcsim.util.Driver; -import org.lcsim.util.aida.AIDA; - -public class MonitoringGui extends JPanel implements ActionListener { - - private JTextField eventCounterField; - private JTextField elapsedTimeField; - private JTextField avgEventRateField; - private JTextField refreshField; - private DecimalFormat rateFormat = new DecimalFormat("#.##"); - - private JButton resetButton; - private JButton saveButton; - private JButton quitButton; - - private static JobControlManager jobMgr; - private static MonitoringGui monitoringGui; - - // Refresh every 1000 events by default. - private int eventRefresh = 1000; - - private long jobStartTime; - private int eventCount; - - MonitoringGui() { - - setLayout(new GridBagLayout()); - - GridBagConstraints c = new GridBagConstraints(); - - // Panel for labels and values. - c.gridx = 0; - c.gridy = 0; - JPanel fieldsPanel = new JPanel(); - fieldsPanel.setLayout(new GridBagLayout()); - add(fieldsPanel, c); - - // Panel for control buttons. - c = new GridBagConstraints(); - c.gridx = 0; - c.gridy = 1; - JPanel buttonsPanel = new JPanel(); - buttonsPanel.setLayout(new GridBagLayout()); - add(buttonsPanel, c); - - c = new GridBagConstraints(); - c.gridx = 0; - c.gridy = 0; - c.anchor = GridBagConstraints.WEST; - JLabel eventLabel = new JLabel("Events Processed: "); - eventLabel.setHorizontalAlignment(JLabel.LEFT); - fieldsPanel.add(eventLabel, c); - - c = new GridBagConstraints(); - c.gridx = 1; - c.gridy = 0; - c.anchor = GridBagConstraints.EAST; - eventCounterField = new JTextField("0", 6); - eventCounterField.setHorizontalAlignment(JTextField.RIGHT); - eventCounterField.setEditable(false); - eventCounterField.setBackground(Color.WHITE); - fieldsPanel.add(eventCounterField, c); - - c = new GridBagConstraints(); - c.gridx = 0; - c.gridy = 1; - c.anchor = GridBagConstraints.WEST; - JLabel timeLabel = new JLabel("Elapsed Time [ms]:"); - timeLabel.setHorizontalAlignment(JLabel.LEFT); - fieldsPanel.add(timeLabel, c); - - c = new GridBagConstraints(); - c.gridx = 1; - c.gridy = 1; - c.anchor = GridBagConstraints.EAST; - elapsedTimeField = new JTextField("0", 10); - elapsedTimeField.setHorizontalAlignment(JTextField.RIGHT); - elapsedTimeField.setEditable(false); - elapsedTimeField.setBackground(Color.WHITE); - fieldsPanel.add(elapsedTimeField, c); - - c = new GridBagConstraints(); - c.gridx = 0; - c.gridy = 2; - c.anchor = GridBagConstraints.WEST; - JLabel avgRateLabel = new JLabel("Average Event Rate [Hz]:"); - avgRateLabel.setHorizontalAlignment(JLabel.LEFT); - fieldsPanel.add(avgRateLabel, c); - - c = new GridBagConstraints(); - c.gridx = 1; - c.gridy = 2; - c.anchor = GridBagConstraints.EAST; - avgEventRateField = new JTextField("0", 6); - avgEventRateField.setHorizontalAlignment(JTextField.RIGHT); - avgEventRateField.setEditable(false); - avgEventRateField.setBackground(Color.WHITE); - fieldsPanel.add(avgEventRateField, c); - - c = new GridBagConstraints(); - c.gridx = 0; - c.gridy = 3; - c.anchor = GridBagConstraints.WEST; - JLabel refreshLabel = new JLabel("Event Refresh:"); - refreshLabel.setHorizontalAlignment(JLabel.LEFT); - fieldsPanel.add(refreshLabel, c); - - c = new GridBagConstraints(); - c.gridx = 1; - c.gridy = 3; - c.anchor = GridBagConstraints.EAST; - refreshField = new JTextField(Integer.toString(eventRefresh), 4); - refreshField.setHorizontalAlignment(JTextField.RIGHT); - - fieldsPanel.add(refreshField, c); - - // Button padding. - Insets buttonInsets = new Insets(1, 1, 1, 1); - - c = new GridBagConstraints(); - c.gridx = 0; - c.gridy = 0; - c.fill = GridBagConstraints.BOTH; - c.insets = buttonInsets; - resetButton = new JButton("Reset"); - resetButton.setActionCommand("reset"); - resetButton.addActionListener(this); - resetButton.setToolTipText("Reset the GUI and the plots."); - buttonsPanel.add(resetButton, c); - - c = new GridBagConstraints(); - c.gridx = 1; - c.gridy = 0; - c.fill = GridBagConstraints.BOTH; - c.insets = buttonInsets; - saveButton = new JButton("Save Plots"); - saveButton.setActionCommand("save"); - saveButton.addActionListener(this); - saveButton.setToolTipText("Save the plots to an AIDA file."); - buttonsPanel.add(saveButton, c); - - c = new GridBagConstraints(); - c.gridx = 2; - c.gridy = 0; - c.fill = GridBagConstraints.BOTH; - c.insets = buttonInsets; - quitButton = new JButton("Quit"); - quitButton.setActionCommand("quit"); - quitButton.addActionListener(this); - quitButton.setToolTipText("Quit the job."); - buttonsPanel.add(quitButton, c); - } - - public static MonitoringGui getMonitoringGui() { - return MonitoringGui.monitoringGui; - } - - public void setJobControlManager(JobControlManager jobMgr) { - MonitoringGui.jobMgr = jobMgr; - } - - public int getEventCount() { - return eventCount; - } - - public int getEventRefresh() { - return Integer.parseInt(refreshField.getText()); - } - - public void updateEventCount() { - ++eventCount; - if (updateEvent()) { - eventCounterField.setText(Integer.toString(eventCount)); - } - } - - public void updateJobStartTime() { - this.jobStartTime = System.currentTimeMillis(); - } - - public boolean updateEvent() { - return (eventCount % getEventRefresh()) == 0; - } - - public void updateAverageEventRate() { - if (updateEvent()) { - double jobTime = System.currentTimeMillis() - jobStartTime; - if (jobTime > 0) { - double jobSeconds = jobTime / 1000; - double eventsPerSecond = eventCount / jobSeconds; - avgEventRateField.setText(rateFormat.format(eventsPerSecond)); - } - } - } - - public void updateElapsedTime() { - if (updateEvent()) { - this.elapsedTimeField.setText(Long.toString(System.currentTimeMillis() - jobStartTime)); - } - } - - private void resetEventCount() { - eventCount = 0; - eventCounterField.setText("0"); - } - - private void resetElapsedTime() { - elapsedTimeField.setText("0"); - } - - private void resetDrivers() { - for (Driver driver : jobMgr.getDriverExecList()) { - if (driver instanceof Resettable) { - ((Resettable) driver).reset(); - } - } - } - - private void resetJobStartTime() { - jobStartTime = System.currentTimeMillis(); - } - - private void resetAverageEventRate() { - avgEventRateField.setText("0"); - } - - public static void createAndShow() { - JFrame frame = new JFrame("HPS Monitoring GUI"); - frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - - monitoringGui = new MonitoringGui(); - monitoringGui.setOpaque(true); - frame.setContentPane(monitoringGui); - - frame.pack(); - frame.setVisible(true); - } - - public void actionPerformed(ActionEvent e) { - String cmd = e.getActionCommand(); - if ("reset".equals(cmd)) { - reset(); - } else if ("save".equals(cmd)) { - save(); - } else if ("quit".equals(cmd)) { - quit(); - } - } - - private void reset() { - resetDrivers(); - resetEventCount(); - resetAverageEventRate(); - resetElapsedTime(); - resetJobStartTime(); - } - - private void save() { - JFileChooser fc = new JFileChooser(); - int r = fc.showSaveDialog(MonitoringGui.this); - if (r == JFileChooser.APPROVE_OPTION) { - File fileName = fc.getSelectedFile(); - try { - AIDA.defaultInstance().saveAs(fileName); - } catch (IOException e) { - e.printStackTrace(); - } - } else { - System.out.println("Save operation was cancelled."); - } - } - - private void quit() { - System.exit(0); - } - - public static void main(String[] args) { - javax.swing.SwingUtilities.invokeLater(new Runnable() { - public void run() { - createAndShow(); - } - }); - } -}
\ No newline at end of file