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

Last change on this file since 13340 was 12536, checked in by lyard, 13 years ago
added flushing of nightly files after each row
File size: 3.0 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 //Description of the table
36 string fTableDesc;
37 ///the data format of the data columns
38 vector<string> fDataFormats;
39
40 ///the pointer to the contiguous memory location where the data is stored (i.e. the dim data pointer)
41 void* fDataPointer;
42 ///the copy buffer. Required to put the standard and data variable in contguous memory
43 vector<char> fCopyBuffer;
44 ///to keep track of the time of the latest written entry (to update the header when closing the file)
45 double fEndMjD;
46 ///Keep track of number of opened fits
47 uint32_t* fNumOpenFitsFiles;
48 ///were to log the errors
49 MessageImp* fMess;
50
51 ///Write the FITS header keys
52 bool WriteHeaderKeys();
53 //if a write error occurs
54 void MoveFileToCorruptedFile();
55
56
57
58public:
59 ///current run number being logged
60 int32_t fRunNumber;
61
62 Fits() : fFile(NULL),
63 fDataPointer(NULL),
64 fEndMjD(0.0),
65 fNumOpenFitsFiles(NULL),
66 fMess(NULL),
67 fRunNumber(0)
68 {}
69
70 virtual ~Fits()
71 {
72 Close();
73 }
74
75 ///returns wether or not the file is currently open or not
76 bool IsOpen() const { return fFile != NULL && fFile->IsOpen(); }
77
78 ///Adds a column that exists in all FITS files
79 void AddStandardColumn(const Description& desc, const string &dataFormat, void* dataPointer, long unsigned int numDataBytes);
80
81 ///Adds columns specific to the service being logged.
82 void InitDataColumns(const vector<Description> &desc, const vector<string>& dataFormat, void* dataPointer, MessageImp* out);
83
84 ///Opens a FITS file
85 bool Open(const string& fileName, const string& tableName, uint32_t* fitsCounter, MessageImp* out, int runNumber, CCfits::FITS *file=0);//ostream& out);
86
87 ///Write one line of data. Use the given converter.
88 bool Write(const Converter &conv);
89
90 ///Close the currently opened file.
91 void Close();
92
93 ///Flush the currently opened file to disk.
94 void Flush();
95
96 ///Get the size currently written on the disk
97 int GetWrittenSize() const;
98
99 string GetName() const { return fFile ? fFile->GetName() : ""; }
100
101};//Fits
102
103
104#endif /*FITS_H_*/
105
106// WriteToFITS vs Open/Close
Note: See TracBrowser for help on using the repository browser.