public class RecordHeader extends java.lang.Object implements IBlockHeader
GENERAL RECORD HEADER STRUCTURE ( 56 bytes, 14 integers (32 bit) )
+----------------------------------+
1 | Record Length | // 32bit words, inclusive
+----------------------------------+
2 + Record Number |
+----------------------------------+
3 + Header Length | // 14 (words)
+----------------------------------+
4 + Event (Index) Count |
+----------------------------------+
5 + Index Array Length | // bytes
+-----------------------+----------+
6 + Bit Info | Version | // version (8 bits)
+-----------------------+----------+
7 + User Header Length | // bytes
+----------------------------------+
8 + Magic Number | // 0xc0da0100
+----------------------------------+
9 + Uncompressed Data Length | // bytes
+------+---------------------------+
10 + CT | Data Length Compressed | // CT = compression type (4 bits); compressed len in words
+----------------------------------+
11 + User Register 1 | // UID 1st (64 bits)
+-- --+
12 + |
+----------------------------------+
13 + User Register 2 | // UID 2nd (64 bits)
+-- --+
14 + |
+----------------------------------+
-------------------
Compression Type
-------------------
0 = none
1 = LZ4 fastest
2 = LZ4 best
3 = gzip
-------------------
Bit Info Word
-------------------
0-7 = version
8 = true if dictionary is included (relevant for first record only)
9 = true if this record has "first" event (to be in every split file)
10 = true if this record is the last in file or stream
11-14 = type of events contained: 0 = ROC Raw,
1 = Physics
2 = PartialPhysics
3 = DisentangledPhysics
4 = User
5 = Control
15 = Other
15-19 = reserved
20-21 = pad 1
22-23 = pad 2
24-25 = pad 3
26-27 = reserved
28-31 = general header type: 0 = Evio record,
3 = Evio file trailer
4 = HIPO record,
7 = HIPO file trailer
------------------------------------------------------------
------------------------------------------------------------
TRAILER HEADER STRUCTURE ( 56 bytes, 14 integers (32 bit) )
+----------------------------------+
1 | Record Length | // 32bit words, inclusive
+----------------------------------+
2 + Record Number |
+----------------------------------+
3 + 14 |
+----------------------------------+
4 + 0 |
+----------------------------------+
5 + Index Array Length | // bytes
+-----------------------+----------+
6 + Bit Info | Version |
+-----------------------+----------+
7 + 0 |
+----------------------------------+
8 + 0xc0da0100 |
+----------------------------------+
9 + Uncompressed Data Length | // bytes
+----------------------------------+
10 + 0 |
+----------------------------------+
11 + 0 |
+-- --+
12 + 0 |
+----------------------------------+
13 + 0 |
+-- --+
14 + 0 |
+----------------------------------+
-------------------
Bit Info Word
bit #s = value
-------------------
0-7 = 6
8 = 0
9 = 0
10 = 1
11-14 = 0
15-19 = 0
20-21 = 0
22-23 = 0
24-25 = 0
26-27 = 0
28-31 = 3
------------------------------------------------------------
Modifier and Type | Field and Description |
---|---|
static int |
BIT_INFO_OFFSET
Byte offset from beginning of header to bit info word.
|
static int |
COMPRESSION_TYPE_OFFSET
Byte offset from beginning of header to the compression type and compressed data length word.
|
static int |
EVENT_COUNT_OFFSET
Byte offset from beginning of header to the event index count.
|
static int |
HEADER_LENGTH_OFFSET
Byte offset from beginning of header to the header length.
|
static int |
HEADER_MAGIC
Magic number used to track endianness.
|
static int |
HEADER_SIZE_BYTES
Number of bytes in a normal sized header.
|
static int |
HEADER_SIZE_WORDS
Number of 32-bit words in a normal sized header.
|
static int |
INDEX_ARRAY_OFFSET
Byte offset from beginning of header to the index array length.
|
static int |
LAST_RECORD_MASK
"Last record" is 11th bit in bitInfo word.
|
static int |
MAGIC_OFFSET
Byte offset from beginning of header to the record length.
|
static int |
RECORD_LENGTH_OFFSET
Byte offset from beginning of header to the record length.
|
static int |
RECORD_NUMBER_OFFSET
Byte offset from beginning of header to the record number.
|
static int |
REGISTER1_OFFSET
Byte offset from beginning of header to the user register #1.
|
static int |
REGISTER2_OFFSET
Byte offset from beginning of header to the user register #2.
|
static int |
UNCOMPRESSED_LENGTH_OFFSET
Byte offset from beginning of header to the uncompressed data length.
|
static int |
USER_LENGTH_OFFSET
Byte offset from beginning of header to the user header length.
|
static int |
VERSION_MASK
Mask to get version number from 6th int in header.
|
MAGIC_NUMBER
Constructor and Description |
---|
RecordHeader()
Default, no-arg constructor.
|
RecordHeader(HeaderType type)
Constructor which sets the type of header this is.
|
RecordHeader(long _pos,
int _l,
int _e)
Constructor.
|
RecordHeader(RecordHeader header)
Constructor which copies another header.
|
Modifier and Type | Method and Description |
---|---|
static void |
byteBufferBinaryString(java.nio.ByteBuffer buffer)
Print out each word of the given buffer as binary, hex, and decimal.
|
int |
bytesRemaining(long position)
Gives the bytes remaining in this block (record) given a buffer position.
|
static int |
clearLastRecordBit(int i)
Clear the bit in the given arg to indicate it is NOT the last record.
|
void |
copy(RecordHeader head)
Copy the contents of the arg into this object.
|
long |
firstEventStartingPosition()
Determines where the start of the first event in this block (record) is located
(bytes).
|
static int |
generateSixthWord(java.util.BitSet set)
Calculates the sixth word of this header which has the version
number (6) in the lowest 8 bits and the set in the upper 24 bits.
|
static int |
generateSixthWord(java.util.BitSet bSet,
int version,
boolean hasDictionary,
boolean isEnd,
int eventType)
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.
|
static int |
generateSixthWord(int version,
boolean hasDictionary,
boolean isEnd,
int eventType)
Calculates the sixth word of this header which has the version number
in the lowest 8 bits.
|
int |
getBitInfoWord()
Get the bit info word.
|
long |
getBufferEndingPosition()
Get the position in the buffer (bytes) of this block's last data word.
|
long |
getBufferStartingPosition()
Get the starting position in the buffer (bytes) from which this header was read--if that happened.
This is not part of the block header proper. |
java.nio.ByteOrder |
getByteOrder()
Get the byte order of the file/buffer this header was read from.
|
int |
getCompressedDataLength()
Get the length of the compressed data in bytes.
|
int |
getCompressedDataLengthPadding()
Get the padding of the compressed data in bytes.
|
int |
getCompressedDataLengthWords()
Get the length of the compressed data in words (padded).
|
int |
getCompressedRecordLength()
Get the padded length in bytes of the entire compressed record.
|
CompressionType |
getCompressionType()
Get the type of compression used.
|
int |
getDataLength()
Get the length of the uncompressed data in bytes.
|
int |
getDataLengthWords()
Get the length of the uncompressed data in words (padded).
|
int |
getEntries()
Get the number of events or entries in index.
|
int |
getEventType()
Get the type of events in block/record (see values of
DataType . |
int |
getHeaderLength()
Get the length of this header data in bytes (NOT including user header or index).
|
HeaderType |
getHeaderType()
Get the type of header this is.
|
int |
getHeaderWords()
Get the length of this header data in words.
|
int |
getIndexLength()
Get the length of the index array in bytes.
|
int |
getLength()
Get the total length of this record in bytes.
|
int |
getLengthWords()
Get the total length of this record in 32 bit words.
|
int |
getMagicNumber()
Get the magic number the block (record) header which should be 0xc0da0100.
|
int |
getNumber()
Get the block number for this block (record).
|
long |
getPosition()
Get the position of this record in a file.
|
int |
getRecordNumber()
Get the record number.
|
int |
getSize()
Get the size of the block (record) in 32 bit words.
|
int |
getSourceId()
Get the source ID number if in CODA online context and data is coming from ROC.
|
int |
getTotalHeaderLength()
Get the length of the regular header + index + user header (including padding) in bytes.
|
int |
getUncompressedRecordLength()
Get the padded length in bytes of the entire uncompressed record.
|
int |
getUserHeaderLength()
Get the length of the user-defined header in bytes.
|
int |
getUserHeaderLengthWords()
Get the length of the user-defined header in words.
|
long |
getUserRegisterFirst()
Get the first user-defined 64-bit register.
|
long |
getUserRegisterSecond()
Get the second user-defined 64-bit register.
|
int |
getVersion()
Get the Evio format version number.
|
boolean |
hasDictionary()
Does this record have a dictionary in the user header?
|
int |
hasDictionary(boolean hasFirst)
Set the bit which says record has a dictionary in the user header.
|
static boolean |
hasDictionary(int bitInfo)
Does this bitInfo arg indicate the existence of a dictionary in the user header?
|
boolean |
hasFirstEvent()
Does this header have a first event in the user header?
|
boolean |
isCompressed()
Does this header indicate compressed data?
|
static boolean |
isCompressed(java.nio.ByteBuffer buffer,
int offset)
Quickly check to see if this buffer contains compressed data or not.
|
boolean |
isEvioRecord()
Is this header an evio record?
|
static boolean |
isEvioRecord(int bitInfo)
Does this arg indicate its header is an evio record?
|
boolean |
isEvioTrailer()
Is this header an evio trailer?
|
static boolean |
isEvioTrailer(int bitInfo)
Does this arg indicate its header is an evio trailer?
|
boolean |
isHipoRecord()
Is this header a hipo record?
|
static boolean |
isHipoRecord(int bitInfo)
Does this arg indicate its header is a hipo record?
|
boolean |
isHipoTrailer()
Is this header a hipo trailer?
|
static boolean |
isHipoTrailer(int bitInfo)
Does this arg indicate its header is a hipo trailer?
|
boolean |
isLastBlock()
Is this the last block in the file or being sent over the network?
|
boolean |
isLastRecord()
Is this the header of the last record?
|
int |
isLastRecord(boolean isLast)
Set the bit which says record is last in file/buffer.
|
static boolean |
isLastRecord(int bitInfo)
Does this word indicate this is the header of the last record?
|
static void |
main(java.lang.String[] args)
Run this class as an executable which tests the writing and reading of a record.
|
long |
nextBufferStartingPosition()
Determines where the start of the next block (record) header in some buffer is located (bytes).
|
void |
readHeader(java.nio.ByteBuffer buffer)
Reads the header information from a byte buffer and validates
it by checking the magic word (8th word).
|
void |
readHeader(java.nio.ByteBuffer buffer,
int offset)
Reads the header information from a byte buffer and validates
it by checking the magic word (8th word).
|
void |
reset()
Reset generated data.
|
int |
setBitInfo(boolean isLastRecord,
boolean haveDictionary)
Set the bit info word for a record header.
|
int |
setBitInfoEventType(int type)
Set the bit info of a record header for a specified CODA event type.
|
void |
setBitInfoWord(java.util.BitSet set)
Set the bit info word and related values.
|
void |
setBitInfoWord(int word)
Set the bit info word and related values.
|
void |
setBufferStartingPosition(long bufferStartingPosition)
Set the starting position in the buffer (bytes) from which this header was read--if that happened.
This is not part of the block header proper. |
RecordHeader |
setCompressedDataLength(int length)
Set the compressed data length in bytes and words and the padding.
|
RecordHeader |
setCompressionType(CompressionType type)
Set the compression type.
|
RecordHeader |
setDataLength(int length)
Set the uncompressed data length in bytes and words and the padding.
|
RecordHeader |
setEntries(int n)
Set the number of events or index entries.
|
RecordHeader |
setHeaderLength(int length)
Set the this header's length in bytes and words.
|
RecordHeader |
setIndexLength(int length)
Set the length of the index array in bytes.
|
RecordHeader |
setLength(int length)
Set the record length in bytes and words.
|
RecordHeader |
setPosition(long pos)
Set the position of this record in a file.
|
RecordHeader |
setRecordNumber(int num)
Set the record number.
|
RecordHeader |
setUserHeaderLength(int length)
Set the user-defined header's length in bytes and words and the padding.
|
RecordHeader |
setUserRegisterFirst(long reg)
Set the first, 64-bit, user-defined register.
|
RecordHeader |
setUserRegisterSecond(long reg)
Set the second, 64-bit, user-defined register.
|
java.lang.String |
toString()
Returns a string representation of the record.
|
int |
write(java.nio.ByteBuffer byteBuffer)
Write myself out into a byte buffer.
|
void |
writeHeader(java.nio.ByteBuffer buffer)
Writes this header into the given byte buffer starting at the beginning.
|
void |
writeHeader(java.nio.ByteBuffer buf,
int off)
Writes this header into the given byte buffer.
|
static void |
writeTrailer(byte[] array,
int recordNumber,
java.nio.ByteOrder order)
Writes an empty trailer into the given byte array.
|
static void |
writeTrailer(byte[] array,
int off,
int recordNumber,
java.nio.ByteOrder order,
java.util.List<java.lang.Integer> index)
Writes a trailer with an optional index array into the given byte array.
|
static void |
writeTrailer(java.nio.ByteBuffer buf,
int recordNumber)
Writes an empty trailer into the given buffer.
|
static void |
writeTrailer(java.nio.ByteBuffer buf,
int off,
int recordNumber,
java.util.List<java.lang.Integer> index)
Writes a trailer with an optional index array into the given buffer.
|
public static final int HEADER_SIZE_WORDS
public static final int HEADER_SIZE_BYTES
public static final int HEADER_MAGIC
public static final int RECORD_LENGTH_OFFSET
public static final int RECORD_NUMBER_OFFSET
public static final int HEADER_LENGTH_OFFSET
public static final int EVENT_COUNT_OFFSET
public static final int INDEX_ARRAY_OFFSET
public static final int BIT_INFO_OFFSET
public static final int USER_LENGTH_OFFSET
public static final int MAGIC_OFFSET
public static final int UNCOMPRESSED_LENGTH_OFFSET
public static final int COMPRESSION_TYPE_OFFSET
public static final int REGISTER1_OFFSET
public static final int REGISTER2_OFFSET
public static final int VERSION_MASK
public static final int LAST_RECORD_MASK
public RecordHeader()
public RecordHeader(HeaderType type) throws HipoException
type
- type of header this isHipoException
- if type is for filepublic RecordHeader(RecordHeader header)
header
- header to copy.public RecordHeader(long _pos, int _l, int _e)
_pos
- position in file._l
- length of record in bytes_e
- number of eventspublic void copy(RecordHeader head)
head
- object to copypublic void reset()
public int getUncompressedRecordLength()
public int getCompressedRecordLength()
public java.nio.ByteOrder getByteOrder()
getByteOrder
in interface IBlockHeader
public long getPosition()
public int getLength()
public int getLengthWords()
public int getEntries()
public CompressionType getCompressionType()
getCompressionType
in interface IBlockHeader
public int getUserHeaderLength()
public int getUserHeaderLengthWords()
public int getVersion()
getVersion
in interface IBlockHeader
public int getDataLength()
public int getDataLengthWords()
public int getIndexLength()
public int getCompressedDataLength()
public int getCompressedDataLengthPadding()
public int getCompressedDataLengthWords()
public int getHeaderLength()
public int getHeaderWords()
getHeaderWords
in interface IBlockHeader
public int getTotalHeaderLength()
public int getRecordNumber()
public long getUserRegisterFirst()
public long getUserRegisterSecond()
public HeaderType getHeaderType()
public int setBitInfo(boolean isLastRecord, boolean haveDictionary)
isLastRecord
- true if record is last in stream or file.haveDictionary
- true if record has dictionary in user header.public int getBitInfoWord()
public void setBitInfoWord(int word)
word
- bit info word.public void setBitInfoWord(java.util.BitSet set)
set
- bit info object.public static int generateSixthWord(java.util.BitSet set)
set
- Bitset containing all bits to be setpublic static int generateSixthWord(int version, boolean hasDictionary, boolean isEnd, int eventType)
version
- evio version numberhasDictionary
- does this block include an evio xml dictionary as the first event?isEnd
- is this the last block of a file or a buffer?eventType
- 4 bit type of events header is containingpublic static int generateSixthWord(java.util.BitSet bSet, int version, boolean hasDictionary, boolean isEnd, int eventType)
bSet
- Bitset containing all bits to be setversion
- evio version numberhasDictionary
- does this block include an evio xml dictionary as the first event?isEnd
- is this the last block of a file or a buffer?eventType
- 4 bit type of events header is containingpublic boolean hasFirstEvent()
hasFirstEvent
in interface IBlockHeader
public int hasDictionary(boolean hasFirst)
hasFirst
- true if record has a dictionary in the user header.public boolean hasDictionary()
hasDictionary
in interface IBlockHeader
public static boolean hasDictionary(int bitInfo)
bitInfo
- bitInfo word.public int isLastRecord(boolean isLast)
isLast
- true if record is last in file/buffer.public boolean isLastRecord()
public static boolean isLastRecord(int bitInfo)
bitInfo
- bitInfo word.public boolean isCompressed()
isCompressed
in interface IBlockHeader
public boolean isEvioTrailer()
public boolean isHipoTrailer()
public boolean isEvioRecord()
public boolean isHipoRecord()
public static boolean isEvioTrailer(int bitInfo)
bitInfo
- bitInfo word.public static boolean isHipoTrailer(int bitInfo)
bitInfo
- bitInfo word.public static boolean isEvioRecord(int bitInfo)
bitInfo
- bitInfo word.public static boolean isHipoRecord(int bitInfo)
bitInfo
- bitInfo word.public static int clearLastRecordBit(int i)
i
- integer in which to clear the last-record bitpublic int setBitInfoEventType(int type)
setBitInfo(boolean, boolean)
or
setBitInfoWord(int)
in order to have change preserved.type
- event type (0=ROC raw, 1=Physics, 2=Partial Physics,
3=Disentangled, 4=User, 5=Control, 15=Other,
else = nothing set).public RecordHeader setPosition(long pos)
pos
- position of this record in a file.public RecordHeader setRecordNumber(int num)
num
- record number.public RecordHeader setLength(int length)
length
- length of record in bytes.public RecordHeader setDataLength(int length)
length
- length of uncompressed data in bytes.public RecordHeader setCompressedDataLength(int length)
length
- length of compressed data in bytes.public RecordHeader setIndexLength(int length)
length
- length of index array in bytes.public RecordHeader setCompressionType(CompressionType type)
type
- compression type.public RecordHeader setEntries(int n)
n
- number of events or index entries.public RecordHeader setUserHeaderLength(int length)
length
- user-defined header's length in bytes.public RecordHeader setHeaderLength(int length)
length
- this header's length in bytes.public RecordHeader setUserRegisterFirst(long reg)
reg
- first, 64-bit, user-defined register.public RecordHeader setUserRegisterSecond(long reg)
reg
- second, 64-bit, user-defined register.public void writeHeader(java.nio.ByteBuffer buf, int off) throws HipoException
buf
- byte buffer to write header into.off
- position in buffer to begin writing.HipoException
- if buffer is null or contains too little room.public void writeHeader(java.nio.ByteBuffer buffer) throws HipoException
buffer
- byte buffer to write header into.HipoException
- if buffer arg is null, contains too little room.public static void writeTrailer(byte[] array, int recordNumber, java.nio.ByteOrder order) throws HipoException
array
- byte array to write trailer into.recordNumber
- record number of trailer.order
- byte order of data to be written.HipoException
- if array arg is null or too small to hold trailerpublic static void writeTrailer(byte[] array, int off, int recordNumber, java.nio.ByteOrder order, java.util.List<java.lang.Integer> index) throws HipoException
array
- byte array to write trailer into.off
- offset into array to start writing.recordNumber
- record number of trailer.order
- byte order of data to be written.index
- list of record lengths interspersed with event counts
to be written to trailer. Null if no index list.HipoException
- if array arg is null, array too small to hold trailer + index.public static void writeTrailer(java.nio.ByteBuffer buf, int off, int recordNumber, java.util.List<java.lang.Integer> index) throws HipoException
buf
- ByteBuffer to write trailer into.off
- offset into buffer to start writing.recordNumber
- record number of trailer.index
- list of record lengths interspersed with event counts
to be written to trailer. Null if no index list.HipoException
- if buf arg is null, buf too small to hold trailer + index.public static void writeTrailer(java.nio.ByteBuffer buf, int recordNumber) throws HipoException
buf
- ByteBuffer to write trailer into.recordNumber
- record number of trailer.HipoException
- if buf arg is null or too small to hold trailerpublic static boolean isCompressed(java.nio.ByteBuffer buffer, int offset) throws HipoException
buffer
- buffer to read from.offset
- position of record header to be read.HipoException
- if buffer is null, contains too little data,
or is not in proper format.public void readHeader(java.nio.ByteBuffer buffer, int offset) throws HipoException
buffer
- buffer to read from.offset
- position of first word to be read.HipoException
- if buffer is null, contains too little data,
is not in proper format, or version earlier than 6.public void readHeader(java.nio.ByteBuffer buffer) throws HipoException
buffer
- buffer to read from starting at beginning.HipoException
- if buffer is not in the proper format or earlier than version 6public java.lang.String toString()
toString
in interface IBlockHeader
toString
in class java.lang.Object
public int getSize()
getSize
in interface IBlockHeader
public int getNumber()
getNumber
in interface IBlockHeader
public int getMagicNumber()
getMagicNumber
in interface IBlockHeader
public boolean isLastBlock()
isLastBlock
in interface IBlockHeader
true
if this is the last block in the file or being sent
over the network, else false
.public int getSourceId()
getSourceId
in interface IBlockHeader
public int getEventType()
DataType
.getEventType
in interface IBlockHeader
public int write(java.nio.ByteBuffer byteBuffer)
write
in interface IBlockHeader
byteBuffer
- the byteBuffer to write to.public long getBufferEndingPosition()
getBufferEndingPosition
in interface IBlockHeader
public long getBufferStartingPosition()
getBufferStartingPosition
in interface IBlockHeader
public void setBufferStartingPosition(long bufferStartingPosition)
setBufferStartingPosition
in interface IBlockHeader
bufferStartingPosition
- starting position in buffer from which this header was read--if that
happened.public long nextBufferStartingPosition()
nextBufferStartingPosition
in interface IBlockHeader
public long firstEventStartingPosition()
firstEventStartingPosition
in interface IBlockHeader
public int bytesRemaining(long position) throws EvioException
bufferStartingPosition
is
being maintained properly by the reader. No block is longer than 2.1GB - 31 bits of length. This is for
practical reasons - so a block can be read into a single byte array.bytesRemaining
in interface IBlockHeader
position
- the absolute current position in a byte buffer.EvioException
- if position out of boundspublic static void byteBufferBinaryString(java.nio.ByteBuffer buffer)
buffer
- byffer to print out.public static void main(java.lang.String[] args)
args
- args.