GammaLib
2.0.0
|
Good Time Interval class. More...
#include <GGti.hpp>
Public Member Functions | |
GGti (void) | |
Void constructor. More... | |
GGti (const GFilename &filename) | |
FITS file constructor. More... | |
GGti (const GGti >i) | |
Copy constructor. More... | |
GGti (const GTime &tstart, const GTime &tstop) | |
Single time interval constructor. More... | |
GGti (const GXmlElement &xml) | |
XML element constructor. More... | |
GGti (const GTimeReference &ref) | |
Time reference constructor. More... | |
virtual | ~GGti (void) |
Destructor. More... | |
GGti & | operator= (const GGti >i) |
Assignment operator. More... | |
void | clear (void) |
Clear Good Time Intervals. More... | |
GGti * | clone (void) const |
Clone Good Time Intervals. More... | |
std::string | classname (void) const |
Return class name. More... | |
int | size (void) const |
Return number of Good Time Intervals. More... | |
bool | is_empty (void) const |
Signal if there are no Good Time Intervals. More... | |
void | append (const GTime &tstart, const GTime &tstop) |
Append Good Time Interval. More... | |
void | insert (const GTime &tstart, const GTime &tstop) |
Insert Good Time Interval. More... | |
void | merge (void) |
Merge all overlapping Good Time Intervals. More... | |
void | merge (const GTime &tstart, const GTime &tstop) |
Merge Good Time Interval into container. More... | |
void | reduce (const GTime &tstart, const GTime &tstop) |
Reduce Good Time Intervals to specified interval. More... | |
void | reduce (const GGti >i) |
Reduce Good Time Intervals to specified intervals. More... | |
void | remove (const int &index) |
Remove Good Time Interval. More... | |
void | reserve (const int &num) |
Reserve space for Good Time Intervals. More... | |
void | extend (const GGti >i) |
Append Good Time Intervals. More... | |
void | load (const GFilename &filename) |
Load Good Time Intervals from FITS file. More... | |
void | save (const GFilename &filename, const bool &clobber=false) const |
Save Good Time Intervals into FITS file. More... | |
void | read (const GFitsTable &table) |
Read Good Time Intervals and time reference from FITS table. More... | |
void | write (GFits &fits, const std::string &extname=gammalib::extname_gti) const |
Write Good Time Intervals and time reference into FITS object. More... | |
void | read (const GXmlElement &xml) |
Read Good Time Intervals from XML element. More... | |
void | write (GXmlElement &xml) const |
Write Good Time Intervals into XML element. More... | |
const GTime & | tstart (void) const |
Returns earliest start time in Good Time Intervals. More... | |
const GTime & | tstop (void) const |
Returns latest stop time in Good Time Intervals. More... | |
const GTime & | tstart (const int &index) const |
Returns start time for a given Good Time Interval. More... | |
const GTime & | tstop (const int &index) const |
Returns stop time for a given Good Time Interval. More... | |
const double & | telapse (void) const |
Returns elapsed time. More... | |
const double & | ontime (void) const |
Returns ontime. More... | |
double | overlap (const GTime &tstart, const GTime &tstop) const |
Computes overlap of time interval with GTIs. More... | |
void | reference (const GTimeReference &ref) |
Set time reference for Good Time Intervals. More... | |
const GTimeReference & | reference (void) const |
Return time reference for Good Time Intervals. More... | |
bool | contains (const GTime &time) const |
Checks whether Good Time Intervals contains time. More... | |
std::string | print (const GChatter &chatter=NORMAL) const |
Print Good Time Intervals. More... | |
Public Member Functions inherited from GContainer | |
virtual | ~GContainer (void) |
Destructor. More... | |
Public Member Functions inherited from GBase | |
virtual | ~GBase (void) |
Destructor. More... | |
Protected Member Functions | |
void | init_members (void) |
Initialise class members. More... | |
void | copy_members (const GGti >i) |
Copy class members. More... | |
void | free_members (void) |
Delete class members. More... | |
void | set_attributes (void) |
Set class attributes. More... | |
void | insert_gti (const int &index, const GTime &tstart, const GTime &tstop) |
Insert Good Time Interval. More... | |
Protected Attributes | |
int | m_num |
Number of Good Time Intervals. More... | |
GTime | m_tstart |
Start time of Good Time Intervals. More... | |
GTime | m_tstop |
Stop time of Good Time Intervals. More... | |
double | m_ontime |
Sum of GTIs durations (in seconds) More... | |
double | m_telapse |
Time between start of first GTI and stop of last GTI (in seconds) More... | |
GTime * | m_start |
Array of start times. More... | |
GTime * | m_stop |
Array of stop times. More... | |
GTimeReference | m_reference |
Time reference. More... | |
GFilename | m_xml_filename |
XML filename. More... | |
int | m_last_index |
Last index for containment test. More... | |
Good Time Interval class.
This class holds a list of Good Time Intervals, i.e. time intervals that are valid for science analysis. Times are stored using the GTime class. The class also holds information about the time reference, which will be retained when reading and used when writing, so that Good Time Intervals are always written in the specified time reference.
The class has no method for sorting of the Good Time Intervals; it is expected that the Good Time Intervals are correctly set by the client.
GGti::GGti | ( | void | ) |
Void constructor.
Constructs empty Good Time Intervals.
Definition at line 68 of file GGti.cpp.
References init_members().
Referenced by clone().
|
explicit |
FITS file constructor.
[in] | filename | FITS file name. |
Constructs Good Time Intervals from a FITS file.
Definition at line 85 of file GGti.cpp.
References init_members(), and load().
GGti::GGti | ( | const GGti & | gti | ) |
Copy constructor.
[in] | gti | Good Time Intervals. |
Constructs Good Time Intervals by copying other Good Time Intervals.
Definition at line 105 of file GGti.cpp.
References copy_members(), and init_members().
Single time interval constructor.
[in] | tstart | Start time of interval. |
[in] | tstop | Stop time of interval. |
Constructs Good Time Intervals from a single time interval, given by [p@ tstart, tstop
].
Definition at line 147 of file GGti.cpp.
References append(), and init_members().
|
explicit |
XML element constructor.
[in] | xml | XML element. |
Constructs Good Time Intervals from an XML element.
Definition at line 125 of file GGti.cpp.
References init_members(), and read().
|
explicit |
Time reference constructor.
[in] | ref | Time reference. |
Constructs Good Time Intervals using a specific time reference. The time reference will be used when writing the Good Time Intervals into a FITS file.
Definition at line 169 of file GGti.cpp.
References init_members(), and reference().
|
virtual |
Append Good Time Interval.
[in] | tstart | Start time of interval. |
[in] | tstop | Stop time of interval. |
Appends a Good Time Interval at the end of the container.
Definition at line 269 of file GGti.cpp.
References insert_gti(), and m_num.
Referenced by GGti(), GCOMEventList::read(), GLATEventList::read(), GCTAEventList::read(), read(), GSPIEventCube::read_gti(), and GPulsar::validity().
|
inlinevirtual |
|
virtual |
Clear Good Time Intervals.
Implements GBase.
Definition at line 237 of file GGti.cpp.
References free_members(), and init_members().
Referenced by GCTACubeExposure::fill(), GCOMTim::init_members(), GLATLtCube::init_members(), GCTACubeExposure::init_members(), GEvents::init_members(), GCOMDri::init_members(), read(), reduce(), and GCTACubeExposure::set().
|
virtual |
bool GGti::contains | ( | const GTime & | time | ) | const |
Checks whether Good Time Intervals contains time.
[in] | time | Time to be checked. |
Checks if a given time
falls in at least one of the Good Time Intervals. The method exits when the first matching interval has been found.
Since this method may be called repeadetly while scanning an ordered list of time it is most efficient to start the search always at the index where the last search was successful.
Definition at line 1070 of file GGti.cpp.
References m_last_index, m_num, m_start, and m_stop.
Referenced by GCOMTim::contains(), and GCOMDri::use_superpacket().
|
protected |
Copy class members.
[in] | gti | Good Time Intervals. |
Definition at line 1197 of file GGti.cpp.
References m_last_index, m_num, m_ontime, m_reference, m_start, m_stop, m_telapse, m_tstart, m_tstop, and m_xml_filename.
Referenced by GGti(), and operator=().
void GGti::extend | ( | const GGti & | gti | ) |
Append Good Time Intervals.
[in] | gti | Good Time Intervals. |
Append Good Time Intervals to the container. The method performs automatic time reference conversion in case that the specified Good Time Intervals gti
have a time reference that differs from that of the current instance.
Definition at line 624 of file GGti.cpp.
References GTime::convert(), is_empty(), m_num, m_reference, m_start, m_stop, GTime::set(), set_attributes(), size(), tstart(), and tstop().
Referenced by GCTACubeExposure::fill_cube().
|
protected |
|
protected |
Initialise class members.
Definition at line 1168 of file GGti.cpp.
References GTime::clear(), GFilename::clear(), m_last_index, m_num, m_ontime, m_reference, m_start, m_stop, m_telapse, m_tstart, m_tstop, m_xml_filename, and GTime::reference().
Referenced by clear(), GGti(), and operator=().
Insert Good Time Interval.
[in] | tstart | Start time of interval. |
[in] | tstop | Stop time of interval. |
Inserts a Good Time Interval into the container after the first interval that has a start time smaller than tstart
. The method implicitely assumes that the Good Time Intervals are ordered by increasing start time.
Definition at line 289 of file GGti.cpp.
References insert_gti(), m_num, and m_start.
Referenced by GCOMTim::read().
Insert Good Time Interval.
[in] | index | Index at which interval is inserted. |
[in] | tstart | Start time of interval. |
[in] | tstop | Stop time of interval. |
GException::invalid_argument | Start time later than stop time |
Inserts a Good Time Interval at the specified index
in the Good Time Intervals. The method does not reorder the intervals by time, instead the client needs to determine the approriate index
.
Invalid parameters do not produce any exception, but are handled transparently. If the interval is invalid (i.e. tstart
> tstop
) an exception is thrown. If the index
is out of the valid range, the index will be adjusted to either the first or the last element.
Definition at line 1304 of file GGti.cpp.
References G_INSERT_GTI, m_num, m_start, m_stop, NORMAL, GTime::print(), set_attributes(), tstart(), and tstop().
|
inlinevirtual |
Signal if there are no Good Time Intervals.
Implements GContainer.
Definition at line 166 of file GGti.hpp.
References m_num.
Referenced by extend(), GCTACubeExposure::fill_cube(), and write().
void GGti::load | ( | const GFilename & | filename | ) |
Load Good Time Intervals from FITS file.
[in] | filename | FITS filename. |
Loads the Good Time Intervals from FITS file.
If no extension name is provided in the filename
, the Good Time Intervals are loaded from the GTI
extension.
Definition at line 683 of file GGti.cpp.
References GFits::close(), GFilename::extname(), gammalib::extname_gti, read(), and GFits::table().
void GGti::merge | ( | void | ) |
Merge all overlapping Good Time Intervals.
Merges all overlapping or connecting successive Good Time Intervals. The method implicitely assumes that the intervals are ordered by increasing start time.
Note that the method does not actually reduce the memory size but just updates the information on the number of elements in the array.
Definition at line 317 of file GGti.cpp.
References m_num, m_start, m_stop, and set_attributes().
Referenced by merge(), and GCOMTim::read().
Merge Good Time Interval into container.
[in] | tstart | Start time of interval. |
[in] | tstop | Stop time of interval. |
Inserts a Good Time Interval into the container after the first interval that has a start time smaller than tstart
and then merges any overlapping or connecting Good Time Intervals. The method implicitely assumes that the intervals are ordered by increasing start time.
Definition at line 365 of file GGti.cpp.
References insert_gti(), m_num, m_start, and merge().
|
inline |
Returns ontime.
Returns the ontime in seconds. The ontime is defined as the sum of all Good Time Intervals.
Definition at line 240 of file GGti.hpp.
References m_ontime.
Referenced by GCTACubeExposure::deadc(), GCOMObservation::load(), GCTACubeExposure::ontime(), GCOMTim::print(), print(), GCTAObservation::read(), GCOMEventCube::set_times(), GLATEventCube::set_times(), GCTAEventCube::set_times(), and GCTACubeExposure::write_attributes().
Assignment operator.
[in] | gti | Good Time Intervals. |
Definition at line 207 of file GGti.cpp.
References copy_members(), free_members(), and init_members().
Print Good Time Intervals.
[in] | chatter | Chattiness. |
Implements GBase.
Definition at line 1106 of file GGti.cpp.
References EXPLICIT, GFilename::is_empty(), m_xml_filename, ontime(), gammalib::parformat(), reference(), SILENT, size(), gammalib::str(), telapse(), tstart(), and tstop().
Referenced by GCOMDri::print(), GLATLtCube::print(), and GCTACubeExposure::print().
void GGti::read | ( | const GFitsTable & | table | ) |
Read Good Time Intervals and time reference from FITS table.
[in] | table | FITS table. |
Reads the Good Time Intervals and time reference from a FITS table. The start and stop times of the Good Time Intervals are read from the "START" and "STOP" columns.
Definition at line 753 of file GGti.cpp.
References clear(), GFitsHDU::integer(), m_num, m_reference, m_start, m_stop, GTimeReference::read(), GTime::set(), and set_attributes().
Referenced by GGti(), load(), GLATEventList::read(), GCTAEventList::read(), GLATLtCube::read(), GCTACubeExposure::read(), GCTAObservation::read(), GLATEventCube::read_gti(), and GCTAEventCube::read_gti().
void GGti::read | ( | const GXmlElement & | xml | ) |
Read Good Time Intervals from XML element.
[in] | xml | XML element. |
GException::invalid_value | Invalid XML format encountered. |
Read Good Time Intervals from an XML element. The format of the Good Time Intervals is either
<parameter name="GoodTimeIntervals" file="..."/>
in case that the information is stored in a FITS file, or
<parameter name="GoodTimeIntervals" tmin="..." tmax="..."/>
if the Good Time Intervals should be constructed from a start and stop time (the units of the tmin and tmax parameters are seconds). In the latter case, the method also expects that the time reference is provided as parameter in the xml
element.
Definition at line 853 of file GGti.cpp.
References append(), GXmlElement::attribute(), clear(), G_READ_XML, GXmlElement::has_attribute(), load(), m_reference, m_xml_filename, GTimeReference::read(), gammalib::todouble(), and gammalib::xml_get_par().
Reduce Good Time Intervals to specified interval.
[in] | tstart | Start time of interval. |
[in] | tstop | Stop time of interval. |
GException::invalid_argument | Start time is later than stop time |
Reduces the Good Time Intervals to the specified interval. Reducing means that all Good Time Intervals are dropped that fall outside the specified interval [tstart
, tstop
], and Good Time Intervals will be limited to >tstart
and <=tstop
in case that their boundaries are outside [tstart
, tstop
].
Definition at line 401 of file GGti.cpp.
References clear(), G_REDUCE, m_num, m_start, m_stop, NORMAL, GTime::print(), set_attributes(), tstart(), and tstop().
Referenced by GCOMDri::compute_dre(), and GCOMTim::reduce().
void GGti::reduce | ( | const GGti & | gti | ) |
Reduce Good Time Intervals to specified intervals.
[in] | gti | Good Time Intervals. |
Reduces the Good Time Intervals to the specified intervals. Reducing means that the resulting Good Time Intervals are the intersection between the initial Good Time Intervals and the specified Good Time Intervals.
Specifically, all Good Time Intervals are dropped that do not overlap with one of the specified intervals, and overlapping intervals will be reduced to the overlapping time intervals, eventually splitting a Good Time Interval into several overlapping intervals.
Definition at line 481 of file GGti.cpp.
References clear(), m_num, m_start, m_stop, set_attributes(), size(), tstart(), and tstop().
|
inline |
Set time reference for Good Time Intervals.
[in] | ref | Time reference. |
Sets the time reference of the Good Time Intervals. This defines the reference time which will be writted into the FITS file upon saving of the Good Time Intervals.
Definition at line 257 of file GGti.hpp.
References m_reference.
Referenced by GCTACubeExposure::fill_cube(), GCTACubeExposure::init_members(), GCTAEventCube::init_members(), GCTAEventList::init_members(), GLATEventList::read(), GCTAEventList::read(), GLATEventList::read_events(), GCTAEventList::read_events(), GCTACubeExposure::write_attributes(), GCOMDri::write_attributes(), and GCTAEventList::write_events().
|
inline |
Return time reference for Good Time Intervals.
Returns the time reference of the Good Time Intervals.
Definition at line 275 of file GGti.hpp.
References m_reference.
|
virtual |
Remove Good Time Interval.
[in] | index | Good Time Interval index [0,...,size()[. |
Removes Good Time Interval at index
from the container. All intervals after the specified index
are moved forward by one position.
Note that the method does not actually reduce the memory size but just updates the information on the number of elements in the array.
Implements GContainer.
Definition at line 587 of file GGti.cpp.
References G_REMOVE, m_num, m_start, m_stop, and set_attributes().
|
inlinevirtual |
Reserve space for Good Time Intervals.
[in] | num | Number of elements. |
This method does nothing (it is needed to satisfy the GContainer interface).
Implements GContainer.
void GGti::save | ( | const GFilename & | filename, |
const bool & | clobber = false |
||
) | const |
Save Good Time Intervals into FITS file.
[in] | filename | FITS filename. |
[in] | clobber | Overwrite an existing Good Time Interval extension? |
Saves Good Time Intervals into a FITS file. If a file with the given filename
does not yet exist it will be created, otherwise the method opens the existing file. Good Time Intervals can only be appended to an existing file if the clobber
flag is set to true
(otherwise an exception is thrown).
The method will append a binary FITS table containing the Good Time Intervals to the FITS file. The extension name can be specified as part of the filename
. For example the filename
myfile.fits[GOOD TIME INTERVALS]
will save the Good Time Intervals in the GOOD TIME INTERVALS
extension of the myfile.fits
file. If the extension exists already in the file it will be replaced, otherwise a new extension will be created. If no extension name is provided, the method will use GTI
as the default extension name for Good Time Intervals.
Definition at line 727 of file GGti.cpp.
References GFilename::extname(), gammalib::extname_gti, GFilename::url(), and write().
Referenced by write().
|
protected |
Set class attributes.
Compute the following class attributes:
m_tstart - Earliest start time of GTIs m_stop - Latest stop time of GTIs m_telapse - Latest stop time minus earliest start time of GTIs [sec] m_ontime - Sum of all intervals [sec]
Definition at line 1254 of file GGti.cpp.
References GTime::clear(), m_num, m_ontime, m_start, m_stop, m_telapse, m_tstart, m_tstop, and GTime::secs().
Referenced by extend(), insert_gti(), merge(), read(), reduce(), and remove().
|
inlinevirtual |
Return number of Good Time Intervals.
Implements GContainer.
Definition at line 154 of file GGti.hpp.
References m_num.
Referenced by GCOMDri::compute_dre(), extend(), GCTAModelIrfBackground::mc(), GCTAModelAeffBackground::mc(), GCTAModelBackground::mc(), GCOMTim::print(), GMWLSpectrum::print(), GCTACubeExposure::print(), GCOMObservation::print(), print(), reduce(), GCOMEventCube::set_times(), GLATEventCube::set_times(), GCTAEventCube::set_times(), GCOMDri::use_superpacket(), and GCOMTim::write().
|
inline |
Returns elapsed time.
Returns the elapsed time in seconds. The elapsed time is defined as the time difference between the latest stop time and the earliest start time in the Good Time Intervals.
Definition at line 224 of file GGti.hpp.
References m_telapse.
Referenced by GCOMTim::print(), print(), and GCTACubeExposure::write_attributes().
|
inline |
Returns earliest start time in Good Time Intervals.
Definition at line 194 of file GGti.hpp.
References m_tstart.
Referenced by GCOMDri::compute_dre(), extend(), insert_gti(), GCTAModelIrfBackground::mc(), GCTAModelAeffBackground::mc(), GCTAModelBackground::mc(), overlap(), GCOMTim::print(), GPulsar::print(), print(), reduce(), GCOMEventCube::set_times(), GLATEventCube::set_times(), GCTAEventCube::set_times(), GEvents::tstart(), GCOMTim::write(), write(), GCTACubeExposure::write_attributes(), and GCOMDri::write_attributes().
const GTime & GGti::tstart | ( | const int & | index | ) | const |
|
inline |
Returns latest stop time in Good Time Intervals.
Definition at line 207 of file GGti.hpp.
References m_tstop.
Referenced by GCOMDri::compute_dre(), extend(), insert_gti(), GCTAModelIrfBackground::mc(), GCTAModelAeffBackground::mc(), GCTAModelBackground::mc(), GCOMTim::print(), GPulsar::print(), print(), reduce(), GCOMEventCube::set_times(), GLATEventCube::set_times(), GCTAEventCube::set_times(), GEvents::tstop(), GCOMTim::write(), write(), GCTACubeExposure::write_attributes(), and GCOMDri::write_attributes().
const GTime & GGti::tstop | ( | const int & | index | ) | const |
void GGti::write | ( | GFits & | fits, |
const std::string & | extname = gammalib::extname_gti |
||
) | const |
Write Good Time Intervals and time reference into FITS object.
[in] | fits | FITS file. |
[in] | extname | GTI extension name. |
Writes Good Time Intervals and time reference into a FITS object. If an extension with the same name does already exist in the FITS object, the values in that extension will be replaced.
The start and stop tims of the Good Time Intervals will be written into double precision columns named START
and STOP
.
Definition at line 796 of file GGti.cpp.
References GFitsTable::append(), GFits::append(), GFits::contains(), GTime::convert(), GFitsHDU::extname(), m_num, m_reference, m_start, m_stop, GFits::remove(), and GTimeReference::write().
Referenced by save(), GLATEventCube::write(), GLATLtCube::write(), GCTAEventCube::write(), GCTACubeExposure::write(), and GCTAEventList::write().
void GGti::write | ( | GXmlElement & | xml | ) | const |
Write Good Time Intervals into XML element.
[in] | xml | XML element. |
Writes Good Time Intervals into an XML element. The format of the Good Time Intervals is
<parameter name="GoodTimeIntervals" file="..."/>
if a file name has been specified previously upon reading from an XML file. In that case, the method will also write the Good Time Intervals to the specified file. If no file name is available, the method will write the first start and the last stop time of the Good Time Intervals in the format
<parameter name="GoodTimeIntervals" tmin="..." tmax="..."/>
The units of the tmin and tmax parameters are seconds. In that case, the time reference is also written into the XML element.
This method does nothing if the Good Time Intervals are empty.
Definition at line 928 of file GGti.cpp.
References GXmlElement::attribute(), G_WRITE_XML, is_empty(), GFilename::is_empty(), m_reference, m_xml_filename, save(), gammalib::str(), tstart(), tstop(), GTimeReference::write(), and gammalib::xml_need_par().
|
mutableprotected |
Last index for containment test.
Definition at line 132 of file GGti.hpp.
Referenced by contains(), copy_members(), and init_members().
|
protected |
Number of Good Time Intervals.
Definition at line 121 of file GGti.hpp.
Referenced by append(), contains(), copy_members(), extend(), init_members(), insert(), insert_gti(), is_empty(), merge(), overlap(), read(), reduce(), remove(), set_attributes(), size(), tstart(), tstop(), and write().
|
protected |
Sum of GTIs durations (in seconds)
Definition at line 124 of file GGti.hpp.
Referenced by copy_members(), init_members(), ontime(), and set_attributes().
|
protected |
Time reference.
Definition at line 128 of file GGti.hpp.
Referenced by copy_members(), extend(), init_members(), read(), reference(), and write().
|
protected |
Array of start times.
Definition at line 126 of file GGti.hpp.
Referenced by contains(), copy_members(), extend(), free_members(), init_members(), insert(), insert_gti(), merge(), overlap(), read(), reduce(), remove(), set_attributes(), tstart(), and write().
|
protected |
Array of stop times.
Definition at line 127 of file GGti.hpp.
Referenced by contains(), copy_members(), extend(), free_members(), init_members(), insert_gti(), merge(), overlap(), read(), reduce(), remove(), set_attributes(), tstop(), and write().
|
protected |
Time between start of first GTI and stop of last GTI (in seconds)
Definition at line 125 of file GGti.hpp.
Referenced by copy_members(), init_members(), set_attributes(), and telapse().
|
protected |
Start time of Good Time Intervals.
Definition at line 122 of file GGti.hpp.
Referenced by copy_members(), init_members(), set_attributes(), and tstart().
|
protected |
Stop time of Good Time Intervals.
Definition at line 123 of file GGti.hpp.
Referenced by copy_members(), init_members(), set_attributes(), and tstop().
|
protected |
XML filename.
Definition at line 129 of file GGti.hpp.
Referenced by copy_members(), init_members(), print(), read(), and write().