Commit eca8692866e9d6a3b1e8de75e3ab6b728c7d8034

Authored by Jürgen Knödlseder
1 parent 495ebbb1

Add GCOMHkd and GCOMHkds classes to handle COMPTEL housekeeping data (#4209)

ChangeLog
1   -2023-03-15
  1 +2023-03-23
2 2  
3 3 * Version 2.1.0 released
4 4 ========================
5 5  
6 6 Replace distutils by setuptools for Python setup (#4223)
  7 + Add GCOMHkd and GCOMHkds classes (#4209)
7 8 Add COMPTEL DRW support to GCOMObservation and GCOMDris (#4209)
8 9 Add GSkyMap comparison operators (#4209)
9 10 Add GIntegral::adaptive_gauss_kronrod() method (#4204)
... ...
1 1 New Features and Important Changes in GammaLib 2.1.0
2 2  
3   -15 March 2023
  3 +23 March 2023
4 4  
5 5  
6 6 1. Introduction
... ... @@ -13,6 +13,8 @@ made since the last release of GammaLib.
13 13 ---------------------------------
14 14 The following classes have been added:
15 15 - GCOMDris
  16 +- GCOMHkd
  17 +- GCOMHkds
16 18  
17 19 The following classes have been removed:
18 20 - none
... ... @@ -172,6 +174,9 @@ None
172 174  
173 175 22. COMPTEL interface
174 176 ---------------------
  177 +Added GCOMHkd and GCOMHkds classes for the handling of housekeeping data
  178 +(#4209).
  179 +
175 180 Added GCOMDris container class. This class specifically provides the
176 181 GCOMDris::compute_drws() that allows computation of weighting cubes for
177 182 all energy bins (#4209).
... ...
README.md
1 1 GammaLib information
2 2 ====================
3   -* Version: 2.1.0.dev (15 March 2023)
  3 +* Version: 2.1.0.dev (23 March 2023)
4 4  
5 5 [![Build Status](https://cta-jenkins.irap.omp.eu/buildStatus/icon?job=gammalib-integrate-os)](https://cta-jenkins.irap.omp.eu/job/gammalib-integrate-os/)
6 6  
... ...
doc/source/admin/release_history/2.1.rst
... ... @@ -28,6 +28,7 @@ Improvements
28 28 * [`4209 <https://cta-redmine.irap.omp.eu/issues/4209>`_] -
29 29 Add ``GSkyMap`` comparison operators.
30 30 Add COMPTEL DRW support to ``GCOMObservation`` and add ``GCOMDris`` class.
  31 + Add ``GCOMHkd`` and ``GCOMHkds`` classes.
31 32 * [`4204 <https://cta-redmine.irap.omp.eu/issues/4204>`_] -
32 33 Add ``GIntegral::adaptive_gauss_kronrod()`` method
33 34 * [`4202 <https://cta-redmine.irap.omp.eu/issues/4202>`_] -
... ...
inst/com/include/GCOMHkd.hpp 0 → 100644
  1 +/***************************************************************************
  2 + * GCOMHkd.hpp - COMPTEL Housekeeping Data container class *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2023 by Juergen Knodlseder *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software: you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation, either version 3 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + * This program is distributed in the hope that it will be useful, *
  13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  15 + * GNU General Public License for more details. *
  16 + * *
  17 + * You should have received a copy of the GNU General Public License *
  18 + * along with this program. If not, see <http://www.gnu.org/licenses/>. *
  19 + * *
  20 + ***************************************************************************/
  21 +/**
  22 + * @file GCOMHkd.hpp
  23 + * @brief COMPTEL Housekeeping Data container class definition
  24 + * @author Juergen Knodlseder
  25 + */
  26 +
  27 +#ifndef GCOMHKD_HPP
  28 +#define GCOMHKD_HPP
  29 +
  30 +/* __ Includes ___________________________________________________________ */
  31 +#include <string>
  32 +#include <vector>
  33 +#include "GContainer.hpp"
  34 +#include "GTimes.hpp"
  35 +
  36 +/* __ Forward declarations _______________________________________________ */
  37 +class GTime;
  38 +
  39 +/* __ Constants __________________________________________________________ */
  40 +
  41 +
  42 +/***********************************************************************//**
  43 + * @class GCOMHkd
  44 + *
  45 + * @brief COMPTEL Housekeeping Data container class
  46 + *
  47 + * This class holds data for one housekeeping parameter.
  48 + ***************************************************************************/
  49 +class GCOMHkd : public GContainer {
  50 +
  51 +public:
  52 + // Constructors and destructors
  53 + GCOMHkd(void);
  54 + explicit GCOMHkd(const std::string& name);
  55 + GCOMHkd(const GCOMHkd& hkd);
  56 + virtual ~GCOMHkd(void);
  57 +
  58 + // Operators
  59 + GCOMHkd& operator=(const GCOMHkd& hkd);
  60 +
  61 + // Methods
  62 + void clear(void);
  63 + GCOMHkd* clone(void) const;
  64 + std::string classname(void) const;
  65 + int size(void) const;
  66 + bool is_empty(void) const;
  67 + void append(const GTime& time, const double& value);
  68 + void remove(const int& index);
  69 + void reserve(const int& num);
  70 + void extend(const GCOMHkd& hkd);
  71 + const std::string& name(void) const;
  72 + void name(const std::string& name);
  73 + std::string print(const GChatter& chatter = NORMAL) const;
  74 +
  75 +protected:
  76 + // Protected methods
  77 + void init_members(void);
  78 + void copy_members(const GCOMHkd& hkd);
  79 + void free_members(void);
  80 +
  81 + // Protected members
  82 + std::string m_name; //!< Name of housekeeping parameter
  83 + GTimes m_times; //!< Times
  84 + std::vector<double> m_values; //!< Values at times
  85 +};
  86 +
  87 +
  88 +/***********************************************************************//**
  89 + * @brief Return class name
  90 + *
  91 + * @return String containing the class name ("GCOMHkd").
  92 + ***************************************************************************/
  93 +inline
  94 +std::string GCOMHkd::classname(void) const
  95 +{
  96 + return ("GCOMHkd");
  97 +}
  98 +
  99 +
  100 +/***********************************************************************//**
  101 + * @brief Return number of Housekeeping Data in container
  102 + *
  103 + * @return Number of Housekeeping Data in container.
  104 + *
  105 + * Returns the number of Housekeeping Data in the container.
  106 + ***************************************************************************/
  107 +inline
  108 +int GCOMHkd::size(void) const
  109 +{
  110 + return (int)m_times.size();
  111 +}
  112 +
  113 +
  114 +/***********************************************************************//**
  115 + * @brief Signals if there are no Housekeeping Data in container
  116 + *
  117 + * @return True if container is empty, false otherwise.
  118 + *
  119 + * Signals if the Housekeeping Data container does not contain any
  120 + * Housekeeping Data.
  121 + ***************************************************************************/
  122 +inline
  123 +bool GCOMHkd::is_empty(void) const
  124 +{
  125 + return (m_times.is_empty());
  126 +}
  127 +
  128 +
  129 +/***********************************************************************//**
  130 + * @brief Reserves space for Housekeeping Data in container
  131 + *
  132 + * @param[in] num Number of Housekeeping Data.
  133 + *
  134 + * Reserves space for @p num Housekeeping Data in the container.
  135 + ***************************************************************************/
  136 +inline
  137 +void GCOMHkd::reserve(const int& num)
  138 +{
  139 + m_times.reserve(num);
  140 + m_values.reserve(num);
  141 + return;
  142 +}
  143 +
  144 +
  145 +/***********************************************************************//**
  146 + * @brief Return Housekeeping Data name
  147 + *
  148 + * @return Housekeeping Data name.
  149 + *
  150 + * Returns the Housekeeping Data name.
  151 + ***************************************************************************/
  152 +inline
  153 +const std::string& GCOMHkd::name(void) const
  154 +{
  155 + return (m_name);
  156 +}
  157 +
  158 +
  159 +/***********************************************************************//**
  160 + * @brief Set Housekeeping Data name
  161 + *
  162 + * @param[in] name Housekeeping Data name.
  163 + *
  164 + * Sets the Housekeeping Data name.
  165 + ***************************************************************************/
  166 +inline
  167 +void GCOMHkd::name(const std::string& name)
  168 +{
  169 + m_name = name;
  170 + return;
  171 +}
  172 +
  173 +#endif /* GCOMHKD_HPP */
... ...
inst/com/include/GCOMHkds.hpp 0 → 100644
  1 +/***************************************************************************
  2 + * GCOMHkds.hpp - COMPTEL Housekeeping Data collection class *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2023 by Juergen Knodlseder *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software: you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation, either version 3 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + * This program is distributed in the hope that it will be useful, *
  13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  15 + * GNU General Public License for more details. *
  16 + * *
  17 + * You should have received a copy of the GNU General Public License *
  18 + * along with this program. If not, see <http://www.gnu.org/licenses/>. *
  19 + * *
  20 + ***************************************************************************/
  21 +/**
  22 + * @file GCOMHkds.hpp
  23 + * @brief COMPTEL Housekeeping Data collection class definition
  24 + * @author Juergen Knodlseder
  25 + */
  26 +
  27 +#ifndef GCOMHKDS_HPP
  28 +#define GCOMHKDS_HPP
  29 +
  30 +/* __ Includes ___________________________________________________________ */
  31 +#include <string>
  32 +#include <vector>
  33 +#include "GCOMHkd.hpp"
  34 +#include "GContainer.hpp"
  35 +
  36 +/* __ Forward declarations _______________________________________________ */
  37 +class GFilename;
  38 +class GFitsTable;
  39 +
  40 +/* __ Constants __________________________________________________________ */
  41 +
  42 +
  43 +/***********************************************************************//**
  44 + * @class GCOMHkds
  45 + *
  46 + * @brief COMPTEL Housekeeping Data collection class
  47 + *
  48 + * The COMPTEL Housekeeping Data collection class holds Housekeeping
  49 + * Data containers for various parameters.
  50 + ***************************************************************************/
  51 +class GCOMHkds : public GContainer {
  52 +
  53 +public:
  54 + // Constructors and destructors
  55 + GCOMHkds(void);
  56 + explicit GCOMHkds(const GFilename& filename);
  57 + GCOMHkds(const GCOMHkds& hkds);
  58 + virtual ~GCOMHkds(void);
  59 +
  60 + // Operators
  61 + GCOMHkds& operator=(const GCOMHkds& hkds);
  62 + GCOMHkd& operator[](const int& index);
  63 + const GCOMHkd& operator[](const int& index) const;
  64 + GCOMHkd& operator[](const std::string& name);
  65 + const GCOMHkd& operator[](const std::string& name) const;
  66 +
  67 + // Methods
  68 + void clear(void);
  69 + GCOMHkds* clone(void) const;
  70 + std::string classname(void) const;
  71 + GCOMHkd& at(const int& index);
  72 + const GCOMHkd& at(const int& index) const;
  73 + int size(void) const;
  74 + bool is_empty(void) const;
  75 + GCOMHkd& set(const int& index, const GCOMHkd& hkd);
  76 + GCOMHkd& set(const std::string& name, const GCOMHkd& hkd);
  77 + GCOMHkd& append(const GCOMHkd& hkd);
  78 + GCOMHkd& insert(const int& index, const GCOMHkd& hkd);
  79 + void remove(const int& index);
  80 + void reserve(const int& num);
  81 + bool contains(const std::string& name) const;
  82 + void extend(const GCOMHkds& hkds);
  83 + void load(const GFilename& filename);
  84 + void read(const GFitsTable& table);
  85 + std::string print(const GChatter& chatter = NORMAL) const;
  86 +
  87 +protected:
  88 + // Protected methods
  89 + void init_members(void);
  90 + void copy_members(const GCOMHkds& hkds);
  91 + void free_members(void);
  92 + int get_index(const std::string& name) const;
  93 +
  94 + // Protected data members
  95 + std::vector<GCOMHkd> m_hkds; //!< Housekeeping Data containers
  96 +};
  97 +
  98 +
  99 +/***********************************************************************//**
  100 + * @brief Return class name
  101 + *
  102 + * @return String containing the class name ("GCOMHkds").
  103 + ***************************************************************************/
  104 +inline
  105 +std::string GCOMHkds::classname(void) const
  106 +{
  107 + return ("GCOMHkds");
  108 +}
  109 +
  110 +
  111 +/***********************************************************************//**
  112 + * @brief Return reference to Housekeeping Data container
  113 + *
  114 + * @param[in] index Housekeeping Data container index [0,...,size()-1].
  115 + * @return Reference to Housekeeping Data container.
  116 + *
  117 + * Returns a reference to the Housekeeping Data container with the specified
  118 + * @p index.
  119 + ***************************************************************************/
  120 +inline
  121 +GCOMHkd& GCOMHkds::operator[](const int& index)
  122 +{
  123 + return (m_hkds[index]);
  124 +}
  125 +
  126 +
  127 +/***********************************************************************//**
  128 + * @brief Return reference to Housekeeping Data (const version)
  129 + *
  130 + * @param[in] index Housekeeping Data container index [0,...,size()-1].
  131 + * @return Reference to Housekeeping Data container.
  132 + *
  133 + * Returns a reference to the Housekeeping Data container with the specified
  134 + * @p index.
  135 + ***************************************************************************/
  136 +inline
  137 +const GCOMHkd& GCOMHkds::operator[](const int& index) const
  138 +{
  139 + return (m_hkds[index]);
  140 +}
  141 +
  142 +
  143 +/***********************************************************************//**
  144 + * @brief Return number of Housekeeping parameters in collection
  145 + *
  146 + * @return Number of Housekeeping parameters in collection.
  147 + *
  148 + * Returns the number of Housekeeping parameters in the collection.
  149 + ***************************************************************************/
  150 +inline
  151 +int GCOMHkds::size(void) const
  152 +{
  153 + return (int)m_hkds.size();
  154 +}
  155 +
  156 +
  157 +/***********************************************************************//**
  158 + * @brief Signals if there are no Housekeeping Data containers in collection
  159 + *
  160 + * @return True if collection is empty, false otherwise.
  161 + *
  162 + * Signals if the collection does not contain any Housekeeping Data
  163 + * containers.
  164 + ***************************************************************************/
  165 +inline
  166 +bool GCOMHkds::is_empty(void) const
  167 +{
  168 + return (m_hkds.empty());
  169 +}
  170 +
  171 +
  172 +/***********************************************************************//**
  173 + * @brief Reserves space for Housekeeping Data containers in collection
  174 + *
  175 + * @param[in] num Number of Housekeeping Data containers in collection.
  176 + *
  177 + * Reserves space for @p num Housekeeping Data containers in the collection.
  178 + ***************************************************************************/
  179 +inline
  180 +void GCOMHkds::reserve(const int& num)
  181 +{
  182 + m_hkds.reserve(num);
  183 + return;
  184 +}
  185 +
  186 +#endif /* GCOMHKDS_HPP */
... ...
inst/com/include/GCOMLib.hpp
1 1 /***************************************************************************
2 2 * GCOMLib.hpp - COMPTEL Support Header files *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2012-2022 by Juergen Knoedlseder *
  4 + * copyright (C) 2012-2023 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -45,6 +45,8 @@
45 45 #include "GCOMDri.hpp"
46 46 #include "GCOMOads.hpp"
47 47 #include "GCOMOad.hpp"
  48 +#include "GCOMHkds.hpp"
  49 +#include "GCOMHkd.hpp"
48 50 #include "GCOMBvcs.hpp"
49 51 #include "GCOMBvc.hpp"
50 52 #include "GCOMTim.hpp"
... ...
inst/com/pyext/GCOMHkd.i 0 → 100644
  1 +/***************************************************************************
  2 + * GCOMHkd.i - COMPTEL Housekeeping Data container class *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2023 by Juergen Knodlseder *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software: you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation, either version 3 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + * This program is distributed in the hope that it will be useful, *
  13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  15 + * GNU General Public License for more details. *
  16 + * *
  17 + * You should have received a copy of the GNU General Public License *
  18 + * along with this program. If not, see <http://www.gnu.org/licenses/>. *
  19 + * *
  20 + ***************************************************************************/
  21 +/**
  22 + * @file GCOMHkd.i
  23 + * @brief COMPTEL Housekeeping Data container class definition
  24 + * @author Juergen Knodlseder
  25 + */
  26 +%{
  27 +/* Put headers and other declarations here that are needed for compilation */
  28 +#include "GCOMHkd.hpp"
  29 +%}
  30 +
  31 +
  32 +/***********************************************************************//**
  33 + * @class GCOMHkd
  34 + *
  35 + * @brief COMPTEL Housekeeping Data container class
  36 + ***************************************************************************/
  37 +class GCOMHkd : public GContainer {
  38 +
  39 +public:
  40 + // Constructors and destructors
  41 + GCOMHkd(void);
  42 + explicit GCOMHkd(const std::string& name);
  43 + GCOMHkd(const GCOMHkd& hkd);
  44 + virtual ~GCOMHkd(void);
  45 +
  46 + // Methods
  47 + void clear(void);
  48 + GCOMHkd* clone(void) const;
  49 + std::string classname(void) const;
  50 + int size(void) const;
  51 + bool is_empty(void) const;
  52 + void append(const GTime& time, const double& value);
  53 + void remove(const int& index);
  54 + void reserve(const int& num);
  55 + void extend(const GCOMHkd& hkd);
  56 + const std::string& name(void) const;
  57 + void name(const std::string& name);
  58 +};
  59 +
  60 +
  61 +/***********************************************************************//**
  62 + * @brief GCOMHkd class extension
  63 + ***************************************************************************/
  64 +%extend GCOMHkd {
  65 + GCOMHkd copy() {
  66 + return (*self);
  67 + }
  68 +%pythoncode {
  69 + def __getstate__(self):
  70 + state = ()
  71 + return state
  72 + def __setstate__(self, state):
  73 + self.__init__()
  74 +}
  75 +};
... ...
inst/com/pyext/GCOMHkds.i 0 → 100644
  1 +/***************************************************************************
  2 + * GCOMHkds.i - COMPTEL Housekeeping Data collection class *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2023 by Juergen Knodlseder *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software: you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation, either version 3 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + * This program is distributed in the hope that it will be useful, *
  13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  15 + * GNU General Public License for more details. *
  16 + * *
  17 + * You should have received a copy of the GNU General Public License *
  18 + * along with this program. If not, see <http://www.gnu.org/licenses/>. *
  19 + * *
  20 + ***************************************************************************/
  21 +/**
  22 + * @file GCOMHkds.i
  23 + * @brief COMPTEL Housekeeping Data collection class definition
  24 + * @author Juergen Knodlseder
  25 + */
  26 +%{
  27 +/* Put headers and other declarations here that are needed for compilation */
  28 +#include "GCOMHkds.hpp"
  29 +%}
  30 +
  31 +
  32 +/***********************************************************************//**
  33 + * @class GCOMHkds
  34 + *
  35 + * @brief COMPTEL Housekeeping Data collection class
  36 + ***************************************************************************/
  37 +class GCOMHkds : public GContainer {
  38 +
  39 +public:
  40 + // Constructors and destructors
  41 + GCOMHkds(void);
  42 + explicit GCOMHkds(const GFilename& filename);
  43 + GCOMHkds(const GCOMHkds& hkds);
  44 + virtual ~GCOMHkds(void);
  45 +
  46 + // Methods
  47 + void clear(void);
  48 + GCOMHkds* clone(void) const;
  49 + std::string classname(void) const;
  50 + int size(void) const;
  51 + bool is_empty(void) const;
  52 + GCOMHkd& set(const int& index, const GCOMHkd& hkd);
  53 + GCOMHkd& set(const std::string& name, const GCOMHkd& hkd);
  54 + GCOMHkd& append(const GCOMHkd& hkd);
  55 + GCOMHkd& insert(const int& index, const GCOMHkd& hkd);
  56 + void remove(const int& index);
  57 + void reserve(const int& num);
  58 + bool contains(const std::string& name) const;
  59 + void extend(const GCOMHkds& hkds);
  60 + void load(const GFilename& filename);
  61 + void read(const GFitsTable& table);
  62 +};
  63 +
  64 +
  65 +/***********************************************************************//**
  66 + * @brief GCOMHkds class extension
  67 + ***************************************************************************/
  68 +%extend GCOMHkds {
  69 + GCOMHkd& __getitem__(const int& index) {
  70 + // Counting from start, e.g. [2]
  71 + if (index >= 0 && index < self->size()) {
  72 + return (*self)[index];
  73 + }
  74 + // Counting from end, e.g. [-1]
  75 + else if (index < 0 && self->size()+index >= 0) {
  76 + return (*self)[self->size()+index];
  77 + }
  78 + else {
  79 + throw GException::out_of_range("__getitem__(int)",
  80 + "Housekeeping Data container index",
  81 + index, self->size());
  82 + }
  83 + }
  84 + GCOMHkd& __getitem__(const std::string& name) {
  85 + return (*self)[name];
  86 + }
  87 + GCOMHkds* __getitem__(PyObject *param) {
  88 + if (PySlice_Check(param)) {
  89 + Py_ssize_t start = 0;
  90 + Py_ssize_t stop = 0;
  91 + Py_ssize_t step = 0;
  92 + Py_ssize_t len = self->size();
  93 + if (PythonSlice_GetIndices(param, len, &start, &stop, &step) == 0) {
  94 + GCOMHkds* hkds = new GCOMHkds;
  95 + if (step > 0) {
  96 + for (int i = (int)start; i < (int)stop; i += (int)step) {
  97 + hkds->append((*self)[i]);
  98 + }
  99 + }
  100 + else {
  101 + for (int i = (int)start; i > (int)stop; i += (int)step) {
  102 + hkds->append((*self)[i]);
  103 + }
  104 + }
  105 + return hkds;
  106 + }
  107 + else {
  108 + throw GException::invalid_argument("__getitem__(PyObject)",
  109 + "Invalid slice indices");
  110 + }
  111 + }
  112 + else {
  113 + throw GException::invalid_argument("__getitem__(PyObject)","");
  114 + }
  115 + }
  116 + void __setitem__(const int& index, const GCOMHkd& val) {
  117 + // Counting from start, e.g. [2]
  118 + if (index >= 0 && index < self->size()) {
  119 + (*self)[index] = val;
  120 + }
  121 + // Counting from end, e.g. [-1]
  122 + else if (index < 0 && self->size()+index >= 0) {
  123 + (*self)[self->size()+index] = val;
  124 + }
  125 + else {
  126 + throw GException::out_of_range("__setitem__(int)",
  127 + "Housekeeping Data container index",
  128 + index, self->size());
  129 + }
  130 + }
  131 + void __setitem__(const std::string& name, const GCOMHkd& val) {
  132 + self->set(name, val);
  133 + return;
  134 + }
  135 + GCOMHkds copy() {
  136 + return (*self);
  137 + }
  138 +%pythoncode {
  139 + def __getstate__(self):
  140 + state = tuple([x for x in self]),
  141 + return state
  142 + def __setstate__(self, state):
  143 + self.__init__()
  144 + size = len(state[0])
  145 + self.reserve(size)
  146 + for x in state[0]:
  147 + self.append(x)
  148 +}
  149 +};
... ...
inst/com/pyext/com.i
... ... @@ -119,6 +119,8 @@
119 119 %include "GCOMTim.i"
120 120 %include "GCOMOad.i"
121 121 %include "GCOMOads.i"
  122 +%include "GCOMHkd.i"
  123 +%include "GCOMHkds.i"
122 124 %include "GCOMBvc.i"
123 125 %include "GCOMBvcs.i"
124 126 %include "GCOMDri.i"
... ...
inst/com/src/GCOMHkd.cpp 0 → 100644
  1 +/***************************************************************************
  2 + * GCOMHkd.cpp - COMPTEL Housekeeping Data container class *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2023 by Juergen Knodlseder *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software: you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation, either version 3 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + * This program is distributed in the hope that it will be useful, *
  13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  15 + * GNU General Public License for more details. *
  16 + * *
  17 + * You should have received a copy of the GNU General Public License *
  18 + * along with this program. If not, see <http://www.gnu.org/licenses/>. *
  19 + * *
  20 + ***************************************************************************/
  21 +/**
  22 + * @file GCOMHkd.cpp
  23 + * @brief COMPTEL Housekeeping Data container class implementation
  24 + * @author Juergen Knodlseder
  25 + */
  26 +
  27 +/* __ Includes ___________________________________________________________ */
  28 +#ifdef HAVE_CONFIG_H
  29 +#include <config.h>
  30 +#endif
  31 +#include "GException.hpp"
  32 +#include "GTools.hpp"
  33 +#include "GCOMTools.hpp"
  34 +#include "GCOMHkd.hpp"
  35 +
  36 +/* __ Method name definitions ____________________________________________ */
  37 +#define G_REMOVE "GCOMHkd::remove(int&)"
  38 +
  39 +/* __ Macros _____________________________________________________________ */
  40 +
  41 +/* __ Coding definitions _________________________________________________ */
  42 +
  43 +/* __ Debug definitions __________________________________________________ */
  44 +
  45 +
  46 +
  47 +/*==========================================================================
  48 + = =
  49 + = Constructors/destructors =
  50 + = =
  51 + ==========================================================================*/
  52 +
  53 +/***********************************************************************//**
  54 + * @brief Void constructor
  55 + ***************************************************************************/
  56 +GCOMHkd::GCOMHkd(void)
  57 +{
  58 + // Initialise class members
  59 + init_members();
  60 +
  61 + // Return
  62 + return;
  63 +}
  64 +
  65 +
  66 +/***********************************************************************//**
  67 + * @brief Name constructor
  68 + *
  69 + * @param[in] name Name of Housekeeping parameter
  70 + ***************************************************************************/
  71 +GCOMHkd::GCOMHkd(const std::string& name)
  72 +{
  73 + // Initialise class members
  74 + init_members();
  75 +
  76 + // Set name
  77 + this->name(name);
  78 +
  79 + // Return
  80 + return;
  81 +}
  82 +
  83 +
  84 +/***********************************************************************//**
  85 + * @brief Copy constructor
  86 + *
  87 + * @param[in] hkd Housekeeping Data container.
  88 + ***************************************************************************/
  89 +GCOMHkd::GCOMHkd(const GCOMHkd& hkd)
  90 +{
  91 + // Initialise class members
  92 + init_members();
  93 +
  94 + // Copy members
  95 + copy_members(hkd);
  96 +
  97 + // Return
  98 + return;
  99 +}
  100 +
  101 +
  102 +/***********************************************************************//**
  103 + * @brief Destructor
  104 + ***************************************************************************/
  105 +GCOMHkd::~GCOMHkd(void)
  106 +{
  107 + // Free members
  108 + free_members();
  109 +
  110 + // Return
  111 + return;
  112 +}
  113 +
  114 +
  115 +/*==========================================================================
  116 + = =
  117 + = Operators =
  118 + = =
  119 + ==========================================================================*/
  120 +
  121 +/***********************************************************************//**
  122 + * @brief Assignment operator
  123 + *
  124 + * @param[in] hkd Housekeeping Data container.
  125 + * @return Housekeeping Data container.
  126 + ***************************************************************************/
  127 +GCOMHkd& GCOMHkd::operator=(const GCOMHkd& hkd)
  128 +{
  129 + // Execute only if object is not identical
  130 + if (this != &hkd) {
  131 +
  132 + // Free members
  133 + free_members();
  134 +
  135 + // Initialise private members
  136 + init_members();
  137 +
  138 + // Copy members
  139 + copy_members(hkd);
  140 +
  141 + } // endif: object was not identical
  142 +
  143 + // Return this object
  144 + return *this;
  145 +}
  146 +
  147 +
  148 +/*==========================================================================
  149 + = =
  150 + = Public methods =
  151 + = =
  152 + ==========================================================================*/
  153 +
  154 +/***********************************************************************//**
  155 + * @brief Clear Housekeeping Data container
  156 + ***************************************************************************/
  157 +void GCOMHkd::clear(void)
  158 +{
  159 + // Free members
  160 + free_members();
  161 +
  162 + // Initialise private members
  163 + init_members();
  164 +
  165 + // Return
  166 + return;
  167 +}
  168 +
  169 +
  170 +/***********************************************************************//**
  171 + * @brief Clone Housekeeping Data container
  172 + *
  173 + * @return Pointer to deep copy of Housekeeping Data container.
  174 + ***************************************************************************/
  175 +GCOMHkd* GCOMHkd::clone(void) const
  176 +{
  177 + return new GCOMHkd(*this);
  178 +}
  179 +
  180 +
  181 +/***********************************************************************//**
  182 + * @brief Append Housekeeping Data to container
  183 + *
  184 + * @param[in] time Time stamp of Housekeeping Data.
  185 + * @param[in] value Value of Housekeeping Data.
  186 + *
  187 + * Appends time stamp and corresponding value to Housekeeping Data container.
  188 + ***************************************************************************/
  189 +void GCOMHkd::append(const GTime& time, const double& value)
  190 +{
  191 + // Append time and value
  192 + m_times.append(time);
  193 + m_values.push_back(value);
  194 +
  195 + // Return
  196 + return;
  197 +}
  198 +
  199 +
  200 +/***********************************************************************//**
  201 + * @brief Remove Housekeeping Data
  202 + *
  203 + * @param[in] index Housekeeping Data index [0,...,size()[.
  204 + *
  205 + * Removes Housekeeping Data at @p index from the container. All data after
  206 + * the specified @p index are moved forward by one position.
  207 + ***************************************************************************/
  208 +void GCOMHkd::remove(const int& index)
  209 +{
  210 + #if defined(G_RANGE_CHECK)
  211 + // If index is outside boundary then throw an error
  212 + if (index < 0 || index >= size()) {
  213 + throw GException::out_of_range(G_REMOVE, "Housekeeping Data index",
  214 + index, size());
  215 + }
  216 + #endif
  217 +
  218 + // Remove time and erase value
  219 + m_times.remove(index);
  220 + m_values.erase(m_values.begin() + index);
  221 +
  222 + // Return
  223 + return;
  224 +}
  225 +
  226 +
  227 +/***********************************************************************//**
  228 + * @brief Extend Housekeeping Data
  229 + *
  230 + * @param[in] hkd Housekeeping Data container.
  231 + *
  232 + * Append Housekeeping Data container to existing container.
  233 + ***************************************************************************/
  234 +void GCOMHkd::extend(const GCOMHkd& hkd)
  235 +{
  236 + // Do nothing if Housekeeping Data container is empty
  237 + if (!hkd.is_empty()) {
  238 +
  239 + // Get size. Note that we extract the size first to avoid an
  240 + // endless loop that arises when a container is appended to
  241 + // itself.
  242 + int num = hkd.size();
  243 +
  244 + // Reserve enough space
  245 + reserve(size() + num);
  246 +
  247 + // Loop over all elements and append them to container
  248 + for (int i = 0; i < num; ++i) {
  249 + m_times.append(hkd.m_times[i]);
  250 + m_values.push_back(hkd.m_values[i]);
  251 + }
  252 +
  253 + } // endif: Housekeeping Data container was not empty
  254 +
  255 + // Return
  256 + return;
  257 +}
  258 +
  259 +
  260 +/***********************************************************************//**
  261 + * @brief Print Housekeeping Data container
  262 + *
  263 + * @param[in] chatter Chattiness.
  264 + * @return String containing Housekeeping Data container information.
  265 + ***************************************************************************/
  266 +std::string GCOMHkd::print(const GChatter& chatter) const
  267 +{
  268 + // Initialise result string
  269 + std::string result;
  270 +
  271 + // Continue only if chatter is not silent
  272 + if (chatter != SILENT) {
  273 +
  274 + // Append header
  275 + result.append("=== GCOMHkd ===");
  276 +
  277 + // Append information
  278 + result.append("\n"+gammalib::parformat("Parameter"));
  279 + result.append(m_name);
  280 + result.append("\n"+gammalib::parformat("Records"));
  281 + result.append(gammalib::str(size()));
  282 +
  283 + // If there are records then print time range
  284 + if (size() > 0) {
  285 +
  286 + // Get start and stop time
  287 + GTime tstart = m_times[0];
  288 + GTime tstop = m_times[size()-1];
  289 +
  290 + // Print time intervals
  291 + result.append("\n"+gammalib::parformat("TJD interval"));
  292 + result.append(gammalib::str(gammalib::com_tjd(tstart))+":");
  293 + result.append(gammalib::str(gammalib::com_tics(tstart))+" - ");
  294 + result.append(gammalib::str(gammalib::com_tjd(tstop))+":");
  295 + result.append(gammalib::str(gammalib::com_tics(tstop)));
  296 + result.append("\n"+gammalib::parformat("MJD interval"));
  297 + result.append(gammalib::str(tstart.mjd())+" - ");
  298 + result.append(gammalib::str(tstop.mjd())+" days");
  299 + result.append("\n"+gammalib::parformat("UTC interval"));
  300 + result.append(tstart.utc()+" - ");
  301 + result.append(tstop.utc());
  302 +
  303 + }
  304 +
  305 + } // endif: chatter was not silent
  306 +
  307 + // Return result
  308 + return result;
  309 +}
  310 +
  311 +
  312 +/*==========================================================================
  313 + = =
  314 + = Private methods =
  315 + = =
  316 + ==========================================================================*/
  317 +
  318 +/***********************************************************************//**
  319 + * @brief Initialise class members
  320 + ***************************************************************************/
  321 +void GCOMHkd::init_members(void)
  322 +{
  323 + // Initialise members
  324 + m_name.clear();
  325 + m_times.clear();
  326 + m_values.clear();
  327 +
  328 + // Return
  329 + return;
  330 +}
  331 +
  332 +
  333 +/***********************************************************************//**
  334 + * @brief Copy class members
  335 + *
  336 + * @param[in] hkd Housekeeping Data container.
  337 + ***************************************************************************/
  338 +void GCOMHkd::copy_members(const GCOMHkd& hkd)
  339 +{
  340 + // Copy members
  341 + m_name = hkd.m_name;
  342 + m_times = hkd.m_times;
  343 + m_values = hkd.m_values;
  344 +
  345 + // Return
  346 + return;
  347 +}
  348 +
  349 +
  350 +/***********************************************************************//**
  351 + * @brief Delete class members
  352 + ***************************************************************************/
  353 +void GCOMHkd::free_members(void)
  354 +{
  355 + // Return
  356 + return;
  357 +}
... ...
inst/com/src/GCOMHkds.cpp 0 → 100644
  1 +/***************************************************************************
  2 + * GCOMHkds.cpp - COMPTEL Housekeeping Data collection class *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2023 by Juergen Knodlseder *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software: you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation, either version 3 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + * This program is distributed in the hope that it will be useful, *
  13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  15 + * GNU General Public License for more details. *
  16 + * *
  17 + * You should have received a copy of the GNU General Public License *
  18 + * along with this program. If not, see <http://www.gnu.org/licenses/>. *
  19 + * *
  20 + ***************************************************************************/
  21 +/**
  22 + * @file GCOMHkds.hpp
  23 + * @brief COMPTEL Housekeeping Data collection class implementation
  24 + * @author Juergen Knodlseder
  25 + */
  26 +
  27 +/* __ Includes ___________________________________________________________ */
  28 +#ifdef HAVE_CONFIG_H
  29 +#include <config.h>
  30 +#endif
  31 +#include "GException.hpp"
  32 +#include "GMath.hpp"
  33 +#include "GFits.hpp"
  34 +#include "GFitsTable.hpp"
  35 +#include "GCOMTools.hpp"
  36 +#include "GCOMSupport.hpp"
  37 +#include "GCOMHkds.hpp"
  38 +
  39 +/* __ Method name definitions ____________________________________________ */
  40 +#define G_ACCESS "GCOMHkds::operator[](std::string&)"
  41 +#define G_AT "GCOMHkds::at(int&)"
  42 +#define G_SET1 "GCOMHkds::set(int&, GCOMHkd&)"
  43 +#define G_SET2 "GCOMHkds::set(std::string&, GCOMHkd&)"
  44 +#define G_INSERT "GCOMHkds::insert(int&, GCOMHkd&)"
  45 +#define G_REMOVE "GCOMHkds::remove(int&)"
  46 +#define G_READ "GCOMHkds::read(GFitsTable&)"
  47 +
  48 +/* __ Macros _____________________________________________________________ */
  49 +
  50 +/* __ Coding definitions _________________________________________________ */
  51 +
  52 +/* __ Debug definitions __________________________________________________ */
  53 +
  54 +
  55 +/*==========================================================================
  56 + = =
  57 + = Constructors/destructors =
  58 + = =
  59 + ==========================================================================*/
  60 +
  61 +/***********************************************************************//**
  62 + * @brief Void constructor
  63 + *
  64 + * Constructs an empty Housekeeping Data collection.
  65 + ***************************************************************************/
  66 +GCOMHkds::GCOMHkds(void)
  67 +{
  68 + // Initialise class members
  69 + init_members();
  70 +
  71 + // Return
  72 + return;
  73 +}
  74 +
  75 +
  76 +/***********************************************************************//**
  77 + * @brief Filename constructor
  78 + *
  79 + * @param[in] filename Housekeeping Data FITS file.
  80 + *
  81 + * Constructs a Housekeeping Data collection from a HKD FITS file.
  82 + ***************************************************************************/
  83 +GCOMHkds::GCOMHkds(const GFilename& filename)
  84 +{
  85 + // Initialise class members
  86 + init_members();
  87 +
  88 + // Load data
  89 + load(filename);
  90 +
  91 + // Return
  92 + return;
  93 +}
  94 +
  95 +
  96 +/***********************************************************************//**
  97 + * @brief Copy constructor
  98 + *
  99 + * @param[in] hkds Housekeeping Data collection.
  100 + ***************************************************************************/
  101 +GCOMHkds::GCOMHkds(const GCOMHkds& hkds)
  102 +{
  103 + // Initialise class members
  104 + init_members();
  105 +
  106 + // Copy members
  107 + copy_members(hkds);
  108 +
  109 + // Return
  110 + return;
  111 +}
  112 +
  113 +
  114 +/***********************************************************************//**
  115 + * @brief Destructor
  116 + ***************************************************************************/
  117 +GCOMHkds::~GCOMHkds(void)
  118 +{
  119 + // Free members
  120 + free_members();
  121 +
  122 + // Return
  123 + return;
  124 +}
  125 +
  126 +
  127 +/*==========================================================================
  128 + = =
  129 + = Operators =
  130 + = =
  131 + ==========================================================================*/
  132 +
  133 +/***********************************************************************//**
  134 + * @brief Assignment operator
  135 + *
  136 + * @param[in] hkds Housekeeping Data collection.
  137 + * @return Housekeeping Data collection.
  138 + ***************************************************************************/
  139 +GCOMHkds& GCOMHkds::operator=(const GCOMHkds& hkds)
  140 +{
  141 + // Execute only if object is not identical
  142 + if (this != &hkds) {
  143 +
  144 + // Free members
  145 + free_members();
  146 +
  147 + // Initialise private members
  148 + init_members();
  149 +
  150 + // Copy members
  151 + copy_members(hkds);
  152 +
  153 + } // endif: object was not identical
  154 +
  155 + // Return this object
  156 + return *this;
  157 +}
  158 +
  159 +
  160 +/***********************************************************************//**
  161 + * @brief Return reference to Housekeeping Data container
  162 + *
  163 + * @param[in] name Housekeeping parameter name.
  164 + * @return Reference to Housekeeping Data container.
  165 + *
  166 + * @exception GException::invalid_argument
  167 + * Housekeeping parameter with specified @p name not found in
  168 + * collection.
  169 + *
  170 + * Returns a reference to the Housekeeping Data container with the specified
  171 + * @p name. An exception is thrown if the specified @p name is not found
  172 + * in the collection.
  173 + ***************************************************************************/
  174 +GCOMHkd& GCOMHkds::operator[](const std::string& name)
  175 +{
  176 + // Get model index
  177 + int index = get_index(name);
  178 +
  179 + // Throw exception if model name was not found
  180 + if (index == -1) {
  181 + std::string msg = "Housekeeping parameter \""+name+"\" not found in "
  182 + "Housekeeping Data collection. Please specify a "
  183 + "valid housekeeping parameter name.";
  184 + throw GException::invalid_argument(G_ACCESS, msg);
  185 + }
  186 +
  187 + // Return reference
  188 + return m_hkds[index];
  189 +}
  190 +
  191 +
  192 +/***********************************************************************//**
  193 + * @brief Return reference to Housekeeping Data container (const version)
  194 + *
  195 + * @param[in] name Housekeeping parameter name.
  196 + * @return Reference to Housekeeping Data container.
  197 + *
  198 + * @exception GException::invalid_argument
  199 + * Housekeeping parameter with specified @p name not found in
  200 + * collection.
  201 + *
  202 + * Returns a reference to the Housekeeping Data container with the specified
  203 + * @p name. An exception is thrown if the specified @p name is not found
  204 + * in the collection.
  205 + ***************************************************************************/
  206 +const GCOMHkd& GCOMHkds::operator[](const std::string& name) const
  207 +{
  208 + // Get model index
  209 + int index = get_index(name);
  210 +
  211 + // Throw exception if model name was not found
  212 + if (index == -1) {
  213 + std::string msg = "Housekeeping parameter \""+name+"\" not found in "
  214 + "Housekeeping Data collection. Please specify a "
  215 + "valid housekeeping parameter name.";
  216 + throw GException::invalid_argument(G_ACCESS, msg);
  217 + }
  218 +
  219 + // Return reference
  220 + return m_hkds[index];
  221 +}
  222 +
  223 +
  224 +/*==========================================================================
  225 + = =
  226 + = Public methods =
  227 + = =
  228 + ==========================================================================*/
  229 +
  230 +/***********************************************************************//**
  231 + * @brief Clear Housekeeping Data collection
  232 + ***************************************************************************/
  233 +void GCOMHkds::clear(void)
  234 +{
  235 + // Free members
  236 + free_members();
  237 +
  238 + // Initialise private members
  239 + init_members();
  240 +
  241 + // Return
  242 + return;
  243 +}
  244 +
  245 +
  246 +/***********************************************************************//**
  247 + * @brief Clone Housekeeping Data collection
  248 + *
  249 + * @return Pointer to deep copy of Housekeeping Data collection.
  250 + ***************************************************************************/
  251 +GCOMHkds* GCOMHkds::clone(void) const
  252 +{
  253 + return new GCOMHkds(*this);
  254 +}
  255 +
  256 +
  257 +/***********************************************************************//**
  258 + * @brief Return reference to Housekeeping Data container
  259 + *
  260 + * @param[in] index Housekeeping Data index [0,...,size()-1].
  261 + * @return Reference to Housekeeping Data container.
  262 + *
  263 + * @exception GException::out_of_range
  264 + * Housekeeping Data container @p index is out of range.
  265 + *
  266 + * Returns a reference to the Housekeeping Data container with the specified
  267 + * @p index.
  268 + ***************************************************************************/
  269 +GCOMHkd& GCOMHkds::at(const int& index)
  270 +{
  271 + // Raise exception if index is out of range
  272 + if (index < 0 || index >= size()) {
  273 + std::string msg = "Housekeeping Data container index";
  274 + throw GException::out_of_range(G_AT, msg, index, size());
  275 + }
  276 +
  277 + // Return reference
  278 + return m_hkds[index];
  279 +}
  280 +
  281 +
  282 +/***********************************************************************//**
  283 + * @brief Return reference to Housekeeping Data container (const version)
  284 + *
  285 + * @param[in] index Housekeeping Data index [0,...,size()-1].
  286 + * @return Reference to Housekeeping Data container.
  287 + *
  288 + * @exception GException::out_of_range
  289 + * Housekeeping Data container @p index is out of range.
  290 + *
  291 + * Returns a reference to the Housekeeping Data container with the specified
  292 + * @p index.
  293 + ***************************************************************************/
  294 +const GCOMHkd& GCOMHkds::at(const int& index) const
  295 +{
  296 + // Raise exception if index is out of range
  297 + if (index < 0 || index >= size()) {
  298 + std::string msg = "Housekeeping Data container index";
  299 + throw GException::out_of_range(G_AT, msg, index, size());
  300 + }
  301 +
  302 + // Return reference
  303 + return m_hkds[index];
  304 +}
  305 +
  306 +
  307 +/***********************************************************************//**
  308 + * @brief Set Housekeeping Data container in collection
  309 + *
  310 + * @param[in] index Housekeeping Data container index [0,...,size()[.
  311 + * @param[in] hkd Housekeeping Data container.
  312 + * @return Reference to deep copy of Housekeeping Data container.
  313 + *
  314 + * @exception GException::out_of_range
  315 + * Housekeeping Data container @p index is out of range.
  316 + * @exception GException::invalid_value
  317 + * Housekeeping parameter exists already in collection at other
  318 + * index.
  319 + *
  320 + * Set Housekeeping Data container in the collection. Note that each
  321 + * housekeeping parameter can only exist once in an collection, hence an
  322 + * exception will be thrown if the same housekeeping parameter exists already
  323 + * at another index. A deep copy of the Housekeeping Data container will be
  324 + * made.
  325 + ***************************************************************************/
  326 +GCOMHkd& GCOMHkds::set(const int& index, const GCOMHkd& hkd)
  327 +{
  328 + // Compile option: raise exception if index is out of range
  329 + #if defined(G_RANGE_CHECK)
  330 + if (index < 0 || index >= size()) {
  331 + std::string msg = "Housekeeping Data container index";
  332 + throw GException::out_of_range(G_SET1, msg, index, size());
  333 + }
  334 + #endif
  335 +
  336 + // Check if a container with specified name does not yet exist
  337 + int inx = get_index(hkd.name());
  338 + if (inx != -1 && inx != index) {
  339 + std::string msg =
  340 + "Attempt to set Housekeeping Data container with name \""+
  341 + hkd.name()+"\" in collection at index "+gammalib::str(index)+
  342 + ", but a Housekeeping Data container with the same name exists "
  343 + "already at index "+gammalib::str(inx)+" in the collection. "
  344 + "Every Housekeeping Data container in the collection needs a "
  345 + "unique name.";
  346 + throw GException::invalid_value(G_SET1, msg);
  347 + }
  348 +
  349 + // Assign Housekeeping Data container
  350 + m_hkds[index] = hkd;
  351 +
  352 + // Return reference to Housekeeping Data container
  353 + return m_hkds[index];
  354 +}
  355 +
  356 +
  357 +/***********************************************************************//**
  358 + * @brief Set Housekeeping Data container in collection
  359 + *
  360 + * @param[in] name Housekeeping parameter name.
  361 + * @param[in] hkd Housekeeping Data container.
  362 + * @return Reference to deep copy of Housekeeping Data container.
  363 + *
  364 + * @exception GException::invalid_argument
  365 + * Housekeeping parameter with specified @p name not found in
  366 + * collection.
  367 + * @exception GException::invalid_value
  368 + * Name of Housekeeping parameter exists already in collection.
  369 + *
  370 + * Set Housekeeping Data container in the collection replacing the container
  371 + * with the specified Housekeeping parameter @p name. Note that each
  372 + * housekeeping parameter can only exist once in an collection, hence an
  373 + * exception will be thrown if the same housekeeping parameter exists already
  374 + * at another index. A deep copy of the Housekeeping Data container will be
  375 + * made.
  376 + ***************************************************************************/
  377 +GCOMHkd& GCOMHkds::set(const std::string& name, const GCOMHkd& hkd)
  378 +{
  379 + // Get parameter index
  380 + int index = get_index(name);
  381 +
  382 + // Throw exception if parameter name was not found
  383 + if (index == -1) {
  384 + std::string msg = "Housekeeping parameter \""+name+"\" not found in "
  385 + "Housekeeping Data collection. Please specify a "
  386 + "Housekeeping parameter name that exists in the "
  387 + "collection.";
  388 + throw GException::invalid_argument(G_SET2, msg);
  389 + }
  390 +
  391 + // Check if a container with specified name does not yet exist
  392 + int inx = get_index(hkd.name());
  393 + if (inx != -1 && inx != index) {
  394 + std::string msg =
  395 + "Attempt to set Housekeeping Data container with name \""+
  396 + hkd.name()+"\" in collection at index "+gammalib::str(index)+
  397 + ", but a Housekeeping Data container with the same name exists "
  398 + "already at index "+gammalib::str(inx)+" in the collection. "
  399 + "Every Housekeeping Data container in the collection needs a "
  400 + "unique name.";
  401 + throw GException::invalid_value(G_SET2, msg);
  402 + }
  403 +
  404 + // Assign Housekeeping Data container
  405 + m_hkds[index] = hkd;
  406 +
  407 + // Return reference to Housekeeping Data container
  408 + return m_hkds[index];
  409 +}
  410 +
  411 +
  412 +/***********************************************************************//**
  413 + * @brief Append Housekeeping Data container to collection
  414 + *
  415 + * @param[in] hkd Housekeeping Data container.
  416 + * @return Reference to appended Housekeeping Data container.
  417 + *
  418 + * Appends Housekeeping Data container to the collection by making a deep
  419 + * copy of specified container.
  420 + ***************************************************************************/
  421 +GCOMHkd& GCOMHkds::append(const GCOMHkd& hkd)
  422 +{
  423 + // Append housekeeping data container to list
  424 + m_hkds.push_back(hkd);
  425 +
  426 + // Return reference
  427 + return m_hkds[size()-1];
  428 +}
  429 +
  430 +
  431 +/***********************************************************************//**
  432 + * @brief Insert Housekeeping Data container into collection
  433 + *
  434 + * @param[in] index Housekeeping Data container index (0,...,size()-1).
  435 + * @param[in] hkd Housekeeping Data container.
  436 + * @return Reference to inserted Housekeeping Data container.
  437 + *
  438 + * @exception GException::out_of_range
  439 + * Housekeeping Data container index is out of range.
  440 + *
  441 + * Inserts an @p Housekeeping Data container into the collection before the
  442 + * Housekeeping Data container with the specified @p index.
  443 + ***************************************************************************/
  444 +GCOMHkd& GCOMHkds::insert(const int& index, const GCOMHkd& hkd)
  445 +{
  446 + // Compile option: raise exception if index is out of range
  447 + #if defined(G_RANGE_CHECK)
  448 + if (is_empty()) {
  449 + if (index > 0) {
  450 + std::string msg = "Housekeeping Data container index";
  451 + throw GException::out_of_range(G_INSERT, msg, index, size());
  452 + }
  453 + }
  454 + else {
  455 + if (index < 0 || index >= size()) {
  456 + std::string msg = "Housekeeping Data container index";
  457 + throw GException::out_of_range(G_INSERT, msg, index, size());
  458 + }
  459 + }
  460 + #endif
  461 +
  462 + // Inserts Housekeeping Data container into collection
  463 + m_hkds.insert(m_hkds.begin()+index, hkd);
  464 +
  465 + // Return reference
  466 + return m_hkds[index];
  467 +}
  468 +
  469 +
  470 +/***********************************************************************//**
  471 + * @brief Remove Housekeeping Data container from collection
  472 + *
  473 + * @param[in] index Housekeeping Data container index (0,...,size()-1).
  474 + *
  475 + * @exception GException::out_of_range
  476 + * Housekeeping Data container index is out of range.
  477 + *
  478 + * Remove Housekeeping Data container of specified @p index from collection.
  479 + ***************************************************************************/
  480 +void GCOMHkds::remove(const int& index)
  481 +{
  482 + // Compile option: raise exception if index is out of range
  483 + #if defined(G_RANGE_CHECK)
  484 + if (index < 0 || index >= size()) {
  485 + std::string msg = "Housekeeping Data container index";
  486 + throw GException::out_of_range(G_REMOVE, msg, index, size());
  487 + }
  488 + #endif
  489 +
  490 + // Erase Housekeeping Data container from collection
  491 + m_hkds.erase(m_hkds.begin() + index);
  492 +
  493 + // Return
  494 + return;
  495 +}
  496 +
  497 +
  498 +/***********************************************************************//**
  499 + * @brief Signals if Housekeeping parameter exists in collection
  500 + *
  501 + * @param[in] name Housekeeping parameter name.
  502 + * @return True if Housekeeping parameter with specified @p name exists.
  503 + *
  504 + * Searches the collection for a given Housekeeping parameter @p name. The
  505 + * method returns @c true if the specified @p name was found.
  506 + ***************************************************************************/
  507 +bool GCOMHkds::contains(const std::string& name) const
  508 +{
  509 + // Get model index
  510 + int index = get_index(name);
  511 +
  512 + // Return
  513 + return (index != -1);
  514 +}
  515 +
  516 +
  517 +/***********************************************************************//**
  518 + * @brief Extend Housekeeping Data collection
  519 + *
  520 + * @param[in] hkds Housekeeping Data collection.
  521 + *
  522 + * Extend Housekeeping Data collection by extending the container for each
  523 + * Housekeeping parameter.
  524 + ***************************************************************************/
  525 +void GCOMHkds::extend(const GCOMHkds& hkds)
  526 +{
  527 + // Continue only if specified Housekeeping Data collection is not empty
  528 + if (!hkds.is_empty()) {
  529 +
  530 + // Loop over all housekeeping parameters
  531 + for (int i = 0; i < hkds.size(); ++i) {
  532 +
  533 + // If parameter exists already in collection then extend the
  534 + // corresponding container
  535 + if (contains(hkds[i].name())) {
  536 + m_hkds[i].extend(hkds[i]);
  537 + }
  538 +
  539 + // ... otherwise append container to collection
  540 + else {
  541 + append(hkds[i]);
  542 + }
  543 +
  544 + } // endfor: looped over housekeeping parameters
  545 +
  546 + } // endif: Specified Housekeeping Data collection was not empty
  547 +
  548 + // Return
  549 + return;
  550 +}
  551 +
  552 +
  553 +/***********************************************************************//**
  554 + * @brief Load Housekeeping Data collection from FITS file
  555 + *
  556 + * @param[in] filename COMPTEL HKD FITS file name.
  557 + *
  558 + * Load a Housekeeping Data collection from a HKD FITS file into the
  559 + * collection.
  560 + ***************************************************************************/
  561 +void GCOMHkds::load(const GFilename& filename)
  562 +{
  563 + // Open FITS file
  564 + GFits fits(filename);
  565 +
  566 + // Get HDU (pointer is always valid)
  567 + const GFitsTable& hdu = *fits.table(1);
  568 +
  569 + // Read Housekeeping Data FITS table
  570 + read(hdu);
  571 +
  572 + // Close FITS file
  573 + fits.close();
  574 +
  575 + // Return
  576 + return;
  577 +}
  578 +
  579 +
  580 +/***********************************************************************//**
  581 + * @brief Read Housekeeping Data collection from FITS table
  582 + *
  583 + * @param[in] table COMPTEL HKD FITS table.
  584 + *
  585 + * Reads a Housekeeping Data collection from a FITS table into the
  586 + * collection.
  587 + ***************************************************************************/
  588 +void GCOMHkds::read(const GFitsTable& table)
  589 +{
  590 + // Clear
  591 + clear();
  592 +
  593 + // Extract number of records in FITS table
  594 + int num = table.nrows();
  595 +
  596 + // If there are records in FITS table then extract housekeeping data
  597 + if (num > 0) {
  598 +
  599 + // Get column pointers
  600 + const GFitsTableCol* ptr_tjd = table["TJD"]; // days
  601 + const GFitsTableCol* ptr_tics = table["TICS"]; // ticks
  602 + const GFitsTableCol* ptr_parameter = table["PARAMETER"];
  603 + const GFitsTableCol* ptr_value = table["VALUE"];
  604 +
  605 + // Loop over HKD records
  606 + for (int i = 0; i < num; ++i) {
  607 +
  608 + // Get reference to Housekeeping Data container by either
  609 + // returning an existing reference or by appending a new
  610 + // housekeeping parameter to the collection
  611 + GCOMHkd* hkd;
  612 + int index = get_index(ptr_parameter->string(i));
  613 + if (index == -1) {
  614 + hkd = &(append(GCOMHkd(ptr_parameter->string(i))));
  615 + }
  616 + else {
  617 + hkd = &((*this)[index]);
  618 + }
  619 +
  620 + // Append time and value to Housekeeping Data container
  621 + hkd->append(gammalib::com_time(ptr_tjd->integer(i), ptr_tics->integer(i)),
  622 + ptr_value->real(i));
  623 +
  624 + } // endfor: looped over HKD records
  625 +
  626 + } // endif: there were records in FITS table
  627 +
  628 + // Return
  629 + return;
  630 +}
  631 +
  632 +
  633 +/***********************************************************************//**
  634 + * @brief Print Housekeeping Data collection
  635 + *
  636 + * @param[in] chatter Chattiness.
  637 + * @return String containing Housekeeping Data collection information.
  638 + ***************************************************************************/
  639 +std::string GCOMHkds::print(const GChatter& chatter) const
  640 +{
  641 + // Initialise result string
  642 + std::string result;
  643 +
  644 + // Continue only if chatter is not silent
  645 + if (chatter != SILENT) {
  646 +
  647 + // Append header
  648 + result.append("=== GCOMHkds ===");
  649 +
  650 + // Append container information
  651 + result.append("\n"+gammalib::parformat("Parameters"));
  652 + result.append(gammalib::str(size()));
  653 +
  654 + // Append information on housekeeping parameters
  655 + for (int i = 0; i < size(); ++i) {
  656 + result.append("\n"+gammalib::parformat((*this)[i].name()));
  657 + result.append(gammalib::str((*this)[i].size()));
  658 + }
  659 +
  660 + } // endif: chatter was not silent
  661 +
  662 + // Return result
  663 + return result;
  664 +}
  665 +
  666 +
  667 +/*==========================================================================
  668 + = =
  669 + = Private methods =
  670 + = =
  671 + ==========================================================================*/
  672 +
  673 +/***********************************************************************//**
  674 + * @brief Initialise class members
  675 + ***************************************************************************/
  676 +void GCOMHkds::init_members(void)
  677 +{
  678 + // Initialise members
  679 + m_hkds.clear();
  680 +
  681 + // Return
  682 + return;
  683 +}
  684 +
  685 +
  686 +/***********************************************************************//**
  687 + * @brief Copy class members
  688 + *
  689 + * @param[in] hkds Housekeeping Data collection.
  690 + ***************************************************************************/
  691 +void GCOMHkds::copy_members(const GCOMHkds& hkds)
  692 +{
  693 + // Copy members
  694 + m_hkds = hkds.m_hkds;
  695 +
  696 + // Return
  697 + return;
  698 +}
  699 +
  700 +
  701 +/***********************************************************************//**
  702 + * @brief Delete class members
  703 + ***************************************************************************/
  704 +void GCOMHkds::free_members(void)
  705 +{
  706 + // Return
  707 + return;
  708 +}
  709 +
  710 +
  711 +/***********************************************************************//**
  712 + * @brief Return Housekeeping Data container index by parameter name
  713 + *
  714 + * @param[in] name Housekeeping parameter name.
  715 + * @return Housekeeping parameter index (-1 if Housekeeping parameter name
  716 + * has not been found)
  717 + *
  718 + * Returns Housekeeping Data container index based on the specified
  719 + * housekeeping parameter @p name. If no Housekeeping Data container with the
  720 + * specified @p name is found the method returns -1.
  721 + ***************************************************************************/
  722 +int GCOMHkds::get_index(const std::string& name) const
  723 +{
  724 + // Initialise index
  725 + int index = -1;
  726 +
  727 + // Search Housekeeping Data with specified name
  728 + for (int i = 0; i < size(); ++i) {
  729 + if (m_hkds[i].name() == name) {
  730 + index = i;
  731 + break;
  732 + }
  733 + }
  734 +
  735 + // Return index
  736 + return index;
  737 +}
... ...