Commit in hps-java/src/main on MAIN
java/org/lcsim/hps/evio/LCSimEventBuilder.java+255added 1.1
                       /EvioConsumer.java+168-4621.10 -> 1.11
                       /MCRawDataToEvio4Converter.java+60-161.1 -> 1.2
java/org/lcsim/hps/monitoring/ConnectionParameters.java+128added 1.1
java/org/lcsim/hps/recon/tracking/TrackerHitDriver.java+21-121.1 -> 1.2
                                 /TrackerReconDriver.java+2-31.13 -> 1.14
resources/org/lcsim/hps/steering/EtTest.lcsim+9-181.1 -> 1.2
+643-511
2 added + 5 modified, total 7 files
current working copies

hps-java/src/main/java/org/lcsim/hps/evio
LCSimEventBuilder.java added at 1.1
diff -N LCSimEventBuilder.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ LCSimEventBuilder.java	22 Mar 2012 02:21:16 -0000	1.1
@@ -0,0 +1,255 @@
+package org.lcsim.hps.evio;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jlab.coda.jevio.BaseStructure;
+import org.jlab.coda.jevio.BaseStructureHeader;
+import org.jlab.coda.jevio.CompositeData;
+import org.jlab.coda.jevio.EvioEvent;
+import org.jlab.coda.jevio.EvioException;
+import org.lcsim.detector.DetectorElementStore;
+import org.lcsim.detector.IDetectorElement;
+import org.lcsim.detector.identifier.IExpandedIdentifier;
+import org.lcsim.detector.identifier.IIdentifier;
+import org.lcsim.detector.identifier.IIdentifierDictionary;
+import org.lcsim.detector.tracker.silicon.SiSensor;
+import org.lcsim.event.EventHeader;
+import org.lcsim.event.RawCalorimeterHit;
+import org.lcsim.event.RawTrackerHit;
+import org.lcsim.event.base.BaseLCSimEvent;
+import org.lcsim.event.base.BaseRawCalorimeterHit;
+import org.lcsim.event.base.BaseRawTrackerHit;
+import org.lcsim.geometry.Detector;
+import org.lcsim.geometry.Subdetector;
+import org.lcsim.geometry.subdetector.HPSEcal3;
+import org.lcsim.geometry.subdetector.HPSTracker;
+import org.lcsim.util.lcio.LCIOConstants;
+
+/**
+ * Build LCSim events from EVIO data.
+ * 
+ * @author Jeremy McCormick <[log in to unmask]>
+ *
+ */
+public class LCSimEventBuilder {
+    
+    // Name of SVT detector.
+    //private String trackerName = "Tracker";
+    //private String calorimeterName = "Ecal";
+    private String trackerName;
+    private String calorimeterName;
+    
+    // Names of raw data collections with defaults.
+    private String rawTrackerHitCollectionName = "RawTrackerHitMaker_RawTrackerHits";
+    private String rawCalorimeterHitCollectionName = "EcalRawHits";
+    
+    // Names of readouts with defaults.
+    //private String trackerReadoutName = "TrackerHits";
+    //private String ecalReadoutName = "EcalHits";
+    
+    // Detector conditions.
+    private Detector detector;
+    //private String detectorName;
+    
+    private boolean debug = false;
+       
+    LCSimEventBuilder(String detectorName) {
+        
+        // Make a dummy event to setup conditions system.
+        EventHeader dummyEvent = new BaseLCSimEvent(0, 0, detectorName);
+        detector = dummyEvent.getDetector();
+        
+        // Set default detector names based on HPS detector types.
+        for (Subdetector subdet : detector.getSubdetectorList()) {
+            if (subdet instanceof HPSTracker) {
+                trackerName = subdet.getName();
+                System.out.println("trackerName = " + trackerName);
+            } else if (subdet instanceof HPSEcal3) {
+                calorimeterName = subdet.getName();
+                System.out.println("calorimeterName = " + calorimeterName);
+            }
+        }
+    }
+    
+    public void setDebug(boolean debug) {
+        this.debug = debug;
+    }
+    
+    public String getRawTrackerHitCollectionName() {
+        return rawTrackerHitCollectionName;
+    }
+    
+    public void setRawTrackerHitCollectionName(String rawTrackerHitCollectionName) {
+        this.rawTrackerHitCollectionName = rawTrackerHitCollectionName;
+    }
+        
+    public String getRawCalorimeterHitCollectionName() {
+        return rawCalorimeterHitCollectionName;
+    }    
+    
+    public void setRawCalorimeterHitCollectionName(String rawCalorimeterHitCollectionName) {
+        this.rawCalorimeterHitCollectionName = rawCalorimeterHitCollectionName;
+    }
+    
+    public String getTrackerName() {
+        return trackerName;
+    }
+    
+    public void setTrackerName(String trackerName) {
+        this.trackerName = trackerName;        
+    }
+    
+    public String getTrackerReadoutName() {
+        return detector.getSubdetector(trackerName).getReadout().getName();
+    }
+                          
+    public String getCalorimeterName() {
+        return calorimeterName;
+    }
+    
+    public void setCalorimeterName(String calorimeterName) {
+        this.calorimeterName = calorimeterName;
+    }
+    
+    public String getCalorimeterReadoutName() {
+        return detector.getSubdetector(calorimeterName).getReadout().getName();
+    }
+        
+    public Detector getDetector() {
+        return detector;
+    }
+            
+    public EventHeader makeLCSimEvent(EvioEvent evioEvent) {
+        
+        // Make RawTrackerHit collection.
+        List<RawTrackerHit> rawTrackerHits = makeRawTrackerHits(evioEvent);
+       
+        // Make RawCalorimeterHit collection, combining top and bottom section of ECal into one list.
+        List<RawCalorimeterHit> rawCalorimeterHits = makeRawCalorimeterHits(evioEvent);
+                                                              
+        // Create a new LCSimEvent.
+        //EventHeader lcsimEvent = new BaseLCSimEvent(0, evioEvent.getHeader().getNumber(), detectorName);
+        EventHeader lcsimEvent = new BaseLCSimEvent(0, evioEvent.getHeader().getNumber(), detector.getDetectorName());
+        
+        // Add the hit collections.
+        lcsimEvent.put(rawTrackerHitCollectionName, rawTrackerHits, RawTrackerHit.class, (1 << LCIOConstants.TRAWBIT_ID1), getTrackerReadoutName());
+        lcsimEvent.put(rawCalorimeterHitCollectionName, rawCalorimeterHits, RawCalorimeterHit.class, 0, getCalorimeterReadoutName());
+        
+        return lcsimEvent;
+    }
+  
+
+    private List<RawTrackerHit> makeRawTrackerHits(EvioEvent event) {
+        List<RawTrackerHit> rawTrackerHits = null;
+        for (BaseStructure bank : event.getChildren()) {
+            if (bank.getHeader().getTag() == MCRawDataToEvio4Converter.trackerBankTag) {
+                //System.out.println("found SVT bank; tag = " + MCRawDataToEvio4Converter.trackerBankTag);
+                CompositeData cdata = null;
+                try {
+                    cdata = bank.getCompositeData();
+                }
+                catch (EvioException e) {
+                    throw new RuntimeException(e);
+                }
+                rawTrackerHits = makeRawTrackerHits(cdata); 
+            }
+        }
+        return rawTrackerHits;
+    }
+    
+    private List<RawTrackerHit> makeRawTrackerHits(CompositeData cdata) {
+        
+        // Get some ID info before looping in order to strip out irrelevant fields.
+        // TODO Next three can be removed from here and done only once at start of run. 
+        IIdentifierDictionary dict = detector.getSubdetector(trackerName).getDetectorElement().getIdentifierHelper().getIdentifierDictionary();
+        int fieldIdx = dict.getFieldIndex("side");
+        int sideIdx = dict.getFieldIndex("strip");
+        
+        // List of hits to be returned.
+        List<RawTrackerHit> hits = new ArrayList<RawTrackerHit>();
+        
+        // Loop over the items in the CompositeData.
+        List<Object> items = cdata.getItems();                        
+        //int n = items.size();
+        int n = cdata.getNValue();
+        if (debug)
+            System.out.println("RawTrackerHit.N = " + n);
+        for (int i=0; i<n; i++) {
+            
+            // Get values for hit.
+            Long id = cdata.getLong();
+            int time = cdata.getInt();
+            int adcValue = cdata.getInt();
+                      
+            // Make the new hit.
+            RawTrackerHit hit = new BaseRawTrackerHit(id, time, new short[] {(short)adcValue});
+                                                            
+            // The "side" and "strip" fields needs to be taken out of the ID or the geometry lookup will fail.
+            IExpandedIdentifier expId = dict.unpack(hit.getIdentifier());            
+            expId.setValue(fieldIdx, 0);
+            expId.setValue(sideIdx, 0);
+            IIdentifier strippedId = dict.pack(expId);
+            
+            // Find the SiSensor of this hit.  This is more complicated than it should be,
+            // because DetectorElements are not guaranteed to have unique IDs.
+            List<IDetectorElement> des = DetectorElementStore.getInstance().find(strippedId);
+            SiSensor sensor = null;
+            if (des == null || des.size() == 0) {
+                throw new RuntimeException("Failed to find DetectorElement for hit with id 0x"+Long.toHexString(strippedId.getValue()));
+            }
+            else if (des.size() == 1) {
+                sensor = (SiSensor)des.get(0);
+            }
+            else {
+                for (IDetectorElement de : des) {
+                    if (de instanceof SiSensor) {
+                        sensor = (SiSensor)de;
+                        break;
+                    }
+                }
+            }                        
+            hit.setDetectorElement(sensor);
+                 
+            // Add this hit to the list.
+            hits.add(hit);                            
+        }              
+        
+        if (debug)
+            System.out.println("makeRawTrackerHits created " + hits.size() + " hits");
+        
+        return hits;
+    }
+    
+    private List<RawCalorimeterHit> makeRawCalorimeterHits(EvioEvent event) {
+        List<RawCalorimeterHit> hits = new ArrayList<RawCalorimeterHit>();        
+        for (BaseStructure bank : event.getChildren()) {
+            BaseStructureHeader header = bank.getHeader();
+            if (header.getTag() == MCRawDataToEvio4Converter.ecalBottomBankTag || header.getTag() == MCRawDataToEvio4Converter.ecalTopBankTag) {
+                CompositeData cdata = null;
+                try {
+                     cdata = bank.getCompositeData();
+                }
+                catch (EvioException e) {
+                    throw new RuntimeException(e);
+                }
+                List<RawCalorimeterHit> bankHits = makeRawCalorimeterHits(cdata);
+                hits.addAll(bankHits);
+            }
+        }                       
+        return hits;        
+    }
+    
+    private List<RawCalorimeterHit> makeRawCalorimeterHits(CompositeData cdata) {        
+        List<RawCalorimeterHit> hits = new ArrayList<RawCalorimeterHit>();
+        List<Object> items = cdata.getItems();                        
+        int n = cdata.getNValue();
+        for (int i=0; i<n; i++) {
+            long id = cdata.getLong();
+            int amplitude = cdata.getInt();
+            int timestamp = cdata.getInt();
+            hits.add(new BaseRawCalorimeterHit(id, amplitude, timestamp));
+        }        
+        return hits;
+    }    
+}
\ No newline at end of file

