From bbd08db3a6caafdd031dce7744ded754946cb97c Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Tue, 15 Mar 2016 01:24:41 +0100 Subject: [PATCH] Add ctool::get_obs_header() method. --- pyext/ctool.i | 2 ++ src/support/ctool.cpp | 33 +++++++++++++++++++++++++++++++++ src/support/ctool.hpp | 11 ++++++----- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/pyext/ctool.i b/pyext/ctool.i index 3f6c940..89234ec 100644 --- a/pyext/ctool.i +++ b/pyext/ctool.i @@ -99,6 +99,7 @@ public: %rename(_set_obs_bounds) set_obs_bounds(GObservations& obs); %rename(_get_mean_pointing) get_mean_pointing(const GObservations& obs); %rename(_get_current_rss) get_current_rss(); + %rename(_get_obs_header) get_obs_header(); // Protected methods const bool& read_ahead(void) const; @@ -122,6 +123,7 @@ public: void set_obs_bounds(GObservations& obs); GSkyDir get_mean_pointing(const GObservations& obs); size_t get_current_rss(void); + std::string get_obs_header(const GObservation* obs); }; diff --git a/src/support/ctool.cpp b/src/support/ctool.cpp index 5cc444d..dd9608a 100644 --- a/src/support/ctool.cpp +++ b/src/support/ctool.cpp @@ -1108,6 +1108,39 @@ size_t ctool::get_current_rss(void) /***********************************************************************//** + * @brief Return observation header string + * + * @param[in] obs Pointer to observation. + * @return String containing observation information. + * + * Returns a string that contains observation information, including the + * instrument name, the observation name, and the observation ID. The format + * of the string is + * + * XXX observation "name" (id=YYYYY) + * + ***************************************************************************/ +std::string ctool::get_obs_header(const GObservation* obs) +{ + // Initialise header string + std::string header = obs->instrument() + " observation"; + + // If observation name is not empty then add name + if (!obs->name().empty()) { + header += " \"" + obs->name() + "\""; + } + + // If observation ID is not empty then add ID + if (!obs->id().empty()) { + header += " (id=" + obs->id() +")"; + } + + // Return header + return header; +} + + +/***********************************************************************//** * @brief Dumps help text in the console ***************************************************************************/ void ctool::provide_help(void) const diff --git a/src/support/ctool.hpp b/src/support/ctool.hpp index 5355efa..e26a008 100644 --- a/src/support/ctool.hpp +++ b/src/support/ctool.hpp @@ -1,7 +1,7 @@ /*************************************************************************** * ctool - ctool base class * * ----------------------------------------------------------------------- * - * copyright (C) 2014-2015 by Juergen Knoedlseder * + * copyright (C) 2014-2016 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -90,17 +90,18 @@ protected: void set_obs_bounds(GObservations& obs); GSkyDir get_mean_pointing(const GObservations& obs); size_t get_current_rss(void); + std::string get_obs_header(const GObservation* obs); // Protected members - bool m_read_ahead; //!< Read ahead parameters + bool m_read_ahead; //!< Read ahead output parameters protected: // Protected methods - void provide_help(void) const; + void provide_help(void) const; // Protected members - bool m_use_xml; //!< Use XML file instead of FITS file for observations - GTimeReference m_cta_ref; //!< CTA time reference + bool m_use_xml; //!< Use XML file instead of FITS file for observations + GTimeReference m_cta_ref; //!< CTA time reference }; -- libgit2 0.21.4