Print

Print


Commit in java/trunk/monitoring-app/src on MAIN
main/java/org/hps/monitoring/gui/MonitoringApplication.java+45-85850 -> 851
                                /RunPanel.java+2-1850 -> 851
main/java/org/hps/monitoring/record/AbstractRecordQueue.java+2-1850 -> 851
                                   /EndRunException.java+12added 851
                                   /EndRunProcessor.java+21added 851
                                   /EtProcessingStep.java+2-1850 -> 851
                                   /EventProcessingChain.java+114-191850 -> 851
                                   /EventProcessingConfiguration.java+92added 851
                                   /EventProcessingThread.java+1-1850 -> 851
                                   /EvioProcessingStep.java+1-15850 -> 851
                                   /LcioProcessingStep.java+10-8850 -> 851
main/java/org/hps/monitoring/record/composite/CompositeRecordLoop.java+2-1850 -> 851
                                             /CompositeRecordLoopAdapter.java+3-4850 -> 851
main/java/org/hps/monitoring/record/etevent/EtConnection.java+2-2850 -> 851
test/java/org/hps/monitoring/record/EventProcessingChainTest.java+10-13850 -> 851
                                   /EvioEventProcessingTest.java+10-13850 -> 851
+329-336
3 added + 13 modified, total 16 files
Use new EventProcessingConfiguration class which simplifies configuration of event processing.

java/trunk/monitoring-app/src/main/java/org/hps/monitoring/gui
MonitoringApplication.java 850 -> 851
--- java/trunk/monitoring-app/src/main/java/org/hps/monitoring/gui/MonitoringApplication.java	2014-08-14 00:04:53 UTC (rev 850)
+++ java/trunk/monitoring-app/src/main/java/org/hps/monitoring/gui/MonitoringApplication.java	2014-08-14 00:21:22 UTC (rev 851)
@@ -1,23 +1,6 @@
 package org.hps.monitoring.gui;
 
-import static org.hps.monitoring.gui.Commands.AIDA_AUTO_SAVE;
-import static org.hps.monitoring.gui.Commands.CHOOSE_LOG_FILE;
-import static org.hps.monitoring.gui.Commands.CLEAR_LOG_TABLE;
-import static org.hps.monitoring.gui.Commands.CONNECT;
-import static org.hps.monitoring.gui.Commands.DISCONNECT;
-import static org.hps.monitoring.gui.Commands.EXIT;
-import static org.hps.monitoring.gui.Commands.LOAD_DEFAULT_CONFIG_FILE;
-import static org.hps.monitoring.gui.Commands.LOG_LEVEL_CHANGED;
-import static org.hps.monitoring.gui.Commands.LOG_TO_TERMINAL;
-import static org.hps.monitoring.gui.Commands.NEXT;
-import static org.hps.monitoring.gui.Commands.PAUSE;
-import static org.hps.monitoring.gui.Commands.RESUME;
-import static org.hps.monitoring.gui.Commands.SAVE_CONFIG_FILE;
-import static org.hps.monitoring.gui.Commands.SAVE_LOG_TABLE;
-import static org.hps.monitoring.gui.Commands.SAVE_PLOTS;
-import static org.hps.monitoring.gui.Commands.SCREENSHOT;
-import static org.hps.monitoring.gui.Commands.SELECT_CONFIG_FILE;
-import static org.hps.monitoring.gui.Commands.SHOW_SETTINGS;
+import static org.hps.monitoring.gui.Commands.*;
 
 import java.awt.Dimension;
 import java.awt.GridBagConstraints;
@@ -73,10 +56,9 @@
 import org.hps.monitoring.plotting.MonitoringAnalysisFactory;
 import org.hps.monitoring.plotting.MonitoringPlotFactory;
 import org.hps.monitoring.record.EventProcessingChain;
+import org.hps.monitoring.record.EventProcessingConfiguration;
 import org.hps.monitoring.record.EventProcessingThread;
 import org.hps.monitoring.record.etevent.EtConnection;
-import org.hps.monitoring.record.etevent.EtEventSource;
-import org.hps.monitoring.record.evio.EvioFileSource;
 import org.hps.monitoring.subsys.StatusCode;
 import org.hps.monitoring.subsys.SystemStatus;
 import org.hps.monitoring.subsys.SystemStatusListener;
@@ -84,8 +66,8 @@
 import org.hps.monitoring.subsys.et.EtSystemMonitor;
 import org.hps.monitoring.subsys.et.EtSystemStripCharts;
 import org.lcsim.job.JobControlManager;
+import org.lcsim.util.Driver;
 import org.lcsim.util.aida.AIDA;
-import org.lcsim.util.loop.LCIOEventSource;
 
 /**
  * This class is the implementation of the GUI for the Monitoring Application.
@@ -817,9 +799,10 @@
             
             // Connect to the ET system.
             connect();                        
-
+            
             // Setup the EventProcessingChain object using the EtConnection.
             setupEventProcessingChain();
+            //setupEventProcessingChainNew();
             
             // Setup the system status monitor table.
             setupSystemStatusMonitor();
@@ -835,7 +818,9 @@
             
             // Log the error that occurred.
             errorHandler.setError(e)
-                .log();
+                .log()
+                .printStackTrace();
+                /*.showErrorDialog("Error setting up the session.");*/
             
             // Disconnect from the session.
             //if (this.connected())
@@ -846,7 +831,7 @@
             dialog.dispatchEvent(new WindowEvent(dialog, WindowEvent.WINDOW_CLOSING));
         }
     }
-
+       
     /**
      * Start the session watchdog thread, which will kill the session if event processing finishes.
      */
@@ -1145,83 +1130,58 @@
     private void log(String m) {
         log(DEFAULT_LOG_LEVEL, m);
     }
