LISTSERV mailing list manager LISTSERV 16.5

Help for HPS-SVN Archives


HPS-SVN Archives

HPS-SVN Archives


HPS-SVN@LISTSERV.SLAC.STANFORD.EDU


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Proportional Font

LISTSERV Archives

LISTSERV Archives

HPS-SVN Home

HPS-SVN Home

HPS-SVN  March 2016

HPS-SVN March 2016

Subject:

r4291 - in /java/trunk: evio/src/main/java/org/hps/evio/AbstractSvtEvioReader.java evio/src/main/java/org/hps/evio/SvtEvioReader.java evio/src/main/java/org/hps/evio/TestRunSvtEvioReader.java record-util/src/main/java/org/hps/record/svt/SvtEvioUtils.java

From:

[log in to unmask]

Reply-To:

Notification of commits to the hps svn repository <[log in to unmask]>

Date:

Sat, 12 Mar 2016 02:29:57 -0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (550 lines)

Author: [log in to unmask]
Date: Fri Mar 11 18:29:19 2016
New Revision: 4291

Log:
break code out into static methods

Modified:
    java/trunk/evio/src/main/java/org/hps/evio/AbstractSvtEvioReader.java
    java/trunk/evio/src/main/java/org/hps/evio/SvtEvioReader.java
    java/trunk/evio/src/main/java/org/hps/evio/TestRunSvtEvioReader.java
    java/trunk/record-util/src/main/java/org/hps/record/svt/SvtEvioUtils.java

Modified: java/trunk/evio/src/main/java/org/hps/evio/AbstractSvtEvioReader.java
 =============================================================================
--- java/trunk/evio/src/main/java/org/hps/evio/AbstractSvtEvioReader.java	(original)
+++ java/trunk/evio/src/main/java/org/hps/evio/AbstractSvtEvioReader.java	Fri Mar 11 18:29:19 2016
@@ -12,12 +12,7 @@
 import org.hps.record.svt.SvtEvioExceptions.SvtEvioReaderException;
 import org.hps.util.Pair;
 import org.jlab.coda.jevio.BaseStructure;
-import org.jlab.coda.jevio.DataType;
 import org.jlab.coda.jevio.EvioEvent;
-import org.jlab.coda.jevio.IEvioFilter;
-import org.jlab.coda.jevio.IEvioStructure;
-import org.jlab.coda.jevio.StructureFinder;
-import org.jlab.coda.jevio.StructureType;
 import org.lcsim.detector.tracker.silicon.HpsSiSensor;
 import org.lcsim.event.EventHeader;
 import org.lcsim.event.RawTrackerHit;
@@ -38,7 +33,7 @@
     public static final String SVT_HEADER_COLLECTION_NAME = "SvtHeaders";
     
     // Initialize the logger
-    public static Logger LOGGER = Logger.getLogger(AbstractSvtEvioReader.class.getPackage().getName());
+    public static final Logger LOGGER = Logger.getLogger(AbstractSvtEvioReader.class.getPackage().getName());
     
     // A Map from DAQ pair (FPGA/Hybrid or FEB ID/FEB Hybrid ID) to the
     // corresponding sensor
@@ -46,16 +41,11 @@
                   HpsSiSensor /* Sensor */> daqPairToSensor 
                       = new HashMap<Pair<Integer, Integer>, HpsSiSensor>();
     
-    // A collection of banks that should be processed after all hits have been made
-    protected List<BaseStructure> eventBanks = new ArrayList<BaseStructure>();
-
     // Flag indicating whether the DAQ map has been setup
     protected boolean isDaqMapSetup = false;
 
     // Collections and names
     private static final String SVT_HIT_COLLECTION_NAME = "SVTRawTrackerHits";
-    List<RawTrackerHit> rawHits = new ArrayList<RawTrackerHit>();
-    List<SvtHeaderDataInfo> headers = new ArrayList<SvtHeaderDataInfo>();
 
     // Constants
     private static final String SUBDETECTOR_NAME = "Tracker";
@@ -75,6 +65,19 @@
      */
     abstract protected int getMaxRocBankTag(); 
     
