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

Last change on this file since 17689 was 17297, checked in by tbretz, 11 years ago
Added some more tweaks needed by CINT (default constructors, handling of __attribute((__packed__)))
File size: 2.8 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#ifdef __CINT__
35 struct TileHeader;
36 struct BlockHeader;
37#else
38 //Structure helper for tiles headers
39 struct TileHeader
40 {
41 char id[4];
42 uint32_t numRows;
43 uint64_t size;
44
45 TileHeader() {}
46
47 TileHeader(uint32_t nRows,
48 uint64_t s) : id({'T', 'I', 'L', 'E'}),
49 numRows(nRows),
50 size(s)
51 { };
52 } __attribute__((__packed__));
53
54 //Structure helper for blocks headers and compresion schemes
55 struct BlockHeader
56 {
57 uint64_t size;
58 char ordering;
59 unsigned char numProcs;
60 uint16_t processings[];
61
62 BlockHeader(uint64_t s=0,
63 char o=kOrderByRow,
64 unsigned char n=1) : size(s),
65 ordering(o),
66 numProcs(n)
67 {}
68 } __attribute__((__packed__));
69#endif
70
71 //Helper structure to simplify the initialization and handling of compressed blocks headers
72 struct Compression
73 {
74 BlockHeader header;
75 std::vector<uint16_t> sequence;
76
77 Compression(const std::vector<uint16_t> &seq, const RowOrdering_t &order=kOrderByCol)
78 : header(0, order, seq.size()), sequence(seq)
79 {
80
81 }
82
83 Compression(const CompressionProcess_t &compression=kFactRaw, const RowOrdering_t &order=kOrderByCol)
84 : header(0, order, 1), sequence(1)
85 {
86 sequence[0] = compression;
87 }
88
89#ifdef __MARS__ // needed for CINT
90 Compression(const int &compression)
91 : header(0, kOrderByCol, 1), sequence(1)
92 {
93 sequence[0] = compression;
94 }
95#endif
96
97 RowOrdering_t getOrdering() const { return RowOrdering_t(header.ordering); }
98 uint32_t getSizeOnDisk() const { return sizeof(BlockHeader) + sizeof(uint16_t)*header.numProcs; }
99 CompressionProcess_t getProc(uint32_t i) const { return CompressionProcess_t(sequence[i]); }
100 uint16_t getNumProcs() const { return header.numProcs; }
101
102 void SetBlockSize(uint64_t size) { header.size = size; }
103 void Memcpy(char *dest) const
104 {
105 memcpy(dest, &header, sizeof(BlockHeader));
106 memcpy(dest+sizeof(BlockHeader), sequence.data(), header.numProcs*sizeof(uint16_t));
107 }
108 };
109};
110
111#endif //_FITS_H_
112
Note: See TracBrowser for help on using the repository browser.