public final class ZFITSHeapReader extends Object implements Reader
This class implements the iterable and iterator interfaces which allow for such nice things as
for(OptionalTypesMap p : heapReader){ assertTrue(p.containsKey("Data")); assertTrue(p.size() == 9); }
The next() and the getNextRow() methods deliver a map with the data from one row in the heap.
Reading the heap in a ZFits bintable works as follows:
The heap data starts at the offset stored in the 'ZHEAPTR' variable in the header. This is wrong according to the FITS standard. It should be the 'THEAP' variable.
Each heap contains one TileHeader for each row with one BlockHeader for each column in the row. Information about the data in the columns can be read from the 'ZFORMn' keywords in the header.
Data in the tiles is in Little Endian byte order.
The data from one tile is read completely into one bytebuffer.
Then for each column the appropriate compression type is parsed from the block header.
,
When a column is huffman compressed, the definition of the huffmann tree will be stored in the first couple of bytes
in that row. This is documented exactly nowhere!
First we start with
[(int) numberOfCompressedBytes, (long) numberOfShortsAfterDecompression, (long) numberOfSymbolsUsedInCompression]
after that for each symbol (numberOfSymbolsUsedInCompression)
[(short) symbol, (byte) codeLengthInBits, the codeword stored in codeLengthInBits-rounded-up-to-bytes bytes (max 4 bytes)]
From these symbols and codewords the tree can be build see the ByteWiseHuffmanTree for details.
,
Created by mackaiver on 14/11/16.
Modifier and Type | Method and Description |
---|---|
static ZFITSHeapReader |
forTable(BinTable binTable)
Creates a ZFITSHeapReader for a given binary table.
|
OptionalTypesMap<String,Serializable> |
getNextRow()
Get the data from the next row.
|
OptionalTypesMap<String,Serializable> |
getNextRow(boolean ignoreWrongTileHeader)
Get the data from the next row.
|
boolean |
hasNext()
Check whether there is another row to return from this heap
|
void |
skipRows(int amount)
Skips the given number of rows.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEachRemaining, remove
forEach, spliterator
public boolean hasNext()
hasNext
in interface Reader
hasNext
in interface Iterator<OptionalTypesMap<String,Serializable>>
public static ZFITSHeapReader forTable(BinTable binTable)
binTable
- the binary table which contains a zfits heap.public void skipRows(int amount) throws IOException
skipRows
in interface Reader
amount
- The amount of rows to skip.IOException
public OptionalTypesMap<String,Serializable> getNextRow() throws IOException
getNextRow
in interface Reader
NoSuchElementException
- iff hasNext() is falseIOException
- if some IO error occurspublic OptionalTypesMap<String,Serializable> getNextRow(boolean ignoreWrongTileHeader) throws IOException
Some zfits file apparently contain a wrong tile header in the heap storing the ZDrsCellOffsets. I haven't figures out to which files this applies. Files from 2013 seem to have that problem. But also newer ones. Some files from 2016 are fine however.
The old ZFits implementation by M.Bulinski ignored the problem by default.
ignoreWrongTileHeader
- if true, ignores wrong tileheader information.NoSuchElementException
- iff hasNext() is falseIOException
Copyright © 2019. All rights reserved.