hps-java/src/test/java/org/lcsim
diff -u -r1.6 -r1.7
--- DoEvioTest.java 17 Feb 2012 07:06:44 -0000 1.6
+++ DoEvioTest.java 18 Feb 2012 16:41:21 -0000 1.7
@@ -50,20 +50,21 @@
* This is a test of using jevio routines to read EVIO files.
*
* @author homer
- * @version $Id: DoEvioTest.java,v 1.6 2012/02/17 07:06:44 homer Exp $
+ * @version $Id: DoEvioTest.java,v 1.7 2012/02/18 16:41:21 homer Exp $
*/
public class DoEvioTest extends TestCase {
private LCIOWriter writer;
BaseLCSimEvent newEvent;
- int VERBOSE = 0;
+ int VERBOSE = 2;
/**
* The buffer representing a map of the input file.
*/
- private MappedByteBuffer mappedByteBuffer;
+ private MappedByteBuffer trkByteBuffer;
int eventDataSizeBytes = 8000000;
// byte rawdataInts[] = new byte[eventDataSizeBytes];
int rawdataInts[] = new int[eventDataSizeBytes];
+ int rawdataLength = 0;
public void testDoTestEvio() throws IOException {
System.out.println("Test for EVIO.");
@@ -79,14 +80,14 @@
int DOUBLE64 = (0x8);
int LONG64 = (0x9);
int ULONG64 = (0xa);
- int INT32 = (0xb);
+ final int INT32 = (0xb);
int TAGSEGMENT = (0xc);
int SEGMENT = (0xd);
int BANK = (0xe);
int ALSOBANK = (0x10);
int ALSOSEGMENT = (0x20);
int ALSOTAGSEGMENT = (0x40);
- int TRACKERTAG = (0x0);
+ final int TRACKERTAG = (600);
// String fileName = "/mydat/neal/hps/cedExport/data/dvcs_5_500.ev";
String fileName = "/mydat/myhpstest/hps_test_data_2011_nov_18_1.evio";
@@ -104,11 +105,15 @@
class myListener implements IEvioListener {
public void startEventParse(EvioEvent evioEvent) {
- if (VERBOSE > 4) System.out.println("step2");
+ if (VERBOSE > 4) {
+ System.out.println("step2");
+ }
}
public void endEventParse(EvioEvent evioEvent) {
- if (VERBOSE > 4) System.out.println("step3 - endEventParse");
+ if (VERBOSE > 4) {
+ System.out.println("step3 - endEventParse");
+ }
}
public void gotStructure(EvioEvent evioEvent, IEvioStructure structure) {
@@ -122,8 +127,12 @@
// System.out.println("Tag type = " + header.getTag());
switch (header.getTag()) {
- case 600: //Tracker (will be TRACKERTAG)
+ case TRACKERTAG: //Tracker (will be TRACKERTAG)
// IReadout ro;
+ if (header.getDataType()!=INT32) {
+ System.out.println("Non INT32 Tracker Data!!!");
+ break;
+ }
System.out.println("about to simulate having received tracker EVIO data");
List<RawTrackerHit> raw_hits = new ArrayList<RawTrackerHit>();
@@ -131,55 +140,79 @@
HPSTrackerEvent trkev = new HPSTrackerEvent();
int trkdata[] = structure.getIntData();
+
+ int trklength = header.getLength();
+ IntBuffer trkIntBuffer = IntBuffer.wrap(trkdata);
// for (int ii=0; ii<10; ii++) System.out.println("trkdata["+ii+"] = "+trkdata[ii]+"\t"+Integer.toString(trkdata[ii] & 0xffff, 16).toUpperCase());
-// trkev.setData(trkdata);
- if (VERBOSE > 4) {
- for (int ii = 0; ii < 10; ii++) {
- System.out.println("rawdataInts[" + ii + "] = " + rawdataInts[ii] + "\t"
- + Integer.toString((rawdataInts[ii] >> 16) & 0xffff, 16).toUpperCase() + ":"
- + Integer.toString(rawdataInts[ii] & 0xffff, 16).toUpperCase());
+
+// ---- this is the code needed for real EVIO data (IF! IntBuffer is too slow.)
+// int dataStartMarker = 0;
+// while (dataStartMarker<trklength) {
+// int frameSize = trkdata[dataStartMarker];
+// for (int ii = 1; ii <= frameSize; ii++) {
+// rawdataInts[ii] = trkdata[dataStartMarker+ii];
+// }
+// dataStartMarker+=frameSize;
+// ----------------------------------------------------
+
+//R int frameSize = trkIntBuffer.get();
+//R while (trkIntBuffer.hasRemaining() && frameSize!=0) {
+ int frameSize = trkByteBuffer.getInt();
+ while (trkByteBuffer.hasRemaining() && frameSize != 0) {
+ for (int ii = 0; ii < frameSize; ii++) {
+ rawdataInts[ii] = trkByteBuffer.getInt();
+//R rawdataInts[ii] = trkIntBuffer.get();
}
- }
- trkev.setData(rawdataInts);
- if (VERBOSE>1) System.out.println("starting loop over samples");
-// for (int i = 0; i < header.getNumber(); i++) {
- for (int i = 0; i < trkev.count(); i++) {
if (VERBOSE > 4) {
- System.out.println("sample# = " + i);
- }
- HPSTrackerSample trksamp = trkev.sample(i);
-// System.out.println("got trksamp, trksamp = " + trksamp);
- long chanaddr = trksamp.channel();
- if (VERBOSE > 3) {
- System.out.println("got chanaddr");
- }
- long chanapv = trksamp.apv();
- if (VERBOSE > 3) {
- System.out.println("got apv");
+ for (int ii = 0; ii < 10; ii++) {
+ System.out.println("rawdataInts[" + ii + "] = " + rawdataInts[ii] + "\t"
+ + Integer.toString((rawdataInts[ii] >> 16) & 0xffff, 16).toUpperCase() + ":"
+ + Integer.toString(rawdataInts[ii] & 0xffff, 16).toUpperCase());
+ }
}
- short chanadc[] = new short[6];
- if (VERBOSE > 3) {
- System.out.println("getting sample data");
+ trkev.setSize(frameSize);
+ trkev.setData(rawdataInts);
+ if (VERBOSE > 1) {
+ System.out.println("starting loop over samples");
}
+// for (int i = 0; i < header.getNumber(); i++) {
+ for (int i = 0; i < trkev.count(); i++) {
+ if (VERBOSE > 4) {
+ System.out.println("sample# = " + i);
+ }
+ HPSTrackerSample trksamp = trkev.sample(i);
+// System.out.println("got trksamp, trksamp = " + trksamp);
+ long chanaddr = trksamp.channel();
+ if (VERBOSE > 3) {
+ System.out.println("got CellID");
+ }
+ long chanapv = trksamp.apv();
+ if (VERBOSE > 3) {
+ System.out.println("got apv");
+ }
+ short chanadc[] = new short[6];
+ if (VERBOSE > 3) {
+ System.out.println("getting sample data");
+ }
- for (int isamp = 0; isamp < 6; isamp++) {
+ for (int isamp = 0; isamp < 6; isamp++) {
// System.out.println("sample = " + isamp);
- chanadc[isamp] = (short) trksamp.value(isamp);
- }
- IDetectorElement detector_element = null;
+ chanadc[isamp] = (short) trksamp.value(isamp);
+ }
+ IDetectorElement detector_element = null;
- if (VERBOSE > 2) {
- System.out.println("Creating raw_hit with channel,apv = " + chanaddr + " , " + chanapv + " and adc = " + chanadc[0]);
- }
+ if (VERBOSE > 2) {
+ System.out.println("Creating raw_hit with channel,apv = " + chanaddr + " , " + chanapv + " and adc = " + chanadc[0]);
+ }
- int time = 0; // need to find source of this
- RawTrackerHit raw_hit = new BaseRawTrackerHit(time, chanaddr, chanadc, sim_hits, detector_element);
- // Put hits onto readout and hit list
+ int time = 0; // need to find source of this
+ RawTrackerHit raw_hit = new BaseRawTrackerHit(time, chanaddr, chanadc, sim_hits, detector_element);
+ // Put hits onto readout and hit list
// ro.addHit(raw_hit);
- raw_hits.add(raw_hit);
+ raw_hits.add(raw_hit);
+ }
}
-
if (VERBOSE > 1) {
System.out.println("Show the hits we created ...");
Iterator<RawTrackerHit> rhiter = raw_hits.iterator();
@@ -318,27 +351,23 @@
FileChannel inputChannel = fileInputStream.getChannel();
long sz = inputChannel.size();
- mappedByteBuffer = inputChannel.map(FileChannel.MapMode.READ_ONLY, 0L, sz);
+ trkByteBuffer = inputChannel.map(FileChannel.MapMode.READ_ONLY, 0L, sz);
inputChannel.close(); // this object is no longer needed
// set buffer to beginning
- mappedByteBuffer.position(0);
+ trkByteBuffer.position(0);
int offset = 0;
- int IntsRemaining = mappedByteBuffer.remaining() / 4;
+ rawdataLength = trkByteBuffer.remaining() / 4;
if (VERBOSE > 4) {
- System.out.println("Number of Ints to read is " + IntsRemaining);
+ System.out.println("Number of Ints to read is " + rawdataLength);
}
ByteOrder byteOrder = ByteOrder.LITTLE_ENDIAN;
- mappedByteBuffer.order(byteOrder);
- for (int ii = 0; ii < IntsRemaining; ii++) {
-// System.out.println("rawdataInts["+ii+"]");
- rawdataInts[ii] = mappedByteBuffer.getInt();
- }
+ trkByteBuffer.order(byteOrder);
// int[] header = new int[8000000];
// for (int i = 0; i < 8000000; i++) {
-// header[i] = mappedByteBuffer.getInt();
+// header[i] = trkByteBuffer.getInt();
// }