GammaLib  1.7.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GGti Class Reference

Good Time Interval class. More...

#include <GGti.hpp>

Inheritance diagram for GGti:
GContainer GBase

Public Member Functions

 GGti (void)
 Void constructor. More...
 
 GGti (const GFilename &filename)
 FITS file constructor. More...
 
 GGti (const GGti &gti)
 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...
 
GGtioperator= (const GGti &gti)
 Assignment operator. More...
 
void clear (void)
 Clear Good Time Intervals. More...
 
GGticlone (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 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 &gti)
 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 GTimetstart (void) const
 Returns earliest start time in Good Time Intervals. More...
 
const GTimetstop (void) const
 Returns latest stop time in Good Time Intervals. More...
 
const GTimetstart (const int &index) const
 Returns start time for a given Good Time Interval. More...
 
const GTimetstop (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 GTimeReferencereference (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 &gti)
 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...
 
GTimem_start
 Array of start times. More...
 
GTimem_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...
 

Detailed Description

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.

Definition at line 62 of file GGti.hpp.

Constructor & Destructor Documentation

GGti::GGti ( void  )

Void constructor.

Constructs empty Good Time Intervals.

Definition at line 68 of file GGti.cpp.

References init_members().

Referenced by clone().

GGti::GGti ( const GFilename filename)
explicit

FITS file constructor.

Parameters
[in]filenameFITS 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.

Parameters
[in]gtiGood 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().

GGti::GGti ( const GTime tstart,
const GTime tstop 
)

Single time interval constructor.

Parameters
[in]tstartStart time of interval.
[in]tstopStop 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().

GGti::GGti ( const GXmlElement xml)
explicit

XML element constructor.

Parameters
[in]xmlXML element.

Constructs Good Time Intervals from an XML element.

Definition at line 125 of file GGti.cpp.

References init_members(), and read().

GGti::GGti ( const GTimeReference ref)
explicit

Time reference constructor.

Parameters
[in]refTime 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().

GGti::~GGti ( void  )
virtual

Destructor.

Definition at line 185 of file GGti.cpp.

References free_members().

Member Function Documentation

void GGti::append ( const GTime tstart,
const GTime tstop 
)

Append Good Time Interval.

Parameters
[in]tstartStart time of interval.
[in]tstopStop 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(), GCOMTim::read(), GCTAEventList::read(), and read().

std::string GGti::classname ( void  ) const
inlinevirtual

Return class name.

Returns
String containing the class name ("GGti").

Implements GBase.

Definition at line 141 of file GGti.hpp.

void GGti::clear ( void  )
virtual
GGti * GGti::clone ( void  ) const
virtual

Clone Good Time Intervals.

Returns
Pointer to deep copy of Good Time Intervals.

Implements GBase.

Definition at line 255 of file GGti.cpp.

References GGti().

bool GGti::contains ( const GTime time) const

Checks whether Good Time Intervals contains time.

Parameters
[in]timeTime 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 952 of file GGti.cpp.

References m_last_index, m_num, m_start, and m_stop.

Referenced by GCOMTim::contains(), and GCOMDri::use_superpacket().

void GGti::copy_members ( const GGti gti)
protected

Copy class members.

Parameters
[in]gtiGood Time Intervals.

Definition at line 1079 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.

Parameters
[in]gtiGood 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 511 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().

void GGti::free_members ( void  )
protected

Delete class members.

Definition at line 1111 of file GGti.cpp.

References m_start, and m_stop.

Referenced by clear(), operator=(), and ~GGti().

void GGti::init_members ( void  )
protected

Initialise class members.

Definition at line 1050 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=().

void GGti::insert ( const GTime tstart,
const GTime tstop 
)

Insert Good Time Interval.

Parameters
[in]tstartStart time of interval.
[in]tstopStop 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.

void GGti::insert_gti ( const int &  index,
const GTime tstart,
const GTime tstop 
)
protected

Insert Good Time Interval.

Parameters
[in]indexIndex after which interval is inserted.
[in]tstartStart time of interval.
[in]tstopStop time of interval.
Exceptions
GException::invalid_argumentStart time later than stop time

Inserts a Good Time Interval after 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 1186 of file GGti.cpp.

References G_INSERT_GTI, m_num, m_start, m_stop, NORMAL, GTime::print(), set_attributes(), tstart(), and tstop().

Referenced by append(), insert(), and merge().

bool GGti::is_empty ( void  ) const
inlinevirtual

Signal if there are no Good Time Intervals.

Returns
True if there are no Good Time Intervals.

Implements GContainer.

Definition at line 165 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.

Parameters
[in]filenameFITS 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 570 of file GGti.cpp.

References GFits::close(), GFilename::extname(), gammalib::extname_gti, read(), and GFits::table().

Referenced by GGti(), and read().

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, and m_stop.

Referenced by merge().

void GGti::merge ( const GTime tstart,
const GTime tstop 
)

Merge Good Time Interval into container.

Parameters
[in]tstartStart time of interval.
[in]tstopStop 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 362 of file GGti.cpp.

References insert_gti(), m_num, m_start, and merge().

const double & GGti::ontime ( void  ) const
inline

Returns ontime.

Returns
Ontime (seconds).

Returns the ontime in seconds. The ontime is defined as the sum of all Good Time Intervals.

Definition at line 239 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().

GGti & GGti::operator= ( const GGti gti)

Assignment operator.

Parameters
[in]gtiGood Time Intervals.
Returns
Good Time Intervals.

Definition at line 207 of file GGti.cpp.

References copy_members(), free_members(), and init_members().

double GGti::overlap ( const GTime tstart,
const GTime tstop 
) const

Computes overlap of time interval with GTIs.

Parameters
[in]tstartStart time of interval.
[in]tstopStop time of interval.
Returns
Overlap (seconds).

Returns the overlap of time interval with GTIs in seconds.

Definition at line 907 of file GGti.cpp.

References m_num, m_start, m_stop, and tstart().

std::string GGti::print ( const GChatter chatter = NORMAL) const
virtual

Print Good Time Intervals.

Parameters
[in]chatterChattiness.
Returns
String containing Good Time Interval information.

Implements GBase.

Definition at line 988 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.

Parameters
[in]tableFITS 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 639 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.

Parameters
[in]xmlXML element.
Exceptions
GException::invalid_valueInvalid 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 739 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().

void GGti::reduce ( const GTime tstart,
const GTime tstop 
)

Reduce Good Time Intervals to specified interval.

Parameters
[in]tstartStart time of interval.
[in]tstopStop time of interval.
Exceptions
GException::invalid_argumentStart 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 398 of file GGti.cpp.

References clear(), G_REDUCE, m_num, m_start, m_stop, NORMAL, GTime::print(), set_attributes(), tstart(), and tstop().

void GGti::reference ( const GTimeReference ref)
inline

Set time reference for Good Time Intervals.

Parameters
[in]refTime 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 256 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().

const GTimeReference & GGti::reference ( void  ) const
inline

Return time reference for Good Time Intervals.

Returns
Time reference.

Returns the time reference of the Good Time Intervals.

Definition at line 274 of file GGti.hpp.

References m_reference.

Referenced by GGti(), and print().

void GGti::remove ( const int &  index)
virtual

Remove Good Time Interval.

Parameters
[in]indexGood Time Interval index (0,...,size()-1).

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 475 of file GGti.cpp.

References G_REMOVE, m_num, m_start, m_stop, and set_attributes().

void GGti::reserve ( const int &  num)
inlinevirtual

Reserve space for Good Time Intervals.

Parameters
[in]numNumber of elements.

This method does nothing (it is needed to satisfy the GContainer interface).

Implements GContainer.

Definition at line 180 of file GGti.hpp.

void GGti::save ( const GFilename filename,
const bool &  clobber = false 
) const

Save Good Time Intervals into FITS file.

Parameters
[in]filenameFITS filename.
[in]clobberOverwrite 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 613 of file GGti.cpp.

References GFilename::extname(), gammalib::extname_gti, GFilename::url(), and write().

Referenced by write().

void GGti::set_attributes ( void  )
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 1136 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(), read(), reduce(), and remove().

const double & GGti::telapse ( void  ) const
inline

Returns elapsed time.

Returns
Elapsed time (seconds).

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 223 of file GGti.hpp.

References m_telapse.

Referenced by GCOMTim::print(), print(), and GCTACubeExposure::write_attributes().

const GTime & GGti::tstart ( void  ) const
inline
const GTime & GGti::tstart ( const int &  index) const

Returns start time for a given Good Time Interval.

Parameters
[in]indexGood Time Interval index (0,...,size()-1).
Exceptions
GException::out_of_rangeSpecified index is out of range.

Definition at line 862 of file GGti.cpp.

References G_TSTART, m_num, and m_start.

const GTime & GGti::tstop ( const int &  index) const

Returns stop time for a given Good Time Interval.

Parameters
[in]indexGood Time Interval index (0,...,size()-1).
Exceptions
GException::out_of_rangeSpecified index is out of range.

Definition at line 884 of file GGti.cpp.

References G_TSTOP, m_num, and m_stop.

void GGti::write ( GFits fits,
const std::string &  extname = gammalib::extname_gti 
) const

Write Good Time Intervals and time reference into FITS object.

Parameters
[in]fitsFITS file.
[in]extnameGTI 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 682 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.

Parameters
[in]xmlXML 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 814 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().

Member Data Documentation

int GGti::m_last_index
mutableprotected

Last index for containment test.

Definition at line 131 of file GGti.hpp.

Referenced by contains(), copy_members(), and init_members().

int GGti::m_num
protected
double GGti::m_ontime
protected

Sum of GTIs durations (in seconds)

Definition at line 123 of file GGti.hpp.

Referenced by copy_members(), init_members(), ontime(), and set_attributes().

GTimeReference GGti::m_reference
protected

Time reference.

Definition at line 127 of file GGti.hpp.

Referenced by copy_members(), extend(), init_members(), read(), reference(), and write().

GTime* GGti::m_start
protected
GTime* GGti::m_stop
protected
double GGti::m_telapse
protected

Time between start of first GTI and stop of last GTI (in seconds)

Definition at line 124 of file GGti.hpp.

Referenced by copy_members(), init_members(), set_attributes(), and telapse().

GTime GGti::m_tstart
protected

Start time of Good Time Intervals.

Definition at line 121 of file GGti.hpp.

Referenced by copy_members(), init_members(), set_attributes(), and tstart().

GTime GGti::m_tstop
protected

Stop time of Good Time Intervals.

Definition at line 122 of file GGti.hpp.

Referenced by copy_members(), init_members(), set_attributes(), and tstop().

GFilename GGti::m_xml_filename
protected

XML filename.

Definition at line 128 of file GGti.hpp.

Referenced by copy_members(), init_members(), print(), read(), and write().


The documentation for this class was generated from the following files: