GammaLib  2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GModelSpectralTablePar.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GModelSpectralTablePar.cpp - Spectral table model parameter class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2019-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 GModelSpectralTablePar.cpp
23  * @brief Spectral table model parameter class implementation
24  * @author Juergen Knoedlseder
25  */
26 
27 /* __ Includes ___________________________________________________________ */
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31 #include <algorithm>
32 #include "GException.hpp"
33 #include "GTools.hpp"
34 #include "GModelPar.hpp"
36 
37 /* __ Constants __________________________________________________________ */
38 
39 /* __ Globals ____________________________________________________________ */
40 
41 /* __ Method name definitions ____________________________________________ */
42 
43 /* __ Macros _____________________________________________________________ */
44 
45 /* __ Coding definitions _________________________________________________ */
46 
47 /* __ Debug definitions __________________________________________________ */
48 
49 
50 /*==========================================================================
51  = =
52  = Constructors/destructors =
53  = =
54  ==========================================================================*/
55 
56 /***********************************************************************//**
57  * @brief Void constructor
58  ***************************************************************************/
60 {
61  // Initialise members
62  init_members();
63 
64  // Return
65  return;
66 }
67 
68 
69 /***********************************************************************//**
70  * @brief Model parameter constructor
71  *
72  * @param[in] par Model parameter.
73  * @param[in] values Parameter values.
74  *
75  * Constructs a model table parameter combining a model parameter with a
76  * vector of parameter values. The values in the @p values vector may be
77  * unsorted, the constructor will put the values into an acsending order.
78  ***************************************************************************/
80  const std::vector<double>& values)
81 {
82  // Initialise members
83  init_members();
84 
85  // Sort parameter values
86  std::vector<double> sorted_values = values;
87  std::sort(sorted_values.begin(), sorted_values.end());
88 
89  // Set members
90  m_par = par;
91  m_values = GNodeArray(sorted_values);
92 
93  // Return
94  return;
95 }
96 
97 
98 /***********************************************************************//**
99  * @brief Copy constructor
100  *
101  * @param[in] par Table model parameter.
102  ***************************************************************************/
104 {
105  // Initialise members
106  init_members();
107 
108  // Copy members
109  copy_members(par);
110 
111  // Return
112  return;
113 }
114 
115 
116 /***********************************************************************//**
117  * @brief Destructor
118  ***************************************************************************/
120 {
121  // Free members
122  free_members();
123 
124  // Return
125  return;
126 }
127 
128 
129 /*==========================================================================
130  = =
131  = Operators =
132  = =
133  ==========================================================================*/
134 
135 /***********************************************************************//**
136  * @brief Assignment operator
137  *
138  * @param[in] par Table model parameter.
139  * @return Table model parameter.
140  ***************************************************************************/
142 {
143  // Execute only if object is not identical
144  if (this != &par) {
145 
146  // Free members
147  free_members();
148 
149  // Initialise members
150  init_members();
151 
152  // Copy members
153  copy_members(par);
154 
155  } // endif: object was not identical
156 
157  // Return
158  return *this;
159 }
160 
161 
162 /*==========================================================================
163  = =
164  = Public methods =
165  = =
166  ==========================================================================*/
167 
168 /***********************************************************************//**
169  * @brief Clear table model parameter
170 ***************************************************************************/
172 {
173  // Free class members (base and derived classes, derived class first)
174  free_members();
175 
176  // Initialise members
177  init_members();
178 
179  // Return
180  return;
181 }
182 
183 
184 /***********************************************************************//**
185  * @brief Clone table model parameter
186 ***************************************************************************/
188 {
189  // Clone table model parameter
190  return new GModelSpectralTablePar(*this);
191 }
192 
193 
194 /***********************************************************************//**
195  * @brief Print table model parameter
196  *
197  * @param[in] chatter Chattiness.
198  * @return String containing table model parameter information.
199  ***************************************************************************/
200 std::string GModelSpectralTablePar::print(const GChatter& chatter) const
201 {
202  // Initialise result string
203  std::string result;
204 
205  // Continue only if chatter is not silent
206  if (chatter != SILENT) {
207 
208  // Append header
209  result.append("=== GModelSpectralTablePar ===");
210 
211  // Append information
212  result.append("\n"+gammalib::parformat("Name"));
213  result.append(m_par.name());
214  result.append("\n"+gammalib::parformat("Number of values"));
215  result.append(gammalib::str(m_values.size()));
216  result.append("\n"+gammalib::parformat("Interpolation method"));
217  if (m_method == 0) {
218  result.append("linear");
219  }
220  else if (m_method == 1) {
221  result.append("logarithmic");
222  }
223  else {
224  result.append("invalid");
225  }
226 
227  } // endif: chatter was not silent
228 
229  // Return result
230  return result;
231 }
232 
233 
234 /*==========================================================================
235  = =
236  = Private methods =
237  = =
238  ==========================================================================*/
239 
240 /***********************************************************************//**
241  * @brief Initialise class members
242  ***************************************************************************/
244 {
245  // Initialize members
246  m_par.clear();
247  m_values.clear();
248  m_method = 0;
249 
250  // Return
251  return;
252 }
253 
254 
255 /***********************************************************************//**
256  * @brief Copy class members
257  *
258  * @param[in] par Table model parameter.
259  ***************************************************************************/
261 {
262  // Copy members
263  m_par = par.m_par;
264  m_values = par.m_values;
265  m_method = par.m_method;
266 
267  // Return
268  return;
269 }
270 
271 
272 /***********************************************************************//**
273  * @brief Delete class members
274  ***************************************************************************/
276 {
277  // Return
278  return;
279 }
int size(void) const
Return number of nodes in node array.
Definition: GNodeArray.hpp:192
Node array class.
Definition: GNodeArray.hpp:60
int m_method
Interpolation method (0: linear, 1: logarithmic)
const std::string & name(void) const
Return parameter name.
GModelPar m_par
Model parameter.
std::string print(const GChatter &chatter=NORMAL) const
Print table model parameter.
GNodeArray m_values
Parameter values.
void clear(void)
Clear node array.
Definition: GNodeArray.cpp:235
Gammalib tools definition.
GModelSpectralTablePar(void)
Void constructor.
Model parameter class interface definition.
Model parameter class.
Definition: GModelPar.hpp:87
virtual ~GModelSpectralTablePar(void)
Destructor.
Spectral table model parameter class definition.
void clear(void)
Clear parameter.
GChatter
Definition: GTypemaps.hpp:33
void free_members(void)
Delete class members.
void init_members(void)
Initialise class members.
void copy_members(const GModelSpectralTablePar &par)
Copy class members.
void clear(void)
Clear table model parameter.
GModelSpectralTablePar * clone(void) const
Clone table model parameter.
Exception handler interface definition.
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
Definition: GTools.cpp:1143
const GNodeArray & values(void) const
Return reference to table model parameter values as node array.
GModelPar & par(void)
Return reference to table model parameter.
Spectral table model parameter class.
GModelSpectralTablePar & operator=(const GModelSpectralTablePar &par)
Assignment operator.
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
Definition: GTools.cpp:489