GammaLib  1.7.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GFitsTableCol.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GFitsTableCol.hpp - FITS table column abstract base class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2008-2017 by Juergen Knoedlseder *
5  * ----------------------------------------------------------------------- *
6  * *
7  * This program is free software: you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation, either version 3 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
19  * *
20  ***************************************************************************/
21 /**
22  * @file GFitsTableCol.hpp
23  * @brief FITS table column abstract base class definition
24  * @author Juergen Knoedlseder
25  */
26 
27 #ifndef GFITSTABLECOL_HPP
28 #define GFITSTABLECOL_HPP
29 
30 /* __ Includes ___________________________________________________________ */
31 #include <string>
32 #include <vector>
33 #include "GBase.hpp"
34 
35 
36 /***********************************************************************//**
37  * @class GFitsTableCol
38  *
39  * @brief Abstract interface for FITS table column
40  *
41  * This class provides an abstract base class for all FITS table columns.
42  * The class supports both fixed-length and variable-length vector columns.
43  ***************************************************************************/
44 class GFitsTableCol : public GBase {
45 
46  // Friend classes
47  friend class GFitsTable;
48 
49 public:
50  // Constructors and destructors
51  GFitsTableCol(void);
52  GFitsTableCol(const std::string& name,
53  const int& nrows,
54  const int& number,
55  const int& width);
56  GFitsTableCol(const GFitsTableCol& column);
57  virtual ~GFitsTableCol(void);
58 
59  // Operators
60  GFitsTableCol& operator=(const GFitsTableCol& column);
61 
62  // Pure virtual methods
63  virtual void clear(void) = 0;
64  virtual GFitsTableCol* clone(void) const = 0;
65  virtual std::string classname(void) const = 0;
66  virtual std::string string(const int& row, const int& inx = 0) const = 0;
67  virtual double real(const int& row, const int& inx = 0) const = 0;
68  virtual int integer(const int& row, const int& inx = 0) const = 0;
69  virtual void insert(const int& row, const int& nrows) = 0;
70  virtual void remove(const int& row, const int& nrows) = 0;
71  virtual bool is_loaded(void) const = 0;
72 
73  // Other methods
74  void name(const std::string& name);
75  const std::string& name(void) const;
76  void unit(const std::string& unit);
77  const std::string& unit(void) const;
78  void dim(const std::vector<int>& dim);
79  const std::vector<int>& dim(void) const;
80  void colnum(const int& colnum);
81  const int& colnum(void) const;
82  void type(const int& type);
83  const int& type(void) const;
84  void repeat(const int& repeat);
85  const int& repeat(void) const;
86  void width(const int& width);
87  const int& width(void) const;
88  void number(const int& number);
89  const int& number(void) const;
90  void elements(const int& row, const int& elements);
91  int elements(const int& row) const;
92  void nrows(const int& nrows);
93  const int& nrows(void) const;
94  void is_variable(const bool& variable);
95  const bool& is_variable(void) const;
96  void anynul(const int& anynul);
97  const int& anynul(void) const;
98  void scale(const double& tscale, const double& tzero) const;
99  std::string tform_binary(void) const;
100  std::string print(const GChatter& chatter = NORMAL) const;
101 
102 protected:
103  // Protected methods
104  void init_members(void);
105  void copy_members(const GFitsTableCol& column);
106  void free_members(void);
107  void connect(void* vptr);
108 
109  // Protected pure virtual methods
110  virtual void alloc_data(void) = 0;
111  virtual void init_data(void) = 0;
112  virtual void fetch_data(void) const = 0;
113  virtual void resize_data(const int& index, const int& number) = 0;
114  virtual void release_data(void) = 0;
115  virtual void* ptr_data(const int& index = 0) = 0;
116  virtual void* ptr_nulval(void) = 0;
117  virtual std::string ascii_format(void) const = 0;
118 
119  // Protected virtual methods
120  virtual void save(void);
121  virtual void load_column(void);
122  virtual void load_column_fixed(void);
123  virtual void load_column_variable(void);
124  virtual void save_column(void);
125  virtual void save_column_fixed(void);
126  virtual void save_column_variable(void);
127  virtual int offset(const int& row, const int& inx) const;
128 
129  // Protected data area
130  std::string m_name; //!< Column name
131  std::string m_unit; //!< Column unit
132  std::vector<int> m_dim; //!< Column dimension
133  int m_colnum; //!< @brief Column number (starting from 1).
134  //!< This parameter is used to signal if a
135  //!< table column corresponds to a FITS file
136  //!< column. If it is set to 0 there is no
137  //!< correspondence.
138  int m_type; //!< Column type
139  int m_repeat; //!< Repeat value of column
140  int m_width; //!< Width in Bytes of single column element
141  int m_number; //!< Number of elements in column
142  int m_length; //!< Length of column (number of rows)
143  bool m_variable; //!< Signals if column is variable length
144  int m_varlen; //!< Maximum number of elements in variable-length
145  std::vector<int> m_rowstart; //!< Start index of each row
146  mutable int m_size; //!< Size of allocated data area (0 if not loaded)
147  int m_anynul; //!< Number of NULLs encountered
148  void* m_fitsfile; //!< FITS file pointer associated with column
149 };
150 
151 
152 /***********************************************************************//**
153  * @brief Set column name
154  *
155  * @param[in] name Column name.
156  ***************************************************************************/
157 inline
158 void GFitsTableCol::name(const std::string& name)
159 {
160  // Set name
161  m_name = name;
162 
163  // Return
164  return;
165 }
166 
167 
168 /***********************************************************************//**
169  * @brief Returns column name
170  *
171  * @return Column name.
172  ***************************************************************************/
173 inline
174 const std::string& GFitsTableCol::name(void) const
175 {
176  // Return name
177  return m_name;
178 }
179 
180 
181 /***********************************************************************//**
182  * @brief Set column unit
183  *
184  * @param[in] unit Column unit.
185  ***************************************************************************/
186 inline
187 void GFitsTableCol::unit(const std::string& unit)
188 {
189  // Set unit
190  m_unit = unit;
191 
192  // Return
193  return;
194 }
195 
196 
197 /***********************************************************************//**
198  * @brief Returns column unit
199  *
200  * @return Column unit.
201  ***************************************************************************/
202 inline
203 const std::string& GFitsTableCol::unit(void) const
204 {
205  // Return column unit
206  return m_unit;
207 }
208 
209 
210 /***********************************************************************//**
211  * @brief Set column dimension
212  *
213  * @param[in] dim Vector of column dimensions.
214  *
215  * Sets the column dimension is a integer vector @p dim.
216  *
217  * @todo Implement dimension check.
218  ***************************************************************************/
219 inline
220 void GFitsTableCol::dim(const std::vector<int>& dim)
221 {
222  // Set dimension
223  m_dim = dim;
224 
225  // Return
226  return;
227 }
228 
229 
230 /***********************************************************************//**
231  * @brief Returns column dimension
232  *
233  * @return Column dimensions (specified by TDIM keyword).
234  ***************************************************************************/
235 inline
236 const std::vector<int>& GFitsTableCol::dim(void) const
237 {
238  // Return column dimension
239  return m_dim;
240 }
241 
242 
243 /***********************************************************************//**
244  * @brief Set column number
245  *
246  * @param[in] colnum Column number.
247  ***************************************************************************/
248 inline
250 {
251  // Set column number
252  m_colnum = colnum;
253 
254  // Return
255  return;
256 }
257 
258 
259 /***********************************************************************//**
260  * @brief Returns column number in FITS file (starting from 1)
261  *
262  * @return Column number in FITS file (starting from 1).
263  ***************************************************************************/
264 inline
265 const int& GFitsTableCol::colnum(void) const
266 {
267  // Return column number
268  return m_colnum;
269 }
270 
271 
272 /***********************************************************************//**
273  * @brief Set type code
274  *
275  * @param[in] type Type code.
276  ***************************************************************************/
277 inline
278 void GFitsTableCol::type(const int& type)
279 {
280  // Set type code
281  m_type = type;
282 
283  // Return
284  return;
285 }
286 
287 
288 /***********************************************************************//**
289  * @brief Returns CFITSIO column type
290  *
291  * Returns one of the following:
292  * 1 (TBIT)
293  * 11 (TBYTE)
294  * 12 (TSBYTE)
295  * 14 (TLOGICAL)
296  * 16 (TSTRING)
297  * 20 (TUSHORT)
298  * 21 (TSHORT)
299  * 30 (TUINT)
300  * 31 (TINT)
301  * 40 (TULONG)
302  * 41 (TLONG)
303  * 42 (TFLOAT)
304  * 81 (TLONGLONG)
305  * 82 (TDOUBLE)
306  * 83 (TCOMPLEX)
307  * 163 (TDBLCOMPLEX)
308  *
309  * If the type value is negative, the column is a variable-length column.
310  ***************************************************************************/
311 inline
312 const int& GFitsTableCol::type(void) const
313 {
314  // Return column type
315  return m_type;
316 }
317 
318 
319 /***********************************************************************//**
320  * @brief Set repeat value
321  *
322  * @param[in] repeat Repeat value.
323  ***************************************************************************/
324 inline
325 void GFitsTableCol::repeat(const int& repeat)
326 {
327  // Set repeat
328  m_repeat = repeat;
329 
330  // Return
331  return;
332 }
333 
334 
335 /***********************************************************************//**
336  * @brief Returns column repeat value (only used for binary tables)
337  ***************************************************************************/
338 inline
339 const int& GFitsTableCol::repeat(void) const
340 {
341  // Return column repeat value
342  return m_repeat;
343 }
344 
345 
346 /***********************************************************************//**
347  * @brief Set width in Bytes of one column element
348  *
349  * @param[in] width Width in Bytes of one column element.
350  ***************************************************************************/
351 inline
352 void GFitsTableCol::width(const int& width)
353 {
354  // Set width
355  m_width = width;
356 
357  // Return
358  return;
359 }
360 
361 
362 /***********************************************************************//**
363  * @brief Return width in Bytes of one column element
364  *
365  * @return Width in Bytes of one column element.
366  ***************************************************************************/
367 inline
368 const int& GFitsTableCol::width(void) const
369 {
370  // Return width of one element in column
371  return m_width;
372 }
373 
374 
375 /***********************************************************************//**
376  * @brief Set number of elements in column
377  *
378  * @param[in] number Number of elements in column.
379  ***************************************************************************/
380 inline
382 {
383  // Set number of elements
384  m_number = number;
385 
386  // Return
387  return;
388 }
389 
390 
391 /***********************************************************************//**
392  * @brief Returns number of elements in column
393  *
394  * @return Number of elements in column.
395  ***************************************************************************/
396 inline
397 const int& GFitsTableCol::number(void) const
398 {
399  // Return number of elements in a column
400  return m_number;
401 }
402 
403 
404 /***********************************************************************//**
405  * @brief Set number of rows in column
406  *
407  * @param[in] nrows Number of rows in column.
408  *
409  * Sets the number of rows in column.
410  ***************************************************************************/
411 inline
412 void GFitsTableCol::nrows(const int& nrows)
413 {
414  // Set length
415  m_length = nrows;
416 
417  // Return
418  return;
419 }
420 
421 
422 /***********************************************************************//**
423  * @brief Returns number of rows in column
424  *
425  * @return Number of rows in column.
426  ***************************************************************************/
427 inline
428 const int& GFitsTableCol::nrows(void) const
429 {
430  // Return column length
431  return m_length;
432 }
433 
434 
435 /***********************************************************************//**
436  * @brief Set variable-length flag
437  *
438  * @param[in] variable Variable-length flag.
439  ***************************************************************************/
440 inline
441 void GFitsTableCol::is_variable(const bool& variable)
442 {
443  // Set variable-length flag
444  m_variable = variable;
445 
446  // Return
447  return;
448 }
449 
450 
451 /***********************************************************************//**
452  * @brief Signals if column is of variable length
453  *
454  * @return True if column is a variable length column
455  ***************************************************************************/
456 inline
457 const bool& GFitsTableCol::is_variable(void) const
458 {
459  // Return variable-length flag
460  return m_variable;
461 }
462 
463 
464 /***********************************************************************//**
465  * @brief Set number of NULLs encountered
466  *
467  * @param[in] anynul Number of NULLs encountered.
468  ***************************************************************************/
469 inline
470 void GFitsTableCol::anynul(const int& anynul)
471 {
472  // Set number of NULLs encountered
473  m_anynul = anynul;
474 
475  // Return
476  return;
477 }
478 
479 
480 /***********************************************************************//**
481  * @brief Returns number of NULLs encountered
482  ***************************************************************************/
483 inline
484 const int& GFitsTableCol::anynul(void) const
485 {
486  // Return number of NULLs encountered
487  return m_anynul;
488 }
489 
490 #endif /* GFITSTABLECOL_HPP */
virtual void * ptr_nulval(void)=0
virtual GFitsTableCol * clone(void) const =0
Clones object.
virtual void init_data(void)=0
const int & anynul(void) const
Returns number of NULLs encountered.
int m_type
Column type.
std::string number(const std::string &noun, const int &number)
Convert singular noun into number noun.
Definition: GTools.cpp:1044
void connect(void *vptr)
Connect table column to FITS file.
int m_colnum
Column number (starting from 1). This parameter is used to signal if a table column corresponds to a ...
bool m_variable
Signals if column is variable length.
int m_anynul
Number of NULLs encountered.
void scale(const double &tscale, const double &tzero) const
Set table column scale value.
int m_number
Number of elements in column.
virtual ~GFitsTableCol(void)
Destructor.
void free_members(void)
Delete class members.
GFitsTableCol & operator=(const GFitsTableCol &column)
Assignment operator.
const std::string & name(void) const
Returns column name.
void elements(const int &row, const int &elements)
Set number of column elements for specific row.
Definition of interface for all GammaLib classes.
std::vector< int > m_dim
Column dimension.
int m_varlen
Maximum number of elements in variable-length.
const bool & is_variable(void) const
Signals if column is of variable length.
virtual void save_column_fixed(void)
Save table column into FITS file.
const std::string & unit(void) const
Returns column unit.
virtual void insert(const int &row, const int &nrows)=0
virtual void load_column(void)
Load table column from FITS file.
const int & colnum(void) const
Returns column number in FITS file (starting from 1)
virtual void alloc_data(void)=0
virtual std::string string(const int &row, const int &inx=0) const =0
virtual void load_column_variable(void)
Load variable-length column from FITS file.
const int & number(void) const
Returns number of elements in column.
std::string print(const GChatter &chatter=NORMAL) const
Print column information.
void init_members(void)
Initialise class members.
virtual void release_data(void)=0
std::string m_unit
Column unit.
Abstract interface for FITS table column.
Interface class for all GammaLib classes.
Definition: GBase.hpp:52
std::vector< int > m_rowstart
Start index of each row.
int m_repeat
Repeat value of column.
const std::vector< int > & dim(void) const
Returns column dimension.
Abstract interface for FITS table.
Definition: GFitsTable.hpp:44
GChatter
Definition: GTypemaps.hpp:33
std::string m_name
Column name.
virtual void save(void)
Save table column into FITS file.
virtual void resize_data(const int &index, const int &number)=0
const int & nrows(void) const
Return number of rows in table.
Definition: GFitsTable.hpp:119
int m_length
Length of column (number of rows)
int colnum(const std::string &colname) const
Returns column number of a given column name.
const int & repeat(void) const
Returns column repeat value (only used for binary tables)
virtual void * ptr_data(const int &index=0)=0
virtual void clear(void)=0
Clear object.
virtual int integer(const int &row, const int &inx=0) const =0
virtual double real(const int &row, const int &inx=0) const =0
int m_size
Size of allocated data area (0 if not loaded)
virtual int offset(const int &row, const int &inx) const
Compute offset of column element in memory.
virtual bool is_loaded(void) const =0
void copy_members(const GFitsTableCol &column)
Copy class members.
GFitsTableCol(void)
Void constructor.
virtual void save_column(void)
Save table column into FITS file.
const int & type(void) const
Returns CFITSIO column type.
virtual void fetch_data(void) const =0
virtual void save_column_variable(void)
Save table column into FITS file.
void * m_fitsfile
FITS file pointer associated with column.
const int & nrows(void) const
Returns number of rows in column.
virtual std::string ascii_format(void) const =0
virtual void load_column_fixed(void)
Load fixed-length column from FITS file.
const int & width(void) const
Return width in Bytes of one column element.
int m_width
Width in Bytes of single column element.
virtual std::string classname(void) const =0
Return class name.
std::string tform_binary(void) const
Returns TFORM code for binary table column.