GammaLib  1.7.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GMWLSpectrum.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GMWLSpectrum.hpp - Multi-wavelength spectrum class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2010-2016 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 GMWLSpectrum.hpp
23  * @brief Multi-wavelength spectrum class interface definition
24  * @author Juergen Knoedlseder
25  */
26 
27 #ifndef GMWLSPECTRUM_HPP
28 #define GMWLSPECTRUM_HPP
29 
30 /* __ Includes ___________________________________________________________ */
31 #include <string>
32 #include "GEventCube.hpp"
33 #include "GMWLDatum.hpp"
34 #include "GFitsTable.hpp"
35 #include "GEnergy.hpp"
36 
37 /* __ Forward declarations _______________________________________________ */
38 class GFilename;
39 
40 
41 /***********************************************************************//**
42  * @class GMWLSpectrum
43  *
44  * @brief Multi-wavelength spectrum class interface
45  *
46  * This class defines a multi-wavelength spectrum and is a container for
47  * spectral points of type GMWLDatum. It derives from the abstract
48  * GEventCube base class.
49  ***************************************************************************/
50 class GMWLSpectrum : public GEventCube {
51 
52 public:
53  // Constructors and destructors
54  GMWLSpectrum(void);
55  explicit GMWLSpectrum(const GFilename& filename);
56  GMWLSpectrum(const GMWLSpectrum& spec);
57  virtual ~GMWLSpectrum(void);
58 
59  // Operators
60  virtual GMWLSpectrum& operator=(const GMWLSpectrum& spec);
61  virtual GMWLDatum* operator[](const int& index);
62  virtual const GMWLDatum* operator[](const int& index) const;
63 
64  // Implemented pure virtual methods
65  virtual void clear(void);
66  virtual GMWLSpectrum* clone(void) const;
67  virtual std::string classname(void) const;
68  virtual int size(void) const;
69  virtual int dim(void) const;
70  virtual int naxis(const int& axis) const;
71  virtual void load(const GFilename& filename);
72  virtual void save(const GFilename& filename,
73  const bool& clobber = false) const;
74  virtual void read(const GFits& file);
75  virtual void write(GFits& file) const;
76  virtual int number(void) const;
77  virtual std::string print(const GChatter& chatter = NORMAL) const;
78 
79  // Other methods
80  void read(const GFits& file, const std::string& extname);
81  void read(const GFits& file, const int& extno);
82  const std::string& telescope(void) const;
83  const std::string& instrument(void) const;
84 
85 protected:
86  // Protected methods
87  void init_members(void);
88  void copy_members(const GMWLSpectrum& spec);
89  void free_members(void);
90  void set_ebounds(void);
91  void read_fits(const GFitsTable& table);
92  GEnergy conv_energy(const double& energy, const std::string& unit);
93  double conv_flux(const GEnergy& energy, const double& flux,
94  const std::string& unit);
95 
96  // Protected members
97  std::string m_telescope; //!< Telescope name
98  std::string m_instrument; //!< Instrument name
99  std::vector<GMWLDatum> m_data; //!< Spectral data
100 };
101 
102 
103 /***********************************************************************//**
104  * @brief Return class name
105  *
106  * @return String containing the class name ("GMWLSpectrum").
107  ***************************************************************************/
108 inline
109 std::string GMWLSpectrum::classname(void) const
110 {
111  return ("GMWLSpectrum");
112 }
113 
114 
115 /***********************************************************************//**
116  * @brief Return number of spectral bins
117  *
118  * @return Number of bins in spectrum.
119  ***************************************************************************/
120 inline
121 int GMWLSpectrum::size(void) const
122 {
123  return (int)m_data.size();
124 }
125 
126 
127 /***********************************************************************//**
128  * @brief Return dimension of spectrum
129  *
130  * @return Dimension of spectrum (always 1).
131  ***************************************************************************/
132 inline
133 int GMWLSpectrum::dim(void) const
134 {
135  return 1;
136 }
137 
138 
139 /***********************************************************************//**
140  * @brief Return number of spectral bins per dimension
141  *
142  * @param[in] axis Axis (ignored).
143  * @return Number of bins in spectrum.
144  ***************************************************************************/
145 inline
146 int GMWLSpectrum::naxis(const int& axis) const
147 {
148  return (int)m_data.size();
149 }
150 
151 
152 /***********************************************************************//**
153  * @brief Return telescope name
154  *
155  * @return Telescope name.
156  ***************************************************************************/
157 inline
158 const std::string& GMWLSpectrum::telescope(void) const
159 {
160  return m_telescope;
161 }
162 
163 
164 /***********************************************************************//**
165  * @brief Return instrument name
166  *
167  * @return Instrument name.
168  ***************************************************************************/
169 inline
170 const std::string& GMWLSpectrum::instrument(void) const
171 {
172  return m_instrument;
173 }
174 
175 #endif /* GMWLSPECTRUM_HPP */
virtual int dim(void) const
Return dimension of spectrum.
virtual void write(GFits &file) const
Write spectrum into FITS file.
Energy value class definition.
virtual GMWLSpectrum & operator=(const GMWLSpectrum &spec)
Assignment operator.
virtual std::string classname(void) const
Return class name.
Abstract event bin container class interface definition.
virtual GMWLDatum * operator[](const int &index)
Spectral point access operator.
const std::string & instrument(void) const
Return instrument name.
FITS file class.
Definition: GFits.hpp:63
Multi-wavelength spectrum class interface.
void read_fits(const GFitsTable &table)
Read spectrum from FITS file.
const std::string & telescope(void) const
Return telescope name.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print spectrum.
void free_members(void)
Delete class members.
Filename class.
Definition: GFilename.hpp:62
virtual int size(void) const
Return number of spectral bins.
virtual int number(void) const
Return number of points in spectrum.
Abstract interface for FITS table.
Definition: GFitsTable.hpp:44
virtual void clear(void)
Clear spectrum.
GChatter
Definition: GTypemaps.hpp:33
GEnergy conv_energy(const double &energy, const std::string &unit)
Convert value into energy.
std::string m_telescope
Telescope name.
virtual GMWLSpectrum * clone(void) const
Clone spectrum.
void set_ebounds(void)
Set energy boundaries.
std::vector< GMWLDatum > m_data
Spectral data.
Multi-wavelength spectral point class.
Definition: GMWLDatum.hpp:45
void copy_members(const GMWLSpectrum &spec)
Copy class members.
virtual void save(const GFilename &filename, const bool &clobber=false) const
Save spectrum.
Multi-wavelength spectral point class interface definition.
GMWLSpectrum(void)
Void constructor.
virtual ~GMWLSpectrum(void)
Destructor.
void init_members(void)
Initialise class members.
double conv_flux(const GEnergy &energy, const double &flux, const std::string &unit)
Convert value into flux.
virtual int naxis(const int &axis) const
Return number of spectral bins per dimension.
Abstract event bin container class.
Definition: GEventCube.hpp:46
std::string m_instrument
Instrument name.
virtual void load(const GFilename &filename)
Load spectrum.
virtual void read(const GFits &file)
Read spectrum from FITS file.
Class that handles energies in a unit independent way.
Definition: GEnergy.hpp:48
FITS table abstract base class interface definition.