Commit in hps-java on MAIN
scripts/et_evio_file_producer_test.sh-31.8 -> 1.9
       /et_monitoring_app.sh+1-11.5 -> 1.6
src/main/java/org/lcsim/hps/monitoring/ConnectionPanel.java+171-1681.11 -> 1.12
                                      /ConnectionParameters.java+7-31.8 -> 1.9
                                      /ConnectionStatusPanel.java+10-161.1 -> 1.2
                                      /EcalMonitoringPlots.java+11-61.2 -> 1.3
                                      /EtConnection.java+62-451.5 -> 1.6
                                      /EventPanel.java+96-351.4 -> 1.5
                                      /MonitoringApplication.java+511-1741.8 -> 1.9
                                      /SensorOccupancyPlotsDriver.java+4-41.10 -> 1.11
                                      /MonitoringExample.java-2551.10 removed
+873-710
1 removed + 10 modified, total 11 files
updates to monitoring classes; major refactoring of primary monitoring application

hps-java/scripts
et_evio_file_producer_test.sh 1.8 -> 1.9
diff -u -r1.8 -r1.9
--- et_evio_file_producer_test.sh	2 Apr 2012 18:59:12 -0000	1.8
+++ et_evio_file_producer_test.sh	8 Apr 2012 23:48:11 -0000	1.9
@@ -23,8 +23,5 @@
 
 # Run it.
 prod="java -classpath $classpath org.lcsim.hps.evio.EvioFileProducer -e ${eviofile} -f ETBuffer -host $(hostname) -s 4000"
-# -d 1"
-#-s 5000"
-# -d 10"
 echo $prod
 exec $prod

hps-java/scripts
et_monitoring_app.sh 1.5 -> 1.6
diff -u -r1.5 -r1.6
--- et_monitoring_app.sh	2 Apr 2012 18:59:12 -0000	1.5
+++ et_monitoring_app.sh	8 Apr 2012 23:48:11 -0000	1.6
@@ -19,7 +19,7 @@
 classpath=`pwd`/target/hps-java-1.1-SNAPSHOT-bin.jar
 
 # Run it.
-prod="java -classpath "$classpath" org.lcsim.hps.monitoring.MonitoringExample"
+prod="java -classpath "$classpath" org.lcsim.hps.monitoring.MonitoringApplication"
 # -c 100"
 echo $prod
 exec $prod

hps-java/src/main/java/org/lcsim/hps/monitoring
ConnectionPanel.java 1.11 -> 1.12
diff -u -r1.11 -r1.12
--- ConnectionPanel.java	4 Apr 2012 23:26:07 -0000	1.11
+++ ConnectionPanel.java	8 Apr 2012 23:48:11 -0000	1.12
@@ -29,43 +29,43 @@
 import org.jlab.coda.et.enums.Mode;
 
 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;
-     JComboBox waitComboBox; 
-     JTextField waitTimeField;
-     JTextField prescaleField;
-                    
+
+    JTextField etNameField;
+    JTextField hostField;
+    JTextField portField;
+    JCheckBox blockingField;
+    JCheckBox verboseField;
+    JTextField statNameField;
+    JTextField chunkField;
+    JTextField qSizeField;
+    JTextField positionField;
+    JTextField ppositionField;
+    JComboBox waitComboBox; 
+    JTextField waitTimeField;
+    JTextField prescaleField;
+
     ConnectionParameters connectionParameters;
-        
+
     boolean connectRequested = false;    
     boolean disconnectRequested = false;
-    
+
     static final String[] waitModes = { 
-    	Mode.SLEEP.toString(), 
-    	Mode.TIMED.toString(), 
-    	Mode.ASYNC.toString() 
+        Mode.SLEEP.toString(), 
+        Mode.TIMED.toString(), 
+        Mode.ASYNC.toString() 
     };
 
     ConnectionPanel() {
-            	
+
         // Starting GUI values will be assigned from default connection parameters. 
         connectionParameters = new ConnectionParameters();
-        
+
         setLayout(new GridBagLayout());        
-                     
+
         //
         // Define the fields.
         //
-        
+
         GridBagConstraints c = new GridBagConstraints();
         c.gridx = 0;
         c.gridy = 0;
@@ -128,7 +128,7 @@
         c.anchor = GridBagConstraints.EAST;
         blockingField = new JCheckBox();
         add(blockingField, c);
-        
+
         c = new GridBagConstraints();
         c.gridx = 0;
         c.gridy = 4;
@@ -136,14 +136,14 @@
         JLabel verboseLabel = new JLabel("Verbose:");
         verboseLabel.setHorizontalAlignment(JLabel.LEFT);
         add(verboseLabel, c);
-        
+
         c = new GridBagConstraints();
         c.gridx = 1;
         c.gridy = 4;
         c.anchor = GridBagConstraints.EAST;
         verboseField = new JCheckBox();
         add(verboseField, c);
-                
+
         c = new GridBagConstraints();
         c.gridx = 0;
         c.gridy = 5;
@@ -151,7 +151,7 @@
         JLabel statNameLabel = new JLabel("Station Name:");
         statNameLabel.setHorizontalAlignment(JLabel.LEFT);
         add(statNameLabel, c);
-        
+
         c = new GridBagConstraints();
         c.gridx = 1;
         c.gridy = 5;
@@ -159,7 +159,7 @@
         statNameField = new JTextField(10);
         statNameField.setHorizontalAlignment(JTextField.RIGHT);
         add(statNameField, c);
-        
+
         c = new GridBagConstraints();
         c.gridx = 0;
         c.gridy = 6;
@@ -168,7 +168,7 @@
         chunkLabel.setToolTipText("Number of events returned in array.");
         chunkLabel.setHorizontalAlignment(JLabel.LEFT);
         add(chunkLabel, c);
-        
+
         c = new GridBagConstraints();
         c.gridx = 1;
         c.gridy = 6;
@@ -176,7 +176,7 @@
         chunkField = new JTextField(3);
         chunkField.setHorizontalAlignment(JTextField.RIGHT);
         add(chunkField, c);
-        
+
         c = new GridBagConstraints();
         c.gridx = 0;
         c.gridy = 7;
@@ -184,7 +184,7 @@
         JLabel qSizeLabel = new JLabel("Queue Size:");
         qSizeLabel.setHorizontalAlignment(JLabel.LEFT);
         add(qSizeLabel, c);
-        
+
         c = new GridBagConstraints();
         c.gridx = 1;
         c.gridy = 7;
@@ -192,7 +192,7 @@
         qSizeField = new JTextField(3);
         qSizeField.setHorizontalAlignment(JTextField.RIGHT);
         add(qSizeField, c);
-        
+
         c = new GridBagConstraints();
         c.gridx = 0;
         c.gridy = 8;
@@ -200,7 +200,7 @@
         JLabel positionLabel = new JLabel("Station Position:");
         positionLabel.setHorizontalAlignment(JLabel.LEFT);
         add(positionLabel, c);
-        
+
         c = new GridBagConstraints();
         c.gridx = 1;
         c.gridy = 8;
@@ -208,7 +208,7 @@
         positionField = new JTextField(3);
         positionField.setHorizontalAlignment(JLabel.RIGHT);
         add(positionField, c);
-        
+
         c = new GridBagConstraints();
         c.gridx = 0;
         c.gridy = 9;
@@ -216,7 +216,7 @@
         JLabel ppositionLabel = new JLabel("Station Parallel Position:");
         ppositionLabel.setHorizontalAlignment(JLabel.LEFT);
         add(ppositionLabel, c);
-        
+
         c = new GridBagConstraints();
         c.gridx = 1;
         c.gridy = 9;
@@ -224,7 +224,7 @@
         ppositionField = new JTextField(3);
         ppositionField.setHorizontalAlignment(JLabel.RIGHT);
         add(ppositionField, c);
-        
+
         c = new GridBagConstraints();
         c.gridx = 0;
         c.gridy = 10;
@@ -232,14 +232,14 @@
         JLabel waitModeLabel = new JLabel("Wait Mode:");
         waitModeLabel.setHorizontalAlignment(JLabel.LEFT);
         add(waitModeLabel, c);
-        
+
         c = new GridBagConstraints();
         c.gridx = 1;
         c.gridy = 10;
         c.anchor = GridBagConstraints.EAST;
         waitComboBox = new JComboBox(waitModes);
         add(waitComboBox, c);
-        
+
         c = new GridBagConstraints();
         c.gridx = 0;
         c.gridy = 11;
@@ -247,7 +247,7 @@
         JLabel waitTimeLabel = new JLabel("Wait Time [microseconds]:");
         waitTimeLabel.setHorizontalAlignment(JLabel.LEFT);
         add(waitTimeLabel, c);
-        
+
         c = new GridBagConstraints();
         c.gridx = 1;
         c.gridy = 11;
@@ -256,7 +256,7 @@
         waitTimeField.setBackground(Color.WHITE);
         waitTimeField.setHorizontalAlignment(JLabel.RIGHT);
         add(waitTimeField, c);
-        
+
         c = new GridBagConstraints();
         c.gridx = 0;
         c.gridy = 12;
@@ -264,7 +264,7 @@
         JLabel prescaleLabel = new JLabel("Prescale:");
         prescaleLabel.setHorizontalAlignment(JLabel.LEFT);
         add(prescaleLabel, c);
-        
+
         c = new GridBagConstraints();
         c.gridx = 1;
         c.gridy = 12;
@@ -273,7 +273,7 @@
         prescaleField.setBackground(Color.WHITE);
         prescaleField.setHorizontalAlignment(JLabel.RIGHT);
         add(prescaleField, c);
-        
+
         // Set default connection parameters which are pushed to GUI.
         setConnectionParameters(new ConnectionParameters());
     }
@@ -295,38 +295,38 @@
         connectionParameters.prescale = Integer.parseInt(prescaleField.getText());
         return connectionParameters;
     }
