| 1 | /*
|
|---|
| 2 | *
|
|---|
| 3 | * FITS.h
|
|---|
| 4 | *
|
|---|
| 5 | * Global fits header
|
|---|
| 6 | *
|
|---|
| 7 | * Author: lyard
|
|---|
| 8 | *
|
|---|
| 9 | */
|
|---|
| 10 |
|
|---|
| 11 | #ifndef _FITS_H_
|
|---|
| 12 | #define _FITS_H_
|
|---|
| 13 |
|
|---|
| 14 | //#include <string>
|
|---|
| 15 |
|
|---|
| 16 | namespace FITS
|
|---|
| 17 | {
|
|---|
| 18 |
|
|---|
| 19 | //Identifier of the compression schemes processes
|
|---|
| 20 | enum CompressionProcess_t
|
|---|
| 21 | {
|
|---|
| 22 | kFactRaw = 0x0,
|
|---|
| 23 | kFactSmoothing = 0x1,
|
|---|
| 24 | kFactHuffman16 = 0x2
|
|---|
| 25 | };
|
|---|
| 26 |
|
|---|
| 27 | //ordering of the columns / rows
|
|---|
| 28 | enum RowOrdering_t
|
|---|
| 29 | {
|
|---|
| 30 | kOrderByCol = 'C',
|
|---|
| 31 | kOrderByRow = 'R'
|
|---|
| 32 | };
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 | #ifndef __CINT__
|
|---|
| 36 |
|
|---|
| 37 | //Structure helper for tiles headers
|
|---|
| 38 | struct TileHeader
|
|---|
| 39 | {
|
|---|
| 40 | char id[4];
|
|---|
| 41 | uint32_t numRows;
|
|---|
| 42 | uint64_t size;
|
|---|
| 43 |
|
|---|
| 44 | TileHeader() {}
|
|---|
| 45 |
|
|---|
| 46 | TileHeader(uint32_t nRows,
|
|---|
| 47 | uint64_t s) : id({'T', 'I', 'L', 'E'}),
|
|---|
| 48 | numRows(nRows),
|
|---|
| 49 | size(s)
|
|---|
| 50 | { };
|
|---|
| 51 | } __attribute__((__packed__));
|
|---|
| 52 |
|
|---|
| 53 | //Structure helper for blocks headers and compresion schemes
|
|---|
| 54 | struct BlockHeader
|
|---|
| 55 | {
|
|---|
| 56 | uint64_t size;
|
|---|
| 57 | char ordering;
|
|---|
| 58 | unsigned char numProcs;
|
|---|
| 59 | uint16_t processings[];
|
|---|
| 60 |
|
|---|
| 61 | BlockHeader(uint64_t s=0,
|
|---|
| 62 | char o=kOrderByRow,
|
|---|
| 63 | unsigned char n=1) : size(s),
|
|---|
| 64 | ordering(o),
|
|---|
| 65 | numProcs(n)
|
|---|
| 66 | {}
|
|---|
| 67 | } __attribute__((__packed__));
|
|---|
| 68 |
|
|---|
| 69 | //Helper structure to simplify the initialization and handling of compressed blocks headers
|
|---|
| 70 | struct Compression
|
|---|
| 71 | {
|
|---|
| 72 | BlockHeader header;
|
|---|
| 73 | std::vector<uint16_t> sequence;
|
|---|
| 74 |
|
|---|
| 75 | Compression(const std::vector<uint16_t> &seq, const RowOrdering_t &order=kOrderByCol)
|
|---|
| 76 | : header(0, order, seq.size()), sequence(seq)
|
|---|
| 77 | {
|
|---|
| 78 |
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | Compression(const CompressionProcess_t &compression=kFactRaw, const RowOrdering_t &order=kOrderByCol)
|
|---|
| 82 | : header(0, order, 1), sequence(1)
|
|---|
| 83 | {
|
|---|
| 84 | sequence[0] = compression;
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | RowOrdering_t getOrdering() const { return RowOrdering_t(header.ordering); }
|
|---|
| 88 | uint32_t getSizeOnDisk() const { return sizeof(BlockHeader) + sizeof(uint16_t)*header.numProcs; }
|
|---|
| 89 | CompressionProcess_t getProc(uint32_t i) const { return CompressionProcess_t(sequence[i]); }
|
|---|
| 90 | uint16_t getNumProcs() const { return header.numProcs; }
|
|---|
| 91 |
|
|---|
| 92 | void SetBlockSize(uint64_t size) { header.size = size; }
|
|---|
| 93 | void Memcpy(char *dest) const
|
|---|
| 94 | {
|
|---|
| 95 | memcpy(dest, &header, sizeof(BlockHeader));
|
|---|
| 96 | memcpy(dest+sizeof(BlockHeader), sequence.data(), header.numProcs*sizeof(uint16_t));
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 | };
|
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 | #endif
|
|---|
| 104 | };
|
|---|
| 105 |
|
|---|
| 106 | #endif //_FITS_H_
|
|---|
| 107 |
|
|---|