GammaLib  1.7.0.dev
 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-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 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, const GEnergy& emin, const GEnergy& emax,
69  const bool& log = true);
70  virtual ~GEnergies(void);
71 
72  // Operators
73  GEnergies& operator=(const GEnergies& energies);
74  GEnergy& operator[](const int& index);
75  const GEnergy& operator[](const int& index) const;
76 
77  // Methods
78  void clear(void);
79  GEnergies* clone(void) const;
80  std::string classname(void) const;
81  GEnergy& at(const int& index);
82  const GEnergy& at(const int& index) const;
83  int size(void) const;
84  bool is_empty(void) const;
85  GEnergy& append(const GEnergy& energy);
86  GEnergy& insert(const int& index, const GEnergy& energy);
87  void remove(const int& index);
88  void reserve(const int& num);
89  void extend(const GEnergies& energies);
90  void set(const GEbounds& ebounds);
91  void set_lin(const int& num, const GEnergy& emin,
92  const GEnergy& emax);
93  void set_log(const int& num, const GEnergy& emin,
94  const GEnergy& emax);
95  void load(const GFilename& filename);
96  void save(const GFilename& filename,
97  const bool& clobber = false) const;
98  void read(const GFitsTable& table);
99  void write(GFits& file,
100  const std::string& extname = gammalib::extname_energies) 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 GEnergies& energies);
107  void free_members(void);
108 
109  // Protected data members
110  std::vector<GEnergy> m_energies; //!< List of energies
111 };
112 
113 
114 /***********************************************************************//**
115  * @brief Return class name
116  *
117  * @return String containing the class name ("GEnergies").
118  ***************************************************************************/
119 inline
120 std::string GEnergies::classname(void) const
121 {
122  return ("GEnergies");
123 }
124 
125 
126 /***********************************************************************//**
127  * @brief Return reference to energy
128  *
129  * @param[in] index Energy index [0,...,size()-1].
130  *
131  * Returns a reference to the energy with the specified @p index.
132  ***************************************************************************/
133 inline
134 GEnergy& GEnergies::operator[](const int& index)
135 {
136  return (m_energies[index]);
137 }
138 
139 
140 /***********************************************************************//**
141  * @brief Return reference to energy (const version)
142  *
143  * @param[in] index Energy index [0,...,size()-1].
144  *
145  * Returns a reference to the energy with the specified @p index.
146  ***************************************************************************/
147 inline
148 const GEnergy& GEnergies::operator[](const int& index) const
149 {
150  return (m_energies[index]);
151 }
152 
153 
154 /***********************************************************************//**
155  * @brief Return number of energies in container
156  *
157  * @return Number of energies in container.
158  *
159  * Returns the number of energies in the energy container.
160  ***************************************************************************/
161 inline
162 int GEnergies::size(void) const
163 {
164  return (int)m_energies.size();
165 }
166 
167 
168 /***********************************************************************//**
169  * @brief Signals if there are no energies in container
170  *
171  * @return True if container is empty, false otherwise.
172  *
173  * Signals if the energy container does not contain any energy.
174  ***************************************************************************/
175 inline
176 bool GEnergies::is_empty(void) const
177 {
178  return (m_energies.empty());
179 }
180 
181 
182 /***********************************************************************//**
183  * @brief Reserves space for energies in container
184  *
185  * @param[in] num Number of energies.
186  *
187  * Reserves space for @p num energies in the container.
188  ***************************************************************************/
189 inline
190 void GEnergies::reserve(const int& num)
191 {
192  m_energies.reserve(num);
193  return;
194 }
195 
196 #endif /* GENERGIES_HPP */
std::string print(const GChatter &chatter=NORMAL) const
Print energy container information.
Definition: GEnergies.cpp:764
void clear(void)
Clear energy container.
Definition: GEnergies.cpp:225
void read(const GFitsTable &table)
Read energies from FITS table.
Definition: GEnergies.cpp:681
Energy value class definition.
void write(GFits &file, const std::string &extname=gammalib::extname_energies) const
Write energies into FITS object.
Definition: GEnergies.cpp:725
void reserve(const int &num)
Reserves space for energies in container.
Definition: GEnergies.hpp:190
void set_lin(const int &num, const GEnergy &emin, const GEnergy &emax)
Set linearly spaced energies.
Definition: GEnergies.cpp:467
FITS file class.
Definition: GFits.hpp:63
FITS file class interface definition.
virtual ~GEnergies(void)
Destructor.
Definition: GEnergies.cpp:171
Energy container class.
Definition: GEnergies.hpp:60
void free_members(void)
Delete class members.
Definition: GEnergies.cpp:832
GEnergy & insert(const int &index, const GEnergy &energy)
Insert energy into container.
Definition: GEnergies.cpp:325
std::vector< GEnergy > m_energies
List of energies.
Definition: GEnergies.hpp:110
GEnergies(void)
Void constructor.
Definition: GEnergies.cpp:67
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:261
int size(void) const
Return number of energies in container.
Definition: GEnergies.hpp:162
GVector log(const GVector &vector)
Computes natural logarithm of vector elements.
Definition: GVector.cpp:1184
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:134
void extend(const GEnergies &energies)
Append energy container.
Definition: GEnergies.cpp:383
void save(const GFilename &filename, const bool &clobber=false) const
Save energies into FITS file.
Definition: GEnergies.cpp:657
bool is_empty(void) const
Signals if there are no energies in container.
Definition: GEnergies.hpp:176
const std::string extname_energies
Definition: GEnergies.hpp:44
void set(const GEbounds &ebounds)
Set energies from energy boundaries.
Definition: GEnergies.cpp:416
GEnergies & operator=(const GEnergies &energies)
Assignment operator.
Definition: GEnergies.cpp:193
GEnergy & append(const GEnergy &energy)
Append energy to container.
Definition: GEnergies.cpp:303
void copy_members(const GEnergies &energies)
Copy class members.
Definition: GEnergies.cpp:819
std::string classname(void) const
Return class name.
Definition: GEnergies.hpp:120
Definition of interface for container classes.
GEnergies * clone(void) const
Clone energy container.
Definition: GEnergies.cpp:245
void set_log(const int &num, const GEnergy &emin, const GEnergy &emax)
Set logarithmically spaced energies.
Definition: GEnergies.cpp:542
void load(const GFilename &filename)
Load energies from FITS file.
Definition: GEnergies.cpp:615
void init_members(void)
Initialise class members.
Definition: GEnergies.cpp:804
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.