From bb659b369a7d51308ed2e33e13d49c05dd253b68 Mon Sep 17 00:00:00 2001 From: knodlseder <> Date: Mon, 12 Oct 2009 10:51:43 +0000 Subject: [PATCH] initial version --- include/GData.hpp | 16 ++++++++-------- include/GEventCube.hpp | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ include/GEventList.hpp | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ include/GLATEventCube.hpp | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ include/GLATEventList.hpp | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/obs/GEventCube.cpp | 265 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/obs/GEventList.cpp | 200 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 745 insertions(+), 8 deletions(-) create mode 100644 include/GEventCube.hpp create mode 100644 include/GEventList.hpp create mode 100644 include/GLATEventCube.hpp create mode 100644 include/GLATEventList.hpp create mode 100644 src/obs/GEventCube.cpp create mode 100644 src/obs/GEventList.cpp diff --git a/include/GData.hpp b/include/GData.hpp index 99212ab..d145a28 100644 --- a/include/GData.hpp +++ b/include/GData.hpp @@ -50,6 +50,7 @@ public: class iterator { friend class GData; public: + iterator(); iterator(GData *data); ~iterator(); iterator& operator++(void); // Prefix @@ -57,13 +58,12 @@ public: bool operator==(const iterator& it) const; bool operator!=(const iterator& it) const; GEvent& operator*(void); - GEvent* operator->(void); protected: - int m_obs_index; //!< Actual observation index [0,m_num-1] - int m_event_index; //!< Actual event index - int m_num_events; //!< Total number of events in actual observation - GObservation *m_obs; //!< Pointer to actual observation - GData *m_data; //!< Pointer to GData object + int m_index; //!< Actual observation index [0,m_num-1] + GEvents::iterator m_event; //!< Iterator on actual event + GEvents::iterator m_end; //!< Iterator on observation end + GObservation* m_obs; //!< Pointer to actual observation + GData* m_data; //!< Pointer to GData object }; iterator begin(void); iterator end(void); @@ -75,8 +75,8 @@ protected: void free_members(void); // Protected data area - int m_num; //!< Number of observations - GObservation **m_obs; //!< Pointers to observations + int m_num; //!< Number of observations + GObservation **m_obs; //!< Pointers to observations private: }; diff --git a/include/GEventCube.hpp b/include/GEventCube.hpp new file mode 100644 index 0000000..0e7374f --- /dev/null +++ b/include/GEventCube.hpp @@ -0,0 +1,74 @@ +/*************************************************************************** + * GEventCube.hpp - Abstract event cube container class * + * ----------------------------------------------------------------------- * + * copyright : (C) 2009 by Jurgen Knodlseder * + * ----------------------------------------------------------------------- * + * * + * 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 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +/** + * @file GEventCube.hpp + * @brief GEventCube container class interface definition. + * @author J. Knodlseder + */ + +#ifndef GEVENTCUBE_HPP +#define GEVENTCUBE_HPP + +/* __ Includes ___________________________________________________________ */ +#include "GEvents.hpp" +#include "GFits.hpp" + + +/***********************************************************************//** + * @class GEventCube + * + * @brief GEventCube container class interface defintion. + ***************************************************************************/ +class GEventCube : public GEvents { + + // Friend classes + friend class GData; + friend class GObservation; + + // I/O friends + friend std::ostream& operator<< (std::ostream& os, const GEventCube& cube); + +public: + // Constructors and destructors + GEventCube(); + GEventCube(const GEventCube& cube); + virtual ~GEventCube(); + + // Operators + virtual GEventCube& operator= (const GEventCube& cube); + + // Virtual methods + virtual void load(const std::string& filename) = 0; + virtual void load(GFitsHDU* hdu) = 0; + virtual GEvent* pointer(int index) const = 0; + + // Implemented methods + int number(void) const; + int dim(void) const; + int naxis(int axis) const; + +protected: + // Protected methods + void init_members(void); + void copy_members(const GEventCube& cube); + void free_members(void); + virtual GEventCube* clone(void) const = 0; + + // Protected data area + int m_dim; //!< Cube dimension + int* m_naxis; //!< Number of bins in each axis + +private: +}; + +#endif /* GEVENTCUBE_HPP */ diff --git a/include/GEventList.hpp b/include/GEventList.hpp new file mode 100644 index 0000000..0c5f01b --- /dev/null +++ b/include/GEventList.hpp @@ -0,0 +1,73 @@ +/*************************************************************************** + * GEventList.hpp - Abstract event list container class * + * ----------------------------------------------------------------------- * + * copyright : (C) 2009 by Jurgen Knodlseder * + * ----------------------------------------------------------------------- * + * * + * 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 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +/** + * @file GEventList.hpp + * @brief GEventList container class interface definition. + * @author J. Knodlseder + */ + +#ifndef GEVENTLIST_HPP +#define GEVENTLIST_HPP + +/* __ Includes ___________________________________________________________ */ +#include "GEvents.hpp" +#include "GFits.hpp" + + +/***********************************************************************//** + * @class GEventList + * + * @brief GEventList container class interface defintion. + ***************************************************************************/ +class GEventList : public GEvents { + + // Friend classes + friend class GData; + friend class GObservation; + + // I/O friends + friend std::ostream& operator<< (std::ostream& os, const GEventList& list); + +public: + // Constructors and destructors + GEventList(); + GEventList(const GEventList& list); + virtual ~GEventList(); + + // Operators + virtual GEventList& operator= (const GEventList& list); + + // Virtual methods + virtual void load(const std::string& filename) = 0; + virtual void load(GFitsHDU* hdu) = 0; + virtual GEvent* pointer(int index) const = 0; + + // Implemented methods + int number(void) const; +// int num(void) const; + +protected: + // Protected methods + void init_members(void); + void copy_members(const GEventList& list); + void free_members(void); + virtual GEventList* clone(void) const = 0; + + // Protected data area +// int m_num; //!< Number of events +// GEvent* m_events; //!< Pointer to events + +private: +}; + +#endif /* GEVENTLIST_HPP */ diff --git a/include/GLATEventCube.hpp b/include/GLATEventCube.hpp new file mode 100644 index 0000000..4b75667 --- /dev/null +++ b/include/GLATEventCube.hpp @@ -0,0 +1,61 @@ +/*************************************************************************** + * GLATEventCube.hpp - LAT event cube class * + * ----------------------------------------------------------------------- * + * copyright : (C) 2009 by Jurgen Knodlseder * + * ----------------------------------------------------------------------- * + * * + * 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 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +/** + * @file GLATEventCube.hpp + * @brief GLATEventCube class interface definition. + * @author J. Knodlseder + */ + +#ifndef GLATEVENTCUBE_HPP +#define GLATEVENTCUBE_HPP + +/* __ Includes ___________________________________________________________ */ +#include "GEventCube.hpp" +#include "GLATEvent.hpp" +#include "GFits.hpp" + + +/***********************************************************************//** + * @class GLATEventCube + * + * @brief GLATEventCube class interface defintion. + ***************************************************************************/ +class GLATEventCube : public GEventCube { + +public: + // Constructors and destructors + GLATEventCube(); + GLATEventCube(const GLATEventCube& cube); + virtual ~GLATEventCube(); + + // Operators + GLATEventCube& operator= (const GLATEventCube& cube); + + // Methods + void load(const std::string& filename); + void load(GFitsHDU* hdu); + GLATEvent* pointer(int index) const; + +protected: + // Protected methods + void init_members(void); + void copy_members(const GLATEventCube& cube); + void free_members(void); + GLATEventCube* clone(void) const; + + // Protected data area + +private: +}; + +#endif /* GLATEVENTCUBE_HPP */ diff --git a/include/GLATEventList.hpp b/include/GLATEventList.hpp new file mode 100644 index 0000000..afd53ca --- /dev/null +++ b/include/GLATEventList.hpp @@ -0,0 +1,64 @@ +/*************************************************************************** + * GLATEventList.hpp - LAT Event list class * + * ----------------------------------------------------------------------- * + * copyright : (C) 2009 by Jurgen Knodlseder * + * ----------------------------------------------------------------------- * + * * + * 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 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +/** + * @file GLATEventList.hpp + * @brief GLATEventList class interface definition. + * @author J. Knodlseder + */ + +#ifndef GLATEVENTLIST_HPP +#define GLATEVENTLIST_HPP + +/* __ Includes ___________________________________________________________ */ +#include "GEventList.hpp" +#include "GLATEvent.hpp" +#include "GFits.hpp" + + +/***********************************************************************//** + * @class GLATEventList + * + * @brief GLATEventList class interface defintion. + ***************************************************************************/ +class GLATEventList : public GEventList { + + // I/O friends + friend std::ostream& operator<< (std::ostream& os, const GLATEventList& list); + +public: + // Constructors and destructors + GLATEventList(); + GLATEventList(const GLATEventList& list); + virtual ~GLATEventList(); + + // Operators + GLATEventList& operator= (const GLATEventList& list); + + // Methods + void load(const std::string& filename); + void load(GFitsHDU* hdu); + GLATEvent* pointer(int index) const; + +protected: + // Protected methods + void init_members(void); + void copy_members(const GLATEventList& list); + void free_members(void); + GLATEventList* clone(void) const; + + // Protected data area + +private: +}; + +#endif /* GLATEVENTLIST_HPP */ diff --git a/src/obs/GEventCube.cpp b/src/obs/GEventCube.cpp new file mode 100644 index 0000000..af1cd39 --- /dev/null +++ b/src/obs/GEventCube.cpp @@ -0,0 +1,265 @@ +/*************************************************************************** + * GEventCube.cpp - Abstract event cube container class * + * ----------------------------------------------------------------------- * + * copyright : (C) 2009 by Jurgen Knodlseder * + * ----------------------------------------------------------------------- * + * * + * 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 2 of the License, or * + * (at your option) any later version. * + * * + * ----------------------------------------------------------------------- * + ***************************************************************************/ +/** + * @file GEventCube.cpp + * @brief GEventCube container class implementation. + * @author J. Knodlseder + */ + +/* __ Includes ___________________________________________________________ */ +#include +#include "GException.hpp" +#include "GEventCube.hpp" + +/* __ Method name definitions ____________________________________________ */ +#define G_COPY_MEMBERS "GEventCube::copy_members(const GEventCube&)" + +/* __ Macros _____________________________________________________________ */ + +/* __ Coding definitions _________________________________________________ */ + +/* __ Debug definitions __________________________________________________ */ + + +/*========================================================================== + = = + = GEventCube constructors/destructors = + = = + ==========================================================================*/ + +/***********************************************************************//** + * @brief Constructor + ***************************************************************************/ +GEventCube::GEventCube() : GEvents() +{ + // Initialise class members for clean destruction + init_members(); + + // Return + return; +} + + +/***********************************************************************//** + * @brief Copy constructor + * + * @param[in] cube Event cube from which the instance should be built. + ***************************************************************************/ +GEventCube::GEventCube(const GEventCube& cube) : GEvents(cube) +{ + // Initialise class members for clean destruction + init_members(); + + // Copy members + copy_members(cube); + + // Return + return; +} + + +/***********************************************************************//** + * @brief Destructor + ***************************************************************************/ +GEventCube::~GEventCube() +{ + // Free members + free_members(); + + // Return + return; +} + + +/*========================================================================== + = = + = GEventCube operators = + = = + ==========================================================================*/ + +/***********************************************************************//** + * @brief Assignment operator + * + * @param[in] cube Event cube to be assigned. + ***************************************************************************/ +GEventCube& GEventCube::operator= (const GEventCube& cube) +{ + // Execute only if object is not identical + if (this != &cube) { + + // Copy base class members + this->GEvents::operator=(cube); + + // Free members + free_members(); + + // Initialise private members for clean destruction + init_members(); + + // Copy members + copy_members(cube); + + } // endif: object was not identical + + // Return this object + return *this; +} + + +/*========================================================================== + = = + = GEventCube public methods = + = = + ==========================================================================*/ + +/***********************************************************************//** + * @brief Return number of events in cube + ***************************************************************************/ +int GEventCube::number(void) const +{ + // Return + return 0; // DUMMY DUMMY +} + + +/***********************************************************************//** + * @brief Return event cube dimension + ***************************************************************************/ +int GEventCube::dim(void) const +{ + // Return + return m_dim; +} + + +/***********************************************************************//** + * @brief Return event cube axis dimension + * + * @param[in] axis Cube axis number (starting from 0). + ***************************************************************************/ +int GEventCube::naxis(int axis) const +{ + // Throw error if index is out of range + #if defined(G_RANGE_CHECK) + if (m_naxis == NULL || axis < 0 || axis >= m_dim) + throw GException::out_of_range(G_NAXIS, axis, 0, m_dim-1); + #endif + + // Return axis dimension + return m_naxis[axis]; +} + + +/*========================================================================== + = = + = GEventCube private methods = + = = + ==========================================================================*/ + +/***********************************************************************//** + * @brief Initialise class members + ***************************************************************************/ +void GEventCube::init_members(void) +{ + // Initialise members + m_dim = 0; + m_naxis = NULL; + + // Return + return; +} + + +/***********************************************************************//** + * @brief Copy class members + * + * @param[in] cube GEventCube members to be copied. + ***************************************************************************/ +void GEventCube::copy_members(const GEventCube& cube) +{ + // Copy attributes + m_dim = cube.m_dim; + + // If the cube is not empty then copy it + if (m_dim > 0 && cube.m_naxis != NULL) { + + // Allocate memory + m_naxis = new int[m_dim]; + if (m_naxis == NULL) + throw GException::mem_alloc(G_COPY_MEMBERS, m_dim); + + // Copy axis dimensions + for (int i = 0; i < m_dim; ++i) + m_naxis[i] = cube.m_naxis[i]; + + } + + // Return + return; +} + + +/***********************************************************************//** + * @brief Delete class members + ***************************************************************************/ +void GEventCube::free_members(void) +{ + // Free memory + if (m_naxis != NULL) delete [] m_naxis; + + // Signal free pointers + m_naxis = NULL; + + // Return + return; +} + + +/*========================================================================== + = = + = GEventCube friends = + = = + ==========================================================================*/ + +/***********************************************************************//** + * @brief Output operator + * + * @param[in] os Output stream into which the event cube will be dumped + * @param[in] cube Event cube to be dumped + ***************************************************************************/ +std::ostream& operator<< (std::ostream& os, const GEventCube& cube) +{ + // Put event cube in stream + os << "=== GEventCube ===" << std::endl; + if (cube.m_naxis != NULL) { + os << " Cube is undefined" << std::endl; + } + else { + os << " Cube dimension ............: " << cube.dim() << std::endl; + for (int axis = 0; axis < cube.m_dim; ++axis) { + os << " Axis " << axis+1 << " dimension ..........: " + << cube.naxis(axis) << std::endl; + } + } + + // Return output stream + return os; +} + + +/*========================================================================== + = = + = Other functions used by GEventList = + = = + ==========================================================================*/ diff --git a/src/obs/GEventList.cpp b/src/obs/GEventList.cpp new file mode 100644 index 0000000..74a7cae --- /dev/null +++ b/src/obs/GEventList.cpp @@ -0,0 +1,200 @@ +/*************************************************************************** + * GEventList.cpp - Abstract event container class * + * ----------------------------------------------------------------------- * + * copyright : (C) 2009 by Jurgen Knodlseder * + * ----------------------------------------------------------------------- * + * * + * 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 2 of the License, or * + * (at your option) any later version. * + * * + * ----------------------------------------------------------------------- * + ***************************************************************************/ +/** + * @file GEventList.cpp + * @brief GEventList container class implementation. + * @author J. Knodlseder + */ + +/* __ Includes ___________________________________________________________ */ +#include +#include "GException.hpp" +#include "GEventList.hpp" + +/* __ Method name definitions ____________________________________________ */ + +/* __ Macros _____________________________________________________________ */ + +/* __ Coding definitions _________________________________________________ */ + +/* __ Debug definitions __________________________________________________ */ + + +/*========================================================================== + = = + = GEventList constructors/destructors = + = = + ==========================================================================*/ + +/***********************************************************************//** + * @brief Constructor + ***************************************************************************/ +GEventList::GEventList() : GEvents() +{ + // Initialise class members for clean destruction + init_members(); + + // Return + return; +} + + +/***********************************************************************//** + * @brief Copy constructor + * + * @param[in] list Event list from which the instance should be built. + ***************************************************************************/ +GEventList::GEventList(const GEventList& list) : GEvents(list) +{ + // Initialise class members for clean destruction + init_members(); + + // Copy members + copy_members(list); + + // Return + return; +} + + +/***********************************************************************//** + * @brief Destructor + ***************************************************************************/ +GEventList::~GEventList() +{ + // Free members + free_members(); + + // Return + return; +} + + +/*========================================================================== + = = + = GEventList operators = + = = + ==========================================================================*/ + +/***********************************************************************//** + * @brief Assignment operator + * + * @param[in] list Event list to be assigned. + ***************************************************************************/ +GEventList& GEventList::operator= (const GEventList& list) +{ + // Execute only if object is not identical + if (this != &list) { + + // Copy base class members + this->GEvents::operator=(list); + + // Free members + free_members(); + + // Initialise private members for clean destruction + init_members(); + + // Copy members + copy_members(list); + + } // endif: object was not identical + + // Return this object + return *this; +} + + +/*========================================================================== + = = + = GEventList public methods = + = = + ==========================================================================*/ + +/***********************************************************************//** + * @brief Return number of events in list + ***************************************************************************/ +int GEventList::number(void) const +{ + // Return + return m_num; +} + + +/*========================================================================== + = = + = GEventList private methods = + = = + ==========================================================================*/ + +/***********************************************************************//** + * @brief Initialise class members + ***************************************************************************/ +void GEventList::init_members(void) +{ + // Return + return; +} + + +/***********************************************************************//** + * @brief Copy class members + * + * @param[in] list GEventList members to be copied. + ***************************************************************************/ +void GEventList::copy_members(const GEventList& list) +{ + // Return + return; +} + + +/***********************************************************************//** + * @brief Delete class members + ***************************************************************************/ +void GEventList::free_members(void) +{ + // Return + return; +} + + +/*========================================================================== + = = + = GEventList friends = + = = + ==========================================================================*/ + +/***********************************************************************//** + * @brief Output operator + * + * @param[in] os Output stream into which the event list will be dumped + * @param[in] list Event list to be dumped + ***************************************************************************/ +std::ostream& operator<< (std::ostream& os, const GEventList& list) +{ + // Put header in stream + os << "=== GEventList ===" << std::endl; + os << " Number of events in list ..: " << list.number(); + + // Return output stream + return os; +} + + +/*========================================================================== + = = + = Other functions used by GEventList = + = = + ==========================================================================*/ -- libgit2 0.21.4