Commit in hps-java on MAIN | |||
sandbox/DoEvioTest.java | +406 | added 1.1 | |
/MCRawDataToEvio4Converter_Test.java | +53 | added 1.1 | |
src/test/java/org/lcsim/hps/evio/DoEvioTest.java | -406 | 1.2 removed | |
/MCRawDataToEvio4Converter_Test.java | -53 | 1.3 removed | |
+459 | -459 |
move deprecated stuff to sandbox
diff -N DoEvioTest.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ DoEvioTest.java 29 Apr 2012 23:34:14 -0000 1.1 @@ -0,0 +1,406 @@
+package org.lcsim.hps.evio; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.IntBuffer; +import java.nio.MappedByteBuffer; +import java.nio.channels.FileChannel; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import junit.framework.TestCase; + +import org.jlab.coda.jevio.BaseStructureHeader; +import org.jlab.coda.jevio.EventParser; +import org.jlab.coda.jevio.EvioEvent; +import org.jlab.coda.jevio.EvioException; +import org.jlab.coda.jevio.EvioFile; +import org.jlab.coda.jevio.IBlockHeader; +import org.jlab.coda.jevio.IEvioListener; +import org.jlab.coda.jevio.IEvioStructure; +import org.lcsim.detector.IDetectorElement; +import org.lcsim.event.RawTrackerHit; +import org.lcsim.event.SimTrackerHit; +import org.lcsim.event.base.BaseLCSimEvent; +import org.lcsim.event.base.BaseRawTrackerHit; +import org.lcsim.hps.users.homer.HPSTrackerEvent; +import org.lcsim.hps.users.homer.HPSTrackerSample; +import org.lcsim.hps.recon.tracking.MapDAQCellID; +import org.lcsim.util.lcio.LCIOWriter; + +/** + * This is a test of using jevio routines to read EVIO files. + * + * @author homer + * @version $Id: DoEvioTest.java,v 1.1 2012/04/29 23:34:14 jeremy Exp $ + */ +public class DoEvioTest extends TestCase { + + private LCIOWriter writer; + BaseLCSimEvent newEvent; + int VERBOSE = 2; + + /** + * The buffer representing a map of the input file. + */ + 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."); + + final int UNKNOWN32 = (0x0); + final int UINT32 = (0x1); + final int FLOAT32 = (0x2); + final int CHARSTAR8 = (0x3); + final int SHORT16 = (0x4); + final int USHORT16 = (0x5); + final int CHAR8 = (0x6); + final int UCHAR8 = (0x7); + final int DOUBLE64 = (0x8); + final int LONG64 = (0x9); + final int ULONG64 = (0xa); + final int INT32 = (0xb); + final int TAGSEGMENT = (0xc); + final int SEGMENT = (0xd); + final int BANK = (0xe); + final int ALSOBANK = (0x10); + final int ALSOSEGMENT = (0x20); + final int ALSOTAGSEGMENT = (0x40); + final int TRACKERTAG = (600); + + // load the DAQ to LCSim cell maps +final MapDAQCellID mapcell = new MapDAQCellID(); + mapcell.fillSVTCellMap(); + + // String fileName = "/mydat/neal/hps/cedExport/data/dvcs_5_500.ev"; + String fileName = "/mydat/myhpstest/hps_test_data_2011_nov_18_1.evio"; +// String fileName = "/mydat/myhpstest/sample.dat"; +// Tracker data file name for testing + String TrkFileName = "/mydat/myhpstest/00_baseline.bin"; + + + ByteBuffer buf = ByteBuffer.allocate(1000 * 8192); + + if (VERBOSE > 4) { + System.out.println("step1" + TRACKERTAG); + } + // parse bytes + class myListener implements IEvioListener { + + public void startEventParse(EvioEvent evioEvent) { + if (VERBOSE > 4) { + System.out.println("step2"); + } + } + + public void endEventParse(EvioEvent evioEvent) { + if (VERBOSE > 4) { + System.out.println("step3 - endEventParse"); + } + } + + public void gotStructure(EvioEvent evioEvent, IEvioStructure structure) { + + BaseStructureHeader header = structure.getHeader(); + +// System.out.println("------------------"); + if (VERBOSE > 0) { + System.out.println("" + structure); + } +// System.out.println("Tag type = " + header.getTag()); + + switch (header.getTag()) { + case TRACKERTAG: //Tracker (will be TRACKERTAG) +// IReadout ro; + if (header.getDataType().getValue() != INT32) { // Is this right??? + 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>(); + List<SimTrackerHit> sim_hits = new ArrayList<SimTrackerHit>(); + + 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()); + +// ---- 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(); + } + 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()); + } + } + 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"); + } + int LCSimCellID_ = mapcell.SVTCellIDlookup(chanaddr); + if (VERBOSE > 3) { + System.out.println("got corresponding LCSim CellID = "+LCSimCellID_); + } + + 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++) { +// System.out.println("sample = " + isamp); + + chanadc[isamp] = (short) trksamp.value(isamp); + } + IDetectorElement detector_element = null; + + if (VERBOSE > 2) { + System.out.println("Creating raw_hit with channel,apv = " + LCSimCellID_ + " , " + chanapv + " and adc = " + chanadc[0]); + } + + int time = 0; // need to find source of this + RawTrackerHit raw_hit = new BaseRawTrackerHit(time, LCSimCellID_, chanadc, sim_hits, detector_element); + // Put hits onto readout and hit list +// ro.addHit(raw_hit); + raw_hits.add(raw_hit); + } + } + if (VERBOSE > 1) { + System.out.println("Show the hits we created ..."); + Iterator<RawTrackerHit> rhiter = raw_hits.iterator(); + + while (rhiter.hasNext()) { + RawTrackerHit rh = rhiter.next(); + System.out.println("this hit was created: cellID=" + rh.getCellID() + " adc[0]=" + (rh.getADCValues())[0]); + } + } + switch (header.getDataType()) { + case FLOAT32: + if (VERBOSE > 4) { + System.out.println(" FLOAT VALS"); + } + float floatdata[] = structure.getFloatData(); + for (float f : floatdata) { + if (VERBOSE > 4) { + System.out.println(" " + f); + } + } + break; + + case DOUBLE64: + if (VERBOSE > 4) { + System.out.println(" DOUBLE VALS"); + } + double doubledata[] = structure.getDoubleData(); + for (double d : doubledata) { + if (VERBOSE > 4) { + System.out.println(" " + d); + } + } + break; + + case SHORT16: + if (VERBOSE > 4) { + System.out.println(" SHORT VALS"); + } + short shortdata[] = structure.getShortData(); + for (short i : shortdata) { + if (VERBOSE > 4) { + System.out.println(" 0x" + Integer.toHexString(i)); + } + } + break; + + case INT32: + case UINT32: + if (VERBOSE > 4) { + System.out.println(" INT VALS"); + } + int intdata[] = structure.getIntData(); + for (int i : intdata) { + if (VERBOSE > 4) { + System.out.println(" 0x" + Integer.toHexString(i)); + } + } + break; + + case LONG64: + if (VERBOSE > 4) { + System.out.println(" LONG VALS"); + } + long longdata[] = structure.getLongData(); + for (long i : longdata) { + if (VERBOSE > 4) { + System.out.println(" 0x" + Long.toHexString(i)); + } + } + break; + + case CHAR8: + case UCHAR8: + if (VERBOSE > 4) { + System.out.println(" BYTE VALS"); + } + byte bytedata[] = structure.getByteData(); + for (byte i : bytedata) { + if (VERBOSE > 4) { + 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; + } + } + } + } + + if (VERBOSE > 4) { + System.out.println("step7"); + } + + // jump past the block header + buf.position(4 * 8); +// ByteBuffer buf2 = buf.slice(); + + + if (VERBOSE > 4) { + System.out.println("step8"); + } +// ByteParser parser = new ByteParser(); +// buf2.rewind(); + EvioEvent event = null; + + if (VERBOSE > 4) { + 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(); + + long sz = inputChannel.size(); + trkByteBuffer = inputChannel.map(FileChannel.MapMode.READ_ONLY, 0L, sz); + + inputChannel.close(); // this object is no longer needed + // set buffer to beginning + trkByteBuffer.position(0); + + int offset = 0; + rawdataLength = trkByteBuffer.remaining() / 4; + if (VERBOSE > 4) { + System.out.println("Number of Ints to read is " + rawdataLength); + } + ByteOrder byteOrder = ByteOrder.LITTLE_ENDIAN; + trkByteBuffer.order(byteOrder); + +// int[] header = new int[8000000]; +// for (int i = 0; i < 8000000; i++) { +// header[i] = trkByteBuffer.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()); + IBlockHeader bh = evioFile.getCurrentBlockHeader(); + System.out.println("nextEvent: BLOCK HEADER :\n" + bh.toString()); + } catch (EvioException e) { + System.out.println(e); + } + + // MappedByteBuffer buffer = evioFile.getMappedByteBuffer(); + if (VERBOSE > 4) { + System.out.println("step10"); + } + } + } catch (IOException e) { + System.out.println(e); + } + // read events until eof reached + inputChannel.close(); + + } +}
diff -N MCRawDataToEvio4Converter_Test.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ MCRawDataToEvio4Converter_Test.java 29 Apr 2012 23:34:14 -0000 1.1 @@ -0,0 +1,53 @@
+package org.lcsim.hps.evio; + +import java.io.File; +import java.net.URL; + +import org.lcsim.util.cache.FileCache; +import org.lcsim.util.loop.LCSimLoop; + +public class MCRawDataToEvio4Converter_Test { + + String url = "http://www.lcsim.org/test/hps"; + String fileName = "ap2.2gev050mevsel_SLIC-v2r11p1_geant4-v9r3p2_QGSP_BERT_HPS-Test-JLAB-v4pt0_rawData.slcio"; + + public void testRawDataCnv() throws Exception { + + FileCache cache = new FileCache(); + cache.setCacheDirectory(new File(".testdata")); + File lcioFile = cache.getCachedFile(new URL(url + "/" + fileName)); + + LCSimLoop loop = new LCSimLoop(); + loop.setLCIORecordSource(lcioFile); + MCRawDataToEvio4Converter driver = new MCRawDataToEvio4Converter(); + loop.add(driver); + loop.loop(-1, null); + loop.dispose(); + + /* + Read back EVIO file...very verbose so left commented out for now. + File evioFile = new File("MCRawData.evio"); + EvioReader reader = new EvioReader(evioFile); + EvioEvent event = reader.parseNextEvent(); + while (true) { + System.out.println("read event " + event.getHeader().getNumber()); + if (reader.getNumEventsRemaining() == 0) { + break; + } + event = reader.parseNextEvent(); + + for (BaseStructure bank : event.getChildren() ) { + System.out.println("read bank w/ tag = " + bank.getHeader().getTag() + "; number = " + bank.getHeader().getNumber()); + if (bank.getHeader().getNumber() == 1) { + System.out.println("read tracker bank"); + } + else if (bank.getHeader().getNumber() == 2) { + System.out.println("read ecal bank"); + } + CompositeData cdata = bank.getCompositeData(); + CompositeTester.printCompositeDataObject(cdata); + } + } + */ + } +}
\ No newline at end of file
diff -N DoEvioTest.java --- DoEvioTest.java 29 Apr 2012 02:10:05 -0000 1.2 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,406 +0,0 @@
-package org.lcsim.hps.evio; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.nio.IntBuffer; -import java.nio.MappedByteBuffer; -import java.nio.channels.FileChannel; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import junit.framework.TestCase; - -import org.jlab.coda.jevio.BaseStructureHeader; -import org.jlab.coda.jevio.EventParser; -import org.jlab.coda.jevio.EvioEvent; -import org.jlab.coda.jevio.EvioException; -import org.jlab.coda.jevio.EvioFile; -import org.jlab.coda.jevio.IBlockHeader; -import org.jlab.coda.jevio.IEvioListener; -import org.jlab.coda.jevio.IEvioStructure; -import org.lcsim.detector.IDetectorElement; -import org.lcsim.event.RawTrackerHit; -import org.lcsim.event.SimTrackerHit; -import org.lcsim.event.base.BaseLCSimEvent; -import org.lcsim.event.base.BaseRawTrackerHit; -import org.lcsim.hps.users.homer.HPSTrackerEvent; -import org.lcsim.hps.users.homer.HPSTrackerSample; -import org.lcsim.hps.recon.tracking.MapDAQCellID; -import org.lcsim.util.lcio.LCIOWriter; - -/** - * This is a test of using jevio routines to read EVIO files. - * - * @author homer - * @version $Id: DoEvioTest.java,v 1.2 2012/04/29 02:10:05 meeg Exp $ - */ -public class DoEvioTest extends TestCase { - - private LCIOWriter writer; - BaseLCSimEvent newEvent; - int VERBOSE = 2; - - /** - * The buffer representing a map of the input file. - */ - 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."); - - final int UNKNOWN32 = (0x0); - final int UINT32 = (0x1); - final int FLOAT32 = (0x2); - final int CHARSTAR8 = (0x3); - final int SHORT16 = (0x4); - final int USHORT16 = (0x5); - final int CHAR8 = (0x6); - final int UCHAR8 = (0x7); - final int DOUBLE64 = (0x8); - final int LONG64 = (0x9); - final int ULONG64 = (0xa); - final int INT32 = (0xb); - final int TAGSEGMENT = (0xc); - final int SEGMENT = (0xd); - final int BANK = (0xe); - final int ALSOBANK = (0x10); - final int ALSOSEGMENT = (0x20); - final int ALSOTAGSEGMENT = (0x40); - final int TRACKERTAG = (600); - - // load the DAQ to LCSim cell maps -final MapDAQCellID mapcell = new MapDAQCellID(); - mapcell.fillSVTCellMap(); - - // String fileName = "/mydat/neal/hps/cedExport/data/dvcs_5_500.ev"; - String fileName = "/mydat/myhpstest/hps_test_data_2011_nov_18_1.evio"; -// String fileName = "/mydat/myhpstest/sample.dat"; -// Tracker data file name for testing - String TrkFileName = "/mydat/myhpstest/00_baseline.bin"; - - - ByteBuffer buf = ByteBuffer.allocate(1000 * 8192); - - if (VERBOSE > 4) { - System.out.println("step1" + TRACKERTAG); - } - // parse bytes - class myListener implements IEvioListener { - - public void startEventParse(EvioEvent evioEvent) { - if (VERBOSE > 4) { - System.out.println("step2"); - } - } - - public void endEventParse(EvioEvent evioEvent) { - if (VERBOSE > 4) { - System.out.println("step3 - endEventParse"); - } - } - - public void gotStructure(EvioEvent evioEvent, IEvioStructure structure) { - - BaseStructureHeader header = structure.getHeader(); - -// System.out.println("------------------"); - if (VERBOSE > 0) { - System.out.println("" + structure); - } -// System.out.println("Tag type = " + header.getTag()); - - switch (header.getTag()) { - case TRACKERTAG: //Tracker (will be TRACKERTAG) -// IReadout ro; - if (header.getDataType().getValue() != INT32) { // Is this right??? - 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>(); - List<SimTrackerHit> sim_hits = new ArrayList<SimTrackerHit>(); - - 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()); - -// ---- 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(); - } - 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()); - } - } - 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"); - } - int LCSimCellID_ = mapcell.SVTCellIDlookup(chanaddr); - if (VERBOSE > 3) { - System.out.println("got corresponding LCSim CellID = "+LCSimCellID_); - } - - 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++) { -// System.out.println("sample = " + isamp); - - chanadc[isamp] = (short) trksamp.value(isamp); - } - IDetectorElement detector_element = null; - - if (VERBOSE > 2) { - System.out.println("Creating raw_hit with channel,apv = " + LCSimCellID_ + " , " + chanapv + " and adc = " + chanadc[0]); - } - - int time = 0; // need to find source of this - RawTrackerHit raw_hit = new BaseRawTrackerHit(time, LCSimCellID_, chanadc, sim_hits, detector_element); - // Put hits onto readout and hit list -// ro.addHit(raw_hit); - raw_hits.add(raw_hit); - } - } - if (VERBOSE > 1) { - System.out.println("Show the hits we created ..."); - Iterator<RawTrackerHit> rhiter = raw_hits.iterator(); - - while (rhiter.hasNext()) { - RawTrackerHit rh = rhiter.next(); - System.out.println("this hit was created: cellID=" + rh.getCellID() + " adc[0]=" + (rh.getADCValues())[0]); - } - } - switch (header.getDataType()) { - case FLOAT32: - if (VERBOSE > 4) { - System.out.println(" FLOAT VALS"); - } - float floatdata[] = structure.getFloatData(); - for (float f : floatdata) { - if (VERBOSE > 4) { - System.out.println(" " + f); - } - } - break; - - case DOUBLE64: - if (VERBOSE > 4) { - System.out.println(" DOUBLE VALS"); - } - double doubledata[] = structure.getDoubleData(); - for (double d : doubledata) { - if (VERBOSE > 4) { - System.out.println(" " + d); - } - } - break; - - case SHORT16: - if (VERBOSE > 4) { - System.out.println(" SHORT VALS"); - } - short shortdata[] = structure.getShortData(); - for (short i : shortdata) { - if (VERBOSE > 4) { - System.out.println(" 0x" + Integer.toHexString(i)); - } - } - break; - - case INT32: - case UINT32: - if (VERBOSE > 4) { - System.out.println(" INT VALS"); - } - int intdata[] = structure.getIntData(); - for (int i : intdata) { - if (VERBOSE > 4) { - System.out.println(" 0x" + Integer.toHexString(i)); - } - } - break; - - case LONG64: - if (VERBOSE > 4) { - System.out.println(" LONG VALS"); - } - long longdata[] = structure.getLongData(); - for (long i : longdata) { - if (VERBOSE > 4) { - System.out.println(" 0x" + Long.toHexString(i)); - } - } - break; - - case CHAR8: - case UCHAR8: - if (VERBOSE > 4) { - System.out.println(" BYTE VALS"); - } - byte bytedata[] = structure.getByteData(); - for (byte i : bytedata) { - if (VERBOSE > 4) { - 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; - } - } - } - } - - if (VERBOSE > 4) { - System.out.println("step7"); - } - - // jump past the block header - buf.position(4 * 8); -// ByteBuffer buf2 = buf.slice(); - - - if (VERBOSE > 4) { - System.out.println("step8"); - } -// ByteParser parser = new ByteParser(); -// buf2.rewind(); - EvioEvent event = null; - - if (VERBOSE > 4) { - 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(); - - long sz = inputChannel.size(); - trkByteBuffer = inputChannel.map(FileChannel.MapMode.READ_ONLY, 0L, sz); - - inputChannel.close(); // this object is no longer needed - // set buffer to beginning - trkByteBuffer.position(0); - - int offset = 0; - rawdataLength = trkByteBuffer.remaining() / 4; - if (VERBOSE > 4) { - System.out.println("Number of Ints to read is " + rawdataLength); - } - ByteOrder byteOrder = ByteOrder.LITTLE_ENDIAN; - trkByteBuffer.order(byteOrder); - -// int[] header = new int[8000000]; -// for (int i = 0; i < 8000000; i++) { -// header[i] = trkByteBuffer.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()); - IBlockHeader bh = evioFile.getCurrentBlockHeader(); - System.out.println("nextEvent: BLOCK HEADER :\n" + bh.toString()); - } catch (EvioException e) { - System.out.println(e); - } - - // MappedByteBuffer buffer = evioFile.getMappedByteBuffer(); - if (VERBOSE > 4) { - System.out.println("step10"); - } - } - } catch (IOException e) { - System.out.println(e); - } - // read events until eof reached - inputChannel.close(); - - } -}
diff -N MCRawDataToEvio4Converter_Test.java --- MCRawDataToEvio4Converter_Test.java 23 Mar 2012 22:42:11 -0000 1.3 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,53 +0,0 @@
-package org.lcsim.hps.evio; - -import java.io.File; -import java.net.URL; - -import org.lcsim.util.cache.FileCache; -import org.lcsim.util.loop.LCSimLoop; - -public class MCRawDataToEvio4Converter_Test { - - String url = "http://www.lcsim.org/test/hps"; - String fileName = "ap2.2gev050mevsel_SLIC-v2r11p1_geant4-v9r3p2_QGSP_BERT_HPS-Test-JLAB-v4pt0_rawData.slcio"; - - public void testRawDataCnv() throws Exception { - - FileCache cache = new FileCache(); - cache.setCacheDirectory(new File(".testdata")); - File lcioFile = cache.getCachedFile(new URL(url + "/" + fileName)); - - LCSimLoop loop = new LCSimLoop(); - loop.setLCIORecordSource(lcioFile); - MCRawDataToEvio4Converter driver = new MCRawDataToEvio4Converter(); - loop.add(driver); - loop.loop(-1, null); - loop.dispose(); - - /* - Read back EVIO file...very verbose so left commented out for now. - File evioFile = new File("MCRawData.evio"); - EvioReader reader = new EvioReader(evioFile); - EvioEvent event = reader.parseNextEvent(); - while (true) { - System.out.println("read event " + event.getHeader().getNumber()); - if (reader.getNumEventsRemaining() == 0) { - break; - } - event = reader.parseNextEvent(); - - for (BaseStructure bank : event.getChildren() ) { - System.out.println("read bank w/ tag = " + bank.getHeader().getTag() + "; number = " + bank.getHeader().getNumber()); - if (bank.getHeader().getNumber() == 1) { - System.out.println("read tracker bank"); - } - else if (bank.getHeader().getNumber() == 2) { - System.out.println("read ecal bank"); - } - CompositeData cdata = bank.getCompositeData(); - CompositeTester.printCompositeDataObject(cdata); - } - } - */ - } -}
\ No newline at end of file
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