GammaLib  1.7.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-2018 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 "GCTAEventAtom.hpp"
34 #include "GCTAException.hpp"
35 #include "GTools.hpp"
36 
37 /* __ Method name definitions ____________________________________________ */
38 
39 /* __ Macros _____________________________________________________________ */
40 
41 /* __ Coding definitions _________________________________________________ */
42 
43 /* __ Debug definitions __________________________________________________ */
44 
45 
46 /*==========================================================================
47  = =
48  = Constructors/destructors =
49  = =
50  ==========================================================================*/
51 
52 /***********************************************************************//**
53  * @brief Void constructor
54  ***************************************************************************/
56 {
57  // Initialise class members for clean destruction
58  init_members();
59 
60  // Return
61  return;
62 }
63 
64 
65 /***********************************************************************//**
66  * @brief Event constructor
67  *
68  * @param[in] dir Event instrument direction.
69  * @param[in] energy Event energy.
70  * @param[in] time Event time.
71  ***************************************************************************/
73  const GEnergy& energy,
74  const GTime& time) : GEventAtom()
75 {
76  // Initialise class members for clean destruction
77  init_members();
78 
79  // Set members
80  m_dir = dir;
81  m_energy = energy;
82  m_time = time;
83 
84  // Return
85  return;
86 }
87 
88 
89 /***********************************************************************//**
90  * @brief Copy constructor
91  *
92  * @param[in] atom Event atom.
93  ***************************************************************************/
95 {
96  // Initialise class members for clean destruction
97  init_members();
98 
99  // Copy members
100  copy_members(atom);
101 
102  // Return
103  return;
104 }
105 
106 
107 /***********************************************************************//**
108  * @brief Destructor
109  ***************************************************************************/
111 {
112  // Free members
113  free_members();
114 
115  // Return
116  return;
117 }
118 
119 
120 /*==========================================================================
121  = =
122  = Operators =
123  = =
124  ==========================================================================*/
125 
126 /***********************************************************************//**
127  * @brief Assignment operator
128  *
129  * @param[in] atom Event atom.
130  * @return Event atom.
131  ***************************************************************************/
133 {
134  // Execute only if object is not identical
135  if (this != &atom) {
136 
137  // Copy base class members
138  this->GEventAtom::operator=(atom);
139 
140  // Free members
141  free_members();
142 
143  // Initialise private members for clean destruction
144  init_members();
145 
146  // Copy members
147  copy_members(atom);
148 
149  } // endif: object was not identical
150 
151  // Return this object
152  return *this;
153 }
154 
155 
156 /*==========================================================================
157  = =
158  = Public methods =
159  = =
160  ==========================================================================*/
161 
162 /***********************************************************************//**
163  * @brief Clear event atom
164  ***************************************************************************/
166 {
167  // Free class members (base and derived classes, derived class first)
168  free_members();
169  this->GEventAtom::free_members();
170  this->GEvent::free_members();
171 
172  // Initialise members
173  this->GEvent::init_members();
174  this->GEventAtom::init_members();
175  init_members();
176 
177  // Return
178  return;
179 }
180 
181 
182 /***********************************************************************//**
183  * @brief Clone event atom
184  *
185  * @return Pointer to deep copy of event atom.
186  ***************************************************************************/
188 {
189  return new GCTAEventAtom(*this);
190 }
191 
192 
193 /***********************************************************************//**
194  * @brief Print event information
195  *
196  * @param[in] chatter Chattiness (defaults to NORMAL).
197  * @return String containing event information.
198  ***************************************************************************/
199 std::string GCTAEventAtom::print(const GChatter& chatter) const
200 {
201  // Initialise result string
202  std::string result;
203 
204  // Continue only if chatter is not silent
205  if (chatter != SILENT) {
206 
207  // Append event information
208  result.append("Dir="+m_dir.print());
209  result.append(" Energy="+m_energy.print());
210  result.append(" Time="+m_time.print());
211 
212  } // endif: chatter was not silent
213 
214  // Return result
215  return result;
216 }
217 
218 
219 /*==========================================================================
220  = =
221  = Private methods =
222  = =
223  ==========================================================================*/
224 
225 /***********************************************************************//**
226  * @brief Initialise class members
227  ***************************************************************************/
229 {
230  // Initialise members
231  m_dir.clear();
232  m_time.clear();
233  m_energy.clear();
234  m_index = 0;
235  m_event_id = 0;
236  m_mc_id = 0;
237  m_phase = 0.0;
238 
239  // Return
240  return;
241 }
242 
243 
244 /***********************************************************************//**
245  * @brief Copy class members
246  *
247  * @param[in] atom Event atom.
248  ***************************************************************************/
250 {
251  // Copy members
252  m_dir = atom.m_dir;
253  m_time = atom.m_time;
254  m_energy = atom.m_energy;
255  m_index = atom.m_index;
256  m_event_id = atom.m_event_id;
257  m_mc_id = atom.m_mc_id;
258  m_phase = atom.m_phase;
259 
260  // Return
261  return;
262 }
263 
264 
265 /***********************************************************************//**
266  * @brief Delete class members
267  ***************************************************************************/
269 {
270  // Return
271  return;
272 }
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:251
Time class.
Definition: GTime.hpp:54
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:1161
void init_members(void)
Initialise class members.
Definition: GEvent.cpp:141
virtual std::string print(const GChatter &chatter=NORMAL) const
Print instrument direction information.
CTA exception handler interface definition.
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:59
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