FACT++  1.0
FitsFile.h
Go to the documentation of this file.
1 #ifndef FACT_FitsFile
2 #define FACT_FitsFile
3 
4 #include <CCfits/CCfits>
5 
6 #include "MessageImp.h"
7 #include "Time.h"
8 
9 class FitsFile : public MessageImp
10 {
11 public:
13 
14  std::vector<std::string> fColNames;
15  std::vector<std::string> fColTypes;
16  std::vector<std::string> fColUnits;
17 
18  CCfits::FITS* fFile;
19  CCfits::Table* fTable;
20 
21  size_t fNumRows;
22  size_t fCursor;
23 
24  bool fIsOwner;
25 
26  int Write(const Time &time, const std::string &txt, int qos)
27  {
28  return fMsg.Write(time, txt, qos);
29  }
30 
31 public:
33  fMsg(imp), fFile(0), fTable(0), fNumRows(0), fCursor(0)
34  {
35  }
36  ~FitsFile() { Close(); }
37 
38  bool WriteDefaultKeys(const string &prgname, float version=1.0);
39 
40  void AddColumn(char type, const string &name, int numElems=1, const string &unit="");
41  void AddColumn(const string &name, const string &format, const string &unit="");
42  void AddColumn(char type, const string &name, const string &unit)
43  {
44  AddColumn(type, name, 1, unit);
45  }
46 
47  void ResetColumns();
48 
49  bool OpenFile(const string &filename, bool allow_open=false);
50  bool SetFile(CCfits::FITS *file=0);
51  bool OpenTable(const string &tablename);
52  bool OpenNewTable(const string &tableName, int maxtry=1);
53 
54  template <typename T>
55  void WriteKey(const string &name, const T &value, const string &comment)
56  {
57  if (fTable)
58  fTable->addKey(name, value, comment);
59  }
60 
61  template <typename T>
62  bool WriteKeyNT(const string &name, const T &value, const string &comment)
63  {
64  if (!fTable)
65  return false;
66 
67  try
68  {
69  fTable->addKey(name, value, comment);
70  }
71  catch (CCfits::FitsException e)
72  {
73  Error("CCfits::Table::addKey failed for '"+name+"' in '"+fFile->name()+'/'+fTable->name()+"': "+e.message());
74  return false;
75  }
76 
77  return true;
78  }
79 
80  bool AddRow();
81  bool WriteData(size_t &start, const void *ptr, size_t size);
82  bool WriteData(const void *ptr, size_t size)
83  {
84  return WriteData(fCursor, ptr, size);
85  }
86 
87  template<typename T>
88  bool WriteData(const std::vector<T> &vec)
89  {
90  return WriteData(fCursor, vec.data(), vec.size()*sizeof(T));
91  }
92 
93  void Close();
94 
95  void Flush();
96 
97  bool IsOpen() const { return fFile && fTable; }
98 
99  const std::vector<std::string> &GetColumnTypes() const { return fColTypes; }
100  string GetName() const { return fFile ? fFile->name() : "<no file open>"; }
101  bool IsOwner() const { return fIsOwner; }
102 
103  size_t GetDataSize() const;
104 
105  size_t GetNumRows() const { return fNumRows; }
106 
107 };
108 
109 #endif
int start(int initState)
Definition: feeserver.c:1740
size_t fNumRows
The pointer to the CCfits binary table.
Definition: FitsFile.h:21
MessageImp & fMsg
Definition: FitsFile.h:12
FitsFile(MessageImp &imp)
Definition: FitsFile.h:32
size_t GetDataSize() const
Definition: FitsFile.cc:463
CCfits::Table * fTable
The pointer to the CCfits FITS file.
Definition: FitsFile.h:19
bool IsOpen() const
Definition: FitsFile.h:97
The base implementation of a distributed messaging system.
Definition: MessageImp.h:10
Adds some functionality to boost::posix_time::ptime for our needs.
Definition: Time.h:30
const std::vector< std::string > & GetColumnTypes() const
Definition: FitsFile.h:99
void WriteKey(const string &name, const T &value, const string &comment)
Definition: FitsFile.h:55
bool SetFile(CCfits::FITS *file=0)
Definition: FitsFile.cc:139
bool WriteDefaultKeys(const string &prgname, float version=1.0)
Definition: FitsFile.cc:21
size_t GetNumRows() const
Definition: FitsFile.h:105
bool IsOwner() const
Definition: FitsFile.h:101
bool AddRow()
Definition: FitsFile.cc:368
void ResetColumns()
Definition: FitsFile.cc:132
bool WriteData(const std::vector< T > &vec)
Definition: FitsFile.h:88
virtual int Write(const Time &time, const std::string &txt, int qos=kMessage)
Definition: MessageImp.cc:133
CCfits::FITS * fFile
Definition: FitsFile.h:18
int type
uint16_t qos
Definition: HeadersGPS.h:29
~FitsFile()
Definition: FitsFile.h:36
void Flush()
Definition: FitsFile.cc:445
int Error(const std::string &str)
Definition: MessageImp.h:49
bool OpenFile(const string &filename, bool allow_open=false)
Definition: FitsFile.cc:94
std::vector< std::string > fColTypes
Definition: FitsFile.h:15
bool OpenTable(const string &tablename)
Definition: FitsFile.cc:159
Warning because the service this data corrsponds to might have been last updated longer ago than Local time
Definition: smartfact.txt:92
bool WriteKeyNT(const string &name, const T &value, const string &comment)
Definition: FitsFile.h:62
size_t fCursor
the number of rows that have been written already to the FITS file.
Definition: FitsFile.h:22
bool WriteData(const void *ptr, size_t size)
Definition: FitsFile.h:82
FITS writter for the FACT project.
Definition: FitsFile.h:9
int size
Definition: db_dim_server.c:17
string GetName() const
Definition: FitsFile.h:100
std::vector< std::string > fColUnits
Definition: FitsFile.h:16
void AddColumn(char type, const string &name, int numElems=1, const string &unit="")
bool WriteData(size_t &start, const void *ptr, size_t size)
Definition: FitsFile.cc:400
std::vector< std::string > fColNames
Definition: FitsFile.h:14
void Close()
Definition: FitsFile.cc:428
bool OpenNewTable(const string &tableName, int maxtry=1)
Definition: FitsFile.cc:206
int Write(const Time &time, const std::string &txt, int qos)
Definition: FitsFile.h:26
bool fIsOwner
Definition: FitsFile.h:24
void AddColumn(char type, const string &name, const string &unit)
Definition: FitsFile.h:42
Changes for version
Definition: README_v11.txt:85