+    /**
+     *  Get the minimum SVT ROC bank tag in the event.
+     *
+     *  @return Minimum SVT ROC bank tag
+     */
+    abstract protected int getMinDataBankTag(); 
+    
+    /**
+     *  Get the maximum SVT ROC bank tag in the event.
+     *
+     *  @return Maximum SVT ROC bank tag
+     */
+    abstract protected int getMaxDataBankTag(); 
 
     /**
      *  Get the SVT ROC bank number of the bank encapsulating the SVT samples.
@@ -115,14 +118,6 @@
      */
     abstract protected HpsSiSensor getSensor(int[] data);
 
-    /**
-     *  Check whether a data bank is valid i.e. contains SVT samples only.
-     * 
-     *  @param dataBank - An EVIO bank containing integer data
-     *  @return true if the bank is valid, false otherwise
-     */
-    abstract protected boolean isValidDataBank(BaseStructure dataBank);
-    
     /**
      * Check whether the samples are valid
      * 
@@ -153,125 +148,88 @@
      *  @return true if the raw hits were created successfully, false otherwise 
      * @throws SvtEvioReaderException 
      */
+    @Override
     public boolean makeHits(EvioEvent event, EventHeader lcsimEvent) throws SvtEvioReaderException {
 
         LOGGER.finest("Physics Event: " + event.toString());
         
-        // Retrieve the ROC banks encapsulated by the physics bank.  The ROC
+        // Retrieve the data banks encapsulated by the physics bank.  The ROC
         // bank range is set in the subclass.
-        List<BaseStructure> rocBanks = new ArrayList<BaseStructure>();
-        for (int rocBankTag = this.getMinRocBankTag(); 
-                rocBankTag <= this.getMaxRocBankTag(); rocBankTag++) { 
-            
-            LOGGER.finest("Retrieving ROC bank: " + rocBankTag);
-            List<BaseStructure> matchingRocBanks = this.getMatchingBanks(event, rocBankTag);
-            if (matchingRocBanks == null) { 
-                LOGGER.finest("ROC bank " + rocBankTag + " was not found!");
-                continue;
-            }
-            rocBanks.addAll(matchingRocBanks);
-        }
-        LOGGER.finest("Total ROC banks found: " + rocBanks.size());
-        
-        // Return false if ROC banks weren't found
-        if (rocBanks.isEmpty()) return false;  
+        List<BaseStructure> dataBanks = SvtEvioUtils.getDataBanks(event, this.getMinRocBankTag(), this.getMaxRocBankTag(), this.getMinDataBankTag(), this.getMaxDataBankTag());
+        
+        // Return false if data banks weren't found
+        if (dataBanks.isEmpty()) return false;  
     
         // Setup the DAQ map if it's not setup
         if (!this.isDaqMapSetup)
             this.setupDaqMap(lcsimEvent.getDetector().getSubdetector(
                     SUBDETECTOR_NAME));
 
-        // Clear the list of raw tracker hits
-        rawHits.clear();
-        
-        // Clear the list of headers
-        headers.clear();
-
-        // Loop over the SVT ROC banks and process all samples
-        for (BaseStructure rocBank : rocBanks) { 
-            
-            LOGGER.finest("ROC bank: " + rocBank.toString());
-            
-            LOGGER.finest("Processing ROC bank " + rocBank.getHeader().getTag());
-            
-            // If the ROC bank doesn't contain any data, raise an exception
-            if (rocBank.getChildCount() == 0) { 
-                throw new SvtEvioReaderException("[ " + this.getClass().getSimpleName() 
-                                + " ]: SVT bank doesn't contain any data banks.");
+        List<RawTrackerHit> rawHits = new ArrayList<RawTrackerHit>();
+        List<SvtHeaderDataInfo> headers = new ArrayList<SvtHeaderDataInfo>();
+
+        LOGGER.finest("Total data banks found: " + dataBanks.size());
+
+            // Loop over all of the data banks contained by the ROC banks and 
+        // processed them
+        for (BaseStructure dataBank : dataBanks) {
+
+            LOGGER.finest("Processing data bank: " + dataBank.toString());
+
+            // Get the int data encapsulated by the data bank
+            int[] data = dataBank.getIntData();
+            LOGGER.finest("Total number of integers contained by the data bank: " + data.length);
+
+            // Check that a complete set of samples exist
+            int sampleCount = data.length - this.getDataHeaderLength()
+                    - this.getDataTailLength();
+            LOGGER.finest("Total number of  samples: " + sampleCount);
+            if (sampleCount % 4 != 0) {
+                throw new SvtEvioReaderException("[ "
+                        + this.getClass().getSimpleName()
+                        + " ]: Size of samples array is not divisible by 4");
             }
-            
-            // Get the data banks containing the SVT samples.  
-            List<BaseStructure> dataBanks = rocBank.getChildren(); 
-            LOGGER.finest("Total data banks found: " + dataBanks.size());
-            
-            // Loop over all of the data banks contained by the ROC banks and 
-            // processed them
-            for (BaseStructure dataBank : dataBanks) { 
-        
-                LOGGER.finest("Processing data bank: " + dataBank.toString());
-                
-                // Check that the bank is valid
-                if (!this.isValidDataBank(dataBank)) continue;
-                
-                // Get the int data encapsulated by the data bank
-                int[] data = dataBank.getIntData();
-                LOGGER.finest("Total number of integers contained by the data bank: " + data.length);
-        
-                // Check that a complete set of samples exist
-                int sampleCount = data.length - this.getDataHeaderLength()
-                        - this.getDataTailLength();
-                LOGGER.finest("Total number of  samples: " + sampleCount);
-                if (sampleCount % 4 != 0) {
-                    throw new SvtEvioReaderException("[ "
-                            + this.getClass().getSimpleName()
-                            + " ]: Size of samples array is not divisible by 4");
-                }
-                
-                // extract header and tail information
-                SvtHeaderDataInfo headerData = this.extractSvtHeader(dataBank.getHeader().getNumber(), data);
-                
-                // Check that the multisample count is consistent
-                this.checkSvtSampleCount(sampleCount, headerData);
-                
-                // Add header to list
-                headers.add(headerData);
-                
-                
-                // Store the multisample headers
-                // Note that the length is not known but can't be longer than the multisample count
-                // in other words the data can be only header multisamples for example.
-                int multisampleHeaderData[] = new int[sampleCount];
-                int multisampleHeaderIndex = 0;
-
-                LOGGER.finest("sampleCount " + sampleCount);
-                
-                // Loop through all of the samples and make hits
-                for (int samplesN = 0; samplesN < sampleCount; samplesN += 4) {
-                    
-                    int[] samples = new int[4];
-                    System.arraycopy(data, this.getDataHeaderLength() + samplesN, samples, 0, samples.length);
-                    
-                    LOGGER.finest("samplesN " + samplesN + " multisampleHeaderCount " + multisampleHeaderIndex);
-                    if(SvtEvioUtils.isMultisampleHeader(samples))
-                        LOGGER.finest("this is a header multisample for apv " + SvtEvioUtils.getApvFromMultiSample(samples) + " ch " + SvtEvioUtils.getChannelNumber(samples));
-                    else 
-                        LOGGER.finest("this is a data multisample for apv " + SvtEvioUtils.getApvFromMultiSample(samples) + " ch " + SvtEvioUtils.getChannelNumber(samples));
-                    
-                    
+
+            // extract header and tail information
+            SvtHeaderDataInfo headerData = this.extractSvtHeader(dataBank.getHeader().getNumber(), data);
+
+            // Check that the multisample count is consistent
+            this.checkSvtSampleCount(sampleCount, headerData);
+
+            // Add header to list
+            headers.add(headerData);
+
+            // Store the multisample headers
+            // Note that the length is not known but can't be longer than the multisample count
+            // in other words the data can be only header multisamples for example.
+            int multisampleHeaderData[] = new int[sampleCount];
+            int multisampleHeaderIndex = 0;
+
+            LOGGER.finest("sampleCount " + sampleCount);
+
+            List<int[]> multisampleList = SvtEvioUtils.getMultisamples(data, sampleCount, this.getDataHeaderLength());
+            // Loop through all of the samples and make hits
+            for (int[] samples:multisampleList) {
+                if (SvtEvioUtils.isMultisampleHeader(samples)) {
+                    LOGGER.finest("this is a header multisample for apv " + SvtEvioUtils.getApvFromMultiSample(samples) + " ch " + SvtEvioUtils.getChannelNumber(samples));
                     // Extract data words from multisample header and update index
                     multisampleHeaderIndex += this.extractMultisampleHeaderData(samples, multisampleHeaderIndex, multisampleHeaderData);
-                    
-                    // If a set of samples is associated with an APV header or tail, skip it
-                    if (!this.isValidSampleSet(samples)) continue;
-                    rawHits.add(this.makeHit(samples));
+                } else {
+                    LOGGER.finest("this is a data multisample for apv " + SvtEvioUtils.getApvFromMultiSample(samples) + " ch " + SvtEvioUtils.getChannelNumber(samples));
                 }
-                
-                LOGGER.finest("got " +  multisampleHeaderIndex + " multisampleHeaderIndex for " + sampleCount + " sampleCount");
-                
-                // add multisample header tails to header data object
-                this.setMultiSampleHeaders(headerData, multisampleHeaderIndex, multisampleHeaderData);
-
+
+                // If a set of samples is associated with an APV header or tail, skip it
+                if (!this.isValidSampleSet(samples)) {
+                    continue;
+                }
+                rawHits.add(this.makeHit(samples));
             }
+
+            LOGGER.finest("got " + multisampleHeaderIndex + " multisampleHeaderIndex for " + sampleCount + " sampleCount");
+
+            // add multisample header tails to header data object
+            this.setMultiSampleHeaders(headerData, multisampleHeaderIndex, multisampleHeaderData);
+
         }
         
         LOGGER.finest("Total number of RawTrackerHits created: " + rawHits.size());
@@ -281,13 +239,9 @@
         // Add the collection of raw hits to the LCSim event
         lcsimEvent.put(SVT_HIT_COLLECTION_NAME, rawHits, RawTrackerHit.class, flag, READOUT_NAME);
 
-        
         // Process SVT headers
         this.processSvtHeaders(headers, lcsimEvent);
         
-       
-        
-
         return true;
     }
 
@@ -393,26 +347,4 @@
         // Create and return a RawTrackerHit
         return new BaseRawTrackerHit(hitTime, cellID, SvtEvioUtils.getSamples(data), null, sensor);
     }
-    
-    /**
-     *  Retrieve all the banks in an event that match the given tag in their
-     *  header and are not data banks. 
-     *
-     *  @param structure : The event/bank being queried
-     *  @param tag : The tag to match
-     *  @return A collection of all bank structures that pass the filter 
-     *          provided by the event
-     */
-    protected List<BaseStructure> getMatchingBanks(BaseStructure structure, final int tag) { 
-        IEvioFilter filter = new IEvioFilter() { 
-            public boolean accept(StructureType type, IEvioStructure struc) { 
-                return (type == StructureType.BANK) 
-                        && (tag == struc.getHeader().getTag())
-                        && (struc.getHeader().getDataType() == DataType.ALSOBANK);
-            }
-        };
-        return StructureFinder.getMatchingStructures(structure, filter);
-    }
-
-   
 }

Modified: java/trunk/evio/src/main/java/org/hps/evio/SvtEvioReader.java
 =============================================================================
--- java/trunk/evio/src/main/java/org/hps/evio/SvtEvioReader.java	(original)
+++ java/trunk/evio/src/main/java/org/hps/evio/SvtEvioReader.java	Fri Mar 11 18:29:19 2016
@@ -7,7 +7,6 @@
 import org.hps.record.svt.SvtEvioExceptions.SvtEvioHeaderException;
 import org.hps.record.svt.SvtEvioExceptions.SvtEvioReaderException;
 import org.hps.util.Pair;
-import org.jlab.coda.jevio.BaseStructure;
 import org.jlab.coda.jevio.EvioEvent;
 import org.lcsim.detector.tracker.silicon.HpsSiSensor;
 import org.lcsim.event.EventHeader;
@@ -28,6 +27,7 @@
     private static final int DATA_TAIL_LENGTH = 1; 
     public static final int MIN_ROC_BANK_TAG = 51;
     public static final int MAX_ROC_BANK_TAG = 66;
+    public static final int DATA_BANK_TAG = 3;
     private static final int ROC_BANK_NUMBER = 0; 
     
     /**
@@ -50,6 +50,16 @@
         return MAX_ROC_BANK_TAG; 
     }
     
+    @Override
+    protected int getMinDataBankTag() {
+        return DATA_BANK_TAG;
+    }
+
+    @Override
+    protected int getMaxDataBankTag() {
+        return DATA_BANK_TAG;
+    }
+
     /**
      *  Get the SVT ROC bank number of the bank encapsulating the SVT samples.
      * 
@@ -125,36 +135,13 @@
     }
     
     /**
-     *  Check whether a data bank is valid i.e. contains SVT samples only.  For
-     *  the engineering run, a valid data bank has a tag of 3.
-     * 
-     *  @param dataBank - An EVIO bank containing integer data
-     *  @return true if the bank is valid, false otherwise
-     * 
-     */
-    @Override
-    protected boolean isValidDataBank(BaseStructure dataBank) { 
-        
-        // The SVT configuration is stored in a bank with tag equal to 57614.
-        // All other event banks are invalid
-        if (dataBank.getHeader().getTag() == 57614) { 
-            
-            // Store the event bank for processing later.
-            eventBanks.add(dataBank);
-            
-            return false;
-        } else if (dataBank.getHeader().getTag() != 3) return false; 
-        
-        return true; 
-    }
-    
-    /**
      * Check whether the samples are valid. Specifically, check if the samples
      * are APV header or tails.
      * 
      * @param data : sample block of data
      * @return true if the samples are valid, false otherwise
      */
+    @Override
     protected boolean isValidSampleSet(int[] data) {
         return !(SvtEvioUtils.isMultisampleHeader(data) || SvtEvioUtils.isMultisampleTail(data));        
     }
@@ -189,9 +176,6 @@
            }
         }*/
         
