public class FileHeader
extends java.lang.Object
implements java.lang.Cloneable
FILE HEADER STRUCTURE ( 56 bytes, 14 integers (32 bit) )
+----------------------------------+
1 | ID | // HIPO: 0x43455248, Evio: 0x4556494F
+----------------------------------+
2 + File Number | // split file #
+----------------------------------+
3 + Header Length | // 14 (words)
+----------------------------------+
4 + Record (Index) Count |
+----------------------------------+
5 + Index Array Length | // bytes
+-----------------------+----------+
6 + Bit Info | Version | // version (8 bits)
+-----------------------+----------+
7 + User Header Length | // bytes
+----------------------------------+
8 + Magic Number | // 0xc0da0100
+----------------------------------+
9 + User Register |
+-- --+
10 + |
+----------------------------------+
11 + Trailer Position | // File offset to trailer head (64 bits).
+-- --+ // 0 = no offset available or no trailer exists.
12 + |
+----------------------------------+
13 + User Integer 1 |
+----------------------------------+
14 + User Integer 2 |
+----------------------------------+
-------------------
Bit Info Word
-------------------
0-7 = version
8 = true if dictionary is included (relevant for first record only)
9 = true if this file has "first" event (in every split file)
10 = File trailer with index array of record lengths exists
11-19 = reserved
20-21 = pad 1
22-23 = pad 2
24-25 = pad 3 (always 0)
26-27 = reserved
28-31 = general header type: 1 = Evio file
2 = Evio extended file
5 = HIPO file
6 = HIPO extended file
Modifier and Type | Field and Description |
---|---|
static int |
BIT_INFO_OFFSET
Byte offset from beginning of header to bit info word.
|
(package private) static int |
DICTIONARY_BIT
8th bit set in bitInfo word in record/file header means contains dictionary.
|
static int |
EVIO_FILE_UNIQUE_WORD
First word in every Evio file for identification purposes.
|
static int |
FILE_ID_OFFSET
Byte offset from beginning of header to the file id.
|
static int |
FILE_NUMBER_OFFSET
Byte offset from beginning of header to the file number.
|
(package private) static int |
FIRST_EVENT_BIT
9th bit set in bitInfo word in file header means every split file has same first event.
|
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 |
HIPO_FILE_UNIQUE_WORD
First word in every HIPO file for identification purposes.
|
static int |
INDEX_ARRAY_OFFSET
Byte offset from beginning of header to the index array length.
|
static int |
INT1_OFFSET
Byte offset from beginning of header to the user integer #1.
|
static int |
INT2_OFFSET
Byte offset from beginning of header to the user integer #2.
|
static int |
MAGIC_OFFSET
Byte offset from beginning of header to the record length.
|
static int |
RECORD_COUNT_OFFSET
Byte offset from beginning of header to the record count.
|
static int |
REGISTER1_OFFSET
Byte offset from beginning of header to the user register #1.
|
static int |
TRAILER_POSITION_OFFSET
Byte offset from beginning of header to write trailer position.
|
(package private) static int |
TRAILER_WITH_INDEX_BIT
10th bit set in bitInfo word in file header means file trailer with index array exists.
|
static int |
USER_LENGTH_OFFSET
Byte offset from beginning of header to the user header length.
|
Constructor and Description |
---|
FileHeader()
Default, no-arg constructor.
|
FileHeader(boolean isEvio)
Constructor which sets the type of header this is and file id.
|
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.
|
java.lang.Object |
clone() |
void |
copy(FileHeader head)
Copy the contents of the arg into this object.
|
int |
getBitInfoWord()
Get the bit info word.
|
java.nio.ByteOrder |
getByteOrder()
Get the byte order of the file this header was read from.
|
int |
getEntries()
Get the number of events or entries in index.
|
int |
getFileId()
Get the file id.
|
int |
getFileNumber()
Get the file number or split number.
|
HeaderType |
getFileType()
Get the file's type.
|
static HeaderType |
getFileType(int word)
Get the file's type from the bit info word.
|
int |
getHeaderLength()
Get the length of this header data in bytes.
|
HeaderType |
getHeaderType()
Get the type of header this is.
|
int |
getIndexLength()
Get the length of the index array in bytes.
|
int |
getLength()
Get the total length of header + index + user header (including padding) in bytes.
|
long |
getPosition()
Get the position of this record in a file.
|
long |
getTrailerPosition()
Get the trailer's (trailing header's) file position in bytes.
|
int |
getUserHeaderLength()
Get the length of the user-defined header in bytes.
|
int |
getUserHeaderLengthPadding()
Get the user header's padding - the number of bytes required to bring uncompressed
user header to 4-byte boundary.
|
int |
getUserHeaderLengthWords()
Get the length of the user-defined header in words.
|
int |
getUserIntFirst()
Get the first user integer value.
|
int |
getUserIntSecond()
Get the second user integer value.
|
long |
getUserRegister()
Get the user register value.
|
int |
getVersion()
Get the Evio format version number.
|
boolean |
hasDictionary()
Does this header have a dictionary in the file header?
|
int |
hasDictionary(boolean hasDictionary)
Set the bit in the file header which says there is a dictionary.
|
static boolean |
hasDictionary(int bitInfo)
Does this bitInfo arg indicate the existence of a dictionary in the file header?
|
boolean |
hasFirstEvent()
Does this header have a first event in the file header?
|
int |
hasFirstEvent(boolean hasFirst)
Set the bit which says file has a first event.
|
static boolean |
hasFirstEvent(int bitInfo)
Does this bitInfo arg indicate the existence of a first event in the file header?
|
boolean |
hasIndex()
Does this file have a valid index of record lengths immediately following header?
There should be at least one integer for valid index.
|
boolean |
hasTrailerWithIndex()
Does this file have a trailer with a record length index?
|
int |
hasTrailerWithIndex(boolean hasTrailerWithIndex)
Set the bit in the file header which says there is a trailer with a record length index.
|
static boolean |
hasTrailerWithIndex(int bitInfo)
Does this bitInfo arg indicate the existence of a trailer with a record length index?
|
boolean |
hasUserHeader()
Is this header followed by a user header?
|
static void |
main(java.lang.String[] args)
Run this class as an executable which tests the writing and reading of a record.
|
void |
readHeader(java.nio.ByteBuffer buffer)
Reads the file 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 file header information from a byte buffer and validates
it by checking the magic word (8th word).
|
void |
reset()
Reset most internal variables (not file id and header type).
|
int |
setBitInfo(boolean haveFirst,
boolean haveDictionary,
boolean haveTrailerWithIndex)
Set the bit info word for a file header.
|
(package private) void |
setBitInfoWord(int word)
Set the bit info word and related values.
|
FileHeader |
setEntries(int n)
Set the number of record entries.
|
FileHeader |
setFileNumber(int num)
Set the file number which is the split number starting at 1.
|
FileHeader |
setHeaderLength(int length)
Set the this header's length in bytes and words.
|
(package private) FileHeader |
setHeaderType(HeaderType type)
Set this header's type.
|
FileHeader |
setIndexLength(int length)
Set the length of the index array in bytes.
|
FileHeader |
setLength(int length)
Set the total length in bytes, header + index + user header.
|
FileHeader |
setPosition(long pos)
Set the position of this record in a file.
|
FileHeader |
setUserHeaderLength(int length)
Set the user-defined header's length in bytes and words and the padding.
|
FileHeader |
setUserIntFirst(int val)
Set the first user integer.
|
FileHeader |
setUserIntSecond(int val)
Set the second user integer.
|
FileHeader |
setUserRegister(long val)
Set the first user register.
|
java.lang.String |
toString()
Returns a string representation of the record.
|
void |
writeHeader(java.nio.ByteBuffer buffer)
Writes the file (not record!) header into the given byte buffer starting at beginning.
|
void |
writeHeader(java.nio.ByteBuffer buf,
int off)
Writes the file (not record!) header into the given byte buffer.
|
public static final int HIPO_FILE_UNIQUE_WORD
public static final int EVIO_FILE_UNIQUE_WORD
public static final int HEADER_SIZE_WORDS
public static final int HEADER_SIZE_BYTES
public static final int HEADER_MAGIC
public static final int FILE_ID_OFFSET
public static final int FILE_NUMBER_OFFSET
public static final int HEADER_LENGTH_OFFSET
public static final int RECORD_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 REGISTER1_OFFSET
public static final int TRAILER_POSITION_OFFSET
public static final int INT1_OFFSET
public static final int INT2_OFFSET
static final int DICTIONARY_BIT
static final int FIRST_EVENT_BIT
static final int TRAILER_WITH_INDEX_BIT
public FileHeader()
public FileHeader(boolean isEvio)
isEvio
- if true, file has EVIO file id and header type, else is HIPO.public java.lang.Object clone()
clone
in class java.lang.Object
public void copy(FileHeader head)
head
- object to copypublic void reset()
public java.nio.ByteOrder getByteOrder()
public int getFileNumber()
public int getFileId()
public long getUserRegister()
public long getTrailerPosition()
public int getUserIntFirst()
public int getUserIntSecond()
public long getPosition()
public int getEntries()
public int getUserHeaderLength()
public int getUserHeaderLengthWords()
public int getVersion()
public int getIndexLength()
public int getHeaderLength()
public HeaderType getHeaderType()
public int getLength()
public int getUserHeaderLengthPadding()
public int getBitInfoWord()
void setBitInfoWord(int word)
word
- bit info word.public int setBitInfo(boolean haveFirst, boolean haveDictionary, boolean haveTrailerWithIndex)
haveFirst
- true if file has first event.haveDictionary
- true if file has dictionary in user header.haveTrailerWithIndex
- true if file has trailer with record length index.public HeaderType getFileType()
public static HeaderType getFileType(int word)
word
- bit-info word.public int hasFirstEvent(boolean hasFirst)
hasFirst
- true if file has a first event.public boolean hasFirstEvent()
public static boolean hasFirstEvent(int bitInfo)
bitInfo
- bitInfo word.public int hasDictionary(boolean hasDictionary)
hasDictionary
- true if file has a dictionary.public boolean hasDictionary()
public static boolean hasDictionary(int bitInfo)
bitInfo
- bitInfo word.public int hasTrailerWithIndex(boolean hasTrailerWithIndex)
hasTrailerWithIndex
- true if file has a trailer with a record length index.public boolean hasTrailerWithIndex()
public static boolean hasTrailerWithIndex(int bitInfo)
bitInfo
- bitInfo word.public boolean hasUserHeader()
public boolean hasIndex()
public FileHeader setFileNumber(int num)
num
- file number starting at 1.public FileHeader setUserRegister(long val)
val
- first user register.public FileHeader setUserIntFirst(int val)
val
- first user integer.public FileHeader setUserIntSecond(int val)
val
- second user integer.FileHeader setHeaderType(HeaderType type)
type
- type of header.public FileHeader setPosition(long pos)
pos
- position of this record in a file.public FileHeader setIndexLength(int length)
length
- length of index array in bytes.public FileHeader setEntries(int n)
n
- number of record entries.public FileHeader setUserHeaderLength(int length)
length
- user-defined header's length in bytes.public FileHeader setHeaderLength(int length)
length
- this header's length in bytes.public FileHeader setLength(int length)
length
- total length in bytes, header + index + user header.public void writeHeader(java.nio.ByteBuffer buf, int off) throws HipoException
buf
- byte buffer to write file 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 file header into.HipoException
- if buffer is null or contains too little room.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,
remaining buffer space (limit - off) is too small,
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 the beginning.HipoException
- if buffer is not in the proper format or earlier than version 6public java.lang.String toString()
toString
in class java.lang.Object
public static void byteBufferBinaryString(java.nio.ByteBuffer buffer)
buffer
- buffer to print out.public static void main(java.lang.String[] args)
args
- args