Commit in hps-java/src/main/java/org/lcsim/hps/monitoring on MAIN
ConnectionPanel.java+13-101.9 -> 1.10
ConnectionParameters.java+14-141.7 -> 1.8
EtConnection.java+91.3 -> 1.4
EventPanel.java+26-251.2 -> 1.3
JobPanel.java+173-201.1 -> 1.2
MonitoringApplication.java+6-11.5 -> 1.6
MonitoringCommands.java+31.1 -> 1.2
MonitoringExample.java+156-461.7 -> 1.8
SensorOccupancyPlotsDriver.java+14-161.8 -> 1.9
+414-132
9 modified files
latest work on monitoring

hps-java/src/main/java/org/lcsim/hps/monitoring
ConnectionPanel.java 1.9 -> 1.10
diff -u -r1.9 -r1.10
--- ConnectionPanel.java	29 Mar 2012 03:52:57 -0000	1.9
+++ ConnectionPanel.java	3 Apr 2012 18:37:04 -0000	1.10
@@ -6,7 +6,6 @@
 import static org.lcsim.hps.monitoring.MonitoringCommands.resetConnectionSettingsCmd;
 import static org.lcsim.hps.monitoring.MonitoringCommands.saveConnectionCmd;
 
-
 import java.awt.Color;
 import java.awt.GridBagConstraints;
 import java.awt.GridBagLayout;
@@ -50,7 +49,11 @@
     private boolean connectRequested = false;    
     private boolean disconnectRequested = false;
     
