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

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