1 | #ifndef FACT_Fits
|
---|
2 | #define FACT_Fits
|
---|
3 |
|
---|
4 | #include <CCfits/CCfits>
|
---|
5 | #include <vector>
|
---|
6 |
|
---|
7 | #include "Description.h"
|
---|
8 |
|
---|
9 | class Converter;
|
---|
10 | class MessageImp;
|
---|
11 |
|
---|
12 | using namespace std;
|
---|
13 |
|
---|
14 | class Fits
|
---|
15 | {
|
---|
16 | private:
|
---|
17 | ///The CCfits object to the FITS file
|
---|
18 | CCfits::FITS* fFile;
|
---|
19 | ///Flag indicating whether the FITS object should be managed internally or not.
|
---|
20 | bool fOwner;
|
---|
21 | ///The CCfits Table
|
---|
22 | CCfits::Table* fTable;
|
---|
23 | ///The current number of Rows in the table
|
---|
24 | int fNumRows;
|
---|
25 | ///Name of the "standard", i.e. data found in every fits file
|
---|
26 | ///TODO make these variable static so that they are shared by every object.
|
---|
27 | ///TODO add also a static boolean to initialize these only once
|
---|
28 | vector<Description> fStandardColDesc;
|
---|
29 | ///Format of the standard columns.
|
---|
30 | vector<string> fStandardFormats;
|
---|
31 | ///the pointers to the standard variables
|
---|
32 | vector<void*> fStandardPointers;
|
---|
33 | ///the number of bytes taken by each standard variable
|
---|
34 | vector<int> fStandardNumBytes;
|
---|
35 | ///the vector of data column names
|
---|
36 | vector<Description> fDataColDesc;
|
---|
37 | ///the data format of the data columns
|
---|
38 | vector<string> fDataFormats;
|
---|
39 | ///the pointer to the contiguous memory location where the data is stored (i.e. the dim data pointer)
|
---|
40 | void* fDataPointer;
|
---|
41 | ///the size of the data, in bytes.
|
---|
42 | int fDataNumBytes;
|
---|
43 | ///the copy buffer. Required to put the standard and data variable in contguous memory
|
---|
44 | unsigned char* fCopyBuffer;
|
---|
45 | ///the total number of bytes per FITS row
|
---|
46 | int fTotalNumBytes;
|
---|
47 | ///to keep track of the time of the latest written entry (to update the header when closing the file)
|
---|
48 | double fEndMjD;
|
---|
49 | ///Write the FITS header keys
|
---|
50 | bool WriteHeaderKeys();
|
---|
51 | public:
|
---|
52 | ///Name of the openned file. For querying stats
|
---|
53 | string fFileName;
|
---|
54 | private:
|
---|
55 | ///Keep track of number of opened fits
|
---|
56 | uint32_t* fNumOpenFitsFiles;
|
---|
57 | ///were to log the errors
|
---|
58 | MessageImp* fMess;
|
---|
59 | public:
|
---|
60 | ///current run number being logged
|
---|
61 | uint32_t fRunNumber;
|
---|
62 |
|
---|
63 | Fits() : fFile(NULL),
|
---|
64 | fOwner(false),
|
---|
65 | fTable(NULL),
|
---|
66 | fNumRows(0),
|
---|
67 | fDataPointer(NULL),
|
---|
68 | fDataNumBytes(0),
|
---|
69 | fCopyBuffer(NULL),
|
---|
70 | fTotalNumBytes(0),
|
---|
71 | fEndMjD(0.0),
|
---|
72 | fFileName(""),
|
---|
73 | fNumOpenFitsFiles(NULL),
|
---|
74 | fMess(NULL),
|
---|
75 | fRunNumber(0)
|
---|
76 | {}
|
---|
77 |
|
---|
78 | virtual ~Fits()
|
---|
79 | {
|
---|
80 | if (IsOpen())
|
---|
81 | Close();
|
---|
82 | }
|
---|
83 | ///returns wether or not the file is currently open or not
|
---|
84 | bool IsOpen() const {return fFile != NULL;}
|
---|
85 |
|
---|
86 | ///Adds a column that exists in all FITS files
|
---|
87 | void AddStandardColumn(const Description& desc, const string &dataFormat, void* dataPointer, long unsigned int numDataBytes);
|
---|
88 |
|
---|
89 | ///Adds columns specific to the service being logged.
|
---|
90 | void InitDataColumns(const vector<Description> &desc, vector<string>& dataFormat, void* dataPointer, int numDataBytes);
|
---|
91 |
|
---|
92 | ///Opens a FITS file
|
---|
93 | bool Open(const string& fileName, const string& tableName, CCfits::FITS* file, uint32_t* fitsCounter, MessageImp* out, int runNumber);//ostream& out);
|
---|
94 |
|
---|
95 | ///Write one line of data. Use the given converter.
|
---|
96 | bool Write(const Converter &conv);
|
---|
97 |
|
---|
98 | ///Close the currently opened file.
|
---|
99 | void Close();
|
---|
100 |
|
---|
101 | ///Get the size currently written on the disk
|
---|
102 | int GetWrittenSize() const;
|
---|
103 | private:
|
---|
104 | template <typename T>
|
---|
105 | bool WriteSingleHeaderKey(const string &name, const T &value, const string &comment);
|
---|
106 | CCfits::Table* findSuitableTableInFitsFile(const string& tableName,const vector<string>& allNames, const vector<string>& allDataTypes, const vector<string>& allUnits);
|
---|
107 |
|
---|
108 | };//Fits
|
---|
109 |
|
---|
110 |
|
---|
111 | #endif /*FITS_H_*/
|
---|
112 |
|
---|