source: trunk/FACT++/src/Fits.h @ 10489

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