source: trunk/Mars/mcore/FITS.h@ 17295

Last change on this file since 17295 was 17290, checked in by tbretz, 11 years ago
Added a Compression constructor which allows CINT to pass the argument as an int:
File size: 2.7 KB
Line 
1/*
2 *
3 * FITS.h
4 *
5 * Global fits header
6 *
7 * Author: lyard
8 *
9 */
10
11#ifndef MARS_FITS
12#define MARS_FITS
13
14#include <stdint.h>
15
16namespace 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 //Structure helper for tiles headers
35 struct TileHeader
36 {
37 char id[4];
38 uint32_t numRows;
39 uint64_t size;
40
41 TileHeader() {}
42
43 TileHeader(uint32_t nRows,
44 uint64_t s) : id({'T', 'I', 'L', 'E'}),
45 numRows(nRows),
46 size(s)
47 { };
48 } __attribute__((__packed__));
49
50 //Structure helper for blocks headers and compresion schemes
51 struct BlockHeader
52 {
53 uint64_t size;
54 char ordering;
55 unsigned char numProcs;
56 uint16_t processings[];
57
58 BlockHeader(uint64_t s=0,
59 char o=kOrderByRow,
60 unsigned char n=1) : size(s),
61 ordering(o),
62 numProcs(n)
63 {}
64 } __attribute__((__packed__));
65
66 //Helper structure to simplify the initialization and handling of compressed blocks headers
67 struct Compression
68 {
69 BlockHeader header;
70 std::vector<uint16_t> sequence;
71
72 Compression(const std::vector<uint16_t> &seq, const RowOrdering_t &order=kOrderByCol)
73 : header(0, order, seq.size()), sequence(seq)
74 {
75
76 }
77
78 Compression(const CompressionProcess_t &compression=kFactRaw, const RowOrdering_t &order=kOrderByCol)
79 : header(0, order, 1), sequence(1)
80 {
81 sequence[0] = compression;
82 }
83
84#ifdef __MARS__ // needed for CINT
85 Compression(const int &compression)
86 : header(0, kOrderByCol, 1), sequence(1)
87 {
88 sequence[0] = compression;
89 }
90#endif
91
92 RowOrdering_t getOrdering() const { return RowOrdering_t(header.ordering); }
93 uint32_t getSizeOnDisk() const { return sizeof(BlockHeader) + sizeof(uint16_t)*header.numProcs; }
94 CompressionProcess_t getProc(uint32_t i) const { return CompressionProcess_t(sequence[i]); }
95 uint16_t getNumProcs() const { return header.numProcs; }
96
97 void SetBlockSize(uint64_t size) { header.size = size; }
98 void Memcpy(char *dest) const
99 {
100 memcpy(dest, &header, sizeof(BlockHeader));
101 memcpy(dest+sizeof(BlockHeader), sequence.data(), header.numProcs*sizeof(uint16_t));
102 }
103 };
104};
105
106#endif //_FITS_H_
107
Note: See TracBrowser for help on using the repository browser.