Print

Print


Commit in java/trunk/record-util/src/main/java/org/hps/record on MAIN
AbstractRecordQueue.java+11-12986 -> 987
composite/CompositeLoop.java+8-1986 -> 987
         /CompositeLoopConfiguration.java+37-1986 -> 987
         /EventProcessingThread.java+4986 -> 987
         /LcioEventSupplier.java+37added 987
lcio/LcioEventQueue.java+47added 987
+144-14
2 added + 4 modified, total 6 files
Add config for supplying events to JAS3 from the CompositeLoop.  This allows Wired to receive events created from the ET ring (and there was much rejoicing).

java/trunk/record-util/src/main/java/org/hps/record
AbstractRecordQueue.java 986 -> 987
--- java/trunk/record-util/src/main/java/org/hps/record/AbstractRecordQueue.java	2014-09-11 01:14:18 UTC (rev 986)
+++ java/trunk/record-util/src/main/java/org/hps/record/AbstractRecordQueue.java	2014-09-11 01:20:23 UTC (rev 987)
@@ -14,42 +14,41 @@
  * {@link #next()} method to get the next record, which might not be immediately
  * available.
  */
+// TODO: Add max elements argument to limit pile up of unconsumed events.
 public abstract class AbstractRecordQueue<RecordType> extends AbstractRecordSource {
 
     // The queue, which is a linked list with blocking behavior. 
-    BlockingQueue<RecordType> records = new LinkedBlockingQueue<RecordType>();
+    BlockingQueue<RecordType> records;
     
     // The current LCIO events.
     RecordType currentRecord;
     
     // The amount of time to wait for an LCIO event from the queue before dying.
-    long timeOutMillis = 1000;
+    long timeOutMillis = -1;
     
     /**
      * Constructor that takes the timeout time in seconds.
      * @param timeoutSeconds the timeout time in seconds
      */
-    public AbstractRecordQueue(long timeoutMillis) {
+    public AbstractRecordQueue(long timeoutMillis, int maxSize) {
         this.timeOutMillis = timeoutMillis;
+        records = new LinkedBlockingQueue<RecordType>(maxSize);
     }
     
     public AbstractRecordQueue() {
+        // Unlimited queue size.
+        records = new LinkedBlockingQueue<RecordType>();
     }
     
     /**
-     * Set the time wait time before the poll call times out.
-     * @param timeoutMillis
-     */
-    public void setTimeOutMillis(long timeoutMillis) {
-        this.timeOutMillis = timeoutMillis;
-    }
-    
-    /**
      * Add a record to the queue.
+     * If the queue is full, then drain it first.
      * @param event the LCIO event to add
      */
     public void addRecord(RecordType record) {
-        records.add(record);
+        if (records.remainingCapacity() > 0)
+            records.add(record);
+        // TODO: Maybe automatically drain the queue here if at capacity???
     }
   
     @Override

java/trunk/record-util/src/main/java/org/hps/record/composite
CompositeLoop.java 986 -> 987
--- java/trunk/record-util/src/main/java/org/hps/record/composite/CompositeLoop.java	2014-09-11 01:14:18 UTC (rev 986)
+++ java/trunk/record-util/src/main/java/org/hps/record/composite/CompositeLoop.java	2014-09-11 01:20:23 UTC (rev 987)
@@ -36,6 +36,9 @@
     boolean done = false;
     
     CompositeLoopConfiguration config = null;
+            
+    // Look in javadoc API and DefaultRecordLoop for what this does.
+    //this._stopOnEOF
                 
     /**
      * No argument constructor.  
@@ -72,7 +75,7 @@
      */
     public void addAdapter(CompositeLoopAdapter adapter) {
         addLoopListener(adapter);
-        addRecordListener(adapter);
+        addRecordListener(adapter);        
     }
         
     /**
@@ -340,6 +343,10 @@
             compositeAdapter.addProcessor(processor);
         }
         
+        if (config.supplyLcioEvents) {
+            addAdapter(new LcioEventSupplier(config.timeout, config.maxQueueSize));
+        }
+        
         // Max records was set?
         if (config.maxRecords != -1) {            
             compositeAdapter.addProcessor(new MaxRecordsProcessor(config.maxRecords));

java/trunk/record-util/src/main/java/org/hps/record/composite
CompositeLoopConfiguration.java 986 -> 987
--- java/trunk/record-util/src/main/java/org/hps/record/composite/CompositeLoopConfiguration.java	2014-09-11 01:14:18 UTC (rev 986)
+++ java/trunk/record-util/src/main/java/org/hps/record/composite/CompositeLoopConfiguration.java	2014-09-11 01:20:23 UTC (rev 987)
@@ -5,7 +5,6 @@
 
 import org.freehep.record.source.RecordSource;
 import org.hps.evio.LCSimEventBuilder;
-import org.hps.record.composite.CompositeRecordProcessor;
 import org.hps.record.enums.DataSourceType;
 import org.hps.record.enums.ProcessingStage;
 import org.hps.record.et.EtConnection;
@@ -41,10 +40,16 @@
     LCSimEventBuilder eventBuilder = null;
     String detectorName = null;
     
+    // Event processors.
     List<EvioEventProcessor> evioProcessors = new ArrayList<EvioEventProcessor>();
     List<Driver> drivers = new ArrayList<Driver>();
     List<CompositeRecordProcessor> compositeProcessors = new ArrayList<CompositeRecordProcessor>();
     List<EtEventProcessor> etProcessors = new ArrayList<EtEventProcessor>();
+    
+    // Configuration for supplying LCIO events to JAS3 Studio.
+    boolean supplyLcioEvents;
+    int maxQueueSize = -1;
+    long timeout = -1L;
                      
     /**
      * Set the full path to a file being used as an event source.
@@ -160,6 +165,37 @@
     }
     
     /**
+     * Set whether to supply LCIO events to a DataSource that will automatically
+     * register itself to JAS3 in order to drive Wired, the LCSim Event Browser, etc. 
+     * @param supplyLcioEvents True to supply LCIO events to JAS3.
+     * @return This object.
+     */
+    public CompositeLoopConfiguration setSupplyLcioEvents(boolean supplyLcioEvents) {
+        this.supplyLcioEvents = supplyLcioEvents;
+        return this;
+    }
+    
+    /**
+     * Set the max queue size for the LCIO DataSource that hooks into JAS3.
+     * @param maxQueueSize The maximum queue size or -1 for unlimited.
+     * @return This object.
+     */
+    public CompositeLoopConfiguration setMaxQueueSize(int maxQueueSize) {
+        this.maxQueueSize = maxQueueSize;
+        return this;
+    }
+    
+    /**
+     * Set the timeout for calling <code>next</code> on the LCIO record queue.
+     * @param timeout The timeout in milliseconds.
+     * @return This object.
+     */
+    public CompositeLoopConfiguration setTimeout(long timeout) {
+        this.timeout = timeout;
+        return this;
+    }
+    
+    /**
      * Add an {@link org.hps.record.et.EtEventProcessor} to the loop.
      * @param processor The EtEventProcessor.
      * @return This object.

java/trunk/record-util/src/main/java/org/hps/record/composite
EventProcessingThread.java 986 -> 987
--- java/trunk/record-util/src/main/java/org/hps/record/composite/EventProcessingThread.java	2014-09-11 01:14:18 UTC (rev 986)
+++ java/trunk/record-util/src/main/java/org/hps/record/composite/EventProcessingThread.java	2014-09-11 01:20:23 UTC (rev 987)
@@ -25,13 +25,17 @@
         // Keep looping until the event processing is flagged as done.
         while (true) {
             // Is the processing unpaused?            
+            // TODO: See if can check for IDLE state. (???)
             if (!loop.isPaused()) {
                 
                 // Loop until done, error occurs, or pause is requested.
                 // FIXME: The maximum number of records should be used here.
                 loop.loop(-1);
                 
+                // If paused, current record will still be completed!
+                
                 // Is loop done?
+                // TODO: See if can check for IDLE state instead.
                 if (loop.isDone()) {
                     // Stop record processing.
                     break;

java/trunk/record-util/src/main/java/org/hps/record/composite
LcioEventSupplier.java added at 987
--- java/trunk/record-util/src/main/java/org/hps/record/composite/LcioEventSupplier.java	                        (rev 0)
+++ java/trunk/record-util/src/main/java/org/hps/record/composite/LcioEventSupplier.java	2014-09-11 01:20:23 UTC (rev 987)
@@ -0,0 +1,37 @@
+package org.hps.record.composite;
+
+import org.freehep.application.studio.Studio;
+import org.freehep.record.loop.RecordEvent;
+import org.hps.record.lcio.LcioEventQueue;
+
+/**
+ * This adapter can be used to supply LCIO EventHeader objects to JAS3
+ * via a DataSource in order to drive Wired, etc.
+ * 
+ * @author Jeremy McCormick <[log in to unmask]>
+ */
+public class LcioEventSupplier extends CompositeLoopAdapter {
+    
+    LcioEventQueue events;
+    
+    LcioEventSupplier(long timeoutMillis, int maxSize) {
+        events = new LcioEventQueue(timeoutMillis, maxSize);
+        events.setName(LcioEventSupplier.class.getName());
+        Studio studio = (Studio)Studio.getApplication(); 
+        if (studio != null) {
+            studio.getLookup().add(events);
+        }
+    }
+          
+    public void recordSupplied(RecordEvent record) {
+        CompositeRecord compositeRecord = (CompositeRecord) record.getRecord();
+        if (compositeRecord.getLcioEvent() != null) {
+            System.out.println("LcioEventSupplier - adding event #" + compositeRecord.getLcioEvent().getEventNumber() + " to queue");
+            events.addRecord(compositeRecord.getLcioEvent());
+        }
+    }
+    
+    public LcioEventQueue getLcioEventQueue() {
+        return events;
+    }
+}

java/trunk/record-util/src/main/java/org/hps/record/lcio
LcioEventQueue.java added at 987
--- java/trunk/record-util/src/main/java/org/hps/record/lcio/LcioEventQueue.java	                        (rev 0)
+++ java/trunk/record-util/src/main/java/org/hps/record/lcio/LcioEventQueue.java	2014-09-11 01:20:23 UTC (rev 987)
@@ -0,0 +1,47 @@
+package org.hps.record.lcio;
+
+import org.hps.record.AbstractRecordQueue;
+import org.lcsim.event.EventHeader;
+
+public class LcioEventQueue extends AbstractRecordQueue<EventHeader> {    
+    
+    public LcioEventQueue(long timeoutMillis, int maxQueueSize) {
+        super(timeoutMillis, maxQueueSize);
+    }
+    
+    public Class<?> getRecordClass() {
+        return EventHeader.class;
+    }
+    
+    public boolean supportsCurrent() {
+        return true;
+    }
+
+    public boolean supportsNext() {
+        return true;
+    }
+    
+    public boolean supportsPrevious() {
+        return false;
+    }
+    
+    public boolean supportsIndex() {
+        return false;
+    }
+    
+    public boolean supportsShift() {
+        return false;
+    }
+    
+    public boolean supportsRewind() {
+        return false;
+    }
+    
+    public boolean hasCurrent() {
+        return this.size() != 0L;
+    }
+
+    public boolean hasNext() {
+        return true;
+    }      
+}
SVNspam 0.1