From b095127733a92aac769fd3498da14aa15062270f Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Thu, 7 Jun 2018 15:50:09 +0200 Subject: [PATCH] Remove ctools::is_valid_filename() method. --- ChangeLog | 3 ++- NEWS | 5 +++-- pyext/ctool.i | 2 -- src/ctbin/ctbin.cpp | 15 +++++++-------- src/ctbkgcube/ctbkgcube.cpp | 39 +++++++++++++++++++++++---------------- src/ctbutterfly/ctbutterfly.cpp | 16 +++++++--------- src/ctcubemask/ctcubemask.cpp | 23 ++++++++++------------- src/ctcubemask/ctcubemask.hpp | 1 - src/ctedispcube/ctedispcube.cpp | 25 +++++++++++++------------ src/cterror/cterror.cpp | 15 +++++++-------- src/ctexpcube/ctexpcube.cpp | 26 ++++++++++++++------------ src/ctlike/ctlike.cpp | 25 +++++++++++++------------ src/ctmapcube/ctmapcube.cpp | 17 ++++++++++------- src/ctmodel/ctmodel.cpp | 46 ++++++++++++++++++++++++---------------------- src/ctobssim/ctobssim.cpp | 7 +++---- src/ctphase/ctphase.cpp | 14 ++++++-------- src/ctprob/ctprob.cpp | 9 ++++----- src/ctpsfcube/ctpsfcube.cpp | 25 +++++++++++++------------ src/ctselect/ctselect.cpp | 7 +++---- src/ctskymap/ctskymap.cpp | 43 ++++++++++++++++++++++++++----------------- src/ctskymap/ctskymap.hpp | 2 +- src/cttsmap/cttsmap.cpp | 17 ++++++++--------- src/support/ctool.cpp | 210 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------------ src/support/ctool.hpp | 16 ---------------- test/test_cscript.py | 14 +------------- 25 files changed, 300 insertions(+), 322 deletions(-) diff --git a/ChangeLog b/ChangeLog index e550624..1882206 100755 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,9 @@ -2018-04-10 +2018-06-07 * Version 1.6.0 released ======================== + Remove ctools::is_valid_filename() method. Fix bug when using precomputed model in csresspec (#2448) Keep existing library path in installation script on Mac OS X (#2420) Add show_rmf.py example script diff --git a/NEWS b/NEWS index b5b9447..76c8faa 100755 --- a/NEWS +++ b/NEWS @@ -1,6 +1,6 @@ New Features and Important Changes in ctools 1.6.0 -5 June 2018 +7 June 2018 Introduction @@ -26,7 +26,8 @@ None Base classes ------------ -None +The ctools::is_valid_filename() method was removed since the validity check +of the filename is now done by the GApplicationPar class. ctbin - CTA event binning diff --git a/pyext/ctool.i b/pyext/ctool.i index 82c4b20..277bc1c 100755 --- a/pyext/ctool.i +++ b/pyext/ctool.i @@ -115,7 +115,6 @@ public: %rename(_get_obs_header) get_obs_header; %rename(_insert_energy_boundaries) insert_energy_boundaries; %rename(_cube_layer_usage) cube_layer_usage; - %rename(_is_valid_filename) is_valid_filename; %rename(_get_gtiname) get_gtiname; %rename(_save_event_list) save_event_list; %rename(_warn_too_few_energies) warn_too_few_energies; @@ -167,7 +166,6 @@ public: const GCTAObservation& obs); std::vector cube_layer_usage(const GEbounds& cube_ebounds, const GEbounds& list_ebounds) const; - bool is_valid_filename(const GFilename& filename) const; std::string get_gtiname(const std::string& filename, const std::string& evtname) const; void save_event_list(const GCTAObservation* obs, diff --git a/src/ctbin/ctbin.cpp b/src/ctbin/ctbin.cpp index 8b5ccea..e1270d8 100755 --- a/src/ctbin/ctbin.cpp +++ b/src/ctbin/ctbin.cpp @@ -301,12 +301,12 @@ void ctbin::save(void) // Write header log_header1(TERSE, "Save counts cube"); - // Get counts cube filename - m_outcube = (*this)["outcube"].filename(); - - // Save only if filename is not empty and if there is at least one + // Save only if filename is valid and if there is at least one // observation - if (!m_outcube.is_empty() && m_obs.size() > 0) { + if ((*this)["outcube"].is_valid() && m_obs.size() > 0) { + + // Get counts cube filename + m_outcube = (*this)["outcube"].filename(); // Get CTA observation from observation container GCTAObservation* obs = dynamic_cast(m_obs[0]); @@ -464,10 +464,9 @@ void ctbin::get_parameters(void) m_publish = (*this)["publish"].boolean(); m_chatter = static_cast((*this)["chatter"].integer()); - // Optionally read ahead parameters so that they get correctly - // dumped into the log file + // If needed later, query output filename now if (read_ahead()) { - m_outcube = (*this)["outcube"].filename(); + (*this)["outcube"].query(); } // Cache sky directions in m_counts diff --git a/src/ctbkgcube/ctbkgcube.cpp b/src/ctbkgcube/ctbkgcube.cpp index 7bb7ea5..0851f31 100755 --- a/src/ctbkgcube/ctbkgcube.cpp +++ b/src/ctbkgcube/ctbkgcube.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * ctbkgcube - Background cube generation tool * * ----------------------------------------------------------------------- * - * copyright (C) 2014-2017 by Chia-Chun Lu * + * copyright (C) 2014-2018 by Chia-Chun Lu * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -351,21 +351,30 @@ void ctbkgcube::save(void) // Write header log_header1(TERSE, "Save background cube"); - // Get background cube and model file names - m_outcube = (*this)["outcube"].filename(); - m_outmodel = (*this)["outmodel"].filename(); - // Determine whether a model definition file should be written - bool write_moddef = is_valid_filename(m_outmodel); + bool write_moddef = (*this)["outmodel"].is_valid(); + + // Save background cube if filename is valid and the background cube is + // not empty + if ((*this)["outcube"].is_valid() && !m_background.cube().is_empty()) { + + // Get background cube file name + m_outcube = (*this)["outcube"].filename(); - // Save background cube if filename and the background cube are not empty - if (!m_outcube.is_empty() && !m_background.cube().is_empty()) { + // Save background cube m_background.save(m_outcube, clobber()); + } // Save model definition file if requested if (write_moddef) { + + // Get model file name + m_outmodel = (*this)["outmodel"].filename(); + + // Save model m_outmdl.save(m_outmodel.url()); + } // Write into logger what has been done @@ -483,14 +492,12 @@ void ctbkgcube::get_parameters(void) // event lists, but do not accept counts cubes. setup_observations(m_obs, true, true, false); - // Get the incube filename - std::string incube = (*this)["incube"].filename(); - // If the "incube" file name is valid then setup the background cube from // the counts cube. Otherwise create a counts cube from the user // parameters - GCTAEventCube cube = is_valid_filename(incube) ? GCTAEventCube(incube) - : create_cube(m_obs); + GCTAEventCube cube = (*this)["incube"].is_valid() + ? GCTAEventCube((*this)["incube"].filename()) + : create_cube(m_obs); // Define background cube m_background = GCTACubeBackground(cube); @@ -503,10 +510,10 @@ void ctbkgcube::get_parameters(void) m_publish = (*this)["publish"].boolean(); m_chatter = static_cast((*this)["chatter"].integer()); - // Read output filenames (if needed) + // If needed later, query output filenames now if (read_ahead()) { - m_outcube = (*this)["outcube"].filename(); - m_outmodel = (*this)["outmodel"].filename(); + (*this)["outcube"].query(); + (*this)["outmodel"].query(); } // Write parameters into logger diff --git a/src/ctbutterfly/ctbutterfly.cpp b/src/ctbutterfly/ctbutterfly.cpp index dbd598a..073c30e 100755 --- a/src/ctbutterfly/ctbutterfly.cpp +++ b/src/ctbutterfly/ctbutterfly.cpp @@ -340,11 +340,11 @@ void ctbutterfly::save(void) // Write header into logger log_header1(TERSE, "Save Butterfly diagram"); - // Get output filename - m_outfile = (*this)["outfile"].filename(); + // Save only if filename is valid + if ((*this)["outfile"].is_valid()) { - // Save only if filename is non-empty - if (!m_outfile.is_empty()) { + // Get output filename + m_outfile = (*this)["outfile"].filename(); // Log butterfly diagram file name log_value(NORMAL, "Butterfly file", m_outfile.url()); @@ -465,8 +465,7 @@ void ctbutterfly::get_parameters(void) m_ebounds = create_ebounds(); // Get matrix file name and load if possible - std::string matrixfilename = (*this)["matrix"].filename(); - if (matrixfilename != "NONE") { + if ((*this)["matrix"].is_valid()) { std::string msg = "Loading of matrix from file not implemented yet. " "Use filename = \"NONE\" to induce a recomputation " "of the matrix internally."; @@ -484,10 +483,9 @@ void ctbutterfly::get_parameters(void) // Check model name and type check_model(); - // Optionally read ahead parameters so that they get correctly - // dumped into the log file + // If needed later, query output filename now if (read_ahead()) { - m_outfile = (*this)["outfile"].filename(); + (*this)["outfile"].query(); } // Write parameters into logger diff --git a/src/ctcubemask/ctcubemask.cpp b/src/ctcubemask/ctcubemask.cpp index b30caa1..b40223f 100755 --- a/src/ctcubemask/ctcubemask.cpp +++ b/src/ctcubemask/ctcubemask.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * ctcubemask - Cube filter tool * * ----------------------------------------------------------------------- * - * copyright (C) 2014-2016 by Chia-Chun Lu * + * copyright (C) 2014-2018 by Chia-Chun Lu * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -372,7 +372,6 @@ void ctcubemask::publish(const std::string& name) void ctcubemask::init_members(void) { // Initialise parameters - m_regfile.clear(); m_outcube.clear(); m_prefix.clear(); m_emin = 0.0; @@ -396,7 +395,6 @@ void ctcubemask::init_members(void) void ctcubemask::copy_members(const ctcubemask& app) { // Copy parameters - m_regfile = app.m_regfile; m_outcube = app.m_outcube; m_prefix = app.m_prefix; m_emin = app.m_emin; @@ -441,8 +439,8 @@ void ctcubemask::get_parameters(void) // information and do not accept event lists. setup_observations(m_obs, false, false, true); - // Get parameters - m_regfile = (*this)["regfile"].filename(); + // Query "regfile" parameter + (*this)["regfile"].query(); // Query the RoI GCTARoi roi = get_roi(); @@ -460,11 +458,10 @@ void ctcubemask::get_parameters(void) // Get remaining parameters m_publish = (*this)["publish"].boolean(); - // Optionally read ahead parameters so that they get correctly - // dumped into the log file + // If needed later, query output filename and prefix now if (read_ahead()) { - m_outcube = (*this)["outcube"].filename(); - m_prefix = (*this)["prefix"].string(); + (*this)["outcube"].query(); + (*this)["prefix"].query(); } // Write parameters into logger @@ -576,8 +573,8 @@ void ctcubemask::apply_mask(GCTAObservation* obs) // Set all pixels inside selected energy bands and inside exclusion // regions to -1.0 - if (m_regfile != "NONE") { - GSkyRegions regions = GSkyRegions(m_regfile); + if ((*this)["regfile"].is_valid()) { + GSkyRegions regions = GSkyRegions((*this)["regfile"].filename()); for (int i = e_idx1; i <= e_idx2; ++i) { for (int pixel = 0; pixel < npix; ++pixel) { GSkyDir dir = map.inx2dir(pixel); @@ -679,8 +676,8 @@ std::string ctcubemask::set_outfile_name(const std::string& filename) const ***************************************************************************/ void ctcubemask::save_fits(void) { - // Save only if filename is non-empty and if there are observations - if (!m_outcube.is_empty() && m_obs.size() > 0) { + // Save only if there are observations + if (m_obs.size() > 0) { // Get CTA observation from observation container GCTAObservation* obs = dynamic_cast(m_obs[0]); diff --git a/src/ctcubemask/ctcubemask.hpp b/src/ctcubemask/ctcubemask.hpp index 463ffc6..cc8997b 100755 --- a/src/ctcubemask/ctcubemask.hpp +++ b/src/ctcubemask/ctcubemask.hpp @@ -76,7 +76,6 @@ protected: void save_xml(void); // User parameters - GFilename m_regfile; //!< ds9 region file GFilename m_outcube; //!< Output event list or XML file std::string m_prefix; //!< Prefix for multiple counts maps double m_emin; //!< Lower energy diff --git a/src/ctedispcube/ctedispcube.cpp b/src/ctedispcube/ctedispcube.cpp index fc0288f..950bbbe 100755 --- a/src/ctedispcube/ctedispcube.cpp +++ b/src/ctedispcube/ctedispcube.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * ctedispcube - Energy dispersion cube generation tool * * ----------------------------------------------------------------------- * - * copyright (C) 2016 by Maria Haupt * + * copyright (C) 2016-2018 by Maria Haupt * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -260,13 +260,16 @@ void ctedispcube::save(void) // Write header into logger log_header1(TERSE, "Save energy dispersion cube"); - // Get output filename - m_outcube = (*this)["outcube"].filename(); - // Save energy dispersion cube if filename and the energy dispersion cube // are not empty - if (!m_outcube.is_empty() && !m_edispcube.cube().is_empty()) { + if ((*this)["outcube"].is_valid() && !m_edispcube.cube().is_empty()) { + + // Get output filename + m_outcube = (*this)["outcube"].filename(); + + // Save energy dispersion cube m_edispcube.save(m_outcube, clobber()); + } // Write into logger what has been done @@ -346,9 +349,6 @@ void ctedispcube::get_parameters(void) // Setup observations from "inobs" parameter. Do not accept counts cubes. setup_observations(m_obs, true, true, false); - // Get the incube filename - std::string incube = (*this)["incube"].filename(); - // Get additional binning parameters double migramax = (*this)["migramax"].real(); int migrabins = (*this)["migrabins"].integer(); @@ -356,8 +356,9 @@ void ctedispcube::get_parameters(void) // If the "incube" file name is valid then setup the energy dispersion // cube from the counts cube. Otherwise create a counts cube from the // user parameters - GCTAEventCube cube = is_valid_filename(incube) ? GCTAEventCube(incube) - : create_cube(m_obs); + GCTAEventCube cube = (*this)["incube"].is_valid() + ? GCTAEventCube((*this)["incube"].filename()) + : create_cube(m_obs); // Define edisp cube m_edispcube = GCTACubeEdisp(cube, migramax, migrabins); @@ -366,9 +367,9 @@ void ctedispcube::get_parameters(void) m_addbounds = (*this)["addbounds"].boolean(); m_chatter = static_cast((*this)["chatter"].integer()); - // Read output filename (if needed) + // If needed later, query output filename now if (read_ahead()) { - m_outcube = (*this)["outcube"].filename(); + (*this)["outcube"].query(); } // Write parameters into logger diff --git a/src/cterror/cterror.cpp b/src/cterror/cterror.cpp index bf00ed5..44fed01 100755 --- a/src/cterror/cterror.cpp +++ b/src/cterror/cterror.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * cterror - Parameter error calculation tool * * ----------------------------------------------------------------------- * - * copyright (C) 2015-2017 by Florent Forest * + * copyright (C) 2015-2018 by Florent Forest * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -344,11 +344,11 @@ void cterror::save(void) // Write header log_header1(TERSE, "Save results"); - // Get output filename - m_outmodel = (*this)["outmodel"].filename(); - // Save only if filename is valid - if (is_valid_filename(m_outmodel)) { + if ((*this)["outmodel"].is_valid()) { + + // Get output filename + m_outmodel = (*this)["outmodel"].filename(); // Log filename log_value(NORMAL, "Model definition file", m_outmodel.url()); @@ -472,10 +472,9 @@ void cterror::get_parameters(void) m_max_iter = (*this)["max_iter"].integer(); m_chatter = static_cast((*this)["chatter"].integer()); - // Read ahead parameters that are only needed when the tool gets - // executed + // If needed later, query output filename now if (read_ahead()) { - m_outmodel = (*this)["outmodel"].filename(); + (*this)["outmodel"].query(); } // Write parameters into logger diff --git a/src/ctexpcube/ctexpcube.cpp b/src/ctexpcube/ctexpcube.cpp index 6d8d354..3be5b66 100755 --- a/src/ctexpcube/ctexpcube.cpp +++ b/src/ctexpcube/ctexpcube.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * ctexpcube - Exposure cube generation tool * * ----------------------------------------------------------------------- * - * copyright (C) 2014-2016 by Juergen Knoedlseder * + * copyright (C) 2014-2018 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -256,12 +256,16 @@ void ctexpcube::save(void) // Write header into logger log_header1(TERSE, "Save exposure cube"); - // Get exposure cube filename - m_outcube = (*this)["outcube"].filename(); + // Save exposure cube if filename is valid and the exposure cube is not + // empty + if ((*this)["outcube"].is_valid() && !m_expcube.cube().is_empty()) { - // Save exposure cube if filename and the exposure cube are not empty - if (!m_outcube.is_empty() && !m_expcube.cube().is_empty()) { + // Get exposure cube filename + m_outcube = (*this)["outcube"].filename(); + + // Save exposure cube m_expcube.save(m_outcube, clobber()); + } // Write into logger what has been done @@ -370,14 +374,12 @@ void ctexpcube::get_parameters(void) // Setup observations from "inobs" parameter. Do not accept counts cubes. setup_observations(m_obs, true, true, false); - // Get the incube filename - std::string incube = (*this)["incube"].filename(); - // If the "incube" file name is valid then setup the exposure cube from // the counts cube. Otherwise create a counts cube from the user // parameters - GCTAEventCube cube = is_valid_filename(incube) ? GCTAEventCube(incube) - : create_cube(m_obs); + GCTAEventCube cube = (*this)["incube"].is_valid() + ? GCTAEventCube((*this)["incube"].filename()) + : create_cube(m_obs); // Define exposure cube m_expcube = GCTACubeExposure(cube); @@ -387,9 +389,9 @@ void ctexpcube::get_parameters(void) m_publish = (*this)["publish"].boolean(); m_chatter = static_cast((*this)["chatter"].integer()); - // Read output filename (if needed) + // If needed later, query output filename now if (read_ahead()) { - m_outcube = (*this)["outcube"].filename(); + (*this)["outcube"].query(); } // Write parameters into logger diff --git a/src/ctlike/ctlike.cpp b/src/ctlike/ctlike.cpp index 51e9a00..4f892d4 100755 --- a/src/ctlike/ctlike.cpp +++ b/src/ctlike/ctlike.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * ctlike - Maximum likelihood fitting tool * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2017 by Juergen Knoedlseder * + * copyright (C) 2010-2018 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -334,12 +334,11 @@ void ctlike::save(void) // Write header log_header1(TERSE, "Save results"); - // Get output filenames - m_outmodel = (*this)["outmodel"].filename(); - m_outcovmat = (*this)["outcovmat"].filename(); + // Save model only if filename is valid + if ((*this)["outmodel"].is_valid()) { - // Save only if filename is valid - if (is_valid_filename(m_outmodel)) { + // Get output filename + m_outmodel = (*this)["outmodel"].filename(); // Log filename log_value(NORMAL, "Model definition file", m_outmodel.url()); @@ -354,8 +353,11 @@ void ctlike::save(void) log_value(NORMAL, "Model definition file", "NONE"); } - // Save covariance matrix if filename is valid - if (is_valid_filename(m_outcovmat)) { + // Save covariance matrix only if filename is valid + if ((*this)["outcovmat"].is_valid()) { + + // Get output filenames + m_outcovmat = (*this)["outcovmat"].filename(); // Log filename log_value(NORMAL, "Covariance matrix file", m_outcovmat.url()); @@ -406,11 +408,10 @@ void ctlike::get_parameters(void) m_fix_spat_for_ts = (*this)["fix_spat_for_ts"].boolean(); m_chatter = static_cast((*this)["chatter"].integer()); - // Optionally read ahead parameters so that they get correctly - // dumped into the log file + // If needed later, query output filenames now if (read_ahead()) { - m_outmodel = (*this)["outmodel"].filename(); - m_outcovmat = (*this)["outcovmat"].filename(); + (*this)["outmodel"].query(); + (*this)["outcovmat"].query(); } // Set optimizer logger diff --git a/src/ctmapcube/ctmapcube.cpp b/src/ctmapcube/ctmapcube.cpp index 6c3af23..c2e7ec2 100755 --- a/src/ctmapcube/ctmapcube.cpp +++ b/src/ctmapcube/ctmapcube.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * ctmapcube - Map cube generation tool * * ----------------------------------------------------------------------- * - * copyright (C) 2016-2017 by Juergen Knoedlseder * + * copyright (C) 2016-2018 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -222,12 +222,15 @@ void ctmapcube::save(void) // Write header log_header1(TERSE, "Save map cube"); - // Get map cube filename - m_outcube = (*this)["outcube"].filename(); + // Save map cube if filename is valid and the map cube is not empty + if ((*this)["outcube"].is_valid() && !m_cube.cube().is_empty()) { - // Save map cube if filename and the map cube are not empty - if (!m_outcube.is_empty() && !m_cube.cube().is_empty()) { + // Get map cube filename + m_outcube = (*this)["outcube"].filename(); + + // Save map cube m_cube.save(m_outcube, clobber()); + } // Write into logger what has been done @@ -365,9 +368,9 @@ void ctmapcube::get_parameters(void) m_publish = (*this)["publish"].boolean(); m_chatter = static_cast((*this)["chatter"].integer()); - // Read optionally output cube filenames + // If needed later, query output filename now if (read_ahead()) { - m_outcube = (*this)["outcube"].filename(); + (*this)["outcube"].query(); } // Allocate map cube diff --git a/src/ctmodel/ctmodel.cpp b/src/ctmodel/ctmodel.cpp index 438b25c..1b938a5 100755 --- a/src/ctmodel/ctmodel.cpp +++ b/src/ctmodel/ctmodel.cpp @@ -313,11 +313,13 @@ void ctmodel::save(void) // Write header log_header1(TERSE, "Save model cube"); - // Get model cube filename - m_outcube = (*this)["outcube"].filename(); + // Save only if filename is valid and cube has some size + if ((*this)["outcube"].is_valid() && m_cube.size() > 0) { - // Save only if filename is non-empty and cube has some size - if (!m_outcube.is_empty() && m_cube.size() > 0) { + // Get model cube filename + m_outcube = (*this)["outcube"].filename(); + + // Save cube m_cube.save(m_outcube, clobber()); } @@ -533,13 +535,13 @@ void ctmodel::get_parameters(void) // should create it from scratch using the task parameters if (!m_has_cube) { - // Read cube definition file - std::string incube = (*this)["incube"].filename(); - // If the cube filename is valid the load the cube and set all cube // bins to zero if ((*this)["incube"].is_valid()) { + // Get cube definition filename + std::string incube = (*this)["incube"].filename(); + // Load cube from given file m_cube.load(incube); @@ -564,9 +566,9 @@ void ctmodel::get_parameters(void) m_publish = (*this)["publish"].boolean(); m_chatter = static_cast((*this)["chatter"].integer()); - // Read optionally output cube filenames + // If needed later, query output filename now if (read_ahead()) { - m_outcube = (*this)["outcube"].filename(); + (*this)["outcube"].query(); } // If cube should be appended to first observation then do that now. @@ -621,29 +623,26 @@ void ctmodel::get_parameters(void) ***************************************************************************/ void ctmodel::get_obs(void) { - // Get the filename from the input parameters - std::string filename = (*this)["inobs"].filename(); - // If no observation definition file has been specified then read all // parameters that are necessary to create an observation from scratch if ((*this)["inobs"].is_undefined()) { - // Get response cube filenames - GFilename edispcube; - bool query_edisp = (*this)["edisp"].boolean(); - std::string expcube = (*this)["expcube"].filename(); - std::string psfcube = (*this)["psfcube"].filename(); - if (query_edisp) { - edispcube = (*this)["edispcube"].filename(); - } - std::string bkgcube = (*this)["bkgcube"].filename(); - // If the filenames are valid then build an observation from cube // response information if ((*this)["expcube"].is_valid() && (*this)["psfcube"].is_valid() && (*this)["bkgcube"].is_valid()) { + // Get response cube filenames + GFilename edispcube; + bool query_edisp = (*this)["edisp"].boolean(); + GFilename expcube = (*this)["expcube"].filename(); + GFilename psfcube = (*this)["psfcube"].filename(); + if (query_edisp && (*this)["edispcube"].is_valid()) { + edispcube = (*this)["edispcube"].filename(); + } + GFilename bkgcube = (*this)["bkgcube"].filename(); + // Get exposure, PSF and background cubes GCTACubeExposure exposure(expcube); GCTACubePsf psf(psfcube); @@ -721,6 +720,9 @@ void ctmodel::get_obs(void) // ... otherwise we have a file name else { + // Get the filename from the input parameters + std::string filename = (*this)["inobs"].filename(); + // If file is a FITS file then create an empty CTA observation // and load file into observation if (GFilename(filename).is_fits()) { diff --git a/src/ctobssim/ctobssim.cpp b/src/ctobssim/ctobssim.cpp index d487d4b..9ec0724 100755 --- a/src/ctobssim/ctobssim.cpp +++ b/src/ctobssim/ctobssim.cpp @@ -643,11 +643,10 @@ void ctobssim::get_parameters(void) m_max_rate = (*this)["maxrate"].real(); m_startindex = (*this)["startindex"].integer(); - // Optionally read ahead parameters so that they get correctly - // dumped into the log file + // If needed later, query output filename and prefix now if (read_ahead()) { - m_outevents = (*this)["outevents"].filename(); - m_prefix = (*this)["prefix"].string(); + (*this)["outevents"].query(); + (*this)["prefix"].query(); } // Initialise random number generators. We initialise here one random diff --git a/src/ctphase/ctphase.cpp b/src/ctphase/ctphase.cpp index a5c2cc3..f961f15 100755 --- a/src/ctphase/ctphase.cpp +++ b/src/ctphase/ctphase.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * ctphase - Append phase information to CTA events file * * ----------------------------------------------------------------------- * - * copyright (C) 2017 by Joshua Cardenzana * + * copyright (C) 2017-2018 by Joshua Cardenzana * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -409,9 +409,8 @@ void ctphase::get_parameters(void) // from a model definiton XML file specified by the "inmodel" parameter. // The model is only loaded of the file is valid. if (m_obs.models().size() == 0) { - GFilename inmodel = (*this)["inmodel"].filename(); - if (is_valid_filename(inmodel)) { - m_obs.models(inmodel); + if ((*this)["inmodel"].is_valid()) { + m_obs.models((*this)["inmodel"].filename()); } } @@ -481,11 +480,10 @@ void ctphase::get_parameters(void) } // endelse: read phase curve information from User parameters - // Optionally read ahead parameters so that they get correctly - // dumped into the log file + // If needed later, query output filename and prefix now if (read_ahead()) { - (*this)["outobs"].filename(); - (*this)["prefix"].string(); + (*this)["outobs"].query(); + (*this)["prefix"].query(); } // Write parameters into logger diff --git a/src/ctprob/ctprob.cpp b/src/ctprob/ctprob.cpp index ae08e0f..ad6ddd9 100755 --- a/src/ctprob/ctprob.cpp +++ b/src/ctprob/ctprob.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * ctprob - Computes event probability for a given model * * ----------------------------------------------------------------------- * - * copyright (C) 2017 by Leonardo Di Venere * + * copyright (C) 2017-2018 by Leonardo Di Venere * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -433,11 +433,10 @@ void ctprob::get_parameters(void) m_publish = (*this)["publish"].boolean(); m_chatter = static_cast((*this)["chatter"].integer()); - // Optionally read ahead parameters so that they get correctly - // dumped into the log file + // If needed later, query output filename and prefix now if (read_ahead()) { - (*this)["outobs"].filename(); - (*this)["prefix"].string(); + (*this)["outobs"].query(); + (*this)["prefix"].query(); } // Write parameters into logger diff --git a/src/ctpsfcube/ctpsfcube.cpp b/src/ctpsfcube/ctpsfcube.cpp index 5b58b3f..42a1585 100755 --- a/src/ctpsfcube/ctpsfcube.cpp +++ b/src/ctpsfcube/ctpsfcube.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * ctpsfcube - PSF cube generation tool * * ----------------------------------------------------------------------- * - * copyright (C) 2014-2017 by Chia-Chun Lu * + * copyright (C) 2014-2018 by Chia-Chun Lu * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -248,12 +248,15 @@ void ctpsfcube::save(void) // Write header into logger log_header1(TERSE, "Save PSF cube"); - // Get output filename - m_outcube = (*this)["outcube"].filename(); + // Save PSF cube if filename is valid and the PSF cube is not empty + if ((*this)["outcube"].is_valid() && !m_psfcube.cube().is_empty()) { - // Save PSF cube if filename and the PSF cube are not empty - if (!m_outcube.is_empty() && !m_psfcube.cube().is_empty()) { + // Get output filename + m_outcube = (*this)["outcube"].filename(); + + // Save PSF cube m_psfcube.save(m_outcube, clobber()); + } // Write into logger what has been done @@ -333,17 +336,15 @@ void ctpsfcube::get_parameters(void) // Setup observations from "inobs" parameter. Do not accept counts cubes. setup_observations(m_obs, true, true, false); - // Get the incube filename - std::string incube = (*this)["incube"].filename(); - // Get additional binning parameters double amax = (*this)["amax"].real(); int anumbins = (*this)["anumbins"].integer(); // If the "incube" file name is valid then setup the PSF cube from the // counts cube. Otherwise create a counts cube from the user parameters - GCTAEventCube cube = is_valid_filename(incube) ? GCTAEventCube(incube) - : create_cube(m_obs); + GCTAEventCube cube = (*this)["incube"].is_valid() + ? GCTAEventCube((*this)["incube"].filename()) + : create_cube(m_obs); // Define PSF cube m_psfcube = GCTACubePsf(cube, amax, anumbins); @@ -352,9 +353,9 @@ void ctpsfcube::get_parameters(void) m_addbounds = (*this)["addbounds"].boolean(); m_chatter = static_cast((*this)["chatter"].integer()); - // Read output filename (if needed) + // If needed later, query output filename now if (read_ahead()) { - m_outcube = (*this)["outcube"].filename(); + (*this)["outcube"].query(); } // Write parameters into logger diff --git a/src/ctselect/ctselect.cpp b/src/ctselect/ctselect.cpp index d5754c5..dd6b478 100755 --- a/src/ctselect/ctselect.cpp +++ b/src/ctselect/ctselect.cpp @@ -647,11 +647,10 @@ void ctselect::get_parameters(void) m_usethres = (*this)["usethres"].string(); m_chatter = static_cast((*this)["chatter"].integer()); - // Optionally read ahead parameters so that they get correctly - // dumped into the log file + // If needed later, query output filename and prefix now if (read_ahead()) { - m_outobs = (*this)["outobs"].filename(); - (*this)["prefix"].string(); + (*this)["outobs"].query(); + (*this)["prefix"].query(); } // Set time interval with input times given in CTA reference diff --git a/src/ctskymap/ctskymap.cpp b/src/ctskymap/ctskymap.cpp index a75fe29..b3b4f79 100755 --- a/src/ctskymap/ctskymap.cpp +++ b/src/ctskymap/ctskymap.cpp @@ -255,11 +255,11 @@ void ctskymap::save(void) // Write header log_header1(TERSE, "Save sky map"); - // Get sky map filename - m_outmap = (*this)["outmap"].filename(); + // Save sky map if filename is valid and sky map is not empty + if ((*this)["outmap"].is_valid() && !m_skymap.is_empty()) { - // Save sky map if filename and the map are not empty - if (!m_outmap.is_empty() && !m_skymap.is_empty()) { + // Get sky map filename + m_outmap = (*this)["outmap"].filename(); // Create empty FITS file GFits fits; @@ -453,9 +453,15 @@ void ctskymap::get_parameters(void) // If an input map was specified then extract try loading the COUNTS // and ACCEPTANCE extensions from that file - GFilename inmap = (*this)["inmap"].filename(); - if (inmap != "NONE") { + if ((*this)["inmap"].is_valid()) { + + // Read inmap filename + GFilename inmap = (*this)["inmap"].filename(); + + // Open file GFits fits(inmap); + + // Continue only if required extensions exist if (fits.contains("COUNTS") && fits.contains("ACCEPTANCE")) { // Get HDUs @@ -508,7 +514,7 @@ void ctskymap::get_parameters(void) // Get RING background parameters if (m_bkgsubtract == "RING") { - // Get parameters + // Get (or query) parameters m_roiradius = (*this)["roiradius"].real(); m_inradius = (*this)["inradius"].real(); m_outradius = (*this)["outradius"].real(); @@ -516,7 +522,7 @@ void ctskymap::get_parameters(void) if (m_iterations > 0) { m_threshold = (*this)["threshold"].real(); } - m_inexclusion = (*this)["inexclusion"].filename(); + (*this)["inexclusion"].query(); m_usefft = (*this)["usefft"].boolean(); // Make sure that (roiradius < inradius < outradius) @@ -541,9 +547,9 @@ void ctskymap::get_parameters(void) m_publish = (*this)["publish"].boolean(); m_chatter = static_cast((*this)["chatter"].integer()); - // Read ahead parameters + // If needed later, query output filename now if (read_ahead()) { - m_outmap = (*this)["outmap"].filename(); + (*this)["outmap"].query(); } // Write parameters into logger @@ -570,7 +576,7 @@ void ctskymap::setup_maps(void) if (m_bkgsubtract != "NONE") { // Setup the exclusions map - setup_exclusion_map(m_inexclusion); + setup_exclusion_map(); // Cache the pixel solid angles and sky directions m_solidangle.reserve(m_counts.npix()); @@ -603,7 +609,7 @@ void ctskymap::setup_maps(void) * background estimation. Pixels with values different from 0 will be * excluded. ***************************************************************************/ -void ctskymap::setup_exclusion_map(const GFilename& filename) +void ctskymap::setup_exclusion_map(void) { // Create exlusion map m_exclmap = m_counts; @@ -611,15 +617,18 @@ void ctskymap::setup_exclusion_map(const GFilename& filename) // Set all pixels to 0 (no pixel excluded) m_exclmap = 0.0; - // Make sure the exclusions filename is valid - if (is_valid_filename(filename)) { + // Generate map only if exclusion map filename is valid + if ((*this)["inexclusion"].is_valid()) { + + // Get exclusion map filename + m_inexclusion = (*this)["inexclusion"].filename(); // Fill the exclusions based on the regions supplied - if (filename.is_fits()) { - setup_exclusion_map_fits(filename); + if (m_inexclusion.is_fits()) { + setup_exclusion_map_fits(m_inexclusion); } else { - setup_exclusion_map_region(filename); + setup_exclusion_map_region(m_inexclusion); } } // endif: filename was valid diff --git a/src/ctskymap/ctskymap.hpp b/src/ctskymap/ctskymap.hpp index f23e292..c30b265 100755 --- a/src/ctskymap/ctskymap.hpp +++ b/src/ctskymap/ctskymap.hpp @@ -69,7 +69,7 @@ protected: void free_members(void); void get_parameters(void); void setup_maps(void); - void setup_exclusion_map(const GFilename& filename); + void setup_exclusion_map(void); void setup_exclusion_map_fits(const GFilename& filename); void setup_exclusion_map_region(const GFilename& filename); void fill_maps(void); diff --git a/src/cttsmap/cttsmap.cpp b/src/cttsmap/cttsmap.cpp index 52c029b..06b6e5d 100755 --- a/src/cttsmap/cttsmap.cpp +++ b/src/cttsmap/cttsmap.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * cttsmap - TS map calculation tool * * ----------------------------------------------------------------------- * - * copyright (C) 2014-2017 by Michael Mayer * + * copyright (C) 2014-2018 by Michael Mayer * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -370,12 +370,12 @@ void cttsmap::save(void) // Write header log_header1(TERSE, "Save TS map"); - // Get TS map filename - m_outmap = (*this)["outmap"].filename(); - - // Save only if filename is non-empty - if (!m_outmap.is_empty() && !m_tsmap.is_empty()) { + // Save only if filename is valid and TS map is not empty + if ((*this)["outmap"].is_valid() && !m_tsmap.is_empty()) { + // Get TS map filename + m_outmap = (*this)["outmap"].filename(); + // Create fits file GFits fits; @@ -578,10 +578,9 @@ void cttsmap::get_parameters(void) m_logL0 = (*this)["logL0"].real(); m_publish = (*this)["publish"].boolean(); - // Optionally read ahead parameters so that they get correctly - // dumped into the log file + // If needed later, query output filename now if (read_ahead()) { - m_outmap = (*this)["outmap"].filename(); + (*this)["outmap"].query(); } // Write parameters into logger diff --git a/src/support/ctool.cpp b/src/support/ctool.cpp index faf9125..fb52f6d 100755 --- a/src/support/ctool.cpp +++ b/src/support/ctool.cpp @@ -86,8 +86,8 @@ * * This constructor should be used for using a ctool from Python. ***************************************************************************/ -ctool::ctool(const std::string& name, const std::string& version) : - GApplication(name, version) +ctool::ctool(const std::string& name, + const std::string& version) : GApplication(name, version) { // Initialise members init_members(); @@ -115,9 +115,10 @@ ctool::ctool(const std::string& name, const std::string& version) : * 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. ***************************************************************************/ -ctool::ctool(const std::string& name, const std::string& version, - int argc, char *argv[]) : - GApplication(name, version, argc, argv) +ctool::ctool(const std::string& name, + const std::string& version, + int argc, + char* argv[]) : GApplication(name, version, argc, argv) { // Catch --help option before doing anything else if (need_help()) { @@ -179,8 +180,9 @@ ctool::~ctool(void) * @brief Assignment operator * * @param[in] app Application. + * @return Application. * - * Assigns one ctool to another. + * Assigns one ctool application to another. ***************************************************************************/ ctool& ctool::operator=(const ctool& app) { @@ -250,11 +252,6 @@ void ctool::init_members(void) m_read_ahead = false; m_use_xml = false; - // Set CTA time reference. G_CTA_MJDREF is the CTA reference MJD, - // which is defined in GCTALib.hpp. This is somehow a kluge. We need - // a better mechanism to implement the CTA reference MJD. - //m_cta_ref.set(G_CTA_MJDREF, "s", "TT", "LOCAL"); - // Set logger properties log.date(true); @@ -276,7 +273,6 @@ void ctool::copy_members(const ctool& app) // Copy members m_read_ahead = app.m_read_ahead; m_use_xml = app.m_use_xml; - //m_cta_ref = app.m_cta_ref; // Return return; @@ -346,19 +342,20 @@ void ctool::setup_observations(GObservations& obs, // Load observations if there are none in the container if (obs.size() == 0) { - // Get the filename from the "inobs" parameter - GFilename filename = (*this)["inobs"].filename(); - // Throw an exception if the "inobs" parameter is not a valid // filename - if (!is_valid_filename(filename)) { - std::string msg = "The \"inobs\" parameter \""+filename.url()+ + if ((*this)["inobs"].is_undefined()) { + std::string msg = "The \"inobs\" parameter \""+ + (*this)["inobs"].current_value()+ "\" is not a valid filename. Please specify " "a valid event list, counts cube or " "observation definition XML file."; throw GException::invalid_value(G_SETUP_OBSERVATION, msg); } + // Get the filename from the "inobs" parameter + GFilename filename = (*this)["inobs"].filename(); + // If file does not exist then throw an exceptions if (!filename.exists()) { std::string msg = "The \"inobs\" parameter \""+filename.url()+ @@ -462,18 +459,19 @@ void ctool::setup_models(GObservations& obs, // observation container if (obs.models().size() == 0) { - // Get models XML filename - GFilename filename = (*this)["inmodel"].filename(); - // Throw an exception if the "inmodel" parameter is not a valid // filename - if (!is_valid_filename(filename)) { - std::string msg = "The \"inmodel\" parameter \""+filename.url()+ + if ((*this)["inmodel"].is_undefined()) { + std::string msg = "The \"inmodel\" parameter \""+ + (*this)["inmodel"].current_value()+ "\" is not a valid filename. Please specify " "a valid model definition XML file."; throw GException::invalid_value(G_SETUP_MODELS, msg); } + // Get models XML filename + GFilename filename = (*this)["inmodel"].filename(); + // Load model container and assign it to observations container obs.models(GModels(filename.url())); @@ -816,19 +814,20 @@ GCTAObservation ctool::create_cta_obs(void) ***************************************************************************/ void ctool::require_inobs(const std::string& method) { - // Get inobs filename - GFilename filename = (*this)["inobs"].filename(); - // Throw exception if no infile is given - if (!is_valid_filename(filename)) { + if ((*this)["inobs"].is_undefined()) { std::string msg = "A valid file needs to be specified for the " - "\"inobs\" parameter, yet \""+filename.url()+ + "\"inobs\" parameter, yet \""+ + (*this)["inobs"].current_value()+ "\" was given." " Specify a valid observation definition or " "FITS file to proceed."; throw GException::invalid_value(method, msg); } + // Get inobs filename + GFilename filename = (*this)["inobs"].filename(); + // Return return; } @@ -845,43 +844,48 @@ void ctool::require_inobs(const std::string& method) ***************************************************************************/ void ctool::require_inobs_nocube(const std::string& method) { - // Get inobs filename - GFilename filename = (*this)["inobs"].filename(); + // Continues only if we have a valid filename + if ((*this)["inobs"].is_valid()) { - // Continue only if we have a FITS file - if (filename.is_fits()) { + // Get inobs filename + GFilename filename = (*this)["inobs"].filename(); - // Signal no cube - bool is_cube = false; + // Continue only if we have a FITS file + if (filename.is_fits()) { - // Try loading file as counts cube. If this is successful then - // throw an exception - try { + // Signal no cube + bool is_cube = false; - // Load cube from file - GCTAEventCube cube(filename); + // Try loading file as counts cube. If this is successful then + // throw an exception + try { - // If we're still alive then signal that we have a cube - is_cube = true; + // Load cube from file + GCTAEventCube cube(filename); - } + // If we're still alive then signal that we have a cube + is_cube = true; - // Catch any exceptions - catch (...) { - ; - } + } - // If we have a counts cube then throw an exception - if (is_cube) { - std::string msg = "A counts cube has been specified for the " - "\"inobs\" parameter, yet no counts cube " - "can be specified as input observation." - " Instead, specify an event list or an " - "observation definition file."; - throw GException::invalid_value(method, msg); - } + // Catch any exceptions + catch (...) { + ; + } + + // If we have a counts cube then throw an exception + if (is_cube) { + std::string msg = "A counts cube has been specified for the " + "\"inobs\" parameter, yet no counts cube " + "can be specified as input observation." + " Instead, specify an event list or an " + "observation definition file."; + throw GException::invalid_value(method, msg); + } - } // endif: we had a FITS file + } // endif: we had a FITS file + + } // endif: filename was valid // Return return; @@ -1178,8 +1182,8 @@ std::string ctool::set_outfile_name(const std::string& filename) bool ctool::is_stacked(void) { // First query the minimum and maximum energies - (*this)["emin"].real(); - (*this)["emax"].real(); + (*this)["emin"].query(); + (*this)["emax"].query(); // Now query the number of energy bins and set the stacked flag bool stacked = ((*this)["enumbins"].integer() > 0) ? true : false; @@ -1187,13 +1191,13 @@ bool ctool::is_stacked(void) // If a stacked analysis is requested then query the spatial definition // of the cube if (stacked) { - (*this)["coordsys"].string(); - (*this)["proj"].string(); - (*this)["xref"].real(); - (*this)["yref"].real(); - (*this)["nxpix"].integer(); - (*this)["nypix"].integer(); - (*this)["binsz"].real(); + (*this)["coordsys"].query(); + (*this)["proj"].query(); + (*this)["xref"].query(); + (*this)["yref"].query(); + (*this)["nxpix"].query(); + (*this)["nypix"].query(); + (*this)["binsz"].query(); } // Return stacked flag @@ -1224,23 +1228,23 @@ bool ctool::is_onoff(void) if (onoff) { // Query csphagen parameters - (*this)["inexclusion"].filename(); - (*this)["emin"].real(); - (*this)["emax"].real(); - (*this)["enumbins"].integer(); - (*this)["coordsys"].string(); - (*this)["xref"].real(); - (*this)["yref"].real(); + (*this)["inexclusion"].query(); + (*this)["emin"].query(); + (*this)["emax"].query(); + (*this)["enumbins"].query(); + (*this)["coordsys"].query(); + (*this)["xref"].query(); + (*this)["yref"].query(); if ((*this)["srcshape"].string() == "CIRCLE"){ - (*this)["rad"].real(); + (*this)["rad"].query(); } if ((*this)["bkgmethod"].string() == "REFLECTED"){ - (*this)["bkgregmin"].integer(); + (*this)["bkgregmin"].query(); } - (*this)["maxoffset"].real(); - (*this)["etruemin"].real(); - (*this)["etruemax"].real(); - (*this)["etruebins"].integer(); + (*this)["maxoffset"].query(); + (*this)["etruemin"].query(); + (*this)["etruemax"].query(); + (*this)["etruebins"].query(); } // endif: method was ONOFF @@ -1419,38 +1423,28 @@ void ctool::set_obs_response(GCTAObservation* obs) query_edisp = (*this)["edisp"].boolean(); } - // Get filenames - GFilename expcube((*this)["expcube"].filename()); - GFilename psfcube((*this)["psfcube"].filename()); - GFilename edispcube; - if (query_edisp) { - edispcube = (*this)["edispcube"].filename(); - } - GFilename bkgcube((*this)["bkgcube"].filename()); - // Extract stacked response information if available - if (is_valid_filename(expcube) && is_valid_filename(psfcube) && - is_valid_filename(bkgcube)) { - - // Load exposure, PSF and background cubes - GCTACubeExposure exposure(expcube); - GCTACubePsf psf(psfcube); - GCTACubeBackground background(bkgcube); + if ((*this)["expcube"].is_valid() && + (*this)["psfcube"].is_valid() && + (*this)["bkgcube"].is_valid()) { + + // Load exposure, PSF and background cubes and query energy + // dispersion cube + GCTACubeExposure exposure((*this)["expcube"].filename()); + GCTACubePsf psf((*this)["psfcube"].filename()); + if (query_edisp && (*this)["edispcube"].is_valid()) { + (*this)["edispcube"].filename(); + } + GCTACubeBackground background((*this)["bkgcube"].filename()); - // If querying of energy dispersion cube is requested then - // query it now + // Set response if (query_edisp) { - // If filename is valid then use energy dispersion ... - if (is_valid_filename(edispcube)) { - - // Load energy dispersion cube - GCTACubeEdisp edisp(edispcube); - - // Set response with all four cubes + // If energy dispersion cube was provided then use it + if ((*this)["edispcube"].is_valid()) { + GCTACubeEdisp edisp((*this)["edispcube"].filename()); obs->response(exposure, psf, edisp, background); - - } // endif: energy dispersion cube was provided + } // ... otherwise work without energy dispersion else { @@ -1606,12 +1600,9 @@ GObservations ctool::get_observations(const bool& get_response) // Initialise empty observation container GObservations obs; - // Get the filename from the input parameters - std::string filename = (*this)["inobs"].filename(); - // If no observation definition file has been specified then read all // parameters that are necessary to create an observation from scratch - if (!is_valid_filename(filename)) { + if ((*this)["inobs"].is_undefined()) { // Setup a new CTA observation GCTAObservation cta_obs = create_cta_obs(); @@ -1632,6 +1623,9 @@ GObservations ctool::get_observations(const bool& get_response) // ... otherwise we have a file name else { + // Get the filename from the input parameters + std::string filename = (*this)["inobs"].filename(); + // If file is a FITS file then create an empty CTA observation // and load file into observation if (GFilename(filename).is_fits()) { diff --git a/src/support/ctool.hpp b/src/support/ctool.hpp index 054ae6a..64dc971 100755 --- a/src/support/ctool.hpp +++ b/src/support/ctool.hpp @@ -134,7 +134,6 @@ protected: const GCTAObservation& obs); std::vector cube_layer_usage(const GEbounds& cube_ebounds, const GEbounds& list_ebounds) const; - bool is_valid_filename(const GFilename& filename) const; std::string get_gtiname(const std::string& filename, const std::string& evtname) const; void save_event_list(const GCTAObservation* obs, @@ -175,19 +174,4 @@ const bool& ctool::read_ahead(void) const return (m_read_ahead); } - -/***********************************************************************//** - * @brief Check of a filename is valid - * - * @return True if filename is valid - * - * Checks whether a filename is not empty and not "NONE". - ***************************************************************************/ -inline -bool ctool::is_valid_filename(const GFilename& filename) const -{ - return (!filename.is_empty() && - (gammalib::tolower(filename.url()) != "none")); -} - #endif /* CTOOL_HPP */ diff --git a/test/test_cscript.py b/test/test_cscript.py index 3b32b78..1daefb7 100755 --- a/test/test_cscript.py +++ b/test/test_cscript.py @@ -2,7 +2,7 @@ # ========================================================================== # This scripts performs unit tests for the cspull script. # -# Copyright (C) 2016-2017 Juergen Knoedlseder +# Copyright (C) 2016-2018 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 @@ -115,10 +115,6 @@ class cscript_test(ctools.cscript): def check_get_current_rss(self): return self._get_current_rss() - # Check is_valid_filename() method - def check_is_valid_filename(self, filename): - return self._is_valid_filename(gammalib.GFilename(filename)) - # Check save_event_list() method def check_save_event_list(self, infile, evtname, gtiname, outfile): obs = gammalib.GCTAObservation() @@ -524,14 +520,6 @@ class Test(test): # Test cube_layer_usage() method # TODO: implement - # Test is_valid_filename() method - self.test_assert(empty.check_is_valid_filename(self._model), - 'Check model definiton XML file') - self.test_assert(not empty.check_is_valid_filename(''), - 'Check empty filename') - self.test_assert(not empty.check_is_valid_filename('NONE'), - 'Check "NONE" filename') - # Test get_gtiname() method # TODO: implement -- libgit2 0.21.4