Commit in hps-java/src/main/java/org/lcsim/hps/monitoring on MAIN
DefaultEtEventProcessor.java+25-301.8 -> 1.9
JobPanel.java+21-121.13 -> 1.14
MonitoringApplication.java+53-361.43 -> 1.44
MonitoringCommands.java+3-21.10 -> 1.11
+102-80
4 modified files
more monitoring updates; mostly minor stuff

hps-java/src/main/java/org/lcsim/hps/monitoring
DefaultEtEventProcessor.java 1.8 -> 1.9
diff -u -r1.8 -r1.9
--- DefaultEtEventProcessor.java	10 May 2012 22:19:29 -0000	1.8
+++ DefaultEtEventProcessor.java	10 May 2012 23:07:43 -0000	1.9
@@ -21,31 +21,30 @@
 
 /**
  * This class executes the default event processing chain for HPS Test Run monitoring: ET -> EVIO -> LCIO.
- * Its method {@link #process()} should be executed on a separate thread which can be joined by the caller
- * until it dies.  {@link EtEventListener} objects can be registered with this class to receive notifications 
+ * {@link EtEventListener} objects can be registered with this class to receive notifications 
  * as processing occurs.  This is how the {@link MonitoringApplication} updates the GUI without the processor
  * having a direct reference to the actual application.
  * 
  * @author Jeremy McCormick <[log in to unmask]>
- * @version $Id: DefaultEtEventProcessor.java,v 1.8 2012/05/10 22:19:29 jeremy Exp $
+ * @version $Id: DefaultEtEventProcessor.java,v 1.9 2012/05/10 23:07:43 jeremy Exp $
  */
 public class DefaultEtEventProcessor implements EtEventProcessor
 {
-    int maxEvents;
-    int eventsProcessed;
-    int errorEvents;
-    LCSimEventBuilder eventBuilder;
-    JobControlManager jobManager;
-    EtConnection et;
-    List<EtEventListener> listeners = new ArrayList<EtEventListener>();
-    int status;    
-    volatile boolean stopProcessing;
-    volatile boolean nextEvents;
-    volatile boolean stopOnError;
-    volatile boolean pauseMode = false;
-    volatile boolean done = false;
-    volatile boolean blocked = false; 
-    static Logger logger;
+    private int maxEvents;
+    private int eventsProcessed;
+    private int errorEvents;
+    private LCSimEventBuilder eventBuilder;
+    private JobControlManager jobManager;
+    private EtConnection et;
+    private List<EtEventListener> listeners = new ArrayList<EtEventListener>();
+    private int status;    
+    private volatile boolean stopProcessing;
+    private volatile boolean nextEvents;
+    private volatile boolean stopOnError;
+    private volatile boolean pauseMode = false;
+    private volatile boolean done = false;
+    private volatile boolean blocked = false; 
+    private static Logger logger;
 
     /**
      * Create an instance of the default EtEvent processor.
@@ -90,11 +89,7 @@
     void setPauseMode(boolean p) {
         this.pauseMode = p;
     }
-    
-    Logger getLogger() {
-        return logger;
-    }
-    
+        
     public void addListener(EtEventListener callme) {
         listeners.add(callme);
     }
@@ -104,32 +99,32 @@
         logger.log(Level.INFO, "Set maxEvents to <" + maxEvents + ">.");
     }
     
-    void begin() {
+    private void begin() {
         for (EtEventListener listener : listeners) {
             listener.begin();
         }
     }
     
-    void startOfEvent() {
+    private void startOfEvent() {
         for (EtEventListener listener : listeners) {
             listener.startOfEvent();
         }
     }
     
-    void endOfEvent() {
+    private void endOfEvent() {
         for (EtEventListener listener : listeners) {
             listener.endOfEvent();
         }
     }
     
-    void errorOnEvent() {
+    private void errorOnEvent() {
         ++errorEvents;
         for (EtEventListener listener : listeners) {
             listener.errorOnEvent();
         }
     }
     
-    void finish() {
+    private void finish() {
         logger.log(Level.FINER, "Calling finish() methods of listeners.");
         for (EtEventListener listener : listeners) {
             listener.finish();
@@ -353,7 +348,7 @@
      * @param event
      * @return
      */
-    private boolean isPreStartEvent(EvioEvent event) {
+    private static boolean isPreStartEvent(EvioEvent event) {
         return event.getHeader().getTag() == EventConstants.PRESTART_EVENT_TAG;
     }
     
@@ -362,7 +357,7 @@
      * @param event
      * @return True if this event is an End Event; false if not.
      */
-    private boolean isEndEvent(EvioEvent event) {
+    private static boolean isEndEvent(EvioEvent event) {
         return event.getHeader().getTag() == EventConstants.END_EVENT_TAG;
     }
     

hps-java/src/main/java/org/lcsim/hps/monitoring
JobPanel.java 1.13 -> 1.14
diff -u -r1.13 -r1.14
--- JobPanel.java	10 May 2012 22:19:29 -0000	1.13
+++ JobPanel.java	10 May 2012 23:07:43 -0000	1.14
@@ -32,7 +32,7 @@
     private JTextField aidaSaveField;
     private JCheckBox aidaSaveCheckBox;
 
-    private String defaultEventBuilderClassName = "";
+    private String defaultEventBuilderClassName = (new JobSettings()).eventBuilderClassName;
 
     private final static String[] steeringTypes = {"RESOURCE", "FILE"};
     final static int RESOURCE = 0;
@@ -60,11 +60,12 @@
         logLevelComboBox = addComboBox("Log Level", this.logLevels);
         logLevelComboBox.setActionCommand(MonitoringCommands.logLevelCmd);
         steeringTypeComboBox = addComboBox("Steering Type", steeringTypes);  
-        steeringFileField = addField("Steering File", 30);        
+        steeringFileField = addField("Steering File", 35);        
         steeringResourcesComboBox = addComboBox("Steering File Resource", SteeringFileUtil.getAvailableSteeringFileResources());
+        steeringResourcesComboBox.setActionCommand(MonitoringCommands.steeringResourceCmd);
         detectorNameField = addField("Detector Name", 20);
         eventBuilderField = addField("Event Builder Class", 30);
-        //eventBuilderField.setActionCommand(MonitoringCommands.eventBuilderCmd);
+        eventBuilderField.setActionCommand(MonitoringCommands.eventBuilderCmd);
         logCheckBox = addCheckBox("Log to File", false, false);
         logFileField = addField("Log File", "", "Full path to log file.", 30, false);
         aidaSaveCheckBox = addCheckBox("Save AIDA at End of Job", false, false);
@@ -87,10 +88,13 @@
         steeringResourcesComboBox.setEnabled(enable);
     }   
     
+    /**
+     * Attaches the ActionListener from the main app to GUI components in this class.
+     */
     void addActionListener(ActionListener listener) {
-        //steeringFileField.addActionListener(listener);
-        //eventBuilderField.addActionListener(listener);
+        steeringResourcesComboBox.addActionListener(listener);
         logLevelComboBox.addActionListener(listener);
+        eventBuilderField.addActionListener(listener);
     }
         
     void chooseAidaAutoSaveFile() {
@@ -137,28 +141,33 @@
             throw new IllegalArgumentException("The steeringType is invalid: " + steeringType);
         }               
     }
- 
+     
     void editEventBuilder() {
         String eventBuilderClassName = eventBuilderField.getText();
+        boolean okay = true;
         try {
-            // Test that the event builder class can be created successfully.
+            // Test that the event builder can be created without throwing any exceptions.
             Class eventBuilderClass = Class.forName(eventBuilderClassName);
             eventBuilderClass.newInstance();
         } 
         catch (ClassNotFoundException e) {
-            JOptionPane.showMessageDialog(this, "Event builder class does not exist.");
-            resetEventBuilder();
+            JOptionPane.showMessageDialog(this, "The event builder class does not exist.");
+            okay = false;
         } 
         catch (InstantiationException e) {
             JOptionPane.showMessageDialog(this, "Failed to instantiate instance of event builder class.");
-            resetEventBuilder();
+            okay = false;
         } 
         catch (IllegalAccessException e) {
             JOptionPane.showMessageDialog(this, "Couldn't access event builder class.");
-            resetEventBuilder();
+            okay = false;
         }
+        
+        if (!okay)
+            resetEventBuilder();
     }
 
+
     private void resetEventBuilder() {
         SwingUtilities.invokeLater(new Runnable() {
             public void run() {
@@ -288,7 +297,7 @@
         });            
     }
     
-    private void setSteeringType(final int t) {
+    void setSteeringType(final int t) {
         SwingUtilities.invokeLater(new Runnable() {
             public void run() {
                 steeringTypeComboBox.setSelectedIndex(t);

hps-java/src/main/java/org/lcsim/hps/monitoring
MonitoringApplication.java 1.43 -> 1.44
diff -u -r1.43 -r1.44
--- MonitoringApplication.java	10 May 2012 22:19:29 -0000	1.43
+++ MonitoringApplication.java	10 May 2012 23:07:43 -0000	1.44
@@ -63,7 +63,7 @@
  * ring. This class is accessible to users by calling its main() method.
  * 
  * @author Jeremy McCormick <[log in to unmask]>
- * @version $Id: MonitoringApplication.java,v 1.43 2012/05/10 22:19:29 jeremy Exp $
+ * @version $Id: MonitoringApplication.java,v 1.44 2012/05/10 23:07:43 jeremy Exp $
  */
 public class MonitoringApplication {
 
@@ -326,7 +326,7 @@
 
         steeringItem = new JMenuItem("Set Steering File...");
         steeringItem.setMnemonic(KeyEvent.VK_S);
-        steeringItem.setActionCommand(setSteeringFileCmd);
+        steeringItem.setActionCommand(steeringFileCmd);
         steeringItem.addActionListener(actionListener);
         steeringItem.setToolTipText("Set the job's LCSim steering file.");
         jobMenu.add(steeringItem);
@@ -538,9 +538,10 @@
         public void actionPerformed(ActionEvent e) {
             String cmd = e.getActionCommand();
             if (cmd != MonitoringCommands.updateTimeCmd) {
-                if (logger != null) {
+                // Log actions performed.  Catch errors in case logging is not initialized yet.
+                try {
                     logger.log(Level.FINEST, "Action performed <" + cmd + ">.");
-                }
+                } catch (Exception xx) {}
             }
             if (connectCmd.equals(cmd)) {
                 startSessionThread();
@@ -570,8 +571,6 @@
                 connectionPanel.load();
             } else if (resetConnectionSettingsCmd.equals(cmd)) {
                 connectionPanel.reset();
-            } else if (setSteeringFileCmd.equals(cmd)) {
-                chooseSteeringFile();
             } else if (setMaxEventsCmd.equals(cmd)) {
                 setMaxEvents();
             } else if (saveLogTableCmd.equals(cmd)) {
@@ -596,6 +595,10 @@
                 loadJobSettings();
             } else if (resetJobSettingsCmd.equals(cmd)) {
                 resetJobSettings();
+            } else if (steeringResourceCmd.equals(cmd)) {
+                steeringResourceSelected();
+            } else if (steeringFileCmd.equals(cmd)) {
+                selectSteeringFile();
             }
         }
 
@@ -609,6 +612,14 @@
             t.start();
         }
     }
+    
+    /**
+     * This fires when a steering resource file is selected from the combo box.
+     * The Job Settings are changed to use a resource type.
+     */
+    private void steeringResourceSelected() {
+        jobPanel.setSteeringType(JobPanel.RESOURCE);
+    }
 
     private void saveJobSettings() {
         JFileChooser fc = new JFileChooser();
@@ -865,7 +876,7 @@
     /**
      * Select an LCSim steering file from disk.
      */
-    private void chooseSteeringFile() {
+    private void selectSteeringFile() {
         JFileChooser fc = new JFileChooser();
         int r = fc.showOpenDialog(mainPanel);
         if (r == JFileChooser.APPROVE_OPTION) {
@@ -873,6 +884,7 @@
             try {
                 (new JobControlManager()).setup(fileName);
                 jobPanel.setSteeringFile(fileName.getPath());
+                jobPanel.setSteeringType(JobPanel.FILE);
                 logger.log(Level.INFO, "Steering file set to <" + fileName.getPath() + ">.");
             }
             catch (Exception e) {
@@ -940,8 +952,8 @@
     }
 
     /**
-     * Redirect System.out and System.err to a file. This is independent of messages that are sent to the
-     * application's log table and is primarily used to capture lengthy debug output from event processing.
+     * Redirect System.out and System.err to a file. This is primarily used to capture lengthy debug 
+     * output from event processing.  Messages sent to the Logger are unaffected.
      */
     private void logToFile() {
         JFileChooser fc = new JFileChooser();
@@ -956,9 +968,8 @@
                     if (!logFile.createNewFile()) {
                         throw new IOException();
                     }
-                    PrintStream ps = new PrintStream(new FileOutputStream(logFile.getPath()));
-                    System.setOut(ps);
-                    System.setErr(ps);
+                    
+                    redirectStdOutAndErrToFile(logFile);
 
                     SwingUtilities.invokeLater(new Runnable() {
 
@@ -971,11 +982,11 @@
                         }
                     });
 
-                    logger.log(Level.INFO, "Redirected print output to file <" + logFile.getPath() + ">.");
+                    logger.log(Level.INFO, "Redirected System output to file <" + logFile.getPath() + ">.");
                 }
                 catch (IOException e) {
-                    logger.log(Level.SEVERE, "Error redirecting print output to file <" + logFile.getPath() + ">.");
-                    showDialog("Error creating log file.");
+                    logger.log(Level.SEVERE, "Error redirecting System output to file <" + logFile.getPath() + ">.");
+                    showDialog("Error redirecting System output to log file.");
                 }
             }
         }
@@ -1025,8 +1036,7 @@
     }
 
     /**
-     * Using a modal dialog, set the maximum number of events to process before an automatic disconnect
-     * occurs.
+     * Using a modal dialog, set the maximum number of events to process before an automatic disconnect.
      */
     private void setMaxEvents() {
         String inputValue = JOptionPane.showInputDialog("Max Events:", eventPanel.getMaxEvents());
@@ -1231,6 +1241,8 @@
                 disconnect(endStatus);
             }
         }
+        
+        logger.log(Level.INFO, "Finished monitoring session.");
     }
 
     /**
@@ -1251,20 +1263,18 @@
     }
 
     /**
-     * Create the Thread for processing EtEvents.
-     * 
-     * @return The Thread for event processing.
+     * Create the thread that will execute the EtEvent processing chain.     
+     * @return The thread on which event processing will occur.
      */
     private void createEventProcessingThread() {
 
         // Create a new event processor.
-        eventProcessor = new DefaultEtEventProcessor(this.connection, this.eventBuilder, this.jobManager, getMaxEvents(), disconnectOnError(),
-                this.logHandler);
+        eventProcessor = new DefaultEtEventProcessor(this.connection, this.eventBuilder, this.jobManager, getMaxEvents(), disconnectOnError(), this.logHandler);
 
-        // Add the application's listener for callback to GUI.
+        // Add the application's listener for callback to the GUI.
         eventProcessor.addListener(this.etListener);
 
-        // Set initial pause mode from job panel after which it can be toggled via event buttons.
+        // Set pause mode from JobPanel, after which it can be toggled using the event buttons.
         eventProcessor.pauseMode(this.jobPanel.pauseMode());
 
         // Create a new thread for event processing.
@@ -1274,7 +1284,10 @@
             }
         };
         eventProcessingThread = new Thread(run, "Event Processing Thread");
+        
+        // Start the event processing thread.
         eventProcessingThread.start();
+        
         logger.log(Level.FINEST, "Started event processing thread.");
         logHandler.flush();
     }
@@ -1336,7 +1349,7 @@
     /**
      * Get whether errors in event processing will cause automatic disconnect.
      * 
-     * @return True if disconnect on event processing error; false if no.
+     * @return True if disconnect on event processing error; false to continue.
      */
     private boolean disconnectOnError() {
         return jobPanel.disconnectOnError();
@@ -1347,7 +1360,7 @@
     }
 
     /**
-     * Disconnect from the ET session with a particular status.
+     * Disconnect from the current ET session with a particular status.
      * 
      * @param status The connection status.
      */
@@ -1388,6 +1401,11 @@
         logger.log(Level.CONFIG, "Disconnected from ET system.");
     }
 
+    /**
+     * This is a thread for cleaning up the ET connection.  This is executed under a separate
+     * path of execution, because it could potentially block forever.  So we need to be able
+     * to kill it after waiting for X amount of time.
+     */
     class EtCleanupThread extends Thread {
 
         boolean succeeded;
@@ -1418,12 +1436,13 @@
 
         if (connection != null) {
 
-            // Put cleanup on a separate thread in case it hangs.
+            // Put cleanup on a separate thread in case it hangs forever.
             EtCleanupThread cleanupThread = new EtCleanupThread();
             logger.log(Level.FINEST, "Starting EtCleanupThread to disconnect from ET system.");
             logHandler.flush();
             cleanupThread.start();
             try {
+                // Wait for cleanup thread to finish.
                 cleanupThread.join(this.maxCleanupTime);
             }
             catch (InterruptedException e) {
@@ -1440,7 +1459,7 @@
                 // Join to cleanup thread until it dies.
                 logger.log(Level.FINEST, "Waiting for EtCleanupThread to die");
                 logger.log(Level.FINEST, "EtCleanupThread was killed.");
-                // The connection is now unusable so set it to null.
+                // The ET connection is now unusable so set it to null.
                 this.connection = null;
             }
         }
@@ -1453,7 +1472,7 @@
 
         logger.log(Level.CONFIG, "Setting up LCSim.");
 
-        // Clear AIDA tree in case plots hanging around from previous sessions.
+        // Clear the static AIDA tree in case plots are hanging around from previous sessions.
         resetAidaTree();
 
         // Get steering resource or file as a String parameter.
@@ -1467,15 +1486,13 @@
             throw new RuntimeException("Invalid steering file or resource < " + steering + ">.");
         }
 
-        // 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 (steeringType == JobPanel.RESOURCE) {
-                logger.log(Level.FINE, "Opening InputStream for resource <" + steering + ">.");
+            if (steeringType == JobPanel.RESOURCE) {                
+                logger.log(Level.FINE, "Setting up steering resource <" + steering + ">.");
                 InputStream is = this.getClass().getClassLoader().getResourceAsStream(steering);
-                // FIXME: This is completely broken the 2nd time around and no idea why!
                 jobManager.setup(is);
                 is.close();
             } else if (getSteeringType() == JobPanel.FILE) {
@@ -1497,7 +1514,7 @@
     }
 
     /**
-     * Create the event builder for converting EVIO events to LCIO events suitable for processing by LCSim.
+     * Create the event builder for converting EVIO events to LCSim.
      */
     private void createEventBuilder() {
 
@@ -1520,8 +1537,8 @@
     }
 
     /**
-     * Create a connection to an ET system using current parameters from GUI. If successful, the
-     * ConnectionStatus is changed to CONNECTED.
+     * Create a connection to an ET system using current parameters from the GUI. 
+     * If successful, the application's ConnectionStatus is changed to CONNECTED.
      */
     private void createEtConnection() {
 

hps-java/src/main/java/org/lcsim/hps/monitoring
MonitoringCommands.java 1.10 -> 1.11
diff -u -r1.10 -r1.11
--- MonitoringCommands.java	10 May 2012 21:14:53 -0000	1.10
+++ MonitoringCommands.java	10 May 2012 23:07:43 -0000	1.11
@@ -24,8 +24,7 @@
     static final String logToTerminalCmd = "logToTerminal";
     static final String screenshotCmd = "screenshot";
     static final String eventRefreshCmd = "eventRefreshEdit";
-    static final String updateTimeCmd = "updateTime";
-    static final String setSteeringFileCmd = "setSteeringFile";
+    static final String updateTimeCmd = "updateTime";    
     static final String setMaxEventsCmd = "setMaxEvents";
     static final String saveLogTableCmd = "saveLogTable";
     static final String clearLogTableCmd = "clearLogTable";    
@@ -37,4 +36,6 @@
     static final String saveJobSettingsCmd = "saveJobSettings";
     static final String loadJobSettingsCmd = "loadJobSettings";
     static final String resetJobSettingsCmd = "resetJobSettings";
+    static final String steeringResourceCmd = "steeringResource";
+    static final String steeringFileCmd = "steeringFile";
 }
\ 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