GammaLib  2.1.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GCTAEventAtom.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GCTAEventAtom.cpp - CTA event atom class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2010-2021 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 GCTAEventAtom.cpp
23  * @brief CTA event atom class implementation
24  * @author Juergen Knoedlseder
25  */
26 
27 /* __ Includes ___________________________________________________________ */
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31 #include <string>
32 #include <cmath>
33 #include "GTools.hpp"
34 #include "GCTAEventAtom.hpp"
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 class members for clean destruction
57  init_members();
58 
59  // Return
60  return;
61 }
62 
63 
64 /***********************************************************************//**
65  * @brief Event constructor
66  *
67  * @param[in] dir Event instrument direction.
68  * @param[in] energy Event energy.
69  * @param[in] time Event time.
70  ***************************************************************************/
72  const GEnergy& energy,
73  const GTime& time) : GEventAtom()
74 {
75  // Initialise class members for clean destruction
76  init_members();
77 
78  // Set members
79  m_dir = dir;
80  m_energy = energy;
81  m_time = time;
82 
83  // Return
84  return;
85 }
86 
87 
88 /***********************************************************************//**
89  * @brief Copy constructor
90  *
91  * @param[in] atom Event atom.
92  ***************************************************************************/
94 {
95  // Initialise class members for clean destruction
96  init_members();
97 
98  // Copy members
99  copy_members(atom);
100 
101  // Return
102  return;
103 }
104 
105 
106 /***********************************************************************//**
107  * @brief Destructor
108  ***************************************************************************/
110 {
111  // Free members
112  free_members();
113 
114  // Return
115  return;
116 }
117 
118 
119 /*==========================================================================
120  = =
121  = Operators =
122  = =
123  ==========================================================================*/
124 
125 /***********************************************************************//**
126  * @brief Assignment operator
127  *
128  * @param[in] atom Event atom.
129  * @return Event atom.
130  ***************************************************************************/
132 {
133  // Execute only if object is not identical
134  if (this != &atom) {
135 
136  // Copy base class members
137  this->GEventAtom::operator=(atom);
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(atom);
147 
148  } // endif: object was not identical
149 
150  // Return this object
151  return *this;
152 }
153 
154 
155 /*==========================================================================
156  = =
157  = Public methods =
158  = =
159  ==========================================================================*/
160 
161 /***********************************************************************//**
162  * @brief Clear event atom
163  ***************************************************************************/
165 {
166  // Free class members (base and derived classes, derived class first)
167  free_members();
168  this->GEventAtom::free_members();
169  this->GEvent::free_members();
170 
171  // Initialise members
172  this->GEvent::init_members();
173  this->GEventAtom::init_members();
174  init_members();
175 
176  // Return
177  return;
178 }
179 
180 
181 /***********************************************************************//**
182  * @brief Clone event atom
183  *
184  * @return Pointer to deep copy of event atom.
185  ***************************************************************************/
187 {
188  return new GCTAEventAtom(*this);
189 }
190 
191 
192 /***********************************************************************//**
193  * @brief Print event information
194  *
195  * @param[in] chatter Chattiness (defaults to NORMAL).
196  * @return String containing event information.
197  ***************************************************************************/
198 std::string GCTAEventAtom::print(const GChatter& chatter) const
199 {
200  // Initialise result string
201  std::string result;
202 
203  // Continue only if chatter is not silent
204  if (chatter != SILENT) {
205 
206  // Append event information
207  result.append("Dir="+m_dir.print());
208  result.append(" Energy="+m_energy.print());
209  result.append(" Time="+m_time.print());
210 
211  } // endif: chatter was not silent
212 
213  // Return result
214  return result;
215 }
216 
217 
218 /*==========================================================================
219  = =
220  = Private methods =
221  = =
222  ==========================================================================*/
223 
224 /***********************************************************************//**
225  * @brief Initialise class members
226  ***************************************************************************/
228 {
229  // Initialise members
230  m_dir.clear();
231  m_time.clear();
232  m_energy.clear();
233  m_index = 0;
234  m_event_id = 0;
235  m_mc_id = 0;
236  m_phase = 0.0;
237 
238  // Return
239  return;
240 }
241 
242 
243 /***********************************************************************//**
244  * @brief Copy class members
245  *
246  * @param[in] atom Event atom.
247  ***************************************************************************/
249 {
250  // Copy members
251  m_dir = atom.m_dir;
252  m_time = atom.m_time;
253  m_energy = atom.m_energy;
254  m_index = atom.m_index;
255  m_event_id = atom.m_event_id;
256  m_mc_id = atom.m_mc_id;
257  m_phase = atom.m_phase;
258 
259  // Return
260  return;
261 }
262 
263 
264 /***********************************************************************//**
265  * @brief Delete class members
266  ***************************************************************************/
268 {
269  // Return
270  return;
271 }
virtual ~GCTAEventAtom(void)
Destructor.
GCTAInstDir m_dir
Event direction.
CTA event atom class definition.
GEnergy m_energy
Event energy.
void free_members(void)
Delete class members.
void clear(void)
Clear time.
Definition: GTime.cpp:252
Time class.
Definition: GTime.hpp:55
Gammalib tools definition.
void init_members(void)
Initialise class members.
Definition: GEventAtom.cpp:143
void init_members(void)
Initialise class members.
GCTAEventAtom(void)
Void constructor.
virtual GEventAtom & operator=(const GEventAtom &atom)
Assignment operator.
Definition: GEventAtom.cpp:104
float m_phase
Optional phase.
GCTAEventAtom * clone(void) const
Clone event atom.
std::string print(const GChatter &chatter=NORMAL) const
Print energy.
Definition: GEnergy.cpp:748
void clear(void)
Clear event atom.
const GTime & time(void) const
Return time.
GChatter
Definition: GTypemaps.hpp:33
std::string print(const GChatter &chatter=NORMAL) const
Print time.
Definition: GTime.cpp:1188
void init_members(void)
Initialise class members.
Definition: GEvent.cpp:141
virtual std::string print(const GChatter &chatter=NORMAL) const
Print instrument direction information.
GCTAEventAtom & operator=(const GCTAEventAtom &atom)
Assignment operator.
virtual void clear(void)
Clear CTA instrument direction.
void copy_members(const GCTAEventAtom &atom)
Copy class members.
GTime m_time
Event time.
void free_members(void)
Delete class members.
Definition: GEvent.cpp:163
void free_members(void)
Delete class members.
Definition: GEventAtom.cpp:165
CTA event atom class.
int m_mc_id
Monte Carlo identifier.
CTA instrument direction class.
Definition: GCTAInstDir.hpp:63
int m_index
Index in list.
unsigned long m_event_id
Event identifier.
std::string print(const GChatter &chatter=NORMAL) const
Print event information.
void clear(void)
Clear instance.
Definition: GEnergy.cpp:261
const GEnergy & energy(void) const
Return energy.
const GCTAInstDir & dir(void) const
Return instrument direction.
Class that handles energies in a unit independent way.
Definition: GEnergy.hpp:48
Abstract interface for the event atom class.
Definition: GEventAtom.hpp:62