Commit in hps-java/src/test/java/org/lcsim on MAIN
DoEvioTest.java+288added 1.1
HPSDetectorTag.java+30added 1.1
HPSTrackerEvent.java+133added 1.1
HPSTrackerSample.java+66added 1.1
+517
4 added files
test routines for reading EVIO data files in LCSIM

hps-java/src/test/java/org/lcsim
DoEvioTest.java added at 1.1
diff -N DoEvioTest.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ DoEvioTest.java	14 Feb 2012 03:19:57 -0000	1.1
@@ -0,0 +1,288 @@
+package org.lcsim;
+
+import junit.framework.TestCase;
+
+import org.jlab.coda.jevio.EvioFile;
+import org.jlab.coda.jevio.IEvioListener;
+import org.jlab.coda.jevio.EvioEvent;
+import org.jlab.coda.jevio.BlockHeader;
+import org.jlab.coda.jevio.EventParser;
+import org.lcsim.HPSTrackerSample;
+import org.lcsim.HPSTrackerEvent;
+import org.lcsim.event.RawTrackerHit;
+import org.lcsim.event.base.BaseRawTrackerHit;
+import org.lcsim.detector.IDetectorElement;
+import org.lcsim.event.SimTrackerHit;
+import java.nio.channels.FileChannel;
+
+import java.io.*;
+import java.nio.*;
+import org.jlab.coda.jevio.ByteParser;
+import org.jlab.coda.jevio.IEvioStructure;
+import org.jlab.coda.jevio.BaseStructureHeader;
+import org.jlab.coda.jevio.EvioException;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.logging.Logger;
+import org.lcsim.event.EventHeader;
+import org.lcsim.event.EventHeader.LCMetaData;
+import org.lcsim.util.lcio.LCIOWriter;
+//import org.lcsim.util.lcio.LCIORunHeader;
+import org.lcsim.util.loop.LCIODriver;
+import org.lcsim.event.base.BaseLCSimEvent;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.lcsim.HPSDetectorTag;
+
+/**
+ * This is a test of using jevio routines to read EVIO files.  
+ * 
+ * @author homer
+ * @version $Id: DoEvioTest.java,v 1.1 2012/02/14 03:19:57 homer Exp $
+ */
+public class DoEvioTest extends TestCase {
+
+    private LCIOWriter writer;
+    BaseLCSimEvent newEvent;
+    /**
+     * The buffer representing a map of the input file.
+     */
+    private MappedByteBuffer mappedByteBuffer;
+
+    public void testDoTestEvio() throws IOException {
+        System.out.println("Test for EVIO.");
+
+        int UNKNOWN32 = (0x0);
+        int UINT32 = (0x1);
+        int FLOAT32 = (0x2);
+        int CHARSTAR8 = (0x3);
+        int SHORT16 = (0x4);
+        int USHORT16 = (0x5);
+        int CHAR8 = (0x6);
+        int UCHAR8 = (0x7);
+        int DOUBLE64 = (0x8);
+        int LONG64 = (0x9);
+        int ULONG64 = (0xa);
+        int INT32 = (0xb);
+        int TAGSEGMENT = (0xc);
+        int SEGMENT = (0xd);
+        int BANK = (0xe);
+        int ALSOBANK = (0x10);
+        int ALSOSEGMENT = (0x20);
+        int ALSOTAGSEGMENT = (0x40);
+        int TRACKERTAG = (0x0);
+
+//        String fileName = "/mydat/neal/hps/cedExport/data/dvcs_5_500.ev";
+        String fileName = "/mydat/myhpstest/hps_test_data_2011_nov_18_1.evio";
+// Tracker data file name for testing
+        String TrkFileName = "/mydat/myhpstest/00_baseline.bin";
+
+        ByteBuffer buf = ByteBuffer.allocate(1000 * 8192);
+
+        System.out.println("step1" + TRACKERTAG);
+        // parse bytes
+        class myListener implements IEvioListener {
+
+            public void startEventParse(EvioEvent evioEvent) {
+                System.out.println("step2");
+            }
+
+            public void endEventParse(EvioEvent evioEvent) {
+                System.out.println("step3");
+            }
+
+            public void gotStructure(EvioEvent evioEvent, IEvioStructure structure) {
+
+                BaseStructureHeader header = structure.getHeader();
+
+                System.out.println("------------------");
+                System.out.println("" + structure);
+
+
+                switch (header.getTag()) {
+                    case 0: //Tracker (will be TRACKERTAG)
+//                        IReadout ro;
+                        List<RawTrackerHit> raw_hits = new ArrayList<RawTrackerHit>();
+                        List<SimTrackerHit> sim_hits = new ArrayList<SimTrackerHit>();
+
+                        HPSTrackerEvent trkev = new HPSTrackerEvent();
+                        int trkdata[] = structure.getIntData();
+                        trkev.setData(trkdata);
+                        for (int i = 0; i < header.getNumber(); i++) {
+                            HPSTrackerSample trksamp = trkev.sample(i);
+                            long chanaddr = trksamp.channel();
+                            short chanadc[] = new short[6];
+                            for (int ichan = 0; ichan < 6; ichan++) {
+                                chanadc[0] = (short) trksamp.value(ichan);
+                                int time = 0; // need to find source of this
+                                IDetectorElement detector_element = null;
+                                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);
+                            }
+                            break;
+                        }
+                        switch (header.getDataTypeEnum()) {
+                            case FLOAT32:
+                                System.out.println("        FLOAT VALS");
+                                float floatdata[] = structure.getFloatData();
+                                for (float f : floatdata) {
+                                    System.out.println("         " + f);
+                                }
+                                break;
+
+                            case DOUBLE64:
+                                System.out.println("        DOUBLE VALS");
+                                double doubledata[] = structure.getDoubleData();
+                                for (double d : doubledata) {
+                                    System.out.println("         " + d);
+                                }
+                                break;
+
+                            case SHORT16:
+                                System.out.println("        SHORT VALS");
+                                short shortdata[] = structure.getShortData();
+                                for (short i : shortdata) {
+                                    System.out.println("        0x" + Integer.toHexString(i));
+                                }
+                                break;
+
+                            case INT32:
+                            case UINT32:
+                                System.out.println("        INT VALS");
+                                int intdata[] = structure.getIntData();
+                                for (int i : intdata) {
+                                    System.out.println("        0x" + Integer.toHexString(i));
+                                }
+                                break;
+
+                            case LONG64:
+                                System.out.println("        LONG VALS");
+                                long longdata[] = structure.getLongData();
+                                for (long i : longdata) {
+                                    System.out.println("        0x" + Long.toHexString(i));
+                                }
+                                break;
+
+                            case CHAR8:
+                            case UCHAR8:
+                                System.out.println("        BYTE VALS");
+                                byte bytedata[] = structure.getByteData();
+                                for (byte i : bytedata) {
+                                    System.out.println("         " + i);
+                                }
+                                break;
+
+                            case CHARSTAR8:
+                                System.out.println("        STRING VALS");
+                                String stringdata[] = structure.getStringData();
+                                for (String str : stringdata) {
+                                    System.out.println("         " + str);
+                                }
+                                break;
+                        }
+                }
+            }
+        }
+
+        System.out.println("step7");
+
+        // jump past the block header
+        buf.position(
+                4 * 8);
+//        ByteBuffer buf2 = buf.slice();
+
+
+        System.out.println(
+                "step8");
+//        ByteParser parser = new ByteParser();
+//        buf2.rewind();
+        EvioEvent event = null;
+
+        System.out.println(
+                "step8.1");
+        /*
+         * try {
+        System.out.println("step8.2");
+        event = parser.parseEvent(buf2);
+        System.out.println("step8.3");
+        System.out.println("Event = " + event.toString());
+        } catch (EvioException e) {
+        e.printStackTrace();
+        }
+         */
+
+        System.out.println(
+                "step9");
+        File fileIn = new File(fileName);
+        File trkIn = new File(TrkFileName);
+
+        System.out.println(
+                "read ev file: " + fileName + " size: " + fileIn.length());
+        System.out.println(
+                "read trk file: " + TrkFileName + " size: " + trkIn.length());
+        FileInputStream fileInputStream = new FileInputStream(trkIn);
+        FileChannel inputChannel = fileInputStream.getChannel();
+
+        mappedByteBuffer = inputChannel.map(FileChannel.MapMode.READ_ONLY, 0L, sz);
+
+        inputChannel.close(); // this object is no longer needed
+        // set buffer to beginning
+        mappedByteBuffer.position(0);
+        int eventDataSizeBytes = 8000000;
+                    byte trkbytes[] = new byte[eventDataSizeBytes];
+
+int offset=0;
+int bytesRemaining=0;
+        mappedByteBuffer.get(trkbytes, offset, bytesRemaining);
+
+//        int[] header = new int[8000000];
+//        for (int i = 0; i < 8000000; i++) {
+//            header[i] = mappedByteBuffer.getInt();
+//        }
+
+
+
+        try {
+            EvioFile evioFile = new EvioFile(fileName);
+
+//            EventParser parser = new EventParser();
+//            parser.addEvioListener(new myListener());
+            EventParser.getInstance().addEvioListener(new myListener());
+            int stat = 1;
+            while (stat != 0) {
+                try {
+                    EvioEvent ev = evioFile.nextEvent();
+                    if (ev == null) {
+                        stat = 0;
+                    }
+                    evioFile.parseEvent(ev);
+                    System.out.println("reading event");
+//                    int[] buftt = ev.getEvtArray();
+                    System.out.println("events remaining =" + evioFile.getNumEventsRemaining());
+                    BlockHeader bh = evioFile.getCurrentBlockHeader();
+                    System.out.println("nextEvent: BLOCK HEADER :\n" + bh.toString());
+                } catch (EvioException e) {
+                    System.out.println(e);
+                }
+
+                //                MappedByteBuffer buffer = evioFile.getMappedByteBuffer();
+                System.out.println("step10");
+            }
+        } catch (IOException e) {
+            System.out.println(e);
+        }
+        // read events until eof reached
+    }
+}

