GammaLib  2.1.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-2021 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 tscale(const double& tscale);
99  const double& tscale(void) const;
100  std::string tform_binary(void) const;
101  std::string print(const GChatter& chatter = NORMAL) const;
102 
103 protected:
104  // Protected methods
105  void init_members(void);
106  void copy_members(const GFitsTableCol& column);
107  void free_members(void);
108  void connect(void* vptr);
109 
110  // Protected pure virtual methods
111  virtual void alloc_data(void) = 0;
112  virtual void init_data(void) = 0;
113  virtual void fetch_data(void) const = 0;
114  virtual void resize_data(const int& index, const int& number) = 0;
115  virtual void release_data(void) = 0;
116  virtual void* ptr_data(const int& index = 0) = 0;
117  virtual void* ptr_nulval(void) = 0;
118  virtual std::string ascii_format(void) const = 0;
119 
120  // Protected virtual methods
121  virtual void save(void);
122  virtual void load_column(void);
123  virtual void load_column_fixed(void);
124  virtual void load_column_variable(void);
125  virtual void save_column(void);
126  virtual void save_column_fixed(void);
127  virtual void save_column_variable(void);
128  virtual int offset(const int& row, const int& inx) const;
129 
130  // Protected data area
131  std::string m_name; //!< Column name
132  std::string m_unit; //!< Column unit
133  std::vector<int> m_dim; //!< Column dimension
134  int m_colnum; //!< @brief Column number (starting from 1).
135  //!< This parameter is used to signal if a
136  //!< table column corresponds to a FITS file
137  //!< column. If it is set to 0 there is no
138  //!< correspondence.
139  int m_type; //!< Column type
140  int m_repeat; //!< Repeat value of column
141  int m_width; //!< Width in Bytes of single column element
142  int m_number; //!< Number of elements in column
143  int m_length; //!< Length of column (number of rows)
144  bool m_variable; //!< Signals if column is variable length
145  int m_varlen; //!< Maximum number of elements in variable-length
146  std::vector<int> m_rowstart; //!< Start index of each row
147  mutable int m_size; //!< Size of allocated data area (0 if not loaded)
148  int m_anynul; //!< Number of NULLs encountered
149  void* m_fitsfile; //!< FITS file pointer associated with column
150  double m_tscale; //!< Optional scaling factor (1 = no scaling)
151 };
152 
153 
154 /***********************************************************************//**
155  * @brief Set column name
156  *
157  * @param[in] name Column name.
158  ***************************************************************************/
159 inline
160 void GFitsTableCol::name(const std::string& name)
161 {
162  // Set name
163  m_name = name;
164 
165  // Return
166  return;
167 }
168 
169 
170 /***********************************************************************//**
171  * @brief Returns column name
172  *
173  * @return Column name.
174  ***************************************************************************/
175 inline
176 const std::string& GFitsTableCol::name(void) const
177 {
178  // Return name
179  return m_name;
180 }
181 
182 
183 /***********************************************************************//**
184  * @brief Set column unit
185  *
186  * @param[in] unit Column unit.
187  ***************************************************************************/
188 inline
189 void GFitsTableCol::unit(const std::string& unit)
190 {
191  // Set unit
192  m_unit = unit;
193 
194  // Return
195  return;
196 }
197 
198 
199 /***********************************************************************//**
200  * @brief Returns column unit
201  *
202  * @return Column unit.
203  ***************************************************************************/
204 inline
205 const std::string& GFitsTableCol::unit(void) const
206 {
207  // Return column unit
208  return m_unit;
209 }
210 
211 
212 /***********************************************************************//**
213  * @brief Set column dimension
214  *
215  * @param[in] dim Vector of column dimensions.
216  *
217  * Sets the column dimension is a integer vector @p dim.
218  *
219  * @todo Implement dimension check.
220  ***************************************************************************/
221 inline
222 void GFitsTableCol::dim(const std::vector<int>& dim)
223 {
224  // Set dimension
225  m_dim = dim;
226 
227  // Return
228  return;
229 }
230 
231 
232 /***********************************************************************//**
233  * @brief Returns column dimension
234  *
235  * @return Column dimensions (specified by TDIM keyword).
236  ***************************************************************************/
237 inline
238 const std::vector<int>& GFitsTableCol::dim(void) const
239 {
240  // Return column dimension
241  return m_dim;
242 }
243 
244 
245 /***********************************************************************//**
246  * @brief Set column number
247  *
248  * @param[in] colnum Column number.
249  ***************************************************************************/
250 inline
252 {
253  // Set column number
254  m_colnum = colnum;
255 
256  // Return
257  return;
258 }
259 
260 
261 /***********************************************************************//**
262  * @brief Returns column number in FITS file (starting from 1)
263  *
264  * @return Column number in FITS file (starting from 1).
265  ***************************************************************************/
266 inline
267 const int& GFitsTableCol::colnum(void) const
268 {
269  // Return column number
270  return m_colnum;
271 }
272 
273 
274 /***********************************************************************//**
275  * @brief Set type code
276  *
277  * @param[in] type Type code.
278  ***************************************************************************/
279 inline
280 void GFitsTableCol::type(const int& type)
281 {
282  // Set type code
283  m_type = type;
284 
285  // Return
286  return;
287 }
288 
289 
290 /***********************************************************************//**
291  * @brief Returns CFITSIO column type
292  *
293  * Returns one of the following:
294  * 1 (TBIT)
295  * 11 (TBYTE)
296  * 12 (TSBYTE)
297  * 14 (TLOGICAL)
298  * 16 (TSTRING)
299  * 20 (TUSHORT)
300  * 21 (TSHORT)
301  * 30 (TUINT)
302  * 31 (TINT)
303  * 40 (TULONG)
304  * 41 (TLONG)
305  * 42 (TFLOAT)
306  * 81 (TLONGLONG)
307  * 82 (TDOUBLE)
308  * 83 (TCOMPLEX)
309  * 163 (TDBLCOMPLEX)
310  *
311  * If the type value is negative, the column is a variable-length column.
312  ***************************************************************************/
313 inline
314 const int& GFitsTableCol::type(void) const
315 {
316  // Return column type
317  return m_type;
318 }
319 
320 
321 /***********************************************************************//**
322  * @brief Set repeat value
323  *
324  * @param[in] repeat Repeat value.
325  ***************************************************************************/
326 inline
327 void GFitsTableCol::repeat(const int& repeat)
328 {
329  // Set repeat
330  m_repeat = repeat;
331 
332  // Return
333  return;
334 }
335 
336 
337 /***********************************************************************//**
338  * @brief Returns column repeat value (only used for binary tables)
339  ***************************************************************************/
340 inline
341 const int& GFitsTableCol::repeat(void) const
342 {
343  // Return column repeat value
344  return m_repeat;
345 }
346 
347 
348 /***********************************************************************//**
349  * @brief Set width in Bytes of one column element
350  *
351  * @param[in] width Width in Bytes of one column element.
352  ***************************************************************************/
353 inline
354 void GFitsTableCol::width(const int& width)
355 {
356  // Set width
357  m_width = width;
358 
359  // Return
360  return;
361 }
362 
363 
364 /***********************************************************************//**
365  * @brief Return width in Bytes of one column element
366  *
367  * @return Width in Bytes of one column element.
368  ***************************************************************************/
369 inline
370 const int& GFitsTableCol::width(void) const
371 {
372  // Return width of one element in column
373  return m_width;
374 }
375 
376 
377 /***********************************************************************//**
378  * @brief Set number of elements in column
379  *
380  * @param[in] number Number of elements in column.
381  ***************************************************************************/
382 inline
384 {
385  // Set number of elements
386  m_number = number;
387 
388  // Return
389  return;
390 }
391 
392 
393 /***********************************************************************//**
394  * @brief Returns number of elements in column
395  *
396  * @return Number of elements in column.
397  ***************************************************************************/
398 inline
399 const int& GFitsTableCol::number(void) const
400 {
401  // Return number of elements in a column
402  return m_number;
403 }
404 
405 
406 /***********************************************************************//**
407  * @brief Set number of rows in column
408  *
409  * @param[in] nrows Number of rows in column.
410  *
411  * Sets the number of rows in column.
412  ***************************************************************************/
413 inline
414 void GFitsTableCol::nrows(const int& nrows)
415 {
416  // Set length
417  m_length = nrows;
418 
419  // Return
420  return;
421 }
422 
423 
424 /***********************************************************************//**
425  * @brief Returns number of rows in column
426  *
427  * @return Number of rows in column.
428  ***************************************************************************/
429 inline
430 const int& GFitsTableCol::nrows(void) const
431 {
432  // Return column length
433  return m_length;
434 }
435 
436 
437 /***********************************************************************//**
438  * @brief Set variable-length flag
439  *
440  * @param[in] variable Variable-length flag.
441  ***************************************************************************/
442 inline
443 void GFitsTableCol::is_variable(const bool& variable)
444 {
445  // Set variable-length flag
446  m_variable = variable;
447 
448  // Return
449  return;
450 }
451 
452 
453 /***********************************************************************//**
454  * @brief Signals if column is of variable length
455  *
456  * @return True if column is a variable length column
457  ***************************************************************************/
458 inline
459 const bool& GFitsTableCol::is_variable(void) const
460 {
461  // Return variable-length flag
462  return m_variable;
463 }
464 
465 
466 /***********************************************************************//**
467  * @brief Set number of NULLs encountered
468  *
469  * @param[in] anynul Number of NULLs encountered.
470  ***************************************************************************/
471 inline
472 void GFitsTableCol::anynul(const int& anynul)
473 {
474  // Set number of NULLs encountered
475  m_anynul = anynul;
476 
477  // Return
478  return;
479 }
480 
481 
482 /***********************************************************************//**
483  * @brief Return number of NULLs encountered
484  *
485  * @return Number of NULLs encountered
486  ***************************************************************************/
487 inline
488 const int& GFitsTableCol::anynul(void) const
489 {
490  // Return number of NULLs encountered
491  return m_anynul;
492 }
493 
494 
495 /***********************************************************************//**
496  * @brief Set TSCALE value
497  *
498  * @param[in] tscale TSCALE value
499  ***************************************************************************/
500 inline
501 void GFitsTableCol::tscale(const double& tscale)
502 {
503  // Set number of NULLs encountered
504  m_tscale = tscale;
505 
506  // Return
507  return;
508 }
509 
510 
511 /***********************************************************************//**
512  * @brief Return TSCALE value
513  *
514  * @return TSCALE value (1 if unscaled).
515  ***************************************************************************/
516 inline
517 const double& GFitsTableCol::tscale(void) const
518 {
519  // Return number of NULLs encountered
520  return m_tscale;
521 }
522 
523 #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
Return 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:1167
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.
int m_number
Number of elements in column.
virtual ~GFitsTableCol(void)
Destructor.
void free_members(void)
Delete class members.
double m_tscale
Optional scaling factor (1 = no scaling)
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
const double & tscale(void) const
Return TSCALE value.
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.