From 24af49bb5cb897d39aad9992a0fde9ed4b8d7f80 Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Fri, 10 Oct 2014 21:27:43 +0200 Subject: [PATCH] ctbkgcube now derives from ctool class, removed get_ebounds() method as it is provided by the base class --- pyext/ctbin.i | 1 - pyext/ctbkgcube.i | 10 ++++------ src/ctbin/ctbin.cpp | 1 - src/ctbkgcube/Makefile.am | 5 ++++- src/ctbkgcube/ctbkgcube.cpp | 112 ++++++++++------------------------------------------------------------------------------------------------------ src/ctbkgcube/ctbkgcube.hpp | 14 +++++++------- 6 files changed, 25 insertions(+), 118 deletions(-) diff --git a/pyext/ctbin.i b/pyext/ctbin.i index 501deb7..a485cee 100644 --- a/pyext/ctbin.i +++ b/pyext/ctbin.i @@ -26,7 +26,6 @@ %{ /* Put headers and other declarations here that are needed for compilation */ #include "ctbin.hpp" -#include "GTools.hpp" %} diff --git a/pyext/ctbkgcube.i b/pyext/ctbkgcube.i index 6f9b6ae..cc4cb1e 100644 --- a/pyext/ctbkgcube.i +++ b/pyext/ctbkgcube.i @@ -1,5 +1,5 @@ /*************************************************************************** - * ctbkgcube - CTA background cube tool * + * ctbkgcube - Background cube generation tool * * ----------------------------------------------------------------------- * * copyright (C) 2014 by Chia-Chun Lu * * ----------------------------------------------------------------------- * @@ -20,23 +20,21 @@ ***************************************************************************/ /** * @file ctbkgcube.i - * @brief CTA background cube tool definition + * @brief Background cube generation tool definition * @author Chia-Chun Lu */ %{ /* Put headers and other declarations here that are needed for compilation */ #include "ctbkgcube.hpp" -#include "GTools.hpp" %} /***********************************************************************//** * @class ctbkgcube * - * @brief CTA background cube tool + * @brief Background cube generation tool ***************************************************************************/ class ctbkgcube : public GApplication { - public: // Constructors and destructors ctbkgcube(void); @@ -54,7 +52,7 @@ public: }; /***********************************************************************//** - * @brief CTA background cube tool Python extension + * @brief Background cube generation tool Python extension ***************************************************************************/ %extend ctbkgcube { ctbkgcube copy() { diff --git a/src/ctbin/ctbin.cpp b/src/ctbin/ctbin.cpp index a3aa5c5..a534d8e 100644 --- a/src/ctbin/ctbin.cpp +++ b/src/ctbin/ctbin.cpp @@ -35,7 +35,6 @@ /* __ Method name definitions ____________________________________________ */ #define G_INIT_CUBE "ctbin::init_cube()" #define G_FILL_CUBE "ctbin::fill_cube(GCTAObservation*)" -#define G_GET_EBOUNDS "ctbin::get_ebounds()" /* __ Debug definitions __________________________________________________ */ diff --git a/src/ctbkgcube/Makefile.am b/src/ctbkgcube/Makefile.am index fa55a8a..fde8dec 100644 --- a/src/ctbkgcube/Makefile.am +++ b/src/ctbkgcube/Makefile.am @@ -1,5 +1,8 @@ ## Process this file with automake to produce Makefile.in +# Set include directories +INCLUDES = -I$(top_srcdir)/src/support + # Program name bin_PROGRAMS = ctbkgcube @@ -14,7 +17,7 @@ libctbkgcube_la_SOURCES = $(sources) ctbkgcube_SOURCES = main.cpp ctbkgcube_LDFLAGS = $(LIB_LINK_OPTION) @LDFLAGS@ ctbkgcube_CPPFLAGS = @CPPFLAGS@ -ctbkgcube_LDADD = libctbkgcube.la +ctbkgcube_LDADD = libctbkgcube.la $(top_srcdir)/src/support/libsupport.la # Parameter files pfilesdir = $(prefix)/syspfiles diff --git a/src/ctbkgcube/ctbkgcube.cpp b/src/ctbkgcube/ctbkgcube.cpp index 1b0a04e..18f0cd9 100644 --- a/src/ctbkgcube/ctbkgcube.cpp +++ b/src/ctbkgcube/ctbkgcube.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * ctbkgcube - CTA background cube tool * + * ctbkgcube - Background cube generation tool * * ----------------------------------------------------------------------- * * copyright (C) 2014 by Chia-Chun Lu * * ----------------------------------------------------------------------- * @@ -20,7 +20,7 @@ ***************************************************************************/ /** * @file ctbkgcube.cpp - * @brief CTA background cube tool implementation + * @brief Background cube generation tool definition * @author Chia-Chun Lu */ @@ -35,7 +35,6 @@ /* __ Method name definitions ____________________________________________ */ #define G_GET_PARAMETERS "ctbkgcube::get_parameters()" #define G_GET_OBS "ctbkgcube::get_obs()" -#define G_GET_EBOUNDS "ctbkgcube::get_ebounds()" #define G_SET_FROM_CNTMAP "ctbkgcube::set_from_cntmap(std::string&)" #define G_FILL_CUBE "ctbkgcube::fill_cube(GCTAObservation*)" @@ -53,14 +52,11 @@ /***********************************************************************//** * @brief Void constructor ***************************************************************************/ -ctbkgcube::ctbkgcube(void) : GApplication(CTBKGCUBE_NAME, CTBKGCUBE_VERSION) +ctbkgcube::ctbkgcube(void) : ctool(CTBKGCUBE_NAME, CTBKGCUBE_VERSION) { // Initialise members init_members(); - // Write header into logger - log_header(); - // Return return; } @@ -75,7 +71,7 @@ ctbkgcube::ctbkgcube(void) : GApplication(CTBKGCUBE_NAME, CTBKGCUBE_VERSION) * observations container. ***************************************************************************/ ctbkgcube::ctbkgcube(const GObservations& obs) : - GApplication(CTBKGCUBE_NAME, CTBKGCUBE_VERSION) + ctool(CTBKGCUBE_NAME, CTBKGCUBE_VERSION) { // Initialise members init_members(); @@ -83,9 +79,6 @@ ctbkgcube::ctbkgcube(const GObservations& obs) : // Set observations m_obs = obs; - // Write header into logger - log_header(); - // Return return; } @@ -99,14 +92,11 @@ ctbkgcube::ctbkgcube(const GObservations& obs) : * @param[in] argv Array of command line arguments. ***************************************************************************/ ctbkgcube::ctbkgcube(int argc, char *argv[]) : - GApplication(CTBKGCUBE_NAME, CTBKGCUBE_VERSION, argc, argv) + ctool(CTBKGCUBE_NAME, CTBKGCUBE_VERSION, argc, argv) { // Initialise members init_members(); - // Write header into logger - log_header(); - // Return return; } @@ -117,7 +107,7 @@ ctbkgcube::ctbkgcube(int argc, char *argv[]) : * * @param[in] app ctbkgcube application. ***************************************************************************/ -ctbkgcube::ctbkgcube(const ctbkgcube& app) : GApplication(app) +ctbkgcube::ctbkgcube(const ctbkgcube& app) : ctool(app) { // Initialise members init_members(); @@ -161,7 +151,7 @@ ctbkgcube& ctbkgcube::operator=(const ctbkgcube& app) if (this != &app) { // Copy base class members - this->GApplication::operator=(app); + this->ctool::operator=(app); // Free members free_members(); @@ -192,10 +182,12 @@ void ctbkgcube::clear(void) { // Free members free_members(); + this->ctool::free_members(); this->GApplication::free_members(); // Initialise members this->GApplication::init_members(); + this->ctool::init_members(); init_members(); // Return @@ -472,11 +464,6 @@ void ctbkgcube::copy_members(const ctbkgcube& app) ***************************************************************************/ void ctbkgcube::free_members(void) { - // Write separator into logger - if (logTerse()) { - log << std::endl; - } - // Return return; } @@ -530,7 +517,7 @@ void ctbkgcube::get_parameters(void) int nypix = (*this)["nypix"].integer(); // Get energy definition - get_ebounds(); + m_ebounds = get_ebounds(); // Define skymap for background cube GSkymap map(proj, coordsys, xref, yref, @@ -613,85 +600,6 @@ void ctbkgcube::get_obs(void) /***********************************************************************//** - * @brief Get energy boundaries from parameters - * - * @exception GException::invalid_value - * Energy bin definition file not defined or invalid extension - * name encountered. - * - * Get the energy boundaries from the user parameters. - ***************************************************************************/ -void ctbkgcube::get_ebounds(void) -{ - // Determine the energy binning alogrithm - std::string ebinalg = (*this)["ebinalg"].string(); - - // If we have the binning given by a file then try to get the boundaries - // from that file - if (ebinalg == "FILE") { - - // Get filename - std::string filename = (*this)["ebinfile"].filename(); - - // Check whether infile parameter is undefined - if (gammalib::toupper(filename) == "NONE") { - std::string msg = "No energy bin definition file specified. " - "Please set the \"ebinfile\" parameter to a " - "file containing the energy bin definition."; - throw GException::invalid_value(G_GET_EBOUNDS, msg); - } - - // Open fits file to check which extension is given - GFits file(filename); - - // Check first for EBOUNDS extension - if (file.contains("EBOUNDS")) { - file.close(); - m_ebounds.load(filename, "EBOUNDS"); - } - - // ... then check for ENERGYBINS extension - else if (file.contains("ENERGYBINS")) { - file.close(); - m_ebounds.load(filename, "ENERGYBINS"); - } - - // ... otherwise throw an exception - else { - file.close(); - std::string msg = "No extension with name \"EBOUNDS\" or" - " \"ENERGYBINS\" found in FITS file" - " \""+filename+"\".\n" - "An \"EBOUNDS\" or \"ENERGYBINS\" extension" - " is required if the parameter \"ebinalg\"" - " is set to \"FILE\"."; - throw GException::invalid_value(G_GET_EBOUNDS, msg); - } - } - - // ... otherwise read emin, emax and nebins - else { - - // Get the relevant parameters - double emin = (*this)["emin"].real(); - double emax = (*this)["emax"].real(); - int enumbins = (*this)["enumbins"].integer(); - bool log = ((*this)["ebinalg"].string() == "LIN") ? false : true; - - // Create energy boundaries - m_ebounds = GEbounds(enumbins, - GEnergy(emin, "TeV"), - GEnergy(emax, "TeV"), - log); - - } - - // Return - return; -} - - -/***********************************************************************//** * @brief Set background cube definition from counts map * * @exception GException::invalid_value diff --git a/src/ctbkgcube/ctbkgcube.hpp b/src/ctbkgcube/ctbkgcube.hpp index 745c127..4024237 100644 --- a/src/ctbkgcube/ctbkgcube.hpp +++ b/src/ctbkgcube/ctbkgcube.hpp @@ -1,5 +1,5 @@ /*************************************************************************** - * ctbkgcube - CTA background cube tool * + * ctbkgcube - Background cube generation tool * * ----------------------------------------------------------------------- * * copyright (C) 2014 by Chia-Chun Lu * * ----------------------------------------------------------------------- * @@ -20,7 +20,7 @@ ***************************************************************************/ /** * @file ctbkgcube.hpp - * @brief CTA background cube tool definition + * @brief Background cube generation tool definition * @author Chia-Chun Lu */ @@ -30,6 +30,7 @@ /* __ Includes ___________________________________________________________ */ #include "GammaLib.hpp" #include "GCTALib.hpp" +#include "ctool.hpp" /* __Definitions _________________________________________________________ */ #define CTBKGCUBE_NAME "ctbkgcube" @@ -39,9 +40,9 @@ /***********************************************************************//** * @class ctbkgcube * - * @brief CTA background cube tool + * @brief Background cube generation tool ***************************************************************************/ -class ctbkgcube : public GApplication { +class ctbkgcube : public ctool { public: // Constructors and destructors @@ -68,7 +69,6 @@ protected: void free_members(void); void get_parameters(void); void get_obs(void); - void get_ebounds(void); void set_from_cntmap(const std::string& filename); void fill_cube(GCTAObservation* obs); @@ -83,9 +83,9 @@ protected: /***********************************************************************//** - * @brief Return CTA event cube containing background rate + * @brief Return event cube containing background rate * - * @return CTA event cube. + * @return Background event cube. ***************************************************************************/ inline const GCTAEventCube& ctbkgcube::cube(void) const -- libgit2 0.21.4