GammaLib  2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GEnergies.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GEnergies.hpp - Energy container class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2013-2020 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 GEnergies.hpp
23  * @brief Energy container class definition
24  * @author Juergen Knoedlseder
25  */
26 
27 #ifndef GENERGIES_HPP
28 #define GENERGIES_HPP
29 
30 /* __ Includes ___________________________________________________________ */
31 #include <string>
32 #include <vector>
33 #include "GContainer.hpp"
34 #include "GEnergy.hpp"
35 #include "GFits.hpp"
36 #include "GFitsTable.hpp"
37 
38 /* __ Forward declarations _______________________________________________ */
39 class GFilename;
40 class GEbounds;
41 
42 /* __ Constants __________________________________________________________ */
43 namespace gammalib {
44  const std::string extname_energies = "ENERGIES";
45 }
46 
47 
48 /***********************************************************************//**
49  * @class GEnergies
50  *
51  * @brief Energy container class.
52  *
53  * This class is a container for energies. Energies are implemented by the
54  * GEnergy class which stores energies in a unit independent way.
55  *
56  * An energy container can be constructed from a FITS file or by defining
57  * a number of energies within a given interval, spaced either linearly or
58  * logarithmically.
59  ***************************************************************************/
60 class GEnergies : public GContainer {
61 
62 public:
63  // Constructors and destructors
64  GEnergies(void);
65  explicit GEnergies(const GFilename& filename);
66  explicit GEnergies(const GEbounds& ebounds);
67  GEnergies(const GEnergies& energies);
68  GEnergies(const int& num,
69  const GEnergy& emin,
70  const GEnergy& emax,
71  const std::string& method = "LOG",
72  const double& gamma = 1.0);
73  virtual ~GEnergies(void);
74 
75  // Operators
76  GEnergies& operator=(const GEnergies& energies);
77  GEnergy& operator[](const int& index);
78  const GEnergy& operator[](const int& index) const;
79 
80  // Methods
81  void clear(void);
82  GEnergies* clone(void) const;
83  std::string classname(void) const;
84  GEnergy& at(const int& index);
85  const GEnergy& at(const int& index) const;
86  int size(void) const;
87  bool is_empty(void) const;
88  GEnergy& append(const GEnergy& energy);
89  GEnergy& insert(const int& index, const GEnergy& energy);
90  void remove(const int& index);
91  void reserve(const int& num);
92  void extend(const GEnergies& energies);
93  void set(const GEbounds& ebounds);
94  void set(const int& num,
95  const GEnergy& emin,
96  const GEnergy& emax,
97  const std::string& method = "LOG",
98  const double& gamma = 1.0);
99  void load(const GFilename& filename);
100  void save(const GFilename& filename,
101  const bool& clobber = false) const;
102  void read(const GFitsTable& table);
103  void write(GFits& file,
104  const std::string& extname = gammalib::extname_energies) const;
105  std::string print(const GChatter& chatter = NORMAL) const;
106 
107 protected:
108  // Protected methods
109  void init_members(void);
110  void copy_members(const GEnergies& energies);
111  void free_members(void);
112  void set_lin(const int& num, const GEnergy& emin, const GEnergy& emax);
113  void set_log(const int& num, const GEnergy& emin, const GEnergy& emax);
114  void set_pow(const int& num, const GEnergy& emin, const GEnergy& emax,
115  const double& gamma);
116 
117  // Protected data members
118  std::vector<GEnergy> m_energies; //!< List of energies
119 };
120 
121 
122 /***********************************************************************//**
123  * @brief Return class name
124  *
125  * @return String containing the class name ("GEnergies").
126  ***************************************************************************/
127 inline
128 std::string GEnergies::classname(void) const
129 {
130  return ("GEnergies");
131 }
132 
133 
134 /***********************************************************************//**
135  * @brief Return reference to energy
136  *
137  * @param[in] index Energy index [0,...,size()-1].
138  *
139  * Returns a reference to the energy with the specified @p index.
140  ***************************************************************************/
141 inline
142 GEnergy& GEnergies::operator[](const int& index)
143 {
144  return (m_energies[index]);
145 }
146 
147 
148 /***********************************************************************//**
149  * @brief Return reference to energy (const version)
150  *
151  * @param[in] index Energy index [0,...,size()-1].
152  *
153  * Returns a reference to the energy with the specified @p index.
154  ***************************************************************************/
155 inline
156 const GEnergy& GEnergies::operator[](const int& index) const
157 {
158  return (m_energies[index]);
159 }
160 
161 
162 /***********************************************************************//**
163  * @brief Return number of energies in container
164  *
165  * @return Number of energies in container.
166  *
167  * Returns the number of energies in the energy container.
168  ***************************************************************************/
169 inline
170 int GEnergies::size(void) const
171 {
172  return (int)m_energies.size();
173 }
174 
175 
176 /***********************************************************************//**
177  * @brief Signals if there are no energies in container
178  *
179  * @return True if container is empty, false otherwise.
180  *
181  * Signals if the energy container does not contain any energy.
182  ***************************************************************************/
183 inline
184 bool GEnergies::is_empty(void) const
185 {
186  return (m_energies.empty());
187 }
188 
189 
190 /***********************************************************************//**
191  * @brief Reserves space for energies in container
192  *
193  * @param[in] num Number of energies.
194  *
195  * Reserves space for @p num energies in the container.
196  ***************************************************************************/
197 inline
198 void GEnergies::reserve(const int& num)
199 {
200  m_energies.reserve(num);
201  return;
202 }
203 
204 #endif /* GENERGIES_HPP */
std::string print(const GChatter &chatter=NORMAL) const
Print energy container information.
Definition: GEnergies.cpp:698
void clear(void)
Clear energy container.
Definition: GEnergies.cpp:227
void read(const GFitsTable &table)
Read energies from FITS table.
Definition: GEnergies.cpp:615
Energy value class definition.
void write(GFits &file, const std::string &extname=gammalib::extname_energies) const
Write energies into FITS object.
Definition: GEnergies.cpp:659
void set_pow(const int &num, const GEnergy &emin, const GEnergy &emax, const double &gamma)
Set power-law spaced energy intervals.
Definition: GEnergies.cpp:926
void reserve(const int &num)
Reserves space for energies in container.
Definition: GEnergies.hpp:198
void set_lin(const int &num, const GEnergy &emin, const GEnergy &emax)
Set linearly spaced energies.
Definition: GEnergies.cpp:791
FITS file class.
Definition: GFits.hpp:63
FITS file class interface definition.
virtual ~GEnergies(void)
Destructor.
Definition: GEnergies.cpp:173
Energy container class.
Definition: GEnergies.hpp:60
void free_members(void)
Delete class members.
Definition: GEnergies.cpp:766
GEnergy & insert(const int &index, const GEnergy &energy)
Insert energy into container.
Definition: GEnergies.cpp:327
std::vector< GEnergy > m_energies
List of energies.
Definition: GEnergies.hpp:118
GEnergies(void)
Void constructor.
Definition: GEnergies.cpp:70
Energy boundaries container class.
Definition: GEbounds.hpp:60
Filename class.
Definition: GFilename.hpp:62
GEnergy & at(const int &index)
Return reference to energy.
Definition: GEnergies.cpp:263
int size(void) const
Return number of energies in container.
Definition: GEnergies.hpp:170
Abstract interface for FITS table.
Definition: GFitsTable.hpp:44
GChatter
Definition: GTypemaps.hpp:33
GEnergy & operator[](const int &index)
Return reference to energy.
Definition: GEnergies.hpp:142
void extend(const GEnergies &energies)
Append energy container.
Definition: GEnergies.cpp:388
void save(const GFilename &filename, const bool &clobber=false) const
Save energies into FITS file.
Definition: GEnergies.cpp:591
bool is_empty(void) const
Signals if there are no energies in container.
Definition: GEnergies.hpp:184
const std::string extname_energies
Definition: GEnergies.hpp:44
void set(const GEbounds &ebounds)
Set energies from energy boundaries.
Definition: GEnergies.cpp:421
GEnergies & operator=(const GEnergies &energies)
Assignment operator.
Definition: GEnergies.cpp:195
GEnergy & append(const GEnergy &energy)
Append energy to container.
Definition: GEnergies.cpp:305
void copy_members(const GEnergies &energies)
Copy class members.
Definition: GEnergies.cpp:753
std::string classname(void) const
Return class name.
Definition: GEnergies.hpp:128
Definition of interface for container classes.
GEnergies * clone(void) const
Clone energy container.
Definition: GEnergies.cpp:247
void set_log(const int &num, const GEnergy &emin, const GEnergy &emax)
Set logarithmically spaced energies.
Definition: GEnergies.cpp:845
void load(const GFilename &filename)
Load energies from FITS file.
Definition: GEnergies.cpp:548
void init_members(void)
Initialise class members.
Definition: GEnergies.cpp:738
Interface class for container classes.
Definition: GContainer.hpp:52
Class that handles energies in a unit independent way.
Definition: GEnergy.hpp:48
FITS table abstract base class interface definition.