diff --git a/inst/lat/src/GLATEventList.cpp b/inst/lat/src/GLATEventList.cpp index e1c0b55..f97155e 100644 --- a/inst/lat/src/GLATEventList.cpp +++ b/inst/lat/src/GLATEventList.cpp @@ -73,7 +73,7 @@ GLATEventList::GLATEventList(void) : GEventList() /***********************************************************************//** * @brief File name constructor * - * @param[in] filename Counts cube filename. + * @param[in] filename Event list filename. * * Construct event list object by loading the events from a FITS file. ***************************************************************************/ diff --git a/src/template/GXXXEventAtom.cpp b/src/template/GXXXEventAtom.cpp new file mode 100644 index 0000000..6fb8184 --- /dev/null +++ b/src/template/GXXXEventAtom.cpp @@ -0,0 +1,243 @@ +/*************************************************************************** + * GXXXEventAtom.cpp - [INSTRUMENT] event atom class * + * ----------------------------------------------------------------------- * + * copyright (C) [YEAR] by [AUTHOR] * + * ----------------------------------------------------------------------- * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + * * + ***************************************************************************/ +/** + * @file GXXXEventAtom.cpp + * @brief [INSTRUMENT] event atom class implementation + * @author [AUTHOR] + */ + +/* __ Includes ___________________________________________________________ */ +#ifdef HAVE_CONFIG_H +#include +#endif +#include +#include "GXXXEventAtom.hpp" +//#include "GTools.hpp" + +/* __ Method name definitions ____________________________________________ */ + +/* __ Macros _____________________________________________________________ */ + +/* __ Coding definitions _________________________________________________ */ + +/* __ Debug definitions __________________________________________________ */ + + +/*========================================================================== + = = + = Constructors/destructors = + = = + ==========================================================================*/ + +/***********************************************************************//** + * @brief Void constructor + * + * Creates an empty [INSTRUMENT] event atom. + ***************************************************************************/ +GXXXEventAtom::GXXXEventAtom(void) : GEventAtom() +{ + // Initialise class members for clean destruction + init_members(); + + // Return + return; +} + + +/***********************************************************************//** + * @brief Copy constructor + * + * @param[in] atom [INSTRUMENT] event atom. + ***************************************************************************/ +GXXXEventAtom::GXXXEventAtom(const GXXXEventAtom& atom) : GEventAtom(atom) +{ + // Initialise class members for clean destruction + init_members(); + + // Copy members + copy_members(atom); + + // Return + return; +} + + +/***********************************************************************//** + * @brief Destructor + ***************************************************************************/ +GXXXEventAtom::~GXXXEventAtom(void) +{ + // Free members + free_members(); + + // Return + return; +} + + +/*========================================================================== + = = + = Operators = + = = + ==========================================================================*/ + +/***********************************************************************//** + * @brief Assignment operator + * + * @param[in] atom [INSTRUMENT] event atom. + * @return [INSTRUMENT] event atom. + ***************************************************************************/ +GXXXEventAtom& GXXXEventAtom::operator=(const GXXXEventAtom& atom) +{ + // Execute only if object is not identical + if (this != &atom) { + + // Copy base class members + this->GEventAtom::operator=(atom); + + // Free members + free_members(); + + // Initialise private members for clean destruction + init_members(); + + // Copy members + copy_members(atom); + + } // endif: object was not identical + + // Return this object + return *this; +} + + +/*========================================================================== + = = + = Public methods = + = = + ==========================================================================*/ + +/***********************************************************************//** + * @brief Clear event atom + * + * Clears [INSTRUMENT] event atom by resetting all class members to an + * initial state. Any information that was present before will be lost. + ***************************************************************************/ +void GXXXEventAtom::clear(void) +{ + // Free class members (base and derived classes, derived class first) + free_members(); + this->GEventAtom::free_members(); + this->GEvent::free_members(); + + // Initialise members + this->GEvent::init_members(); + this->GEventAtom::init_members(); + init_members(); + + // Return + return; +} + + +/***********************************************************************//** + * @brief Clone event atom + * + * @return Pointer to deep copy of [INSTRUMENT] event atom. + ***************************************************************************/ +GXXXEventAtom* GXXXEventAtom::clone(void) const +{ + return new GXXXEventAtom(*this); +} + + +/***********************************************************************//** + * @brief Print event information + * + * @param[in] chatter Chattiness. + * @return String containing event information. + ***************************************************************************/ +std::string GXXXEventAtom::print(const GChatter& chatter) const +{ + // Initialise result string + std::string result; + + // Continue only if chatter is not silent + if (chatter != SILENT) { + + // Append event attributes + result.append("Dir="+m_dir.print(chatter)); + result.append(" Energy="+m_energy.print(chatter)); + result.append(" Time="+m_time.print(chatter)); + + } // endif: chatter was not silent + + // Return result + return result; +} + + +/*========================================================================== + = = + = Private methods = + = = + ==========================================================================*/ + +/***********************************************************************//** + * @brief Initialise class members + ***************************************************************************/ +void GXXXEventAtom::init_members(void) +{ + // Initialise members + m_dir.clear(); + m_time.clear(); + m_energy.clear(); + + // Return + return; +} + + +/***********************************************************************//** + * @brief Copy class members + * + * @param[in] atom [INSTRUMENT] event atom. + ***************************************************************************/ +void GXXXEventAtom::copy_members(const GXXXEventAtom& atom) +{ + // Copy members + m_dir = atom.m_dir; + m_time = atom.m_time; + m_energy = atom.m_energy; + + // Return + return; +} + + +/***********************************************************************//** + * @brief Delete class members + ***************************************************************************/ +void GXXXEventAtom::free_members(void) +{ + // Return + return; +} diff --git a/src/template/GXXXEventAtom.hpp b/src/template/GXXXEventAtom.hpp new file mode 100644 index 0000000..e343e5f --- /dev/null +++ b/src/template/GXXXEventAtom.hpp @@ -0,0 +1,137 @@ +/*************************************************************************** + * GXXXEventAtom.hpp - [INSTRUMENT] event atom class * + * ----------------------------------------------------------------------- * + * copyright (C) [YEAR] by [AUTHOR] * + * ----------------------------------------------------------------------- * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + * * + ***************************************************************************/ +/** + * @file GXXXEventAtom.hpp + * @brief [INSTRUMENT] event atom class definition + * @author [AUTHOR] + */ + +#ifndef GXXXEVENTATOM_HPP +#define GXXXEVENTATOM_HPP + +/* __ Includes ___________________________________________________________ */ +#include +#include "GEventAtom.hpp" +#include "GEnergy.hpp" +#include "GTime.hpp" +#include "GXXXInstDir.hpp" + +/* __ Forward declarations _______________________________________________ */ + + +/***********************************************************************//** + * @class GXXXEventAtom + * + * @brief [INSTRUMENT] event atom class + ***************************************************************************/ +class GXXXEventAtom : public GEventAtom { + + // Friend classes + //friend class GXXXEventList; + +public: + // Constructors and destructors + GXXXEventAtom(void); + GXXXEventAtom(const GXXXEventAtom& atom); + virtual ~GXXXEventAtom(void); + + // Operators + GXXXEventAtom& operator=(const GXXXEventAtom& atom); + + // Implemented pure virtual base class methods + void clear(void); + GXXXEventAtom* clone(void) const; + std::string classname(void) const; + const GXXXInstDir& dir(void) const; + const GEnergy& energy(void) const; + const GTime& time(void) const; + std::string print(const GChatter& chatter = NORMAL) const; + +protected: + // Protected methods + void init_members(void); + void copy_members(const GXXXEventAtom& atom); + void free_members(void); + + // Protected members + GXXXInstDir m_dir; //!< Event direction + GEnergy m_energy; //!< Event energy + GTime m_time; //!< Event time +}; + + +/***********************************************************************//** + * @brief Return class name + * + * @return String containing the class name ("GXXXEventAtom"). + ***************************************************************************/ +inline +std::string GXXXEventAtom::classname(void) const +{ + return ("GXXXEventAtom"); +} + + +/***********************************************************************//** + * @brief Return event instrument direction + * + * @return Event instrument direction. + * + * Returns the direction of the event. + * + * @todo Specify what actually an event direction is. You instrument may + * not be an imaging instrument. + ***************************************************************************/ +inline +const GXXXInstDir& GXXXEventAtom::dir(void) const +{ + return m_dir; +} + + +/***********************************************************************//** + * @brief Return event energy + * + * @return Event energy. + * + * Returns the reconstructed energy of the photon on the sky. + ***************************************************************************/ +inline +const GEnergy& GXXXEventAtom::energy(void) const +{ + return m_energy; +} + + +/***********************************************************************//** + * @brief Return event time + * + * @return Event time. + * + * Returns the event triggering time. + ***************************************************************************/ +inline +const GTime& GXXXEventAtom::time(void) const +{ + return m_time; +} + +#endif /* GXXXEVENTATOM_HPP */ diff --git a/src/template/GXXXEventAtom.i b/src/template/GXXXEventAtom.i new file mode 100644 index 0000000..ef15e61 --- /dev/null +++ b/src/template/GXXXEventAtom.i @@ -0,0 +1,62 @@ +/*************************************************************************** + * GXXXEventAtom.i - [INSTRUMENT] event atom class * + * ----------------------------------------------------------------------- * + * copyright (C) [YEAR] by [AUTHOR] * + * ----------------------------------------------------------------------- * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + * * + ***************************************************************************/ +/** + * @file GXXXEventAtom.i + * @brief [INSTRUMENT] event atom class definition + * @author [AUTHOR] + */ +%{ +/* Put headers and other declarations here that are needed for compilation */ +#include "GXXXEventAtom.hpp" +%} + + +/***********************************************************************//** + * @class GXXXEventAtom + * + * @brief [INSTRUMENT] event atom class + ***************************************************************************/ +class GXXXEventAtom : public GEventAtom { + +public: + // Constructors and destructors + GXXXEventAtom(void); + GXXXEventAtom(const GXXXEventAtom& atom); + virtual ~GXXXEventAtom(void); + + // Implemented pure virtual base class methods + void clear(void); + GXXXEventAtom* clone(void) const; + std::string classname(void) const; + const GXXXInstDir& dir(void) const; + const GEnergy& energy(void) const; + const GTime& time(void) const; +}; + + +/***********************************************************************//** + * @brief GXXXEventAtom class extension + ***************************************************************************/ +%extend GXXXEventAtom { + GXXXEventAtom copy() { + return (*self); + } +}; diff --git a/src/template/GXXXEventList.cpp b/src/template/GXXXEventList.cpp new file mode 100644 index 0000000..2080ca3 --- /dev/null +++ b/src/template/GXXXEventList.cpp @@ -0,0 +1,489 @@ +/*************************************************************************** + * GXXXEventList.cpp - [INSTRUMENT] event list class * + * ----------------------------------------------------------------------- * + * copyright (C) [YEAR] by [AUTHOR] * + * ----------------------------------------------------------------------- * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + * * + ***************************************************************************/ +/** + * @file GXXXEventList.hpp + * @brief [INSTRUMENT] event list class implementation + * @author [AUTHOR] + */ + +/* __ Includes ___________________________________________________________ */ +#ifdef HAVE_CONFIG_H +#include +#endif +#include "GFits.hpp" +#include "GException.hpp" +#include "GXXXEventList.hpp" + +/* __ Method name definitions ____________________________________________ */ +#define G_OPERATOR "GXXXEventList::operator[](int&)" +#define G_ROI "GXXXEventList::roi(GRoi&)" + +/* __ Macros _____________________________________________________________ */ + +/* __ Coding definitions _________________________________________________ */ + +/* __ Debug definitions __________________________________________________ */ + + +/*========================================================================== + = = + = Constructors/destructors = + = = + ==========================================================================*/ + +/***********************************************************************//** + * @brief Void constructor + * + * Creates an empty [INSTRUMENT] event list. + ***************************************************************************/ +GXXXEventList::GXXXEventList(void) : GEventList() +{ + // Initialise class members for clean destruction + init_members(); + + // Return + return; +} + + +/***********************************************************************//** + * @brief File name constructor + * + * @param[in] filename [INSTRUMENT] event list filename. + * + * Construct [INSTRUMENT] event list object by loading the events from a + * FITS file. + ***************************************************************************/ +GXXXEventList::GXXXEventList(const GFilename& filename) : GEventList() +{ + // Initialise members + init_members(); + + // Load event list + load(filename); + + // Return + return; +} + + +/***********************************************************************//** + * @brief Copy constructor + * + * @param[in] list [INSTRUMENT] event list. + ***************************************************************************/ +GXXXEventList::GXXXEventList(const GXXXEventList& list) : GEventList(list) +{ + // Initialise members + init_members(); + + // Copy members + copy_members(list); + + // Return + return; +} + + +/***********************************************************************//** + * @brief Destructor + ***************************************************************************/ +GXXXEventList::~GXXXEventList(void) +{ + // Free members + free_members(); + + // Return + return; +} + + +/*========================================================================== + = = + = Operators = + = = + ==========================================================================*/ + +/***********************************************************************//** + * @brief Assignment operator + * + * @param[in] list [INSTRUMENT] event list. + * @return [INSTRUMENT] event list. + ***************************************************************************/ +GXXXEventList& GXXXEventList::operator=(const GXXXEventList& list) +{ + // Execute only if object is not identical + if (this != &list) { + + // Copy base class members + this->GEventList::operator=(list); + + // Free members + free_members(); + + // Initialise members + init_members(); + + // Copy members + copy_members(list); + + } // endif: object was not identical + + // Return this object + return *this; +} + + +/***********************************************************************//** + * @brief [INSTRUMENT] event atom access operator + * + * @param[in] index Event index [0,...,size()-1]. + * @return Pointer to [INSTRUMENT] event atom. + * + * @exception GException::out_of_range + * Event index outside valid range. + * + * Returns pointer to a [INSTRUMENT] event atom. + ***************************************************************************/ +GXXXEventAtom* GXXXEventList::operator[](const int& index) +{ + // Optionally check if the index is valid + #if defined(G_RANGE_CHECK) + if (index < 0 || index >= size()) { + throw GException::out_of_range(G_OPERATOR, "Event index", index, size()); + } + #endif + + // Return pointer + return (&(m_events[index])); +} + + +/***********************************************************************//** + * @brief [INSTRUMENT] event atom access operator + * + * @param[in] index Event index [0,...,size()-1]. + * @return Pointer to [INSTRUMENT] event atom. + * + * @exception GException::out_of_range + * Event index outside valid range. + * + * Returns pointer to a [INSTRUMENT] event atom. + ***************************************************************************/ +const GXXXEventAtom* GXXXEventList::operator[](const int& index) const +{ + // Optionally check if the index is valid + #if defined(G_RANGE_CHECK) + if (index < 0 || index >= size()) { + throw GException::out_of_range(G_OPERATOR, "Event index", index, size()); + } + #endif + + // Return pointer + return (&(m_events[index])); +} + + +/*========================================================================== + = = + = Public methods = + = = + ==========================================================================*/ + +/***********************************************************************//** + * @brief Clear [INSTRUMENT] event list + * + * Clears [INSTRUMENT] event list by resetting all class members to an + * initial state. Any information that was present before will be lost. + ***************************************************************************/ +void GXXXEventList::clear(void) +{ + // Free class members (base and derived classes, derived class first) + free_members(); + this->GEventList::free_members(); + this->GEvents::free_members(); + + // Initialise members + this->GEvents::init_members(); + this->GEventList::init_members(); + init_members(); + + // Return + return; +} + + +/***********************************************************************//** + * @brief Clone event list + * + * @return Pointer to deep copy of [INSTRUMENT] event list. + ***************************************************************************/ +GXXXEventList* GXXXEventList::clone(void) const +{ + return new GXXXEventList(*this); +} + + +/***********************************************************************//** + * @brief Load [INSTRUMENT] events from FITS file + * + * @param[in] filename [INSTRUMENT] event list FITS file name. + * + * Loads [INSTRUMENT] events from a FITS file into the event list. + ***************************************************************************/ +void GXXXEventList::load(const GFilename& filename) +{ + // Open FITS file + GFits fits(filename); + + // Read event list from FITS file + read(fits); + + // Close FITS file + fits.close(); + + // Return + return; +} + + +/***********************************************************************//** + * @brief Save [INSTRUMENT] events + * + * @param[in] filename [INSTRUMENT] event list FITS file name. + * @param[in] clobber Overwrite existing FITS file? + * + * Save [INSTRUMENT] events from a FITS file into the event list. + ***************************************************************************/ +void GXXXEventList::save(const GFilename& filename, + const bool& clobber) const +{ + // Open FITS file + GFits fits; + + // Write events + write(fits); + + // Save events + fits.saveto(filename, clobber); + + // Close FITS file + fits.close(); + + // Return + return; +} + + +/***********************************************************************//** + * @brief Read [INSTRUMENT] events from FITS file. + * + * @param[in] file FITS file. + * + * Read the [INSTRUMENT] event list from a FITS file object. + * + * @todo Implement method. + ***************************************************************************/ +void GXXXEventList::read(const GFits& file) +{ + // Clear object + clear(); + + // TODO: You need to implement an interface to the FITS file that stores + // your events. Make sure that you read all relevant information. + + // Return + return; +} + + +/***********************************************************************//** + * @brief Write [INSTRUMENT] event list into FITS file. + * + * @param[in] file FITS file. + * + * Write the L[INSTRUMENT]AT event list into FITS file. + * + * @todo Implement method. + ***************************************************************************/ +void GXXXEventList::write(GFits& file) const +{ + // TODO: You need to implement an interface to the FITS file that so + // that you can save your events. + + // Return + return; +} + + +/***********************************************************************//** + * @brief Set region of interest + * + * @param[in] roi Region of interest. + * + * @exception GException::invalid_argument + * Specified RoI is not a [INSTRUMENT] RoI. + * + * Sets the region of interest for the observation. + ***************************************************************************/ +void GXXXEventList::roi(const GRoi& roi) +{ + // Get pointer on [INSTRUMENT] region of interest + const GXXXRoi* xxxroi = dynamic_cast(&roi); + if (xxxroi == NULL) { + std::string cls = std::string(typeid(&roi).name()); + std::string msg = "Region of interest of type \""+cls+"\" is " + "not a [INSTRUMENT] RoI. Please specify a " + "[INSTRUMENT] RoI as argument."; + throw GException::invalid_argument(G_ROI, msg); + } + + // Set RoI + m_roi = *xxxroi; + + // Return + return; +} + + +/***********************************************************************//** + * @brief Append event to event list + * + * @param[in] event Event. + * + * Appends an event to the end of the event list. + ***************************************************************************/ +void GXXXEventList::append(const GXXXEventAtom& event) +{ + // Append event + m_events.push_back(event); + + // Return + return; +} + + +/***********************************************************************//** + * @brief Remove events from event list + * + * @param[in] index Index from which on events should be removed. + * @param[in] number Number of event to remove (default: 1). + * + * Removes events from the event list. This method does nothing if @p index + * points beyond the event list. The method does also gently accept + * @p number arguments where @p index + @p number reach beyond the event + * list. In that case, all events from event @p index on will be removed. + ***************************************************************************/ +void GXXXEventList::remove(const int& index, const int& number) +{ + // Continue only if index is valid + if (index < size()) { + + // Determine number of elements to remove + int n_remove = (index + number > size()) ? size() - index : number; + + // Remove events + m_events.erase(m_events.begin() + index, + m_events.begin() + index + n_remove); + + } // endif: index was valid + + // Return + return; +} + + +/***********************************************************************//** + * @brief Print [INSTRUMENT] event list information + * + * @param[in] chatter Chattiness. + * @return String containing [INSTRUMENT] event list information. + ***************************************************************************/ +std::string GXXXEventList::print(const GChatter& chatter) const +{ + // Initialise result string + std::string result; + + // Continue only if chatter is not silent + if (chatter != SILENT) { + + // Append header + result.append("=== GXXXEventList ==="); + + // Append information + result.append("\n"+gammalib::parformat("Number of events") + + gammalib::str(number())); + + // Append additional information + // TODO: Add code to append any additional information that might + // be relevant. + + } // endif: chatter was not silent + + // Return result + return result; +} + + +/*========================================================================== + = = + = Private methods = + = = + ==========================================================================*/ + +/***********************************************************************//** + * @brief Initialise class members + ***************************************************************************/ +void GXXXEventList::init_members(void) +{ + // Initialise members + m_roi.clear(); + m_events.clear(); + + // Return + return; +} + + +/***********************************************************************//** + * @brief Copy class members + * + * @param[in] list [INSTRUMENT] event list. + ***************************************************************************/ +void GXXXEventList::copy_members(const GXXXEventList& list) +{ + // Copy members + m_roi = list.m_roi; + m_events = list.m_events; + + // Return + return; +} + + +/***********************************************************************//** + * @brief Delete class members + ***************************************************************************/ +void GXXXEventList::free_members(void) +{ + // Return + return; +} diff --git a/src/template/GXXXEventList.hpp b/src/template/GXXXEventList.hpp new file mode 100644 index 0000000..456a0c7 --- /dev/null +++ b/src/template/GXXXEventList.hpp @@ -0,0 +1,184 @@ +/*************************************************************************** + * GXXXEventList.hpp - [INSTRUMENT] event list class * + * ----------------------------------------------------------------------- * + * copyright (C) [YEAR] by [AUTHOR] * + * ----------------------------------------------------------------------- * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + * * + ***************************************************************************/ +/** + * @file GXXXEventList.hpp + * @brief [INSTRUMENT] event list class definition + * @author [AUTHOR] + */ + +#ifndef GXXXEVENTLIST_HPP +#define GXXXEVENTLIST_HPP + +/* __ Includes ___________________________________________________________ */ +#include +#include +#include "GEventList.hpp" +#include "GXXXEventAtom.hpp" +#include "GXXXRoi.hpp" + +/* __ Forward declarations _______________________________________________ */ +class GRoi; +class GFits; +class GFilename; + +/* __ Constants __________________________________________________________ */ + + +/***********************************************************************//** + * @class GXXXEventList + * + * @brief [INSTRUMENT] event list class + ***************************************************************************/ +class GXXXEventList : public GEventList { + +public: + // Constructors and destructors + GXXXEventList(void); + explicit GXXXEventList(const GFilename& filename); + GXXXEventList(const GXXXEventList& list); + virtual ~GXXXEventList(void); + + // Operators + virtual GXXXEventList& operator=(const GXXXEventList& list); + virtual GXXXEventAtom* operator[](const int& index); + virtual const GXXXEventAtom* operator[](const int& index) const; + + // Implemented pure virtual base class methods + virtual void clear(void); + virtual GXXXEventList* clone(void) const; + virtual std::string classname(void) const; + virtual int size(void) const; + virtual void load(const GFilename& filename); + virtual void save(const GFilename& filename, + const bool& clobber = false) const; + virtual void read(const GFits& file); + virtual void write(GFits& file) const; + virtual int number(void) const; + virtual void roi(const GRoi& roi); + virtual const GXXXRoi& roi(void) const; + virtual std::string print(const GChatter& chatter = NORMAL) const; + + // Other methods + void append(const GXXXEventAtom& event); + void reserve(const int& number); + void remove(const int& index, const int& number = 1); + +protected: + // Protected methods + void init_members(void); + void copy_members(const GXXXEventList& list); + void free_members(void); + virtual void set_energies(void); + virtual void set_times(void); + + // Protected members + GXXXRoi m_roi; //!< Region of interest + std::vector m_events; //!< Events +}; + + +/***********************************************************************//** + * @brief Return class name + * + * @return String containing the class name ("GXXXEventList"). + ***************************************************************************/ +inline +std::string GXXXEventList::classname(void) const +{ + return ("GXXXEventList"); +} + + +/***********************************************************************//** + * @brief Return number of events in list + * + * @return Number of events in list. + ***************************************************************************/ +inline +int GXXXEventList::size(void) const +{ + return (int)m_events.size(); +} + + +/***********************************************************************//** + * @brief Return number of events in list + * + * @return Number of events in list. + ***************************************************************************/ +inline +int GXXXEventList::number(void) const +{ + return (int)m_events.size(); +} + + +/***********************************************************************//** + * @brief Return Region of Interest + * + * @return Region of Interest. + ***************************************************************************/ +inline +const GXXXRoi& GXXXEventList::roi(void) const +{ + return m_roi; +} + + +/***********************************************************************//** + * @brief Reserves space for events + * + * @param[in] number Number of events. + * + * Reserves space for a @p number events in the event list. + ***************************************************************************/ +inline +void GXXXEventList::reserve(const int& number) +{ + m_events.reserve(number); + return; +} + + +/***********************************************************************//** + * @brief Set energies + * + * Sets energies. + ***************************************************************************/ +inline +void GXXXEventList::set_energies(void) +{ + return; +} + + +/***********************************************************************//** + * @brief Set times + * + * Sets times. + ***************************************************************************/ +inline +void GXXXEventList::set_times(void) +{ + return; +} + +#endif /* GLATEVENTLIST_HPP */ diff --git a/src/template/GXXXEventList.i b/src/template/GXXXEventList.i new file mode 100644 index 0000000..e731da1 --- /dev/null +++ b/src/template/GXXXEventList.i @@ -0,0 +1,132 @@ +/*************************************************************************** + * GXXXEventList.i - [INSTRUMENT] event list class * + * ----------------------------------------------------------------------- * + * copyright (C) [YEAR] by [AUTHOR] * + * ----------------------------------------------------------------------- * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + * * + ***************************************************************************/ +/** + * @file GXXXEventList.i + * @brief [INSTRUMENT] event list class definition + * @author [AUTHOR] + */ +%{ +/* Put headers and other declarations here that are needed for compilation */ +#include "GXXXEventList.hpp" +#include "GTools.hpp" +%} + + +/***********************************************************************//** + * @class GXXXEventList + * + * @brief [INSTRUMENT] event list class + ***************************************************************************/ +class GXXXEventList : public GEventList { + +public: + // Constructors and destructors + GXXXEventList(void); + explicit GXXXEventList(const GFilename& filename); + GXXXEventList(const GXXXEventList& list); + virtual ~GXXXEventList(void); + + // Implemented pure virtual base class methods + virtual void clear(void); + virtual GXXXEventList* clone(void) const; + virtual std::string classname(void) const; + virtual int size(void) const; + virtual void load(const GFilename& filename); + virtual void save(const GFilename& filename, + const bool& clobber = false) const; + virtual void read(const GFits& file); + virtual void write(GFits& file) const; + virtual int number(void) const; + virtual void roi(const GRoi& roi); + virtual const GXXXRoi& roi(void) const; + + // Other methods + void append(const GXXXEventAtom& event); + void reserve(const int& number); + void remove(const int& index, const int& number = 1); +}; + + +/***********************************************************************//** + * @brief GXXXEventList class extension + ***************************************************************************/ +%extend GXXXEventList { + GXXXEventAtom* __getitem__(const int& index) { + // Counting from start, e.g. [2] + if (index >= 0 && index < self->size()) { + return (*self)[index]; + } + // Counting from end, e.g. [-1] + else if (index < 0 && self->size()+index >= 0) { + return (*self)[self->size()+index]; + } + else { + throw GException::out_of_range("__getitem__(int)", "Event index", + index, self->size()); + } + } + GXXXEventList* __getitem__(PyObject *param) { + if (PySlice_Check(param)) { + Py_ssize_t start = 0; + Py_ssize_t stop = 0; + Py_ssize_t step = 0; + Py_ssize_t len = self->size(); + if (PythonSlice_GetIndices(param, len, &start, &stop, &step) == 0) { + GXXXEventList* list = new GXXXEventList; + if (step > 0) { + for (int i = (int)start; i < (int)stop; i += (int)step) { + list->append(*(*self)[i]); + } + } + else { + for (int i = (int)start; i > (int)stop; i += (int)step) { + list->append(*(*self)[i]); + } + } + return list; + } + else { + throw GException::invalid_argument("__getitem__(PyObject)", + "Invalid slice indices"); + } + } + else { + throw GException::invalid_argument("__getitem__(PyObject)",""); + } + } + void __setitem__(const int& index, const GXXXEventAtom& event) { + // Counting from start, e.g. [2] + if (index >= 0 && index < self->size()) { + *(*self)[index] = event; + } + // Counting from end, e.g. [-1] + else if (index < 0 && self->size()+index >= 0) { + *(*self)[self->size()+index] = event; + } + else { + throw GException::out_of_range("__setitem__(int)", "Event index", + index, self->size()); + } + } + GXXXEventList copy() { + return (*self); + } +}; diff --git a/src/template/GXXXInstDir.cpp b/src/template/GXXXInstDir.cpp new file mode 100644 index 0000000..4a5bbb8 --- /dev/null +++ b/src/template/GXXXInstDir.cpp @@ -0,0 +1,230 @@ +/*************************************************************************** + * GXXXInstDir.cpp - [INSTRUMENT] instrument direction class * + * ----------------------------------------------------------------------- * + * copyright (C) [YEAR] by [AUTHOR] * + * ----------------------------------------------------------------------- * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + * * + ***************************************************************************/ +/** + * @file GXXXInstDir.cpp + * @brief [INSTRUMENT] instrument direction class implementation + * @author [AUTHOR] + */ + +/* __ Includes ___________________________________________________________ */ +#ifdef HAVE_CONFIG_H +#include +#endif +#include "GXXXInstDir.hpp" + +/* __ Method name definitions ____________________________________________ */ + +/* __ Macros _____________________________________________________________ */ + +/* __ Coding definitions _________________________________________________ */ + +/* __ Debug definitions __________________________________________________ */ + +/* __ Prototypes _________________________________________________________ */ + +/*========================================================================== + = = + = Constructors/destructors = + = = + ==========================================================================*/ + +/***********************************************************************//** + * @brief Void constructor + * + * Creates an empty [INSTRUMENT] instrument direction. + ***************************************************************************/ +GXXXInstDir::GXXXInstDir(void) : GInstDir() +{ + // Initialise class members + init_members(); + + // Return + return; +} + + +/***********************************************************************//** + * @brief Copy constructor + * + * @param[in] dir [INSTRUMENT] instrument direction. + ***************************************************************************/ +GXXXInstDir::GXXXInstDir(const GXXXInstDir& dir) : GInstDir(dir) +{ + // Initialise class members + init_members(); + + // Copy members + copy_members(dir); + + // Return + return; +} + + +/***********************************************************************//** + * @brief Destructor + ***************************************************************************/ +GXXXInstDir::~GXXXInstDir(void) +{ + // Free members + free_members(); + + // Return + return; +} + + +/*========================================================================== + = = + = Operators = + = = + ==========================================================================*/ + +/***********************************************************************//** + * @brief Assignment operator + * + * @param[in] dir [INSTRUMENT] instrument direction. + * @return [INSTRUMENT] instrument direction. + ***************************************************************************/ +GXXXInstDir& GXXXInstDir::operator=(const GXXXInstDir& dir) +{ + // Execute only if object is not identical + if (this != &dir) { + + // Copy base class members + this->GInstDir::operator=(dir); + + // Free members + free_members(); + + // Initialise private members + init_members(); + + // Copy members + copy_members(dir); + + } // endif: object was not identical + + // Return this object + return *this; +} + + +/*========================================================================== + = = + = Public methods = + = = + ==========================================================================*/ + +/***********************************************************************//** + * @brief Clear [INSTRUMENT] instrument direction + * + * Clears [INSTRUMENT] instrument direction by resetting all class members to + * an initial state. Any information that was present before will be lost. + ***************************************************************************/ +void GXXXInstDir::clear(void) +{ + // Free members + free_members(); + this->GInstDir::free_members(); + + // Initialise private members + this->GInstDir::init_members(); + init_members(); + + // Return + return; +} + + +/***********************************************************************//** + * @brief Clone [INSTRUMENT] instrument direction + * + * @return Pointer to deep copy of [INSTRUMENT] instrument direction. + ***************************************************************************/ +GXXXInstDir* GXXXInstDir::clone(void) const +{ + return new GXXXInstDir(*this); +} + + +/***********************************************************************//** + * @brief Print [INSTRUMENT] instrument direction information + * + * @param[in] chatter Chattiness. + * @return String containing [INSTRUMENT] instrument direction information. + ***************************************************************************/ +std::string GXXXInstDir::print(const GChatter& chatter) const +{ + // Initialise result string + std::string result; + + // Continue only if chatter is not silent + if (chatter != SILENT) { + + // Append instrument direction + // TODO: Add code to append any information that might be relevant. + // Keep the information short, and don't print a header, since you + // may have many events + + } // endif: chatter was not silent + + // Return result + return result; +} + + +/*========================================================================== + = = + = Private methods = + = = + ==========================================================================*/ + +/***********************************************************************//** + * @brief Initialise class members + ***************************************************************************/ +void GXXXInstDir::init_members(void) +{ + // Return + return; +} + + +/***********************************************************************//** + * @brief Copy class members + * + * @param[in] dir [INSTRUMENT] instrument direction. + ***************************************************************************/ +void GXXXInstDir::copy_members(const GXXXInstDir& dir) +{ + // Return + return; +} + + +/***********************************************************************//** + * @brief Delete class members + ***************************************************************************/ +void GXXXInstDir::free_members(void) +{ + // Return + return; +} diff --git a/src/template/GXXXInstDir.hpp b/src/template/GXXXInstDir.hpp new file mode 100644 index 0000000..8465c92 --- /dev/null +++ b/src/template/GXXXInstDir.hpp @@ -0,0 +1,82 @@ +/*************************************************************************** + * GXXXInstDir.hpp - [INSTRUMENT] instrument direction class * + * ----------------------------------------------------------------------- * + * copyright (C) [YEAR] by [AUTHOR] * + * ----------------------------------------------------------------------- * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + * * + ***************************************************************************/ +/** + * @file GXXXInstDir.hpp + * @brief [INSTRUMENT] instrument direction class definition + * @author [AUTHOR] + */ + +#ifndef GXXXINSTDIR_HPP +#define GXXXINSTDIR_HPP + +/* __ Includes ___________________________________________________________ */ +#include +#include "GInstDir.hpp" + + +/***********************************************************************//** + * @class GXXXInstDir + * + * @brief [INSTRUMENT] instrument direction class + * + * The [INSTRUMENT] instrument direction defines the spatial information + * associated to an event. + ***************************************************************************/ +class GXXXInstDir : public GInstDir { + +public: + // Constructors and destructors + GXXXInstDir(void); + GXXXInstDir(const GXXXInstDir& dir); + virtual ~GXXXInstDir(void); + + // Operators + GXXXInstDir& operator=(const GXXXInstDir& dir); + + // Implemented pure virtual base class methods + virtual void clear(void); + virtual GXXXInstDir* clone(void) const; + virtual std::string classname(void) const; + virtual std::string print(const GChatter& chatter = NORMAL) const; + + // Other methods + // TODO: Add any further methods that are needed + +protected: + // Protected methods + void init_members(void); + void copy_members(const GXXXInstDir& dir); + void free_members(void); +}; + + +/***********************************************************************//** + * @brief Return class name + * + * @return String containing the class name ("GXXXInstDir"). + ***************************************************************************/ +inline +std::string GXXXInstDir::classname(void) const +{ + return ("GXXXInstDir"); +} + +#endif /* GXXXINSTDIR_HPP */ diff --git a/src/template/GXXXInstDir.i b/src/template/GXXXInstDir.i new file mode 100644 index 0000000..d75cb69 --- /dev/null +++ b/src/template/GXXXInstDir.i @@ -0,0 +1,62 @@ +/*************************************************************************** + * GXXXInstDir.i - [INSTRUMENT] instrument direction class * + * ----------------------------------------------------------------------- * + * copyright (C) [YEAR] by [AUTHOR] * + * ----------------------------------------------------------------------- * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + * * + ***************************************************************************/ +/** + * @file GXXXInstDir.i + * @brief [INSTRUMENT] instrument direction class definition + * @author [AUTHOR] + */ +%{ +/* Put headers and other declarations here that are needed for compilation */ +#include "GXXXInstDir.hpp" +%} + + +/***********************************************************************//** + * @class GXXXInstDir + * + * @brief [INSTRUMENT] instrument direction class + ***************************************************************************/ +class GXXXInstDir : public GInstDir { + +public: + // Constructors and destructors + GXXXInstDir(void); + GXXXInstDir(const GXXXInstDir& dir); + virtual ~GXXXInstDir(void); + + // Implemented pure virtual base class methods + virtual void clear(void); + virtual GXXXInstDir* clone(void) const; + virtual std::string classname(void) const; + + // Other methods + // TODO: Copy methods from GXXXInstDir.hpp file +}; + + +/***********************************************************************//** + * @brief GXXXInstDir class extension + ***************************************************************************/ +%extend GXXXInstDir { + GXXXInstDir copy() { + return (*self); + } +}; diff --git a/src/template/GXXXObservation.hpp b/src/template/GXXXObservation.hpp index 271815e..77e2078 100644 --- a/src/template/GXXXObservation.hpp +++ b/src/template/GXXXObservation.hpp @@ -88,8 +88,9 @@ protected: double m_ontime; //!< Ontime (sec) double m_livetime; //!< Livetime (sec) double m_deadc; //!< Deadtime correction - // TODO: Add any data members that are necessary. Note that the events - // are stored in the GObservation base class + // TODO: Add any data members that are necessary. Note that the event + // list or cubes (type GEvents) are stored in the GObservation base + // class }; diff --git a/src/template/Makefile.am b/src/template/Makefile.am index bc18389..bf28b9a 100644 --- a/src/template/Makefile.am +++ b/src/template/Makefile.am @@ -27,6 +27,9 @@ INCLUDES = -I$(top_srcdir)/include \ # Define sources for this directory sources = GXXXObservation.cpp \ GXXXResponse.cpp \ + GXXXEventList.cpp \ + GXXXEventAtom.cpp \ + GXXXInstDir.cpp \ GXXXRoi.cpp # Build libtool library