hps-java/src/main/java/org/lcsim/hps/evio
EvioConsumer.java 1.10 -> 1.11
diff -u -r1.10 -r1.11
--- EvioConsumer.java	21 Mar 2012 20:19:13 -0000	1.10
+++ EvioConsumer.java	22 Mar 2012 02:21:16 -0000	1.11
@@ -45,29 +45,21 @@
 import org.jlab.coda.et.enums.Mode;
 import org.jlab.coda.et.enums.Modify;
 import org.jlab.coda.et.exception.EtTimeoutException;
-import org.jlab.coda.jevio.BaseStructure;
-import org.jlab.coda.jevio.CompositeData;
 import org.jlab.coda.jevio.EvioEvent;
 import org.jlab.coda.jevio.EvioReader;
-import org.lcsim.detector.DetectorElementStore;
-import org.lcsim.detector.IDetectorElement;
-import org.lcsim.detector.identifier.IExpandedIdentifier;
-import org.lcsim.detector.identifier.IIdentifier;
-import org.lcsim.detector.identifier.IIdentifierDictionary;
 import org.lcsim.detector.tracker.silicon.SiSensor;
+import org.lcsim.event.EventHeader;
 import org.lcsim.event.RawCalorimeterHit;
 import org.lcsim.event.RawTrackerHit;
 import org.lcsim.event.Track;
 import org.lcsim.event.TrackerHit;
-import org.lcsim.event.base.BaseLCSimEvent;
-import org.lcsim.event.base.BaseRawCalorimeterHit;
-import org.lcsim.event.base.BaseRawTrackerHit;
 import org.lcsim.geometry.Detector;
+import org.lcsim.hps.monitoring.ConnectionParameters;
+import org.lcsim.hps.monitoring.ConnectionParameters.ConnectionParametersException;
 import org.lcsim.job.JobControlManager;
 import org.lcsim.util.Driver;
 import org.lcsim.util.DriverAdapter;
 import org.lcsim.util.aida.AIDA;
-import org.lcsim.util.lcio.LCIOConstants;
 
 /**
  * This class is an example of an event consumer for an ET system.
@@ -76,52 +68,30 @@
  *
  * @author Jeremy McCormick
  */