-
+    
     /**
-     * Setup the <tt>EventProcessingChain</tt> object and create a <tt>Thread</tt> for running it.
-     * The processing is not started by this method.
+     * Configure the event processing chain.
      */
     private void setupEventProcessingChain() {
         
-        // Initialize the event processing chain object.
-        eventProcessing = new EventProcessingChain();                
+        EventProcessingConfiguration configuration = new EventProcessingConfiguration();
         
-        // Configure the data source, e.g. ET, EVIO or LCIO.
-        configDataSource();
-        
-        // Set the event builder.
-        eventProcessing.setEventBuilder(eventBuilder);
-        
-        // Set the detector name for LCSim conditions system.
-        eventProcessing.setDetectorName(configurationModel.getDetectorName());
-        
-        // Get a list of Drivers to execute from the JobManager which was
-        // already configured.
-        eventProcessing.add(jobManager.getDriverExecList());
-                                                         
-        // Using an ET server?
-        if (usingEtServer()) {
+        configuration.setStopOnEndRun(true);
+        configuration.setStopOnErrors(true);
+         
+        configuration.setDataSourceType(configurationModel.getDataSourceType());
+        configuration.setEtConnection(connection);
+        configuration.setFilePath(configurationModel.getDataSourcePath());
+        configuration.setLCSimEventBuild(eventBuilder);
+        configuration.setDetectorName(configurationModel.getDetectorName());                
+               
+        // Add all Drivers from the pre-configured JobManager.
+        for (Driver driver : jobManager.getDriverExecList()) {
+            configuration.add(driver);
+        }        
+               
+        // ET system monitor processor.
+        configuration.add(new EtSystemMonitor());
             
-            // ET system monitor.
-            eventProcessing.add(new EtSystemMonitor());
-            
-            // ET system strip charts.
-            eventProcessing.add(new EtSystemStripCharts());
-        }
-                
-        // Setup the event processing based on the above configuration.
-        eventProcessing.setup();
+        // ET system strip charts processor.
+        configuration.add(new EtSystemStripCharts());
+              
+        // RunPanel updater processor.
+        configuration.add(runPanel.new RunModelUpdater());
         
-        // Add processor for updating the RunPanel.
-        eventProcessing.add(runPanel.new RunModelUpdater());
+        // Create the EventProcessingChain object.
+        eventProcessing = new EventProcessingChain(configuration);
         
         // Create the event processing thread.
         eventProcessingThread = new EventProcessingThread(eventProcessing);
         
         // Start the event processing thread.
-        eventProcessingThread.start();
+        eventProcessingThread.start();        
     }
     
+    /**
+     * True if ET server is being used.
+     * @return True if using ET server.
+     */
     private boolean usingEtServer() {
         return configurationModel.getDataSourceType().equals(DataSourceType.ET_SERVER);
     }
-    
-    private boolean usingEvioFile() {
-        return configurationModel.getDataSourceType().equals(DataSourceType.EVIO_FILE);
-    }
-    
-    private void configDataSource() {
-        DataSourceType dataSourceType = configurationModel.getDataSourceType();
-        String filePath = configurationModel.getDataSourcePath();
-        log(Level.CONFIG, "Data source type <" + dataSourceType + ">");
-        if (dataSourceType.equals(DataSourceType.ET_SERVER)) {
-            eventProcessing.setRecordSource(new EtEventSource(connection));
-            log(Level.CONFIG, "ET event source");
-        } else if (dataSourceType.equals(DataSourceType.EVIO_FILE)){
-            eventProcessing.setRecordSource(new EvioFileSource(new File(filePath)));
-            log(Level.CONFIG, "EVIO file <" + filePath + " >");
-        } else if (dataSourceType.equals(DataSourceType.LCIO_FILE)) {
-            try {
-                eventProcessing.setRecordSource(new LCIOEventSource(new File(filePath)));
-                log(Level.CONFIG, "LCIO file <" + filePath + ">");
-            } catch (IOException e) {
-                errorHandler.setError(e)
-                    .log()
-                    .printStackTrace()
-                    .raiseException();
-            }
-        }
-    }
-    
+           
+    /**
+     * Configure the system status monitor panel for a new job.
+     */
     private void setupSystemStatusMonitor() {
         // Clear the system status monitor table.        
         systemStatusFrame.getTableModel().clear();
@@ -1526,7 +1486,7 @@
     }
 
     /**
-     * Log all status changes.
+     * Hook for logging all status changes from the system status monitor.
      */
     @Override
     public void statusChanged(SystemStatus status) {

java/trunk/monitoring-app/src/main/java/org/hps/monitoring/gui
RunPanel.java 850 -> 851
--- java/trunk/monitoring-app/src/main/java/org/hps/monitoring/gui/RunPanel.java	2014-08-14 00:04:53 UTC (rev 850)
+++ java/trunk/monitoring-app/src/main/java/org/hps/monitoring/gui/RunPanel.java	2014-08-14 00:21:22 UTC (rev 851)
@@ -25,7 +25,8 @@
  * Dashboard for displaying information about the current run.
  * @author Jeremy McCormick <[log in to unmask]>
  */
-// FIXME: Add current EVIO event number, current event sequence number, job start date, and job end date fields.
+// FIXME: Add current EVIO event number, current event sequence number, job start date, 
+// and job end date fields.
 public class RunPanel extends JPanel implements PropertyChangeListener {
 
     FieldPanel runNumberField = new FieldPanel("Run Number", "", 10, false);

java/trunk/monitoring-app/src/main/java/org/hps/monitoring/record
AbstractRecordQueue.java 850 -> 851
--- java/trunk/monitoring-app/src/main/java/org/hps/monitoring/record/AbstractRecordQueue.java	2014-08-14 00:04:53 UTC (rev 850)
+++ java/trunk/monitoring-app/src/main/java/org/hps/monitoring/record/AbstractRecordQueue.java	2014-08-14 00:21:22 UTC (rev 851)
@@ -112,7 +112,8 @@
             throw new NoSuchRecordException("No records in queue.");
         }
     }