-        // Clear out the event banks after they have been processed
-        eventBanks.clear();
-        
         return success;
     }
     

Modified: java/trunk/evio/src/main/java/org/hps/evio/TestRunSvtEvioReader.java
 =============================================================================
--- java/trunk/evio/src/main/java/org/hps/evio/TestRunSvtEvioReader.java	(original)
+++ java/trunk/evio/src/main/java/org/hps/evio/TestRunSvtEvioReader.java	Fri Mar 11 18:29:19 2016
@@ -6,7 +6,6 @@
 import org.hps.record.svt.SvtEvioUtils;
 import org.hps.record.svt.SvtHeaderDataInfo;
 import org.hps.util.Pair;
-import org.jlab.coda.jevio.BaseStructure;
 import org.lcsim.detector.tracker.silicon.HpsSiSensor;
 import org.lcsim.detector.tracker.silicon.HpsTestRunSiSensor;
 import org.lcsim.event.EventHeader;
@@ -28,6 +27,7 @@
     private static final int DATA_HEADER_LENGTH = 7;
     private static final int DATA_TAIL_LENGTH = 1; 
     private static final int MAX_FPGA_ID = 6;
+    public static final int MIN_DATA_BANK_TAG = 0;
     private static final int ROC_BANK_TAG = 3;
     private static final int ROC_BANK_NUMBER = -1; 
     
