diff --git a/src/ctbin/main.cpp b/src/ctbin/main.cpp index 89b3418..988183d 100644 --- a/src/ctbin/main.cpp +++ b/src/ctbin/main.cpp @@ -28,7 +28,7 @@ #ifdef HAVE_CONFIG_H #include #endif -#include +#include "support.hpp" #include "ctbin.hpp" @@ -41,7 +41,7 @@ * This is the main entry point of the ctbin application. It allocates a * ctbin object and executes the application. Any exceptions that occur * will be catched and corresponding error messages written in the - * application logger and on the standard output. + * application logger and into the standard output. ***************************************************************************/ int main (int argc, char *argv[]) { @@ -51,41 +51,26 @@ int main (int argc, char *argv[]) // Initialise pointer on application ctbin* application = NULL; - // Execute application + // Try creating an instance of the application and executing the instance try { // Create instance of application application = new ctbin(argc, argv); - // Execute application - application->execute(); + // Execute ctool + rc = execute_ctool(application); - // Delete application - delete application; - - // Signal success - rc = 0; } - catch (std::exception &e) { - // Extract error message - std::string message = e.what(); - std::string signal = "*** ERROR encounterted in the execution of " - "ctbin. Run aborted ..."; + catch (std::exception &e) { - // If application exists then write error in logger and delete - // application - if (application != NULL) { - application->log << signal << std::endl; - application->log << message << std::endl; - delete application; - } + // Report exception + report_ctool_failure("ctbin", e.what()); - // Write error on standard output - std::cout << signal << std::endl; - std::cout << message << std::endl; + } - } // endcatch: catched any application error + // Delete application + delete application; // Return return rc; diff --git a/src/ctbkgcube/main.cpp b/src/ctbkgcube/main.cpp index bd1e749..63a774a 100644 --- a/src/ctbkgcube/main.cpp +++ b/src/ctbkgcube/main.cpp @@ -28,7 +28,7 @@ #ifdef HAVE_CONFIG_H #include #endif -#include +#include "support.hpp" #include "ctbkgcube.hpp" @@ -41,7 +41,7 @@ * This is the main entry point of the ctbkgcube application. It allocates a * ctbkgcube object and executes the application. Any exceptions that occur * will be catched and corresponding error messages written in the - * application logger and on the standard output. + * application logger and into the standard output. ***************************************************************************/ int main (int argc, char *argv[]) { @@ -57,35 +57,20 @@ int main (int argc, char *argv[]) // Create instance of application application = new ctbkgcube(argc, argv); - // Execute application - application->execute(); + // Execute ctool + rc = execute_ctool(application); - // Delete application - delete application; - - // Signal success - rc = 0; } - catch (std::exception &e) { - // Extract error message - std::string message = e.what(); - std::string signal = "*** ERROR encounterted in the execution of " - "ctbkgcube. Run aborted ..."; + catch (std::exception &e) { - // If application exists then write error in logger and delete - // application - if (application != NULL) { - application->log << signal << std::endl; - application->log << message << std::endl; - delete application; - } + // Report exception + report_ctool_failure("ctbkgcube", e.what()); - // Write error on standard output - std::cout << signal << std::endl; - std::cout << message << std::endl; + } - } // endcatch: catched any application error + // Delete application + delete application; // Return return rc; diff --git a/src/ctbutterfly/main.cpp b/src/ctbutterfly/main.cpp index 803ffd5..9a5b9f0 100644 --- a/src/ctbutterfly/main.cpp +++ b/src/ctbutterfly/main.cpp @@ -28,7 +28,7 @@ #ifdef HAVE_CONFIG_H #include #endif -#include +#include "support.hpp" #include "ctbutterfly.hpp" @@ -41,7 +41,7 @@ * This is the main entry point of the ctbutterfly application. It allocates * a ctbutterfly object and executes the application. Any exceptions that * occur will be catched and corresponding error messages written in the - * application logger and on the standard output. + * application logger and into the standard output. ***************************************************************************/ int main (int argc, char *argv[]) { @@ -57,35 +57,20 @@ int main (int argc, char *argv[]) // Create instance of application application = new ctbutterfly(argc, argv); - // Execute application - application->execute(); + // Execute ctool + rc = execute_ctool(application); - // Delete application - delete application; - - // Signal success - rc = 0; } - catch (std::exception &e) { - // Extract error message - std::string message = e.what(); - std::string signal = "*** ERROR encounterted in the execution of " - "ctbutterfly. Run aborted ..."; + catch (std::exception &e) { - // If application exists then write error in logger and delete - // application - if (application != NULL) { - application->log << signal << std::endl; - application->log << message << std::endl; - delete application; - } + // Report exception + report_ctool_failure("ctbutterfly", e.what()); - // Write error on standard output - std::cout << signal << std::endl; - std::cout << message << std::endl; + } - } // endcatch: catched any application error + // Delete application + delete application; // Return return rc; diff --git a/src/ctcubemask/main.cpp b/src/ctcubemask/main.cpp index a265732..ed41afe 100644 --- a/src/ctcubemask/main.cpp +++ b/src/ctcubemask/main.cpp @@ -28,7 +28,7 @@ #ifdef HAVE_CONFIG_H #include #endif -#include +#include "support.hpp" #include "ctcubemask.hpp" @@ -41,7 +41,7 @@ * This is the main entry point of the ctcubemask application. It allocates * a ctcubemask object and executes the application. Any exceptions that * occur will be catched and corresponding error messages written in the - * application logger and on the standard output. + * application logger and into the standard output. ***************************************************************************/ int main (int argc, char *argv[]) { @@ -57,35 +57,20 @@ int main (int argc, char *argv[]) // Create instance of application application = new ctcubemask(argc, argv); - // Execute application - application->execute(); + // Execute ctool + rc = execute_ctool(application); - // Delete application - delete application; - - // Signal success - rc = 0; } - catch (std::exception &e) { - // Extract error message - std::string message = e.what(); - std::string signal = "*** ERROR encounterted in the execution of " - "ctcubemask. Run aborted ..."; + catch (std::exception &e) { - // If application exists then write error in logger and delete - // application - if (application != NULL) { - application->log << signal << std::endl; - application->log << message << std::endl; - delete application; - } + // Report exception + report_ctool_failure("ctcubemask", e.what()); - // Write error on standard output - std::cout << message << std::endl; - std::cout << signal << std::endl; + } - } // endcatch: catched any application error + // Delete application + delete application; // Return return rc; diff --git a/src/ctedispcube/main.cpp b/src/ctedispcube/main.cpp index fab8d44..fb1ede5 100644 --- a/src/ctedispcube/main.cpp +++ b/src/ctedispcube/main.cpp @@ -28,7 +28,7 @@ #ifdef HAVE_CONFIG_H #include #endif -#include +#include "support.hpp" #include "ctedispcube.hpp" @@ -41,7 +41,7 @@ * This is the main entry point of the ctedispcube application. It allocates * a ctedispcube object and executes the application. Any exceptions that * occur will be catched and corresponding error messages written in the - * application logger and on the standard output. + * application logger and into the standard output. ***************************************************************************/ int main (int argc, char *argv[]) { @@ -57,35 +57,20 @@ int main (int argc, char *argv[]) // Create instance of application application = new ctedispcube(argc, argv); - // Execute application - application->execute(); + // Execute ctool + rc = execute_ctool(application); - // Delete application - delete application; - - // Signal success - rc = 0; } - catch (std::exception &e) { - // Extract error message - std::string message = e.what(); - std::string signal = "*** ERROR encounterted in the execution of " - "ctedispcube. Run aborted ..."; + catch (std::exception &e) { - // If application exists then write error in logger and delete - // application - if (application != NULL) { - application->log << signal << std::endl; - application->log << message << std::endl; - delete application; - } + // Report exception + report_ctool_failure("ctedispcube", e.what()); - // Write error on standard output - std::cout << signal << std::endl; - std::cout << message << std::endl; + } - } // endcatch: catched any application error + // Delete application + delete application; // Return return rc; diff --git a/src/cterror/main.cpp b/src/cterror/main.cpp index a9246f8..652b0db 100644 --- a/src/cterror/main.cpp +++ b/src/cterror/main.cpp @@ -28,7 +28,7 @@ #ifdef HAVE_CONFIG_H #include #endif -#include +#include "support.hpp" #include "cterror.hpp" @@ -41,7 +41,7 @@ * This is the main entry point of the cterror application. It allocates a * cterror object and executes the application. Any exceptions that occur * will be catched and corresponding error messages written in the - * application logger and on the standard output. + * application logger and into the standard output. ***************************************************************************/ int main (int argc, char *argv[]) { @@ -57,35 +57,20 @@ int main (int argc, char *argv[]) // Create instance of application application = new cterror(argc, argv); - // Execute application - application->execute(); + // Execute ctool + rc = execute_ctool(application); - // Delete application - delete application; - - // Signal success - rc = 0; } - catch (std::exception &e) { - // Extract error message - std::string message = e.what(); - std::string signal = "*** ERROR encounterted in the execution of " - "cterror. Run aborted ..."; + catch (std::exception &e) { - // If application exists then write error in logger and delete - // application - if (application != NULL) { - application->log << signal << std::endl; - application->log << message << std::endl; - delete application; - } + // Report exception + report_ctool_failure("cterror", e.what()); - // Write error on standard output - std::cout << signal << std::endl; - std::cout << message << std::endl; + } - } // endcatch: catched any application error + // Delete application + delete application; // Return return rc; diff --git a/src/ctexpcube/main.cpp b/src/ctexpcube/main.cpp index 58f7d8a..a4784d1 100644 --- a/src/ctexpcube/main.cpp +++ b/src/ctexpcube/main.cpp @@ -28,7 +28,7 @@ #ifdef HAVE_CONFIG_H #include #endif -#include +#include "support.hpp" #include "ctexpcube.hpp" @@ -41,7 +41,7 @@ * This is the main entry point of the ctexpcube application. It allocates a * ctexpcube object and executes the application. Any exceptions that occur * will be catched and corresponding error messages written in the - * application logger and on the standard output. + * application logger and into the standard output. ***************************************************************************/ int main (int argc, char *argv[]) { @@ -60,32 +60,20 @@ int main (int argc, char *argv[]) // Execute application application->execute(); - // Delete application - delete application; + // Execute ctool + rc = execute_ctool(application); - // Signal success - rc = 0; } - catch (std::exception &e) { - // Extract error message - std::string message = e.what(); - std::string signal = "*** ERROR encounterted in the execution of " - "ctexpcube. Run aborted ..."; + catch (std::exception &e) { - // If application exists then write error in logger and delete - // application - if (application != NULL) { - application->log << signal << std::endl; - application->log << message << std::endl; - delete application; - } + // Report exception + report_ctool_failure("ctexpcube", e.what()); - // Write error on standard output - std::cout << signal << std::endl; - std::cout << message << std::endl; + } - } // endcatch: catched any application error + // Delete application + delete application; // Return return rc; diff --git a/src/ctlike/main.cpp b/src/ctlike/main.cpp index 22c7375..bffbfca 100644 --- a/src/ctlike/main.cpp +++ b/src/ctlike/main.cpp @@ -28,7 +28,7 @@ #ifdef HAVE_CONFIG_H #include #endif -#include +#include "support.hpp" #include "ctlike.hpp" @@ -41,7 +41,7 @@ * This is the main entry point of the ctlike application. It allocates a * ctlike object and executes the application. Any exceptions that occur * will be catched and corresponding error messages written in the - * application logger and on the standard output. + * application logger and into the standard output. ***************************************************************************/ int main (int argc, char *argv[]) { @@ -57,35 +57,20 @@ int main (int argc, char *argv[]) // Create instance of application application = new ctlike(argc, argv); - // Execute application - application->execute(); + // Execute ctool + rc = execute_ctool(application); - // Delete application - delete application; - - // Signal success - rc = 0; } - catch (std::exception &e) { - // Extract error message - std::string message = e.what(); - std::string signal = "*** ERROR encounterted in the execution of " - "ctlike. Run aborted ..."; + catch (std::exception &e) { - // If application exists then write error in logger and delete - // application - if (application != NULL) { - application->log << signal << std::endl; - application->log << message << std::endl; - delete application; - } + // Report exception + report_ctool_failure("ctlike", e.what()); - // Write error on standard output - std::cout << signal << std::endl; - std::cout << message << std::endl; + } - } // endcatch: catched any application error + // Delete application + delete application; // Return return rc; diff --git a/src/ctmapcube/main.cpp b/src/ctmapcube/main.cpp index f5b03f3..a29a944 100644 --- a/src/ctmapcube/main.cpp +++ b/src/ctmapcube/main.cpp @@ -28,7 +28,7 @@ #ifdef HAVE_CONFIG_H #include #endif -#include +#include "support.hpp" #include "ctmapcube.hpp" @@ -41,7 +41,7 @@ * This is the main entry point of the ctmapcube application. It allocates a * ctmapcube object and executes the application. Any exceptions that occur * will be catched and corresponding error messages written in the - * application logger and on the standard output. + * application logger and into the standard output. ***************************************************************************/ int main (int argc, char *argv[]) { @@ -57,35 +57,20 @@ int main (int argc, char *argv[]) // Create instance of application application = new ctmapcube(argc, argv); - // Execute application - application->execute(); + // Execute ctool + rc = execute_ctool(application); - // Delete application - delete application; - - // Signal success - rc = 0; } - catch (std::exception &e) { - // Extract error message - std::string message = e.what(); - std::string signal = "*** ERROR encounterted in the execution of " - "ctmapcube. Run aborted ..."; + catch (std::exception &e) { - // If application exists then write error in logger and delete - // application - if (application != NULL) { - application->log << signal << std::endl; - application->log << message << std::endl; - delete application; - } + // Report exception + report_ctool_failure("ctmapcube", e.what()); - // Write error on standard output - std::cout << signal << std::endl; - std::cout << message << std::endl; + } - } // endcatch: catched any application error + // Delete application + delete application; // Return return rc; diff --git a/src/ctmodel/main.cpp b/src/ctmodel/main.cpp index 9e929cc..e2f5ea0 100644 --- a/src/ctmodel/main.cpp +++ b/src/ctmodel/main.cpp @@ -28,7 +28,7 @@ #ifdef HAVE_CONFIG_H #include #endif -#include +#include "support.hpp" #include "ctmodel.hpp" @@ -41,7 +41,7 @@ * This is the main entry point of the ctmodel application. It allocates a * ctmodel object and executes the application. Any exceptions that occur * will be catched and corresponding error messages written in the - * application logger and on the standard output. + * application logger and into the standard output. ***************************************************************************/ int main (int argc, char *argv[]) { @@ -57,34 +57,20 @@ int main (int argc, char *argv[]) // Create instance of application application = new ctmodel(argc, argv); - // Execute application - application->execute(); + // Execute ctool + rc = execute_ctool(application); - // Delete application - delete application; - - // Signal success - rc = 0; } + catch (std::exception &e) { - // Extract error message - std::string message = e.what(); - std::string signal = "*** ERROR encounterted in the execution of " - "ctmodel. Run aborted ..."; + // Report exception + report_ctool_failure("ctmodel", e.what()); - // If application exists then write error in logger and delete - // application - if (application != NULL) { - application->log << signal << std::endl; - application->log << message << std::endl; - delete application; - } - // Write error on standard output - std::cout << signal << std::endl; - std::cout << message << std::endl; + } - } // endcatch: catched any application error + // Delete application + delete application; // Return return rc; diff --git a/src/ctobssim/main.cpp b/src/ctobssim/main.cpp index 0ed8426..5de449f 100644 --- a/src/ctobssim/main.cpp +++ b/src/ctobssim/main.cpp @@ -28,7 +28,7 @@ #ifdef HAVE_CONFIG_H #include #endif -#include +#include "support.hpp" #include "ctobssim.hpp" @@ -57,35 +57,20 @@ int main (int argc, char *argv[]) // Create instance of application application = new ctobssim(argc, argv); - // Execute application - application->execute(); + // Execute ctool + rc = execute_ctool(application); - // Delete application - delete application; - - // Signal success - rc = 0; } - catch (std::exception &e) { - // Extract error message - std::string message = e.what(); - std::string signal = "*** ERROR encounterted in the execution of " - "ctobssim. Run aborted ..."; + catch (std::exception &e) { - // If application exists then write error in logger and delete - // application - if (application != NULL) { - application->log << signal << std::endl; - application->log << message << std::endl; - delete application; - } + // Report exception + report_ctool_failure("ctobssim", e.what()); - // Write error on standard output - std::cout << signal << std::endl; - std::cout << message << std::endl; + } - } // endcatch: catched any application error + // Delete application + delete application; // Return return rc; diff --git a/src/ctpsfcube/main.cpp b/src/ctpsfcube/main.cpp index 5dd9836..1ed78be 100644 --- a/src/ctpsfcube/main.cpp +++ b/src/ctpsfcube/main.cpp @@ -28,7 +28,7 @@ #ifdef HAVE_CONFIG_H #include #endif -#include +#include "support.hpp" #include "ctpsfcube.hpp" @@ -41,7 +41,7 @@ * This is the main entry point of the ctpsfcube application. It allocates a * ctpsfcube object and executes the application. Any exceptions that occur * will be catched and corresponding error messages written in the - * application logger and on the standard output. + * application logger and into the standard output. ***************************************************************************/ int main (int argc, char *argv[]) { @@ -57,35 +57,20 @@ int main (int argc, char *argv[]) // Create instance of application application = new ctpsfcube(argc, argv); - // Execute application - application->execute(); + // Execute ctool + rc = execute_ctool(application); - // Delete application - delete application; - - // Signal success - rc = 0; } - catch (std::exception &e) { - // Extract error message - std::string message = e.what(); - std::string signal = "*** ERROR encounterted in the execution of " - "ctpsfcube. Run aborted ..."; + catch (std::exception &e) { - // If application exists then write error in logger and delete - // application - if (application != NULL) { - application->log << signal << std::endl; - application->log << message << std::endl; - delete application; - } + // Report exception + report_ctool_failure("ctpsfcube", e.what()); - // Write error on standard output - std::cout << signal << std::endl; - std::cout << message << std::endl; + } - } // endcatch: catched any application error + // Delete application + delete application; // Return return rc; diff --git a/src/ctselect/main.cpp b/src/ctselect/main.cpp index 9b0170e..039e0a3 100644 --- a/src/ctselect/main.cpp +++ b/src/ctselect/main.cpp @@ -28,7 +28,7 @@ #ifdef HAVE_CONFIG_H #include #endif -#include +#include "support.hpp" #include "ctselect.hpp" @@ -41,7 +41,7 @@ * This is the main entry point of the ctselect application. It allocates a * ctselect object and executes the application. Any exceptions that occur * will be catched and corresponding error messages written in the - * application logger and on the standard output. + * application logger and into the standard output. ***************************************************************************/ int main (int argc, char *argv[]) { @@ -57,35 +57,20 @@ int main (int argc, char *argv[]) // Create instance of application application = new ctselect(argc, argv); - // Execute application - application->execute(); + // Execute ctool + rc = execute_ctool(application); - // Delete application - delete application; - - // Signal success - rc = 0; } - catch (std::exception &e) { - // Extract error message - std::string message = e.what(); - std::string signal = "*** ERROR encounterted in the execution of " - "ctselect. Run aborted ..."; + catch (std::exception &e) { - // If application exists then write error in logger and delete - // application - if (application != NULL) { - application->log << signal << std::endl; - application->log << message << std::endl; - delete application; - } + // Report exception + report_ctool_failure("ctselect", e.what()); - // Write error on standard output - std::cout << message << std::endl; - std::cout << signal << std::endl; + } - } // endcatch: catched any application error + // Delete application + delete application; // Return return rc; diff --git a/src/ctskymap/main.cpp b/src/ctskymap/main.cpp index 09a1516..1fd3e40 100644 --- a/src/ctskymap/main.cpp +++ b/src/ctskymap/main.cpp @@ -28,7 +28,7 @@ #ifdef HAVE_CONFIG_H #include #endif -#include +#include "support.hpp" #include "ctskymap.hpp" @@ -41,7 +41,7 @@ * This is the main entry point of the ctskymap application. It allocates a * ctskymap object and executes the application. Any exceptions that occur * will be catched and corresponding error messages written in the - * application logger and on the standard output. + * application logger and into the standard output. ***************************************************************************/ int main (int argc, char *argv[]) { @@ -57,35 +57,20 @@ int main (int argc, char *argv[]) // Create instance of application application = new ctskymap(argc, argv); - // Execute application - application->execute(); + // Execute ctool + rc = execute_ctool(application); - // Delete application - delete application; - - // Signal success - rc = 0; } - catch (std::exception &e) { - // Extract error message - std::string message = e.what(); - std::string signal = "*** ERROR encounterted in the execution of " - "ctskymap. Run aborted ..."; + catch (std::exception &e) { - // If application exists then write error in logger and delete - // application - if (application != NULL) { - application->log << signal << std::endl; - application->log << message << std::endl; - delete application; - } + // Report exception + report_ctool_failure("ctskymap", e.what()); - // Write error on standard output - std::cout << signal << std::endl; - std::cout << message << std::endl; + } - } // endcatch: catched any application error + // Delete application + delete application; // Return return rc; diff --git a/src/cttsmap/main.cpp b/src/cttsmap/main.cpp index 5dad9ec..51abec2 100644 --- a/src/cttsmap/main.cpp +++ b/src/cttsmap/main.cpp @@ -28,7 +28,7 @@ #ifdef HAVE_CONFIG_H #include #endif -#include +#include "support.hpp" #include "cttsmap.hpp" @@ -41,7 +41,7 @@ * This is the main entry point of the cttsmap application. It allocates a * cttsmap object and executes the application. Any exceptions that occur * will be catched and corresponding error messages written in the - * application logger and on the standard output. + * application logger and into the standard output. ***************************************************************************/ int main (int argc, char *argv[]) { @@ -57,35 +57,20 @@ int main (int argc, char *argv[]) // Create instance of application application = new cttsmap(argc, argv); - // Execute application - application->execute(); + // Execute ctool + rc = execute_ctool(application); - // Delete application - delete application; - - // Signal success - rc = 0; } - catch (std::exception &e) { - // Extract error message - std::string message = e.what(); - std::string signal = "*** ERROR encounterted in the execution of " - "cttsmap. Run aborted ..."; + catch (std::exception &e) { - // If application exists then write error in logger and delete - // application - if (application != NULL) { - application->log << signal << std::endl; - application->log << message << std::endl; - delete application; - } + // Report exception + report_ctool_failure("cttsmap", e.what()); - // Write error on standard output - std::cout << signal << std::endl; - std::cout << message << std::endl; + } - } // endcatch: catched any application error + // Delete application + delete application; // Return return rc; diff --git a/src/ctulimit/main.cpp b/src/ctulimit/main.cpp index 3a33aa2..7a8691e 100644 --- a/src/ctulimit/main.cpp +++ b/src/ctulimit/main.cpp @@ -28,7 +28,7 @@ #ifdef HAVE_CONFIG_H #include #endif -#include +#include "support.hpp" #include "ctulimit.hpp" @@ -39,7 +39,9 @@ * @param[in] argv Command line arguments. * * This is the main entry point of the ctulimit application. It allocates a - * ctupperlimit object and runs the application. + * ctulimit object and executes the application. Any exceptions that occur + * will be catched and corresponding error messages written in the + * application logger and into the standard output. ***************************************************************************/ int main (int argc, char *argv[]) { @@ -55,35 +57,20 @@ int main (int argc, char *argv[]) // Create instance of application application = new ctulimit(argc, argv); - // Execute application - application->execute(); + // Execute ctool + rc = execute_ctool(application); - // Delete application - delete application; - - // Signal success - rc = 0; } - catch (std::exception &e) { - // Extract error message - std::string message = e.what(); - std::string signal = "*** ERROR encounterted in the execution of " - "ctulimit. Run aborted ..."; + catch (std::exception &e) { - // If application exists then write error in logger and delete - // application - if (application != NULL) { - application->log << signal << std::endl; - application->log << message << std::endl; - delete application; - } + // Report exception + report_ctool_failure("ctulimit", e.what()); - // Write error on standard output - std::cout << signal << std::endl; - std::cout << message << std::endl; + } - } // endcatch: catched any application error + // Delete application + delete application; // Return return rc; diff --git a/src/support/Makefile.am b/src/support/Makefile.am index b6d8bda..aa54ad8 100644 --- a/src/support/Makefile.am +++ b/src/support/Makefile.am @@ -20,7 +20,8 @@ ############################################################################# # Define sources for this directory -sources = ctool.cpp ctool.hpp \ +sources = support.cpp support.hpp \ + ctool.cpp ctool.hpp \ ctobservation.cpp ctobservation.hpp \ ctlikelihood.cpp ctlikelihood.hpp diff --git a/src/support/support.cpp b/src/support/support.cpp new file mode 100644 index 0000000..c9e11dc --- /dev/null +++ b/src/support/support.cpp @@ -0,0 +1,121 @@ +/*************************************************************************** + * support - support functions * + * ----------------------------------------------------------------------- * + * copyright (C) 2016 by Juergen Knoedlseder * + * ----------------------------------------------------------------------- * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + * * + ***************************************************************************/ +/** + * @file support + * @brief Support function implementation + * @author Juergen Knoedlseder + */ + +/* __ Includes ___________________________________________________________ */ +#ifdef HAVE_CONFIG_H +#include +#endif +//#include // std::getenv() function +//#include // std::fopen(), etc. functions +#include "GammaLib.hpp" +#include "GCTALib.hpp" +#include "support.hpp" +//#include "GTools.hpp" + +/* __ Method name definitions ____________________________________________ */ + +/* __ Debug definitions __________________________________________________ */ + +/* __ Coding definitions _________________________________________________ */ + + +/*========================================================================== + = = + = Support functions = + = = + ==========================================================================*/ + +/***********************************************************************//** + * @brief Execute ctool + * + * @param[in] tool Pointer to ctool. + * @return Return code + * + * Executes a ctool. The execution is enclosed in a try-catch statement so + * that any exceptions that occur during execution will be properly logged + * and written into the standard output. + ***************************************************************************/ +int execute_ctool(ctool* tool) +{ + // Initialise return code + int rc = 1; + + // Try executing tool. This catches any exceptions that occur during + // the execution. + try { + + // Execute ctool + tool->execute(); + + // Signal success + rc = 0; + + } // endtry + + // Handle any exceptions that have occured + catch (std::exception &e) { + + // Extract error message + std::string message = e.what(); + std::string signal = "*** ERROR encounterted in the execution of "+ + tool->name()+". Run aborted ..."; + + // Write error in logger + tool->log << signal << std::endl; + tool->log << message << std::endl; + + // Write error in standard output + std::cout << signal << std::endl; + std::cout << message << std::endl; + + } // endcatch: catched any exception + + // Return return code + return rc; +} + + +/***********************************************************************//** + * @brief Report ctool failure + * + * @param[in] name Name of ctool. + * @param[in] message Exception message. + * + * Reports a ctools failure. + ***************************************************************************/ +void report_ctool_failure(const std::string& name, const std::string& message) +{ + // Set signal string + std::string signal = "*** ERROR encounterted in the execution of "+ + name+". Run aborted ..."; + + // Write error in standard output + std::cout << signal << std::endl; + std::cout << message << std::endl; + + // Return + return; +} diff --git a/src/support/support.hpp b/src/support/support.hpp new file mode 100644 index 0000000..0dec9b2 --- /dev/null +++ b/src/support/support.hpp @@ -0,0 +1,39 @@ +/*************************************************************************** + * support - support functions * + * ----------------------------------------------------------------------- * + * copyright (C) 2016 by Juergen Knoedlseder * + * ----------------------------------------------------------------------- * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + * * + ***************************************************************************/ +/** + * @file support + * @brief Support function definitions + * @author Juergen Knoedlseder + */ + +#ifndef SUPPORT_HPP +#define SUPPORT_HPP + +/* __ Includes ___________________________________________________________ */ +#include "ctool.hpp" + +/* __ Definitions ________________________________________________________ */ + +/* __ Prototypes _________________________________________________________ */ +int execute_ctool(ctool* tool); +void report_ctool_failure(const std::string& name, const std::string& message); + +#endif /* SUPPORT_HPP */ diff --git a/test/test_ctbin.py b/test/test_ctbin.py index 68d1425..352b1e9 100755 --- a/test/test_ctbin.py +++ b/test/test_ctbin.py @@ -82,7 +82,7 @@ class Test(test): 'Self test of test script') # Check if execution was successful - self.test_assert(self._execute(cmd) == 0, + self.test_value(self._execute(cmd), 0, 'Check successful execution from command line') # Load counts cube and check content. @@ -107,13 +107,11 @@ class Test(test): # Check if execution was successful in case that the CTOOLS # environment variable was set or failed otherwise if 'CTOOLS' in os.environ: - rc = 0 - what = 'success' + self.test_value(self._execute(cmd), 0, + 'Check successful execution with --help option') else: - rc = 1 - what = 'failure' - self.test_value(self._execute(cmd), rc, - 'Check execution %s from command line with --help option' % what) + self.test_assert(self._execute(cmd) != 0, + 'Check execution failure with --help option') # Return return diff --git a/test/test_ctbkgcube.py b/test/test_ctbkgcube.py index 4b43888..b12cb76 100755 --- a/test/test_ctbkgcube.py +++ b/test/test_ctbkgcube.py @@ -110,13 +110,11 @@ class Test(test): # Check if execution was successful in case that the CTOOLS # environment variable was set or failed otherwise if 'CTOOLS' in os.environ: - rc = 0 - what = 'success' + self.test_value(self._execute(cmd), 0, + 'Check successful execution with --help option') else: - rc = 1 - what = 'failure' - self.test_value(self._execute(cmd), rc, - 'Check execution %s from command line with --help option' % what) + self.test_assert(self._execute(cmd) != 0, + 'Check execution failure with --help option') # Return return diff --git a/test/test_ctbutterfly.py b/test/test_ctbutterfly.py index 2bd641f..ba7fe16 100755 --- a/test/test_ctbutterfly.py +++ b/test/test_ctbutterfly.py @@ -102,13 +102,11 @@ class Test(test): # Check if execution was successful in case that the CTOOLS # environment variable was set or failed otherwise if 'CTOOLS' in os.environ: - rc = 0 - what = 'success' + self.test_value(self._execute(cmd), 0, + 'Check successful execution with --help option') else: - rc = 1 - what = 'failure' - self.test_value(self._execute(cmd), rc, - 'Check execution %s from command line with --help option' % what) + self.test_assert(self._execute(cmd) != 0, + 'Check execution failure with --help option') # Return return diff --git a/test/test_ctcubemask.py b/test/test_ctcubemask.py index 9ffbc17..149f800 100755 --- a/test/test_ctcubemask.py +++ b/test/test_ctcubemask.py @@ -105,13 +105,11 @@ class Test(test): # Check if execution was successful in case that the CTOOLS # environment variable was set or failed otherwise if 'CTOOLS' in os.environ: - rc = 0 - what = 'success' + self.test_value(self._execute(cmd), 0, + 'Check successful execution with --help option') else: - rc = 1 - what = 'failure' - self.test_value(self._execute(cmd), rc, - 'Check execution %s from command line with --help option' % what) + self.test_assert(self._execute(cmd) != 0, + 'Check execution failure with --help option') # Return return diff --git a/test/test_ctedispcube.py b/test/test_ctedispcube.py index 4b0e90c..05a8889 100755 --- a/test/test_ctedispcube.py +++ b/test/test_ctedispcube.py @@ -108,13 +108,11 @@ class Test(test): # Check if execution was successful in case that the CTOOLS # environment variable was set or failed otherwise if 'CTOOLS' in os.environ: - rc = 0 - what = 'success' + self.test_value(self._execute(cmd), 0, + 'Check successful execution with --help option') else: - rc = 1 - what = 'failure' - self.test_value(self._execute(cmd), rc, - 'Check execution %s from command line with --help option' % what) + self.test_assert(self._execute(cmd) != 0, + 'Check execution failure with --help option') # Return return diff --git a/test/test_cterror.py b/test/test_cterror.py index d427962..3490595 100755 --- a/test/test_cterror.py +++ b/test/test_cterror.py @@ -100,13 +100,11 @@ class Test(test): # Check if execution was successful in case that the CTOOLS # environment variable was set or failed otherwise if 'CTOOLS' in os.environ: - rc = 0 - what = 'success' + self.test_value(self._execute(cmd), 0, + 'Check successful execution with --help option') else: - rc = 1 - what = 'failure' - self.test_value(self._execute(cmd), rc, - 'Check execution %s from command line with --help option' % what) + self.test_assert(self._execute(cmd) != 0, + 'Check execution failure with --help option') # Return return diff --git a/test/test_ctexpcube.py b/test/test_ctexpcube.py index fda3b8e..9931c3f 100755 --- a/test/test_ctexpcube.py +++ b/test/test_ctexpcube.py @@ -106,13 +106,11 @@ class Test(test): # Check if execution was successful in case that the CTOOLS # environment variable was set or failed otherwise if 'CTOOLS' in os.environ: - rc = 0 - what = 'success' + self.test_value(self._execute(cmd), 0, + 'Check successful execution with --help option') else: - rc = 1 - what = 'failure' - self.test_value(self._execute(cmd), rc, - 'Check execution %s from command line with --help option' % what) + self.test_assert(self._execute(cmd) != 0, + 'Check execution failure with --help option') # Return return diff --git a/test/test_ctlike.py b/test/test_ctlike.py index 29fbca2..f010031 100755 --- a/test/test_ctlike.py +++ b/test/test_ctlike.py @@ -100,13 +100,11 @@ class Test(test): # Check if execution was successful in case that the CTOOLS # environment variable was set or failed otherwise if 'CTOOLS' in os.environ: - rc = 0 - what = 'success' + self.test_value(self._execute(cmd), 0, + 'Check successful execution with --help option') else: - rc = 1 - what = 'failure' - self.test_value(self._execute(cmd), rc, - 'Check execution %s from command line with --help option' % what) + self.test_assert(self._execute(cmd) != 0, + 'Check execution failure with --help option') # Return return diff --git a/test/test_ctmapcube.py b/test/test_ctmapcube.py index d2b078f..767b9b8 100644 --- a/test/test_ctmapcube.py +++ b/test/test_ctmapcube.py @@ -106,13 +106,11 @@ class Test(test): # Check if execution was successful in case that the CTOOLS # environment variable was set or failed otherwise if 'CTOOLS' in os.environ: - rc = 0 - what = 'success' + self.test_value(self._execute(cmd), 0, + 'Check successful execution with --help option') else: - rc = 1 - what = 'failure' - self.test_value(self._execute(cmd), rc, - 'Check execution %s from command line with --help option' % what) + self.test_assert(self._execute(cmd) != 0, + 'Check execution failure with --help option') # Return return diff --git a/test/test_ctmodel.py b/test/test_ctmodel.py index 1415462..e58def8 100755 --- a/test/test_ctmodel.py +++ b/test/test_ctmodel.py @@ -110,13 +110,11 @@ class Test(test): # Check if execution was successful in case that the CTOOLS # environment variable was set or failed otherwise if 'CTOOLS' in os.environ: - rc = 0 - what = 'success' + self.test_value(self._execute(cmd), 0, + 'Check successful execution with --help option') else: - rc = 1 - what = 'failure' - self.test_value(self._execute(cmd), rc, - 'Check execution %s from command line with --help option' % what) + self.test_assert(self._execute(cmd) != 0, + 'Check execution failure with --help option') # Return return diff --git a/test/test_ctobssim.py b/test/test_ctobssim.py index 79ee063..c6e18db 100755 --- a/test/test_ctobssim.py +++ b/test/test_ctobssim.py @@ -108,13 +108,11 @@ class Test(test): # Check if execution was successful in case that the CTOOLS # environment variable was set or failed otherwise if 'CTOOLS' in os.environ: - rc = 0 - what = 'success' + self.test_value(self._execute(cmd), 0, + 'Check successful execution with --help option') else: - rc = 1 - what = 'failure' - self.test_value(self._execute(cmd), rc, - 'Check execution %s from command line with --help option' % what) + self.test_assert(self._execute(cmd) != 0, + 'Check execution failure with --help option') # Return return diff --git a/test/test_ctpsfcube.py b/test/test_ctpsfcube.py index e8f0e98..534fe38 100755 --- a/test/test_ctpsfcube.py +++ b/test/test_ctpsfcube.py @@ -108,13 +108,11 @@ class Test(test): # Check if execution was successful in case that the CTOOLS # environment variable was set or failed otherwise if 'CTOOLS' in os.environ: - rc = 0 - what = 'success' + self.test_value(self._execute(cmd), 0, + 'Check successful execution with --help option') else: - rc = 1 - what = 'failure' - self.test_value(self._execute(cmd), rc, - 'Check execution %s from command line with --help option' % what) + self.test_assert(self._execute(cmd) != 0, + 'Check execution failure with --help option') # Return return diff --git a/test/test_ctselect.py b/test/test_ctselect.py index b109c31..c70f51a 100755 --- a/test/test_ctselect.py +++ b/test/test_ctselect.py @@ -105,13 +105,11 @@ class Test(test): # Check if execution was successful in case that the CTOOLS # environment variable was set or failed otherwise if 'CTOOLS' in os.environ: - rc = 0 - what = 'success' + self.test_value(self._execute(cmd), 0, + 'Check successful execution with --help option') else: - rc = 1 - what = 'failure' - self.test_value(self._execute(cmd), rc, - 'Check execution %s from command line with --help option' % what) + self.test_assert(self._execute(cmd) != 0, + 'Check execution failure with --help option') # Return return diff --git a/test/test_ctskymap.py b/test/test_ctskymap.py index d160b59..862bd34 100755 --- a/test/test_ctskymap.py +++ b/test/test_ctskymap.py @@ -102,13 +102,11 @@ class Test(test): # Check if execution was successful in case that the CTOOLS # environment variable was set or failed otherwise if 'CTOOLS' in os.environ: - rc = 0 - what = 'success' + self.test_value(self._execute(cmd), 0, + 'Check successful execution with --help option') else: - rc = 1 - what = 'failure' - self.test_value(self._execute(cmd), rc, - 'Check execution %s from command line with --help option' % what) + self.test_assert(self._execute(cmd) != 0, + 'Check execution failure with --help option') # Return return diff --git a/test/test_cttsmap.py b/test/test_cttsmap.py index 5c860f1..0e2edea 100755 --- a/test/test_cttsmap.py +++ b/test/test_cttsmap.py @@ -104,13 +104,11 @@ class Test(test): # Check if execution was successful in case that the CTOOLS # environment variable was set or failed otherwise if 'CTOOLS' in os.environ: - rc = 0 - what = 'success' + self.test_value(self._execute(cmd), 0, + 'Check successful execution with --help option') else: - rc = 1 - what = 'failure' - self.test_value(self._execute(cmd), rc, - 'Check execution %s from command line with --help option' % what) + self.test_assert(self._execute(cmd) != 0, + 'Check execution failure with --help option') # Return return diff --git a/test/test_ctulimit.py b/test/test_ctulimit.py index 25ba38c..e9ccbe9 100755 --- a/test/test_ctulimit.py +++ b/test/test_ctulimit.py @@ -98,13 +98,11 @@ class Test(test): # Check if execution was successful in case that the CTOOLS # environment variable was set or failed otherwise if 'CTOOLS' in os.environ: - rc = 0 - what = 'success' + self.test_value(self._execute(cmd), 0, + 'Check successful execution with --help option') else: - rc = 1 - what = 'failure' - self.test_value(self._execute(cmd), rc, - 'Check execution %s from command line with --help option' % what) + self.test_assert(self._execute(cmd) != 0, + 'Check execution failure with --help option') # Return return