-    
+   
+    @Override
     public long size() {
         return records.size();
     }

java/trunk/monitoring-app/src/main/java/org/hps/monitoring/record
EndRunException.java added at 851
--- java/trunk/monitoring-app/src/main/java/org/hps/monitoring/record/EndRunException.java	                        (rev 0)
+++ java/trunk/monitoring-app/src/main/java/org/hps/monitoring/record/EndRunException.java	2014-08-14 00:21:22 UTC (rev 851)
@@ -0,0 +1,12 @@
+package org.hps.monitoring.record;
+
+import java.io.IOException;
+
+/**
+ * An Exception thrown when an end run occurs.
+ */
+class EndRunException extends IOException {
+    EndRunException(String message) {
+        super(message);
+    }
+}

java/trunk/monitoring-app/src/main/java/org/hps/monitoring/record
EndRunProcessor.java added at 851
--- java/trunk/monitoring-app/src/main/java/org/hps/monitoring/record/EndRunProcessor.java	                        (rev 0)
+++ java/trunk/monitoring-app/src/main/java/org/hps/monitoring/record/EndRunProcessor.java	2014-08-14 00:21:22 UTC (rev 851)
@@ -0,0 +1,21 @@
+package org.hps.monitoring.record;
+
+import org.hps.evio.EventConstants;
+import org.hps.monitoring.record.composite.CompositeRecord;
+import org.hps.monitoring.record.composite.CompositeRecordProcessor;
+
+/**
+ * This is a CompositeRecordProcessor for ending the run when an EVIO
+ * end event is received.  It should be placed last in the chain of
+ * processors so that all the other registered processors are executed
+ * beforehand because it throws an Exception.
+ */
+public class EndRunProcessor extends CompositeRecordProcessor {
+    
+    @Override
+    public void processEvent(CompositeRecord event) throws EndRunException {
+        if (event.getEvioEvent() != null)
+            if (EventConstants.isEndEvent(event.getEvioEvent()))
+                throw new EndRunException("EVIO end event received.");
+    }
+}

java/trunk/monitoring-app/src/main/java/org/hps/monitoring/record
EtProcessingStep.java 850 -> 851
--- java/trunk/monitoring-app/src/main/java/org/hps/monitoring/record/EtProcessingStep.java	2014-08-14 00:04:53 UTC (rev 850)
+++ java/trunk/monitoring-app/src/main/java/org/hps/monitoring/record/EtProcessingStep.java	2014-08-14 00:21:22 UTC (rev 851)
@@ -47,6 +47,7 @@
      }
     
     public void endJob() {
+        System.out.println("EtProcessingStep.endJob");
         loop.execute(Command.STOP);
-    }
+    }        
 }
\ No newline at end of file

java/trunk/monitoring-app/src/main/java/org/hps/monitoring/record
EventProcessingChain.java 850 -> 851
--- java/trunk/monitoring-app/src/main/java/org/hps/monitoring/record/EventProcessingChain.java	2014-08-14 00:04:53 UTC (rev 850)
+++ java/trunk/monitoring-app/src/main/java/org/hps/monitoring/record/EventProcessingChain.java	2014-08-14 00:21:22 UTC (rev 851)
@@ -1,16 +1,15 @@
 package org.hps.monitoring.record;
 
+import java.io.File;
 import java.io.IOException;
-import java.util.Collection;
 
 import org.freehep.record.loop.AbstractLoopListener;
 import org.freehep.record.loop.LoopEvent;
+import org.freehep.record.loop.LoopListener;
 import org.freehep.record.loop.RecordLoop.Command;
-import org.freehep.record.loop.RecordLoop.State;
-import org.freehep.record.source.RecordSource;
-import org.hps.evio.LCSimEventBuilder;
 import org.hps.monitoring.enums.DataSourceType;
 import org.hps.monitoring.record.composite.CompositeRecordLoop;
+import org.hps.monitoring.record.composite.CompositeRecordLoopAdapter;
 import org.hps.monitoring.record.composite.CompositeRecordProcessor;
 import org.hps.monitoring.record.etevent.EtEventProcessor;
 import org.hps.monitoring.record.etevent.EtEventSource;
@@ -26,7 +25,8 @@
  * for the monitoring app.  Implementations of FreeHep's <tt>RecordLoop</tt> 
  * are chained together via a <tt>CompositeRecordLoop</tt>.  The processing for 
  * each record type is done by activating registered processors on their
- * individual loop implementations.
+ * individual loop implementations.  Essentially, the class is a facade that
+ * hides the complexity of configuring all the different record loops.
  * 
  * The processing chain can be configured to execute the ET, EVIO event building,
  * or LCIO event building stages.  The source can be set to an ET ring,
@@ -34,10 +34,6 @@
  * can be registered with the three different loops for processing the different 
  * record types, in order to plot, update a GUI component, or analyze the events.
  */