@@ -54,6 +54,16 @@
     @Override 
     protected int getMaxRocBankTag() { 
         return ROC_BANK_TAG; 
+    }
+    
+    @Override
+    protected int getMinDataBankTag() {
+        return MIN_DATA_BANK_TAG;
+    }
+
+    @Override
+    protected int getMaxDataBankTag() {
+        return MAX_FPGA_ID;
     }
     
     /**
@@ -129,26 +139,12 @@
     }
 
     /**
-     *  Check whether a data bank is valid i.e. contains SVT samples only.  For
-     *  the test run, a valid data bank has a tag in the range 0-6.
-     * 
-     *  @param dataBank - An EVIO bank containing integer data
-     *  @return true if the bank is valid, false otherwise
-     * 
-     */
-    @Override
-    protected boolean isValidDataBank(BaseStructure dataBank) { 
-        if (dataBank.getHeader().getTag() < 0 
-                || dataBank.getHeader().getTag() >= MAX_FPGA_ID) return false; 
-        return true; 
-    }
-    
-    /**
      * Check whether the samples are valid.
      * 
      * @param data : sample block of data
      * @return true if the samples are valid, false otherwise
      */
+    @Override
     protected boolean isValidSampleSet(int[] data) { 
         return true;        
     }

Modified: java/trunk/record-util/src/main/java/org/hps/record/svt/SvtEvioUtils.java
 =============================================================================
