From 50a8694217ed666339d64d198d3713637f0a92f5 Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Sun, 6 Dec 2015 22:22:54 +0100 Subject: [PATCH] Throw an exception if an event list is provided as input to ctcubemask. --- pyext/ctool.i | 1 + src/ctcubemask/ctcubemask.cpp | 15 +++++---------- src/support/ctool.cpp | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++- src/support/ctool.hpp | 1 + 4 files changed, 60 insertions(+), 11 deletions(-) diff --git a/pyext/ctool.i b/pyext/ctool.i index 19d2c80..1fdee62 100644 --- a/pyext/ctool.i +++ b/pyext/ctool.i @@ -99,6 +99,7 @@ public: // Protected methods that check user parameters void require_inobs(const std::string& method); + void require_inobs_nolist(const std::string& method); void require_inobs_nocube(const std::string& method); // Protected support methods diff --git a/src/ctcubemask/ctcubemask.cpp b/src/ctcubemask/ctcubemask.cpp index d7dc088..b3f7691 100644 --- a/src/ctcubemask/ctcubemask.cpp +++ b/src/ctcubemask/ctcubemask.cpp @@ -357,16 +357,11 @@ void ctcubemask::get_parameters(void) // parameters if (m_obs.size() == 0) { - // Throw exception if no infile is given - if ((*this)["inobs"].filename() == "NONE" || - (*this)["inobs"].filename() == "") { - std::string msg = "A valid file needs to be specified for the " - "\"inobs\" parameter, yet \""+ - (*this)["inobs"].filename()+"\" was given." - " Specify a valid observation definition or " - "event list FITS file to proceed."; - throw GException::invalid_value(G_GET_PARAMETERS, msg); - } + // Throw exception if no input observation file is given + require_inobs(G_GET_PARAMETERS); + + // Throw exception if event list is given + require_inobs_nolist(G_GET_PARAMETERS); // Build observation container without response (not needed) m_obs = get_observations(false); diff --git a/src/support/ctool.cpp b/src/support/ctool.cpp index c64d41f..35b5267 100644 --- a/src/support/ctool.cpp +++ b/src/support/ctool.cpp @@ -684,6 +684,58 @@ void ctool::require_inobs(const std::string& method) /***********************************************************************//** + * @brief Throws exception if inobs parameter is an event list + * + * @param[in] method Method name. + * + * Throw an exception if the inobs parameter is an event list. + ***************************************************************************/ +void ctool::require_inobs_nolist(const std::string& method) +{ + // Get inobs filename + std::string filename = (*this)["inobs"].filename(); + + // Continue only if we have a FITS file + if (gammalib::is_fits(filename)) { + + // Signal no list + bool is_list = false; + + // Try loading file as counts cube. If this is successful then + // throw an exception + try { + + // Load list from file + GCTAEventList list(filename); + + // If we're still alive then signal that we have a list + is_list = true; + + } + + // Catch any exceptions + catch (...) { + ; + } + + // If we have an event list then throw an exception + if (is_list) { + std::string msg = "An event list has been specified for the " + "\"inobs\" parameter, yet no event list " + "can be specified as input observation." + " Instead, specify a counts cube or an " + "observation definition file."; + throw GException::invalid_value(method, msg); + } + + } // endif: we had a FITS file + + // Return + return; +} + + +/***********************************************************************//** * @brief Throws exception if inobs parameter is a counts cube * * @param[in] method Method name. @@ -698,7 +750,7 @@ void ctool::require_inobs_nocube(const std::string& method) // Continue only if we have a FITS file if (gammalib::is_fits(filename)) { - // Signal su + // Signal no cube bool is_cube = false; // Try loading file as counts cube. If this is successful then diff --git a/src/support/ctool.hpp b/src/support/ctool.hpp index aa4ac8c..0189588 100644 --- a/src/support/ctool.hpp +++ b/src/support/ctool.hpp @@ -81,6 +81,7 @@ protected: // Protected methods that check user parameters void require_inobs(const std::string& method); + void require_inobs_nolist(const std::string& method); void require_inobs_nocube(const std::string& method); // Protected support methods -- libgit2 0.21.4