Commit in hps-java/src/main/java/org/lcsim/hps/recon/tracking on MAIN | |||
HPSSVTData.java | +154 | -52 | 1.2 -> 1.3 |
Fixed encoding; added ability to decode; Can now create SVT data packet from existing data
diff -u -r1.2 -r1.3 --- HPSSVTData.java 28 Mar 2012 00:07:08 -0000 1.2 +++ HPSSVTData.java 29 Mar 2012 03:55:50 -0000 1.3 @@ -1,102 +1,204 @@
package org.lcsim.hps.recon.tracking;
-//--- org.lcsim ---// -import org.lcsim.detector.tracker.silicon.SiSensor; -
/**
- * - * @author Omar Moreno - * @version $Id: HPSSVTData.java,v 1.2 2012/03/28 00:07:08 jeremy Exp $
+ * + * + * @author Omar Moreno <[log in to unmask]> + * @version $Id: HPSSVTData.java,v 1.3 2012/03/29 03:55:50 omoreno Exp $
*/ public class HPSSVTData {
+ // Masks used to encode SVT hit information + public static final int HYBRID_MASK = 0x3; + public static final int APV_MASK = 0x7; + public static final int CHANNEL_MASK = 0x7F; + public static final int FPGA_MASK = 0xFFFF; + public static final int SAMPLE_MASK = 0x3FFF;
- int[] data = new int[4]; - SiSensor sensor; - Integer channelNumber; - short[] adc; - int apvNumber; - int hybridNumber; - int fpgaNumber;
+ // 4x32 + int[] sample = new int[4];
- public HPSSVTData(SiSensor sensor, Integer channelNumber, short[] adc)
+ /** + * + * Creates an SVT data packet from + * + * @param hybridNumber + * Hybrid number (0-3) + * @param apvNumber + * APV25 chip number (0-4) + * @param channelNumber + * Sensor strip number (0-127) + * @param fpgaAddress + * FPGA address + * @param adc + * ADC samples obtained by sampling the shaper output. Currently, + * six samples are obtained per raw hit. + */ + public HPSSVTData(int hybridNumber, int apvNumber, + int channelNumber, int fpgaAddress, short[] adc)
{
- this.sensor = sensor; - this.adc = adc; - this.channelNumber = channelNumber;
+ this.createSVTDataPacket(hybridNumber, apvNumber, + channelNumber, fpgaAddress, adc); + } + + /** + * Creates and SVT data packet from existing SVT data + * + * @param data + * The packed data as int array of size 4 + */ + public HPSSVTData(int[] data) + { + if(sample.length != 4) + throw new RuntimeException("Data sample size is not valid!");
- createSVTData();
+ this.sample = data;
} /**
- * Get the packed data for this sample. - * @return The packed data as an int array of size 4.
+ * Get the packed data for this sample + * @return sample + * The packed data as an int array of size 4.
*/ public int[] getData() {
- return data;
+ return sample;
}
- private void createSVTData()
+ + /** + * Creates and SVT data packet + */ + private void createSVTDataPacket(int hybridNumber, int apvNumber, + int channelNumber, int fpgaAddress, short[] adc)
{ /* * Sample Data consists of the following: Z[xx:xx] = Zeros, O[xx:xx] = Ones
- * data[0] = O[0], Z[0], Hybrid[1:0], Z[0], ApvChip[2:0], Z[0], Channel[6:0], FpgaAddress[15:0] - * data[1] = Z[1:0], Sample1[13:0]], Z[1:0], Sample0[13:0] - * data[2] = Z[1:0], Sample3[13:0]], Z[1:0], Sample2[13:0] - * data[3] = Z[1:0], Sample5[13:0]], Z[1:0], Sample4[13:0]
+ * sample[0] = O[0], Z[0], Hybrid[1:0], Z[0], ApvChip[2:0], Z[0], Channel[6:0], FpgaAddress[15:0] + * sample[1] = Z[1:0], Sample1[13:0]], Z[1:0], Sample0[13:0] + * sample[2] = Z[1:0], Sample3[13:0]], Z[1:0], Sample2[13:0] + * sample[3] = Z[1:0], Sample5[13:0]], Z[1:0], Sample4[13:0]
*
- * <--Still need to add header and temperature information-->
*/
- //--- data[0] ---// - //---------------//
+ //--- sample[0] ---// + //-----------------//
- // Add the FPGA address - data[0] = ( ~(0xFFFF << 16) & data[0] ) | ( ( fpgaNumber & 0xFFFF ) << 16);
+ // The most significant digit of sample[0] is set to 1 + sample[0] |= 0x80000000;
- // Add the channel number - data[0] = ( ~(0x7F << 22) & data[0] ) | ( ( channelNumber%128 & 0x7F ) << 22);
+ // Insert the hybrid number + sample[0] = (sample[0] &= ~(HYBRID_MASK << 28)) | ((hybridNumber & HYBRID_MASK) << 28);
- // Add the chip number - apvNumber = (int) Math.floor(channelNumber/128); - data[0] = ( ~(0x7 << 26) & data[0] ) | ( ( apvNumber & 0x7 ) << 26);
+ // Insert the APV number + sample[0] = (sample[0] &= ~(APV_MASK << 24)) | ((apvNumber & APV_MASK) << 24);
- // Add the hybrid number - data[0] = ( ~(0x3 << 29) & data[0] ) | ( ( apvNumber & 0x3 ) << 29);
+ // Insert the channel number + sample[0] = (sample[0] &= ~(CHANNEL_MASK << 16)) | ((channelNumber & CHANNEL_MASK) << 16);
- //--- data[1] ----// - //----------------//
+ // Insert the FPGA address + sample[0] = (sample[0] &= ~FPGA_MASK) | (fpgaAddress & FPGA_MASK); + + + //--- sample[1] ----// + //------------------//
// Add sample 0
- data[1] = ( ~(0x3FFF << 14) & data[1] ) | ( ( adc[0] & 0x3FFF ) << 14);
+ sample[1] = (sample[1] &= ~SAMPLE_MASK) | (adc[0] & SAMPLE_MASK);
// Add sample 1
- data[1] = ( ~(0x3FFF << 29) & data[1] ) | ( ( adc[1] & 0x3FFF ) << 29);
+ sample[1] = (sample[1] &= ~(SAMPLE_MASK << 16)) | ((adc[1] & SAMPLE_MASK) << 16); +
- //--- data[2] ----// - //----------------//
+ //--- sample[2] ----// + //------------------//
// Add sample 2
- data[2] = ( ~(0x3FFF << 14) & data[2] ) | ( ( adc[2] & 0x3FFF ) << 14);
+ sample[2] = (sample[2] &= ~SAMPLE_MASK) | (adc[2] & SAMPLE_MASK); +
// Add sample 3
- data[2] = ( ~(0x3FFF << 29) & data[2] ) | ( ( adc[3] & 0x3FFF ) << 29);
+ sample[2] = (sample[2] &= ~(SAMPLE_MASK << 16)) | ((adc[3] & SAMPLE_MASK) << 16); +
- //--- data[3] ----// - //----------------//
+ //--- sample[3] ----// + //------------------//
// Add sample 4
- data[3] = ( ~(0x3FFF << 14) & data[3] ) | ( ( adc[4] & 0x3FFF ) << 14);
+ sample[3] = (sample[3] &= ~SAMPLE_MASK) | (adc[4] & SAMPLE_MASK); +
// Add sample 5
- data[3] = ( ~(0x3FFF << 29) & data[3] ) | ( ( adc[5] & 0x3FFF ) << 29); - -
+ sample[3] = (sample[3] &= ~(SAMPLE_MASK << 16)) | ((adc[5] & SAMPLE_MASK) << 16); +
}
+ /** + * Get the hybrid number associated with this SVT data packet + * @return hybrid number (0-3) + */ + public int getHybridNumber() + { + return (sample[0] >>> 28) & HYBRID_MASK; + }
+ /** + * Get the APV number associated with this SVT data packet + * @return APV number (0-4) + */ + public int getAPVNumber() + { + return (sample[0] >>> 24) & APV_MASK; + } + + /** + * Get the channel number associated with this SVT data packet + * @return channel number (0-127) + */ + public int getChannelNumber() + { + return (sample[0] >>> 16) & CHANNEL_MASK; + }
+ /** + * Get the FPGA address associated with this SVT data packet + * @return FPGA address + */ + public int getFPGAAddress(int data) + { + return sample[0] & FPGA_MASK; + } + + /** + * Get the nth SVT sample + * @param n + * The sample number of interest. Valid values are 0 to 5 + * @throws RuntimeException if the sample number is out of range + * @return ADC value of the nth sample + * + * + */ + public int getSample(int n) + { + + switch(n) { + case 0: + return sample[1] & SAMPLE_MASK; + case 1: + return (sample[1] >>> 16) & SAMPLE_MASK; + case 2: + return sample[2] & SAMPLE_MASK; + case 3: + return (sample[2] >>> 16) & SAMPLE_MASK; + case 4: + return sample[3] & SAMPLE_MASK; + case 5: + return (sample[3] >>> 16) & SAMPLE_MASK; + default: + throw new RuntimeException("Invalid sample number! Valid range of values for n are from 0 - 5"); + } + + }
}
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