public final class BlockHeaderV4 extends java.lang.Object implements java.lang.Cloneable, IEvioWriter, IBlockHeader
################################
Evio block header, version 4:
################################
MSB(31) LSB(0)
<--- 32 bits ------------------------>
_______________________________________
| Block Length |
|_____________________________________|
| Block Number |
|_____________________________________|
| Header Length = 8 |
|_____________________________________|
| Event Count |
|_____________________________________|
| reserved 1 |
|_____________________________________|
| Bit info & Version |
|_____________________________________|
| reserved 2 |
|_____________________________________|
| Magic Int |
|_____________________________________|
Block Length = number of ints in block (including this one).
Block Number = id number (starting at 1)
Header Length = number of ints in this header (8)
Event Count = number of events in this block (always an integral #).
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 11-14 in bit info are RocRaw (1), then (in the first block)
this contains the CODA id of the source
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)
If a last block, bit #10 is set (=1)
Reserved 2 = unused
Magic Int = magic number (0xc0da0100) used to check endianness
Bit info has the following bits defined (bit #s start with 1):
Bit 9 = true if dictionary is included (relevant for first block only)
Bit 10 = true if this block is the last block in file or network transmission
Bits 11-14 = type of events following (ROC Raw = 0, Physics = 1, PartialPhysics = 2,
DisentangledPhysics = 3, User = 4, Control = 5, Other = 15).
Bit 15 = true if next (non-dictionary) event in this block is a "first event" to
be placed at the beginning of each written file and its splits.
Bits 11-15 are useful ONLY for the CODA online use of evio.
That's because only a single CODA event type is placed into
a single (ET, cMsg) buffer, and each user or control event has its own
buffer as well. That buffer then is parsed by an EvioReader or
EvioCompactReader object. Thus all events will be of a single CODA type.
Modifier and Type | Field and Description |
---|---|
static int |
EV_BLOCKNUM
Position of word for block number, starting at 1.
|
static int |
EV_BLOCKSIZE
Position of word for size of block in 32-bit words.
|
static int |
EV_COUNT
Position of word for number of events in block.
|
static int |
EV_DICTIONARY_MASK
Dictionary presence is 9th bit in version/info word
|
static int |
EV_EVENTTYPE_MASK
"Event type" is 11-14th bits` in version/info word
|
static int |
EV_FIRSTEVENT_MASK
"First event" is 15th bit in version/info word
|
static int |
EV_HEADERSIZE
Position of word for size of header in 32-bit words (=8).
|
static int |
EV_LASTBLOCK_MASK
"Last block" is 10th bit in version/info word
|
static int |
EV_MAGIC
Position of word for magic number for endianness tracking.
|
static int |
EV_RESERVED1
Position of word for reserved.
|
static int |
EV_RESERVED2
Position of word for reserved.
|
static int |
EV_VERSION
Position of word for version of file format.
|
static int |
HEADER_SIZE
The minimum and expected block header size in 32 bit ints.
|
MAGIC_NUMBER
Constructor and Description |
---|
BlockHeaderV4()
Null constructor initializes all fields to zero, except block# = 1.
|
BlockHeaderV4(BlockHeaderV4 blkHeader)
This copy constructor creates an evio version 4 BlockHeader
from another object of this class.
|
BlockHeaderV4(int size,
int number)
Creates a BlockHeader for evio version 4 format.
|
Modifier and Type | Method and Description |
---|---|
int |
bytesRemaining(long position)
Gives the bytes remaining in this block (physical record) given a buffer position.
|
static int |
clearFirstEventBit(int i)
Clear the bit in the given arg to indicate this block does NOT have a first event.
|
static int |
clearLastBlockBit(int i)
Clear the bit in the given arg to indicate it is NOT the last block.
|
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).
|
static int |
generateSixthWord(java.util.BitSet set)
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(java.util.BitSet bSet,
boolean hasDictionary,
boolean isEnd)
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(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.
|
java.util.BitSet |
getBitInfo()
Gets a copy of all stored bit information.
|
boolean |
getBitInfo(int bitIndex)
Gets the value of a particular bit in the bitInfo field.
|
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 |
getEventCount()
Get the number of events completely contained in the block.
|
int |
getEventType()
Get the value of bits 2-5.
|
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 (record) header which should be 0xc0da0100.
|
int |
getNumber()
Get the block number for this block (physical record).
|
int |
getReserved1()
Get the first reserved word.
|
int |
getReserved2()
Get the second reserved word.
|
int |
getSixthWord()
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.
|
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 |
getVersion()
Get the evio version of the block (physical record) header.
|
boolean |
hasDictionary()
Is this block's first event an evio dictionary?
|
static boolean |
hasDictionary(int i)
Does this integer indicate that there is an evio dictionary
(assuming it's the header's sixth word)?
|
boolean |
hasFirstEvent()
Does this block contain the "first event"
(first event to be written to each file split)?
|
static boolean |
hasFirstEvent(int i)
Does this integer indicate that block has the first event
(assuming it's the header's sixth word)? Only makes sense if the
integer arg comes from the first block header of a file or buffer.
|
boolean |
isCompressed()
Is this the data in this block compressed?
This is always false in evio version 4.
|
boolean |
isLastBlock()
Is this the last block in the file/buffer or being sent over the network?
|
static boolean |
isLastBlock(int i)
Does this integer indicate that this is the last block
(assuming it's the header's sixth word)?
|
long |
nextBufferStartingPosition()
Determines where the start of the next block (physical record) header in some buffer is located (in bytes).
|
void |
parseToBitInfo(int word)
Parses the argument into the bit info fields.
|
void |
setBit(int bitIndex,
boolean value)
Sets a particular bit in the bitInfo field.
|
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 |
setEventCount(int count)
Set the number of events completely contained in the block.
|
static void |
setEventType(java.util.BitSet bSet,
int type)
Sets the right bits in bit set (2-5 when starting at 0)
to hold 4 bits of the given type value.
|
static void |
setFirstEvent(java.util.BitSet bSet)
Encode the "is first event" into the bit info word
which will be in evio block header.
|
static int |
setFirstEventBit(int i)
Set the bit in the given arg which indicates this block has a first event.
|
void |
setHeaderLength(int headerLength)
Set the block header length, in ints.
|
static int |
setLastBlockBit(int i)
Set the bit in the given arg which indicates this is the last block.
|
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 first reserved word.
|
void |
setReserved2(int reserved2)
Sets the value of second reserved word.
|
void |
setSize(int size)
Set the size 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.
|
static void |
unsetFirstEvent(java.util.BitSet bSet)
Encode the "is NOT first event" into the bit info word
which will be in evio block header.
|
int |
write(java.nio.ByteBuffer byteBuffer)
Write myself out a byte buffer.
|
public static final int HEADER_SIZE
public static final int EV_DICTIONARY_MASK
public static final int EV_LASTBLOCK_MASK
public static final int EV_EVENTTYPE_MASK
public static final int EV_FIRSTEVENT_MASK
public static final int EV_BLOCKSIZE
public static final int EV_BLOCKNUM
public static final int EV_HEADERSIZE
public static final int EV_COUNT
public static final int EV_RESERVED1
public static final int EV_VERSION
public static final int EV_RESERVED2
public static final int EV_MAGIC
public BlockHeaderV4()
public BlockHeaderV4(int size, int number)
block size
and block number
are provided. The other words, which can be
modified by setters, are initialized to these values:headerLength
is initialized to 8version
is initialized to 4bitInfo
is initialized to all bits offmagicNumber
is initialized to MAGIC_NUMBER
size
- the size of the block in ints.number
- the block number--usually sequential.public BlockHeaderV4(BlockHeaderV4 blkHeader)
blkHeader
- block header object to copypublic int getSize()
getSize
in interface IBlockHeader
public java.lang.Object clone()
clone
in class java.lang.Object
public void setSize(int size) throws EvioException
size
- the new value for the size, in ints.EvioException
- if size < 8public int getEventCount()
public void setEventCount(int count) throws EvioException
count
- the new number of events in the block.EvioException
- if count < 0public int getNumber()
getNumber
in interface IBlockHeader
public 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 IBlockHeader
public void setHeaderLength(int headerLength)
headerLength
- the new block header length. This should be 8.public int getVersion()
getVersion
in interface IBlockHeader
public void setVersion(int version)
version
- the evio version of evio.public static boolean hasDictionary(int i)
i
- integer to examine.true
if this int indicates an evio dictionary, else false
public boolean hasDictionary()
hasDictionary
in interface IBlockHeader
true
if this block's first event is an evio dictionary, else false
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 boolean isCompressed()
isCompressed
in interface IBlockHeader
false
.public CompressionType getCompressionType()
CompressionType.RECORD_UNCOMPRESSED
in evio version 4.getCompressionType
in interface IBlockHeader
public boolean hasFirstEvent()
hasFirstEvent
in interface IBlockHeader
true
if this contains the first event, else false
public static boolean isLastBlock(int i)
i
- integer to examine.true
if this int indicates the last block, else false
public static int setLastBlockBit(int i)
i
- integer in which to set the last-block bitpublic static int clearLastBlockBit(int i)
i
- integer in which to clear the last-block bitpublic static boolean hasFirstEvent(int i)
i
- integer to examine.true
if this int indicates the block has a first event,
else false
public static int setFirstEventBit(int i)
i
- integer in which to set the last-block bitpublic static int clearFirstEventBit(int i)
i
- integer in which to clear the first event bitpublic int getEventType()
getEventType
in interface IBlockHeader
public static void setFirstEvent(java.util.BitSet bSet)
bSet
- bit set which will become part of the bit info wordpublic static void unsetFirstEvent(java.util.BitSet bSet)
bSet
- bit set which will become part of the bit info wordpublic java.util.BitSet getBitInfo()
public boolean getBitInfo(int bitIndex)
bitIndex
- index of bit to getpublic void setBit(int bitIndex, boolean value)
bitIndex
- index of bit to changevalue
- value to set bit topublic static void setEventType(java.util.BitSet bSet, int type)
EventWriter
constructor.bSet
- Bitset containing all bits to be settype
- event type as intpublic int getSixthWord()
public static int generateSixthWord(java.util.BitSet set)
set
- Bitset containing all bits to be setpublic static int generateSixthWord(java.util.BitSet bSet, boolean hasDictionary, boolean isEnd)
bSet
- Bitset containing all bits to be sethasDictionary
- does this block include an evio xml dictionary as the first event?isEnd
- is this the last block of a file or a buffer?public 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 void parseToBitInfo(int word)
word
- integer to parse into bit info fieldspublic int getSourceId()
getSourceId
in interface IBlockHeader
public int getReserved1()
public void setReserved1(int reserved1)
reserved1
- the value for first reserved word.public int getReserved2()
public void setReserved2(int reserved2)
reserved2
- the value for second reserved word.public int getMagicNumber()
getMagicNumber
in interface IBlockHeader
public void setMagicNumber(int magicNumber) throws EvioException
magicNumber
- the new value for magic number.EvioException
- if magic number != MAGIC_NUMBER.public java.nio.ByteOrder getByteOrder()
getByteOrder
in interface IBlockHeader
public void setByteOrder(java.nio.ByteOrder byteOrder)
byteOrder
- the new value for data's byte order.public java.lang.String toString()
toString
in interface IBlockHeader
toString
in class java.lang.Object
public long getBufferEndingPosition()
getBufferEndingPosition
in interface IBlockHeader
public long getBufferStartingPosition()
getBufferStartingPosition
in interface IBlockHeader
public void setBufferStartingPosition(long bufferStartingPosition)
setBufferStartingPosition
in interface IBlockHeader
bufferStartingPosition
- the starting position in the 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 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 IBlockHeader
write
in interface IEvioWriter
byteBuffer
- the byteBuffer to write to.java.nio.BufferOverflowException
- if insufficient room to write header into buffer.