-    static final String[] waitStrings = { "SLEEP", "TIMED", "ASYNC" };
+    static final String[] waitModes = { 
+    	Mode.SLEEP.toString(), 
+    	Mode.TIMED.toString(), 
+    	Mode.ASYNC.toString() 
+    };
 
     ConnectionPanel() {
             	
@@ -234,7 +237,7 @@
         c.gridx = 1;
         c.gridy = 10;
         c.anchor = GridBagConstraints.EAST;
-        waitComboBox = new JComboBox(waitStrings);
+        waitComboBox = new JComboBox(waitModes);
         add(waitComboBox, c);
         
         c = new GridBagConstraints();
@@ -296,11 +299,11 @@
     private Mode getWaitMode() {
     	Mode mode = null;
     	String sel = (String)waitComboBox.getSelectedItem();
-    	if ("wait".equalsIgnoreCase(sel)) {
+    	if (Mode.TIMED.toString().equalsIgnoreCase(sel)) {
     		mode = Mode.TIMED;
-    	} else if ("async".equalsIgnoreCase(sel)) {
+    	} else if (Mode.ASYNC.toString().equalsIgnoreCase(sel)) {
     		mode = Mode.ASYNC;
-    	} else if ("sleep".equalsIgnoreCase(sel)) {
+    	} else if (Mode.SLEEP.toString().equalsIgnoreCase(sel)) {
     		mode = Mode.SLEEP;
     	// Values are constrained by combo box so shouldn't happen but check anyways.
     	} else {
@@ -309,7 +312,7 @@
     	return mode;
     }
     
-    private void setWaitMode(Mode waitMode) {
+    private void setWaitMode(Mode waitMode) {    	
     	if (waitMode == Mode.SLEEP) {
         	waitComboBox.setSelectedIndex(0);
         } else if (waitMode == Mode.TIMED) {
@@ -437,11 +440,11 @@
     }
     
     private void setWaitMode(String waitMode) {
-    	if ("sleep".equals(waitMode.toLowerCase())) {
+    	if (Mode.SLEEP.toString().equals(waitMode.toLowerCase())) {
 			waitComboBox.setSelectedIndex(0);
-		} else if ("wait".equals(waitMode.toLowerCase())) {
+		} else if (Mode.TIMED.toString().equals(waitMode.toLowerCase())) {
 			waitComboBox.setSelectedIndex(1);
-		} else if ("async".equals(waitMode.toLowerCase())) {
+		} else if (Mode.ASYNC.toString().equals(waitMode.toLowerCase())) {
 			waitComboBox.setSelectedIndex(2);
 		}
     }

hps-java/src/main/java/org/lcsim/hps/monitoring
ConnectionParameters.java 1.7 -> 1.8
diff -u -r1.7 -r1.8
--- ConnectionParameters.java	29 Mar 2012 03:52:57 -0000	1.7
+++ ConnectionParameters.java	3 Apr 2012 18:37:04 -0000	1.8
@@ -12,20 +12,20 @@
  */
 class ConnectionParameters {
 
-    public String etName = "ETBuffer";
-    public String host = null;
-    public int port = EtConstants.serverPort;
-    public boolean blocking = true;
-    public boolean verbose = false;
-    public String statName = "MY_STATION";
-    public int chunk = 1;
-    public int qSize = 0;
-    public int position = 1;
-    public int pposition = 0;
-    public int flowMode = EtConstants.stationSerial;
-    public Mode waitMode = Mode.SLEEP; // sleep, timed or async
-    public int waitTime = 20000000; // wait time in microseconds
-    public int prescale = 1;
+    String etName = "ETBuffer";
+    String host = null;
+    int port = EtConstants.serverPort;
+    boolean blocking = true;
+    boolean verbose = false;
+    String statName = "MY_STATION";
+    int chunk = 1;
+    int qSize = 0;
+    int position = 1;
+    int pposition = 0;
+    int flowMode = EtConstants.stationSerial;
+    Mode waitMode = Mode.SLEEP; 
+    int waitTime = 20000000; // microseconds
+    int prescale = 1;
                    
     public ConnectionParameters() {
         // Set the default host to this machine.

hps-java/src/main/java/org/lcsim/hps/monitoring
EtConnection.java 1.3 -> 1.4
diff -u -r1.3 -r1.4
--- EtConnection.java	29 Mar 2012 03:52:57 -0000	1.3
+++ EtConnection.java	3 Apr 2012 18:37:04 -0000	1.4
@@ -49,10 +49,19 @@
 	    // Set prescale.  Only values > 1 are used, as 1 means select every event.  
 	    // Invalid values of 0 or negative numbers are simply ignored.
 	    if (cn.prescale > 1) {
+	    	System.out.println("setting prescale to " + cn.prescale);
 	    	statConfig.setPrescale(cn.prescale);
 	    }
 
 	    // create station
+	    /*
+	    if (sys.stationExists(cn.statName)) {
+	    	System.out.println("removing existing station");
+	    	EtStation stat = sys.stationNameToObject(cn.statName);
+	    	sys.removeStation(stat);
+	    	System.out.println("station removed");
+	    }
+	    */
 	    EtStation stat = sys.createStation(statConfig, cn.statName, cn.position, cn.pposition);
 	     
 	    // attach to new station

hps-java/src/main/java/org/lcsim/hps/monitoring
EventPanel.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- EventPanel.java	27 Mar 2012 03:18:21 -0000	1.2
+++ EventPanel.java	3 Apr 2012 18:37:04 -0000	1.3
@@ -186,34 +186,12 @@
             this.elapsedTimeField.setText(Long.toString(System.currentTimeMillis() - jobStartTime));
         }
     }
-        
-    private void resetEventCount() {
-        eventCount = 0;
-        eventCounterField.setText("0");
-    }
-    
-    private void resetElapsedTime() {
-        elapsedTimeField.setText("0");
-    }   
-        
-    private void resetJobStartTime() {
-        jobStartTime = System.currentTimeMillis();
-    }
-    
-    private void resetAverageEventRate() {
-        avgEventRateField.setText("0");
-    }
-    
-    private void resetBadEventCount() {
-    	this.badEventCount = 0;
-    	this.badEventsField.setText("0");
-    }
  
     public void actionPerformed(ActionEvent e) {
         String cmd = e.getActionCommand();
-        if ("resetEvents".equals(cmd)) {
+        if (MonitoringCommands.resetEventsCmd.equals(cmd)) {
             reset();
-        } else if ("eventRefreshEdit".equals(cmd)) {
+        } else if (MonitoringCommands.refreshCmd.equals(cmd)) {
         	eventRefreshEdit();
         }
     }
@@ -232,11 +210,34 @@
     	}
     }
         
-	synchronized private void reset() {
+	synchronized void reset() {
         resetEventCount();
         resetBadEventCount();
         resetAverageEventRate();
         resetElapsedTime();
         resetJobStartTime();
     }
+	
+    
+	private void resetEventCount() {
+		eventCount = 0;
+		eventCounterField.setText("0");
+	}
+
+	private void resetElapsedTime() {
+		elapsedTimeField.setText("0");
+	}   
+
+	private void resetJobStartTime() {
+		jobStartTime = System.currentTimeMillis();
+	}
+
+	private void resetAverageEventRate() {
+		avgEventRateField.setText("0");
+	}
+
+	private void resetBadEventCount() {
+		this.badEventCount = 0;
+		this.badEventsField.setText("0");
+	}
 }
\ No newline at end of file

hps-java/src/main/java/org/lcsim/hps/monitoring
JobPanel.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- JobPanel.java	27 Mar 2012 03:18:21 -0000	1.1
+++ JobPanel.java	3 Apr 2012 18:37:04 -0000	1.2
@@ -3,18 +3,33 @@
 import java.awt.Color;
 import java.awt.GridBagConstraints;
 import java.awt.GridBagLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.File;
+import java.io.InputStream;
 
-import javax.swing.JCheckBox;
+import javax.swing.JComboBox;
 import javax.swing.JLabel;
+import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 import javax.swing.JTextField;
 
-class JobPanel extends JPanel {
-	
-	JTextField lcsimSteeringField;
+// TODO Add field for setting the class to do LCSim event building.  Use EventBuilder interface to check if given class makes sense. 
+class JobPanel extends JPanel implements ActionListener {
+
+	final static String[] steeringTypes = { "RESOURCE", "FILE", "NONE" };	
+	final static int RESOURCE = 0;
+	final static int FILE = 1;
+	final static int NONE = 2;
+		
+	JComboBox steeringComboBox;
+	JTextField steeringField;
 	JTextField detectorNameField;
+	JTextField eventBuilderField;
+	
+	String defaultEventBuilderClassName = "";
 		
-	public JobPanel() {
+	JobPanel() {
 		
 		setLayout(new GridBagLayout());
 		
@@ -22,23 +37,43 @@
         c.gridx = 0;
         c.gridy = 0;
         c.anchor = GridBagConstraints.WEST;
-        JLabel lcsimSteeringLabel = new JLabel("LCSim Steering File:");
+        JLabel lcsimSteeringTypeLabel = new JLabel("Steering Type:");
+        lcsimSteeringTypeLabel.setHorizontalAlignment(JLabel.LEFT);
+        lcsimSteeringTypeLabel.setToolTipText("Type of LCSim steering file, either resource or local file.");
+        add(lcsimSteeringTypeLabel, c);
+
+        c = new GridBagConstraints();
+        c.gridx = 1;
+        c.gridy = 0;
+        c.anchor = GridBagConstraints.EAST;
+        steeringComboBox  = new JComboBox(steeringTypes);
+        steeringComboBox.setSelectedIndex(NONE);
+        steeringComboBox.setBackground(Color.WHITE);
+        add(steeringComboBox, c);
+		
+		c = new GridBagConstraints();
+        c.gridx = 0;
+        c.gridy = 1;
+        c.anchor = GridBagConstraints.WEST;
+        JLabel lcsimSteeringLabel = new JLabel("Steering File:");
         lcsimSteeringLabel.setHorizontalAlignment(JLabel.LEFT);
         lcsimSteeringLabel.setToolTipText("Resource in jar pointing to LCSim steering file.");
         add(lcsimSteeringLabel, c);
 
         c = new GridBagConstraints();
         c.gridx = 1;
-        c.gridy = 0;
+        c.gridy = 1;
         c.anchor = GridBagConstraints.EAST;
-        lcsimSteeringField = new JTextField("", 30);
-        lcsimSteeringField.setHorizontalAlignment(JTextField.RIGHT);
-        lcsimSteeringField.setBackground(Color.WHITE);
-        add(lcsimSteeringField, c);		
+        steeringField = new JTextField("", 30);
+        steeringField.setHorizontalAlignment(JTextField.RIGHT);
+        steeringField.setBackground(Color.WHITE);
+        steeringField.setActionCommand(MonitoringCommands.steeringCmd);
+        steeringField.addActionListener(this);
+        add(steeringField, c);		
         
         c = new GridBagConstraints();
         c.gridx = 0;
-        c.gridy = 1;
+        c.gridy = 2;
         c.anchor = GridBagConstraints.WEST;
         JLabel detectorLabel = new JLabel("Detector Name:");
         detectorLabel.setHorizontalAlignment(JLabel.LEFT);
@@ -47,27 +82,145 @@
 
         c = new GridBagConstraints();
         c.gridx = 1;
-        c.gridy = 1;
+        c.gridy = 2;
         c.anchor = GridBagConstraints.EAST;
         detectorNameField = new JTextField("", 20);
         detectorNameField.setHorizontalAlignment(JTextField.RIGHT);
         detectorNameField.setBackground(Color.WHITE);
-        add(detectorNameField, c);
+        add(detectorNameField, c);   
+        
+        c = new GridBagConstraints();
+        c.gridx = 0;
+        c.gridy = 3;
+        c.anchor = GridBagConstraints.WEST;
+        JLabel eventBuilderLabel = new JLabel("Event Builder Class:");
+        eventBuilderLabel.setHorizontalAlignment(JLabel.LEFT);
+        eventBuilderLabel.setToolTipText("Fully qualified name of class used to convert to LCSim events from EVIO.");
+        add(eventBuilderLabel, c);
+
+        c = new GridBagConstraints();
+        c.gridx = 1;
+        c.gridy = 3;
+        c.anchor = GridBagConstraints.EAST;
+        eventBuilderField = new JTextField("", 30);
+        eventBuilderField.setHorizontalAlignment(JTextField.RIGHT);
+        eventBuilderField.setBackground(Color.WHITE);
+        eventBuilderField.addActionListener(this);
+        eventBuilderField.setActionCommand(MonitoringCommands.eventBuilderCmd);
+        add(eventBuilderField, c);
+	}
+	
+	public void actionPerformed(ActionEvent e) {
+		if (MonitoringCommands.steeringCmd == e.getActionCommand()) {
+			editSteering();
+		} else if (MonitoringCommands.eventBuilderCmd == e.getActionCommand()) {
+			editEventBuilder();
+		}
+	}
+	
+	private void editSteering() {
+		String steering = steeringField.getText();
+		int steeringType = steeringComboBox.getSelectedIndex();		
+		if (RESOURCE == steeringType) {
+			// Check that steering resource exists.
+			InputStream is = getClass().getResourceAsStream(steering);
+			if (is == null) {
+				JOptionPane.showMessageDialog(this, "The LCSim steering resource does not exist.");
+				disableSteering();
+			}
+		} else if (FILE == steeringType) {
+			// Check that steering file exists.
+			File f = new File(steering);
+			if (!f.exists()) {
+				JOptionPane.showMessageDialog(this, "The LCSim steering file does not exist.");
+				disableSteering();
+			}
+		} else if (NONE == steeringType) {
+			if (!("".equals(steeringField.getText().trim()))) {
+				JOptionPane.showMessageDialog(this, "Select resource or file type in above combo box to enable LCSim.");
+			}
+		}
+	}
+	
+	private void disableSteering() {
+		JOptionPane.showMessageDialog(this, "No valid steering file was selected, so job will run without LCSim.");
+		steeringComboBox.setSelectedIndex(NONE);
+	}
+	
+	private void editEventBuilder() {
+		String eventBuilderClassName = eventBuilderField.getText();
+		try {
+			// Test that the event builder class can be created successfully.
+			Class eventBuilderClass = Class.forName(eventBuilderClassName);
+			eventBuilderClass.newInstance();
+		} catch (ClassNotFoundException e) {
+			JOptionPane.showMessageDialog(this, "Event builder class does not exist.");
+			resetEventBuilder();
+		} catch (InstantiationException e) {
+			JOptionPane.showMessageDialog(this, "Failed to instantiate instance of event builder class.");
+			resetEventBuilder();
+		} catch (IllegalAccessException e) {
+			JOptionPane.showMessageDialog(this, "Couldn't access event builder class.");
+			resetEventBuilder();
+		}
+	}
+	
+	private void resetEventBuilder() {
+		eventBuilderField.setText(defaultEventBuilderClassName);
 	}
 	
-	public void setSteeringFile(String steeringFile) {
-		lcsimSteeringField.setText(steeringFile);
+	String getEventBuilderClassName() {
+		if (!"".equals(eventBuilderField.getText().trim())) {
+			return eventBuilderField.getText();
+		} else {
+			return null;
+		}
 	}
 	
-	public void setDetectorName(String detectorName) {
+	void setSteeringFile(String steeringFile) {
+		steeringField.setText(steeringFile);
+		steeringComboBox.setSelectedIndex(FILE);
+		this.actionPerformed(new ActionEvent(this, 0, MonitoringCommands.steeringCmd));
+	}
+	
+	void setSteeringResource(String steeringResource) {
+		steeringField.setText(steeringResource);
+		steeringComboBox.setSelectedIndex(RESOURCE);
+		this.actionPerformed(new ActionEvent(this, 0, MonitoringCommands.steeringCmd));
+	}
+	
+	void setDetectorName(String detectorName) {
 		detectorNameField.setText(detectorName);
 	}
 	
-	public String getSteeringFile() {
-		return lcsimSteeringField.getText();
+	String getSteering() {
+		if (steeringComboBox.getSelectedIndex() != NONE)
+			return steeringField.getText();
+		else
+			return null;
 	}
 	
-	public String getDetectorName() {
+	int getSteeringType() {
+		return steeringComboBox.getSelectedIndex();
+	}
+		
+	String getDetectorName() {
 		return detectorNameField.getText();
 	}
+	
+	boolean validSteering() {
+		return !("".equals(steeringField.getText().trim())) && (this.steeringComboBox.getSelectedIndex() != NONE);
+	}
+	
+	void setDefaultEventBuilder(String defaultEventBuilderClassName) {
+		this.defaultEventBuilderClassName = defaultEventBuilderClassName;
+		eventBuilderField.setText(this.defaultEventBuilderClassName);
+	}
+	
+	void enableJobPanel(boolean enable) {
+		steeringComboBox.setEnabled(enable);
+		steeringField.setEnabled(enable);
+		detectorNameField.setEnabled(enable);
+		eventBuilderField.setEnabled(enable);
+	}	
 }
\ No newline at end of file

hps-java/src/main/java/org/lcsim/hps/monitoring
MonitoringApplication.java 1.5 -> 1.6
diff -u -r1.5 -r1.6
--- MonitoringApplication.java	29 Mar 2012 03:52:57 -0000	1.5
+++ MonitoringApplication.java	3 Apr 2012 18:37:04 -0000	1.6
@@ -213,7 +213,6 @@
         	savePlots();
         } else if (resetDriversCmd.equals(cmd)) {
         	resetDrivers();
-        // Quit.
         } else if (exitCmd.equals(cmd)) {
         	exit();
         }
@@ -236,6 +235,9 @@
 		// Re-enable the ConnectionPanel.
 		connectionPanel.enableConnectionPanel(true);
 		
+		// Re-enable the JobPanel.
+		jobPanel.enableJobPanel(true);
+		
 		// Set status.
 		connectionStatusPanel.setStatus(ConnectionStatus.DISCONNECTED);
 		
@@ -253,6 +255,9 @@
 		savePlotsItem.setEnabled(true);
 		resetDriversItem.setEnabled(true);
 		
+		// Disable JobPanel.
+		jobPanel.enableJobPanel(false);
+		
 		// Set status.
 		connectionStatusPanel.setStatus(ConnectionStatus.CONNECTED);
 	}

hps-java/src/main/java/org/lcsim/hps/monitoring
MonitoringCommands.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- MonitoringCommands.java	27 Mar 2012 20:31:49 -0000	1.1
+++ MonitoringCommands.java	3 Apr 2012 18:37:04 -0000	1.2
@@ -13,5 +13,8 @@
 	static final String resetEventsCmd = "resetEvents";
 	static final String savePlotsCmd = "savePlots";
 	static final String resetDriversCmd = "resetDrivers";
+	static final String steeringCmd = "editSteering";
+	static final String eventBuilderCmd = "eventBuilder";
+	static final String refreshCmd = "eventRefreshEdit";
 	static final String exitCmd = "exit";
 }

hps-java/src/main/java/org/lcsim/hps/monitoring
MonitoringExample.java 1.7 -> 1.8
diff -u -r1.7 -r1.8
--- MonitoringExample.java	3 Apr 2012 17:02:35 -0000	1.7
+++ MonitoringExample.java	3 Apr 2012 18:37:04 -0000	1.8
@@ -1,8 +1,10 @@
 package org.lcsim.hps.monitoring;
 
+import java.io.File;
 import java.io.InputStream;
 import java.nio.ByteBuffer;
 
+import javax.swing.JOptionPane;
 import javax.swing.SwingUtilities;
 
 import org.freehep.record.loop.event.RecordSuppliedEvent;
@@ -15,6 +17,7 @@
 import org.jlab.coda.jevio.EvioEvent;
 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.job.JobControlManager;
@@ -25,13 +28,20 @@
  * @author Jeremy McCormick
  */
 // TODO Allow interrupt of sleep mode using EtWakeUpException.  Probably need a separate thread to do this.  To
-//      set connection status to "sleeping", would probably also need a separate thread that checks for this state.
+//      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.
 public class MonitoringExample {
     
-    private static final String defaultDetectorName = "HPS-Test-JLAB-v4pt0";
-    private static final String defaultSteeringFile = "/org/lcsim/hps/steering/EtSensorOccupancy.lcsim";
+    static final String detectorName = "HPS-Test-JLAB-v4pt0";
+    // TODO Change to EtTest or something that has ECal and SVT plots.
+    static final String steering = "/org/lcsim/hps/steering/EtSensorOccupancy.lcsim";
+    //static final String steering = "/u1/hps/trackerTest/EtEcalTest.lcsim";
+    //static final String eventBuilderClassName = MCEventBuilder.class.getCanonicalName();
+    static final String eventBuilderClassName = LCSimTestRunEventBuilder.class.getCanonicalName();
     
-    private JobControlManager jobMgr; 
+    JobControlManager jobManager;
+
+    boolean debug = true;
                        
     public MonitoringExample() 
     {}
@@ -51,74 +61,127 @@
 			}
 		});
     	
-    	// Set default detector and steering file in job GUI.
+    	// Push default settings to JobPanel.
     	JobPanel jobPanel = gui.getJobPanel();
-    	jobPanel.setDetectorName(defaultDetectorName);
-    	jobPanel.setSteeringFile(defaultSteeringFile);
+    	jobPanel.setDetectorName(detectorName);
+    	jobPanel.setSteeringResource(steering);
+    	jobPanel.setDefaultEventBuilder(eventBuilderClassName);
     	
-    	// Get ConnectionPanel which can be used to connect/disconnect from ET system.
+    	// Get ConnectionPanel which will have user connection settings.
 		ConnectionPanel connectionPanel = gui.getConnectionPanel();
+		
+		if (debug)
+			System.out.println("about to enter GUI loop");
     	
-    	// GUI loop.  Use 'Exit' command from GUI to quit.
+    	// GUI loop.  Use 'Exit' command from GUI to quit the application.
     	while (true) {
 
+    		if (debug)
+    			System.out.println("top of GUI loop");
+    		
     		// Wait for connection request from GUI.
     		while (!connectionPanel.connectRequested()) {
     			try { Thread.sleep(1000); } catch (InterruptedException e)  {};
     		}        
     		ConnectionParameters cn = connectionPanel.getConnectionParameters();
+    		
+    		if (debug)
+    			System.out.println("user requested connection");
     		    		
-    		// This makes sure applicable menu items are enabled/disabled.
+    		// This makes sure applicable menu items are enabled/disabled while connected.
     		gui.connect();
-    		gui.getConnectionStatusPanel().setStatus(ConnectionStatus.CONNECTING);
 
+    		// Set the GUI status.
+    		gui.getConnectionStatusPanel().setStatus(ConnectionStatus.CONNECTING);
+    		    							
     		// Try block is mostly for EtExceptions and friends.
     		try {        	
 
+    			if (debug)
+    				System.out.println("setting up ET system");
+    			
     			// Setup connection to ET system.
     			EtConnection et = EtConnection.makeEtConnection(cn);
     			EtSystem sys = et.getEtSystem();
     			EtAttachment att = et.getEtAttachment();   
+    			
+    			if (debug)
+    				System.out.println("done setting up ET system");
+    			    			
+    			// Setup LCSim if a valid steering file and event builder were selected.
+    			// Otherwise, the monitoring job will run without LCSim.
+    			if (debug)
+    				System.out.println("initializing lcsim for job");
+    			DriverAdapter driverAdapter = null;
+    			String eventBuilderClassName = gui.getJobPanel().getEventBuilderClassName();
+    			LCSimEventBuilder eventBuilder = null;
+				try {
+					eventBuilder = (LCSimEventBuilder)Class.forName(eventBuilderClassName).newInstance();
+				} catch (Exception e) {					
+					JOptionPane.showMessageDialog(gui, "Failed to create event builder.  Job will run without LCSim.");					
+				}			
+    			if (jobPanel.validSteering() && (eventBuilder != null)) {
+    				
+    				// Get steering resource or file.
+    				String steering = jobPanel.getSteering();
+    				
+    				// Create job manager and configure based on steering type of resource or file.
+    				jobManager = new JobControlManager();
+    				jobManager.checkInputFiles(false);
+    				if (gui.getJobPanel().getSteeringType() == JobPanel.RESOURCE) {
+    					InputStream is = this.getClass().getResourceAsStream(steering);
+    					jobManager.setup(is);
+    				} else if (gui.getJobPanel().getSteeringType() == JobPanel.FILE) {
+    					jobManager.setup(new File(steering));
+    				} 
+    				
+        			// Set job manager in GUI so resetting Drivers works.
+        			gui.setJobControlManager(jobManager);
+        			
+        			// Make a DriverAdapter for wrapping the event loop calls.
+        			driverAdapter = jobManager.getDriverAdapter();
+
+        			// Call wrapper to startOfData() on DriverAdapter.
+        			// FIXME This might happen automatically later.  Need to check.
+        			driverAdapter.configure(null);
 
-    			// Job manager to run LCSim.
-    			String steeringFile = jobPanel.getSteeringFile();
-    			jobMgr = new JobControlManager();
-    			jobMgr.checkInputFiles(false);
-    			InputStream is = this.getClass().getResourceAsStream(steeringFile);
-    			jobMgr.setup(is);
-
-    			// Set ref to JobControlManager in GUI so resetting works.
-    			gui.setJobControlManager(jobMgr);
-
-    			// Make a DriverAdapter for wrapping event loop.
-    			DriverAdapter driverAdapter = jobMgr.getDriverAdapter();
-
-    			// Call wrapper to startOfData() on DriverAdapter.
-    			driverAdapter.configure(null);
-
-    			// Make the builder for creating LCSim events from EVIO data.
-    			String detectorName = jobPanel.getDetectorName();
-    			LCSimTestRunEventBuilder eventBuilder = new LCSimTestRunEventBuilder(detectorName);
-    			eventBuilder.setDebug(false);
+        			// Set the detector name on the event builder so it can find conditions data.
+        			eventBuilder.setDetectorName(jobPanel.getDetectorName());
+    			}
+    			
+    			if (debug)
+    				System.out.println("done initializing lcsim");
 
     			// Start job timer.
     			EventPanel eventPanel = gui.getEventPanel();
     			eventPanel.updateJobStartTime();
 
-    			// array of events
+    			// Array of events.
     			EtEvent[] mevs = null;
     			
+    			// Parameters to fetch events from ET ring.  These won't change unless we disconnect
+    			// and start a new session.
     			Mode waitMode = cn.waitMode;
     			int waitTime = cn.waitTime;
     			int chunk = cn.chunk;
     			    			
+    			// Set status to connected.
     			gui.getConnectionStatusPanel().setStatus(ConnectionStatus.CONNECTED);
+    			
+    			// Reset the event panel in case there have been multiple jobs.
+    			gui.getEventPanel().reset();
 
     			// EtEvent loop.
     			while (true) { 
-    				try {           
+    				if (debug)
+    					System.out.println("top of event loop");
+    				try {
+    					if (debug)
+    						System.out.println("waiting for events");
     					// Get EtEvents.
     					mevs = sys.getEvents(att, waitMode, Modify.NOTHING, waitTime, chunk);
+    					if (debug)
+    						System.out.println("got " + mevs.length + " events");
 
     					// Loop over retrieved EtEvents.
     					for (EtEvent mev : mevs) {
@@ -126,6 +189,9 @@
     						// Update GUI's event count.
     						eventPanel.updateEventCount();                    
 
+    						if (debug)
+    							System.out.println("about to create EVIO event");
+    						
     						// Get EvioEvent and check for errors.
     						ByteBuffer buf = mev.getDataBuffer();
     						EvioReader reader = new EvioReader(buf);
@@ -133,19 +199,45 @@
     						try {
     							evioEvent = reader.parseNextEvent();
     						} catch (java.nio.BufferUnderflowException e) {
-    							// Error will be caught by subsequent check on null event.
+    							// This error will be handled by subsequent check for null event.
     						}
+    						if (debug)
+    							System.out.println("made EVIO event");
     						if (evioEvent == null) {
+    							if (debug)
+    								System.out.println("got a bad event");
     							eventPanel.updateBadEventCount();
     							continue;
+    						}    						
+    						
+    						// Only run LCSim if JobControlManager was setup successfully.
+    						if (jobManager != null) {
+    							
+    							if (debug)
+    								System.out.println("creating lcsim event");
+    							
+    							// Create LCSim event from EVIO data.
+    							EventHeader lcsimEvent = eventBuilder.makeLCSimEvent(evioEvent);
+    							
+    							if (debug)
+    								System.out.println("done creating lcsim event");
+
+    							// Supply record to Driver Adapter.
+    							try {
+    								if (debug)
+    									System.out.println("running lcsim drivers");
+    								driverAdapter.recordSupplied(new RecordSuppliedEvent(new Object(), lcsimEvent));
+    								if (debug)
+    									System.out.println("done running lcsim drivers");
+    							} catch (Exception e) {
+    								if (debug)
+    									System.out.println("caught exception while running lcsim");
+    								System.err.println(e.getLocalizedMessage());
+    							}
+    							if (debug)
+    								System.out.println("done running lcsim");
     						}
 
-    						// Create LCSim event from EVIO data.
-    						EventHeader lcsimEvent = eventBuilder.makeLCSimEvent(evioEvent);
-
-    						// Supply record to Driver Adapter.
-    						driverAdapter.recordSupplied(new RecordSuppliedEvent(new Object(), lcsimEvent));
-
     						// Update the average event rate.
     						eventPanel.updateAverageEventRate();                    
 
@@ -154,25 +246,43 @@
     					}
 
     					// Put events back into the ET system.
+    					if (debug)
+    						System.out.println("putting events back into ET system");
     					sys.putEvents(att, mevs);   
+    					if (debug)
+    						System.out.println("done with putEvents");
     					
     					// Break out of event loop if GUI wants disconnect. 
     					if (connectionPanel.disconnectRequested()) {
-    						gui.getConnectionStatusPanel().setStatus(ConnectionStatus.DISCONNECTING); 
-    						driverAdapter.finish(null);
+    						if (debug)
+    							System.out.println("in disconnect");
+    						gui.getConnectionStatusPanel().setStatus(ConnectionStatus.DISCONNECTING);
+    						if (driverAdapter != null)
+    							driverAdapter.finish(null);
+    						sys.detach(att);
+        					sys.removeStation(att.getStation());
     						gui.disconnect();
+    						if (debug)
+    							System.out.println("suceessfully disconnected");
     						break;
     					}
     				// Session timed out.
     				} catch (EtTimeoutException e) {
+    					if (debug)
+    						System.out.println("timeout occurred");
     					gui.getConnectionStatusPanel().setStatus(ConnectionStatus.TIMED_OUT);
-    					driverAdapter.finish(null);
+    					if (driverAdapter != null)
+    						driverAdapter.finish(null);
+    					sys.detach(att);
+    					sys.removeStation(att.getStation());
+    					if (debug)
+    						System.out.println("done handling timeout");
     					break;
     				}
     			}
-    		} catch (Exception ex) {
-    			System.out.println("Error using ET system as consumer.");
-    			ex.printStackTrace();
+    		// This catches A LOT of different exception types.  Might want to make this more granular at some point.
+    		} catch (Exception e) {
+    			System.err.println(e.getLocalizedMessage());
     		}
     	}      
     }

hps-java/src/main/java/org/lcsim/hps/monitoring
SensorOccupancyPlotsDriver.java 1.8 -> 1.9
diff -u -r1.8 -r1.9
--- SensorOccupancyPlotsDriver.java	27 Mar 2012 20:31:49 -0000	1.8
+++ SensorOccupancyPlotsDriver.java	3 Apr 2012 18:37:04 -0000	1.9
@@ -17,6 +17,15 @@
 import org.lcsim.util.Driver;
 import org.lcsim.util.aida.AIDA;
 
+/**
+ * This Driver makes plots of sensor occupancies across a run.  It is intended to be
+ * used with the monitoring system.  It will currently only run on a test run detector,
+ * 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.9 2012/04/03 18:37:04 jeremy Exp $
+ *
+ */
 public class SensorOccupancyPlotsDriver extends Driver implements Resettable {
 
     private String rawTrackerHitCollectionName = "RawTrackerHitMaker_RawTrackerHits";
@@ -52,7 +61,7 @@
         int layer = helper.getValue(id, "layer"); // 1-10; axial layers are odd layers; stereo layers are even
         int module = helper.getValue(id, "module"); // 0-1; module number is top or bottom
         
-        // Compute the sensor's x and y grid coordinates for 5x4 region layout and then translate to region number.
+        // Compute the sensor's x and y grid coordinates and then translate to region number.
         int ix = (layer - 1) / 2;
         int iy = 0;
         if (module > 0) {
@@ -67,26 +76,18 @@
     }
         
     protected void detectorChanged(Detector detector) {
-        
-        // If called multiple times then destroy plots that might be currently up.
-        //if (occuPlotter != null) {
-        //    occuPlotter.hide();
-        //    occuPlotter.destroyRegions();
-        //}
-       
-        // Setup the plotter.  Should only need to be done once per job.
+               
+        // Setup the plotter.
         IAnalysisFactory fac = aida.analysisFactory();
-        //if (occuPlotter == null) {
         occuPlotter = fac.createPlotterFactory().create(detector.getDetectorName() + " : HPS SVT Sensor Occupancy Plots");
         IPlotterStyle pstyle = occuPlotter.style();
         pstyle.dataStyle().fillStyle().setColor("green");
         pstyle.dataStyle().markerStyle().setColor("green");
         pstyle.dataStyle().errorBarStyle().setVisible(false);
         pstyle.statisticsBoxStyle().setVisible(false);            
-        //}            
         
         // Create regions.
-        occuPlotter.createRegions(5, 4); // FIXME Hard-coded to 20 sensors.
+        occuPlotter.createRegions(5, 4); 
         
         // Cache Detector object.
         this.detector = detector;
@@ -127,7 +128,7 @@
         // Get RawTrackerHit collection from event.
         List<RawTrackerHit> rawTrackerHits = event.get(RawTrackerHit.class, rawTrackerHitCollectionName);        
         
-        // Increment hit count of each strip.
+        // Increment strip hit count.
         for (RawTrackerHit hit : rawTrackerHits) {
             int[] strips = occupancyMap.get((SiSensor) hit.getDetectorElement());
             strips[hit.getIdentifierFieldValue("strip")] += 1;
@@ -161,10 +162,7 @@
     }
     
     public void reset() {
-    	//occuPlotter.hide();
         eventCount = 0;
         resetOccupancyMap();
-        //resetOccupancyMap();        
-        //detectorChanged(detector);        
     }
 }
\ 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