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