GammaLib  1.7.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-2019 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 remove(const int& index);
89  void reserve(const int& num);
90  void extend(const GGti& gti);
91  void load(const GFilename& filename);
92  void save(const GFilename& filename,
93  const bool& clobber = false) const;
94  void read(const GFitsTable& table);
95  void write(GFits& fits,
96  const std::string& extname = gammalib::extname_gti) const;
97  void read(const GXmlElement& xml);
98  void write(GXmlElement& xml) const;
99  const GTime& tstart(void) const;
100  const GTime& tstop(void) const;
101  const GTime& tstart(const int& index) const;
102  const GTime& tstop(const int& index) const;
103  const double& telapse(void) const;
104  const double& ontime(void) const;
105  double overlap(const GTime& tstart, const GTime& tstop) const;
106  void reference(const GTimeReference& ref);
107  const GTimeReference& reference(void) const;
108  bool contains(const GTime& time) const;
109  std::string print(const GChatter& chatter = NORMAL) const;
110 
111 protected:
112  // Protected methods
113  void init_members(void);
114  void copy_members(const GGti& gti);
115  void free_members(void);
116  void set_attributes(void);
117  void insert_gti(const int& index, const GTime& tstart, const GTime& tstop);
118 
119  // Protected data area
120  int m_num; //!< Number of Good Time Intervals
121  GTime m_tstart; //!< Start time of Good Time Intervals
122  GTime m_tstop; //!< Stop time of Good Time Intervals
123  double m_ontime; //!< Sum of GTIs durations (in seconds)
124  double m_telapse; //!< Time between start of first GTI and stop of last GTI (in seconds)
125  GTime *m_start; //!< Array of start times
126  GTime *m_stop; //!< Array of stop times
127  GTimeReference m_reference; //!< Time reference
128  GFilename m_xml_filename; //!< XML filename
129 
130  // Computation cache
131  mutable int m_last_index; //!< Last index for containment test
132 };
133 
134 
135 /***********************************************************************//**
136  * @brief Return class name
137  *
138  * @return String containing the class name ("GGti").
139  ***************************************************************************/
140 inline
141 std::string GGti::classname(void) const
142 {
143  return ("GGti");
144 }
145 
146 
147 /***********************************************************************//**
148  * @brief Return number of Good Time Intervals
149  *
150  * @return Number of Good Time Intervals.
151  ***************************************************************************/
152 inline
153 int GGti::size(void) const
154 {
155  return m_num;
156 }
157 
158 
159 /***********************************************************************//**
160  * @brief Signal if there are no Good Time Intervals
161  *
162  * @return True if there are no Good Time Intervals.
163  ***************************************************************************/
164 inline
165 bool GGti::is_empty(void) const
166 {
167  return (m_num == 0);
168 }
169 
170 
171 /***********************************************************************//**
172  * @brief Reserve space for Good Time Intervals
173  *
174  * @param[in] num Number of elements.
175  *
176  * This method does nothing (it is needed to satisfy the GContainer
177  * interface).
178  ***************************************************************************/
179 inline
180 void GGti::reserve(const int& num)
181 {
182  // Return
183  return;
184 }
185 
186 
187 /***********************************************************************//**
188  * @brief Returns earliest start time in Good Time Intervals
189  *
190  * @return Earliest start time in Good Time Intervals.
191  ***************************************************************************/
192 inline
193 const GTime& GGti::tstart(void) const
194 {
195  // Return
196  return m_tstart;
197 }
198 
199 
200 /***********************************************************************//**
201  * @brief Returns latest stop time in Good Time Intervals
202  *
203  * @return Latest stop time in Good Time Intervals.
204  ***************************************************************************/
205 inline
206 const GTime& GGti::tstop(void) const
207 {
208  // Return
209  return m_tstop;
210 }
211 
212 
213 /***********************************************************************//**
214  * @brief Returns elapsed time
215  *
216  * @return Elapsed time (seconds).
217  *
218  * Returns the elapsed time in seconds. The elapsed time is defined as the
219  * time difference between the latest stop time and the earliest start time
220  * in the Good Time Intervals.
221  ***************************************************************************/
222 inline
223 const double& GGti::telapse(void) const
224 {
225  // Return
226  return m_telapse;
227 }
228 
229 
230 /***********************************************************************//**
231  * @brief Returns ontime
232  *
233  * @return Ontime (seconds).
234  *
235  * Returns the ontime in seconds. The ontime is defined as the sum of all
236  * Good Time Intervals.
237  ***************************************************************************/
238 inline
239 const double& GGti::ontime(void) const
240 {
241  // Return
242  return m_ontime;
243 }
244 
245 
246 /***********************************************************************//**
247  * @brief Set time reference for Good Time Intervals
248  *
249  * @param[in] ref Time reference.
250  *
251  * Sets the time reference of the Good Time Intervals. This defines the
252  * reference time which will be writted into the FITS file upon saving of
253  * the Good Time Intervals.
254  ***************************************************************************/
255 inline
257 {
258  // Set time reference
259  m_reference = ref;
260 
261  // Return
262  return;
263 }
264 
265 
266 /***********************************************************************//**
267  * @brief Return time reference for Good Time Intervals
268  *
269  * @return Time reference.
270  *
271  * Returns the time reference of the Good Time Intervals.
272  ***************************************************************************/
273 inline
274 const GTimeReference& GGti::reference(void) const
275 {
276  // Return time reference
277  return m_reference;
278 }
279 
280 #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:952
double m_ontime
Sum of GTIs durations (in seconds)
Definition: GGti.hpp:123
void reserve(const int &num)
Reserve space for Good Time Intervals.
Definition: GGti.hpp:180
int m_last_index
Last index for containment test.
Definition: GGti.hpp:131
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:274
GFilename m_xml_filename
XML filename.
Definition: GGti.hpp:128
XML element node class.
Definition: GXmlElement.hpp:47
void free_members(void)
Delete class members.
Definition: GGti.cpp:1111
GTimeReference m_reference
Time reference.
Definition: GGti.hpp:127
Time class.
Definition: GTime.hpp:54
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:1186
std::string print(const GChatter &chatter=NORMAL) const
Print Good Time Intervals.
Definition: GGti.cpp:988
GGti * clone(void) const
Clone Good Time Intervals.
Definition: GGti.cpp:255
void init_members(void)
Initialise class members.
Definition: GGti.cpp:1050
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:153
double m_telapse
Time between start of first GTI and stop of last GTI (in seconds)
Definition: GGti.hpp:124
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:613
void clear(void)
Clear Good Time Intervals.
Definition: GGti.cpp:237
int m_num
Number of Good Time Intervals.
Definition: GGti.hpp:120
void load(const GFilename &filename)
Load Good Time Intervals from FITS file.
Definition: GGti.cpp:570
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:206
void set_attributes(void)
Set class attributes.
Definition: GGti.cpp:1136
const GTime & tstart(void) const
Returns earliest start time in Good Time Intervals.
Definition: GGti.hpp:193
GTime m_tstart
Start time of Good Time Intervals.
Definition: GGti.hpp:121
void copy_members(const GGti &gti)
Copy class members.
Definition: GGti.cpp:1079
double overlap(const GTime &tstart, const GTime &tstop) const
Computes overlap of time interval with GTIs.
Definition: GGti.cpp:907
GTime m_tstop
Stop time of Good Time Intervals.
Definition: GGti.hpp:122
void read(const GFitsTable &table)
Read Good Time Intervals and time reference from FITS table.
Definition: GGti.cpp:639
Implements a time reference.
Definition of interface for container classes.
GTime * m_stop
Array of stop times.
Definition: GGti.hpp:126
const double & telapse(void) const
Returns elapsed time.
Definition: GGti.hpp:223
bool is_empty(void) const
Signal if there are no Good Time Intervals.
Definition: GGti.hpp:165
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:682
GTime * m_start
Array of start times.
Definition: GGti.hpp:125
Time class interface definition.
void extend(const GGti &gti)
Append Good Time Intervals.
Definition: GGti.cpp:511
const double & ontime(void) const
Returns ontime.
Definition: GGti.hpp:239
std::string classname(void) const
Return class name.
Definition: GGti.hpp:141
void reduce(const GTime &tstart, const GTime &tstop)
Reduce Good Time Intervals to specified interval.
Definition: GGti.cpp:398
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