hps-java/src/test/java/org/lcsim
HPSDetectorTag.java added at 1.1
diff -N HPSDetectorTag.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ HPSDetectorTag.java	14 Feb 2012 03:19:57 -0000	1.1
@@ -0,0 +1,30 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.lcsim;
+
+/**
+ *
+ * @author neal
+ */
+public enum HPSDetectorTag {
+    TRACKERTAG  (0x0),
+    EMCTAG  (0x1);
+
+    
+        private int value;
+
+        private HPSDetectorTag(int value) {
+                this.value = value;
+        }
+
+        /**
+         * Get the enum's value.
+         * 
+         * @return the value, e.g., 0xe for a BANK
+         */
+        public int getValue() {
+                return value;
+        }
+}
\ No newline at end of file

hps-java/src/test/java/org/lcsim
HPSTrackerEvent.java added at 1.1
diff -N HPSTrackerEvent.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ HPSTrackerEvent.java	14 Feb 2012 03:19:57 -0000	1.1
@@ -0,0 +1,133 @@
+/*
+ * Description : based on the C++ version from Ryan Herbst
+ * 
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ *  Description :
+ * Event Container
+ * Event Data consists of the following: Z[xx:xx] = Zeros
+ *    Frame Size = 1 x 32-bits (32-bit dwords)
+ *    Header = 8 x 32-bits
+ *       Header[0] = Z[19:0], SampleSize[3:0], Revision[7:0]
+ *       Header[1] = FpgaAddress[31:0]
+ *       Header[2] = Sequence[31:0]
+ *       Header[3] = TriggerCode[31:0]
+ *       Header[4] = TempB[15:0], TempA[15:0]
+ *       Header[5] = TempD[15:0], TempC[15:0]
+ *       Header[6] = Z[31:0]
+ *       Header[7] = Z[31:0]
+ *
+ *       Samples... (See TrackerSample.h)
+ *
+ *   Tail = 1 x 32-bits
+ *       Should be zero
+
+ */
+package org.lcsim;
+
+import org.lcsim.HPSTrackerSample;
+
+/**
+ *
+ * @author neal
+ */
+public class HPSTrackerEvent extends HPSTrackerSample {
+
+    double temp;
+    double tk;
+    double res;
+    double volt;
+    int idx;
+    // Temperature Constants
+    double coeffA_ = -1.4141963e1;
+    double coeffB_ = 4.4307830e3;
+    double coeffC_ = -3.4078983e4;
+    double coeffD_ = -8.8941929e6;
+    double t25_ = 10000.0;
+    double k0_ = 273.15;
+    double vmax_ = 2.5;
+    double vref_ = 2.5;
+    double rdiv_ = 10000;
+    double minTemp_ = -50;
+    double maxTemp_ = 150;
+    double incTemp_ = 0.01;
+    int adcCnt_ = 4096;
+    // Temperature lookup table
+    double tempTable_[] = new double[adcCnt_];
+    // Frame Constants
+    int headSize_ = 8;
+    int tailSize_ = 1;
+    int sampleSize_ = 4;
+
+    public void TrackerEvent() {
+
+        // Fill temperature lookup table
+        temp = minTemp_;
+        while (temp < maxTemp_) {
+            tk = k0_ + temp;
+            res = t25_ * Math.exp(coeffA_ + (coeffB_ / tk) + (coeffC_ / (tk * tk)) + (coeffD_ / (tk * tk * tk)));
+            volt = (res * vmax_) / (rdiv_ + res);
+            idx = (int) ((volt / vref_) * (double) (adcCnt_ - 1));
+            if (idx < adcCnt_) {
+                tempTable_[idx] = temp;
+            }
+            temp += incTemp_;
+        }
+    }
+
+    // Set address of data buffer
+    public void setData(int indat[]) {
+        data_ = indat;
+    }
+
+// Get sample size value from header.
+    public int sampleSize() {
+        return ((data_[0] >> 8) & 0xF);
+    }
+
+// Get FpgaAddress value from header.
+    public int fpgaAddress() {
+        return (data_[1]);
+    }
+
+// Get sequence count from header.
+    public int sequence() {
+        return (data_[2]);
+    }
+
+// Get trigger value from header.
+    public int trigger() {
+        return (data_[3]);
+    }
+
+// Get temperature values from header.
+    public double temperature(int index) {
+        switch (index) {
+            case 0:
+                return (tempTable_[(data_[4] & 0x3FFF)]);
+            case 1:
+                return (tempTable_[((data_[4] >> 16) & 0x3FFF)]);
+            case 2:
+                return (tempTable_[(data_[5] & 0x3FFF)]);
+            case 3:
+                return (tempTable_[((data_[5] >> 16) & 0x3FFF)]);
+            default:
+                return (0.0);
+        }
+    }
+
+// Get sample count
+//    int count() {
+//        return ((size_ - (headSize_ + tailSize_)) / sampleSize_);
+//    }
+// Get sample at index
+    public HPSTrackerSample sample(int index) {
+        if (index >= 5) { // should be count()
+            return (null);
+        } else {
+            HPSTrackerSample sample_ = new HPSTrackerSample();
+//            sample_.setData( (data_[headSize_ + (index * sampleSize_)])[];
+            return (sample_);
+        }
+    }
+}

