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

Last change on this file since 12064 was 12035, checked in by lyard, 13 years ago
added moving of corrupted files to corrupted naming
File size: 2.8 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"
9//#include "Time.h"
10#include "FitsFile.h"
11
12class Converter;
13
14using namespace std;
15
16class Fits
17{
18private:
19 FitsFile *fFile;
20 string fFileName;
21
22 ///Name of the "standard", i.e. data found in every fits file
23 ///TODO make these variable static so that they are shared by every object.
24 ///TODO add also a static boolean to initialize these only once
25 vector<Description> fStandardColDesc;
26 ///Format of the standard columns.
27 vector<string> fStandardFormats;
28 ///the pointers to the standard variables
29 vector<void*> fStandardPointers;
30 ///the number of bytes taken by each standard variable
31 vector<int> fStandardNumBytes;
32
33 ///the vector of data column names
34 vector<Description> fDataColDesc;
35 ///the data format of the data columns
36 vector<string> fDataFormats;
37
38 ///the pointer to the contiguous memory location where the data is stored (i.e. the dim data pointer)
39 void* fDataPointer;
40 ///the copy buffer. Required to put the standard and data variable in contguous memory
41 vector<char> fCopyBuffer;
42 ///to keep track of the time of the latest written entry (to update the header when closing the file)
43 double fEndMjD;
44 ///Keep track of number of opened fits
45 uint32_t* fNumOpenFitsFiles;
46 ///were to log the errors
47 MessageImp* fMess;
48
49 ///Write the FITS header keys
50 bool WriteHeaderKeys();
51 //if a write error occurs
52 void MoveFileToCorruptedFile();
53
54
55
56public:
57 ///current run number being logged
58 uint32_t fRunNumber;
59
60 Fits() : fFile(NULL),
61 fDataPointer(NULL),
62 fEndMjD(0.0),
63 fNumOpenFitsFiles(NULL),
64 fMess(NULL),
65 fRunNumber(0)
66 {}
67
68 virtual ~Fits()
69 {
70 Close();
71 }
72
73 ///returns wether or not the file is currently open or not
74 bool IsOpen() const { return fFile != NULL && fFile->IsOpen(); }
75
76 ///Adds a column that exists in all FITS files
77 void AddStandardColumn(const Description& desc, const string &dataFormat, void* dataPointer, long unsigned int numDataBytes);
78
79 ///Adds columns specific to the service being logged.
80 void InitDataColumns(const vector<Description> &desc, const vector<string>& dataFormat, void* dataPointer);
81
82 ///Opens a FITS file
83 bool Open(const string& fileName, const string& tableName, uint32_t* fitsCounter, MessageImp* out, int runNumber, CCfits::FITS *file=0);//ostream& out);
84
85 ///Write one line of data. Use the given converter.
86 bool Write(const Converter &conv);
87
88 ///Close the currently opened file.
89 void Close();
90
91 ///Get the size currently written on the disk
92 int GetWrittenSize() const;
93
94 string GetName() const { return fFile ? fFile->GetName() : ""; }
95
96};//Fits
97
98
99#endif /*FITS_H_*/
100
101// WriteToFITS vs Open/Close
Note: See TracBrowser for help on using the repository browser.