-    
+
     private Mode getWaitMode() {
-    	Mode mode = null;
-    	String sel = (String)waitComboBox.getSelectedItem();
-    	if (Mode.TIMED.toString().equalsIgnoreCase(sel)) {
-    		mode = Mode.TIMED;
-    	} else if (Mode.ASYNC.toString().equalsIgnoreCase(sel)) {
-    		mode = Mode.ASYNC;
-    	} else if (Mode.SLEEP.toString().equalsIgnoreCase(sel)) {
-    		mode = Mode.SLEEP;
-    	// Values are constrained by combo box so shouldn't happen but check anyways.
-    	} else {
-    		throw new RuntimeException("Invalid wait mode.");
-    	}
-    	return mode;
+        Mode mode = null;
+        String sel = (String)waitComboBox.getSelectedItem();
+        if (Mode.TIMED.toString().equalsIgnoreCase(sel)) {
+            mode = Mode.TIMED;
+        } else if (Mode.ASYNC.toString().equalsIgnoreCase(sel)) {
+            mode = Mode.ASYNC;
+        } else if (Mode.SLEEP.toString().equalsIgnoreCase(sel)) {
+            mode = Mode.SLEEP;
+            // Values are constrained by combo box so shouldn't happen but check anyways.
+        } else {
+            throw new RuntimeException("Invalid wait mode.");
+        }
+        return mode;
     }
-    
+
     private void setWaitMode(Mode waitMode) {    	
-    	if (waitMode == Mode.SLEEP) {
-        	waitComboBox.setSelectedIndex(0);
+        if (waitMode == Mode.SLEEP) {
+            waitComboBox.setSelectedIndex(0);
         } else if (waitMode == Mode.TIMED) {
-        	waitComboBox.setSelectedIndex(1);
+            waitComboBox.setSelectedIndex(1);
         } else if (waitMode == Mode.ASYNC) {
-        	waitComboBox.setSelectedIndex(2);
+            waitComboBox.setSelectedIndex(2);
         }
     }
-    
+
     private void setConnectionParameters(ConnectionParameters cn) {
-    	etNameField.setText(cn.etName);
-    	hostField.setText(cn.host);
-    	portField.setText(Integer.toString(cn.port));
-    	blockingField.setSelected(cn.blocking);
+        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));
@@ -336,31 +336,33 @@
         setWaitMode(cn.waitMode);
         waitTimeField.setText(Integer.toString(cn.waitTime));
         prescaleField.setText(Integer.toString(cn.prescale));
-    	this.connectionParameters = cn;
+        this.connectionParameters = cn;
     }
-    
+
+    /*
     void setConnectRequested(boolean b) {
-    	this.connectRequested = false;
+        this.connectRequested = false;
     }
-    
+
     void setDisconnectRequested(boolean b) {
-    	this.disconnectRequested = false;
+        this.disconnectRequested = false;
     }
-                
+
     private void setConnectRequested() {
-    	connectRequested = true;
-    	disconnectRequested = false;
-    	enableConnectionPanel(false);
-    }
-    
-	// FIXME Somehow this needs to interrupt if events are being fetched in Mode.SLEEP or we will never wake-up.
-    private void setDisconnectRequested() {
-    	disconnectRequested = true;
-    	connectRequested = false;
+        connectRequested = true;
+        disconnectRequested = false;
+        enableConnectionPanel(false);
     }
-    
+    */
+
+    // FIXME Somehow this needs to interrupt if events are being fetched in Mode.SLEEP or we will never wake-up.
+    //private void setDisconnectRequested() {
+    //    disconnectRequested = true;
+    //    connectRequested = false;
+    //}
+
     void enableConnectionPanel(boolean e) {
-    	etNameField.setEnabled(e);
+        etNameField.setEnabled(e);
         hostField.setEnabled(e);
         portField.setEnabled(e);
         blockingField.setEnabled(e);
@@ -374,111 +376,112 @@
         waitTimeField.setEnabled(e);
         prescaleField.setEnabled(e);
     }
-    
-    boolean connectRequested() {
-    	return this.connectRequested;
-    }
-    
-    boolean disconnectRequested() {
-    	return this.disconnectRequested;
-    }
-    
+
+    //boolean connectRequested() {
+    //    return this.connectRequested;
+    //}
+
+    //boolean disconnectRequested() {
+    //    return this.disconnectRequested;
+    //}
+
     // 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 (connectCmd.equals(e.getActionCommand())) {
-    		setConnectRequested();
-    	} else if (disconnectCmd.equals(e.getActionCommand())) {
-    		setDisconnectRequested();    		
-    	} else if (saveConnectionCmd.equals(e.getActionCommand())) {
-    		save();
-    	} else if (loadConnectionCmd.equals(e.getActionCommand())) {
-    		load();
-    	} else if (resetConnectionSettingsCmd.equals(e.getActionCommand())) {
-    		reset();
-    	}
+        //if (connectCmd.equals(e.getActionCommand())) {
+        //    setConnectRequested();
+        //} else if (disconnectCmd.equals(e.getActionCommand())) {
+        //    setDisconnectRequested();    		
+        //} else 
+        if (saveConnectionCmd.equals(e.getActionCommand())) {
+            save();
+        } else if (loadConnectionCmd.equals(e.getActionCommand())) {
+            load();
+        } else if (resetConnectionSettingsCmd.equals(e.getActionCommand())) {
+            reset();
+        }
     }
-    
+
     private void save() {
-    	JFileChooser fc = new JFileChooser();
+        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);
-    	}
+        JFileChooser fc = new JFileChooser();
+        int r = fc.showOpenDialog(ConnectionPanel.this);
+        if (r == JFileChooser.APPROVE_OPTION) {
+            File file = fc.getSelectedFile();
+            loadPropertiesFile(file);
+        }
     }
-        
+
     private void reset() {
-    	setConnectionParameters(new ConnectionParameters());
+        setConnectionParameters(new ConnectionParameters());
     }
-                
+
     private void writePropertiesFile(File file) {
-    	Properties prop = new Properties();
-    	prop.setProperty("etName", etNameField.getText());
-    	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());
-    	prop.setProperty("waitMode", (String)waitComboBox.getSelectedItem());
-    	prop.setProperty("waitTime", waitTimeField.getText());
-    	prop.setProperty("prescale", prescaleField.getText());
-    	try {
-    		prop.store(new FileOutputStream(file), null);
-    	} catch (Exception e) {
-    		showErrorDialog(e.getLocalizedMessage());
-    	}
+        Properties prop = new Properties();
+        prop.setProperty("etName", etNameField.getText());
+        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());
+        prop.setProperty("waitMode", (String)waitComboBox.getSelectedItem());
+        prop.setProperty("waitTime", waitTimeField.getText());
+        prop.setProperty("prescale", prescaleField.getText());
+        try {
+            prop.store(new FileOutputStream(file), null);
+        } catch (Exception e) {
+            showErrorDialog(e.getLocalizedMessage());
+        }
     }
-    
+
     private void showErrorDialog(String mesg) {
-    	JOptionPane.showMessageDialog(this, mesg);
+        JOptionPane.showMessageDialog(this, mesg);
     }
-    
+
     private void setWaitMode(String waitMode) {
-    	if (Mode.SLEEP.toString().equals(waitMode.toLowerCase())) {
-			waitComboBox.setSelectedIndex(0);
-		} else if (Mode.TIMED.toString().equals(waitMode.toLowerCase())) {
-			waitComboBox.setSelectedIndex(1);
-		} else if (Mode.ASYNC.toString().equals(waitMode.toLowerCase())) {
-			waitComboBox.setSelectedIndex(2);
-		}
+        if (Mode.SLEEP.toString().equals(waitMode.toLowerCase())) {
+            waitComboBox.setSelectedIndex(0);
+        } else if (Mode.TIMED.toString().equals(waitMode.toLowerCase())) {
+            waitComboBox.setSelectedIndex(1);
+        } else if (Mode.ASYNC.toString().equals(waitMode.toLowerCase())) {
+            waitComboBox.setSelectedIndex(2);
+        }
     }
-    
+
     private void loadPropertiesFile(File file) {
-    	Properties prop = new Properties();
-    	try {
-    		prop.load(new FileInputStream(file));
-    		etNameField.setText(prop.getProperty("etName"));
-    		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"));
-    		setWaitMode(prop.getProperty("waitMode"));    		
-    		waitTimeField.setText(prop.getProperty("waitTime"));
-    		prescaleField.setText(prop.getProperty("prescale"));
-    	} catch (FileNotFoundException e) {
-    		showErrorDialog(e.getLocalizedMessage());
-    	} catch (IOException e) {
-    		showErrorDialog(e.getLocalizedMessage());
-    	}    
-    	this.connectionParameters = getConnectionParameters();
+        Properties prop = new Properties();
+        try {
+            prop.load(new FileInputStream(file));
+            etNameField.setText(prop.getProperty("etName"));
+            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"));
+            setWaitMode(prop.getProperty("waitMode"));    		
+            waitTimeField.setText(prop.getProperty("waitTime"));
+            prescaleField.setText(prop.getProperty("prescale"));
+        } catch (FileNotFoundException e) {
+            showErrorDialog(e.getLocalizedMessage());
+        } catch (IOException e) {
+            showErrorDialog(e.getLocalizedMessage());
+        }    
+        this.connectionParameters = getConnectionParameters();
     }                           
 }
\ No newline at end of file

hps-java/src/main/java/org/lcsim/hps/monitoring
ConnectionParameters.java 1.8 -> 1.9
diff -u -r1.8 -r1.9
--- ConnectionParameters.java	3 Apr 2012 18:37:04 -0000	1.8
+++ ConnectionParameters.java	8 Apr 2012 23:48:11 -0000	1.9
@@ -1,6 +1,5 @@
 package org.lcsim.hps.monitoring;
 
