GammaLib  2.1.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GCTAInstDir.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GCTAInstDir.cpp - CTA instrument direction class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2010-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 GCTAInstDir.cpp
23  * @brief CTA instrument direction class implementation
24  * @author Juergen Knoedlseder
25  */
26 
27 /* __ Includes ___________________________________________________________ */
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31 #include <cstring> // memcpy
32 #include "GTools.hpp"
33 #include "GMath.hpp"
34 #include "GCTAInstDir.hpp"
35 
36 /* __ Method name definitions ____________________________________________ */
37 
38 /* __ Macros _____________________________________________________________ */
39 
40 /* __ Coding definitions _________________________________________________ */
41 
42 /* __ Debug definitions __________________________________________________ */
43 
44 /* __ Prototypes _________________________________________________________ */
45 
46 
47 /*==========================================================================
48  = =
49  = Constructors/destructors =
50  = =
51  ==========================================================================*/
52 
53 /***********************************************************************//**
54  * @brief Void constructor
55  ***************************************************************************/
57 {
58  // Initialise class members
59  init_members();
60 
61  // Return
62  return;
63 }
64 
65 
66 /***********************************************************************//**
67  * @brief Sky direction constructor
68  *
69  * @param[in] dir Sky direction.
70  *
71  * Construct CTA instrument direction from sky direction.
72  ***************************************************************************/
74 {
75  // Initialise class members
76  init_members();
77 
78  // Assign sky direction
79  this->dir(dir);
80 
81  // Return
82  return;
83 }
84 
85 
86 /***********************************************************************//**
87  * @brief Instrument coordinates constructor
88  *
89  * @param[in] detx Instrument coordinate X (radians).
90  * @param[in] dety Instrument coordinate Y (radians).
91  *
92  * Construct CTA instrument direction from instrument coordinates.
93  ***************************************************************************/
94 GCTAInstDir::GCTAInstDir(const double& detx, const double& dety) : GInstDir()
95 {
96  // Initialise class members
97  init_members();
98 
99  // Assign instrument coordinates
100  this->detx(detx);
101  this->dety(dety);
102 
103  // Return
104  return;
105 }
106 
107 
108 /***********************************************************************//**
109  * @brief Instrument direction constructor
110  *
111  * @param[in] dir Sky direction.
112  * @param[in] detx Instrument coordinate X (radians).
113  * @param[in] dety Instrument coordinate Y (radians).
114  *
115  * Construct CTA instrument direction from sky direction and instrument
116  * coordinates.
117  ***************************************************************************/
119  const double& detx,
120  const double& dety) : GInstDir()
121 {
122  // Initialise class members
123  init_members();
124 
125  // Assign instrument coordinates
126  this->dir(dir);
127  this->detx(detx);
128  this->dety(dety);
129 
130  // Return
131  return;
132 }
133 
134 
135 /***********************************************************************//**
136  * @brief Copy constructor
137  *
138  * @param[in] dir CTA instrument direction.
139  ***************************************************************************/
141 {
142  // Initialise class members
143  init_members();
144 
145  // Copy members
146  copy_members(dir);
147 
148  // Return
149  return;
150 }
151 
152 
153 /***********************************************************************//**
154  * @brief Destructor
155  ***************************************************************************/
157 {
158  // Free members
159  free_members();
160 
161  // Return
162  return;
163 }
164 
165 
166 /*==========================================================================
167  = =
168  = Operators =
169  = =
170  ==========================================================================*/
171 
172 /***********************************************************************//**
173  * @brief Assignment operator
174  *
175  * @param[in] dir CTA instrument direction.
176  * @return CTA instrument direction.
177  ***************************************************************************/
179 {
180  // Execute only if object is not identical
181  if (this != &dir) {
182 
183  // Copy base class members
184  this->GInstDir::operator=(dir);
185 
186  // Free members
187  free_members();
188 
189  // Initialise private members
190  init_members();
191 
192  // Copy members
193  copy_members(dir);
194 
195  } // endif: object was not identical
196 
197  // Return this object
198  return *this;
199 }
200 
201 
202 /*==========================================================================
203  = =
204  = Public methods =
205  = =
206  ==========================================================================*/
207 
208 /***********************************************************************//**
209  * @brief Clear CTA instrument direction
210  ***************************************************************************/
212 {
213  // Free members
214  free_members();
215  this->GInstDir::free_members();
216 
217  // Initialise private members
218  this->GInstDir::init_members();
219  init_members();
220 
221  // Return
222  return;
223 }
224 
225 
226 /***********************************************************************//**
227  * @brief CTA instrument direction
228  *
229  * @return Pointer to deep copy of CTA instrument direction.
230  ***************************************************************************/
232 {
233  return new GCTAInstDir(*this);
234 }
235 
236 
237 /***********************************************************************//**
238  * @brief Return instrument direction hash value
239  *
240  * @return Hash value.
241  *
242  * Returns a hash value that can be used in the response cache.
243  ***************************************************************************/
244 u_int64_t GCTAInstDir::hash(void) const
245 {
246  // Allocate static array to store the information as floats
247  static float buffer[2];
248 
249  // Store the two sky coordinates as floats
250  buffer[0] = float(m_dir.ra());
251  buffer[1] = float(m_dir.dec());
252 
253  // Map the floats to an unsigned 64 Bit integer
254  u_int64_t hash; std::memcpy(&hash, &buffer, sizeof hash);
255 
256  // Return hash value
257  return hash;
258 }
259 
260 
261 /***********************************************************************//**
262  * @brief Print instrument direction information
263  *
264  * @param[in] chatter Chattiness.
265  * @return String containing instrument direction information.
266  ***************************************************************************/
267 std::string GCTAInstDir::print(const GChatter& chatter) const
268 {
269  // Initialise result string
270  std::string result;
271 
272  // Continue only if chatter is not silent
273  if (chatter != SILENT) {
274 
275  // Append instrument direction
276  std::string msg = "RA=" + gammalib::str(m_dir.ra_deg()) +
277  ", DEC=" + gammalib::str(m_dir.dec_deg()) +
278  " [" + gammalib::str(m_detx) +
279  "," + gammalib::str(m_dety) + "]";
280  result.append(msg);
281 
282  } // endif: chatter was not silent
283 
284  // Return result
285  return result;
286 }
287 
288 
289 /*==========================================================================
290  = =
291  = Private methods =
292  = =
293  ==========================================================================*/
294 
295 /***********************************************************************//**
296  * @brief Initialise class members
297  ***************************************************************************/
299 {
300  // Initialise members
301  m_dir.clear();
302  m_detx = 0.0;
303  m_dety = 0.0;
304  m_has_dir = false;
305  m_has_detx = false;
306  m_has_dety = false;
307 
308  // Return
309  return;
310 }
311 
312 
313 /***********************************************************************//**
314  * @brief Copy class members
315  *
316  * @param[in] dir CTA instrument direction.
317  ***************************************************************************/
319 {
320  // Copy attributes
321  m_dir = dir.m_dir;
322  m_detx = dir.m_detx;
323  m_dety = dir.m_dety;
324  m_has_dir = dir.m_has_dir;
325  m_has_detx = dir.m_has_detx;
326  m_has_dety = dir.m_has_dety;
327 
328  // Return
329  return;
330 }
331 
332 
333 /***********************************************************************//**
334  * @brief Delete class members
335  ***************************************************************************/
337 {
338  // Return
339  return;
340 }
bool m_has_detx
Has valid instrument coordinate X.
virtual ~GCTAInstDir(void)
Destructor.
const double & dety(void) const
Return reference to DETY coordinate (in radians)
double dec_deg(void) const
Returns Declination in degrees.
Definition: GSkyDir.hpp:256
bool m_has_dir
Has valid incident direction.
const double & detx(void) const
Return reference to DETX coordinate (in radians)
Gammalib tools definition.
virtual GInstDir & operator=(const GInstDir &dir)
Assignment operator.
Definition: GInstDir.cpp:105
void free_members(void)
Delete class members.
Definition: GInstDir.cpp:163
GCTAInstDir & operator=(const GCTAInstDir &dir)
Assignment operator.
const double & ra(void) const
Return Right Ascension in radians.
Definition: GSkyDir.hpp:214
const GSkyDir & dir(void) const
Return reference to sky direction (const version)
Abstract instrument direction base class.
Definition: GInstDir.hpp:51
double m_dety
Instrument coordinate Y (radians)
void init_members(void)
Initialise class members.
double m_detx
Instrument coordinate X (radians)
bool m_has_dety
Has valid instrument coordinate Y.
CTA instrument direction class interface definition.
double ra_deg(void) const
Returns Right Ascension in degrees.
Definition: GSkyDir.hpp:229
GChatter
Definition: GTypemaps.hpp:33
const double & dec(void) const
Return Declination in radians.
Definition: GSkyDir.hpp:241
GCTAInstDir(void)
Void constructor.
Definition: GCTAInstDir.cpp:56
virtual std::string print(const GChatter &chatter=NORMAL) const
Print instrument direction information.
virtual GCTAInstDir * clone(void) const
CTA instrument direction.
virtual void clear(void)
Clear CTA instrument direction.
void clear(void)
Clear sky direction.
Definition: GSkyDir.cpp:164
GSkyDir m_dir
Observed incident direction of event.
void init_members(void)
Initialise class members.
Definition: GInstDir.cpp:141
void copy_members(const GCTAInstDir &dir)
Copy class members.
CTA instrument direction class.
Definition: GCTAInstDir.hpp:63
Sky direction class.
Definition: GSkyDir.hpp:62
void free_members(void)
Delete class members.
virtual u_int64_t hash(void) const
Return instrument direction hash value.
Mathematical function definitions.
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
Definition: GTools.cpp:489