--- java/trunk/record-util/src/main/java/org/hps/record/svt/SvtEvioUtils.java	(original)
+++ java/trunk/record-util/src/main/java/org/hps/record/svt/SvtEvioUtils.java	Fri Mar 11 18:29:19 2016
@@ -1,4 +1,10 @@
 package org.hps.record.svt;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.jlab.coda.jevio.BaseStructure;
+import org.jlab.coda.jevio.DataType;
+import org.jlab.coda.jevio.StructureType;
 
 
 /**
@@ -437,6 +443,56 @@
         return samples;
     }
 
+    /**
+     *  Retrieve all the banks in an event that match the given tag in their
+     *  header and are not data banks. 
+     *
+     *  @param evioEvent : The event/bank being queried
+     *  @param tag : The tag to match
+     *  @return A collection of all bank structures that pass the filter 
+     *          provided by the event
+     */
+    public static List<BaseStructure> getROCBanks(BaseStructure evioEvent, int minROCTag, int maxROCTag) {
+        List<BaseStructure> matchingBanks = new ArrayList<BaseStructure>();
+        if (evioEvent.getChildCount() > 0) {
+            for (BaseStructure childBank : evioEvent.getChildrenList()) {
+                if (childBank.getStructureType() == StructureType.BANK
+                        && childBank.getHeader().getDataType() == DataType.ALSOBANK
+                        && childBank.getHeader().getTag() >= minROCTag
+                        && childBank.getHeader().getTag() <= maxROCTag) {
+                    matchingBanks.add(childBank);
+                }
+            }
+        }
+        return matchingBanks;
+    }
+
+    public static List<BaseStructure> getDataBanks(BaseStructure evioEvent, int minROCTag, int maxROCTag, int minDataTag, int maxDataTag) {
+        List<BaseStructure> rocBanks = getROCBanks(evioEvent, minROCTag, maxROCTag);
+        List<BaseStructure> matchingBanks = new ArrayList<BaseStructure>();
+        for (BaseStructure rocBank : rocBanks) {
+            if (rocBank.getChildCount() > 0) {
+                for (BaseStructure childBank : rocBank.getChildrenList()) {
+                    if (childBank.getHeader().getTag() >= minDataTag
+                            && childBank.getHeader().getTag() <= maxDataTag) {
+                        matchingBanks.add(childBank);
+                    }
+                }
+            }
+        }
+        return matchingBanks;
+    }
+    
+    public static List<int[]> getMultisamples(int[] data, int sampleCount, int headerLength) {
+        List<int[]> sampleList = new ArrayList<int[]>();
+        // Loop through all of the samples and make hits
+        for (int samplesN = 0; samplesN < sampleCount; samplesN += 4) {
+            int[] samples = new int[4];
+            System.arraycopy(data, headerLength + samplesN, samples, 0, samples.length);
+            sampleList.add(samples);
+        }
+        return sampleList;
+    }
 
     /**
      *  Private constructor to prevent the class from being instantiated.

Top of Message | Previous Page | Permalink

Advanced Options


Options

Log In

Log In

Get Password

Get Password


Search Archives

Search Archives


Subscribe or Unsubscribe

Subscribe or Unsubscribe


Archives

November 2017
August 2017
July 2017
January 2017
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
December 2013
November 2013

ATOM RSS1 RSS2



LISTSERV.SLAC.STANFORD.EDU

Secured by F-Secure Anti-Virus CataList Email List Search Powered by the LISTSERV Email List Manager

Privacy Notice, Security Notice and Terms of Use