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