GammaLib 2.1.0.dev
Loading...
Searching...
No Matches
GGti.hpp
Go to the documentation of this file.
1/***************************************************************************
2 * GGti.hpp - Good time interval class *
3 * ----------------------------------------------------------------------- *
4 * copyright (C) 2008-2024 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 GGti.hpp
23 * @brief Good time interval class interface definition
24 * @author Juergen Knoedlseder
25 */
26
27#ifndef GGTI_HPP
28#define GGTI_HPP
29
30/* __ Includes ___________________________________________________________ */
31#include <string>
32#include "GContainer.hpp"
33#include "GTime.hpp"
34#include "GTimes.hpp"
35#include "GTimeReference.hpp"
36#include "GFilename.hpp"
37
38/* __ Forward declarations _______________________________________________ */
39class GXmlElement;
40class GFits;
41class GFitsTable;
42
43/* __ Constants __________________________________________________________ */
44namespace gammalib {
45 const std::string extname_gti = "GTI";
46}
47
48
49/***********************************************************************//**
50 * @class GGti
51 *
52 * @brief Good Time Interval class
53 *
54 * This class holds a list of Good Time Intervals, i.e. time intervals that
55 * are valid for science analysis. Times are stored using the GTime class.
56 * The class also holds information about the time reference, which will
57 * be retained when reading and used when writing, so that Good Time
58 * Intervals are always written in the specified time reference.
59 *
60 * The class has no method for sorting of the Good Time Intervals; it is
61 * expected that the Good Time Intervals are correctly set by the client.
62 ***************************************************************************/
63class GGti : public GContainer {
64
65public:
66 // Constructors and destructors
67 GGti(void);
68 explicit GGti(const GFilename& filename);
69 GGti(const GGti& gti);
70 GGti(const GTime& tstart, const GTime& tstop);
71 explicit GGti(const GXmlElement& xml);
72 explicit GGti(const GTimeReference& ref);
73 virtual ~GGti(void);
74
75 // Operators
76 GGti& operator=(const GGti& gti);
77
78 // Methods
79 void clear(void);
80 GGti* clone(void) const;
81 std::string classname(void) const;
82 int size(void) const;
83 bool is_empty(void) const;
84 void append(const GTime& tstart, const GTime& tstop);
85 void append(const GTimes& tstart, const GTimes& tstop);
86 void insert(const GTime& tstart, const GTime& tstop);
87 void merge(void);
88 void merge(const GTime& tstart, const GTime& tstop);
89 void reduce(const GTime& tstart, const GTime& tstop);
90 void reduce(const GGti& gti);
91 void remove(const int& index);
92 void reserve(const int& num);
93 void extend(const GGti& gti);
94 void load(const GFilename& filename);
95 void save(const GFilename& filename,
96 const bool& clobber = false) const;
97 void read(const GFitsTable& table);
98 void write(GFits& fits,
99 const std::string& extname = gammalib::extname_gti) const;
100 void read(const GXmlElement& xml);
101 void write(GXmlElement& xml) const;
102 const GTime& tstart(void) const;
103 const GTime& tstop(void) const;
104 const GTime& tstart(const int& index) const;
105 const GTime& tstop(const int& index) const;
106 const double& telapse(void) const;
107 const double& ontime(void) const;
108 double overlap(const GTime& tstart, const GTime& tstop) const;
109 void reference(const GTimeReference& ref);
110 const GTimeReference& reference(void) const;
111 bool contains(const GTime& time) const;
112 std::string print(const GChatter& chatter = NORMAL) const;
113
114protected:
115 // Protected methods
116 void init_members(void);
117 void copy_members(const GGti& gti);
118 void free_members(void);
119 void set_attributes(void);
120 void insert_gti(const int& index, const GTime& tstart, const GTime& tstop);
121 void insert_gtis(const int& index, const GTimes& tstart, const GTimes& tstop);
122
123 // Protected data area
124 int m_num; //!< Number of Good Time Intervals
125 GTime m_tstart; //!< Start time of Good Time Intervals
126 GTime m_tstop; //!< Stop time of Good Time Intervals
127 double m_ontime; //!< Sum of GTIs durations (in seconds)
128 double m_telapse; //!< Time between start of first GTI and stop of last GTI (in seconds)
129 GTime *m_start; //!< Array of start times
130 GTime *m_stop; //!< Array of stop times
131 GTimeReference m_reference; //!< Time reference
132 GFilename m_xml_filename; //!< XML filename
133
134 // Computation cache
135 mutable int m_last_index; //!< Last index for containment test
136};
137
138
139/***********************************************************************//**
140 * @brief Return class name
141 *
142 * @return String containing the class name ("GGti").
143 ***************************************************************************/
144inline
145std::string GGti::classname(void) const
146{
147 return ("GGti");
148}
149
150
151/***********************************************************************//**
152 * @brief Return number of Good Time Intervals
153 *
154 * @return Number of Good Time Intervals.
155 ***************************************************************************/
156inline
157int GGti::size(void) const
158{
159 return m_num;
160}
161
162
163/***********************************************************************//**
164 * @brief Signal if there are no Good Time Intervals
165 *
166 * @return True if there are no Good Time Intervals.
167 ***************************************************************************/
168inline
169bool GGti::is_empty(void) const
170{
171 return (m_num == 0);
172}
173
174
175/***********************************************************************//**
176 * @brief Reserve space for Good Time Intervals
177 *
178 * @param[in] num Number of elements.
179 *
180 * This method does nothing (it is needed to satisfy the GContainer
181 * interface).
182 ***************************************************************************/
183inline
184void GGti::reserve(const int& num)
185{
186 // Return
187 return;
188}
189
190
191/***********************************************************************//**
192 * @brief Returns earliest start time in Good Time Intervals
193 *
194 * @return Earliest start time in Good Time Intervals.
195 ***************************************************************************/
196inline
197const GTime& GGti::tstart(void) const
198{
199 // Return
200 return m_tstart;
201}
202
203
204/***********************************************************************//**
205 * @brief Returns latest stop time in Good Time Intervals
206 *
207 * @return Latest stop time in Good Time Intervals.
208 ***************************************************************************/
209inline
210const GTime& GGti::tstop(void) const
211{
212 // Return
213 return m_tstop;
214}
215
216
217/***********************************************************************//**
218 * @brief Returns elapsed time
219 *
220 * @return Elapsed time (seconds).
221 *
222 * Returns the elapsed time in seconds. The elapsed time is defined as the
223 * time difference between the latest stop time and the earliest start time
224 * in the Good Time Intervals.
225 ***************************************************************************/
226inline
227const double& GGti::telapse(void) const
228{
229 // Return
230 return m_telapse;
231}
232
233
234/***********************************************************************//**
235 * @brief Returns ontime
236 *
237 * @return Ontime (seconds).
238 *
239 * Returns the ontime in seconds. The ontime is defined as the sum of all
240 * Good Time Intervals.
241 ***************************************************************************/
242inline
243const double& GGti::ontime(void) const
244{
245 // Return
246 return m_ontime;
247}
248
249
250/***********************************************************************//**
251 * @brief Set time reference for Good Time Intervals
252 *
253 * @param[in] ref Time reference.
254 *
255 * Sets the time reference of the Good Time Intervals. This defines the
256 * reference time which will be writted into the FITS file upon saving of
257 * the Good Time Intervals.
258 ***************************************************************************/
259inline
261{
262 // Set time reference
263 m_reference = ref;
264
265 // Return
266 return;
267}
268
269
270/***********************************************************************//**
271 * @brief Return time reference for Good Time Intervals
272 *
273 * @return Time reference.
274 *
275 * Returns the time reference of the Good Time Intervals.
276 ***************************************************************************/
277inline
279{
280 // Return time reference
281 return m_reference;
282}
283
284#endif /* GGTI_HPP */
Definition of interface for container classes.
Filename class interface definition.
Time reference class interface definition.
Time class interface definition.
Time container class definition.
GChatter
Definition GTypemaps.hpp:33
@ NORMAL
Definition GTypemaps.hpp:36
Interface class for container classes.
Filename class.
Definition GFilename.hpp:62
Abstract interface for FITS table.
FITS file class.
Definition GFits.hpp:63
Good Time Interval class.
Definition GGti.hpp:63
int m_last_index
Last index for containment test.
Definition GGti.hpp:135
GGti * clone(void) const
Clone Good Time Intervals.
Definition GGti.cpp:256
void set_attributes(void)
Set class attributes.
Definition GGti.cpp:1273
bool contains(const GTime &time) const
Checks whether Good Time Intervals contains time.
Definition GGti.cpp:1089
const GTimeReference & reference(void) const
Return time reference for Good Time Intervals.
Definition GGti.hpp:278
void insert(const GTime &tstart, const GTime &tstop)
Insert Good Time Interval.
Definition GGti.cpp:308
std::string print(const GChatter &chatter=NORMAL) const
Print Good Time Intervals.
Definition GGti.cpp:1125
const double & telapse(void) const
Returns elapsed time.
Definition GGti.hpp:227
void remove(const int &index)
Remove Good Time Interval.
Definition GGti.cpp:606
void load(const GFilename &filename)
Load Good Time Intervals from FITS file.
Definition GGti.cpp:702
GGti & operator=(const GGti &gti)
Assignment operator.
Definition GGti.cpp:208
void copy_members(const GGti &gti)
Copy class members.
Definition GGti.cpp:1216
GTime m_tstart
Start time of Good Time Intervals.
Definition GGti.hpp:125
GTime * m_stop
Array of stop times.
Definition GGti.hpp:130
void write(GFits &fits, const std::string &extname=gammalib::extname_gti) const
Write Good Time Intervals and time reference into FITS object.
Definition GGti.cpp:815
GTime m_tstop
Stop time of Good Time Intervals.
Definition GGti.hpp:126
GTime * m_start
Array of start times.
Definition GGti.hpp:129
void init_members(void)
Initialise class members.
Definition GGti.cpp:1187
void insert_gtis(const int &index, const GTimes &tstart, const GTimes &tstop)
Insert Good Time Intervals.
Definition GGti.cpp:1400
std::string classname(void) const
Return class name.
Definition GGti.hpp:145
void insert_gti(const int &index, const GTime &tstart, const GTime &tstop)
Insert Good Time Interval.
Definition GGti.cpp:1323
const GTime & tstop(void) const
Returns latest stop time in Good Time Intervals.
Definition GGti.hpp:210
GTimeReference m_reference
Time reference.
Definition GGti.hpp:131
void save(const GFilename &filename, const bool &clobber=false) const
Save Good Time Intervals into FITS file.
Definition GGti.cpp:746
void extend(const GGti &gti)
Append Good Time Intervals.
Definition GGti.cpp:643
double m_telapse
Time between start of first GTI and stop of last GTI (in seconds)
Definition GGti.hpp:128
void read(const GFitsTable &table)
Read Good Time Intervals and time reference from FITS table.
Definition GGti.cpp:772
bool is_empty(void) const
Signal if there are no Good Time Intervals.
Definition GGti.hpp:169
int size(void) const
Return number of Good Time Intervals.
Definition GGti.hpp:157
GFilename m_xml_filename
XML filename.
Definition GGti.hpp:132
int m_num
Number of Good Time Intervals.
Definition GGti.hpp:124
virtual ~GGti(void)
Destructor.
Definition GGti.cpp:186
void free_members(void)
Delete class members.
Definition GGti.cpp:1248
void reserve(const int &num)
Reserve space for Good Time Intervals.
Definition GGti.hpp:184
void reduce(const GTime &tstart, const GTime &tstop)
Reduce Good Time Intervals to specified interval.
Definition GGti.cpp:420
const double & ontime(void) const
Returns ontime.
Definition GGti.hpp:243
GGti(void)
Void constructor.
Definition GGti.cpp:69
void merge(void)
Merge all overlapping Good Time Intervals.
Definition GGti.cpp:336
void append(const GTime &tstart, const GTime &tstop)
Append Good Time Interval.
Definition GGti.cpp:270
const GTime & tstart(void) const
Returns earliest start time in Good Time Intervals.
Definition GGti.hpp:197
void clear(void)
Clear Good Time Intervals.
Definition GGti.cpp:238
double m_ontime
Sum of GTIs durations (in seconds)
Definition GGti.hpp:127
double overlap(const GTime &tstart, const GTime &tstop) const
Computes overlap of time interval with GTIs.
Definition GGti.cpp:1044
Implements a time reference.
Time class.
Definition GTime.hpp:55
Time container class.
Definition GTimes.hpp:45
XML element node class.
const std::string extname_gti
Definition GGti.hpp:45