-import java.io.File;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 
@@ -23,8 +22,8 @@
     int position = 1;
     int pposition = 0;
     int flowMode = EtConstants.stationSerial;
-    Mode waitMode = Mode.SLEEP; 
-    int waitTime = 20000000; // microseconds
+    Mode waitMode = Mode.TIMED; 
+    int waitTime = 5000000; // wait time in microseconds
     int prescale = 1;
                    
     public ConnectionParameters() {
@@ -53,14 +52,17 @@
                 "       -pos   position of created station in station list (1,2,...)\n" +
                 "       -ppos  position of created station within a group of parallel stations (-1=end, -2=head)\n" +
                 "       -a     run in async mode which looks for immediate connection to ET system\n" +
+                "       -x     run in sleep mode\n" +
                 "       -t     time to wait for events before timing out\n\n" +
                 "       -e     set event prescaling where argument is every N events to read\n" +
                 "        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.
@@ -68,6 +70,7 @@
      * @param args
      * @return
      */
+    /*
     public void setup(String[] args) {
         for (int i = 0; i < args.length; i++) {
             if (args[i].equalsIgnoreCase("-f")) {
@@ -159,6 +162,7 @@
             throw new ConnectionParametersException("Missing required arguments.");
         }
     }
+    */
     
     public class ConnectionParametersException extends RuntimeException {
         ConnectionParametersException(String msg) {

hps-java/src/main/java/org/lcsim/hps/monitoring
ConnectionStatusPanel.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- ConnectionStatusPanel.java	27 Mar 2012 20:31:49 -0000	1.1
+++ ConnectionStatusPanel.java	8 Apr 2012 23:48:11 -0000	1.2
@@ -1,5 +1,6 @@
 package org.lcsim.hps.monitoring;
 
+import java.awt.Color;
 import java.awt.GridBagConstraints;
 import java.awt.GridBagLayout;
 
@@ -7,21 +8,12 @@
 import javax.swing.JPanel;
 import javax.swing.JTextField;
 
+import org.lcsim.hps.monitoring.ConnectionStatus;
+
 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());
 		
@@ -37,17 +29,19 @@
         c.gridx = 1;
         c.gridy = 0;
         c.anchor = GridBagConstraints.EAST;
-        statusField = new JTextField("", 12);
+        statusField = new JTextField("", 20);
         statusField.setHorizontalAlignment(JTextField.RIGHT);
+        statusField.setEditable(false);
+        statusField.setBackground(Color.WHITE);
         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 + ".");
+		if (idx < 0 || idx > (ConnectionStatus.NUMBER_STATUSES - 1)) {
+			throw new IllegalArgumentException("Invalid index value.  Must be between 0 and " + (ConnectionStatus.NUMBER_STATUSES - 1) + ".");
 		}
-		statusField.setText(statuses[idx].toUpperCase());
+		statusField.setText(ConnectionStatus.toString(idx));
 	}
 }
\ No newline at end of file

hps-java/src/main/java/org/lcsim/hps/monitoring
EcalMonitoringPlots.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- EcalMonitoringPlots.java	5 Apr 2012 23:58:19 -0000	1.2
+++ EcalMonitoringPlots.java	8 Apr 2012 23:48:11 -0000	1.3
@@ -27,6 +27,8 @@
 	
 	Detector detector;
 	
+	int eventn = 0;
+	
 	public EcalMonitoringPlots() 
 	{}
 	
@@ -69,15 +71,18 @@
 	}	
 	
 	public void process(EventHeader event) {
-		List<RawCalorimeterHit> hits = event.get(RawCalorimeterHit.class, rawCalorimeterHitCollectionName);				 
-		for (RawCalorimeterHit hit : hits) {
-			dec.setID(hit.getCellID());
-			hitCountPlot.fill(dec.getValue("ix"), dec.getValue("iy"));
-		}
+	    List<RawCalorimeterHit> hits = event.get(RawCalorimeterHit.class, rawCalorimeterHitCollectionName);
+	    for (RawCalorimeterHit hit : hits) {
+	        dec.setID(hit.getCellID());
+	        hitCountPlot.fill(dec.getValue("ix"), dec.getValue("iy"));
+	    }
+	    ++eventn;
 	}	
 	
     public void endOfData() {
     	plotter.hide();
+    	plotter.destroyRegions();
+    	hitCountPlot.reset();
     }
 
     public void reset() {
@@ -85,4 +90,4 @@
     	hitCountPlot.reset();
     	detectorChanged(detector);
     }
-}
+}
\ No newline at end of file

hps-java/src/main/java/org/lcsim/hps/monitoring
EtConnection.java 1.5 -> 1.6
diff -u -r1.5 -r1.6
--- EtConnection.java	4 Apr 2012 23:26:07 -0000	1.5
+++ EtConnection.java	8 Apr 2012 23:48:11 -0000	1.6
@@ -13,17 +13,19 @@
  */
 class EtConnection {
 	
+    ConnectionParameters param;
 	EtSystem sys;
 	EtAttachment att;
 	EtStation stat;
-	MonitoringExitCallback shutdownCallback;
 	
-	EtConnection(EtSystem sys, EtAttachment att, EtStation stat) {
+	//boolean usable;
+	
+	private EtConnection(ConnectionParameters param, EtSystem sys, EtAttachment att, EtStation stat) {
+	    this.param = param;
 		this.sys = sys;
 		this.att = att;
 		this.stat = stat;
-		this.shutdownCallback = new MonitoringExitCallback(this);
-		Runtime.getRuntime().addShutdownHook(shutdownCallback);
+		//this.usable = true; // Assume objects come from static createEtConnection() call so should be valid.
 	}
 	
 	EtSystem getEtSystem() {
@@ -38,53 +40,68 @@
 		return stat;
 	}
 	
-	MonitoringExitCallback getShutdownCallback() {
-		return shutdownCallback;
+	ConnectionParameters getConnectionParameters() {
+	    return param;
 	}
 		
 	void cleanup() {
-		if (sys.alive()) {
-			try {
-				sys.detach(att);
-				sys.removeStation(stat);
-				sys.close();
-			} catch (Exception e) {
-				e.printStackTrace();
-			}
-		}
-	}
-	
-	static EtConnection createEtConnection(ConnectionParameters cn) throws Exception {
-		
-		// make a direct connection to ET system's tcp server
-	    EtSystemOpenConfig config = new EtSystemOpenConfig(cn.etName, cn.host, cn.port);
+	    //System.out.println("cleanup");
+	    try {
+	        //System.out.println("alive");
+	        //System.out.println("wakeUpAll");
+	        sys.wakeUpAll(stat);
+	        //System.out.println("detach");
+	        sys.detach(att);
+	        //System.out.println("stat");
+	        sys.removeStation(stat);
+	        //System.out.println("close");
+	        sys.close();
+	    } catch (Exception e) {
+	        e.printStackTrace();
+	    } 
+	    //finally {
+	    //    usable = false;
+	    //}
+	    System.out.println("done w/ cleanup");
+	}
+	
+	static EtConnection createEtConnection(ConnectionParameters cn) {
+	    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();
+	        // 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);
+	        // 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);
+	            }
 	        }
-	    }
-	    // Set prescale.
-	    if (cn.prescale > 0) {
-	    	System.out.println("setting prescale to " + cn.prescale);
-	    	statConfig.setPrescale(cn.prescale);
-	    }
+	        // Set prescale.
+	        if (cn.prescale > 0) {
+	            System.out.println("setting prescale to " + cn.prescale);
+	            statConfig.setPrescale(cn.prescale);
+	        }
+
+	        // Create the station.
+	        EtStation stat = sys.createStation(statConfig, cn.statName, cn.position, cn.pposition);
 
-	    // Create the station.
-	    EtStation stat = sys.createStation(statConfig, cn.statName, cn.position, cn.pposition);
-	     
-	    // attach to new station
-	    EtAttachment att = sys.attach(stat);
-	    
-	    // Return new connection.
-	    return new EtConnection(sys, att, stat);
+	        // attach to new station
+	        EtAttachment att = sys.attach(stat);
+
+	        // Return new connection.
+	        return new EtConnection(cn, sys, att, stat);
+	        
+	    } catch (Exception e) {
+	        e.printStackTrace();
+	        return null;
+	    }
 	}       
 }
\ No newline at end of file

hps-java/src/main/java/org/lcsim/hps/monitoring
EventPanel.java 1.4 -> 1.5
diff -u -r1.4 -r1.5
--- EventPanel.java	4 Apr 2012 23:26:07 -0000	1.4
+++ EventPanel.java	8 Apr 2012 23:48:12 -0000	1.5
@@ -11,23 +11,30 @@
 import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 import javax.swing.JTextField;
