Commit in hps-java/src/main/java/org/lcsim/hps on MAIN | |||
recon/tracking/FpgaData.java | +124 | -113 | 1.1 -> 1.2 |
evio/SVTEvioReader.java | +116 | -105 | 1.5 -> 1.6 |
+240 | -218 |
don't choke on bogus or out-of-sequence SVT bank tags
diff -u -r1.1 -r1.2 --- FpgaData.java 28 Apr 2012 23:26:27 -0000 1.1 +++ FpgaData.java 29 Apr 2012 23:06:58 -0000 1.2 @@ -22,121 +22,132 @@
import static org.lcsim.hps.recon.tracking.HPSSVTConstants.TEMP_INC; /**
- * Generic object to contain hybrid temperatures and data tail value. - * Converts and ADC value to a temperature in celsius - *
+ * Generic object to contain hybrid temperatures and data tail value. Converts + * and ADC value to a temperature in celsius + *
* @author Omar Moreno <[log in to unmask]>
- * @version $Id: FpgaData.java,v 1.1 2012/04/28 23:26:27 omoreno Exp $
+ * @version $Id: FpgaData.java,v 1.2 2012/04/29 23:06:58 meeg Exp $
*/ public class FpgaData implements GenericObject {
- List<Double> temperatures = new ArrayList<Double>(); - int tail; - - public static double[] temperatureTable = null; - - /** - * - * @param temperature : array containing hybrid temperatures - * @param tail : word present at the end of a FPGA data set - */ - public FpgaData(int[] data, int tail){ - - int[] temperature = this.extractTemperature(data); - - // Fill the temperature lookup table - this.fillTemperatureTable(); - - this.tail = tail; - - // Fill the temperature list - for(int index = 0; index < temperature.length; index++){ - temperatures.add(temperatureTable[temperature[index]]); - } - } - - /** - * Extract temperatures from the SVT data stream - * - * @param data : array containing temperature data - * @return temperatures - * - */ - public int[] extractTemperature(int[] data) { - int[] temperatures = new int[(data.length) * 2]; - - int tempIndex = 0; - for (int index = 0; index < data.length; index++) { - temperatures[tempIndex] = data[index] & TEMP_MASK; - temperatures[tempIndex + 1] = (data[index] >>> 16) & TEMP_MASK; - tempIndex += 2; - } - return temperatures; - } - - /** - * Temperature lookup table. Takes an ADC value and returns a temperature in Celsius - */ - private void fillTemperatureTable() { - - if(temperatureTable == null){ - temperatureTable = new double[ADC_TEMP_COUNT]; - - double tempK, res, volt; - int idx; - double temp = MIN_TEMP; - - while(temp < MAX_TEMP){ - - tempK = TEMP_K0 + temp; - res = CONST_A*Math.exp(BETA/tempK); - volt = (res*V_MAX)/(R_DIV + res); - idx = (int) ((volt/V_REF)*(double)(ADC_TEMP_COUNT - 1)); - if(idx < ADC_TEMP_COUNT) temperatureTable[idx] = temp; - temp += TEMP_INC; - } - } - } - - - /** - * Get the temperature at a given index - */ - @Override - public double getDoubleVal(int index) { - return temperatures.get(index); - } - - @Override - public float getFloatVal(int index) { - return 0; - } - - /** - * Get the tail value - */ - @Override - public int getIntVal(int index) { - return tail; - } - - @Override - public int getNDouble() { - return temperatures.size(); - } - - @Override - public int getNFloat() { - return 0; - } - - @Override - public int getNInt() { - return 1; - } - - @Override - public boolean isFixedSize() { - return true; - };
+ int fpgaID; + List<Double> temperatures = new ArrayList<Double>(); + int tail; + public static double[] temperatureTable = null; + + /** + * + * @param temperature : array containing hybrid temperatures + * @param tail : word present at the end of a FPGA data set + */ + public FpgaData(int fpgaID, int[] data, int tail) { + this.fpgaID = fpgaID; + + int[] temperature = this.extractTemperature(data); + + // Fill the temperature lookup table + this.fillTemperatureTable(); + + this.tail = tail; + + // Fill the temperature list + for (int index = 0; index < temperature.length; index++) { + temperatures.add(temperatureTable[temperature[index]]); + } + } + + /** + * Extract temperatures from the SVT data stream + * + * @param data : array containing temperature data + * @return temperatures + * + */ + public static int[] extractTemperature(int[] data) { + int[] temperatures = new int[(data.length) * 2]; + + int tempIndex = 0; + for (int index = 0; index < data.length; index++) { + temperatures[tempIndex] = data[index] & TEMP_MASK; + temperatures[tempIndex + 1] = (data[index] >>> 16) & TEMP_MASK; + tempIndex += 2; + } + return temperatures; + } + + /** + * Temperature lookup table. Takes an ADC value and returns a temperature in + * Celsius + */ + private void fillTemperatureTable() { + + if (temperatureTable == null) { + temperatureTable = new double[ADC_TEMP_COUNT]; + + double tempK, res, volt; + int idx; + double temp = MIN_TEMP; + + while (temp < MAX_TEMP) { + + tempK = TEMP_K0 + temp; + res = CONST_A * Math.exp(BETA / tempK); + volt = (res * V_MAX) / (R_DIV + res); + idx = (int) ((volt / V_REF) * (double) (ADC_TEMP_COUNT - 1)); + if (idx < ADC_TEMP_COUNT) { + temperatureTable[idx] = temp; + } + temp += TEMP_INC; + } + } + } + + /** + * Get the temperature at a given index + */ + @Override + public double getDoubleVal(int index) { + return temperatures.get(index); + } + + @Override + public float getFloatVal(int index) { + return 0; + } + + /** + * Get the tail value + */ + @Override + public int getIntVal(int index) { + switch (index) { + case 0: + return fpgaID; + case 1: + return tail; + default: + throw new ArrayIndexOutOfBoundsException(index); + } + } + + @Override + public int getNDouble() { + return temperatures.size(); + } + + @Override + public int getNFloat() { + return 0; + } + + @Override + public int getNInt() { + return 2; + } + + @Override + public boolean isFixedSize() { + return false; + } +;
}
diff -u -r1.5 -r1.6 --- SVTEvioReader.java 29 Apr 2012 16:55:34 -0000 1.5 +++ SVTEvioReader.java 29 Apr 2012 23:06:58 -0000 1.6 @@ -3,6 +3,7 @@
//--- java ---// import java.util.ArrayList; import java.util.List;
+import java.util.Vector;
//--- Coda ---// import org.jlab.coda.jevio.BaseStructure;
@@ -19,118 +20,128 @@
//--- Constants ---// import static org.lcsim.hps.evio.EventConstants.SVT_BANK_TAG;
+import org.lcsim.hps.recon.tracking.HPSSVTConstants;
/**
- *
+ *
* @author Omar Moreno <[log in to unmask]>
- * @version $Id: SVTEvioReader.java,v 1.5 2012/04/29 16:55:34 omoreno Exp $
+ * @version $Id: SVTEvioReader.java,v 1.6 2012/04/29 23:06:58 meeg Exp $
*/ public class SVTEvioReader extends EvioReader {
- - SVTDataToRawTrackerHitDriver hitMaker; - String fpgaDataCollectionName = "FPGAData"; - - /** - * - */ - public SVTEvioReader(){ - hitCollectionName = "SVTData"; - debug = false; - }; - - /** - * - */ - public boolean makeHits(EvioEvent event, EventHeader lcsimEvent){ - // Create a list of HPSSVTData to extract the - List<HPSSVTData> svtData = new ArrayList<HPSSVTData>(); - - // Create a list to hold the temperatures - List<FpgaData> fpgaData = new ArrayList<FpgaData>(); - - boolean foundBank = makeSVTData(event, svtData, fpgaData); - - lcsimEvent.put(hitCollectionName, svtData, HPSSVTData.class, 0); - lcsimEvent.put(fpgaDataCollectionName, fpgaData, GenericObject.class, 0); - - return foundBank; - } -
+ SVTDataToRawTrackerHitDriver hitMaker; + String fpgaDataCollectionName = "FPGAData"; + + /** + * + */ + public SVTEvioReader() { + hitCollectionName = "SVTData"; + debug = false; + } +
/** *
- * @param event - * @return
*/
- public boolean makeSVTData(EvioEvent event, List<HPSSVTData> svtDataCollection , - List<FpgaData> fpgaDataCollection){ - boolean foundBank = false; - for(BaseStructure crateBank : event.getChildren()){ - int crateTag = crateBank.getHeader().getTag(); - - // Process only events inside the SVT Bank - if(crateTag == SVT_BANK_TAG){ - foundBank = true; - if(crateBank.getChildCount() == 0) - throw new RuntimeException("No children found in SVT bank!"); - - // Loop over all FPGA banks - for(BaseStructure fpgaBank : crateBank.getChildren()){ - - // The data contained in FPGA 7 is currently not used - if(fpgaBank.getHeader().getTag() == 7) continue; - - // Get data - int[] data = fpgaBank.getIntData(); - - if(debug) System.out.println(this.getClass().getSimpleName() + ": The data size is " + data.length); - - if(debug){ - for(int index = 0; index < data.length; index++){ - System.out.println("Data " + index + ": " + data[index]); - } - } - - // Get the hybrid temperature data associated with this FPGA - int[] temperatureData = new int[6]; - System.arraycopy(data, 1, temperatureData, 0, 6); - - // Add temperatures to FPGA data container - fpgaDataCollection.add(fpgaBank.getHeader().getTag(), new FpgaData(temperatureData, data[data.length - 1])); - - if(debug){ - System.out.println(this.getClass().getSimpleName() + ": The temperatures are: "); - double[] temps = HPSSVTData.getTemperature(temperatureData); - for(int index = 0; index < temps.length; index++){ - System.out.println("Temp " + index + ": " + temps[index]); - } - } - - // Get all of the samples - int sampleLength = data.length - temperatureData.length - 2; // Tail length - int[] allSamples = new int[sampleLength]; - System.arraycopy(data, 7, allSamples, 0, sampleLength); - - if(debug){ - for(int index = 0; index < allSamples.length; index++){ - System.out.println("Sample " + index + ": " + allSamples[index]); - } - } - - // Check whether a complete set of samples exist - if(allSamples.length % 4 != 0) - throw new RuntimeException("Size of samples array is not divisible by 4!"); - - // Loop over all samples and create HPSSVTData - for(int index = 0; index < allSamples.length; index +=4){ - int[] samples = new int[4]; - System.arraycopy(allSamples, index, samples, 0, samples.length); - svtDataCollection.add(new HPSSVTData(samples)); - } - } - } - } - System.out.println("Adding SVTData Collection of Size " + svtDataCollection.size()); - return foundBank; - }
+ public boolean makeHits(EvioEvent event, EventHeader lcsimEvent) { + // Create a list of HPSSVTData to extract the + List<HPSSVTData> svtData = new ArrayList<HPSSVTData>(); + + // Create a list to hold the temperatures + List<FpgaData> fpgaData = new ArrayList<FpgaData>(); + + boolean foundBank = makeSVTData(event, svtData, fpgaData); + + lcsimEvent.put(hitCollectionName, svtData, HPSSVTData.class, 0); + lcsimEvent.put(fpgaDataCollectionName, fpgaData, GenericObject.class, 0); + + return foundBank; + } + + /** + * + * @param event + * @return + */ + public boolean makeSVTData(EvioEvent event, List<HPSSVTData> svtDataCollection, + List<FpgaData> fpgaDataCollection) { + boolean foundBank = false; + for (BaseStructure crateBank : event.getChildren()) { + int crateTag = crateBank.getHeader().getTag(); + + // Process only events inside the SVT Bank + if (crateTag == SVT_BANK_TAG) { + foundBank = true; + if (crateBank.getChildCount() == 0) { + throw new RuntimeException("No children found in SVT bank!"); + } + + // Loop over all FPGA banks + for (BaseStructure fpgaBank : crateBank.getChildren()) { + int fpgaID = fpgaBank.getHeader().getTag(); + if (fpgaID < 0 || fpgaID >= HPSSVTConstants.SVT_TOTAL_FPGAS) { + System.out.println("Unexpected FPGA bank tag " + fpgaID); + } + + // The data contained in FPGA 7 is currently not used + if (fpgaBank.getHeader().getTag() == 7) { + continue; + } + + // Get data + int[] data = fpgaBank.getIntData(); + + if (debug) { + System.out.println(this.getClass().getSimpleName() + ": The data size is " + data.length); + } + + if (debug) { + for (int index = 0; index < data.length; index++) { + System.out.println("Data " + index + ": " + data[index]); + } + } + + // Get the hybrid temperature data associated with this FPGA + int[] temperatureData = new int[6]; + System.arraycopy(data, 1, temperatureData, 0, 6); + FpgaData fpgaData = new FpgaData(fpgaID, temperatureData, data[data.length - 1]); + fpgaDataCollection.add(fpgaData); + + + if (debug) { + System.out.println(this.getClass().getSimpleName() + ": The temperatures are: "); + double[] temps = HPSSVTData.getTemperature(temperatureData); + for (int index = 0; index < temps.length; index++) { + System.out.println("Temp " + index + ": " + temps[index]); + } + } + + // Get all of the samples + int sampleLength = data.length - temperatureData.length - 2; // Tail length + int[] allSamples = new int[sampleLength]; + System.arraycopy(data, 7, allSamples, 0, sampleLength); + + if (debug) { + for (int index = 0; index < allSamples.length; index++) { + System.out.println("Sample " + index + ": " + allSamples[index]); + } + } + + // Check whether a complete set of samples exist + if (allSamples.length % 4 != 0) { + throw new RuntimeException("Size of samples array is not divisible by 4!"); + } + + // Loop over all samples and create HPSSVTData + for (int index = 0; index < allSamples.length; index += 4) { + int[] samples = new int[4]; + System.arraycopy(allSamples, index, samples, 0, samples.length); + svtDataCollection.add(new HPSSVTData(samples)); + } + } + } + } + System.out.println("Adding SVTData Collection of Size " + svtDataCollection.size()); + return foundBank; + }
}
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