Commit 50a8694217ed666339d64d198d3713637f0a92f5

Authored by Jürgen Knödlseder
1 parent 03aa111b

Throw an exception if an event list is provided as input to ctcubemask.

pyext/ctool.i
@@ -99,6 +99,7 @@ public: @@ -99,6 +99,7 @@ public:
99 99
100 // Protected methods that check user parameters 100 // Protected methods that check user parameters
101 void require_inobs(const std::string& method); 101 void require_inobs(const std::string& method);
  102 + void require_inobs_nolist(const std::string& method);
102 void require_inobs_nocube(const std::string& method); 103 void require_inobs_nocube(const std::string& method);
103 104
104 // Protected support methods 105 // Protected support methods
src/ctcubemask/ctcubemask.cpp
@@ -357,16 +357,11 @@ void ctcubemask::get_parameters(void) @@ -357,16 +357,11 @@ void ctcubemask::get_parameters(void)
357 // parameters 357 // parameters
358 if (m_obs.size() == 0) { 358 if (m_obs.size() == 0) {
359 359
360 - // Throw exception if no infile is given  
361 - if ((*this)["inobs"].filename() == "NONE" ||  
362 - (*this)["inobs"].filename() == "") {  
363 - std::string msg = "A valid file needs to be specified for the "  
364 - "\"inobs\" parameter, yet \""+  
365 - (*this)["inobs"].filename()+"\" was given."  
366 - " Specify a valid observation definition or "  
367 - "event list FITS file to proceed.";  
368 - throw GException::invalid_value(G_GET_PARAMETERS, msg);  
369 - } 360 + // Throw exception if no input observation file is given
  361 + require_inobs(G_GET_PARAMETERS);
  362 +
  363 + // Throw exception if event list is given
  364 + require_inobs_nolist(G_GET_PARAMETERS);
370 365
371 // Build observation container without response (not needed) 366 // Build observation container without response (not needed)
372 m_obs = get_observations(false); 367 m_obs = get_observations(false);
src/support/ctool.cpp
@@ -684,6 +684,58 @@ void ctool::require_inobs(const std::string& method) @@ -684,6 +684,58 @@ void ctool::require_inobs(const std::string& method)
684 684
685 685
686 /***********************************************************************//** 686 /***********************************************************************//**
  687 + * @brief Throws exception if inobs parameter is an event list
  688 + *
  689 + * @param[in] method Method name.
  690 + *
  691 + * Throw an exception if the inobs parameter is an event list.
  692 + ***************************************************************************/
  693 +void ctool::require_inobs_nolist(const std::string& method)
  694 +{
  695 + // Get inobs filename
  696 + std::string filename = (*this)["inobs"].filename();
  697 +
  698 + // Continue only if we have a FITS file
  699 + if (gammalib::is_fits(filename)) {
  700 +
  701 + // Signal no list
  702 + bool is_list = false;
  703 +
  704 + // Try loading file as counts cube. If this is successful then
  705 + // throw an exception
  706 + try {
  707 +
  708 + // Load list from file
  709 + GCTAEventList list(filename);
  710 +
  711 + // If we're still alive then signal that we have a list
  712 + is_list = true;
  713 +
  714 + }
  715 +
  716 + // Catch any exceptions
  717 + catch (...) {
  718 + ;
  719 + }
  720 +
  721 + // If we have an event list then throw an exception
  722 + if (is_list) {
  723 + std::string msg = "An event list has been specified for the "
  724 + "\"inobs\" parameter, yet no event list "
  725 + "can be specified as input observation."
  726 + " Instead, specify a counts cube or an "
  727 + "observation definition file.";
  728 + throw GException::invalid_value(method, msg);
  729 + }
  730 +
  731 + } // endif: we had a FITS file
  732 +
  733 + // Return
  734 + return;
  735 +}
  736 +
  737 +
  738 +/***********************************************************************//**
687 * @brief Throws exception if inobs parameter is a counts cube 739 * @brief Throws exception if inobs parameter is a counts cube
688 * 740 *
689 * @param[in] method Method name. 741 * @param[in] method Method name.
@@ -698,7 +750,7 @@ void ctool::require_inobs_nocube(const std::string& method) @@ -698,7 +750,7 @@ void ctool::require_inobs_nocube(const std::string& method)
698 // Continue only if we have a FITS file 750 // Continue only if we have a FITS file
699 if (gammalib::is_fits(filename)) { 751 if (gammalib::is_fits(filename)) {
700 752
701 - // Signal su 753 + // Signal no cube
702 bool is_cube = false; 754 bool is_cube = false;
703 755
704 // Try loading file as counts cube. If this is successful then 756 // Try loading file as counts cube. If this is successful then
src/support/ctool.hpp
@@ -81,6 +81,7 @@ protected: @@ -81,6 +81,7 @@ protected:
81 81
82 // Protected methods that check user parameters 82 // Protected methods that check user parameters
83 void require_inobs(const std::string& method); 83 void require_inobs(const std::string& method);
  84 + void require_inobs_nolist(const std::string& method);
84 void require_inobs_nocube(const std::string& method); 85 void require_inobs_nocube(const std::string& method);
85 86
86 // Protected support methods 87 // Protected support methods