Commit in lcsim/src/org/lcsim/util on MAIN
Driver.java+56-51.8 -> 1.9
DriverAdapter.java+10-21.2 -> 1.3
+66-7
2 modified files
Add support for aborting current event
Improve Javadoc

lcsim/src/org/lcsim/util
Driver.java 1.8 -> 1.9
diff -u -r1.8 -r1.9
--- Driver.java	18 Jul 2005 19:18:28 -0000	1.8
+++ Driver.java	8 Nov 2005 16:49:39 -0000	1.9
@@ -11,9 +11,12 @@
  * A driver is a steering routine which can deal with event processing, and/or
  * call any number of child drivers. When used as a child driver all parameters such as
  * histogramLevel and logger are inherited from the parent driver.
- *
+ * <p>
  * It also allows controlling the histogram level of the processors being called
  * and handles coordination of random numbers between Monte Carlo processors.
+ *
+ * @author Tony Johnson
+ * @version $Id: Driver.java,v 1.9 2005/11/08 16:49:39 tonyj Exp $
  */
 
 public class Driver
@@ -26,7 +29,7 @@
    private Random random;
    
    /**
-    * Add a sub-Driver to this Driver. sub-drivers are automatically
+    * Add a sub-Driver to this Driver. Sub-drivers are automatically
     * called from the process method.
     * @param driver The Driver to be added
     */
@@ -36,9 +39,9 @@
       driver.parent = this;
    }
    /**
-    * Removes a Processor from this Driver
-    * @param driver The Driver to be removed
-    */
+     * Removes a sub-Driver from this Driver
+     * @param driver The Driver to be removed
+     */
    public void remove(Driver driver)
    {
       drivers.remove(driver);
@@ -85,6 +88,9 @@
       return parent.getConditionsManager();
    }
    
+    /**
+     * Called by the framework when event processing is suspended.
+     */
    protected void suspend()
    {
       for (int i=0; i<drivers.size(); i++)
@@ -92,6 +98,9 @@
          ((Driver) drivers.get(i)).suspend();
       }      
    }
+    /**
+     * Called by the framework when event processing is resumed.
+     */
    protected void resume()
    {
       for (int i=0; i<drivers.size(); i++)
@@ -99,6 +108,9 @@
          ((Driver) drivers.get(i)).resume();
       }       
    }
+    /**
+     * Called when all data processing is finished.
+     */
    protected void endOfData()
    {
       for (int i=0; i<drivers.size(); i++)
@@ -106,6 +118,9 @@
          ((Driver) drivers.get(i)).endOfData();
       }       
    }
+    /**
+     * Called before the first event is processed, or after a rewind.
+     */
    protected void startOfData()
    {
       for (int i=0; i<drivers.size(); i++)
@@ -113,6 +128,19 @@
          ((Driver) drivers.get(i)).startOfData();
       }   
    }
+   /**
+     * Called by the framework to process an event. Don't forget to call
+     * <code>super.process(event)</code> to cause the child processes to 
+     * be executed. In addition the process event can call throw some special
+     * exceptions:
+     * <ul>
+     * <li>NextEventException - aborts further processing of this event</li>
+     * <li>StopRunException - causes event processing to be stopped</li>
+     * </ul>
+     * @param event The event to be processed
+     * @see Driver.NextEventException
+     * @see Driver.AbortRunException
+     */
    protected void process(EventHeader event)
    {
       processChildren(event);
@@ -155,4 +183,27 @@
          return ConditionsManager.defaultInstance();
       }
    }
+   /**
+    * If thrown during the process method of a driver, causes 
+    * processing of the current event to be aborted. Event procssing skips 
+    * immediately to the next event.
+    */
+   public static class NextEventException extends RuntimeException
+   {
+      public NextEventException()
+      {
+         super("Next Event");
+      }
+   }
+   /**
+    * If thrown during the process method of a driver, causes 
+    * processing of events to be aborted.
+    */
+   public static class AbortRunException extends RuntimeException
+   {
+      public AbortRunException()
+      {
+         super("Abort Run");
+      }
+   }
 }
\ No newline at end of file

lcsim/src/org/lcsim/util
DriverAdapter.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- DriverAdapter.java	3 May 2005 02:04:40 -0000	1.2
+++ DriverAdapter.java	8 Nov 2005 16:49:39 -0000	1.3
@@ -10,6 +10,7 @@
 /**
  * Drive a Driver from a Record loop
  * @author Tony Johnson
+ * @version $Id: DriverAdapter.java,v 1.3 2005/11/08 16:49:39 tonyj Exp $
  */
 public class DriverAdapter extends RecordAdapter
 {
@@ -36,8 +37,15 @@
 
    public void recordSupplied(RecordSuppliedEvent rse)
    {
-      Object event = rse.getRecord();
-      if (event instanceof EventHeader) driver.process((EventHeader) event);
+      try
+      {
+         Object event = rse.getRecord();
+         if (event instanceof EventHeader) driver.process((EventHeader) event);
+      }
+      catch (Driver.NextEventException x)
+      {
+         // OK, just continue with next event.
+      }
    }
 
    public void configure(ConfigurationEvent event)
CVSspam 0.2.8