GammaLib 2.0.0
Loading...
Searching...
No Matches
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 _______________________________________________ */
39class GFilename;
40class GEbounds;
41
42/* __ Constants __________________________________________________________ */
43namespace 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 ***************************************************************************/
60class GEnergies : public GContainer {
61
62public:
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
107protected:
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 ***************************************************************************/
127inline
128std::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 ***************************************************************************/
141inline
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 ***************************************************************************/
155inline
156const 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 ***************************************************************************/
169inline
170int 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 ***************************************************************************/
183inline
184bool 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 ***************************************************************************/
197inline
198void GEnergies::reserve(const int& num)
199{
200 m_energies.reserve(num);
201 return;
202}
203
204#endif /* GENERGIES_HPP */
Definition of interface for container classes.
Energy value class definition.
FITS table abstract base class interface definition.
FITS file class interface definition.
GChatter
Definition GTypemaps.hpp:33
@ NORMAL
Definition GTypemaps.hpp:36
Interface class for container classes.
Energy boundaries container class.
Definition GEbounds.hpp:60
Energy container class.
Definition GEnergies.hpp:60
std::string print(const GChatter &chatter=NORMAL) const
Print energy container information.
void init_members(void)
Initialise class members.
void read(const GFitsTable &table)
Read energies from FITS table.
void load(const GFilename &filename)
Load energies from FITS file.
GEnergies & operator=(const GEnergies &energies)
Assignment operator.
GEnergies(void)
Void constructor.
Definition GEnergies.cpp:70
void clear(void)
Clear energy container.
int size(void) const
Return number of energies in container.
void set_pow(const int &num, const GEnergy &emin, const GEnergy &emax, const double &gamma)
Set power-law spaced energy intervals.
void copy_members(const GEnergies &energies)
Copy class members.
GEnergy & at(const int &index)
Return reference to energy.
void set(const GEbounds &ebounds)
Set energies from energy boundaries.
void reserve(const int &num)
Reserves space for energies in container.
void extend(const GEnergies &energies)
Append energy container.
GEnergies * clone(void) const
Clone energy container.
GEnergy & append(const GEnergy &energy)
Append energy to container.
std::string classname(void) const
Return class name.
void save(const GFilename &filename, const bool &clobber=false) const
Save energies into FITS file.
GEnergy & operator[](const int &index)
Return reference to energy.
virtual ~GEnergies(void)
Destructor.
void write(GFits &file, const std::string &extname=gammalib::extname_energies) const
Write energies into FITS object.
void set_lin(const int &num, const GEnergy &emin, const GEnergy &emax)
Set linearly spaced energies.
void remove(const int &index)
Remove energy from container.
bool is_empty(void) const
Signals if there are no energies in container.
void set_log(const int &num, const GEnergy &emin, const GEnergy &emax)
Set logarithmically spaced energies.
GEnergy & insert(const int &index, const GEnergy &energy)
Insert energy into container.
void free_members(void)
Delete class members.
std::vector< GEnergy > m_energies
List of energies.
Class that handles energies in a unit independent way.
Definition GEnergy.hpp:48
Filename class.
Definition GFilename.hpp:62
Abstract interface for FITS table.
FITS file class.
Definition GFits.hpp:63
const std::string extname_energies
Definition GEnergies.hpp:44