-// FIXME: Adding of CompositeRecordProcessors has to happen after setup is called because
-// otherwise the CompositeRecord doesn't have the references to EVIO, etc.  Instead the 
-// additional CompositeRecordProcessors should be stored in a separate list and added
-// automatically after the standard event processing chain is setup.
 public class EventProcessingChain extends AbstractLoopListener {
              
     /**
@@ -49,58 +45,85 @@
         LCIO
     }
     
-    private DataSourceType sourceType = DataSourceType.ET_SERVER;
-    private ProcessingStage processingStage = ProcessingStage.LCIO;    
-    private RecordSource recordSource;
-    private LCSimEventBuilder eventBuilder;
-    private int totalEventsProcessed;
-    private String detectorName;
-    private Throwable lastError;
-    private boolean done;
-    private boolean paused;
-    private boolean wasSetup;
-    private boolean stopOnErrors = true;
+    protected int totalEventsProcessed;
+    protected Throwable lastError;
+    protected boolean done;
+    protected boolean paused;
     
-    private EtProcessingStep etStep = new EtProcessingStep();
-    private EvioProcessingStep evioStep = new EvioProcessingStep();
-    private LcioProcessingStep lcioStep = new LcioProcessingStep();
-    private CompositeRecordLoop compositeLoop = new CompositeRecordLoop();
-            
+    protected EtProcessingStep etStep = new EtProcessingStep();
+    protected EvioProcessingStep evioStep = new EvioProcessingStep();
+    protected LcioProcessingStep lcioStep = new LcioProcessingStep();
+    protected CompositeRecordLoop compositeLoop = new CompositeRecordLoop();
+                  
     /**
-     * No argument constructor.  
-     * The setter methods should be used to configure this class.
+     * A configuration object must be supplied to use this class.
+     * @param configuration The configuration of the event processing.
      */
-    public EventProcessingChain() {  
+    public EventProcessingChain(EventProcessingConfiguration configuration) {                
+        configure(configuration);
     }
-            
-    /**
-     * Setup the event processing chain based on the current configuration.
-     */
-    public void setup() {
+
+    private void configure(EventProcessingConfiguration configuration) {
         
-        if (wasSetup) {
-            throw new RuntimeException("The EventProcessingChain was already setup.");
-        }
-        
         // Add this class as a loop listener.
         compositeLoop.addLoopListener(this);
         
-        // Record source must be set by here.
-        if (recordSource == null)
-            throw new RuntimeException("No record source was set.");
-        
-        // Using the ET server for events.
-        if (sourceType == DataSourceType.ET_SERVER) {
+        // Was there no RecordSource provided explicitly?
+        if (configuration.recordSource == null) {
+            // Using an ET server connection?
+            if (configuration.sourceType.equals(DataSourceType.ET_SERVER)) {
+                if (configuration.connection != null)
+                    etStep.getLoop().setRecordSource(new EtEventSource(configuration.connection));
+                else
+                    throw new IllegalArgumentException("Configuration is missing a valid ET connection.");
+            // Using an EVIO file?
+            } else if (configuration.sourceType.equals(DataSourceType.EVIO_FILE)) {
+                if (configuration.filePath != null)
+                    evioStep.getLoop().setRecordSource(new EvioFileSource(new File(configuration.filePath)));
+                else
+                    throw new IllegalArgumentException("Configuration is missing a file path.");
+            // Using an LCIO file?
+            } else if (configuration.sourceType.equals(DataSourceType.LCIO_FILE)) {
+                if (configuration.filePath != null)
+                    try {
+                        lcioStep.getLoop().setLCIORecordSource(new LCIOEventSource(new File(configuration.filePath)));
+                    } catch (IOException e) {
+                        throw new RuntimeException("Error configurating LCIOEventSource.", e);
+                    }
+                else
+                    throw new IllegalArgumentException("Configuration is missing a file path.");
+            }
+        } else {           
+            // User provided an EtEventSource?
+            if (configuration.recordSource instanceof EtEventSource) {
+                etStep.getLoop().setRecordSource((EtEventSource) configuration.recordSource);
+            // User provided an EvioFileSource?
+            } else if (configuration.recordSource instanceof EvioFileSource) {
+                evioStep.getLoop().setRecordSource((EvioFileSource) configuration.recordSource);
+            // User provided an LCIOEventSource?
+            } else if (configuration.recordSource instanceof LCIOEventSource) {
+                try {
+                    lcioStep.getLoop().setLCIORecordSource((LCIOEventSource)configuration.recordSource);
+                } catch (IOException e) {
+                    throw new RuntimeException("Error setting up LCIORecordSource.", e);
+                }
+            } else {
+                throw new IllegalArgumentException("Unknown RecordSource type was supplied.");
+            }
+        }
+                
+        // Using the ET server for events?
+        if (configuration.sourceType == DataSourceType.ET_SERVER) {
             // Add the ET event processing step.
             compositeLoop.addProcessor(etStep);
         }
    
-        // Building EVIO events.
-        if (processingStage.ordinal() >= ProcessingStage.EVIO.ordinal()) {
+        // Building EVIO events?
+        if (configuration.processingStage.ordinal() >= ProcessingStage.EVIO.ordinal()) {
             // Using EVIO event source.
-            if (sourceType.ordinal() <= DataSourceType.EVIO_FILE.ordinal()) {
+            if (configuration.sourceType.ordinal() <= DataSourceType.EVIO_FILE.ordinal()) {
                 // Using ET event source.
-                if (sourceType == DataSourceType.ET_SERVER) {
+                if (configuration.sourceType == DataSourceType.ET_SERVER) {
                     // Use dynamic event queue.
                     evioStep.setEvioEventQueue(new EvioEventQueue());
                 }
@@ -109,135 +132,56 @@
             }
         }
         
-        // Building LCIO events.
-        if (processingStage.ordinal() >= ProcessingStage.LCIO.ordinal()) {
+        // Building LCIO events?
+        if (configuration.processingStage.ordinal() >= ProcessingStage.LCIO.ordinal()) {
             // Set detector on event builder.
-            if (eventBuilder != null) 
-                eventBuilder.setDetectorName(detectorName);
-            if (sourceType.ordinal() != DataSourceType.LCIO_FILE.ordinal()) {
+            if (configuration.eventBuilder != null) 
+                configuration.eventBuilder.setDetectorName(configuration.detectorName);
+            else
+                throw new IllegalArgumentException("The eventBuilder was not set in the configuration.");
+            
+            if (configuration.sourceType.ordinal() != DataSourceType.LCIO_FILE.ordinal()) {
                 // Use dynamic event queue.
                 lcioStep.setLcioEventQueue(new LcioEventQueue());
             }
             // Set event builder.
-            lcioStep.setEventBuilder(eventBuilder);
+            lcioStep.setEventBuilder(configuration.eventBuilder);
+            
             // Add LCIO processing step.
             compositeLoop.addProcessor(lcioStep);
         }
         
-        compositeLoop.setStopOnErrors(stopOnErrors);
+        // Set whether to stop on event processing errors.
+        compositeLoop.setStopOnErrors(configuration.stopOnErrors);
         
-        wasSetup = true;
-    }
-    
-    /**
-     * Set the type of source being used.
-     * @param sourceType The type of source.
-     */
-    void setSourceType(DataSourceType sourceType) {
-        this.sourceType = sourceType;
-    }
+        // Add EtEventProcessors to loop.
+        for (EtEventProcessor processor : configuration.etProcessors) {
+            etStep.getLoop().addEtEventProcessor(processor);
+        }
         
-    /**
-     * Set the processing stages to execute.
-     * @param processingStage The processing stages to execute.
-     */
-    public void setProcessingStage(ProcessingStage processingStage) {
-        this.processingStage = processingStage;
-    }
-            
-    /**
-     * Set the event builder to be used for the EVIO to LCIO conversion.
-     * @param eventBuilder The event builder to use for EVIO to LCIO conversion.
-     */
-    public void setEventBuilder(LCSimEventBuilder eventBuilder) {
-        this.eventBuilder = eventBuilder;
-    }
-    
-    /**
-     * Set the record source.
-     * @param recordSource The record source.
-     */
-    public void setRecordSource(EtEventSource recordSource) {
-        this.recordSource = recordSource;
-        this.etStep.getLoop().setRecordSource(recordSource);
-        this.sourceType = DataSourceType.ET_SERVER;
-    }
-    
-    /**
-     * Set an EVIO event source.
-     * @param recordSource The EVIO event source.
-     */
-    public void setRecordSource(EvioFileSource recordSource) {
-        this.recordSource = recordSource;
-        evioStep.getLoop().setRecordSource(recordSource);
-        setSourceType(DataSourceType.EVIO_FILE);
-    }
-    
-    /**
-     * Set an LCIO event source.
-     * @param recordSource The LCIO event source.
-     */
-    public void setRecordSource(LCIOEventSource recordSource) {
-        this.recordSource = recordSource;
-        try {
-            lcioStep.getLoop().setLCIORecordSource(recordSource);
-        } catch (IOException e) {
-            throw new RuntimeException(e);
+        // Add EvioEventProcessors to loop.
+        for (EvioEventProcessor processor : configuration.evioProcessors) {
+            evioStep.getLoop().addEvioEventProcessor(processor);
         }
-        setSourceType(DataSourceType.LCIO_FILE);
-    }
-    
-    /**
-     * Add a driver to the LCIO loop.
-     * @param driver The Driver to add.
-     */
-    public void add(Driver driver) {
-        lcioStep.getLoop().add(driver);
-    }
-    
-    /**
-     * Add a list of <tt>Drivers</tt> to the LCIO loop.
-     * @param drivers The list of <tt>Drivers</tt> to add.
-     */
-    public void add(Collection<Driver> drivers) {
-        for (Driver driver : drivers) { 
+        
+        // Add Drivers to loop.
+        for (Driver driver : configuration.drivers) {
             lcioStep.getLoop().add(driver);
         }
+        
+        // Add CompositeRecordProcessors to loop.
+        for (CompositeRecordProcessor processor : configuration.compositeProcessors) {
+            compositeLoop.addProcessor(processor);
+        }
+
+        // Stop on end run?
+        if (configuration.stopOnEndRun) {
+            // Add the CompositeRecordProcessor that will throw the EndRunException.
+            compositeLoop.addProcessor(new EndRunProcessor());
+        }
     }
-    
+                                 
     /**
-     * Add a processor of ET events.
-     * @param processor The processor of ET events.
-     */
-    public void add(EtEventProcessor processor) {
-        etStep.getLoop().addEtEventProcessor(processor);
-    }
-    
-    /**
-     * Add a processor of EVIO events.
-     * @param processor The processor of EVIO events.
-     */
-    public void add(EvioEventProcessor processor) {
-        evioStep.getLoop().addEvioEventProcessor(processor);
-    }
-    
-    /**
-     * Add a processor of composite events.
-     * @param processor The processor of composite events.
-     */
-    public void add(CompositeRecordProcessor processor) {
-        compositeLoop.addProcessor(processor);
-    }
-    
-    /**
-     * Set the name of the detector model to use.
-     * @param detectorName The name of the detector model.
-     */
-    public void setDetectorName(String detectorName) {
-        this.detectorName = detectorName;
-    }
-                   
-    /**
      * Resume event processing from pause mode.
      */
     public void resume() {
@@ -264,10 +208,8 @@
             // Go into loop mode if the system is not paused.
             if (!paused) {
                 try {
-                    if (compositeLoop.getState() != State.IDLE)
-                        throw new IllegalLoopStateException(compositeLoop.getState());
                     compositeLoop.execute(Command.GO, true);
-                } catch (RuntimeException exception) {
+                } catch (Exception exception) {
                     setLastError(exception);
                 } 
                 
@@ -295,8 +237,6 @@
      * Pause the event processing.
      */
     public void pause() {
-        if (compositeLoop.getState() != State.LOOPING)
-            throw new IllegalLoopStateException(compositeLoop.getState());
         compositeLoop.execute(Command.PAUSE);
         paused = true;
     }
@@ -305,8 +245,14 @@
      * Finish the event processing.
      */
     public void finish() {
-        // TODO: Add check here for correct loop state.        
-        compositeLoop.execute(Command.STOP);    
+        compositeLoop.execute(Command.STOP);
+        
+        // FIXME: Ugly hack because Command.STOP doesn't activate the finish() method
+        // on the CompositeRecordLoopAdapter when errors occur.
+        for (LoopListener listener : compositeLoop.getLoopListeners()) {
+            if (listener instanceof CompositeRecordLoopAdapter)
+                ((CompositeRecordLoopAdapter)listener).finish(null);
+        }
         done = true;
     }    
         
@@ -314,8 +260,6 @@
      * Get the next event e.g. while in pause mode.
      */
     public void next() {
-        if (compositeLoop.getState() != State.READY)
-            throw new IllegalLoopStateException(compositeLoop.getState());
         compositeLoop.execute(Command.GO_N, 1L, true);
     }
             
@@ -325,26 +269,5 @@
      */
     public int getTotalEventsProcessed() {
         return this.totalEventsProcessed;
-    }
-    
-    /**
-     * Set whether processing will stop when errors occur.
-     * Only specific types of non-fatal errors are affected by this.
-     * For instance, <code>NoSuchRecordException</code> is never 
-     * ignored and always causes processing to stop.
-     * @param stopOnErrors True if processing should stop on errors. 
-     */
-    public void setStopOnErrors(boolean stopOnErrors) {
-        this.stopOnErrors = stopOnErrors;
-    }
-    
-    /**
-     * Exception thrown if the loop is not in the correct state
-     * when a certain method is called.
-     */
-    class IllegalLoopStateException extends RuntimeException {
-        IllegalLoopStateException(State state) {
-            super("Illegal loop state: " + state);
-        }
-    }
+    }           
 }
\ No newline at end of file

java/trunk/monitoring-app/src/main/java/org/hps/monitoring/record
EventProcessingConfiguration.java added at 851
--- java/trunk/monitoring-app/src/main/java/org/hps/monitoring/record/EventProcessingConfiguration.java	                        (rev 0)
+++ java/trunk/monitoring-app/src/main/java/org/hps/monitoring/record/EventProcessingConfiguration.java	2014-08-14 00:21:22 UTC (rev 851)
@@ -0,0 +1,92 @@
+package org.hps.monitoring.record;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.freehep.record.source.RecordSource;
+import org.hps.evio.LCSimEventBuilder;
+import org.hps.monitoring.enums.DataSourceType;
+import org.hps.monitoring.record.EventProcessingChain.ProcessingStage;
+import org.hps.monitoring.record.composite.CompositeRecordProcessor;
+import org.hps.monitoring.record.etevent.EtConnection;
+import org.hps.monitoring.record.etevent.EtEventProcessor;
+import org.hps.monitoring.record.evio.EvioEventProcessor;
+import org.lcsim.util.Driver;
+
+/**
+ * A configuration object for the {@link EventProcessingChain}.
+ * The instance variables are readable within this package, but
+ * must be set through the public set methods when used
+ * outside of it, e.g. from MonitoringApplication.
+ */
+public class EventProcessingConfiguration {
+        
+    boolean stopOnErrors = true;
+    boolean stopOnEndRun = true;
+
+    DataSourceType sourceType = DataSourceType.ET_SERVER;
+    ProcessingStage processingStage = ProcessingStage.LCIO;
+    
+    String filePath = null;
+    EtConnection connection = null;
+    RecordSource recordSource = null;
+    LCSimEventBuilder eventBuilder = null;
+    String detectorName = null;
+    
+    List<EvioEventProcessor> evioProcessors = new ArrayList<EvioEventProcessor>();
+    List<Driver> drivers = new ArrayList<Driver>();
+    List<CompositeRecordProcessor> compositeProcessors = new ArrayList<CompositeRecordProcessor>();
+    List<EtEventProcessor> etProcessors = new ArrayList<EtEventProcessor>();
+                 
+    public void setFilePath(String filePath) {
+        this.filePath = filePath;
+    }
+    
+    public void setEtConnection(EtConnection connection) {
+        this.connection = connection;
+    }
+    
+    public void setDataSourceType(DataSourceType sourceType) {
+        this.sourceType = sourceType;
+    }
+    
+    public void setProcessingStage(ProcessingStage processingStage) {
+        this.processingStage = processingStage;
+    }
+    
+    public void setRecordSource(RecordSource recordSource) {
+        this.recordSource = recordSource;
+    }
+    
+    public void setLCSimEventBuild(LCSimEventBuilder eventBuilder) {
+        this.eventBuilder = eventBuilder;
+    }
+    
+    public void setDetectorName(String detectorName) {
+        this.detectorName = detectorName;
+    }
+    
+    public void setStopOnErrors(boolean stopOnErrors) {
+        this.stopOnErrors = stopOnErrors;
+    }
+    
+    public void setStopOnEndRun(boolean stopOnEndRun) {
+        this.stopOnEndRun = stopOnEndRun;
+    }
+    
+    public void add(EtEventProcessor processor) {
+        etProcessors.add(processor);
+    }
+    
+    public void add(EvioEventProcessor processor) {
+        evioProcessors.add(processor);
+    }
+    
+    public void add(Driver processor) {
+        drivers.add(processor);
+    }
+    
+    public void add(CompositeRecordProcessor processor) {
+        compositeProcessors.add(processor);
+    }
+}

java/trunk/monitoring-app/src/main/java/org/hps/monitoring/record
EventProcessingThread.java 850 -> 851
--- java/trunk/monitoring-app/src/main/java/org/hps/monitoring/record/EventProcessingThread.java	2014-08-14 00:04:53 UTC (rev 850)
+++ java/trunk/monitoring-app/src/main/java/org/hps/monitoring/record/EventProcessingThread.java	2014-08-14 00:21:22 UTC (rev 851)
@@ -22,6 +22,6 @@
             processing.loop();
         } catch (Exception e) {
             throw new RuntimeException("Error in event processing.", e);
-        }
+        } 
     }
 }
\ No newline at end of file

java/trunk/monitoring-app/src/main/java/org/hps/monitoring/record
EvioProcessingStep.java 850 -> 851
--- java/trunk/monitoring-app/src/main/java/org/hps/monitoring/record/EvioProcessingStep.java	2014-08-14 00:04:53 UTC (rev 850)
+++ java/trunk/monitoring-app/src/main/java/org/hps/monitoring/record/EvioProcessingStep.java	2014-08-14 00:21:22 UTC (rev 851)
@@ -29,13 +29,6 @@
     DataSourceType sourceType;
     EvioEventQueue evioEventQueue;
     boolean stopOnEndRun;
-
-    // FIXME: Should this really be extending IOException?
-    class EndRunException extends IOException {
-        EndRunException(String message) {
-            super(message);
-        }
-    }
     
     /**
      * Get the <tt>EvioEventLoop</tt> associated with this processing step.
@@ -106,16 +99,9 @@
         if (nextEvioEvent == null)
             throw new NoSuchRecordException("No current EVIO event.");
         
+        // Update the CompositeRecord.
         record.setEvioEvent(nextEvioEvent);
         record.setEventNumber(nextEvioEvent.getEventNumber());
-        
-        // Encountered an end of run record.
-        if (EventConstants.isEndEvent(nextEvioEvent))
-            // If stop on end run is enabled, then trigger an exception to end processing.
-            if (stopOnEndRun)
-                throw new EndRunException("EVIO end event received, and stop on end run is enabled.");
-        
-        //System.out.println("done with EvioProcessingStep.processEvent");
     }
     
     /**

java/trunk/monitoring-app/src/main/java/org/hps/monitoring/record
LcioProcessingStep.java 850 -> 851
--- java/trunk/monitoring-app/src/main/java/org/hps/monitoring/record/LcioProcessingStep.java	2014-08-14 00:04:53 UTC (rev 850)
+++ java/trunk/monitoring-app/src/main/java/org/hps/monitoring/record/LcioProcessingStep.java	2014-08-14 00:21:22 UTC (rev 851)
@@ -84,28 +84,30 @@
                 // The LCIO processing ignores non-physics events coming from EVIO.
                 return;
             }
+        }
             
-            if (!loop.getRecordSource().hasNext())
-                throw new NoSuchRecordException("No next LCIO event.");
-        }
-                
+        // Is there a next record?
         if (!loop.getRecordSource().hasNext())
+            // The next record does not exist.
             throw new NoSuchRecordException("No next LCIO event.");
         
-        // Load the next LCIO event.
+        // Load the next LCIO event, triggering Driver process methods.
         loop.execute(NEXT);
-                      
-        // The last call to the loop did not create a current record.
+            
+        // Is there a current record?
         if (loop.getRecordSource().getCurrentRecord() == null) {
+            // The last call to the loop did not create a current record.
             throw new NoSuchRecordException("No current LCIO event.");
         }
         
         // Get the current LCIO event.
         EventHeader lcioEvent = (EventHeader) loop.getRecordSource().getCurrentRecord();
                 
-        // Update the CompositeRecord with reference to the LCIO event.
+        // Update the CompositeRecord with reference to the LCIO event.
         record.setLcioEvent(lcioEvent);
+        // Was there an EVIO event set?
         if (record.getEvioEvent() == null) {
+            // Set event number from LCIO if no EVIO event was set.
             record.setEventNumber(lcioEvent.getEventNumber());
         }
     }

java/trunk/monitoring-app/src/main/java/org/hps/monitoring/record/composite
CompositeRecordLoop.java 850 -> 851
--- java/trunk/monitoring-app/src/main/java/org/hps/monitoring/record/composite/CompositeRecordLoop.java	2014-08-14 00:04:53 UTC (rev 850)
+++ java/trunk/monitoring-app/src/main/java/org/hps/monitoring/record/composite/CompositeRecordLoop.java	2014-08-14 00:21:22 UTC (rev 851)
@@ -45,10 +45,11 @@
     
     protected void handleClientError(Throwable x) {
         if (stopOnErrors || x instanceof NoSuchRecordException) {
+            //this.execute(Command.STOP);
             throw new RuntimeException("Error during event processing.", x);
         } else {
             x.printStackTrace();
-        }        
+        }                
     }
 
     protected void handleSourceError(Throwable x) {

java/trunk/monitoring-app/src/main/java/org/hps/monitoring/record/composite
CompositeRecordLoopAdapter.java 850 -> 851
--- java/trunk/monitoring-app/src/main/java/org/hps/monitoring/record/composite/CompositeRecordLoopAdapter.java	2014-08-14 00:04:53 UTC (rev 850)
+++ java/trunk/monitoring-app/src/main/java/org/hps/monitoring/record/composite/CompositeRecordLoopAdapter.java	2014-08-14 00:21:22 UTC (rev 851)
@@ -20,7 +20,6 @@
      * @param loopEvent 
      */
     public void finish(LoopEvent loopEvent) {
-        System.out.println("CompositeRecordLoopAdapter.finish");
         for (CompositeRecordProcessor processor : processors) {
             // Call end job hook on all registered processors, which are 
             // responsible for sending the stop command to their loops.
@@ -52,9 +51,9 @@
      * @param loopEvent
      */
     public void suspend(LoopEvent loopEvent) { 
-        if (loopEvent.getException() != null) {
-            throw new RuntimeException("Error in event processing.", loopEvent.getException());
-        }
+        //if (loopEvent.getException() != null) {
+        //    throw new RuntimeException("Error in event processing.", loopEvent.getException());
+        //}
     }
 
     /**

java/trunk/monitoring-app/src/main/java/org/hps/monitoring/record/etevent
EtConnection.java 850 -> 851
--- java/trunk/monitoring-app/src/main/java/org/hps/monitoring/record/etevent/EtConnection.java	2014-08-14 00:04:53 UTC (rev 850)
+++ java/trunk/monitoring-app/src/main/java/org/hps/monitoring/record/etevent/EtConnection.java	2014-08-14 00:21:22 UTC (rev 851)
@@ -70,8 +70,8 @@
      * Get the ET station. 
      * @return The ET station.
      */
-    public EtStation getEtStation() {
-        return stat;
+    public EtStation getEtStation() {              
+        return stat;        
     }
     
     /**

java/trunk/monitoring-app/src/test/java/org/hps/monitoring/record
EventProcessingChainTest.java 850 -> 851
--- java/trunk/monitoring-app/src/test/java/org/hps/monitoring/record/EventProcessingChainTest.java	2014-08-14 00:04:53 UTC (rev 850)
+++ java/trunk/monitoring-app/src/test/java/org/hps/monitoring/record/EventProcessingChainTest.java	2014-08-14 00:21:22 UTC (rev 851)
@@ -1,17 +1,12 @@
 package org.hps.monitoring.record;
 
-import java.io.File;
-import java.io.IOException;
-
 import org.hps.evio.LCSimTestRunEventBuilder;
-import org.hps.monitoring.record.etevent.EtEventSource;
+import org.hps.monitoring.enums.DataSourceType;
 import org.hps.monitoring.record.evio.EvioEventProcessor;
-import org.hps.monitoring.record.evio.EvioFileSource;
 import org.jlab.coda.jevio.EvioEvent;
 import org.lcsim.event.EventHeader;
 import org.lcsim.event.EventHeader.LCMetaData;
 import org.lcsim.util.Driver;
-import org.lcsim.util.loop.LCIOEventSource;
 
 public class EventProcessingChainTest {
     
@@ -37,13 +32,15 @@
     */
     
     public void testEvioFile() {
-        EventProcessingChain processing = new EventProcessingChain();
-        processing.setRecordSource(new EvioFileSource(new File(evioFilePath)));
-        processing.setEventBuilder(new LCSimTestRunEventBuilder());
-        processing.setDetectorName(detectorName);
-        processing.add(new DummyEvioProcessor());
-        processing.add(new DummyDriver());
-        processing.setup();
+        
+        EventProcessingConfiguration config = new EventProcessingConfiguration();
+        config.setDataSourceType(DataSourceType.EVIO_FILE);
+        config.setFilePath(evioFilePath);
+        config.setLCSimEventBuild(new LCSimTestRunEventBuilder());
+        config.setDetectorName(detectorName);
+        config.add(new DummyEvioProcessor());
+        config.add(new DummyDriver());     
+        EventProcessingChain processing = new EventProcessingChain(config);
         processing.loop();
     }
     

java/trunk/monitoring-app/src/test/java/org/hps/monitoring/record
EvioEventProcessingTest.java 850 -> 851
--- java/trunk/monitoring-app/src/test/java/org/hps/monitoring/record/EvioEventProcessingTest.java	2014-08-14 00:04:53 UTC (rev 850)
+++ java/trunk/monitoring-app/src/test/java/org/hps/monitoring/record/EvioEventProcessingTest.java	2014-08-14 00:21:22 UTC (rev 851)
@@ -1,32 +1,29 @@
 package org.hps.monitoring.record;
 
-import java.io.File;
-
 import org.hps.evio.LCSimTestRunEventBuilder;
+import org.hps.monitoring.enums.DataSourceType;
 import org.hps.monitoring.record.evio.EvioEventProcessor;
-import org.hps.monitoring.record.evio.EvioFileSource;
 import org.jlab.coda.jevio.EvioEvent;
 import org.lcsim.event.EventHeader;
 import org.lcsim.event.EventHeader.LCMetaData;
 import org.lcsim.geometry.Detector;
 import org.lcsim.util.Driver;
 
-
 public class EvioEventProcessingTest {
     
     static String evioFilePath = "/nfs/slac/g/hps3/data/testrun/runs/evio/hps_001351.evio.0";   
     static String detectorName = "HPS-TestRun-v8-5";
          
-    public void testEvioFile() {
-        EventProcessingChain processing = new EventProcessingChain();
-        processing.setRecordSource(new EvioFileSource(new File(evioFilePath)));
-        processing.setEventBuilder(new LCSimTestRunEventBuilder());
-        processing.setDetectorName(detectorName);
-        processing.add(new DummyEvioProcessor());
-        processing.add(new DummyDriver());
-        processing.setup();
+    public void testEvioFile() {        
+        EventProcessingConfiguration config = new EventProcessingConfiguration();
+        config.setDataSourceType(DataSourceType.EVIO_FILE);
+        config.setFilePath(evioFilePath);
+        config.setLCSimEventBuild(new LCSimTestRunEventBuilder());
+        config.setDetectorName(detectorName);
+        config.add(new DummyEvioProcessor());
+        config.add(new DummyDriver());
+        EventProcessingChain processing = new EventProcessingChain(config);
         processing.loop();
-        processing.finish();
     }
         
     static class DummyDriver extends Driver {
SVNspam 0.1