12 modified files
jevio-base/src/main/java/org/jlab/coda/jevio
diff -u -r1.4 -r1.5
--- BaseStructure.java 8 Mar 2012 20:39:26 -0000 1.4
+++ BaseStructure.java 20 Mar 2012 23:21:49 -0000 1.5
@@ -121,7 +121,7 @@
protected String xmlContentAttributeName;
/**
- * Endianness of the data if appropriate,
+ * Endianness of the raw data if appropriate,
* either {@link ByteOrder#BIG_ENDIAN} or {@link ByteOrder#LITTLE_ENDIAN}.
*/
protected ByteOrder byteOrder;
jevio-base/src/main/java/org/jlab/coda/jevio
diff -u -r1.1 -r1.2
--- BlockHeaderV4.java 28 Feb 2012 19:41:36 -0000 1.1
+++ BlockHeaderV4.java 20 Mar 2012 23:21:49 -0000 1.2
@@ -28,11 +28,11 @@
* |_____________________________________|
* | Event Count |
* |_____________________________________|
- * | unused/reserved |
+ * | reserved 1 |
* |_____________________________________|
* | Bit info | Version |
* |_____________________________________|
- * | unused/reserved |
+ * | reserved 2 |
* |_____________________________________|
* | Magic Int |
* |_____________________________________|
@@ -45,6 +45,8 @@
* NOTE: this value should not be used to parse the following
* events since the first block may have a dictionary whose
* presence is not included in this count.
+ * Reserved 1 = If bits 2-5 in bit info are RocRaw (1), then (in the first block)
+ * this contains the total number of payload banks following
* Bit info & Version = Lowest 8 bits are the version number (4).
* Upper 24 bits contain bit info.
* If a dictionary is included as the first event, bit #9 is set (=1)
@@ -52,9 +54,12 @@
*
*
*
- * Bit info has the first (lowest) 2 bits taken:
- * Bit 0 = true if dictionary is included (relevant for first block only)
- * Bit 1 = true if this block is the last block in file or network transmission
+ * Bit info has the first (lowest) 6 bits taken:
+ * Bit 0 = true if dictionary is included (relevant for first block only)
+ * Bit 1 = true if this block is the last block in file or network transmission
+ * Bits 2-5 = type of events following (ROC Raw = 0, Physics = 1, PartialPhysics = 2,
+ * DisentangledPhysics = 3, User = 4, Control = 5, Prestart = 6, Go = 7,
+ * Pause = 8, End = 9, Other = 15)
*
*
*
@@ -91,6 +96,12 @@
/** The evio version which is always 4. */
private int version;
+ /** Value of first reserved word. */
+ private int reserved1;
+
+ /** Value of second reserved word. */
+ private int reserved2;
+
/** Bit information. Bit one: is the first event a dictionary? */
private BitSet bitInfo = new BitSet(24);
;
@@ -122,6 +133,8 @@
headerLength = 0;
version = 0;
eventCount = 0;
+ reserved1 = 0;
+ reserved2 = 0;
magicNumber = 0;
}
@@ -146,6 +159,8 @@
headerLength = 8;
version = 4;
eventCount = 0;
+ reserved1 = 0;
+ reserved2 = 0;
magicNumber = MAGIC_NUMBER;
}
@@ -240,7 +255,7 @@
/**
* Sets the evio version. Should be 4 but no check is performed here, see
- * {@link EvioFile#nextBlockHeader()}.
+ * {@link EvioReader#nextBlockHeader()}.
*
* @param version the evio version of evio.
*/
@@ -268,6 +283,22 @@
}
/**
+ * Get the value of bits 2-5. If this header is coming from the ROC,
+ * it represents the type of event being sent.
+ *
+ * @return bits 2-5 as an integer, representing event type.
+ */
+ public int getEventType() {
+ int type=0;
+ boolean bitSet;
+ for (int i=0; i < 4; i++) {
+ bitSet = bitInfo.get(i+2);
+ if (bitSet) type |= 1 << i;
+ }
+ return type;
+ }
+
+ /**
* Gets a copy of all stored bit information.
*
* @return copy of BitSet containing all stored bit information.
@@ -303,6 +334,19 @@
}
/**
+ * Sets the right bits int the sixth word corresponding to the given type.
+ * @param type event type as int
+ */
+ public void setEventType(int type) {
+ if (type < 0) type = 0;
+ else if (type > 15) type = 15;
+
+ for (int i=2; i < 6; i++) {
+ bitInfo.set(i, ((type >>> i-2) & 0x1) > 0);
+ }
+ }
+
+ /**
* Calculates the sixth word of this header which has the version number
* in the lowest 8 bits and the bit info in the highest 24 bits.
*
@@ -324,7 +368,7 @@
* Calculates the sixth word of this header which has the version number (4)
* in the lowest 8 bits and the set in the upper 24 bits.
*
- * @param set Bitset containing all bits to be set?
+ * @param set Bitset containing all bits to be set
* @return generated sixth word of this header.
*/
static public int generateSixthWord(BitSet set) {
@@ -347,7 +391,7 @@
* in the lowest 8 bits and the set in the upper 24 bits. The arg isDictionary
* is set in the 9th bit and isEnd is set in the 10th bit.
*
- * @param set Bitset containing all bits to be set?
+ * @param set Bitset containing all bits to be set
* @param isDictionary does this block include an evio xml dictionary as the first event?
* @param isEnd is this the last block of a file or a buffer?
* @return generated sixth word of this header.
@@ -381,6 +425,22 @@
}
}
+ /**
+ * Get the first reserved word.
+ * @return the first reserved word.
+ */
+ public int getReserved1() {
+ return reserved1;
+ }
+
+ /**
+ * Get the second reserved word.
+ * @return the second reserved word.
+ */
+ public int getReserved2() {
+ return reserved2;
+ }
+
/**
* Get the magic number the block (physical record) header which should be 0xc0da0100.
*
jevio-base/src/main/java/org/jlab/coda/jevio
diff -u -r1.3 -r1.4
--- ByteDataTransformer.java 28 Feb 2012 19:41:36 -0000 1.3
+++ ByteDataTransformer.java 20 Mar 2012 23:21:49 -0000 1.4
@@ -864,7 +864,7 @@
else {
return (short)(
(0xff & data[ off]) |
- (0xff & data[1+off] << 8)
+ (0xff & data[1+off]) << 8
);
}
}
@@ -888,7 +888,7 @@
else {
return (short)(
(0xff & b1) |
- (0xff & b2 << 8)
+ (0xff & b2) << 8
);
}
}
jevio-base/src/main/java/org/jlab/coda/jevio
diff -u -r1.4 -r1.5
--- CompositeData.java 16 Mar 2012 20:35:07 -0000 1.4
+++ CompositeData.java 20 Mar 2012 23:21:49 -0000 1.5
@@ -987,6 +987,14 @@
}
/**
+ * This method gets a list of all the n values of the data items inside the composite.
+ * @return list of all the n values of the data items inside the composite.
+ */
+ public List<Integer> getNValues() {
+ return nList;
+ }
+
+ /**
* This methods returns the index of the data item to be returned
* on the next call to one of the get<Type>() methods
* (e.g. {@link #getInt()}.
@@ -1028,6 +1036,18 @@
}
/**
+ * This method gets the next N value item as an Integer object.
+ * @return Integer object, if the correct type of the next data item is NVALUE.
+ * @return null if no more data items or data item is not an NVALUE type.
+ */
+ public Integer getNValue() {
+ if (getIndex > types.size()) return null;
+ DataType type = types.get(getIndex);
+ if (type != DataType.NVALUE) return null;
+ return (Integer) (items.get(getIndex++));
+ }
+
+ /**
* This method gets the next data item (which is of Hollerit type) as an Integer object.
* @return Integer object, if Hollerit is the type of the next data item.
* @return null if no more data items or data item is not a 32 bit signed or
@@ -1356,8 +1376,7 @@
// Move to beginning of tagseg header
int srcDataOffset = srcOff;
int destDataOffset = destOff;
- //if (debug)
- // System.out.println("srcDataOffset = " + srcDataOffset + ", len (Bytes) = " + (4*length) + ", src array len = " + src.length);
+ System.out.println("srcDataOffset = " + srcDataOffset + ", len (Bytes) = " + (4*length) + ", src array len = " + src.length);
ByteBuffer srcBuffer = ByteBuffer.wrap( src, srcDataOffset, 4*length);
ByteBuffer destBuffer = ByteBuffer.wrap(dest, destDataOffset, 4*length);
@@ -2160,6 +2179,8 @@
}
ncnf = i;
nList.add(i);
+ items.add(i);
+ types.add(DataType.NVALUE);
dataIndex += 4;
}
@@ -2205,6 +2226,8 @@
if (swap) i = Integer.reverseBytes(i);
ncnf = i;
nList.add(i);
+ items.add(i);
+ types.add(DataType.NVALUE);
dataIndex += 4;
}
jevio-base/src/main/java/org/jlab/coda/jevio
diff -u -r1.3 -r1.4
--- DataType.java 28 Feb 2012 19:41:36 -0000 1.3
+++ DataType.java 20 Mar 2012 23:21:49 -0000 1.4
@@ -1,5 +1,7 @@
package org.jlab.coda.jevio;
+import org.omg.CORBA.NamedValue;
+
/**
* This an enum used to convert data type numerical values to a more meaningful name. For example, the data type with
* value 0xe corresponds to the enum BANK. Mostly this is used for printing. In this version of evio, the
@@ -7,7 +9,8 @@
* the datatype are now used to store padding data.
*
* @author heddle
- *
+ * @author timmer
+ *
*/
public enum DataType {
@@ -29,12 +32,16 @@
COMPOSITE (0xf),
ALSOBANK (0x10),
ALSOSEGMENT (0x20),
- // This is only used when dealing with COMPOSITE data.
- // It is never transported independently.
- HOLLERIT (0x21);
-// Remove ALSOTAGSEGMENT (0x40) since it was never
-// used and we now need that to store padding data.
-// ALSOTAGSEGMENT (0x40);
+
+ // Remove ALSOTAGSEGMENT (0x40) since it was never
+ // used and we now need that to store padding data.
+ // ALSOTAGSEGMENT (0x40),
+
+ // These 2 types are only used when dealing with COMPOSITE data.
+ // They are never transported independently and are stored in integers.
+ HOLLERIT (0x41),
+ NVALUE (0x42);
+
private int value;
private DataType(int value) {
jevio-base/src/main/java/org/jlab/coda/jevio
diff -u -r1.3 -r1.4
--- Demo.java 28 Feb 2012 19:41:36 -0000 1.3
+++ Demo.java 20 Mar 2012 23:21:49 -0000 1.4
@@ -3,6 +3,7 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.util.BitSet;
/**
* Used for demoing the JEvio library.
@@ -12,12 +13,27 @@
*/
public class Demo implements IEvioListener {
+ public static void main(String args[]) {
+ BitSet bitInfo = new BitSet(24);
+ bitInfo.set(3);
+ bitInfo.set(5);
+
+ int type=0;
+ boolean bitSet;
+ for (int i=0; i < 4; i++) {
+ bitSet = bitInfo.get(i+2);
+ if (bitSet) type |= 1 << i;
+ }
+ System.out.println("Resulting int = 0x" + Integer.toHexString(type));
+ }
+
+
/**
* Main program for testing
*
* @param args the command line arguments.
*/
- public static void main(String args[]) {
+ public static void main2(String args[]) {
System.out.println("Test of EvioFile class.");
String cwd = Environment.getInstance().getCurrentWorkingDirectory();
@@ -29,13 +45,13 @@
String testEventFile = cwd + File.separator + "testdata" + File.separator + "out.ev";
String testDictFile = cwd + File.separator + "testdata" + File.separator + "eviodict.xml";
- EvioFile evioFile = null;
+ EvioReader reader = null;
try {
File file = new File(testEventFile);
System.out.println("ev file: " + testEventFile + " size: " + file.length());
- evioFile = new EvioFile(testEventFile);
+ reader = new EvioReader(testEventFile);
// uncomment below to test a filter
// IEvioFilter myFilter = new IEvioFilter() {
@@ -50,22 +66,22 @@
//add myself as a listener
- evioFile.getParser().addEvioListener(new Demo());
+ reader.getParser().addEvioListener(new Demo());
// create a dictionary, set the global name provider
NameProvider.setProvider(NameProviderFactory.createNameProvider(new File(testDictFile)));
// try a block test
- EvioFileTest.readAllBlockHeadersTest(evioFile);
+ EvioFileTest.readAllBlockHeadersTest(reader);
// try read all events test
- EvioFileTest.readAllEventsTest(evioFile);
+ EvioFileTest.readAllEventsTest(reader);
// just count the blocks
- EvioFileTest.totalBlockCount(evioFile);
+ EvioFileTest.totalBlockCount(reader);
// try processing some events
- EvioFileTest.parseEventsTest(evioFile, 1);
+ EvioFileTest.parseEventsTest(reader, 1);
}
catch (FileNotFoundException e) {
e.printStackTrace();
jevio-base/src/main/java/org/jlab/coda/jevio
diff -u -r1.3 -r1.4
--- EventParser.java 28 Feb 2012 19:41:36 -0000 1.3
+++ EventParser.java 20 Mar 2012 23:21:49 -0000 1.4
@@ -190,16 +190,16 @@
notifyEvioListeners(evioEvent, structure);
} // parseStructure
- /**
- * Create a bank header from the first eight bytes of the data array.
- *
- * @param bytes the byte array, probably from a bank that encloses this new bank.
- * @param offset the offset to start reading from the byte array.
+ /**
+ * Create a bank header from the first eight bytes of the data array.
+ *
+ * @param bytes the byte array, probably from a bank that encloses this new bank.
+ * @param offset the offset to start reading from the byte array.
* @param byteOrder byte order of array, {@link ByteOrder#BIG_ENDIAN} or {@link ByteOrder#LITTLE_ENDIAN}
- * @return the new header.
- */
- static BankHeader createBankHeader(byte bytes[], int offset, ByteOrder byteOrder) {
- BankHeader header = new BankHeader();
+ * @return the new header.
+ */
+ static BankHeader createBankHeader(byte bytes[], int offset, ByteOrder byteOrder) {
+ BankHeader header = new BankHeader();
try {
header.setLength(ByteDataTransformer.toInt(bytes, byteOrder, offset));
jevio-base/src/main/java/org/jlab/coda/jevio
diff -u -r1.3 -r1.4
--- EventWriter.java 28 Feb 2012 19:41:36 -0000 1.3
+++ EventWriter.java 20 Mar 2012 23:21:49 -0000 1.4
@@ -111,6 +111,16 @@
*/
private boolean toFile;
+ /**
+ * Version 4 block header reserved int 1. Used by CODA for source ID in event building.
+ */
+ private int reserved1;
+
+ /**
+ * Version 4 block header reserved int 2.
+ */
+ private int reserved2;
+
//-----------------------
// File related members
//-----------------------
@@ -380,6 +390,56 @@
}
/**
+ * Create an <code>EventWriter</code> for writing events to a ByteBuffer.
+ *
+ * @param buf the buffer to write to.
+ * @param blockSizeMax the max blocksize to use which must be >= 1K and <= 1M ints.
+ * The size of the block will not be larger than this size.
+ * The one exception is when a single event being written is larger
+ * than the max size.
+ * @param blockCountMax the max number of events in a single block which must be
+ * >= 1 and <= 1000.
+ * @param xmlDictionary dictionary in xml format or null if none.
+ * @param bitInfo set of bits to include in first block header.
+ * @param reserved1 set the value of the first "reserved" int in first block header.
+ * NOTE: only CODA (i.e. EMU) software should use this.
+ * @throws EvioException if blockSizeMax or blockCountMax exceed limits; if buf arg is null
+ */
+ public EventWriter(ByteBuffer buf, int blockSizeMax, int blockCountMax,
+ String xmlDictionary, BitSet bitInfo, int reserved1) throws EvioException {
+
+ if (blockSizeMax < 100 || blockSizeMax > 1000000) { // TODO: restore limits
+ throw new EvioException("Pick a block size >= 1K and <= 1M");
+ }
+
+ if (blockCountMax < 1 || blockCountMax > 1000) {
+ throw new EvioException("Pick a block count >= 1 and <= 1000");
+ }
+
+ if (buf == null) {
+ throw new EvioException("Buffer arg cannot be null");
+ }
+
+ toFile = false;
+ this.buffer = buf;
+ this.reserved1 = reserved1;
+ this.blockSizeMax = blockSizeMax;
+ this.blockCountMax = blockCountMax;
+ this.xmlDictionary = xmlDictionary;
+
+ if (bitInfo != null) {
+ this.bitInfo = (BitSet)bitInfo.clone();
+ }
+ else {
+ this.bitInfo = new BitSet(24);
+ }
+
+ if (xmlDictionary != null) {
+ this.bitInfo.set(0,true);
+ }
+ }
+
+ /**
* Set the buffer being written into (initially set in constructor).
* This method allows the user to avoid having to create a new EventWriter
* each time a bank needs to be written to a different buffer.
@@ -490,9 +550,9 @@
blockBuffer.putInt(blockNumber++); // incremental count of blocks
blockBuffer.putInt(8); // header size always 8
blockBuffer.putInt(eventCount); // number of events in block
- blockBuffer.putInt(0); // unused
+ blockBuffer.putInt(reserved1); // unused / sourceId for coda eventbuilding
blockBuffer.putInt(BlockHeaderV4.generateSixthWord(bitInfo)); // version = 4 & bit info stored
- blockBuffer.putInt(0); // unused
+ blockBuffer.putInt(reserved2); // unused
blockBuffer.putInt(IBlockHeader.MAGIC_NUMBER); // MAGIC_NUMBER
}
@@ -542,6 +602,7 @@
fileOutputStream.write(blockBuffer.array(), 0, requiredBufferByteSize);
// finish writing file
+ fileOutputStream.flush();
fileOutputStream.close();
closed = true;
@@ -724,10 +785,10 @@
buffer.putInt(blockNumber++); // incremental count of blocks
buffer.putInt(8); // header size always 8
buffer.putInt(eventCount); // number of events in block
- buffer.putInt(0); // unused
+ buffer.putInt(reserved1); // unused / sourceId for coda eventbuilding
buffer.putInt(BlockHeaderV4.generateSixthWord(bitInfo)); // version = 4 & bit info stored
//System.out.println("writing 6th word = " + BlockHeaderV4.generateSixthWord(bitInfo));
- buffer.putInt(0); // unused
+ buffer.putInt(reserved2); // unused
buffer.putInt(IBlockHeader.MAGIC_NUMBER); // MAGIC_NUMBER
}
@@ -938,8 +999,8 @@
int count = 0;
try {
- //an EvioFile object is used for reading
- EvioFile inFile = new EvioFile(new File(infile));
+ //an EvioReader object is used for reading
+ EvioReader inFile = new EvioReader(new File(infile));
//an EvioWriter object is used for writing
EventWriter eventWriter = new EventWriter(new File(outfile));
//EventWriter eventWriter = new EventWriter(new File(outfile), 8192, true);
@@ -962,7 +1023,7 @@
System.out.println("copied: " + count + " events.");
//compare the two files
- EvioFile.compareEventFiles(new File(infile), new File(outfile));
+ EvioReader.compareEventFiles(new File(infile), new File(outfile));
}
/**
@@ -977,7 +1038,7 @@
int count = 0;
try {
- EvioFile inFile = new EvioFile(new File(infile));
+ EvioReader inFile = new EvioReader(new File(infile));
int eventCount = inFile.getEventCount();
System.out.println("eventCount = " + eventCount);
@@ -1008,7 +1069,7 @@
}
//compare the two files
- EvioFile.compareEventFiles(new File(infile), new File(outfile));
+ EvioReader.compareEventFiles(new File(infile), new File(outfile));
}
jevio-base/src/main/java/org/jlab/coda/jevio
diff -u -r1.3 -r1.4
--- EvioFileTest.java 28 Feb 2012 19:41:36 -0000 1.3
+++ EvioFileTest.java 20 Mar 2012 23:21:49 -0000 1.4
@@ -1,6 +1,7 @@
package org.jlab.coda.jevio;
-import org.jlab.coda.jevio.EvioFile.ReadStatus;
+import org.jlab.coda.jevio.EvioReader.ReadStatus;
+
/**
* A set of static functions that test evio files. It also has some other diagnostic methods for getting counts.
@@ -22,43 +23,44 @@
/**
* Get a total count of the number of physical records.
*
- * @param evioFile the file to be processed.
+ * @param reader reader of the file to be processed.
* @return the total count of blocks (physical records.)
*/
- public static int totalBlockCount(EvioFile evioFile) {
- evioFile.rewind();
- ReadStatus status = ReadStatus.SUCCESS;
+ public static int totalBlockCount(EvioReader reader) {
+ reader.rewind();
+ ReadStatus status = EvioReader.ReadStatus.SUCCESS;
int count = 0;
while (status == ReadStatus.SUCCESS) {
- status = evioFile.nextBlockHeader();
+ status = reader.nextBlockHeader();
if (status == ReadStatus.SUCCESS) {
- evioFile.position(evioFile.getCurrentBlockHeader().nextBufferStartingPosition());
+ reader.position(reader.getCurrentBlockHeader().nextBufferStartingPosition());
count++;
}
}
System.out.println("total block count: " + count);
- evioFile.rewind();
+ reader.rewind();
return count;
- } // totalBlockCount
+ }
+
/**
* Tests whether we can look through the file and find all the block headers.
*
- * @param evioFile the file to be tested.
+ * @param reader reader of the file to be processed.
* @return the result of this test, either PASS or FAIL.
*/
- public static TestResult readAllBlockHeadersTest(EvioFile evioFile) {
- evioFile.rewind();
+ public static TestResult readAllBlockHeadersTest(EvioReader reader) {
+ reader.rewind();
ReadStatus status = ReadStatus.SUCCESS;
int blockCount = 0;
while (status == ReadStatus.SUCCESS) {
- status = evioFile.nextBlockHeader();
+ status = reader.nextBlockHeader();
if (status == ReadStatus.SUCCESS) {
- evioFile.position(evioFile.getCurrentBlockHeader().nextBufferStartingPosition());
+ reader.position(reader.getCurrentBlockHeader().nextBufferStartingPosition());
blockCount++;
}
}
@@ -76,27 +78,28 @@
System.out.println("readAllBlockHeadersTest: " + result);
- evioFile.rewind();
+ reader.rewind();
return result;
- } // readAllBlockHeadersTest
+ }
+
/**
* Tests whether we can look through the file read all the events.
*
- * @param evioFile the file to be tested.
+ * @param reader reader of the file to be processed.
* @return the result of this test, either <code>TestResult.PASS</code> or <code>TestResult.FAIL</code>.
*/
- public static TestResult readAllEventsTest(EvioFile evioFile) {
+ public static TestResult readAllEventsTest(EvioReader reader) {
// store current file position
- int oldPosition = evioFile.position();
+ int oldPosition = reader.position();
- evioFile.rewind();
+ reader.rewind();
EvioEvent event;
int count = 0;
TestResult result = TestResult.PASS;
try {
- while ((event = evioFile.nextEvent()) != null) {
+ while ((event = reader.nextEvent()) != null) {
count++;
BaseStructureHeader header = event.getHeader();
@@ -112,35 +115,36 @@
System.out.println("readAllBlockHeadersTest: " + result);
// restore file position
- evioFile.position(oldPosition);
+ reader.position(oldPosition);
return result;
- } // readAllEventsTest
+ }
+
/**
* Tests whether we can parse events from the file.
*
- * @param evioFile the file to be tested.
+ * @param reader reader of the file to be processed.
* @param num the number to parse. Will try to parse this many (unless it runs out.) Use -1 to parse all events.
* Note: if <code>num</code> is greater than the number of events in the file, it doesn't constitute an
* error.
* @return the result of this test, either <code>TestResult.PASS</code> or <code>TestResult.FAIL</code>.
*/
- public static TestResult parseEventsTest(EvioFile evioFile, int num) {
+ public static TestResult parseEventsTest(EvioReader reader, int num) {
// store current file position
- int oldPosition = evioFile.position();
+ int oldPosition = reader.position();
if (num < 0) {
num = Integer.MAX_VALUE;
}
- evioFile.rewind();
+ reader.rewind();
EvioEvent event;
int count = 0;
TestResult result = TestResult.PASS;
try {
- while ((count < num) && ((event = evioFile.nextEvent()) != null)) {
- evioFile.parseEvent(event);
+ while ((count < num) && ((event = reader.nextEvent()) != null)) {
+ reader.parseEvent(event);
count++;
}
}
@@ -153,8 +157,8 @@
System.out.println("parseEventsTest result: " + result);
// restore file position
- evioFile.position(oldPosition);
+ reader.position(oldPosition);
return result;
- } // readAllEventsTest
+ }
}
jevio-base/src/main/java/org/jlab/coda/jevio
diff -u -r1.1 -r1.2
--- EvioReader.java 28 Feb 2012 19:41:36 -0000 1.1
+++ EvioReader.java 20 Mar 2012 23:21:49 -0000 1.2
@@ -59,31 +59,21 @@
SUCCESS, CANNOT_OPEN_FILE, EVIO_EXCEPTION, UNKNOWN_ERROR
}
- /**
- * Offset to get magic number from start of file.
- */
+ /** Offset to get magic number from start of file. */
private static final int MAGIC_OFFSET = 28;
- /**
- * Offset to get version number from start of file.
- */
+ /** Offset to get version number from start of file. */
private static final int VERSION_OFFSET = 20;
- /**
- * Mask to get version number from 6th int in block.
- */
+ /** Mask to get version number from 6th int in block. */
private static final int VERSION_MASK = 0xff;
- /**
- * Root element tag for XML file
- */
+ /** Root element tag for XML file */
private static final String ROOT_ELEMENT = "evio-data";
- /**
- * Used to assign a transient number [1..n] to events as they are being read.
- */
+ /** Used to assign a transient number [1..n] to events as they are being read. */
private int eventNumber = 0;
/**
@@ -92,9 +82,7 @@
*/
private int eventCount = -1;
- /**
- * Evio version number (1-4). Obtain this by reading first block header.
- */
+ /** Evio version number (1-4). Obtain this by reading first block header. */
private int evioVersion;
/**
@@ -104,24 +92,25 @@
*/
private ByteOrder byteOrder;
- /**
- * The current block header for evio versions 1-3.
- */
+ /** The current block header for evio versions 1-3. */
private BlockHeaderV2 blockHeader2 = new BlockHeaderV2();
- /**
- * The current block header for evio version 4.
- */
+ /** The current block header for evio version 4. */
private BlockHeaderV4 blockHeader4 = new BlockHeaderV4();
- /**
- * Reference to current block header, any version, through interface.
- */
+ /** Reference to current block header, any version, through interface. */
private IBlockHeader blockHeader;
- /**
- * Is this the last block in the file or buffer?
- */
+ /** Block number expected when reading. Used to check sequence of blocks. */
+ private int blockNumberExpected = 1;
+
+ /** Difference between expected & actual block numbers when reading. For warning messages. */
+ private int blockNumberDiff;
+
+ /** If true, throw an exception if block numbers are out of sequence. */
+ private boolean checkBlockNumberSequence;
+
+ /** Is this the last block in the file or buffer? */
private boolean lastBlock;
/**
@@ -130,28 +119,20 @@
*/
private String dictionaryXML;
- /**
- * The buffer being read.
- */
+ /** The buffer being read. */
private ByteBuffer byteBuffer;
- /**
- * Parser object for this file/buffer.
- */
+ /** Parser object for this file/buffer. */
private EventParser parser;
- /**
- * Initial position of buffer or mappedByteBuffer when reading a file.
- */
+ /** Initial position of buffer or mappedByteBuffer when reading a file. */
private int initialPosition;
//------------------------
// File specific members
//------------------------
- /**
- * Absolute path of the underlying file.
- */
+ /** Absolute path of the underlying file. */
private String path;
/**
@@ -239,6 +220,41 @@
parser = new EventParser();
}
+ /**
+ * Is this reader checking the block number sequence and
+ * throwing an exception is it's not sequential and starting with 1?
+ * @return <code>true</code> if checking block number sequence, else <code>false</code>
+ */
+ public boolean checkBlockNumberSequence() {
+ return checkBlockNumberSequence;
+ }
+
+ /**
+ * Set whether this reader will check the block number sequence
+ * and throw an exception is it's not sequential and starting with 1.
+ * This method must be called before parsing events if you want to
+ * change from not checking to checking.
+ * @param checkBlockNumberSequence <code>true</code> to check block number sequence,
+ * else <code>false</code>
+ */
+ public void checkBlockNumberSequence(boolean checkBlockNumberSequence) {
+ // Are we at the top of the file?
+ // If not, do NOT start checking block
+ // numbers part way into reading events.
+ if (byteBuffer.position() != 0 && checkBlockNumberSequence) {
+ return;
+ }
+
+ this.checkBlockNumberSequence = checkBlockNumberSequence;
+ }
+
+ /**
+ * Get the evio version number.
+ * @return evio version number.
+ */
+ public int getEvioVersion() {
+ return evioVersion;
+ }
/**
* Get the path to the file.
@@ -464,6 +480,26 @@
if (evioVersion < 1) {
evioVersion = version;
}
+
+ // check block number if so configured
+ if (checkBlockNumberSequence) {
+ if (blockHeader.getNumber() != blockNumberExpected) {
+System.out.println("block number out of sequence, got " +
+ blockHeader.getNumber() + " expecting " + blockNumberExpected);
+ blockNumberExpected++;
+ return ReadStatus.EVIO_EXCEPTION;
+ }
+ }
+ // otherwise print out a warning if number skips
+ else {
+ if (blockHeader.getNumber() != blockNumberExpected + blockNumberDiff) {
+ System.out.println("block number out of sequence, got " +
+ blockHeader.getNumber() + " expecting " +
+ (blockNumberExpected + blockNumberDiff));
+ }
+ blockNumberDiff = blockHeader.getNumber() - blockNumberExpected;
+ blockNumberExpected++;
+ }
}
catch (EvioException e) {
e.printStackTrace();
jevio-base/src/main/java/org/jlab/coda/jevio/graphics
diff -u -r1.1 -r1.2
--- EventTreeMenu.java 8 Mar 2012 21:05:14 -0000 1.1
+++ EventTreeMenu.java 20 Mar 2012 23:21:49 -0000 1.2
@@ -1179,6 +1179,15 @@
/**
+ * Get the EvioReader object so the file/buffer can be read.
+ * @return EvioReader object
+ */
+ public EvioReader getEvioFileReader() {
+ return evioFileReader;
+ }
+
+
+ /**
* Set the default directory in which to look for event files.
* @param defaultDataDir default directory in which to look for event files
*/
jevio-base/src/main/java/org/jlab/coda/jevio/test
diff -u -r1.1 -r1.2
--- Tester.java 28 Feb 2012 19:41:37 -0000 1.1
+++ Tester.java 20 Mar 2012 23:21:49 -0000 1.2
@@ -39,11 +39,22 @@
System.out.println();
}
-
- /** For testing only */
public static void main(String args[]) {
+ byte[] data = new byte[] {(byte)1, (byte)2};
+ int off=0;
+ // treat the high bit improperly (shift first, then mask, high byte disappears)
+ short s1 = (short) ((0xff & data[ off]) | (0xff & data[1+off] << 8));
+ //proper method
+ short s2 = (short) ((0xff & data[ off]) | (0xff & data[1+off]) << 8);
+ String i1 = Integer.toHexString(ByteDataTransformer.shortBitsToInt(s1));
+ String i2 = Integer.toHexString(ByteDataTransformer.shortBitsToInt(s2));
+ System.out.println("littleE s1 = 0x"+ i1 + ", s2 = 0x" + i2);
+ }
+ /** For testing only */
+ public static void main2(String args[]) {
+
double freq;
long t1, t2, deltaT;
final int LOOPS = 1000000;
CVSspam 0.2.12