+import javax.swing.SwingUtilities;
 
 class EventPanel extends JPanel implements ActionListener {
 
-    private JTextField eventCounterField;
-    private JTextField elapsedTimeField;
-    private JTextField avgEventRateField;
-    private JTextField refreshField;
-    private JTextField badEventsField;
+    private JTextField eventCounterField; // number of events in this job, can be reset via menu
+    private JTextField elapsedTimeField; // elapsed time between job start or reset command
+    private JTextField avgEventRateField; // average event rate in this job or between resets
+    private JTextField refreshField; // number of events to wait before updating GUI
+    private JTextField badEventsField; // number of bad events where event event processing failed
+    private JTextField sessionSuppliedField; // number of events supplied in this session, ignored by reset command
+    private JTextField totalSuppliedField; // number of events supplied since app started (this is never reset by any user command)
     
     private DecimalFormat rateFormat = new DecimalFormat("#.##");
    
-    private static final int defaultEventRefresh = 1000;
+    private static final int defaultEventRefresh = 100;
     private int eventRefresh = defaultEventRefresh;
     
     private long jobStartTime;
     private int eventCount;
     private int badEventCount;
+    private int sessionSupplied;
+    private int totalSupplied;
+    
+    boolean updateEvent = true;
     
     EventPanel() {
 
@@ -72,7 +79,7 @@
         c.gridx = 0;
         c.gridy = 1;
         c.anchor = GridBagConstraints.WEST;
-        JLabel timeLabel = new JLabel("Elapsed Time [ms]:");
+        JLabel timeLabel = new JLabel("Elapsed Time [seconds]:");
         timeLabel.setHorizontalAlignment(JLabel.LEFT);
         fieldsPanel.add(timeLabel, c);
 
@@ -140,53 +147,103 @@
         badEventsField.setEditable(false);
         badEventsField.setBackground(Color.WHITE);
         fieldsPanel.add(badEventsField, c);
+        
+        c = new GridBagConstraints();
+        c.gridx = 0;
+        c.gridy = 5;
+        c.anchor = GridBagConstraints.WEST;
+        JLabel sessionSuppliedLabel = new JLabel("Session Supplied Events:");
+        sessionSuppliedLabel.setHorizontalAlignment(JLabel.LEFT);
+        fieldsPanel.add(sessionSuppliedLabel, c);
+        
+        c = new GridBagConstraints();
+        c.gridx = 1;
+        c.gridy = 5;
+        c.anchor = GridBagConstraints.EAST;
+        sessionSuppliedField = new JTextField("0", 8);
+        sessionSuppliedField.setHorizontalAlignment(JTextField.RIGHT);
+        sessionSuppliedField.setEditable(false);
+        sessionSuppliedField.setBackground(Color.WHITE);
+        fieldsPanel.add(sessionSuppliedField, c);
+        
+        c = new GridBagConstraints();
+        c.gridx = 0;
+        c.gridy = 6;
+        c.anchor = GridBagConstraints.WEST;
+        JLabel totalSuppliedLabel = new JLabel("Total Supplied Events:");
+        totalSuppliedLabel.setHorizontalAlignment(JLabel.LEFT);
+        fieldsPanel.add(totalSuppliedLabel, c);
+        
+        c = new GridBagConstraints();
+        c.gridx = 1;
+        c.gridy = 6;
+        c.anchor = GridBagConstraints.EAST;
+        totalSuppliedField = new JTextField("0", 8);
+        totalSuppliedField.setHorizontalAlignment(JTextField.RIGHT);
+        totalSuppliedField.setEditable(false);
+        totalSuppliedField.setBackground(Color.WHITE);
+        fieldsPanel.add(totalSuppliedField, c);
     }
-           
-    public int getEventCount() {
-        return eventCount;
+            
+    private int getEventRefresh() {
+    	return eventRefresh;
     }
     
-    public int getEventRefresh() {
-    	return eventRefresh;
+    public void checkUpdateEvent() {
+        updateEvent = ((eventCount % getEventRefresh()) == 0);
     }
     
-    public void updateEventCount() {
+    void updateEventCount() {
         ++eventCount;
-        if (updateEvent()) {
-            eventCounterField.setText(Integer.toString(eventCount));
+        ++sessionSupplied;
+        ++totalSupplied;
+        checkUpdateEvent();
+        if (updateEvent) {
+            Runnable r = new Runnable() {
+                public void run() {
+                    eventCounterField.setText(Integer.toString(eventCount));
+                    sessionSuppliedField.setText(Integer.toString(sessionSupplied));
+                    totalSuppliedField.setText(Integer.toString(totalSupplied));
+                }
+            };
+            SwingUtilities.invokeLater(r);
         }
     }
     
-    public void updateBadEventCount() {
+    void updateBadEventCount() {
     	++badEventCount;
-    	badEventsField.setText(Integer.toString(badEventCount));
-    }
-    
-    public void updateJobStartTime() {
-        this.jobStartTime = System.currentTimeMillis();
+    	SwingUtilities.invokeLater(new Runnable() {
+    	    public void run() {
+    	        badEventsField.setText(Integer.toString(badEventCount));
+    	    }
+    	});
     }
     
-    public boolean updateEvent() {
-        return (eventCount % getEventRefresh()) == 0; 
-    }
-    
-    public void updateAverageEventRate() {
-        if (updateEvent()) {
+    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));
+                final double eventsPerSecond = eventCount / jobSeconds;
+                SwingUtilities.invokeLater(new Runnable() {
+                    public void run() {
+                        avgEventRateField.setText(rateFormat.format(eventsPerSecond));
+                    }
+                });
             }
         }
     }
         
-    public void updateElapsedTime() {    
-        if (updateEvent()) {
-            this.elapsedTimeField.setText(Long.toString(System.currentTimeMillis() - jobStartTime));
+    void updateElapsedTime() {    
+        if (updateEvent) {
+            SwingUtilities.invokeLater(new Runnable() {
+                public void run() {
+                    elapsedTimeField.setText(Long.toString((System.currentTimeMillis() - jobStartTime)/1000));                    
+                }
+            });            
         }
     }
- 
+    
     public void actionPerformed(ActionEvent e) {
         String cmd = e.getActionCommand();
         if (MonitoringCommands.resetEventsCmd.equals(cmd)) {
@@ -217,8 +274,7 @@
         resetElapsedTime();
         resetJobStartTime();
     }
-	
-    
+	    
 	private void resetEventCount() {
 		eventCount = 0;
 		eventCounterField.setText("0");
@@ -240,4 +296,9 @@
 		this.badEventCount = 0;
 		this.badEventsField.setText("0");
 	}
+	
+	void resetSessionSupplied() {
+	    this.sessionSupplied = 0;
+	    this.sessionSuppliedField.setText("0");
+	}
 }
\ No newline at end of file

hps-java/src/main/java/org/lcsim/hps/monitoring
MonitoringApplication.java 1.8 -> 1.9
diff -u -r1.8 -r1.9
--- MonitoringApplication.java	6 Apr 2012 00:11:05 -0000	1.8
+++ MonitoringApplication.java	8 Apr 2012 23:48:12 -0000	1.9
@@ -27,7 +27,9 @@
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.PrintStream;
+import java.nio.ByteBuffer;
 
 import javax.imageio.ImageIO;
 import javax.swing.JFileChooser;
@@ -38,20 +40,42 @@
 import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 import javax.swing.JTabbedPane;
+import javax.swing.SwingUtilities;
 
-import org.lcsim.hps.monitoring.ConnectionStatusPanel.ConnectionStatus;
+import org.jlab.coda.et.EtAttachment;
+import org.jlab.coda.et.EtEvent;
+import org.jlab.coda.et.EtSystem;
+import org.jlab.coda.et.enums.Mode;
+import org.jlab.coda.et.enums.Modify;
+import org.jlab.coda.et.exception.EtTimeoutException;
+import org.jlab.coda.jevio.EvioEvent;
+import org.jlab.coda.jevio.EvioException;
+import org.jlab.coda.jevio.EvioReader;
+import org.lcsim.event.EventHeader;
+import org.lcsim.hps.evio.LCSimEventBuilder;
+import org.lcsim.hps.evio.MCEventBuilder;
 import org.lcsim.job.JobControlManager;
 import org.lcsim.util.Driver;
-import org.lcsim.util.DriverAdapter;
 import org.lcsim.util.aida.AIDA;
 
-public class MonitoringApplication extends JPanel implements ActionListener {
-	
-	private JTabbedPane tabs;	
+// TODO: Make screenshot format selectable in combo box (png, jpeg, etc.).
+// TODO: Have subclass that implements ActionListener instead of this one.
+// TODO: Add some spacing/padding in tab fields.
+// TODO: Event refresh should be set via "Event -> Event Refresh..." which can check for validity and then push to GUI.
+//       Disallow direct edits to Event Monitor GUI component.
+// TODO: Move the parts of this class having to do with EtEvent/EvioEvent/LCSimEvent to separate classes.
+// TODO: Move the Swing parts of this class to MonitoringApplicationGui.
+// TODO: Need Timer thread to update elapsed time fields independent of event processing.
+// http://docs.oracle.com/javase/1.4.2/docs/api/java/util/Timer.html
+// TODO: help menu
+public class MonitoringApplication {
+    
+    private JPanel mainPanel;
+    private JTabbedPane tabs;	
 	private ConnectionPanel connectionPanel;
 	private ConnectionStatusPanel connectionStatusPanel;
 	private EventPanel eventPanel;
-	private JobPanel jobPanel;	
+	private JobPanel jobPanel;		
 	
 	private JMenuBar menuBar;	
 	private JMenuItem connectItem;
@@ -66,33 +90,96 @@
 	private JMenuItem logItem;
 	private JMenuItem terminalItem;
 	private JMenuItem screenshotItem;
-		
-	private JobControlManager mgr = null;
-	
-	// Saved references to original System PrintStreams.
-	private PrintStream sysOut;
-	private PrintStream sysErr;
-		
-	private static final String screenshotFormat = "png";
-	
+			
+	private PrintStream sysOut = System.out;
+	private PrintStream sysErr = System.err;
+			
+	private ConnectionParameters connectionParameters;
 	private EtConnection connection;
+    private EtSystem sys;
+    private EtAttachment att;
+    private Mode waitMode;
+    private int waitTime;
+    private int chunk;    
+	private int connectionStatus = ConnectionStatus.DISCONNECTED;
 	
-	private DriverAdapter driverAdapter;
+	private JobControlManager jobManager;
+	private LCSimEventBuilder eventBuilder;
 	
-	static final class JobParameters {
-		String detectorName;
-    	String steeringResource;
-    	String eventBuilderClassName;
+	private MonitoringApplicationActionListener actionListener;
+
+	public static final class JobParameters {
+		private String detectorName;
+		private String steeringResource;
+		private String eventBuilderClassName;
+    	JobParameters() {}
+    	JobParameters(String[] params) {
+    	    if (params.length != 3) {
+    	        new IllegalArgumentException("Parameter array is wrong length.");
+    	    }
+    	    this.detectorName = params[0];
+    	    this.steeringResource = params[1];
+    	    this.eventBuilderClassName = params[2];
+    	}
+	}
+	
+	private static final class MonitoringApplicationActionListener implements ActionListener
+	{
+	    MonitoringApplication app;
+	    MonitoringApplicationActionListener(MonitoringApplication app) {
+	        this.app = app;
+	    }
+	    
+	    public void actionPerformed(ActionEvent e) {
+	        String cmd = e.getActionCommand();
+	        if (connectCmd.equals(cmd)) {
+	            app.requestConnection();
+	        } 
+	        else if (disconnectCmd.equals(cmd)) {
+	            app.disconnect(ConnectionStatus.DISCONNECTING);
+	        } 
+	        else if (saveConnectionCmd.equals(cmd)) {
+	            app.connectionPanel.actionPerformed(e);
+	        } 
+	        else if (loadConnectionCmd.equals(cmd)) {
+	            app.connectionPanel.actionPerformed(e);
+	        } 
+	        else if (resetConnectionSettingsCmd.equals(cmd)) {
+	            app.connectionPanel.actionPerformed(e);        
+	        } 
+	        else if (resetEventsCmd.equals(cmd)) {
+	            app.eventPanel.actionPerformed(e);        
+	        } 
+	        else if (savePlotsCmd.equals(cmd)) {
+	            app.savePlots();
+	        } 
+	        else if (resetDriversCmd.equals(cmd)) {
+	            app.resetDrivers();
+	        } 
+	        else if (logCmd.equals(cmd)) {
+	            app.logToFile();
+	        } 
+	        else if (terminalCmd.equals(cmd)) {
+	            app.logToTerminal();
+	        }
+	        else if (screenshotCmd.equals(cmd)) {
+	            app.screenshot();
+	        }
+	        else if (exitCmd.equals(cmd)) {
+	            app.exit();
+	        }
+	    } 
 	}
-			
+	
 	public MonitoringApplication() {
-				
-		super(new GridBagLayout());
 		
-		// Save system's out and err.
-		sysOut = System.out;
-		sysErr = System.err;
-								
+	    // Create ActionEvent listener.
+	    actionListener = new MonitoringApplicationActionListener(this);
+	    
+	    // Main panel for the application.
+		mainPanel = new JPanel();
+		mainPanel.setLayout(new GridBagLayout());
+		
 		// Setup the menus.
 		createMenu();
 		
@@ -105,30 +192,27 @@
 		c.gridy = 0;
 		c.anchor = GridBagConstraints.NORTHWEST;
 		connectionStatusPanel = new ConnectionStatusPanel();
-		add(connectionStatusPanel, c);
+		mainPanel.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.
+		JPanel tabsPanel = new JPanel();
+	    tabs = new JTabbedPane();
 		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);
+		mainPanel.add(tabsPanel, c);
 	}
 		
 	private void createMenu() {
@@ -141,38 +225,38 @@
 		connectItem = new JMenuItem("Connect");
 		connectItem.setMnemonic(KeyEvent.VK_C);
 		connectItem.setActionCommand(connectCmd);
-		connectItem.addActionListener(this);
+		connectItem.addActionListener(actionListener);
 		connectionMenu.add(connectItem);
 		
 		disconnectItem = new JMenuItem("Disconnect");
 		disconnectItem.setMnemonic(KeyEvent.VK_D);
 		disconnectItem.setActionCommand(disconnectCmd);
-		disconnectItem.addActionListener(this);
+		disconnectItem.addActionListener(actionListener);
 		disconnectItem.setEnabled(false);
 		connectionMenu.add(disconnectItem);
 		
 		resetConnectionItem = new JMenuItem("Reset Connection Settings");
 		resetConnectionItem.setMnemonic(KeyEvent.VK_R);
 		resetConnectionItem.setActionCommand(resetConnectionSettingsCmd);
-		resetConnectionItem.addActionListener(this);
+		resetConnectionItem.addActionListener(actionListener);
 		connectionMenu.add(resetConnectionItem);
 				
 		connectionLoadItem = new JMenuItem("Load Connection...");
 		connectionLoadItem.setMnemonic(KeyEvent.VK_L);
 		connectionLoadItem.setActionCommand(loadConnectionCmd);
-		connectionLoadItem.addActionListener(this);
+		connectionLoadItem.addActionListener(actionListener);
 		connectionMenu.add(connectionLoadItem);
 		
 		connectionSaveItem = new JMenuItem("Save Connection...");
 		connectionSaveItem.setMnemonic(KeyEvent.VK_S);
 		connectionSaveItem.setActionCommand(saveConnectionCmd);
-		connectionSaveItem.addActionListener(this);
+		connectionSaveItem.addActionListener(actionListener);
 		connectionMenu.add(connectionSaveItem);
 		
 		exitItem = new JMenuItem("Exit");
 		exitItem.setMnemonic(KeyEvent.VK_X);
 		exitItem.setActionCommand(exitCmd);
-		exitItem.addActionListener(this);
+		exitItem.addActionListener(actionListener);
 		connectionMenu.add(exitItem);
 		
 		JMenu eventMenu = new JMenu("Event");
@@ -181,7 +265,7 @@
 		resetEventsItem = new JMenuItem("Reset Event Monitor");
 		resetEventsItem.setMnemonic(KeyEvent.VK_E);
 		resetEventsItem.setActionCommand(resetEventsCmd);
-		resetEventsItem.addActionListener(this);
+		resetEventsItem.addActionListener(actionListener);
 		eventMenu.add(resetEventsItem);		
 		
 		JMenu jobMenu = new JMenu("Job");
@@ -190,104 +274,125 @@
 		savePlotsItem = new JMenuItem("Save Plots to AIDA File...");
 		savePlotsItem.setMnemonic(KeyEvent.VK_P);
 		savePlotsItem.setActionCommand(savePlotsCmd);
-		savePlotsItem.addActionListener(this);
+		savePlotsItem.addActionListener(actionListener);
 		savePlotsItem.setEnabled(false);
 		jobMenu.add(savePlotsItem);		
 		
 		resetDriversItem = new JMenuItem("Reset LCSim Drivers");
 		resetDriversItem.setMnemonic(KeyEvent.VK_D);
 		resetDriversItem.setActionCommand(resetDriversCmd);
-		resetDriversItem.addActionListener(this);
+		resetDriversItem.addActionListener(actionListener);
 		resetDriversItem.setEnabled(false);
 		jobMenu.add(resetDriversItem);
 		
 		logItem = new JMenuItem("Log to File...");
 		logItem.setMnemonic(KeyEvent.VK_F);
 		logItem.setActionCommand(logCmd);
-		logItem.addActionListener(this);
+		logItem.addActionListener(actionListener);
 		logItem.setEnabled(true);
 		jobMenu.add(logItem);
 		
 		terminalItem = new JMenuItem("Log to Terminal");
 		terminalItem.setMnemonic(KeyEvent.VK_T);
 		terminalItem.setActionCommand(terminalCmd);
-		terminalItem.addActionListener(this);
+		terminalItem.addActionListener(actionListener);
 		terminalItem.setEnabled(false);
 		jobMenu.add(terminalItem);
 		
 		screenshotItem = new JMenuItem("Take a screenshot...");
 		screenshotItem.setMnemonic(KeyEvent.VK_N);
 		screenshotItem.setActionCommand(screenshotCmd);
-		screenshotItem.addActionListener(this);
+		screenshotItem.addActionListener(actionListener);
 		jobMenu.add(screenshotItem);
 	}
 	
-	void setJobParameters(JobParameters p) {		
+	private void setJobParameters(JobParameters p) {		
     	jobPanel.setDetectorName(p.detectorName);
     	jobPanel.setSteeringResource(p.steeringResource);
     	jobPanel.setDefaultEventBuilder(p.eventBuilderClassName);
 	}
 	
+	private void requestConnection() {
+        setConnectionStatus(ConnectionStatus.CONNECTION_REQUESTED);
+	}
+	
+	private void setConnectionStatus(int status) {
+	    connectionStatus = status;
+	    connectionStatusPanel.setStatus(status);
+	}
+
+	int getConnectionStatus() {
+	    return connectionStatus;
+	}
+	    
+	private boolean connectionRequested() {
+	    return connectionStatus == ConnectionStatus.CONNECTION_REQUESTED;
+	}            
+	/*
 	public void actionPerformed(ActionEvent e) {
-        String cmd = e.getActionCommand();    
+        String cmd = e.getActionCommand();
         if (connectCmd.equals(cmd)) {
-            connectionPanel.actionPerformed(e);
-        } else if (disconnectCmd.equals(cmd)) {
-            connectionPanel.actionPerformed(e);
-        } else if (saveConnectionCmd.equals(cmd)) {
+            requestConnection();
+        } 
+        else if (disconnectCmd.equals(cmd)) {
+            disconnect(ConnectionStatus.DISCONNECTING);
+        } 
+        else if (saveConnectionCmd.equals(cmd)) {
+        	connectionPanel.actionPerformed(e);
+        } 
+        else if (loadConnectionCmd.equals(cmd)) {
         	connectionPanel.actionPerformed(e);
-        } else if (loadConnectionCmd.equals(cmd)) {
-        	connectionPanel.actionPerformed(e);        	
-        } else if (resetConnectionSettingsCmd.equals(cmd)) {
+        } 
+        else if (resetConnectionSettingsCmd.equals(cmd)) {
         	connectionPanel.actionPerformed(e);        
-        } else if (resetEventsCmd.equals(cmd)) {
+        } 
+        else if (resetEventsCmd.equals(cmd)) {
         	eventPanel.actionPerformed(e);        
-        } else if (savePlotsCmd.equals(cmd)) {
+        } 
+        else if (savePlotsCmd.equals(cmd)) {
         	savePlots();
-        } else if (resetDriversCmd.equals(cmd)) {
+        } 
+        else if (resetDriversCmd.equals(cmd)) {
         	resetDrivers();
-        } else if (logCmd.equals(cmd)) {
+        } 
+        else if (logCmd.equals(cmd)) {
         	logToFile();
-        } else if (terminalCmd.equals(cmd)) {
+        } 
+        else if (terminalCmd.equals(cmd)) {
         	logToTerminal();
-        } else if (screenshotCmd.equals(cmd)) {
+        }
+        else if (screenshotCmd.equals(cmd)) {
         	screenshot();
         }
         else if (exitCmd.equals(cmd)) {
         	exit();
         }
     }
+    */
 	
-	void setJobControlManager(JobControlManager mgr) {
-		this.mgr = mgr;
-	}
-	
-	void showDialog(String m) {
-		JOptionPane.showMessageDialog(this, m);
-	}
-	
-	void setDriverAdapter(DriverAdapter adapter) {
-		this.driverAdapter = adapter;
+	private void showDialog(String m) {
+		JOptionPane.showMessageDialog(mainPanel, m);
 	}
 	
 	/**
 	 * Sets up the frame to run the application.  
 	 * This should be called using Runnable.run() (see MonitoringExample).
 	 */
-	void start() {
+	private void createApplicationFrame() {
+	    mainPanel.setOpaque(true);
         JFrame frame = new JFrame("HPS Monitoring");
-        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-        this.setOpaque(true);
-        frame.setContentPane(this);
+        frame.setContentPane(mainPanel);
         frame.setJMenuBar(menuBar);
+        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+        //frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); 
         frame.setResizable(false);                       
         frame.pack();
         frame.setVisible(true);
     }
 						
-	private synchronized void savePlots() {
+	private void savePlots() {
         JFileChooser fc = new JFileChooser();
-        int r = fc.showSaveDialog(this);
+        int r = fc.showSaveDialog(mainPanel);
         if (r == JFileChooser.APPROVE_OPTION) {
             File fileName = fc.getSelectedFile();
             try {
@@ -297,10 +402,11 @@
             }
         }
     }
-	
+
 	private synchronized void resetDrivers() {
-		if (mgr != null) {
-			for (Driver driver : mgr.getDriverExecList()) {
+	    // FIXME: Put this in JobManager???
+		if (jobManager != null) {
+			for (Driver driver : jobManager.getDriverExecList()) {
 				if (driver instanceof Resettable) {
 					try {
 						((Resettable) driver).reset();
@@ -315,39 +421,41 @@
 	private void logToFile() {
 		JFileChooser fc = new JFileChooser();
 		fc.setDialogTitle("Log File");
-		int r = fc.showSaveDialog(this);
-		if (r == JFileChooser.APPROVE_OPTION) {
-			File logFile = fc.getSelectedFile();
+		int fcs = fc.showSaveDialog(this.mainPanel);
+		if (fcs == JFileChooser.APPROVE_OPTION) {
+			final File logFile = fc.getSelectedFile();
 			if (logFile.exists()) {
-				JOptionPane.showMessageDialog(this, "Log file already exists.");
+				JOptionPane.showMessageDialog(this.mainPanel, "Log file already exists.");
 			} else {			
 				try {
 					if (!logFile.createNewFile()) throw new IOException();
-					jobPanel.logFileField.setText(logFile.getPath());
-					jobPanel.logCheckBox.setSelected(true);
 					PrintStream ps = new PrintStream(new FileOutputStream(logFile.getPath()));
 					System.setOut(ps);
-					System.setErr(ps);
-					terminalItem.setEnabled(true);
-					logItem.setEnabled(false);
+					System.setErr(ps);				
+					
+					jobPanel.logFileField.setText(logFile.getPath());
+                    jobPanel.logCheckBox.setSelected(true);
+                    terminalItem.setEnabled(true);
+                    logItem.setEnabled(false);
+                    
 				} catch (IOException e) {
-					JOptionPane.showMessageDialog(this, "Error creating log file.");
+					JOptionPane.showMessageDialog(this.mainPanel, "Error creating log file.");
 				}
 			}
 		}
 	}
 	
-	private synchronized void logToTerminal() {
+	private void logToTerminal() {
 		System.setOut(sysOut);
-		System.setErr(sysErr);
-		jobPanel.logFileField.setText("");
-		jobPanel.logCheckBox.setSelected(false);
-		terminalItem.setEnabled(false);
-		logItem.setEnabled(true);
+		System.setErr(sysErr);		
+        jobPanel.logFileField.setText("");
+        jobPanel.logCheckBox.setSelected(false);
+        terminalItem.setEnabled(false);
+        logItem.setEnabled(true);
 	}
 				
-	synchronized private void setDisconnected() {		
-		
+	private void setDisconnectedGuiState() {		
+		 
 		// Enable or disable appropriate menu items.
 		connectItem.setEnabled(true);
 		disconnectItem.setEnabled(false);
@@ -360,26 +468,19 @@
 		
 		// Re-enable the ConnectionPanel.
 		connectionPanel.enableConnectionPanel(true);
-		
-		// Need to reset this or won't get into GUI hook at top of loop.
-		connectionPanel.setConnectRequested(false);
-		
+				
 		// Re-enable the JobPanel.
 		jobPanel.enableJobPanel(true);
-		
-		// Set status.
-		connectionStatusPanel.setStatus(ConnectionStatus.DISCONNECTED);
-		
-		// Reset the LCSim Drivers, which should destroy Plotters.
-		// FIXME: Needed?  Doesn't really make sense here.
-		//resetDrivers();
 	}
 	
-	synchronized void setConnected() {
-		
-		// This status indicates that we are attempting to connect.
-		setConnectionStatus(ConnectionStatus.CONNECTING);
-		
+	private void setConnectedGuiState() {
+	    
+	    // Disable connection panel.
+        connectionPanel.enableConnectionPanel(false);
+	   
+        // Disable JobPanel.
+        jobPanel.enableJobPanel(false);
+        
 		// Enable or disable appropriate menu items.
 		connectItem.setEnabled(false);
 		disconnectItem.setEnabled(true);
@@ -389,22 +490,20 @@
 		resetDriversItem.setEnabled(true);
 		logItem.setEnabled(false);
 		terminalItem.setEnabled(false);
-		
-		// Disable JobPanel.
-		jobPanel.enableJobPanel(false);
-		
-		// Reset this on connect.
-		connectionPanel.setConnectRequested(false);
 	}
 				
 	private void exit() {
+        if (connection != null)
+            connection.cleanup();
 		System.exit(0);
 	}
-		
-	private void screenshot() {
+	
+    private static final String screenshotFormat = "png";
+	
+    private void screenshot() {
 		JFileChooser fc = new JFileChooser();
 		fc.setDialogTitle("Save Screenshot");
-		int r = fc.showSaveDialog(this);
+		int r = fc.showSaveDialog(this.mainPanel);
 		if (r == JFileChooser.APPROVE_OPTION) {
 			String fileName = fc.getSelectedFile().getPath();
 			int extIndex = fileName.lastIndexOf(".");
@@ -428,38 +527,69 @@
 			showDialog(e.getMessage());
 		}
 	}
-	
-	boolean connectionRequested() {
-		return connectionPanel.connectRequested();
+
+	private String getEventBuilderClassName() {
+		return jobPanel.getEventBuilderClassName();
 	}
 	
-	boolean disconnectRequested() {
-		return connectionPanel.disconnectRequested();
+	private int getSteeringType() {
+		return jobPanel.getSteeringType();
 	}
 	
-	void setConnectionStatus(int status) {
-		connectionStatusPanel.setStatus(status);				
+    // Wait for connection request from GUI.
+	private void waitForConnectionRequest() {
+        while (!connectionRequested()) {
+            try { Thread.sleep(1000); } catch (InterruptedException e)  {};
+        }        
 	}
 	
-	String getEventBuilderClassName() {
-		return jobPanel.getEventBuilderClassName();
+	// Job is everything that happens from waiting for and getting a connect (or cancel/error) to disconnect.
+	private void startJob() {
+
+        // Wait until connection is requested.
+        waitForConnectionRequest();
+	    
+	    // Connect to LCSim and ET system.
+	    connect();
+	    
+	    // Reset event GUI.
+	    eventPanel.reset();
+	    
+	    // This is only reset between different jobs (disconnects).
+        eventPanel.resetSessionSupplied();
+
+	    // Start the event processing loop.
+	    int status = eventLoop();
+	    
+	    // If event loop stops then disconnect LCSim and the ET system.
+	    disconnect(status);
 	}
 	
-	int getSteeringType() {
-		return jobPanel.getSteeringType();
+	private void connect() {
+	    
+	    // Make sure applicable menu items are enabled or disabled.
+        setConnectedGuiState();
+
+        // Setup LCSim.
+        setupLCSim();
+
+        // Create a connection to the ET server.
+        createEtConnection();
+        
+        // If this method completes should be connected to valid Et/LCSim session.
+        connectionStatusPanel.setStatus(ConnectionStatus.CONNECTED);
 	}
 	
-	void startJob() {
-		connectionStatusPanel.setStatus(ConnectionStatus.CONNECTED);
-		eventPanel.reset();
-		eventPanel.updateJobStartTime();
+	private void stopJob() {
+        if (jobManager != null)
+            jobManager.finish();
 	}
 	
-	void startEvent() {
+	private void startEvent() {
 		eventPanel.updateEventCount();
 	}
 	
-	void endEvent() {
+	private void endEvent() {
 
 		// Update the average event rate.
 		eventPanel.updateAverageEventRate();                    
@@ -468,52 +598,259 @@
 		eventPanel.updateElapsedTime();
 	}
 	
-	void badEvent() {
+	private void badEvent() {
 		eventPanel.updateBadEventCount();
 	}
 	
-	boolean validSteering() {
+	private boolean validSteering() {
 		return jobPanel.validSteering();
 	}
 	
-	String getSteering() {
+	private String getSteering() {
 		return jobPanel.getSteering();
 	}
 	
-	String getDetectorName() {
+	private String getDetectorName() {
 		return jobPanel.getDetectorName();
 	}
 	
-	ConnectionParameters getConnectionParameters() {
+	private ConnectionParameters getConnectionParameters() {
 		return connectionPanel.getConnectionParameters();
 	}
-	
-	void setEtConnection(EtConnection connection) {
-		this.connection = connection;
-	}
-	
-	void error(Exception e, String mesg) {
-		e.printStackTrace();
-		if (driverAdapter != null)
-			driverAdapter.finish(null);		
-		if (mesg != null)
-			showDialog(mesg);
-		else
-			showDialog(e.getMessage());
-		connection.cleanup();
-		Runtime.getRuntime().removeShutdownHook(connection.getShutdownCallback());
-		setDisconnected();
+
+	// Method for disconnecting cleanly from the ET server and LCSim.
+	synchronized private void disconnect(int status) {
+	    setConnectionStatus(status);
+	    try {
+	        // Stop the LCSim job.
+	        stopJob();
+	    } catch (Exception e) {
+	        e.printStackTrace();
+	    }
+	    if (connection != null) {
+	        
+	        // Disconnect from ET system.
+	        connection.cleanup();
+	        
+	        // These are now unusable so reset until next reconnect.
+	        connection = null;
+	        sys = null;
+	        att = null;
+	    }
+	    setDisconnectedGuiState();
+	    setConnectionStatus(ConnectionStatus.DISCONNECTED);
 	}
 	
-	void disconnect(int status) {
-		if (driverAdapter != null)
-			driverAdapter.finish(null);
-		setConnectionStatus(status);
-		if (status == ConnectionStatus.TIMED_OUT) {
-			showDialog("ET session timed out.  You will be disconnected.");	
-		}
-		connection.cleanup();
-		Runtime.getRuntime().removeShutdownHook(connection.getShutdownCallback());
-		setDisconnected();
+	private void setupLCSim() {
+
+	    // Steering file looks valid?
+	    if (!validSteering())
+	            throw new RuntimeException("Invalid steering file or resource.");
+
+	    // Get steering resource or file as a String.
+	    String steering = getSteering();
+	    
+	    // Try to setup LCSim based on type.  
+	    try {               
+	        // Create job manager and configure based on steering type of resource or file.
+	        jobManager = new JobControlManager();
+	        jobManager.setPerformDryRun(true);
+	        if (getSteeringType() == JobPanel.RESOURCE) {
+	            InputStream is = this.getClass().getResourceAsStream(steering);
+	            jobManager.setup(is);
+	            is.close();
+	        } else if (getSteeringType() == JobPanel.FILE) {
+	            jobManager.setup(new File(steering));
+	        } 
+	            	                        
+	        // Reset reference to event builder.
+	        createEventBuilder();
+	            
+	    } catch (Exception e) {
+	        e.printStackTrace();
+	        throw new RuntimeException("Failed to setup LCSim.", e);
+	    }
 	}
+
+	private void createEventBuilder() {
+	      
+	    // Setup the EventBuilder class.
+	    String eventBuilderClassName = getEventBuilderClassName();
+	    
+	    try {
+	        eventBuilder = (LCSimEventBuilder)Class.forName(eventBuilderClassName).newInstance();
+	    } catch (Exception e) {         
+	        throw new RuntimeException("Failed to create LCSimEventBuilder class.", e);
+	    }           
+	    if (eventBuilder == null)
+	        throw new RuntimeException("LCSimEventBuilder points to null");
+	        
+	    // Set the detector name on the event builder so it can find conditions data.
+	    eventBuilder.setDetectorName(getDetectorName());
+	}       
+
+	private void processEtEvent(EtEvent mev) {
+	    
+	    // Start of event GUI hook.
+        startEvent();
+        
+        // Create EvioEvent from EtEvent and skip if failed.
+        EvioEvent evioEvent = null;
+        try {
+            evioEvent = createEvioEvent(mev);
+        } catch (Exception e) {
+            badEvent();
+            return;
+        } 
+        if (evioEvent == null) {
+            badEvent();
+            return;
+        }
+                                                                                                
+        // Create LCSim event from EVIO data.
+        EventHeader lcsimEvent = eventBuilder.makeLCSimEvent(evioEvent);
+        
+        if (lcsimEvent == null) {
+            badEvent();
+            return;
+        }
+  
+        // Supply record to Driver Adapter.
+        try {
+            jobManager.processEvent(lcsimEvent);
+        } catch (Exception e) {
+            e.printStackTrace();
+            badEvent();
+            return;
+        }
+        
+        // End of event GUI hook.
+        endEvent();
+	}
+	
+	private EvioEvent createEvioEvent(EtEvent etEvent) throws IOException, EvioException {
+	    ByteBuffer buf = etEvent.getDataBuffer();
+	    EvioReader reader = new EvioReader(buf);
+	    EvioEvent evioEvent = null;
+	    try {
+	        evioEvent = reader.parseNextEvent();
+	    } catch (java.nio.BufferUnderflowException e) {
+	        e.printStackTrace();
+	    }
+	    return evioEvent;
+	}
+	
+    public static final MonitoringApplication createMonitoringApplication() {
+        final MonitoringApplication app = new MonitoringApplication();
+        SwingUtilities.invokeLater(new Runnable() {
+            public void run() {
+                app.createApplicationFrame();
+            }
+        });
+        return app;
+    }
+    
+    // Run the app with default parameters.    
+    public static void main(String[] args)
+    {                   
+        // Setup the MonitoringApplication GUI.
+        MonitoringApplication app = MonitoringApplication.createMonitoringApplication();
+       
+        // Default job settings.
+        final String defaultDetectorName = "HPS-Test-JLAB-v4pt0";
+        final String defaultSteering = "/org/lcsim/hps/steering/MCMonitoring.lcsim";  
+        final String defaultEventBuilder = MCEventBuilder.class.getCanonicalName();
+
+        // These are for Test Run data.
+        //final String defaultSteering = "/org/lcsim/hps/defaultSteering/TestRunMonitoring.lcsim";   
+        //final String defaultEventBuilder = LCSimTestRunEventBuilder.class.getCanonicalName();
+        
+        // Push default settings to JobPanel.
+        app.setJobParameters(new JobParameters(new String[] {defaultDetectorName, defaultSteering, defaultEventBuilder}));
+        app.run();
+    }
+    
+    private void run() {
+        // GUI outer loop.  
+        while (true) {  
+            try {                
+                // Start job with current parameters.
+                startJob();
+            }
+            // Top-level exception catcher.
+            catch (Exception e) {
+                disconnect(ConnectionStatus.ERROR);
+                showDialog(e.getMessage());
+            }
+        }      
+    }
+    
+    private void processEtEvents() throws Exception {
+        
+        // Get EtEvents.
+        // If in wait mode, continue after waitTime in microseconds if there are no events.
+        // If in async mode, expects non-empty event list or an error occurs.
+        // If in sleep mode, this call will pretty much block everything, including requests to wake-up, until events arrive.
+        EtEvent[] mevs = sys.getEvents(att, waitMode, Modify.NOTHING, waitTime, chunk);
+
+        // Loop over retrieved EtEvents.
+        for (EtEvent mev : mevs) {
+            
+            // Process one EtEvent.
+            processEtEvent(mev);
+        }
+    }
+
+    private void createEtConnection() {
+
+        // Cache connection parameters.
+        connectionParameters = getConnectionParameters();
+        
+        // Setup connection to ET system.
+        connection = EtConnection.createEtConnection(connectionParameters);
+        if (connection != null) {
+            
+            // Cache the ET objects.
+            sys = connection.getEtSystem();
+            att = connection.getEtAttachment();
+            
+            // Cache these too as they are needed for every EtSystem.getEvents() call.
+            chunk = connectionParameters.chunk;
+            waitMode = connectionParameters.waitMode;
+            waitTime = connectionParameters.waitTime;
+            
+            // Set status to connected as there is now a live ET connection.
+            setConnectionStatus(ConnectionStatus.CONNECTED);
+        } 
+        else {
+            // An error occurred.
+            setConnectionStatus(ConnectionStatus.ERROR);
+            throw new RuntimeException("Failed to create ET connection.");
+        }
+    }
+    
+    // Run the event loop and return the connection status for disconnect.
+    private int eventLoop() {
+        while (true) { 
+            
+            // User wants to disconnect or system went down so need to stop processing loop.
+            if (getConnectionStatus() != ConnectionStatus.CONNECTED) { 
+                return getConnectionStatus();
+            }
+
+            // Try to process the next set of ET events.
+            try {
+                processEtEvents();
+            } 
+            // The session timed out.
+            catch (EtTimeoutException e) {
+                return ConnectionStatus.TIMED_OUT;
+            } 
+            // There was some error processing events.
+            catch (Exception e) {
+                e.printStackTrace();
+                return ConnectionStatus.ERROR;
+            }
+        }
+    }
 }
\ No newline at end of file

hps-java/src/main/java/org/lcsim/hps/monitoring
SensorOccupancyPlotsDriver.java 1.10 -> 1.11
diff -u -r1.10 -r1.11
--- SensorOccupancyPlotsDriver.java	4 Apr 2012 23:26:07 -0000	1.10
+++ SensorOccupancyPlotsDriver.java	8 Apr 2012 23:48:12 -0000	1.11
@@ -26,7 +26,7 @@
  * as the number of sensors, and hence plotter regions, is hardcoded to 20.
  * 
  * @author Jeremy McCormick <[log in to unmask]>
- * @version $Id: SensorOccupancyPlotsDriver.java,v 1.10 2012/04/04 23:26:07 jeremy Exp $
+ * @version $Id: SensorOccupancyPlotsDriver.java,v 1.11 2012/04/08 23:48:12 jeremy Exp $
  *
  */
 public class SensorOccupancyPlotsDriver extends Driver implements Resettable {
@@ -129,9 +129,6 @@
             
     public void process(EventHeader event) {
             	    
-        // Increment event counter.
-        ++eventCount;
-
         // Get RawTrackerHit collection from event.
         List<RawTrackerHit> rawTrackerHits = event.get(RawTrackerHit.class, rawTrackerHitCollectionName);        
         
@@ -155,6 +152,9 @@
                 }
             }
         }
+        
+        // Increment event counter.
+        ++eventCount;
     }    
     
     private void resetOccupancyMap() {

hps-java/src/main/java/org/lcsim/hps/monitoring
MonitoringExample.java removed after 1.10
diff -N MonitoringExample.java
--- MonitoringExample.java	6 Apr 2012 00:11:06 -0000	1.10
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,255 +0,0 @@
-package org.lcsim.hps.monitoring;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.ByteBuffer;
-
-import javax.swing.SwingUtilities;
-
-import org.freehep.record.loop.event.RecordSuppliedEvent;
-import org.jlab.coda.et.EtAttachment;
-import org.jlab.coda.et.EtEvent;
-import org.jlab.coda.et.EtSystem;
-import org.jlab.coda.et.enums.Mode;
-import org.jlab.coda.et.enums.Modify;
-import org.jlab.coda.et.exception.EtTimeoutException;
-import org.jlab.coda.jevio.EvioEvent;
-import org.jlab.coda.jevio.EvioException;
-import org.jlab.coda.jevio.EvioReader;
-import org.lcsim.event.EventHeader;
-import org.lcsim.hps.evio.LCSimEventBuilder;
-import org.lcsim.hps.evio.LCSimTestRunEventBuilder;
-import org.lcsim.hps.monitoring.ConnectionStatusPanel.ConnectionStatus;
-import org.lcsim.hps.monitoring.MonitoringApplication.JobParameters;
-import org.lcsim.job.JobControlManager;
-import org.lcsim.util.DriverAdapter;
-
-/**
- * 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 the connection status to "sleeping", would probably also need a separate thread that checks for this state.
-// TODO Calling 'Exit' on the GUI should disconnect the station properly from the ET server using a shutdown hook.
-public class MonitoringExample {
-    
-	// Default detector name.
-    static final String detectorName = "HPS-Test-JLAB-v4pt0";
-
-    // Default steering resource.
-    static final String steering = "/org/lcsim/hps/steering/TestRunMonitoring.lcsim";    
-    
-    // Default event builder.
-    static final String eventBuilderClassName = LCSimTestRunEventBuilder.class.getCanonicalName();
-    
-    // The LCSim job manager for running Drivers.
-    JobControlManager jobManager;
-    
-    // The driver adapter for wrapping event loop calls.
-    DriverAdapter driverAdapter;
-    
-    // The GUI monitoring application.
-    MonitoringApplication app;
-    
-    // The ET connection parameters.
-    EtConnection et;
-    
-    // LCSim event builder.
-    LCSimEventBuilder eventBuilder = null;
-                       
-    public MonitoringExample() 
-    {}
-        
-    public static void main(String [] args) {
-        MonitoringExample app = new MonitoringExample();
-        app.run();        
-    }
-    
-    final void createMonitoringApplication() {
-    	final MonitoringApplication app = new MonitoringApplication();
-		SwingUtilities.invokeLater(new Runnable() {
-			public void run() {
-				app.start();
-			}
-		});
-		this.app = app;
-    }
-                
-    void run()
-    {        	    	
-    	// Setup the MonitoringApplication GUI.
-    	createMonitoringApplication();
-    	
-    	// Push default settings to JobPanel.
-    	JobParameters jobParams = new JobParameters();
-    	jobParams.detectorName = detectorName;
-    	jobParams.steeringResource = steering;
-    	jobParams.eventBuilderClassName = eventBuilderClassName;
-    	app.setJobParameters(jobParams);
-    	    			    	
-    	// GUI loop.  The 'Exit' command will cause the applicatino to quit.
-    	while (true) {
-    		
-    		// Wait for connection request from GUI.
-    		while (!app.connectionRequested()) {
-    			try { Thread.sleep(1000); } catch (InterruptedException e)  {};
-    		}        
-    		ConnectionParameters cn = app.getConnectionParameters();
-    		    		    		
-    		// Make sure applicable menu items are enabled or disabled.
-    		app.setConnected();
-    		
-    		// Setup LCSim.
-    		try {
-    			setupLCSim();
-    		} catch (Exception e) {
-    			app.error(e, "Failed to setup LCSim.  You will be disconnected.");
-				continue;
-    		}
-    		
-    		// Try block is mostly for EtExceptions and friends.
-    		try {        	
-    			    			    			    			    			        			
-    			// Array of events.
-    			EtEvent[] mevs = null;
-    			
-    			// Parameters for getting events from ET server.
-    			Mode waitMode = cn.waitMode;
-    			int waitTime = cn.waitTime;
-    			int chunk = cn.chunk;
-    			
-    			// Setup connection to ET system.
-    			et = EtConnection.createEtConnection(cn);
-    			EtSystem sys = et.getEtSystem();
-    			EtAttachment att = et.getEtAttachment();
-    			
-    			// Set reference to EtConnection in GUI.
-    			app.setEtConnection(et);
-    			
-    			// Starts the job in the GUI, which is set of events processed in one session.
-    			app.startJob();
-    			
-    			// EtEvent loop.
-    			while (true) { 
-    				try {
-    					
-    					// Get EtEvents.
-    					mevs = sys.getEvents(att, waitMode, Modify.NOTHING, waitTime, chunk);
-    					
-    					// Loop over retrieved EtEvents.
-    					for (EtEvent mev : mevs) {
-    						                        					
-    						// Create EvioEvent from EtEvent and skip if failed.
-    						EvioEvent evioEvent = createEvioEvent(mev);
-    						if (evioEvent == null) {
-    							app.badEvent();
-    							continue;
-    						}
-    						
-    						// Start of event GUI hook.
-    						app.startEvent();
-    						    							    						
-    						// Create LCSim event from EVIO data.
-    						EventHeader lcsimEvent = eventBuilder.makeLCSimEvent(evioEvent);
-
-    						// Supply record to Driver Adapter.
-    						try {
-    							driverAdapter.recordSupplied(new RecordSuppliedEvent(new Object(), lcsimEvent));
-    						} catch (Exception e) {
-    							e.printStackTrace();
-    						}
-    						
-    						// End of event GUI hook.
-    						app.endEvent();
-    					}
-
-    					// Put events back into the ET system.
-    					sys.putEvents(att, mevs);   
-    					
-    					// User requested disconnect in GUI. 
-    					if (app.disconnectRequested()) {    						
-    						app.disconnect(ConnectionStatus.DISCONNECTING);
-    						break;
-    					}
-    				// The session timed out.
-    				} catch (EtTimeoutException e) {
-    					app.disconnect(ConnectionStatus.TIMED_OUT);
-    					break;
-    				}
-    			}
-    		// Top-level exception catcher.
-    		} catch (Exception e) {
-    			app.error(e, null);
-    		}
-    	}      
-    }
-
-	private EvioEvent createEvioEvent(EtEvent etEvent) throws IOException, EvioException {
-		ByteBuffer buf = etEvent.getDataBuffer();
-		EvioReader reader = new EvioReader(buf);
-		EvioEvent evioEvent = null;
-		try {
-			evioEvent = reader.parseNextEvent();
-		} catch (java.nio.BufferUnderflowException e) {
-			e.printStackTrace();
-		}
-		return evioEvent;
-	}
-
-	private void setupLCSim() {
-								
-		// Reset the DriverAdapter.
-		driverAdapter = null;
-		
-		if (!app.validSteering())
-			throw new RuntimeException("Invalid steering file or resource.");
-			
-		// Get steering resource or file.
-		String steering = app.getSteering();
-
-		// Try to setup LCSim.  If it fails, we get disconnected.
-		try {				
-			// Create job manager and configure based on steering type of resource or file.
-			jobManager = new JobControlManager();
-			jobManager.checkInputFiles(false);
-			if (app.getSteeringType() == JobPanel.RESOURCE) {
-				InputStream is = this.getClass().getResourceAsStream(steering);
-				jobManager.setup(is);
-			} else if (app.getSteeringType() == JobPanel.FILE) {
-				jobManager.setup(new File(steering));
-			} 
-
-			// Set job manager in GUI so resetting Drivers works.
-			app.setJobControlManager(jobManager);
-
-			// Make a DriverAdapter for wrapping the event loop calls.
-			driverAdapter = jobManager.getDriverAdapter();
-			
-			// Call startOfData() on DriverAdapter, which initializes conditions system.
-			driverAdapter.configure(null);
-
-			// Set reference to DriverAdapter in GUI so it can disconnect cleanly.
-			app.setDriverAdapter(driverAdapter);
-			
-		} catch (Exception e) {
-			throw new RuntimeException("Failed to setup LCSim.", e);
-		}
-		
-		// Reset reference to event builder.
-		eventBuilder = null;
-		
-		// Setup the EventBuilder class.
-		String eventBuilderClassName = app.getEventBuilderClassName();
-		try {
-			eventBuilder = (LCSimEventBuilder)Class.forName(eventBuilderClassName).newInstance();
-		} catch (Exception e) {			
-			throw new RuntimeException("Failed to create LCSimEventBuilder class.", e);
-		}			
-		if (eventBuilder == null)
-			throw new RuntimeException("LCSimEventBuilder points to null");
-		
-		// Set the detector name on the event builder so it can find conditions data.
-		eventBuilder.setDetectorName(app.getDetectorName());
-	}	
-}
\ No newline at end of file
CVSspam 0.2.12


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