From 46d3467f0273135de2fb67883ad9ea22ffeec280 Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Wed, 4 Jul 2018 12:35:07 +0200 Subject: [PATCH] Avoid mangling of log files after application pickling (#2421) --- pyext/ctlikelihood.i | 40 ++++++++++++++++++++-------------------- pyext/ctobservation.i | 40 ++++++++++++++++++++-------------------- pyext/ctool.i | 24 +++++++++++++++--------- src/support/ctlikelihood.cpp | 53 +++++++++++++++++++++++++++-------------------------- src/support/ctlikelihood.hpp | 12 ++++++------ src/support/ctobservation.cpp | 49 +++++++++++++++++++++++++------------------------ src/support/ctobservation.hpp | 12 ++++++------ src/support/ctool.cpp | 98 +++++++++++++++++++++++++++++++++++++++----------------------------------------------------------- src/support/ctool.hpp | 17 +++++++++-------- 9 files changed, 167 insertions(+), 178 deletions(-) diff --git a/pyext/ctlikelihood.i b/pyext/ctlikelihood.i index b1f8cee..5b7332f 100755 --- a/pyext/ctlikelihood.i +++ b/pyext/ctlikelihood.i @@ -45,19 +45,19 @@ public: cslikelihood(const std::string& name, const std::string& version) : ctlikelihood(name, version) {} - cslikelihood(const std::string& name, - const std::string& version, - const GObservations& obs) : - ctlikelihood(name, version, obs) {} - cslikelihood(const std::string& name, - const std::string& version, - const std::vector& args) : - ctlikelihood(name, version, args) {} + cslikelihood(const std::string& name, + const std::string& version, + const GApplicationPars& pars) : + ctlikelihood(name, version, pars) {} cslikelihood(const std::string& name, const std::string& version, int argc, char* argv[]) : ctlikelihood(name, version, argc, argv) {} + cslikelihood(const std::string& name, + const std::string& version, + const GObservations& obs) : + ctlikelihood(name, version, obs) {} cslikelihood(const cslikelihood& app) : ctlikelihood(app) {} virtual ~cslikelihood(void) {} @@ -84,16 +84,16 @@ public: // Constructors and destructors ctlikelihood(const std::string& name, const std::string& version); - ctlikelihood(const std::string& name, - const std::string& version, - const GObservations& obs); - ctlikelihood(const std::string& name, - const std::string& version, - const std::vector& args); + ctlikelihood(const std::string& name, + const std::string& version, + const GApplicationPars& pars); ctlikelihood(const std::string& name, const std::string& version, int argc, char* argv[]); + ctlikelihood(const std::string& name, + const std::string& version, + const GObservations& obs); ctlikelihood(const ctlikelihood& app); virtual ~ctlikelihood(void); @@ -125,16 +125,16 @@ public: // Constructors and destructors cslikelihood(const std::string& name, const std::string& version); - cslikelihood(const std::string& name, - const std::string& version, - const GObservations& obs); - cslikelihood(const std::string& name, - const std::string& version, - const std::vector& args); + cslikelihood(const std::string& name, + const std::string& version, + const GApplicationPars& pars); cslikelihood(const std::string& name, const std::string& version, int ARGC, char **ARGV); + cslikelihood(const std::string& name, + const std::string& version, + const GObservations& obs); cslikelihood(const cslikelihood& app); virtual ~cslikelihood(void); diff --git a/pyext/ctobservation.i b/pyext/ctobservation.i index 7b1bf75..905fd8c 100755 --- a/pyext/ctobservation.i +++ b/pyext/ctobservation.i @@ -45,19 +45,19 @@ public: csobservation(const std::string& name, const std::string& version) : ctobservation(name, version) {} - csobservation(const std::string& name, - const std::string& version, - const GObservations& obs) : - ctobservation(name, version, obs) {} - csobservation(const std::string& name, - const std::string& version, - const std::vector& args) : - ctobservation(name, version, args) {} + csobservation(const std::string& name, + const std::string& version, + const GApplicationPars& pars) : + ctobservation(name, version, pars) {} csobservation(const std::string& name, const std::string& version, int argc, char* argv[]) : ctobservation(name, version, argc, argv) {} + csobservation(const std::string& name, + const std::string& version, + const GObservations& obs) : + ctobservation(name, version, obs) {} csobservation(const csobservation& app) : ctobservation(app) {} virtual ~csobservation(void) {} @@ -84,16 +84,16 @@ public: // Constructors and destructors ctobservation(const std::string& name, const std::string& version); - ctobservation(const std::string& name, - const std::string& version, - const GObservations& obs); - ctobservation(const std::string& name, - const std::string& version, - const std::vector& args); + ctobservation(const std::string& name, + const std::string& version, + const GApplicationPars& pars); ctobservation(const std::string& name, const std::string& version, int ARGC, char **ARGV); + ctobservation(const std::string& name, + const std::string& version, + const GObservations& obs); ctobservation(const ctobservation& app); virtual ~ctobservation(void); @@ -137,16 +137,16 @@ public: // Constructors and destructors csobservation(const std::string& name, const std::string& version); - csobservation(const std::string& name, - const std::string& version, - const GObservations& obs); - csobservation(const std::string& name, - const std::string& version, - const std::vector& args); + csobservation(const std::string& name, + const std::string& version, + const GApplicationPars& pars); csobservation(const std::string& name, const std::string& version, int ARGC, char **ARGV); + csobservation(const std::string& name, + const std::string& version, + const GObservations& obs); csobservation(const csobservation& app); virtual ~csobservation(void); diff --git a/pyext/ctool.i b/pyext/ctool.i index d5784ab..86d1f84 100755 --- a/pyext/ctool.i +++ b/pyext/ctool.i @@ -38,9 +38,9 @@ public: // Constructors and destructors cscript(const std::string& name, const std::string& version) : ctool(name, version) {} - cscript(const std::string& name, - const std::string& version, - const std::vector& args) : ctool(name, version, args) {} + cscript(const std::string& name, + const std::string& version, + const GApplicationPars& pars) : ctool(name, version, pars) {} cscript(const std::string& name, const std::string& version, int argc, @@ -75,9 +75,9 @@ public: // Constructors and destructors ctool(const std::string& name, const std::string& version); - ctool(const std::string& name, - const std::string& version, - const std::vector& args); + ctool(const std::string& name, + const std::string& version, + const GApplicationPars& pars); ctool(const std::string& name, const std::string& version, int ARGC, @@ -200,9 +200,15 @@ public: class cscript : public ctool { public: // Constructors and destructors - cscript(const std::string& name, const std::string& version); - cscript(const std::string& name, const std::string& version, - int ARGC, char **ARGV); + cscript(const std::string& name, + const std::string& version); + cscript(const std::string& name, + const std::string& version, + const GApplicationPars& pars); + cscript(const std::string& name, + const std::string& version, + int ARGC, + char **ARGV); cscript(const ctool& app); virtual ~cscript(void); diff --git a/src/support/ctlikelihood.cpp b/src/support/ctlikelihood.cpp index d251d54..b8c7d24 100755 --- a/src/support/ctlikelihood.cpp +++ b/src/support/ctlikelihood.cpp @@ -55,7 +55,7 @@ ***************************************************************************/ ctlikelihood::ctlikelihood(const std::string& name, const std::string& version) : - ctobservation(name, version) + ctobservation(name, version) { // Initialise members init_members(); @@ -66,19 +66,20 @@ ctlikelihood::ctlikelihood(const std::string& name, /***********************************************************************//** - * @brief Observations constructor + * @brief Application parameters constructor * - * @param[in] name Likelihood tool name. - * @param[in] version Likelihood tool version. - * param[in] obs Observation container. + * @param[in] name Observation tool name. + * @param[in] version Observation tool version. + * @param[in] pars Application parameters. * - * Constructs a likelihood tool from the @p name, @p version and an - * observation container. + * Constructs a likelihood tool from the @p name, @p version and the + * application parameters @p pars. See the equivalent ctool constructor + * for details. ***************************************************************************/ -ctlikelihood::ctlikelihood(const std::string& name, - const std::string& version, - const GObservations& obs) : - ctobservation(name, version, obs) +ctlikelihood::ctlikelihood(const std::string& name, + const std::string& version, + const GApplicationPars& pars) : + ctobservation(name, version, pars) { // Initialise members init_members(); @@ -93,15 +94,17 @@ ctlikelihood::ctlikelihood(const std::string& name, * * @param[in] name Likelihood tool name. * @param[in] version Likelihood tool version. - * @param[in] args Arguments vector. + * @param[in] argc Number of arguments in command line. + * @param[in] argv Array of command line arguments. * * Constructs a likelihood tool from the @p name, @p version and command * line arguments. See the equivalent ctool constructor for details. ***************************************************************************/ -ctlikelihood::ctlikelihood(const std::string& name, - const std::string& version, - const std::vector& args) : - ctobservation(name, version, args) +ctlikelihood::ctlikelihood(const std::string& name, + const std::string& version, + int argc, + char *argv[]) : + ctobservation(name, version, argc, argv) { // Initialise members init_members(); @@ -112,21 +115,19 @@ ctlikelihood::ctlikelihood(const std::string& name, /***********************************************************************//** - * @brief Command line constructor + * @brief Observations constructor * * @param[in] name Likelihood tool name. * @param[in] version Likelihood tool version. - * @param[in] argc Number of arguments in command line. - * @param[in] argv Array of command line arguments. + * param[in] obs Observation container. * - * Constructs a likelihood tool from the @p name, @p version and command - * line arguments. See the equivalent ctool constructor for details. + * Constructs a likelihood tool from the @p name, @p version and an + * observation container. ***************************************************************************/ -ctlikelihood::ctlikelihood(const std::string& name, - const std::string& version, - int argc, - char *argv[]) : - ctobservation(name, version, argc, argv) +ctlikelihood::ctlikelihood(const std::string& name, + const std::string& version, + const GObservations& obs) : + ctobservation(name, version, obs) { // Initialise members init_members(); diff --git a/src/support/ctlikelihood.hpp b/src/support/ctlikelihood.hpp index 8ffb9a9..17fa9b2 100755 --- a/src/support/ctlikelihood.hpp +++ b/src/support/ctlikelihood.hpp @@ -44,16 +44,16 @@ public: // Constructors and destructors ctlikelihood(const std::string& name, const std::string& version); - ctlikelihood(const std::string& name, - const std::string& version, - const GObservations& obs); - ctlikelihood(const std::string& name, - const std::string& version, - const std::vector& args); + ctlikelihood(const std::string& name, + const std::string& version, + const GApplicationPars& pars); ctlikelihood(const std::string& name, const std::string& version, int argc, char* argv[]); + ctlikelihood(const std::string& name, + const std::string& version, + const GObservations& obs); ctlikelihood(const ctlikelihood& app); virtual ~ctlikelihood(void); diff --git a/src/support/ctobservation.cpp b/src/support/ctobservation.cpp index 170167d..128bed2 100755 --- a/src/support/ctobservation.cpp +++ b/src/support/ctobservation.cpp @@ -64,25 +64,24 @@ ctobservation::ctobservation(const std::string& name, /***********************************************************************//** - * @brief Observations constructor + * @brief Application parameters constructor * * @param[in] name Observation tool name. * @param[in] version Observation tool version. - * param[in] obs Observation container. + * @param[in] pars Application parameters. * - * Constructs a observation tool from the @p name, @p version and an - * observation container. + * Constructs a observation tool from the @p name, @p version and the + * application parameters @p pars. See the equivalent ctool constructor + * for details. ***************************************************************************/ -ctobservation::ctobservation(const std::string& name, - const std::string& version, - const GObservations& obs) : ctool(name, version) +ctobservation::ctobservation(const std::string& name, + const std::string& version, + const GApplicationPars& pars) : + ctool(name, version, pars) { // Initialise members init_members(); - // Set observations - m_obs = obs; - // Return return; } @@ -93,15 +92,16 @@ ctobservation::ctobservation(const std::string& name, * * @param[in] name Observation tool name. * @param[in] version Observation tool version. - * @param[in] args Arguments vector. + * @param[in] argc Number of arguments in command line. + * @param[in] argv Array of command line arguments. * * Constructs a observation tool from the @p name, @p version and command * line arguments. See the equivalent ctool constructor for details. ***************************************************************************/ -ctobservation::ctobservation(const std::string& name, - const std::string& version, - const std::vector& args) : - ctool(name, version, args) +ctobservation::ctobservation(const std::string& name, + const std::string& version, + int argc, + char *argv[]) : ctool(name, version, argc, argv) { // Initialise members init_members(); @@ -112,24 +112,25 @@ ctobservation::ctobservation(const std::string& name, /***********************************************************************//** - * @brief Command line constructor + * @brief Observations constructor * * @param[in] name Observation tool name. * @param[in] version Observation tool version. - * @param[in] argc Number of arguments in command line. - * @param[in] argv Array of command line arguments. + * param[in] obs Observation container. * - * Constructs a observation tool from the @p name, @p version and command - * line arguments. See the equivalent ctool constructor for details. + * Constructs a observation tool from the @p name, @p version and an + * observation container. ***************************************************************************/ -ctobservation::ctobservation(const std::string& name, - const std::string& version, - int argc, - char *argv[]) : ctool(name, version, argc, argv) +ctobservation::ctobservation(const std::string& name, + const std::string& version, + const GObservations& obs) : ctool(name, version) { // Initialise members init_members(); + // Set observations + m_obs = obs; + // Return return; } diff --git a/src/support/ctobservation.hpp b/src/support/ctobservation.hpp index 3548580..4fd48e3 100755 --- a/src/support/ctobservation.hpp +++ b/src/support/ctobservation.hpp @@ -47,16 +47,16 @@ public: // Constructors and destructors ctobservation(const std::string& name, const std::string& version); - ctobservation(const std::string& name, - const std::string& version, - const GObservations& obs); - ctobservation(const std::string& name, - const std::string& version, - const std::vector& args); + ctobservation(const std::string& name, + const std::string& version, + const GApplicationPars& pars); ctobservation(const std::string& name, const std::string& version, int argc, char* argv[]); + ctobservation(const std::string& name, + const std::string& version, + const GObservations& obs); ctobservation(const ctobservation& app); virtual ~ctobservation(void); diff --git a/src/support/ctool.cpp b/src/support/ctool.cpp index 715815e..2e22e11 100755 --- a/src/support/ctool.cpp +++ b/src/support/ctool.cpp @@ -92,19 +92,8 @@ ctool::ctool(const std::string& name, // Initialise members init_members(); - // If CTOOLS environment variable is set and if a parameter exists in - // the syspfiles folder then set syspfiles folder and reload parameter - // file - char* ptr = std::getenv("CTOOLS"); - if (ptr != NULL) { - std::string path = std::string(ptr) + "/syspfiles"; - std::string filename = path + "/" + par_filename(); - if (access(filename.c_str(), R_OK) == 0) { - m_pars.clear(); - m_pars.syspfiles(path); - m_pars.load(par_filename()); - } - } + // Synchronise parameter files + sync_pfiles(); // Return return; @@ -112,49 +101,24 @@ ctool::ctool(const std::string& name, /***********************************************************************//** - * @brief Command line constructor + * @brief Application parameter constructor * * @param[in] name Application name. * @param[in] version Application version. - * @param[in] args Arguments vector. + * @param[in] pars Application parameters. * - * Constructs a ctool from the @p name, @p version and command line - * arguments. The constructor uses the equivalent GApplication constructor + * Constructs a ctool from the @p name, @p version and application parameters + * @p pars. The constructor uses the equivalent GApplication constructor * to set the parameter filename to ".par" and the log filename to - * "".log. The parameters will be loaded from the parameter file. - * In addition, the constructor opens the log file. - * - * If the "--help" option is provided as command line argument a help text - * about the usage of the ctool will be shown in the console and the ctool - * will exit. No log file will be opened in that case. + * "".log. The constructor opens the log file. ***************************************************************************/ -ctool::ctool(const std::string& name, - const std::string& version, - const std::vector& args) : GApplication(name, version, args) +ctool::ctool(const std::string& name, + const std::string& version, + const GApplicationPars& pars) : GApplication(name, version, pars) { - // Catch --help option before doing anything else - if (need_help()) { - provide_help(); - exit(0); - } - // Initialise members init_members(); - // If CTOOLS environment variable is set and if a parameter exists in - // the syspfiles folder then set syspfiles folder and reload parameter - // file - char* ptr = std::getenv("CTOOLS"); - if (ptr != NULL) { - std::string path = std::string(ptr) + "/syspfiles"; - std::string filename = path + "/" + par_filename(); - if (access(filename.c_str(), R_OK) == 0) { - m_pars.clear(); - m_pars.syspfiles(path); - m_pars.load(par_filename(), m_args); - } - } - // Open the log file logFileOpen(); @@ -195,19 +159,8 @@ ctool::ctool(const std::string& name, // Initialise members init_members(); - // If CTOOLS environment variable is set and if a parameter exists in - // the syspfiles folder then set syspfiles folder and reload parameter - // file - char* ptr = std::getenv("CTOOLS"); - if (ptr != NULL) { - std::string path = std::string(ptr) + "/syspfiles"; - std::string filename = path + "/" + par_filename(); - if (access(filename.c_str(), R_OK) == 0) { - m_pars.clear(); - m_pars.syspfiles(path); - m_pars.load(par_filename(), m_args); - } - } + // Synchronise parameter files + sync_pfiles(); // Open the log file logFileOpen(); @@ -370,6 +323,33 @@ void ctool::free_members(void) /***********************************************************************//** + * @brief Synchronise parameter files + * + * Make sure that the structure of the parameter files in the syspfiles + * folder is used as a reference. + ***************************************************************************/ +void ctool::sync_pfiles(void) +{ + // If CTOOLS environment variable is set and if a parameter file exists + // in the syspfiles folder then set syspfiles folder and reload + // parameter file + char* ptr = std::getenv("CTOOLS"); + if (ptr != NULL) { + std::string path = std::string(ptr) + "/syspfiles"; + std::string filename = path + "/" + par_filename(); + if (access(filename.c_str(), R_OK) == 0) { + m_pars.clear(); + m_pars.syspfiles(path); + m_pars.load(par_filename(), m_args); + } + } + + // Return + return; +} + + +/***********************************************************************//** * @brief Setup observation container * * @param[in] obs Observation container diff --git a/src/support/ctool.hpp b/src/support/ctool.hpp index f7a287a..1029790 100755 --- a/src/support/ctool.hpp +++ b/src/support/ctool.hpp @@ -52,9 +52,9 @@ public: // Constructors and destructors ctool(const std::string& name, const std::string& version); - ctool(const std::string& name, - const std::string& version, - const std::vector& args); + ctool(const std::string& name, + const std::string& version, + const GApplicationPars& pars); ctool(const std::string& name, const std::string& version, int argc, @@ -79,10 +79,11 @@ public: protected: #endif // Protected methods - void init_members(void); - void copy_members(const ctool& app); - void free_members(void); - const bool& read_ahead(void) const; + void init_members(void); + void copy_members(const ctool& app); + void free_members(void); + void sync_pfiles(void); + const bool& read_ahead(void) const; // Protected high-level setup methods void setup_observations(GObservations& obs, const bool& response = true, @@ -154,7 +155,7 @@ protected: protected: // Protected methods void provide_help(void) const; - + // Protected members bool m_use_xml; //!< Use XML file instead of FITS file for observations }; -- libgit2 0.21.4