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