hps-java/src/test/java/org/lcsim/hps/evio
diff -u -r1.1 -r1.2
--- RawTrackerHitToEvio4Converter.java 1 Mar 2012 22:32:30 -0000 1.1
+++ RawTrackerHitToEvio4Converter.java 1 Mar 2012 22:44:20 -0000 1.2
@@ -2,6 +2,7 @@
import java.io.File;
import java.io.IOException;
+import java.net.URL;
import java.nio.ByteOrder;
import java.util.List;
@@ -12,6 +13,7 @@
import org.lcsim.event.EventHeader;
import org.lcsim.event.RawTrackerHit;
import org.lcsim.util.Driver;
+import org.lcsim.util.cache.FileCache;
import org.lcsim.util.loop.LCSimLoop;
/**
@@ -19,16 +21,19 @@
* and compares the two to make sure they match.
*
* @author Jeremy McCormick <[log in to unmask]>
- * @version $Id: RawTrackerHitToEvio4Converter.java,v 1.1 2012/03/01 22:32:30 jeremy Exp $
+ * @version $Id: RawTrackerHitToEvio4Converter.java,v 1.2 2012/03/01 22:44:20 jeremy Exp $
*/
public class RawTrackerHitToEvio4Converter extends Driver {
private final String format = "N(L,I,I)";
private String rawHitCollectionName = "RawTrackerHitMaker_RawTrackerHits";
- private static String lcioFileName = "/u1/hps/trackerTest/ap2.2gev050mevsel_SLIC-v2r11p1_geant4-v9r3p2_QGSP_BERT_HPS-Test-JLAB-v4pt0_trackRecon.slcio";
+ private static String lcioFileName = "ap2.2gev050mevsel_SLIC-v2r11p1_geant4-v9r3p2_QGSP_BERT_HPS-Test-JLAB-v4pt0_trackRecon.slcio";
+ private static String lcioFileUrl = "http://www.lcsim.org/test/hps/" + lcioFileName;
public static void testMe() throws IOException, LoopException {
- File file = new File(lcioFileName);
+ FileCache cache = new FileCache();
+ cache.setCacheDirectory(new File("."));
+ File file = cache.getCachedFile(new URL(lcioFileUrl));
LCSimLoop loop = new LCSimLoop();
loop.setLCIORecordSource(file);
loop.add(new RawTrackerHitToEvio4Converter());
@@ -39,8 +44,8 @@
private static final int BANK_SIZE = 11;
- // Convert a single RawTrackerHit into a CompositeData object. The real converter would put N hits into each CompositeData but
- // this method just contains one hit per composite block (for testing purposes).
+ // Convert a single RawTrackerHit into a CompositeData object. The real converter would put N hits into each object
+ // but this method just puts one hit in each composite block (for testing purposes).
private CompositeData convertToCompositeData(RawTrackerHit hit) {
// Data bank which will include both header and data.
@@ -87,35 +92,31 @@
this.rawHitCollectionName = rawHitCollectionName;
}
- public void startOfData() {
- if (this.rawHitCollectionName == null) {
- throw new RuntimeException("The rawHitCollectName parameter was not set.");
- }
- }
-
public void process(EventHeader event) {
List<RawTrackerHit> hits = event.get(RawTrackerHit.class, rawHitCollectionName);
CompositeData cData = null;
for (RawTrackerHit hit : hits) {
+ // Print out RawTrackerHit.
System.out.println("Converting RawTrackerHit: ");
- System.out.println(" cellID = " + hit.getCellID());
+ System.out.println(" cellID = " + Long.toHexString(hit.getCellID()));
System.out.println(" time = " + hit.getTime());
System.out.println(" adc = " + hit.getADCValues()[0]);
+ // Make composite data.
cData = this.convertToCompositeData(hit);
+ // Print out EVIO.
System.out.println("Converted to EVIO: ");
long cellID = cData.getLong();
- System.out.println(" cellID = " + cellID);
+ System.out.println(" cellID = " + Long.toHexString(cellID));
int time = cData.getInt();
System.out.println(" time = " + time);
int adc = cData.getInt();
System.out.println(" adc = " + adc);
- // Poor man's test assertions...
-
+ // Throw exceptions if data doesn't match...
if (hit.getCellID() != cellID) {
throw new RuntimeException("CellID doesn't match.");
}
@@ -127,99 +128,5 @@
}
System.out.println("----------------------------");
}
-
- //CompositeTester.printCompositeDataObject(cData);
- }
-
- /*
- private CompositeData convertToCompositeData(List<RawTrackerHit> hits) throws EvioException {
-
- // -----------------------------------------------------------
-
- // Need to put in format tag and bank info as below....
-
- //bank[0] = 23; // bank length
- //bank[1] = 6 << 16 | 0xF << 8 | 3; // tag = 6, bank contains composite type, num = 3
-
- // N(I,D,F,2S,8a)
- // first part of composite type (for format) = tagseg (tag & type ignored, len used)
- //bank[2] = 5 << 20 | 0x3 << 16 | 4; // tag = 5, seg has char data, len = 4
-
- // ASCII chars values in latest evio string (array) format, N(I,D,F,2S,8a) with N=2
- //bank[3] = 0x4E << 24 | 0x28 << 16 | 0x49 << 8 | 0x2C; // N ( I ,
- //bank[4] = 0x44 << 24 | 0x2C << 16 | 0x46 << 8 | 0x2C; // D , F ,
- //bank[5] = 0x32 << 24 | 0x53 << 16 | 0x2C << 8 | 0x38 ; // 2 S , 8
- //bank[6] = 0x61 << 24 | 0x29 << 16 | 0x00 << 8 | 0x04 ; // a ) \0 \4
-
- // second part of composite type (for data) = bank (tag, num, type ignored, len used)
- //bank[7] = 16;
- //bank[8] = 6 << 16 | 0xF << 8 | 1;
- //bank[9] = 0x2; // N
- //bank[10] = 0x00001111; // I
-
- // -----------------------------------------------------------
-
- // Need 4 int values for each hit.
- int nhits = hits.size();
-
- // Total bank size.
- int bankSize = headerLen + (nhits * hitSize);
-
- // Create bank with space for header and data.
- int[] bank = new int[bankSize];
-
- // ???????
-
- // Bank size.
- bank[0] = bankSize; // ?
-
- // Make the bank header.
- // FIXME Are these settings right???
- bank[1] = 6 << 16 | 0xF << 8 | 3; // tag = 6, bank contains composite type, num = 3
- bank[2] = 5 << 20 | 0x3 << 16 | 2; // tag = 5, seg has char data, len = 2
-
- // Format string.
- // N(I,
- // L,S)
- bank[3] = (int)format.charAt(0) << 24 | (int)format.charAt(1) << 16 | (int)format.charAt(2) << 8 | (int)format.charAt(3);
- bank[4] = (int)format.charAt(4) << 24 | (int)format.charAt(5) << 16 | (int)format.charAt(6) << 8 | (int)format.charAt(7);
-
- // second part of composite type (for data) = bank (tag, num, type ignored, len used)
- bank[5] = 16;
- bank[6] = 6 << 16 | 0xF << 8 | 1;
- // FIXME Is this right?
- bank[7] = 0x2; // N
- bank[8] = 0x00001111; // I
-
- // ??????????
-
- // Loop over byte array to pack hit data, starting after header.
- int ihit = 0;
- for (int i = headerLen; i < bank.length; i += 4) {
-
- // Get hit.
- RawTrackerHit hit = hits.get(ihit);
-
- // 64-bit ID.
- long id = hit.getCellID();
- bank[i] = (int) (id >>> 32); // higher 32
- bank[i+1] = (int) id; // lower 32 bits
-
- // Time.
- int time = hit.getTime();
- bank[i+2] = time;
-
- // ADC value.
- short adcValue = hit.getADCValues()[0];
- bank[i+3] = adcValue;
-
- // Next hit index.
- ++ihit;
- }
-
- byte[] byteArray = ByteDataTransformer.toBytes(bank, ByteOrder.BIG_ENDIAN);
- return new CompositeData(byteArray, ByteOrder.BIG_ENDIAN);
}
- */
-
}
\ No newline at end of file