+// FIXME Try to put plots into separate Driver which can be called from the .lcsim file, in order to cleanup this class.
 public class EvioConsumer {
     
+    //private static final String trackCollectionName = "MatchedTracks";
     private static final String detectorName = "HPS-Test-JLAB-v4pt0";
-    
-    private static final String trackerName = "Tracker";
-    private static final String rawTrackerHitCollectionName = "RawTrackerHitMaker_RawTrackerHits";
-    private static final String trackerReadoutName = "TrackerHits";
-    private static final String trackCollectionName = "MatchedTracks";
     private static final String trackerHitCollectionName = "StripClusterer_SiTrackerHitStrip1D";
     
-    private static final String rawCalorimeterHitCollectionName = "EcalRawHits";
-    private static final String ecalReadoutName = "EcalHits";
-    
     private static final String lcsimXml = "/org/lcsim/hps/steering/EtTest.lcsim";
-    private static final boolean debug = false;    
-    private static Detector detector;    
+    
+    private static Detector detector;
     private static Map<SiSensor,int[]> occupancyMap;
     private static IPlotter occuPlot;
     private static EvioConsumerGui gui;
+    
     private static long jobStartTime;
     private static int eventCount;
    
     private static List<IPlotter> plotters = new ArrayList<IPlotter>();
+    
+    private static final boolean debug = true;
             
     public EvioConsumer() {
     }
-
-    private static void usage() {
-        System.out.println("\nUsage: java Consumer -f <et name> -host <ET host> -s <station name> [-h] [-v] [-nb]\n" +
-                "                      [-p <ET server port>] [-c <chunk size>] [-q <queue size>]\n" +
-                "                      [-pos <station position>] [-ppos <parallel station position>]\n\n" +
-                "       -host  ET system's host\n" +
-                "       -f     ET system's (memory-mapped file) name\n" +
-                "       -s     create station of this name\n" +
-                "       -h     help\n" +
-                "       -v     verbose output\n" +
-                "       -nb    make station non-blocking\n" +
-                "       -p     ET server port\n" +
-                "       -c     number of events in one get/put array\n" +
-                "       -q     queue size if creating nonblocking station\n" +
-                "       -pos   position of created station in station list (1,2,...)\n" +
-                "       -ppos  position of created station within a group of parallel stations (-1=end, -2=head)\n\n" +
-                "        This consumer works by making a direct connection\n" +
-                "        to the ET system's tcp server port.\n");
-    }
-    
+       
     static void clearAidaTree() {
         ITree tree = AIDA.defaultInstance().tree();
         String names[] = tree.listObjectNames("/", true);
@@ -221,124 +191,22 @@
         plotter4.region(2).plot(ecalHitsPlot);
         plotter4.show();
     }
-    
+           
     public static void main(String[] args) {
-        int position = 1, pposition = 0, qSize = 0, chunk = 1;
-        boolean blocking = true, verbose = false;
-        String etName = null, host = null, statName = null;
-        int port = EtConstants.serverPort;
-        int flowMode = EtConstants.stationSerial;
-
-        for (int i = 0; i < args.length; i++) {
-            if (args[i].equalsIgnoreCase("-f")) {
-                etName = args[++i];
-            }
-            else if (args[i].equalsIgnoreCase("-host")) {
-                host = args[++i];
-            }
-            else if (args[i].equalsIgnoreCase("-nb")) {
-                blocking = false;
-            }
-            else if (args[i].equalsIgnoreCase("-v")) {
-                verbose = true;
-            }
-            else if (args[i].equalsIgnoreCase("-s")) {
-                statName = args[++i];
-            }
-            else if (args[i].equalsIgnoreCase("-p")) {
-                try {
-                    port = Integer.parseInt(args[++i]);
-                    if ((port < 1024) || (port > 65535)) {
-                        System.out.println("Port number must be between 1024 and 65535.");
-                        usage();
-                        return;
-                    }
-                }
-                catch (NumberFormatException ex) {
-                    System.out.println("Did not specify a proper port number.");
-                    usage();
-                    return;
-                }
-            }
-            else if (args[i].equalsIgnoreCase("-c")) {
-                try {
-                    chunk = Integer.parseInt(args[++i]);
-                    if ((chunk < 1) || (chunk > 1000)) {
-                        System.out.println("Chunk size may be 1 - 1000.");
-                        usage();
-                        return;
-                    }
-                }
-                catch (NumberFormatException ex) {
-                    System.out.println("Did not specify a proper chunk size.");
-                    usage();
-                    return;
-                }
-            }
-            else if (args[i].equalsIgnoreCase("-q")) {
-                try {
-                    qSize = Integer.parseInt(args[++i]);
-                    if (qSize < 1) {
-                        System.out.println("Queue size must be > 0.");
-                        usage();
-                        return;
-                    }
-                }
-                catch (NumberFormatException ex) {
-                    System.out.println("Did not specify a proper queue size number.");
-                    usage();
-                    return;
-                }
-            }
-            else if (args[i].equalsIgnoreCase("-pos")) {
-                try {
-                    position = Integer.parseInt(args[++i]);
-                    if (position < 1) {
-                        System.out.println("Position must be > 0.");
-                        usage();
-                        return;
-                    }
-                }
-                catch (NumberFormatException ex) {
-                    System.out.println("Did not specify a proper position number.");
-                    usage();
-                    return;
-                }
-            }
-            else if (args[i].equalsIgnoreCase("-ppos")) {
-                try {
-                    pposition = Integer.parseInt(args[++i]);
-                    if (pposition < -2 || pposition == 0) {
-                        System.out.println("Parallel position must be > -3 and != 0.");
-                        usage();
-                        return;
-                    }
-                    System.out.println("FLOW moDE is ||");
-                    flowMode = EtConstants.stationParallel;
-                    if (pposition == -2) pposition = EtConstants.newHead;
-                    else if (pposition == -1) pposition = EtConstants.end;
-
-                }
-                catch (NumberFormatException ex) {
-                    System.out.println("Did not specify a proper parallel position number.");
-                    usage();
-                    return;
-                }
-            }
-            else {
-                usage();
-                return;
-            }
-        }
-
-        if (host == null || etName == null || statName == null) {
-            usage();
-            return;
+            
+        // Create ET system connection parameters.
+        ConnectionParameters cn = new ConnectionParameters();
+        try {
+            cn.setup(args);
+        } catch (ConnectionParametersException e) {
+            e.printStackTrace();
+            ConnectionParameters.usage();
+            System.exit(1);
         }
 
         try {
             // make a direct connection to ET system's tcp server
-            EtSystemOpenConfig config = new EtSystemOpenConfig(etName, host, port);
+            EtSystemOpenConfig config = new EtSystemOpenConfig(cn.etName, cn.host, cn.port);
 
             // create ET system object with verbose debugging output
             EtSystem sys = new EtSystem(config, EtConstants.debugInfo);
@@ -346,16 +214,16 @@
 
             // configuration of a new station
             EtStationConfig statConfig = new EtStationConfig();
-            statConfig.setFlowMode(flowMode);
-            if (!blocking) {
+            statConfig.setFlowMode(cn.flowMode);
+            if (!cn.blocking) {
                 statConfig.setBlockMode(EtConstants.stationNonBlocking);
-                if (qSize > 0) {
-                    statConfig.setCue(qSize);
+                if (cn.qSize > 0) {
+                    statConfig.setCue(cn.qSize);
                 }
             }
 
             // create station
-            EtStation stat = sys.createStation(statConfig, statName, position, pposition);
+            EtStation stat = sys.createStation(statConfig, cn.statName, cn.position, cn.pposition);
 
             // attach to new station
             EtAttachment att = sys.attach(stat);
@@ -383,9 +251,19 @@
             driverAdapter.configure(null);            
             
             // Create a dummy event in order to get Detector conditions.
-            BaseLCSimEvent dummyEvent = new BaseLCSimEvent(0, 0, detectorName);
-            Detector detector = dummyEvent.getDetector();
-            EvioConsumer.detector = detector;
+            //BaseLCSimEvent dummyEvent = new BaseLCSimEvent(0, 0, detectorName);
+            //Detector detector = dummyEvent.getDetector();
+            //EvioConsumer.detector = detector;
+            
+            // Make the builder for creating LCSim events from EVIO data.
+            LCSimEventBuilder eventBuilder = new LCSimEventBuilder(detectorName);
+            eventBuilder.setDebug(true);
+            
+            EvioConsumer.detector = eventBuilder.getDetector();
+            
+            // Get names of raw data collections.
+            String rawTrackerHitCollectionName = eventBuilder.getRawTrackerHitCollectionName();
+            String rawCalorimeterHitCollectionName = eventBuilder.getRawCalorimeterHitCollectionName();
             
             // Setup all the plots for the job.
             setupPlots();
@@ -393,7 +271,7 @@
             // The default AIDA instance.
             AIDA aida = AIDA.defaultInstance();
            
-            ConnectionPanel.main(new String[]{});
+            //ConnectionPanel.main(new String[]{});
             
             // Show GUI.
             EvioConsumerGui.main(new String[]{});
@@ -403,28 +281,26 @@
             //int eventCount = 0;                     
             jobStartTime = System.currentTimeMillis();
             long eventRateStart = System.nanoTime();
-            final int eventRateInterval = 10;
+            final int eventRateInterval = 50;
             while (true) {
-                
-                //long startTime = System.nanoTime();
-                
-                // get events from ET system
+                                
+                // Use this for unlimited wait time.
                 //mevs = sys.getEvents(att, Mode.SLEEP, null, 0, chunk);                
                 boolean timedOut = false;
                 try {
-                    mevs = sys.getEvents(att, Mode.TIMED, Modify.NOTHING, 5000000, chunk);
+                    mevs = sys.getEvents(att, Mode.TIMED, Modify.NOTHING, 5000000, cn.chunk);
                 } catch (EtTimeoutException e) {
                     timedOut = true;
                 }              
                 // When timeout occurs, do cleanup and exit.
                 if (timedOut) {
                     
-                    long jobEndTime = System.currentTimeMillis();                    
+                    long jobEndTime = System.currentTimeMillis();
                     long jobTime = jobEndTime - jobStartTime;
                     System.out.println("Job time: " + jobTime / 1000 + " seconds");
                     
-                    long avgEventTime = jobTime / (eventCount);
-                    System.out.println("Avg event processing time: " + avgEventTime + " ms");
+                    //long avgEventTime = jobTime / (eventCount);
+                    //System.out.println("Avg event processing time: " + avgEventTime + " ms");
                     
                     // Call wrapper to endOfData() on DriverAdapter.
                     driverAdapter.finish(null);
@@ -434,249 +310,140 @@
                     System.console().readLine();
                     System.exit(0);
                 }
-                
-                //if (debug)
-                //    System.out.println("EvioConsumer read event #" + eventCount);
-                
-                if (mevs.length > 1) {
-                    throw new RuntimeException("Did not expect to get more than one EtEvent!");
-                }
-                
-                // This is the EtEvent corresponding to a single MC event with tracker data.
-                EtEvent mev = mevs[0];
-                
-                // Get EvioEvent and check for errors.
-                ByteBuffer buf = mev.getDataBuffer();
-                EvioReader reader = new EvioReader(buf);
-                EvioEvent evioEvent = null;
-                try {
-                    evioEvent = reader.parseNextEvent();                    
-                } catch (java.nio.BufferUnderflowException e) {
-                    System.out.println("Caught underflow!"); 
-                }                
-                // Something bad happened and event was not built.  Just skip it.
-                if (evioEvent == null) {
-                    System.out.println("Failed to build EVIO event <" + eventCount + ">.  Skipping this EtEvent!");
-                    aida.cloud1D("Bad Event Count").fill(0);
-                    continue;
-                }
-                
-                // Make CompositeData from data buffer.
-                //CompositeData cdata = evioEvent.getCompositeData();
-
-                // Convert from EVIO to LCIO objects.
-                List<RawTrackerHit> rawTrackerHits = null;
-                List<RawCalorimeterHit> rawCalorimeterHits = null;
-                for (BaseStructure bank : evioEvent.getChildren()) {
-                    if (bank.getHeader().getNumber() == MCRawDataToEvio4Converter.trackerBankNumber) {
-                        rawTrackerHits = makeRawTrackerHits(detector, bank.getCompositeData()); 
+                                           
+                // Loop over retrieved EtEvents.
+                for (EtEvent mev : mevs) {
+
+                    // Get EvioEvent and check for errors.
+                    ByteBuffer buf = mev.getDataBuffer();
+                    EvioReader reader = new EvioReader(buf);
+                    EvioEvent evioEvent = null;
+                    try {
+                        evioEvent = reader.parseNextEvent();
+                    } catch (java.nio.BufferUnderflowException e) {
+                        System.out.println("Caught underflow!");
                     }
-                    else if (bank.getHeader().getNumber() == MCRawDataToEvio4Converter.ecalBankNumber) {
-                        rawCalorimeterHits = makeRawCalorimeterHits(detector, bank.getCompositeData());
+                    // Something bad happened and event was not built. Just skip it.
+                    if (evioEvent == null) {
+                        System.out.println("Failed to build EVIO event <" + eventCount + ">.  Skipping this EtEvent!");
+                        aida.cloud1D("Bad Event Count").fill(0);
+                        continue;
                     }
-                }
-                
-                //System.out.println("rawTrackerHits.size = " + rawTrackerHits.size());
-                //System.out.println("rawCalorimeterHits.size = " + rawCalorimeterHits.size());
-                                                              
-                // Create a new LCSimEvent and add the hit collections.
-                BaseLCSimEvent lcsimEvent = new BaseLCSimEvent(0, eventCount, detectorName);
-                lcsimEvent.put(rawTrackerHitCollectionName, rawTrackerHits, RawTrackerHit.class, (1 << LCIOConstants.TRAWBIT_ID1), trackerReadoutName);
-                lcsimEvent.put(rawCalorimeterHitCollectionName, rawCalorimeterHits, RawCalorimeterHit.class, 0, ecalReadoutName);
-                
-                // Make a new event for DriverAdapter.
-                RecordSuppliedEvent loopEvent = new RecordSuppliedEvent(new Object(), lcsimEvent);
-                
-                // Call process methods via Driver Adapter.
-                driverAdapter.recordSupplied(loopEvent);
-                
-                // Make ECal plots.
-                makeEcalPlots(aida, rawCalorimeterHits);
-                                                               
-                // Fill RawTrackerHit count.
-                aida.histogram1D("Number of RawTrackerHits in Event").fill(rawTrackerHits.size());
 
-                // Loop over RawTrackerHit collection.
-                for (RawTrackerHit hit : rawTrackerHits) {
-                    
-                    // Fill ADC value plot.
-                    aida.histogram1D("ADC Value").fill(hit.getADCValues()[0]);
-                    
-                    // Fill time plot.
-                    aida.cloud1D("Time [ns]").fill(hit.getTime());
-                    
-                    // Fill basic (non-normalized) occupancy plot.
-                    aida.histogram1D(hit.getDetectorElement().getName()).fill(hit.getIdentifierFieldValue("strip"));
-                    
-                    // Increment hit counts for occupancy calculations.
-                    int[] strips = occupancyMap.get((SiSensor)hit.getDetectorElement());
-                    strips[hit.getIdentifierFieldValue("strip")] += 1;
-                }
-                
-                // Normalized occupancy plots.
-                occuPlot.clearRegions();
-                int si = 0;
-                for (SiSensor sensor : occupancyMap.keySet()) {
-                    int[] strips = occupancyMap.get(sensor);
-                    aida.histogram1D(sensor.getName() + " Normalized").reset();
-                    for (int i=0; i<strips.length; i++) {
-                        double stripOccupancy = (double)strips[i] / (double)(eventCount + 1);
-                        if (stripOccupancy != 0) {
-                            aida.histogram1D(sensor.getName() + " Normalized").fill(i, stripOccupancy);
+                    // Create LCSim event from EVIO data.
+                    EventHeader lcsimEvent = eventBuilder.makeLCSimEvent(evioEvent);
+
+                    // Get collections from event.
+                    List<RawTrackerHit> rawTrackerHits = lcsimEvent.get(RawTrackerHit.class, rawTrackerHitCollectionName);
+                    if (debug)
+                        System.out.println("rawTrackerHits.size = " + rawTrackerHits.size());
+                    List<RawCalorimeterHit> rawCalorimeterHits = lcsimEvent.get(RawCalorimeterHit.class, rawCalorimeterHitCollectionName);
+                    if (debug)
+                        System.out.println("rawCalHits.size = " + rawCalorimeterHits.size());
+
+                    // Make a new event for DriverAdapter.
+                    RecordSuppliedEvent loopEvent = new RecordSuppliedEvent(new Object(), lcsimEvent);
+
+                    // Call process methods via Driver Adapter.
+                    driverAdapter.recordSupplied(loopEvent);
+
+                    // Make ECal plots.
+                    makeEcalPlots(aida, rawCalorimeterHits);
+
+                    // Fill RawTrackerHit count.
+                    aida.histogram1D("Number of RawTrackerHits in Event").fill(rawTrackerHits.size());
+
+                    // Loop over RawTrackerHit collection.
+                    for (RawTrackerHit hit : rawTrackerHits) {
+
+                        // Fill ADC value plot.
+                        aida.histogram1D("ADC Value").fill(hit.getADCValues()[0]);
+
+                        // Fill time plot.
+                        aida.cloud1D("Time [ns]").fill(hit.getTime());
+
+                        // Fill basic (non-normalized) occupancy plot.
+                        aida.histogram1D(hit.getDetectorElement().getName()).fill(hit.getIdentifierFieldValue("strip"));
+
+                        // Increment hit counts for occupancy calculations.
+                        int[] strips = occupancyMap.get((SiSensor) hit.getDetectorElement());
+                        strips[hit.getIdentifierFieldValue("strip")] += 1;
+                    }
+
+                    // Normalized occupancy plots.
+                    occuPlot.clearRegions();
+                    int si = 0;
+                    for (SiSensor sensor : occupancyMap.keySet()) {
+                        int[] strips = occupancyMap.get(sensor);
+                        aida.histogram1D(sensor.getName() + " Normalized").reset();
+                        for (int i = 0; i < strips.length; i++) {
+                            double stripOccupancy = (double) strips[i] / (double) (eventCount + 1);
+                            if (stripOccupancy != 0) {
+                                aida.histogram1D(sensor.getName() + " Normalized").fill(i, stripOccupancy);
+                            }
                         }
+                        occuPlot.region(si).plot(aida.histogram1D(sensor.getName() + " Normalized"));
+                        ++si;
                     }
-                    occuPlot.region(si).plot(aida.histogram1D(sensor.getName() + " Normalized"));
-                    ++si;
-                }
-                occuPlot.show();
-                
-                // Get Tracks from event.
-                List<Track> tracks = lcsimEvent.get(Track.class, trackCollectionName);
-                
-                // Plot number of Tracks.
-                aida.histogram1D("Number of Tracks in Event").fill(tracks.size());
-                
-                // Track plots.
-                for (Track track : tracks) {
-                    aida.cloud1D("Number of Hits per Track").fill(track.getTrackerHits().size());
-                    aida.histogram1D("Track Px").fill(track.getPX());
-                    aida.histogram1D("Track Py").fill(track.getPY());
-                    aida.histogram1D("Track Pz").fill(track.getPZ());
-                    double[] p = track.getMomentum();
-                    aida.histogram1D("Track P").fill(Math.sqrt(p[0]*p[0]+p[1]*p[1]+p[2]*p[2]));
+                    occuPlot.show();
+
+                    // Get Tracks from event.
+                    //List<Track> tracks = lcsimEvent.get(Track.class, trackCollectionName);
+                    List<Track> tracks = lcsimEvent.get(Track.class).get(0);
+
+                    // Plot number of Tracks.
+                    aida.histogram1D("Number of Tracks in Event").fill(tracks.size());
+
+                    // Track plots.
+                    for (Track track : tracks) {
+                        aida.cloud1D("Number of Hits per Track").fill(track.getTrackerHits().size());
+                        aida.histogram1D("Track Px").fill(track.getPX());
+                        aida.histogram1D("Track Py").fill(track.getPY());
+                        aida.histogram1D("Track Pz").fill(track.getPZ());
+                        double[] p = track.getMomentum();
+                        aida.histogram1D("Track P").fill(Math.sqrt(p[0] * p[0] + p[1] * p[1] + p[2] * p[2]));
+                    }
+
+                    // Number of TrackerHits.
+                    List<TrackerHit> trackerHits = lcsimEvent.get(TrackerHit.class, trackerHitCollectionName);
+                    aida.histogram1D("Number of TrackerHits in Event").fill(trackerHits.size());
+               
+                    long currTime = System.currentTimeMillis() - jobStartTime;
+                    gui.setElapsedTime(currTime);
+
+                    // Increment event count.
+                    ++eventCount;
+
+                    // Periodically compute event rate.
+                    if (eventCount % eventRateInterval == 0) {
+
+                        long eventRateEnd = System.nanoTime();
+                        long eventElapsed = eventRateEnd - eventRateStart;
+                        long nsPerEvent = eventElapsed / eventRateInterval;
+                        double eventRate = 10e9 / nsPerEvent;
+                        gui.setEventRate(eventRate);
+                        eventRateStart = System.nanoTime();
+
+                        // Compute rolling average event processing time.
+                        double avgProcTime = (System.currentTimeMillis() - jobStartTime) / (double) eventCount;
+                        double avgEventRate = 1000 / avgProcTime;
+                        gui.setAverageEventRate(avgEventRate);
+                    }
+
+                    gui.incrEventCount();
+
                 }
-                
-                // Number of TrackerHits.
-                List<TrackerHit> trackerHits = lcsimEvent.get(TrackerHit.class, trackerHitCollectionName);
-                aida.histogram1D("Number of TrackerHits in Event").fill(trackerHits.size());
                                                 
                 // put events back into ET system
                 // FIXME Is this even necessary when running in read-only mode?
                 sys.putEvents(att, mevs);
-                
-                // Compute event processing time.
-                //long endTime = System.nanoTime();
-                //long elapsed = endTime - startTime;
-                //System.out.println("processed event in " + elapsed + " ns");
-                
-                // Compute instantaneous event rate e.g. this event only.
-                //double eventRate = 10e9 / elapsed;
-                //System.out.println("instantaneous event rate = " + eventRate + " hz");
-                                
-                // Fill event rate plot.
-                //aida.cloud1D("Event Rate [Hz]").fill(eventRate);
-                
-                long currTime = System.currentTimeMillis() - jobStartTime;
-                gui.setElapsedTime(currTime);
-                                                                                           
-                // Increment event count.
-                ++eventCount;
-                
-                // Periodically compute event rate.
-                if (eventCount % eventRateInterval == 0) {
-                    long eventRateEnd = System.nanoTime();
-                    long eventElapsed = eventRateEnd - eventRateStart;
-                    long nsPerEvent = eventElapsed / eventRateInterval;
-                    double eventRate = 10e9 / nsPerEvent;
-                    gui.setEventRate(eventRate);          
-                    eventRateStart = System.nanoTime();
-                }
-                
-                gui.incrEventCount();
-
-                // Compute rolling average event processing time.
-                double avgProcTime = (System.currentTimeMillis() - jobStartTime) / (double)eventCount;
-                double avgEventRate = 1000 / avgProcTime;
-                gui.setAverageEventRate(avgEventRate);
-                                
-                //if (debug)
-                //    System.out.println("----------------------");
             }
         }
         catch (Exception ex) {
             System.out.println("Error using ET system as consumer.");
             ex.printStackTrace();
         }
-    }   
-        
-    private static boolean HIT_MAKING_DEBUG = false;
-    
-    private static List<RawTrackerHit> makeRawTrackerHits(Detector detector, CompositeData cdata) {
-        
-        // Get some ID info before looping in order to strip out irrelevant fields.
-        // TODO Next three can be removed from here and done only once at start of run. 
-        IIdentifierDictionary dict = detector.getSubdetector(trackerName).getDetectorElement().getIdentifierHelper().getIdentifierDictionary();
-        int fieldIdx = dict.getFieldIndex("side");
-        int sideIdx = dict.getFieldIndex("strip");
-        
-        // List of hits to be returned.
-        List<RawTrackerHit> hits = new ArrayList<RawTrackerHit>();
-        
-        // Loop over the items in the CompositeData.
-        List<Object> items = cdata.getItems();                        
-        //int n = items.size();
-        int n = cdata.getNValue();
-        System.out.println("RawTrackerHit.N = " + n);
-        for (int i=1; i<n; i+=3) {
-            
-            // Get values for hit.
-            Long id = (Long)items.get(i);
-            int time = (Integer)items.get(i+1);
-            int adcValue = (Integer)items.get(i+2);
-            
-            // Make the new hit.
-            RawTrackerHit hit = new BaseRawTrackerHit(id, time, new short[] {(short)adcValue});
-            
-            if (HIT_MAKING_DEBUG) {
-                System.out.println("id=0x"+Long.toHexString(id)+"; time="+time+"; adcValue="+adcValue);
-            }
-                                                
-            // The "side" and "strip" fields needs to be taken out of the ID or the geometry lookup will fail.
-            IExpandedIdentifier expId = dict.unpack(hit.getIdentifier());            
-            expId.setValue(fieldIdx, 0);
-            expId.setValue(sideIdx, 0);
-            IIdentifier strippedId = dict.pack(expId);
-            
-            // Find the SiSensor of this hit.  This is more complicated than it should be,
-            // because DetectorElements are not guaranteed to have unique IDs.
-            List<IDetectorElement> des = DetectorElementStore.getInstance().find(strippedId);
-            SiSensor sensor = null;
-            if (des == null || des.size() == 0) {
-                throw new RuntimeException("Failed to find DetectorElement for hit with id 0x"+Long.toHexString(strippedId.getValue()));
-            }
-            else if (des.size() == 1) {
-                sensor = (SiSensor)des.get(0);
-            }
-            else {
-                for (IDetectorElement de : des) {
-                    if (de instanceof SiSensor) {
-                        sensor = (SiSensor)de;
-                        break;
-                    }
-                }
-            }                        
-            hit.setDetectorElement(sensor);
-                 
-            // Add this hit to the list.
-            hits.add(hit);                            
-        }                           
-        return hits;
-    }
-    
-    private static List<RawCalorimeterHit> makeRawCalorimeterHits(Detector detector, CompositeData cdata) {        
-        List<RawCalorimeterHit> hits = new ArrayList<RawCalorimeterHit>();
-        List<Object> items = cdata.getItems();                        
-        //int n = items.size();
-        int n = cdata.getNValue();
-        System.out.println("RawCalHit.N = " + n);
-        for (int i=1; i<n; i+=3) {
-            long id = (Long)items.get(i);
-            int amplitude = (Integer)items.get(i+1);
-            int timestamp = (Integer)items.get(i+2);
-            hits.add(new BaseRawCalorimeterHit(id, amplitude, timestamp));
-        }        
-        return hits;
-    }
+    }      
     
     private static void makeEcalPlots(AIDA aida, List<RawCalorimeterHit> hits) {
         aida.cloud1D("Number of Hits").fill(hits.size());
@@ -685,18 +452,6 @@
             aida.cloud1D("Amplitude").fill(hit.getAmplitude());
         }
     }
-           
-    static class ConnectionParameters {
-        String etName; // x
-        String host; // x
-        int port; // x
-        boolean nonBlocking;
-        String stationName;
-        int neventsPerArray;
-        int queueSize;
-        int stationPos;
-        int stationParallelPos;            
-    }
     
     static class ConnectionPanel extends JPanel implements ActionListener {
 
@@ -847,45 +602,7 @@
             c.gridy = 1;
             JPanel buttonsPanel = new JPanel();
             buttonsPanel.setLayout(new GridBagLayout());
-            add(buttonsPanel, c);
-                        
-            /*
-            c = new GridBagConstraints();
-            c.gridx = 0;
-            c.gridy = 0;
-            c.anchor = GridBagConstraints.WEST;
-            JLabel hostLabel = new JLabel("Host:");            
-            hostLabel.setHorizontalAlignment(JLabel.LEFT);            
-            fieldsPanel.add(hostLabel, c);
-            
-            c = new GridBagConstraints();
-            c.gridx = 1;
-            c.gridy = 0;
-            c.anchor = GridBagConstraints.EAST;
-            host = new JTextField("", 20);
-            host.setHorizontalAlignment(JTextField.RIGHT);
-            host.setEditable(false);
-            host.setBackground(Color.WHITE);
-            fieldsPanel.add(host, c);
-            
-            c = new GridBagConstraints();
-            c.gridx = 0;
-            c.gridy = 1;
-            c.anchor = GridBagConstraints.WEST;
-            JLabel portLabel = new JLabel("Port:");
-            portLabel.setHorizontalAlignment(JLabel.LEFT);
-            fieldsPanel.add(portLabel, c);
-            
-            c = new GridBagConstraints();
-            c.gridx = 1;
-            c.gridy = 1;
-            c.anchor = GridBagConstraints.EAST;
-            port = new JTextField("", 6);
-            port.setHorizontalAlignment(JTextField.RIGHT);
-            port.setEditable(false);
-            port.setBackground(Color.WHITE);
-            fieldsPanel.add(port, c);
-            */
+            add(buttonsPanel, c);       
             
             c = new GridBagConstraints();
             c.gridx = 0;
@@ -1002,17 +719,6 @@
             eventCounter.setText(Integer.toString(e));
         }
 
-        /*
-
-        public void setHost(String host) {
-            this.host.setText(host);
-        }
-        
-        public void setPort(int port) {
-            this.port.setText(Integer.toString(port));
-        }
-        */
-        
         public void setElapsedTime(long time) {
             elapsedTime.setText(Long.toString(time));
         }
@@ -1067,7 +773,7 @@
             plotters.clear();
             
             clearAidaTree();
-            setupPlots(); 
+            setupPlots();
             resetEventCount();
             resetTimer();  
             

hps-java/src/main/java/org/lcsim/hps/evio
MCRawDataToEvio4Converter.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- MCRawDataToEvio4Converter.java	21 Mar 2012 20:19:13 -0000	1.1
+++ MCRawDataToEvio4Converter.java	22 Mar 2012 02:21:16 -0000	1.2
@@ -1,6 +1,7 @@
 package org.lcsim.hps.evio;
 
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.List;
 
 import org.jlab.coda.jevio.CompositeData;
@@ -10,8 +11,10 @@
 import org.jlab.coda.jevio.EvioBank;
 import org.jlab.coda.jevio.EvioException;
 import org.lcsim.event.EventHeader;
+import org.lcsim.event.EventHeader.LCMetaData;
 import org.lcsim.event.RawCalorimeterHit;
 import org.lcsim.event.RawTrackerHit;
+import org.lcsim.geometry.IDDecoder;
 import org.lcsim.util.Driver;
 
 /**
@@ -40,14 +43,19 @@
     
     String rawTrackerHitCollectionName = "RawTrackerHitMaker_RawTrackerHits";
     String rawCalorimeterHitCollectionName = "EcalRawHits";    
-            
-    public static final int trackerBankTag = 0x0;
-    public static final int trackerBankNumber = 1;
+
+    // These correspond to ROC (readout crate) IDs from the DAQ system.
+    public static final int ecalTopBankTag = 0x1;
+    public static final int ecalBottomBankTag = 0x2;
+    public static final int trackerBankTag = 0x3;
+        
+    // CompositeData formats.
     public static final String trackerFormat = "N(L,I,I)";
+    public static final String ecalFormat = "N(L,I,I)";
     
-    public static final int ecalBankTag = 0xe103;
+    //public static final int ecalBankTag = 0xe103;
+    public static final int trackerBankNumber = 1;
     public static final int ecalBankNumber = 2;
-    public static final String ecalFormat = "N(L,I,I)";
     
     public MCRawDataToEvio4Converter() 
     {}
@@ -85,9 +93,18 @@
     
     public void process(EventHeader event) {
         
+        // Make a new EVIO event.
         EventBuilder builder = new EventBuilder(0, DataType.BANK, event.getEventNumber());
+        
+        // Write RawTrackerHit collection.
         writeRawTrackerHits(event.get(RawTrackerHit.class, rawTrackerHitCollectionName), builder);
-        writeRawCalorimeterHits(event.get(RawCalorimeterHit.class, rawCalorimeterHitCollectionName), builder);
+        
+        // Write RawCalorimeterHit collection.
+        List<RawCalorimeterHit> rawCalorimeterHits = event.get(RawCalorimeterHit.class, rawCalorimeterHitCollectionName); 
+        LCMetaData meta = event.getMetaData(rawCalorimeterHits);
+        writeRawCalorimeterHits(meta, rawCalorimeterHits, builder);
+        
+        // Write this EVIO event.
         builder.setAllHeaderLengths();
         try {
             writer.writeEvent(builder.getEvent());
@@ -101,7 +118,10 @@
     public void writeRawTrackerHits(List<RawTrackerHit> rawTrackerHits, EventBuilder builder) {
 
         int dataSize = rawTrackerHits.size();
-        CompositeData.Data data = new CompositeData.Data();
+        
+        System.out.println("writeRawTrackerHits will write " + dataSize + " hits");
+                                             
+        CompositeData.Data data = new CompositeData.Data();       
         data.addN(dataSize);     
         for (RawTrackerHit hit : rawTrackerHits) {
             data.addLong(hit.getCellID());
@@ -128,24 +148,24 @@
             throw new RuntimeException(e);
         }
     }
-    
-    public void writeRawCalorimeterHits(List<RawCalorimeterHit> rawCalorimeterHits, EventBuilder builder) {
+       
+    public void writeRawCalorimeterHitCollection(List<RawCalorimeterHit> hits, int bankTag, EventBuilder builder) {
         CompositeData.Data data = new CompositeData.Data();
-        int nhits = rawCalorimeterHits.size();
-        data.addN(nhits);
-        for (RawCalorimeterHit hit : rawCalorimeterHits) {
+        int nTopHits = hits.size();
+        data.addN(nTopHits);
+        for (RawCalorimeterHit hit : hits) {
             data.addLong(hit.getCellID());
             data.addInt(hit.getAmplitude());
             data.addInt(hit.getTimeStamp());
-        }        
+        }
         CompositeData cdata = null;
         try {
-            cdata = new CompositeData(ecalFormat, 1, data, 0 ,0);
+            cdata = new CompositeData(ecalFormat, 1, data, 00);
         }
         catch (EvioException e) {
             throw new RuntimeException(e);
-        }        
-        EvioBank bank = new EvioBank(ecalBankTag, DataType.COMPOSITE, ecalBankNumber);
+        }
+        EvioBank bank = new EvioBank(bankTag, DataType.COMPOSITE, ecalBankNumber);
         try {
             bank.appendCompositeData(cdata);
         } catch (EvioException e) {
@@ -158,4 +178,28 @@
             throw new RuntimeException(e);
         }
     }
+    
+    public void writeRawCalorimeterHits(LCMetaData meta, List<RawCalorimeterHit> rawCalorimeterHits, EventBuilder builder) {
+        
+        // Make two lists containing the hits from top and bottom sections, which go into separate EVIO data banks.
+        IDDecoder dec = meta.getIDDecoder();
+        List<RawCalorimeterHit> topHits = new ArrayList<RawCalorimeterHit>();
+        List<RawCalorimeterHit> bottomHits = new ArrayList<RawCalorimeterHit>();        
+        for (RawCalorimeterHit hit : rawCalorimeterHits) {
+            dec.setID(hit.getCellID());
+            int iy = dec.getValue("iy");
+            // Negative iy should be bottom section.
+            if (iy < 0) {
+                bottomHits.add(hit);
+            }
+            // Positive iy should be top section.
+            else {
+                topHits.add(hit);
+            }
+        }
+        
+        // Write the two collections for top and bottom hits to separate EVIO banks.
+        writeRawCalorimeterHitCollection(topHits, ecalTopBankTag, builder);
+        writeRawCalorimeterHitCollection(bottomHits, ecalBottomBankTag, builder);        
+    }      
 }
\ No newline at end of file

hps-java/src/main/java/org/lcsim/hps/monitoring
ConnectionParameters.java added at 1.1
diff -N ConnectionParameters.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ConnectionParameters.java	22 Mar 2012 02:21:16 -0000	1.1
@@ -0,0 +1,128 @@
+package org.lcsim.hps.monitoring;
+
+import org.jlab.coda.et.EtConstants;
+
+/**
+ * Connection parameters for ET system.
+ */
+public class ConnectionParameters {
+
+    public String etName = null;
+    public String host = null;
+    public int port = EtConstants.serverPort;
+    public boolean blocking = true;
+    public boolean verbose = false;
+    public String statName = null;
+    public int chunk = 1;
+    public int neventsPerArray;
+    public int qSize = 0;
+    public int position = 1;
+    public int pposition = 0;
+    public int flowMode = EtConstants.stationSerial;
+    
+    public class ConnectionParametersException extends RuntimeException {
+        ConnectionParametersException(String msg) {
+            super(msg);
+        }
+    }
+
+    public static final void usage() {
+        System.out.println("\nUsage: java Consumer -f <et name> -host <ET host> -s <station name> [-h] [-v] [-nb]\n" +
+                "                      [-p <ET server port>] [-c <chunk size>] [-q <queue size>]\n" +
+                "                      [-pos <station position>] [-ppos <parallel station position>]\n\n" +
+                "       -host  ET system's host\n" +
+                "       -f     ET system's (memory-mapped file) name\n" +
+                "       -s     create station of this name\n" +
+                "       -h     help\n" +
+                "       -v     verbose output\n" +
+                "       -nb    make station non-blocking\n" +
+                "       -p     ET server port\n" +
+                "       -c     number of events in one get/put array\n" +
+                "       -q     queue size if creating nonblocking station\n" +
+                "       -pos   position of created station in station list (1,2,...)\n" +
+                "       -ppos  position of created station within a group of parallel stations (-1=end, -2=head)\n\n" +
+                "        This consumer works by making a direct connection\n" +
+                "        to the ET system's tcp server port.\n");
+    }
+
+    /**
+     * Setup this ConnectionParameters object from command line arguments.
+     * 
+     * @param args
+     * @return
+     */
+    public void setup(String[] args) {
+        for (int i = 0; i < args.length; i++) {
+            if (args[i].equalsIgnoreCase("-f")) {
+                etName = args[++i];
+            } else if (args[i].equalsIgnoreCase("-host")) {
+                host = args[++i];
+            } else if (args[i].equalsIgnoreCase("-nb")) {
+                blocking = false;
+            } else if (args[i].equalsIgnoreCase("-v")) {
+                verbose = true;
+            } else if (args[i].equalsIgnoreCase("-s")) {
+                statName = args[++i];
+            } else if (args[i].equalsIgnoreCase("-p")) {
+                try {
+                    port = Integer.parseInt(args[++i]);
+                    if ((port < 1024) || (port > 65535)) {
+                        throw new ConnectionParametersException("Port number must be between 1024 and 65535.");
+                    }
+                } catch (NumberFormatException ex) {
+                    throw new ConnectionParametersException("Did not specify a proper port number.");
+                }
+            } else if (args[i].equalsIgnoreCase("-c")) {
+                try {
+                    chunk = Integer.parseInt(args[++i]);
+                    if ((chunk < 1) || (chunk > 1000)) {
+                        throw new ConnectionParametersException("Chunk size must be 1 - 1000.");
+                    }
+                } catch (NumberFormatException ex) {
+                    throw new ConnectionParametersException("Did not specify a proper chunk size.");
+                }
+            } else if (args[i].equalsIgnoreCase("-q")) {
+                try {
+                    qSize = Integer.parseInt(args[++i]);
+                    if (qSize < 1) {
+                        throw new ConnectionParametersException("Queue size must be > 0.");
+                    }
+                } catch (NumberFormatException ex) {
+                    throw new ConnectionParametersException("Did not specify a proper queue size number.");
+                }
+            } else if (args[i].equalsIgnoreCase("-pos")) {
+                try {
+                    position = Integer.parseInt(args[++i]);
+                    if (position < 1) {
+                        throw new ConnectionParametersException("Position must be > 0.");
+                    }
+                } catch (NumberFormatException ex) {
+                    throw new ConnectionParametersException("Did not specify a proper position number.");
+                }
+            } else if (args[i].equalsIgnoreCase("-ppos")) {
+                try {
+                    pposition = Integer.parseInt(args[++i]);
+                    if (pposition < -2 || pposition == 0) {
+                        throw new ConnectionParametersException("Parallel position must be > -3 and != 0.");
+                    }
+                    System.out.println("FLOW moDE is ||");
+                    flowMode = EtConstants.stationParallel;
+                    if (pposition == -2) {
+                        pposition = EtConstants.newHead;
+                    } else if (pposition == -1) {
+                        pposition = EtConstants.end;
+                    }
+
+                } catch (NumberFormatException ex) {
+                    throw new ConnectionParametersException("Did not specify a proper parallel position number.");
+                }
+            } else {
+                throw new ConnectionParametersException("Arguments included invalid command line parameter.");
+            }
+        }
+
+        if (host == null || etName == null || statName == null) {
+            throw new ConnectionParametersException("Missing required arguments.");
+        }
+    }
+}
\ No newline at end of file

hps-java/src/main/java/org/lcsim/hps/recon/tracking
TrackerHitDriver.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- TrackerHitDriver.java	16 Mar 2012 19:11:11 -0000	1.1
+++ TrackerHitDriver.java	22 Mar 2012 02:21:17 -0000	1.2
@@ -34,11 +34,12 @@
  * algorithm like Seed Tracker.
  * 
  * @author jeremym
- * @version $Id: TrackerHitDriver.java,v 1.1 2012/03/16 19:11:11 jeremy Exp $
+ * @version $Id: TrackerHitDriver.java,v 1.2 2012/03/22 02:21:17 jeremy Exp $
  */
 public class TrackerHitDriver extends Driver {
+    
     // Debug switch for development.
-    private static final boolean DEBUG = false;
+    private boolean debug = false;
 
     // Collection name.
     private String readoutCollectionName = "TrackerHits";
@@ -87,6 +88,14 @@
 
     // Digi class objects.
     private StripHitMaker stripClusterer;
+    
+    public void setDebug(boolean debug) {
+        this.debug = debug;
+    }
+    
+    public void setRawTrackerHitCollectionName(String rawTrackerHitCollectionName) {
+        this.rawTrackerHitCollectionName = rawTrackerHitCollectionName;
+    }
 
     public void setReadoutCollectionName(String readoutCollectionName) {
         this.readoutCollectionName = readoutCollectionName;
@@ -257,11 +266,6 @@
             sensorMap.put(sensor.getIdentifier().getValue(), sensor);
         }
     }
-
-    public void setRawTrackerHitCollectionName(
-            String rawTrackerHitCollectionName) {
-        this.rawTrackerHitCollectionName = rawTrackerHitCollectionName;
-    }
     
     private static IIdentifier makeSensorId(Detector detector, RawTrackerHit hit) {
         
@@ -288,6 +292,9 @@
 
         // Read RawTrackerHits from LCSimEvent.
         List<RawTrackerHit> rawHits = event.get(RawTrackerHit.class, rawTrackerHitCollectionName);
+        
+        if (debug)
+            System.out.println("RawTrackerHit collection " + rawTrackerHitCollectionName + " has " + rawHits.size() + " hits.");
                
         // Add hits to sensors.
         for (RawTrackerHit hit : rawHits) {            
@@ -302,16 +309,18 @@
         // Make strip hits.
         List<SiTrackerHit> stripHits1D = new ArrayList<SiTrackerHit>();
         for (SiSensor sensor : processSensors) {
-            //System.out.println("making TrackerHits for sensor " + sensor.getName() + " with " + sensor.getReadout().getHits(RawTrackerHit.class).size() + " hits");
+            if (debug)
+                System.out.println("Making TrackerHits for sensor " + sensor.getName() + " with " + sensor.getReadout().getHits(RawTrackerHit.class).size() + " hits.");
             List<SiTrackerHit> trackerHits = stripClusterer.makeHits(sensor);
-            //System.out.println("made " + trackerHits.size() + " hits on sensor " + sensor.getName());
+            if (debug)
+                System.out.println("Made " + trackerHits.size() + " hits on sensor " + sensor.getName() + ".");
             stripHits1D.addAll(trackerHits);
         }
 
         // Debug prints.
-        //if (DEBUG) {
-        //    System.out.println("TrackerHit collection " + this.stripHitOutputCollectionName + " has " + stripHits1D.size() + " hits.");
-        //}
+        if (debug) {
+            System.out.println("TrackerHit collection " + this.stripHitOutputCollectionName + " has " + stripHits1D.size() + " hits.");
+        }
 
         // Put output TrackerHits into event.
         // FIXME Does this collection need a non-zero flag?

hps-java/src/main/java/org/lcsim/hps/recon/tracking
TrackerReconDriver.java 1.13 -> 1.14
diff -u -r1.13 -r1.14
--- TrackerReconDriver.java	19 Mar 2012 21:59:24 -0000	1.13
+++ TrackerReconDriver.java	22 Mar 2012 02:21:17 -0000	1.14
@@ -23,7 +23,7 @@
  * with the {@link TrackerDigiDriver} digitization Driver.
  * 
  * @author jeremym
- * @version $Id: TrackerReconDriver.java,v 1.13 2012/03/19 21:59:24 jeremy Exp $
+ * @version $Id: TrackerReconDriver.java,v 1.14 2012/03/22 02:21:17 jeremy Exp $
  */
 public final class TrackerReconDriver extends Driver {
     
@@ -147,8 +147,7 @@
         // Cache Detector object.
         this.detector = detector;
 
-        // Get B-field Y with no sign. Seed Tracker doesn't like signed B-field
-        // components.
+        // Get B-field Y with no sign. Seed Tracker doesn't like signed B-field components.
         // FIXME Is this always right?
         this.bfield = Math.abs((detector.getFieldMap().getField(new BasicHep3Vector(0, 0, 0)).y()));
         if (debug)

hps-java/src/main/resources/org/lcsim/hps/steering
EtTest.lcsim 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- EtTest.lcsim	16 Mar 2012 19:09:57 -0000	1.1
+++ EtTest.lcsim	22 Mar 2012 02:21:17 -0000	1.2
@@ -10,42 +10,33 @@
         <printInputFiles>true</printInputFiles>
         <printDriversDetailed>true</printDriversDetailed>
     </control>
-
-<!--    
-    <classpath>
-        <jar>~/.m2/repository/org/lcsim/hps-java/1.0-SNAPSHOT/hps-java-1.0-SNAPSHOT.jar</jar>
-    </classpath>
--->
     
     <execute>
-        <driver name="EventMarkerDriver"/>
         <driver name="SVTSetupDriver"/>
-<!--
-        <driver name="TrackerDigiDriver"/>
--->
+        <driver name="EventMarkerDriver"/>
         <driver name="TrackerHitDriver"/>
         <driver name="TrackerReconDriver"/>
     </execute>
     
     <drivers>
 
-        <driver name="TrackerHitDriver"
-                type="org.lcsim.hps.recon.tracking.TrackerHitDriver"/>
-
         <driver name="SVTSetupDriver"
                 type="org.lcsim.hps.recon.tracking.HPSSVTSensorSetup">   
         </driver>
 
         <driver name="EventMarkerDriver"
                 type="org.lcsim.job.EventMarkerDriver">
-            <eventInterval>100</eventInterval>
+            <eventInterval>1</eventInterval>
         </driver>
-    
-        <driver name="TrackerDigiDriver"
-                type="org.lcsim.hps.recon.tracking.TrackerDigiDriver"/>
-                
+
+        <driver name="TrackerHitDriver"
+                type="org.lcsim.hps.recon.tracking.TrackerHitDriver">
+            <debug>true</debug>
+        </driver>
+                    
         <driver name="TrackerReconDriver"
                 type="org.lcsim.hps.recon.tracking.TrackerReconDriver">
+            <debug>true</debug>
             <strategyResource>/org/lcsim/hps/recon/tracking/strategies/HPS-Test-4pt0.xml</strategyResource>
             <stripMaxSeparation>20.0</stripMaxSeparation>
             <stripTolerance>1.0</stripTolerance>
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