public final class BlockHeaderV2 extends java.lang.Object implements java.lang.Cloneable, IEvioWriter, IBlockHeader
####################################
Evio block header, versions 1,2 & 3:
####################################
MSB(31) LSB(0)
<--- 32 bits ------------------------>
_______________________________________
| Block Length |
|_____________________________________|
| Block Number |
|_____________________________________|
| Header Length = 8 |
|_____________________________________|
| Start |
|_____________________________________|
| End |
|_____________________________________|
| Version |
|_____________________________________|
| Reserved 1 |
|_____________________________________|
| Magic Number |
|_____________________________________|
Block Length = number of ints in block (including this one).
This is fixed for versions 1-3, generally at 8192 (32768 bytes)
Block Number = id number (starting at 0)
Header Length = number of ints in this header (always 8)
Start = offset to first event header in block relative to start of block
End = # of valid words (header + data) in block (normally = block size)
Version = evio format version
Reserved 1 = reserved
Magic # = magic number (0xc0da0100) used to check endianness
| Modifier and Type | Field and Description |
|---|---|
static int |
MAX_BLOCK_SIZE
The maximum block size in 32 bit ints in this implementation of evio.
|
MAGIC_NUMBER| Constructor and Description |
|---|
BlockHeaderV2()
Null constructor initializes all fields to zero.
|
BlockHeaderV2(BlockHeaderV2 blkHeader)
This copy constructor creates an evio version 1-3 BlockHeader
from another object of this class.
|
BlockHeaderV2(int size,
int number)
Creates a BlockHeader for evio versions 1-3 format.
|
| Modifier and Type | Method and Description |
|---|---|
int |
bytesRemaining(long position)
Gives the bytes remaining in this block (physical record) given a buffer position.
|
java.lang.Object |
clone() |
long |
firstEventStartingPosition()
Determines where the start of the first event (logical record) in this block (physical record) is located
(in bytes).
|
long |
getBufferEndingPosition()
Get the position in the buffer (in bytes) of this block's last data word.
|
long |
getBufferStartingPosition()
Get the starting position in the buffer (in 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 data being read.
|
CompressionType |
getCompressionType()
Get the type of data compression used.
|
int |
getEnd()
Get the ending position of the block (physical record.) This is the number of valid words (header + data) in the
block (physical record.) This is normally the same as the block size, except for the last block (physical record)
in the file.
NOTE: for evio files, even if end < size (blocksize) for the last block (physical record), the data behind it will be padded with zeroes so that the file size is an integer multiple of the block size. |
int |
getEventType()
Get the type of events in block (see values of
DataType. |
int |
getHeaderLength()
Get the block header length in ints.
|
int |
getHeaderWords()
Get the block header length, in 32 bit words (ints).
|
int |
getMagicNumber()
Get the magic number the block (physical record) header which should be 0xc0da0100.
|
int |
getNumber()
Get the block number for this block (physical record).
|
int |
getReserved1()
Get the first reserved word in the block (physical record) header.
|
int |
getSize()
Get the size of the block (physical record).
|
int |
getSourceId()
Get the source ID number if in CODA online context and data is coming from ROC.
|
int |
getStart()
Get the starting position of the block (physical record.).
|
int |
getVersion()
Get the evio version of the block (physical record) header.
|
boolean |
hasDictionary()
Gets whether this block's first event is an evio dictionary.
|
boolean |
hasFirstEvent()
Does this block/record contain the "first event"
(first event to be written to each file split)?
First event is not supported by this evio version.
|
boolean |
isCompressed()
Is this the data in this block compressed?
This is always false in evio versions 1-3.
|
boolean |
isLastBlock()
Is this the last block in the file or being sent over the network?
This is not implemented in evio versions 1-3.
|
long |
nextBufferStartingPosition()
Determines where the start of the next block (physical record) header in some buffer is located (in bytes).
|
void |
setBufferStartingPosition(long bufferStartingPosition)
Set the starting position in the buffer (in bytes) from which this header was read--if that happened.
This is not part of the block header proper. |
void |
setByteOrder(java.nio.ByteOrder byteOrder)
Sets the byte order of data being read.
|
void |
setEnd(int end)
Set the ending position of the block (physical record.) This is the number of valid words (header + data) in the
block (physical record.) This is normally the same as the block size, except for the last block (physical record)
in the file.
|
void |
setHeaderLength(int headerLength)
Set the block header length, in ints.
|
void |
setMagicNumber(int magicNumber)
Sets the value of magicNumber.
|
void |
setNumber(int number)
Set the block number for this block (physical record).
|
void |
setReserved1(int reserved1)
Sets the value of reserved 1.
|
void |
setSize(int size)
Set the size of the block (physical record).
|
void |
setStart(int start)
Set the starting position of the block (physical record.).
|
void |
setVersion(int version)
Sets the evio version.
|
java.lang.String |
toString()
Obtain a string representation of the block (physical record) header.
|
int |
write(java.nio.ByteBuffer byteBuffer)
Write myself out a byte buffer.
|
public static final int MAX_BLOCK_SIZE
public BlockHeaderV2()
public BlockHeaderV2(int size,
int number)
block size
and block number are provided. The other six words, which can be
modified by setters, are initialized to these values:headerLength is initialized to 8start is initialized to 8end is initialized to sizeversion is initialized to 2reserved1 is initialized to 0magicNumber is initialized to MAGIC_NUMBERsize - the size of the block in ints.number - the block number--usually sequential.public BlockHeaderV2(BlockHeaderV2 blkHeader)
blkHeader - block header object to copypublic int getSize()
getSize in interface IBlockHeaderpublic java.lang.Object clone()
clone in class java.lang.Objectpublic boolean hasDictionary()
hasDictionary in interface IBlockHeaderpublic boolean isLastBlock()
isLastBlock in interface IBlockHeaderpublic boolean isCompressed()
isCompressed in interface IBlockHeaderfalse.public CompressionType getCompressionType()
CompressionType.RECORD_UNCOMPRESSED in evio versions 1-3.getCompressionType in interface IBlockHeaderpublic void setSize(int size)
throws EvioException
size - the new value for the size, in ints.EvioException - if size < 8 or > MAX_BLOCK_SIZEpublic int getStart()
start = 0.
NOTE: a logical record (event) that spans three blocks (physical records) will have start = 0.public void setStart(int start)
throws EvioException
start = 0.
NOTE: a logical record (event) that spans three blocks (physical records) will have start = 0.start - the new value for the start.EvioException - if start < 8 or > MAX_BLOCK_SIZEpublic int getEnd()
public void setEnd(int end)
throws EvioException
end - the new value for the end.EvioException - if end < 8 or > MAX_BLOCK_SIZEpublic int getNumber()
getNumber in interface IBlockHeaderpublic void setNumber(int number)
number - the number of the block (physical record).public int getHeaderLength()
public int getHeaderWords()
getHeaderLength()
method cannot be used since the new hipo code uses that method to return a
length in bytes.getHeaderWords in interface IBlockHeaderpublic void setHeaderLength(int headerLength)
throws EvioException
headerLength - the new block header length. This should be 8.EvioException - if headerLength is not 8.public boolean hasFirstEvent()
hasFirstEvent in interface IBlockHeaderfalsepublic int getEventType()
DataType.
This is not supported by this version header. So just return -1.getEventType in interface IBlockHeaderpublic int getVersion()
getVersion in interface IBlockHeaderpublic void setVersion(int version)
version - the evio version of evio.public int getSourceId()
getSourceId in interface IBlockHeaderpublic int getReserved1()
public void setReserved1(int reserved1)
reserved1 - the value for reserved1.public int getMagicNumber()
getMagicNumber in interface IBlockHeaderpublic void setMagicNumber(int magicNumber)
throws EvioException
magicNumber - the new value for magic number.EvioException - if magic number not the correct value.public java.nio.ByteOrder getByteOrder()
getByteOrder in interface IBlockHeaderpublic void setByteOrder(java.nio.ByteOrder byteOrder)
byteOrder - the new value for data's byte order.public java.lang.String toString()
toString in interface IBlockHeadertoString in class java.lang.Objectpublic long getBufferEndingPosition()
getBufferEndingPosition in interface IBlockHeaderpublic long getBufferStartingPosition()
getBufferStartingPosition in interface IBlockHeaderpublic void setBufferStartingPosition(long bufferStartingPosition)
setBufferStartingPosition in interface IBlockHeaderbufferStartingPosition - the starting position in the buffer from which this header was read--if that
happened.public long nextBufferStartingPosition()
nextBufferStartingPosition in interface IBlockHeaderpublic long firstEventStartingPosition()
firstEventStartingPosition in interface IBlockHeaderpublic 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 IBlockHeaderposition - the absolute current position is a byte buffer.EvioException - if position < buffer starting position or > buffer end positionpublic int write(java.nio.ByteBuffer byteBuffer)
throws java.nio.BufferOverflowException
write in interface IBlockHeaderwrite in interface IEvioWriterbyteBuffer - the byteBuffer to write to.java.nio.BufferOverflowException - if insufficient room to write header into buffer.