Luiza  v03-01
GloriaFitsTable.h
1 // -*- mode: c++; mode: auto-fill; mode: flyspell-prog; -*-
2 
3 
4 #ifndef GloriaFitsTable_h
5 #define GloriaFitsTable_h 1
6 
7 
8 /*
9  * This source code is part of the LUIZA software package for GLORIA.
10  * You are free to use this source files for your own development as
11  * long as it stays in a public research context. You are not
12  * allowed to use it for commercial purpose. You must put this
13  * header with author names in all development based on this file.
14  *
15  */
16 
17 #include <string>
18 #include <vector>
19 #include <map>
20 
21 #include "GloriaFitsHeader.h"
22 #include "GloriaTableColumn.h"
23 
24 using namespace std;
25 
26 namespace gloria{
27 
29 
110 
111  public:
112 
114 
116  GloriaFitsTable();
117 
119  /* Creates empty table and reads its contents from the fits file */
120  GloriaFitsTable(string FitsFileName);
121 
123  GloriaFitsTable(const GloriaFitsTable& sourceFitsTable);
124 
126  virtual ~GloriaFitsTable();
127 
129  GloriaFitsTable& operator= (const GloriaFitsTable& tab);
130 
132 
135  void ReadFitsFile(string FitsFileName);
136 
138 
141  void ReadTextFile(string TextFileName);
142 
144 
146  void WriteFitsFile(string FitsFileName, bool binary_tbl=true);
147 
149 
151  void WriteTextFile(string TextFileName, int colWidth=10, char ColumnSeparator = ' ');
152 
154 
156  void WriteTextStream(std::ostream& outF, int colWidth=10, char ColumnSeparator = ' ');
157 
158 
159  // Data access methods
160  // ===================
161 
163  inline int GetColumnNumber() {return _nColumn;};
164 
166  inline int GetRowNumber() {return _nRow;};
167 
169  inline string GetColumnName(int iCol)
170  {return _columns.at(iCol)->Name();};
171 
173  inline int GetColumnId(string name)
174  {return _nameMap.find(name)->second; };
175 
178  {return _columns.at(iCol)->Type(); };
179 
181  inline TableColumnType GetColumnType(string name)
182  {return _columns.at(_nameMap.find(name)->second)->Type(); };
183 
184 
186  inline bool ColumnExists(string name)
187  {return _nameMap.find(name)!=_nameMap.end();};
188 
190  inline GloriaTableColumn* GetColumn(int iCol)
191  {return _columns.at(iCol); } ;
192 
194  inline GloriaTableColumn* GetColumn(string name)
195  {return _columns.at(_nameMap.find(name)->second); } ;
196 
198  /* This method DOES NOT check consistency of types nor indexes - be careful */
199  template <class T>
201  {return (GloriaTableColumnOf<T> *)_columns.at(iCol); } ;
202 
204  /* This method DOES NOT check consistency of types nor indexes - be careful */
205  template <class T>
206  inline GloriaTableColumnOf<T>* GetColumnOf(string name)
207  {return (GloriaTableColumnOf<T> *)_columns.at(_nameMap.find(name)->second); } ;
208 
210  /* This method DOES NOT check consistency of types nor indexes - be careful */
211  template <class T>
212  inline vector<T>& GetVectorOf(int iCol)
213  { return ((GloriaTableColumnOf<T> *)_columns.at(iCol))->Data(); };
214 
215 
217  /* This method DOES NOT check consistency of types nor indexes - be careful */
218  template <class T>
219  inline vector<T>& GetVectorOf(string name)
220  { return ((GloriaTableColumnOf<T> *)_columns.at(_nameMap.find(name)->second))->Data(); };
221 
222 
224  /* This method DOES NOT check consistency of types nor indexes - be careful */
225  template <class T>
226  inline T& GetValueOf(int iCol, int iRow)
227  { return ((GloriaTableColumnOf<T> *)_columns.at(iCol))->At(iRow); };
228 
229 
231  /* This method DOES NOT check consistency of types nor indexes - be careful */
232  template <class T>
233  inline T& GetValueOf(string name, int iRow)
234  { return ((GloriaTableColumnOf<T> *)_columns.at(_nameMap.find(name)->second))->At(iRow); };
235 
236 
238 
242  void AddColumn(string Name, TableColumnType Type, string Unit = "" , string Comment = "" );
243 
244 
246 
250  template <class T>
251  void AddColumn(string Name, T empty, string Unit = "" , string Comment = "" );
252 
254 
258  void InsertColumn(GloriaTableColumn* source);
259 
261 
266  void InsertColumn(string NewName, GloriaTableColumn* source);
267 
269 
273  void AddRow();
274 
275 
277 
280  template <class T>
281  inline void AddRow(T val){ AddRow(); SetLast(0,val); };
282 
284 
287  template <class T0, class T1>
288  inline void AddRow(T0 val0, T1 val1){ AddRow(); SetLast(0,val0); SetLast(1,val1);};
289 
290 
292 
295  template <class T0, class T1, class T2>
296  inline void AddRow(T0 val0, T1 val1, T2 val2){ AddRow(); SetLast(0,val0); SetLast(1,val1); SetLast(2,val2);};
297 
299 
302  template <class T0, class T1, class T2, class T3>
303  inline void AddRow(T0 val0, T1 val1, T2 val2, T3 val3)
304  { AddRow(); SetLast(0,val0); SetLast(1,val1); SetLast(2,val2);SetLast(3,val3);};
305 
307 
310  template <class T0, class T1, class T2, class T3, class T4>
311  inline void AddRow(T0 val0, T1 val1, T2 val2, T3 val3, T4 val4)
312  { AddRow(); SetLast(0,val0); SetLast(1,val1); SetLast(2,val2);SetLast(3,val3);SetLast(4,val4);};
313 
315  /* This method checks consistency of variable and column types */
316  template <class T>
317  void SetValue(string Name, int iRow, T val);
318 
319 
321  /* This method checks consistency of variable and column types */
322  template <class T>
323  void SetValue(int iCol, int iRow, T val);
324 
325 
327  /* This method checks consistency of variable and column types */
328  template <class T>
329  void SetLast(int iCol, T val);
330 
332  /* This method checks consistency of variable and column types */
333  template <class T>
334  void SetLast(string Name, T val);
335 
337  /* This method checks consistency of variable and column types */
338  template <class T>
339  void GetValue(string Name, int iRow, T* val);
340 
342  /* This method checks consistency of variable and column types */
343  template <class T>
344  void GetValue(int iCol, int iRow, T* val);
345 
347 
348  void CopyTableRow(GloriaFitsTable* source, int isource, int itarget=-1);
349 
351  GloriaFitsTable* EmptyClone();
352 
354  void AdjustColumns();
355 
357  bool CheckTable();
358 
359 
361  long* CreateSortIndex(int iCol, bool reverse=false);
362 
364  long* CreateSortIndex(string name, bool reverse=false);
365 
367  void SortTable(int iCol, bool reverse=false);
368 
370  void SortTable(string name, bool reverse=false);
371 
372 
374  inline bool IsSorted() { return (_nSorted == _nRow); } ;
375 
377  inline bool IsSortedBy(string name)
378  { return (_nSorted == _nRow && name == _sortName); } ;
379 
381  inline string SortName() { return _sortName; } ;
382 
384  inline int SortColumn() { return _sortColumn; } ;
385 
387  void DeleteRow(int iRow);
388 
390  GloriaTableColumn* RemoveColumn(int iCol);
391 
393  GloriaTableColumn* RemoveColumn(string name);
394 
396  void DeleteColumn(int iCol);
397 
399  void DeleteColumn(string name);
400 
402  void ClearTable();
403 
405  void EmptyTable();
406 
408  /* Column width can be set between 3 and 20 characters */
409 
410  void Print( std::ostream& os, int colWidth=10);
411 
412 protected:
413 
414  void InitializeEmptyTable();
415 
416 
418  int _nRow, _nColumn;
419 
421  vector<GloriaTableColumn* > _columns;
422 
424  multimap< string, int > _nameMap;
425 
427  int _nSorted;
428 
430  string _sortName;
431 
434 
435  } ;
436 
437 
438 }
439 
440 #endif
string SortName()
Return name of the column used for table sorting.
Definition: GloriaFitsTable.h:381
TableColumnType
Enumerator for allowed column type classes.
Definition: GloriaTableColumn.h:46
TableColumnType GetColumnType(string name)
Returns type for given column name.
Definition: GloriaFitsTable.h:181
bool IsSorted()
Check if table is sorted.
Definition: GloriaFitsTable.h:374
int _sortColumn
ID of column used for sorting.
Definition: GloriaFitsTable.h:433
T & GetValueOf(int iCol, int iRow)
Returns value of given type, from given column index and row.
Definition: GloriaFitsTable.h:226
namespace for data storing and exchange formats
Definition: GloriaAstrometry.h:15
string _sortName
Name of column used for sorting.
Definition: GloriaFitsTable.h:430
GloriaTableColumnOf< T > * GetColumnOf(int iCol)
Returns pointer to the column of given type, for given column index.
Definition: GloriaFitsTable.h:200
void AddRow(T0 val0, T1 val1, T2 val2)
Add new row and set value to the first three columns.
Definition: GloriaFitsTable.h:296
void AddRow(T0 val0, T1 val1)
Add new row and set value to the first two columns.
Definition: GloriaFitsTable.h:288
bool IsSortedBy(string name)
Check if table is sorted by given column.
Definition: GloriaFitsTable.h:377
vector< T > & GetVectorOf(int iCol)
Returns data vector of given type, from given column index.
Definition: GloriaFitsTable.h:212
Abstract class. Used for deriving classes with different column types.
Definition: GloriaTableColumn.h:80
multimap< string, int > _nameMap
Column name map. Name is not always unique!
Definition: GloriaFitsTable.h:424
bool ColumnExists(string name)
Check if given column exists.
Definition: GloriaFitsTable.h:186
string GetColumnName(int iCol)
Returns name of column.
Definition: GloriaFitsTable.h:169
int GetColumnId(string name)
Returns column Id.
Definition: GloriaFitsTable.h:173
int _nSorted
Number of sorted rows.
Definition: GloriaFitsTable.h:427
T & GetValueOf(string name, int iRow)
Returns value of given type, from given column name and row.
Definition: GloriaFitsTable.h:233
Table column class for different content types.
Definition: GloriaTableColumn.h:185
int _nRow
Table size.
Definition: GloriaFitsTable.h:418
TableColumnType GetColumnType(int iCol)
Returns type of column.
Definition: GloriaFitsTable.h:177
int GetColumnNumber()
Returns number of defined columns.
Definition: GloriaFitsTable.h:163
GloriaTableColumn * GetColumn(int iCol)
Returns base class pointer for given column index.
Definition: GloriaFitsTable.h:190
GloriaTableColumnOf< T > * GetColumnOf(string name)
Returns pointer to the column of given type, for given column name.
Definition: GloriaFitsTable.h:206
Class for reading and processing fits tables in Luiza.
Definition: GloriaFitsTable.h:109
void AddRow(T val)
Add new row and set value to the first column.
Definition: GloriaFitsTable.h:281
int SortColumn()
Return name of the column used for table sorting.
Definition: GloriaFitsTable.h:384
void AddRow(T0 val0, T1 val1, T2 val2, T3 val3, T4 val4)
Add new row and set value to the first five columns.
Definition: GloriaFitsTable.h:311
Class for handling fits file headers.
Definition: GloriaFitsHeader.h:33
GloriaTableColumn * GetColumn(string name)
Returns base class pointer for named column stored in the table.
Definition: GloriaFitsTable.h:194
int GetRowNumber()
Returns number of filled rows.
Definition: GloriaFitsTable.h:166
vector< T > & GetVectorOf(string name)
Returns data vector of given type, from given column name.
Definition: GloriaFitsTable.h:219
vector< GloriaTableColumn * > _columns
Column vector.
Definition: GloriaFitsTable.h:421
void AddRow(T0 val0, T1 val1, T2 val2, T3 val3)
Add new row and set value to the first four columns.
Definition: GloriaFitsTable.h:303