GammaLib  2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GSource.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GSource.cpp - Source class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2012-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 GSource.cpp
23  * @brief Source class implementation
24  * @author Juergen Knodlseder
25  */
26 
27 /* __ Includes ___________________________________________________________ */
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31 #include "GSource.hpp"
32 #include "GTools.hpp"
33 
34 /* __ Constants __________________________________________________________ */
35 
36 /* __ Method name definitions ____________________________________________ */
37 
38 /* __ Macros _____________________________________________________________ */
39 
40 /* __ Coding definitions _________________________________________________ */
41 
42 /* __ Debug definitions __________________________________________________ */
43 
44 
45 /*==========================================================================
46  = =
47  = Constructors/destructors =
48  = =
49  ==========================================================================*/
50 
51 /***********************************************************************//**
52  * @brief Void constructor
53  ***************************************************************************/
55 {
56  // Initialise private members
57  init_members();
58 
59  // Return
60  return;
61 }
62 
63 
64 /***********************************************************************//**
65  * @brief Source constructor
66  *
67  * @param[in] name Source name.
68  * @param[in] model Spatial model pointer.
69  * @param[in] energy Energy.
70  * @param[in] time Time.
71  ***************************************************************************/
72 GSource::GSource(const std::string& name,
73  GModelSpatial* model,
74  const GEnergy& energy,
75  const GTime& time)
76 {
77  // Initialise private members
78  init_members();
79 
80  // Set members
81  m_name = name;
82  m_model = model;
83  m_energy = energy;
84  m_time = time;
85 
86  // Return
87  return;
88 }
89 
90 
91 /***********************************************************************//**
92  * @brief Copy constructor
93  *
94  * @param[in] src Source.
95  ***************************************************************************/
97 {
98  // Initialise private members
99  init_members();
100 
101  // Copy members
102  copy_members(src);
103 
104  // Return
105  return;
106 }
107 
108 
109 /***********************************************************************//**
110  * @brief Destructor
111  ***************************************************************************/
113 {
114  // Free members
115  free_members();
116 
117  // Return
118  return;
119 }
120 
121 
122 /*==========================================================================
123  = =
124  = Operators =
125  = =
126  ==========================================================================*/
127 
128 /***********************************************************************//**
129  * @brief Assignment operator
130  *
131  * @param[in] src Source.
132  * @return Source.
133  ***************************************************************************/
135 {
136  // Execute only if object is not identical
137  if (this != &src) {
138 
139  // Free members
140  free_members();
141 
142  // Initialise private members for clean destruction
143  init_members();
144 
145  // Copy members
146  copy_members(src);
147 
148  } // endif: object was not identical
149 
150  // Return
151  return *this;
152 }
153 
154 
155 /*==========================================================================
156  = =
157  = Public methods =
158  = =
159  ==========================================================================*/
160 
161 /***********************************************************************//**
162  * @brief Clear instance
163  ***************************************************************************/
164 void GSource::clear(void)
165 {
166  // Free members
167  free_members();
168 
169  // Initialise private members
170  init_members();
171 
172  // Return
173  return;
174 }
175 
176 
177 /***********************************************************************//**
178  * @brief Clone object
179  *
180  * @return Pointer to deep copy of source.
181  ***************************************************************************/
183 {
184  // Clone this image
185  return new GSource(*this);
186 }
187 
188 
189 /***********************************************************************//**
190  * @brief Print source
191  *
192  * @param[in] chatter Chattiness.
193  * @return String containing source information
194  ***************************************************************************/
195 std::string GSource::print(const GChatter& chatter) const
196 {
197  // Initialise result string
198  std::string result;
199 
200  // Continue only if chatter is not silent
201  if (chatter != SILENT) {
202 
203  // Build photon string
204  result.append("GSource(");
205  result.append(m_name);
206  if (m_model != NULL) {
207  result.append(", "+m_model->type());
208  }
209  else {
210  result.append(", None");
211  }
212  result.append(", E="+m_energy.print(chatter));
213  result.append(", MET="+m_time.print(chatter));
214  result.append(")");
215 
216  } // endif: chatter was not silent
217 
218  // Return
219  return result;
220 }
221 
222 
223 /*==========================================================================
224  = =
225  = Private methods =
226  = =
227  ==========================================================================*/
228 
229 /***********************************************************************//**
230  * @brief Initialise class members
231  ***************************************************************************/
233 {
234  // Initialise members
235  m_name.clear();
236  m_model = NULL;
237  m_energy.clear();
238  m_time.clear();
239 
240  // Return
241  return;
242 }
243 
244 
245 /***********************************************************************//**
246  * @brief Copy class members
247  *
248  * @param[in] src Source.
249  ***************************************************************************/
251 {
252  // Copy members
253  m_model = src.m_model;
254  m_name = src.m_name;
255  m_energy = src.m_energy;
256  m_time = src.m_time;
257 
258  // Return
259  return;
260 }
261 
262 
263 /***********************************************************************//**
264  * @brief Delete class members
265  ***************************************************************************/
267 {
268  // Return
269  return;
270 }
GSource * clone(void) const
Clone object.
Definition: GSource.cpp:182
std::string m_name
Source name.
Definition: GSource.hpp:87
void clear(void)
Clear time.
Definition: GTime.cpp:252
Time class.
Definition: GTime.hpp:55
Gammalib tools definition.
void free_members(void)
Delete class members.
Definition: GSource.cpp:266
const std::string & name(void) const
Return model name.
Definition: GSource.hpp:114
Source class definition.
virtual ~GSource(void)
Destructor.
Definition: GSource.cpp:112
std::string print(const GChatter &chatter=NORMAL) const
Print energy.
Definition: GEnergy.cpp:748
const GTime & time(void) const
Return photon arrival time.
Definition: GSource.hpp:156
GChatter
Definition: GTypemaps.hpp:33
std::string print(const GChatter &chatter=NORMAL) const
Print time.
Definition: GTime.cpp:1188
GSource & operator=(const GSource &src)
Assignment operator.
Definition: GSource.cpp:134
const GModelSpatial * model(void) const
Return spatial model component.
Definition: GSource.hpp:128
const GEnergy & energy(void) const
Return photon energy.
Definition: GSource.hpp:142
std::string type(void) const
Return model type.
GSource(void)
Void constructor.
Definition: GSource.cpp:54
GTime m_time
Photon arrival time.
Definition: GSource.hpp:90
void copy_members(const GSource &src)
Copy class members.
Definition: GSource.cpp:250
void init_members(void)
Initialise class members.
Definition: GSource.cpp:232
void clear(void)
Clear instance.
Definition: GSource.cpp:164
Abstract spatial model base class.
GModelSpatial * m_model
Spatial model.
Definition: GSource.hpp:88
Class that handles gamma-ray sources.
Definition: GSource.hpp:53
std::string print(const GChatter &chatter=NORMAL) const
Print source.
Definition: GSource.cpp:195
void clear(void)
Clear instance.
Definition: GEnergy.cpp:261
GEnergy m_energy
Photon energy.
Definition: GSource.hpp:89
Class that handles energies in a unit independent way.
Definition: GEnergy.hpp:48