hps-java/src/test/java/org/lcsim
HPSTrackerSample.java added at 1.1
diff -N HPSTrackerSample.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ HPSTrackerSample.java	14 Feb 2012 03:19:57 -0000	1.1
@@ -0,0 +1,66 @@
+/*
+ * Description : based on the C++ version from Ryan Herbst
+ * Sample Container
+ * Sample Data consists of the following: Z[xx:xx] = Zeros, O[xx:xx] = Ones
+ *    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]
+ * 
+ */
+package org.lcsim;
+
+/**
+ *
+ * @author neal
+ */
+public class HPSTrackerSample {
+    // Local data
+
+    protected int ldata_[] = new int[4];
+    // Data pointer
+    protected int data_[];
+
+    public void setData(int data[]) {
+        data_ = data;
+    }
+    //! Get hybrid index.
+    public int hybrid() {
+        return ((data_[0] >> 28) & 0x3);
+    }
+    //! Get apv index.
+
+    public int apv() {
+        return ((data_[0] >> 24) & 0x7);
+    }
+
+    //! Get channel index.
+    public int channel() {
+        return ((data_[0] >> 16) & 0x7F);
+    }
+
+    //! Get FpgaAddress value from header.
+    public int fpgaAddress() {
+        return (data_[0] & 0xFFFF);
+    }
+    //! Get adc value at index.
+
+    public int value(int index) {
+        switch (index) {
+            case 0:
+                return (data_[1] & 0x3FFF);
+            case 1:
+                return ((data_[1] >> 16) & 0x3FFF);
+            case 2:
+                return (data_[2] & 0x3FFF);
+            case 3:
+                return ((data_[2] >> 16) & 0x3FFF);
+            case 4:
+                return (data_[3] & 0x3FFF);
+            case 5:
+                return ((data_[3] >> 16) & 0x3FFF);
+            default:
+                return (0);
+        }
+    }
+}
CVSspam 0.2.12


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