Commit b095127733a92aac769fd3498da14aa15062270f

Authored by Jürgen Knödlseder
1 parent 261e0fb4

Remove ctools::is_valid_filename() method.

ChangeLog
1   -2018-04-10
  1 +2018-06-07
2 2  
3 3 * Version 1.6.0 released
4 4 ========================
5 5  
  6 + Remove ctools::is_valid_filename() method.
6 7 Fix bug when using precomputed model in csresspec (#2448)
7 8 Keep existing library path in installation script on Mac OS X (#2420)
8 9 Add show_rmf.py example script
... ...
1 1 New Features and Important Changes in ctools 1.6.0
2 2  
3   -5 June 2018
  3 +7 June 2018
4 4  
5 5  
6 6 Introduction
... ... @@ -26,7 +26,8 @@ None
26 26  
27 27 Base classes
28 28 ------------
29   -None
  29 +The ctools::is_valid_filename() method was removed since the validity check
  30 +of the filename is now done by the GApplicationPar class.
30 31  
31 32  
32 33 ctbin - CTA event binning
... ...
pyext/ctool.i
... ... @@ -115,7 +115,6 @@ public:
115 115 %rename(_get_obs_header) get_obs_header;
116 116 %rename(_insert_energy_boundaries) insert_energy_boundaries;
117 117 %rename(_cube_layer_usage) cube_layer_usage;
118   - %rename(_is_valid_filename) is_valid_filename;
119 118 %rename(_get_gtiname) get_gtiname;
120 119 %rename(_save_event_list) save_event_list;
121 120 %rename(_warn_too_few_energies) warn_too_few_energies;
... ... @@ -167,7 +166,6 @@ public:
167 166 const GCTAObservation& obs);
168 167 std::vector<bool> cube_layer_usage(const GEbounds& cube_ebounds,
169 168 const GEbounds& list_ebounds) const;
170   - bool is_valid_filename(const GFilename& filename) const;
171 169 std::string get_gtiname(const std::string& filename,
172 170 const std::string& evtname) const;
173 171 void save_event_list(const GCTAObservation* obs,
... ...
src/ctbin/ctbin.cpp
... ... @@ -301,12 +301,12 @@ void ctbin::save(void)
301 301 // Write header
302 302 log_header1(TERSE, "Save counts cube");
303 303  
304   - // Get counts cube filename
305   - m_outcube = (*this)["outcube"].filename();
306   -
307   - // Save only if filename is not empty and if there is at least one
  304 + // Save only if filename is valid and if there is at least one
308 305 // observation
309   - if (!m_outcube.is_empty() && m_obs.size() > 0) {
  306 + if ((*this)["outcube"].is_valid() && m_obs.size() > 0) {
  307 +
  308 + // Get counts cube filename
  309 + m_outcube = (*this)["outcube"].filename();
310 310  
311 311 // Get CTA observation from observation container
312 312 GCTAObservation* obs = dynamic_cast<GCTAObservation*>(m_obs[0]);
... ... @@ -464,10 +464,9 @@ void ctbin::get_parameters(void)
464 464 m_publish = (*this)["publish"].boolean();
465 465 m_chatter = static_cast<GChatter>((*this)["chatter"].integer());
466 466  
467   - // Optionally read ahead parameters so that they get correctly
468   - // dumped into the log file
  467 + // If needed later, query output filename now
469 468 if (read_ahead()) {
470   - m_outcube = (*this)["outcube"].filename();
  469 + (*this)["outcube"].query();
471 470 }
472 471  
473 472 // Cache sky directions in m_counts
... ...
src/ctbkgcube/ctbkgcube.cpp
1 1 /***************************************************************************
2 2 * ctbkgcube - Background cube generation tool *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2014-2017 by Chia-Chun Lu *
  4 + * copyright (C) 2014-2018 by Chia-Chun Lu *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -351,21 +351,30 @@ void ctbkgcube::save(void)
351 351 // Write header
352 352 log_header1(TERSE, "Save background cube");
353 353  
354   - // Get background cube and model file names
355   - m_outcube = (*this)["outcube"].filename();
356   - m_outmodel = (*this)["outmodel"].filename();
357   -
358 354 // Determine whether a model definition file should be written
359   - bool write_moddef = is_valid_filename(m_outmodel);
  355 + bool write_moddef = (*this)["outmodel"].is_valid();
  356 +
  357 + // Save background cube if filename is valid and the background cube is
  358 + // not empty
  359 + if ((*this)["outcube"].is_valid() && !m_background.cube().is_empty()) {
  360 +
  361 + // Get background cube file name
  362 + m_outcube = (*this)["outcube"].filename();
360 363  
361   - // Save background cube if filename and the background cube are not empty
362   - if (!m_outcube.is_empty() && !m_background.cube().is_empty()) {
  364 + // Save background cube
363 365 m_background.save(m_outcube, clobber());
  366 +
364 367 }
365 368  
366 369 // Save model definition file if requested
367 370 if (write_moddef) {
  371 +
  372 + // Get model file name
  373 + m_outmodel = (*this)["outmodel"].filename();
  374 +
  375 + // Save model
368 376 m_outmdl.save(m_outmodel.url());
  377 +
369 378 }
370 379  
371 380 // Write into logger what has been done
... ... @@ -483,14 +492,12 @@ void ctbkgcube::get_parameters(void)
483 492 // event lists, but do not accept counts cubes.
484 493 setup_observations(m_obs, true, true, false);
485 494  
486   - // Get the incube filename
487   - std::string incube = (*this)["incube"].filename();
488   -
489 495 // If the "incube" file name is valid then setup the background cube from
490 496 // the counts cube. Otherwise create a counts cube from the user
491 497 // parameters
492   - GCTAEventCube cube = is_valid_filename(incube) ? GCTAEventCube(incube)
493   - : create_cube(m_obs);
  498 + GCTAEventCube cube = (*this)["incube"].is_valid()
  499 + ? GCTAEventCube((*this)["incube"].filename())
  500 + : create_cube(m_obs);
494 501  
495 502 // Define background cube
496 503 m_background = GCTACubeBackground(cube);
... ... @@ -503,10 +510,10 @@ void ctbkgcube::get_parameters(void)
503 510 m_publish = (*this)["publish"].boolean();
504 511 m_chatter = static_cast<GChatter>((*this)["chatter"].integer());
505 512  
506   - // Read output filenames (if needed)
  513 + // If needed later, query output filenames now
507 514 if (read_ahead()) {
508   - m_outcube = (*this)["outcube"].filename();
509   - m_outmodel = (*this)["outmodel"].filename();
  515 + (*this)["outcube"].query();
  516 + (*this)["outmodel"].query();
510 517 }
511 518  
512 519 // Write parameters into logger
... ...
src/ctbutterfly/ctbutterfly.cpp
... ... @@ -340,11 +340,11 @@ void ctbutterfly::save(void)
340 340 // Write header into logger
341 341 log_header1(TERSE, "Save Butterfly diagram");
342 342  
343   - // Get output filename
344   - m_outfile = (*this)["outfile"].filename();
  343 + // Save only if filename is valid
  344 + if ((*this)["outfile"].is_valid()) {
345 345  
346   - // Save only if filename is non-empty
347   - if (!m_outfile.is_empty()) {
  346 + // Get output filename
  347 + m_outfile = (*this)["outfile"].filename();
348 348  
349 349 // Log butterfly diagram file name
350 350 log_value(NORMAL, "Butterfly file", m_outfile.url());
... ... @@ -465,8 +465,7 @@ void ctbutterfly::get_parameters(void)
465 465 m_ebounds = create_ebounds();
466 466  
467 467 // Get matrix file name and load if possible
468   - std::string matrixfilename = (*this)["matrix"].filename();
469   - if (matrixfilename != "NONE") {
  468 + if ((*this)["matrix"].is_valid()) {
470 469 std::string msg = "Loading of matrix from file not implemented yet. "
471 470 "Use filename = \"NONE\" to induce a recomputation "
472 471 "of the matrix internally.";
... ... @@ -484,10 +483,9 @@ void ctbutterfly::get_parameters(void)
484 483 // Check model name and type
485 484 check_model();
486 485  
487   - // Optionally read ahead parameters so that they get correctly
488   - // dumped into the log file
  486 + // If needed later, query output filename now
489 487 if (read_ahead()) {
490   - m_outfile = (*this)["outfile"].filename();
  488 + (*this)["outfile"].query();
491 489 }
492 490  
493 491 // Write parameters into logger
... ...
src/ctcubemask/ctcubemask.cpp
1 1 /***************************************************************************
2 2 * ctcubemask - Cube filter tool *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2014-2016 by Chia-Chun Lu *
  4 + * copyright (C) 2014-2018 by Chia-Chun Lu *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -372,7 +372,6 @@ void ctcubemask::publish(const std::string&amp; name)
372 372 void ctcubemask::init_members(void)
373 373 {
374 374 // Initialise parameters
375   - m_regfile.clear();
376 375 m_outcube.clear();
377 376 m_prefix.clear();
378 377 m_emin = 0.0;
... ... @@ -396,7 +395,6 @@ void ctcubemask::init_members(void)
396 395 void ctcubemask::copy_members(const ctcubemask& app)
397 396 {
398 397 // Copy parameters
399   - m_regfile = app.m_regfile;
400 398 m_outcube = app.m_outcube;
401 399 m_prefix = app.m_prefix;
402 400 m_emin = app.m_emin;
... ... @@ -441,8 +439,8 @@ void ctcubemask::get_parameters(void)
441 439 // information and do not accept event lists.
442 440 setup_observations(m_obs, false, false, true);
443 441  
444   - // Get parameters
445   - m_regfile = (*this)["regfile"].filename();
  442 + // Query "regfile" parameter
  443 + (*this)["regfile"].query();
446 444  
447 445 // Query the RoI
448 446 GCTARoi roi = get_roi();
... ... @@ -460,11 +458,10 @@ void ctcubemask::get_parameters(void)
460 458 // Get remaining parameters
461 459 m_publish = (*this)["publish"].boolean();
462 460  
463   - // Optionally read ahead parameters so that they get correctly
464   - // dumped into the log file
  461 + // If needed later, query output filename and prefix now
465 462 if (read_ahead()) {
466   - m_outcube = (*this)["outcube"].filename();
467   - m_prefix = (*this)["prefix"].string();
  463 + (*this)["outcube"].query();
  464 + (*this)["prefix"].query();
468 465 }
469 466  
470 467 // Write parameters into logger
... ... @@ -576,8 +573,8 @@ void ctcubemask::apply_mask(GCTAObservation* obs)
576 573  
577 574 // Set all pixels inside selected energy bands and inside exclusion
578 575 // regions to -1.0
579   - if (m_regfile != "NONE") {
580   - GSkyRegions regions = GSkyRegions(m_regfile);
  576 + if ((*this)["regfile"].is_valid()) {
  577 + GSkyRegions regions = GSkyRegions((*this)["regfile"].filename());
581 578 for (int i = e_idx1; i <= e_idx2; ++i) {
582 579 for (int pixel = 0; pixel < npix; ++pixel) {
583 580 GSkyDir dir = map.inx2dir(pixel);
... ... @@ -679,8 +676,8 @@ std::string ctcubemask::set_outfile_name(const std::string&amp; filename) const
679 676 ***************************************************************************/
680 677 void ctcubemask::save_fits(void)
681 678 {
682   - // Save only if filename is non-empty and if there are observations
683   - if (!m_outcube.is_empty() && m_obs.size() > 0) {
  679 + // Save only if there are observations
  680 + if (m_obs.size() > 0) {
684 681  
685 682 // Get CTA observation from observation container
686 683 GCTAObservation* obs = dynamic_cast<GCTAObservation*>(m_obs[0]);
... ...
src/ctcubemask/ctcubemask.hpp
... ... @@ -76,7 +76,6 @@ protected:
76 76 void save_xml(void);
77 77  
78 78 // User parameters
79   - GFilename m_regfile; //!< ds9 region file
80 79 GFilename m_outcube; //!< Output event list or XML file
81 80 std::string m_prefix; //!< Prefix for multiple counts maps
82 81 double m_emin; //!< Lower energy
... ...
src/ctedispcube/ctedispcube.cpp
1 1 /***************************************************************************
2 2 * ctedispcube - Energy dispersion cube generation tool *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2016 by Maria Haupt *
  4 + * copyright (C) 2016-2018 by Maria Haupt *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -260,13 +260,16 @@ void ctedispcube::save(void)
260 260 // Write header into logger
261 261 log_header1(TERSE, "Save energy dispersion cube");
262 262  
263   - // Get output filename
264   - m_outcube = (*this)["outcube"].filename();
265   -
266 263 // Save energy dispersion cube if filename and the energy dispersion cube
267 264 // are not empty
268   - if (!m_outcube.is_empty() && !m_edispcube.cube().is_empty()) {
  265 + if ((*this)["outcube"].is_valid() && !m_edispcube.cube().is_empty()) {
  266 +
  267 + // Get output filename
  268 + m_outcube = (*this)["outcube"].filename();
  269 +
  270 + // Save energy dispersion cube
269 271 m_edispcube.save(m_outcube, clobber());
  272 +
270 273 }
271 274  
272 275 // Write into logger what has been done
... ... @@ -346,9 +349,6 @@ void ctedispcube::get_parameters(void)
346 349 // Setup observations from "inobs" parameter. Do not accept counts cubes.
347 350 setup_observations(m_obs, true, true, false);
348 351  
349   - // Get the incube filename
350   - std::string incube = (*this)["incube"].filename();
351   -
352 352 // Get additional binning parameters
353 353 double migramax = (*this)["migramax"].real();
354 354 int migrabins = (*this)["migrabins"].integer();
... ... @@ -356,8 +356,9 @@ void ctedispcube::get_parameters(void)
356 356 // If the "incube" file name is valid then setup the energy dispersion
357 357 // cube from the counts cube. Otherwise create a counts cube from the
358 358 // user parameters
359   - GCTAEventCube cube = is_valid_filename(incube) ? GCTAEventCube(incube)
360   - : create_cube(m_obs);
  359 + GCTAEventCube cube = (*this)["incube"].is_valid()
  360 + ? GCTAEventCube((*this)["incube"].filename())
  361 + : create_cube(m_obs);
361 362  
362 363 // Define edisp cube
363 364 m_edispcube = GCTACubeEdisp(cube, migramax, migrabins);
... ... @@ -366,9 +367,9 @@ void ctedispcube::get_parameters(void)
366 367 m_addbounds = (*this)["addbounds"].boolean();
367 368 m_chatter = static_cast<GChatter>((*this)["chatter"].integer());
368 369  
369   - // Read output filename (if needed)
  370 + // If needed later, query output filename now
370 371 if (read_ahead()) {
371   - m_outcube = (*this)["outcube"].filename();
  372 + (*this)["outcube"].query();
372 373 }
373 374  
374 375 // Write parameters into logger
... ...
src/cterror/cterror.cpp
1 1 /***************************************************************************
2 2 * cterror - Parameter error calculation tool *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2015-2017 by Florent Forest *
  4 + * copyright (C) 2015-2018 by Florent Forest *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -344,11 +344,11 @@ void cterror::save(void)
344 344 // Write header
345 345 log_header1(TERSE, "Save results");
346 346  
347   - // Get output filename
348   - m_outmodel = (*this)["outmodel"].filename();
349   -
350 347 // Save only if filename is valid
351   - if (is_valid_filename(m_outmodel)) {
  348 + if ((*this)["outmodel"].is_valid()) {
  349 +
  350 + // Get output filename
  351 + m_outmodel = (*this)["outmodel"].filename();
352 352  
353 353 // Log filename
354 354 log_value(NORMAL, "Model definition file", m_outmodel.url());
... ... @@ -472,10 +472,9 @@ void cterror::get_parameters(void)
472 472 m_max_iter = (*this)["max_iter"].integer();
473 473 m_chatter = static_cast<GChatter>((*this)["chatter"].integer());
474 474  
475   - // Read ahead parameters that are only needed when the tool gets
476   - // executed
  475 + // If needed later, query output filename now
477 476 if (read_ahead()) {
478   - m_outmodel = (*this)["outmodel"].filename();
  477 + (*this)["outmodel"].query();
479 478 }
480 479  
481 480 // Write parameters into logger
... ...
src/ctexpcube/ctexpcube.cpp
1 1 /***************************************************************************
2 2 * ctexpcube - Exposure cube generation tool *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2014-2016 by Juergen Knoedlseder *
  4 + * copyright (C) 2014-2018 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -256,12 +256,16 @@ void ctexpcube::save(void)
256 256 // Write header into logger
257 257 log_header1(TERSE, "Save exposure cube");
258 258  
259   - // Get exposure cube filename
260   - m_outcube = (*this)["outcube"].filename();
  259 + // Save exposure cube if filename is valid and the exposure cube is not
  260 + // empty
  261 + if ((*this)["outcube"].is_valid() && !m_expcube.cube().is_empty()) {
261 262  
262   - // Save exposure cube if filename and the exposure cube are not empty
263   - if (!m_outcube.is_empty() && !m_expcube.cube().is_empty()) {
  263 + // Get exposure cube filename
  264 + m_outcube = (*this)["outcube"].filename();
  265 +
  266 + // Save exposure cube
264 267 m_expcube.save(m_outcube, clobber());
  268 +
265 269 }
266 270  
267 271 // Write into logger what has been done
... ... @@ -370,14 +374,12 @@ void ctexpcube::get_parameters(void)
370 374 // Setup observations from "inobs" parameter. Do not accept counts cubes.
371 375 setup_observations(m_obs, true, true, false);
372 376  
373   - // Get the incube filename
374   - std::string incube = (*this)["incube"].filename();
375   -
376 377 // If the "incube" file name is valid then setup the exposure cube from
377 378 // the counts cube. Otherwise create a counts cube from the user
378 379 // parameters
379   - GCTAEventCube cube = is_valid_filename(incube) ? GCTAEventCube(incube)
380   - : create_cube(m_obs);
  380 + GCTAEventCube cube = (*this)["incube"].is_valid()
  381 + ? GCTAEventCube((*this)["incube"].filename())
  382 + : create_cube(m_obs);
381 383  
382 384 // Define exposure cube
383 385 m_expcube = GCTACubeExposure(cube);
... ... @@ -387,9 +389,9 @@ void ctexpcube::get_parameters(void)
387 389 m_publish = (*this)["publish"].boolean();
388 390 m_chatter = static_cast<GChatter>((*this)["chatter"].integer());
389 391  
390   - // Read output filename (if needed)
  392 + // If needed later, query output filename now
391 393 if (read_ahead()) {
392   - m_outcube = (*this)["outcube"].filename();
  394 + (*this)["outcube"].query();
393 395 }
394 396  
395 397 // Write parameters into logger
... ...
src/ctlike/ctlike.cpp
1 1 /***************************************************************************
2 2 * ctlike - Maximum likelihood fitting tool *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2010-2017 by Juergen Knoedlseder *
  4 + * copyright (C) 2010-2018 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -334,12 +334,11 @@ void ctlike::save(void)
334 334 // Write header
335 335 log_header1(TERSE, "Save results");
336 336  
337   - // Get output filenames
338   - m_outmodel = (*this)["outmodel"].filename();
339   - m_outcovmat = (*this)["outcovmat"].filename();
  337 + // Save model only if filename is valid
  338 + if ((*this)["outmodel"].is_valid()) {
340 339  
341   - // Save only if filename is valid
342   - if (is_valid_filename(m_outmodel)) {
  340 + // Get output filename
  341 + m_outmodel = (*this)["outmodel"].filename();
343 342  
344 343 // Log filename
345 344 log_value(NORMAL, "Model definition file", m_outmodel.url());
... ... @@ -354,8 +353,11 @@ void ctlike::save(void)
354 353 log_value(NORMAL, "Model definition file", "NONE");
355 354 }
356 355  
357   - // Save covariance matrix if filename is valid
358   - if (is_valid_filename(m_outcovmat)) {
  356 + // Save covariance matrix only if filename is valid
  357 + if ((*this)["outcovmat"].is_valid()) {
  358 +
  359 + // Get output filenames
  360 + m_outcovmat = (*this)["outcovmat"].filename();
359 361  
360 362 // Log filename
361 363 log_value(NORMAL, "Covariance matrix file", m_outcovmat.url());
... ... @@ -406,11 +408,10 @@ void ctlike::get_parameters(void)
406 408 m_fix_spat_for_ts = (*this)["fix_spat_for_ts"].boolean();
407 409 m_chatter = static_cast<GChatter>((*this)["chatter"].integer());
408 410  
409   - // Optionally read ahead parameters so that they get correctly
410   - // dumped into the log file
  411 + // If needed later, query output filenames now
411 412 if (read_ahead()) {
412   - m_outmodel = (*this)["outmodel"].filename();
413   - m_outcovmat = (*this)["outcovmat"].filename();
  413 + (*this)["outmodel"].query();
  414 + (*this)["outcovmat"].query();
414 415 }
415 416  
416 417 // Set optimizer logger
... ...
src/ctmapcube/ctmapcube.cpp
1 1 /***************************************************************************
2 2 * ctmapcube - Map cube generation tool *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2016-2017 by Juergen Knoedlseder *
  4 + * copyright (C) 2016-2018 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -222,12 +222,15 @@ void ctmapcube::save(void)
222 222 // Write header
223 223 log_header1(TERSE, "Save map cube");
224 224  
225   - // Get map cube filename
226   - m_outcube = (*this)["outcube"].filename();
  225 + // Save map cube if filename is valid and the map cube is not empty
  226 + if ((*this)["outcube"].is_valid() && !m_cube.cube().is_empty()) {
227 227  
228   - // Save map cube if filename and the map cube are not empty
229   - if (!m_outcube.is_empty() && !m_cube.cube().is_empty()) {
  228 + // Get map cube filename
  229 + m_outcube = (*this)["outcube"].filename();
  230 +
  231 + // Save map cube
230 232 m_cube.save(m_outcube, clobber());
  233 +
231 234 }
232 235  
233 236 // Write into logger what has been done
... ... @@ -365,9 +368,9 @@ void ctmapcube::get_parameters(void)
365 368 m_publish = (*this)["publish"].boolean();
366 369 m_chatter = static_cast<GChatter>((*this)["chatter"].integer());
367 370  
368   - // Read optionally output cube filenames
  371 + // If needed later, query output filename now
369 372 if (read_ahead()) {
370   - m_outcube = (*this)["outcube"].filename();
  373 + (*this)["outcube"].query();
371 374 }
372 375  
373 376 // Allocate map cube
... ...
src/ctmodel/ctmodel.cpp
... ... @@ -313,11 +313,13 @@ void ctmodel::save(void)
313 313 // Write header
314 314 log_header1(TERSE, "Save model cube");
315 315  
316   - // Get model cube filename
317   - m_outcube = (*this)["outcube"].filename();
  316 + // Save only if filename is valid and cube has some size
  317 + if ((*this)["outcube"].is_valid() && m_cube.size() > 0) {
318 318  
319   - // Save only if filename is non-empty and cube has some size
320   - if (!m_outcube.is_empty() && m_cube.size() > 0) {
  319 + // Get model cube filename
  320 + m_outcube = (*this)["outcube"].filename();
  321 +
  322 + // Save cube
321 323 m_cube.save(m_outcube, clobber());
322 324 }
323 325  
... ... @@ -533,13 +535,13 @@ void ctmodel::get_parameters(void)
533 535 // should create it from scratch using the task parameters
534 536 if (!m_has_cube) {
535 537  
536   - // Read cube definition file
537   - std::string incube = (*this)["incube"].filename();
538   -
539 538 // If the cube filename is valid the load the cube and set all cube
540 539 // bins to zero
541 540 if ((*this)["incube"].is_valid()) {
542 541  
  542 + // Get cube definition filename
  543 + std::string incube = (*this)["incube"].filename();
  544 +
543 545 // Load cube from given file
544 546 m_cube.load(incube);
545 547  
... ... @@ -564,9 +566,9 @@ void ctmodel::get_parameters(void)
564 566 m_publish = (*this)["publish"].boolean();
565 567 m_chatter = static_cast<GChatter>((*this)["chatter"].integer());
566 568  
567   - // Read optionally output cube filenames
  569 + // If needed later, query output filename now
568 570 if (read_ahead()) {
569   - m_outcube = (*this)["outcube"].filename();
  571 + (*this)["outcube"].query();
570 572 }
571 573  
572 574 // If cube should be appended to first observation then do that now.
... ... @@ -621,29 +623,26 @@ void ctmodel::get_parameters(void)
621 623 ***************************************************************************/
622 624 void ctmodel::get_obs(void)
623 625 {
624   - // Get the filename from the input parameters
625   - std::string filename = (*this)["inobs"].filename();
626   -
627 626 // If no observation definition file has been specified then read all
628 627 // parameters that are necessary to create an observation from scratch
629 628 if ((*this)["inobs"].is_undefined()) {
630 629  
631   - // Get response cube filenames
632   - GFilename edispcube;
633   - bool query_edisp = (*this)["edisp"].boolean();
634   - std::string expcube = (*this)["expcube"].filename();
635   - std::string psfcube = (*this)["psfcube"].filename();
636   - if (query_edisp) {
637   - edispcube = (*this)["edispcube"].filename();
638   - }
639   - std::string bkgcube = (*this)["bkgcube"].filename();
640   -
641 630 // If the filenames are valid then build an observation from cube
642 631 // response information
643 632 if ((*this)["expcube"].is_valid() &&
644 633 (*this)["psfcube"].is_valid() &&
645 634 (*this)["bkgcube"].is_valid()) {
646 635  
  636 + // Get response cube filenames
  637 + GFilename edispcube;
  638 + bool query_edisp = (*this)["edisp"].boolean();
  639 + GFilename expcube = (*this)["expcube"].filename();
  640 + GFilename psfcube = (*this)["psfcube"].filename();
  641 + if (query_edisp && (*this)["edispcube"].is_valid()) {
  642 + edispcube = (*this)["edispcube"].filename();
  643 + }
  644 + GFilename bkgcube = (*this)["bkgcube"].filename();
  645 +
647 646 // Get exposure, PSF and background cubes
648 647 GCTACubeExposure exposure(expcube);
649 648 GCTACubePsf psf(psfcube);
... ... @@ -721,6 +720,9 @@ void ctmodel::get_obs(void)
721 720 // ... otherwise we have a file name
722 721 else {
723 722  
  723 + // Get the filename from the input parameters
  724 + std::string filename = (*this)["inobs"].filename();
  725 +
724 726 // If file is a FITS file then create an empty CTA observation
725 727 // and load file into observation
726 728 if (GFilename(filename).is_fits()) {
... ...
src/ctobssim/ctobssim.cpp
... ... @@ -643,11 +643,10 @@ void ctobssim::get_parameters(void)
643 643 m_max_rate = (*this)["maxrate"].real();
644 644 m_startindex = (*this)["startindex"].integer();
645 645  
646   - // Optionally read ahead parameters so that they get correctly
647   - // dumped into the log file
  646 + // If needed later, query output filename and prefix now
648 647 if (read_ahead()) {
649   - m_outevents = (*this)["outevents"].filename();
650   - m_prefix = (*this)["prefix"].string();
  648 + (*this)["outevents"].query();
  649 + (*this)["prefix"].query();
651 650 }
652 651  
653 652 // Initialise random number generators. We initialise here one random
... ...
src/ctphase/ctphase.cpp
1 1 /***************************************************************************
2 2 * ctphase - Append phase information to CTA events file *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2017 by Joshua Cardenzana *
  4 + * copyright (C) 2017-2018 by Joshua Cardenzana *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -409,9 +409,8 @@ void ctphase::get_parameters(void)
409 409 // from a model definiton XML file specified by the "inmodel" parameter.
410 410 // The model is only loaded of the file is valid.
411 411 if (m_obs.models().size() == 0) {
412   - GFilename inmodel = (*this)["inmodel"].filename();
413   - if (is_valid_filename(inmodel)) {
414   - m_obs.models(inmodel);
  412 + if ((*this)["inmodel"].is_valid()) {
  413 + m_obs.models((*this)["inmodel"].filename());
415 414 }
416 415 }
417 416  
... ... @@ -481,11 +480,10 @@ void ctphase::get_parameters(void)
481 480  
482 481 } // endelse: read phase curve information from User parameters
483 482  
484   - // Optionally read ahead parameters so that they get correctly
485   - // dumped into the log file
  483 + // If needed later, query output filename and prefix now
486 484 if (read_ahead()) {
487   - (*this)["outobs"].filename();
488   - (*this)["prefix"].string();
  485 + (*this)["outobs"].query();
  486 + (*this)["prefix"].query();
489 487 }
490 488  
491 489 // Write parameters into logger
... ...
src/ctprob/ctprob.cpp
1 1 /***************************************************************************
2 2 * ctprob - Computes event probability for a given model *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2017 by Leonardo Di Venere *
  4 + * copyright (C) 2017-2018 by Leonardo Di Venere *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -433,11 +433,10 @@ void ctprob::get_parameters(void)
433 433 m_publish = (*this)["publish"].boolean();
434 434 m_chatter = static_cast<GChatter>((*this)["chatter"].integer());
435 435  
436   - // Optionally read ahead parameters so that they get correctly
437   - // dumped into the log file
  436 + // If needed later, query output filename and prefix now
438 437 if (read_ahead()) {
439   - (*this)["outobs"].filename();
440   - (*this)["prefix"].string();
  438 + (*this)["outobs"].query();
  439 + (*this)["prefix"].query();
441 440 }
442 441  
443 442 // Write parameters into logger
... ...
src/ctpsfcube/ctpsfcube.cpp
1 1 /***************************************************************************
2 2 * ctpsfcube - PSF cube generation tool *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2014-2017 by Chia-Chun Lu *
  4 + * copyright (C) 2014-2018 by Chia-Chun Lu *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -248,12 +248,15 @@ void ctpsfcube::save(void)
248 248 // Write header into logger
249 249 log_header1(TERSE, "Save PSF cube");
250 250  
251   - // Get output filename
252   - m_outcube = (*this)["outcube"].filename();
  251 + // Save PSF cube if filename is valid and the PSF cube is not empty
  252 + if ((*this)["outcube"].is_valid() && !m_psfcube.cube().is_empty()) {
253 253  
254   - // Save PSF cube if filename and the PSF cube are not empty
255   - if (!m_outcube.is_empty() && !m_psfcube.cube().is_empty()) {
  254 + // Get output filename
  255 + m_outcube = (*this)["outcube"].filename();
  256 +
  257 + // Save PSF cube
256 258 m_psfcube.save(m_outcube, clobber());
  259 +
257 260 }
258 261  
259 262 // Write into logger what has been done
... ... @@ -333,17 +336,15 @@ void ctpsfcube::get_parameters(void)
333 336 // Setup observations from "inobs" parameter. Do not accept counts cubes.
334 337 setup_observations(m_obs, true, true, false);
335 338  
336   - // Get the incube filename
337   - std::string incube = (*this)["incube"].filename();
338   -
339 339 // Get additional binning parameters
340 340 double amax = (*this)["amax"].real();
341 341 int anumbins = (*this)["anumbins"].integer();
342 342  
343 343 // If the "incube" file name is valid then setup the PSF cube from the
344 344 // counts cube. Otherwise create a counts cube from the user parameters
345   - GCTAEventCube cube = is_valid_filename(incube) ? GCTAEventCube(incube)
346   - : create_cube(m_obs);
  345 + GCTAEventCube cube = (*this)["incube"].is_valid()
  346 + ? GCTAEventCube((*this)["incube"].filename())
  347 + : create_cube(m_obs);
347 348  
348 349 // Define PSF cube
349 350 m_psfcube = GCTACubePsf(cube, amax, anumbins);
... ... @@ -352,9 +353,9 @@ void ctpsfcube::get_parameters(void)
352 353 m_addbounds = (*this)["addbounds"].boolean();
353 354 m_chatter = static_cast<GChatter>((*this)["chatter"].integer());
354 355  
355   - // Read output filename (if needed)
  356 + // If needed later, query output filename now
356 357 if (read_ahead()) {
357   - m_outcube = (*this)["outcube"].filename();
  358 + (*this)["outcube"].query();
358 359 }
359 360  
360 361 // Write parameters into logger
... ...
src/ctselect/ctselect.cpp
... ... @@ -647,11 +647,10 @@ void ctselect::get_parameters(void)
647 647 m_usethres = (*this)["usethres"].string();
648 648 m_chatter = static_cast<GChatter>((*this)["chatter"].integer());
649 649  
650   - // Optionally read ahead parameters so that they get correctly
651   - // dumped into the log file
  650 + // If needed later, query output filename and prefix now
652 651 if (read_ahead()) {
653   - m_outobs = (*this)["outobs"].filename();
654   - (*this)["prefix"].string();
  652 + (*this)["outobs"].query();
  653 + (*this)["prefix"].query();
655 654 }
656 655  
657 656 // Set time interval with input times given in CTA reference
... ...
src/ctskymap/ctskymap.cpp
... ... @@ -255,11 +255,11 @@ void ctskymap::save(void)
255 255 // Write header
256 256 log_header1(TERSE, "Save sky map");
257 257  
258   - // Get sky map filename
259   - m_outmap = (*this)["outmap"].filename();
  258 + // Save sky map if filename is valid and sky map is not empty
  259 + if ((*this)["outmap"].is_valid() && !m_skymap.is_empty()) {
260 260  
261   - // Save sky map if filename and the map are not empty
262   - if (!m_outmap.is_empty() && !m_skymap.is_empty()) {
  261 + // Get sky map filename
  262 + m_outmap = (*this)["outmap"].filename();
263 263  
264 264 // Create empty FITS file
265 265 GFits fits;
... ... @@ -453,9 +453,15 @@ void ctskymap::get_parameters(void)
453 453  
454 454 // If an input map was specified then extract try loading the COUNTS
455 455 // and ACCEPTANCE extensions from that file
456   - GFilename inmap = (*this)["inmap"].filename();
457   - if (inmap != "NONE") {
  456 + if ((*this)["inmap"].is_valid()) {
  457 +
  458 + // Read inmap filename
  459 + GFilename inmap = (*this)["inmap"].filename();
  460 +
  461 + // Open file
458 462 GFits fits(inmap);
  463 +
  464 + // Continue only if required extensions exist
459 465 if (fits.contains("COUNTS") && fits.contains("ACCEPTANCE")) {
460 466  
461 467 // Get HDUs
... ... @@ -508,7 +514,7 @@ void ctskymap::get_parameters(void)
508 514 // Get RING background parameters
509 515 if (m_bkgsubtract == "RING") {
510 516  
511   - // Get parameters
  517 + // Get (or query) parameters
512 518 m_roiradius = (*this)["roiradius"].real();
513 519 m_inradius = (*this)["inradius"].real();
514 520 m_outradius = (*this)["outradius"].real();
... ... @@ -516,7 +522,7 @@ void ctskymap::get_parameters(void)
516 522 if (m_iterations > 0) {
517 523 m_threshold = (*this)["threshold"].real();
518 524 }
519   - m_inexclusion = (*this)["inexclusion"].filename();
  525 + (*this)["inexclusion"].query();
520 526 m_usefft = (*this)["usefft"].boolean();
521 527  
522 528 // Make sure that (roiradius < inradius < outradius)
... ... @@ -541,9 +547,9 @@ void ctskymap::get_parameters(void)
541 547 m_publish = (*this)["publish"].boolean();
542 548 m_chatter = static_cast<GChatter>((*this)["chatter"].integer());
543 549  
544   - // Read ahead parameters
  550 + // If needed later, query output filename now
545 551 if (read_ahead()) {
546   - m_outmap = (*this)["outmap"].filename();
  552 + (*this)["outmap"].query();
547 553 }
548 554  
549 555 // Write parameters into logger
... ... @@ -570,7 +576,7 @@ void ctskymap::setup_maps(void)
570 576 if (m_bkgsubtract != "NONE") {
571 577  
572 578 // Setup the exclusions map
573   - setup_exclusion_map(m_inexclusion);
  579 + setup_exclusion_map();
574 580  
575 581 // Cache the pixel solid angles and sky directions
576 582 m_solidangle.reserve(m_counts.npix());
... ... @@ -603,7 +609,7 @@ void ctskymap::setup_maps(void)
603 609 * background estimation. Pixels with values different from 0 will be
604 610 * excluded.
605 611 ***************************************************************************/
606   -void ctskymap::setup_exclusion_map(const GFilename& filename)
  612 +void ctskymap::setup_exclusion_map(void)
607 613 {
608 614 // Create exlusion map
609 615 m_exclmap = m_counts;
... ... @@ -611,15 +617,18 @@ void ctskymap::setup_exclusion_map(const GFilename&amp; filename)
611 617 // Set all pixels to 0 (no pixel excluded)
612 618 m_exclmap = 0.0;
613 619  
614   - // Make sure the exclusions filename is valid
615   - if (is_valid_filename(filename)) {
  620 + // Generate map only if exclusion map filename is valid
  621 + if ((*this)["inexclusion"].is_valid()) {
  622 +
  623 + // Get exclusion map filename
  624 + m_inexclusion = (*this)["inexclusion"].filename();
616 625  
617 626 // Fill the exclusions based on the regions supplied
618   - if (filename.is_fits()) {
619   - setup_exclusion_map_fits(filename);
  627 + if (m_inexclusion.is_fits()) {
  628 + setup_exclusion_map_fits(m_inexclusion);
620 629 }
621 630 else {
622   - setup_exclusion_map_region(filename);
  631 + setup_exclusion_map_region(m_inexclusion);
623 632 }
624 633  
625 634 } // endif: filename was valid
... ...
src/ctskymap/ctskymap.hpp
... ... @@ -69,7 +69,7 @@ protected:
69 69 void free_members(void);
70 70 void get_parameters(void);
71 71 void setup_maps(void);
72   - void setup_exclusion_map(const GFilename& filename);
  72 + void setup_exclusion_map(void);
73 73 void setup_exclusion_map_fits(const GFilename& filename);
74 74 void setup_exclusion_map_region(const GFilename& filename);
75 75 void fill_maps(void);
... ...
src/cttsmap/cttsmap.cpp
1 1 /***************************************************************************
2 2 * cttsmap - TS map calculation tool *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2014-2017 by Michael Mayer *
  4 + * copyright (C) 2014-2018 by Michael Mayer *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -370,12 +370,12 @@ void cttsmap::save(void)
370 370 // Write header
371 371 log_header1(TERSE, "Save TS map");
372 372  
373   - // Get TS map filename
374   - m_outmap = (*this)["outmap"].filename();
375   -
376   - // Save only if filename is non-empty
377   - if (!m_outmap.is_empty() && !m_tsmap.is_empty()) {
  373 + // Save only if filename is valid and TS map is not empty
  374 + if ((*this)["outmap"].is_valid() && !m_tsmap.is_empty()) {
378 375  
  376 + // Get TS map filename
  377 + m_outmap = (*this)["outmap"].filename();
  378 +
379 379 // Create fits file
380 380 GFits fits;
381 381  
... ... @@ -578,10 +578,9 @@ void cttsmap::get_parameters(void)
578 578 m_logL0 = (*this)["logL0"].real();
579 579 m_publish = (*this)["publish"].boolean();
580 580  
581   - // Optionally read ahead parameters so that they get correctly
582   - // dumped into the log file
  581 + // If needed later, query output filename now
583 582 if (read_ahead()) {
584   - m_outmap = (*this)["outmap"].filename();
  583 + (*this)["outmap"].query();
585 584 }
586 585  
587 586 // Write parameters into logger
... ...
src/support/ctool.cpp
... ... @@ -86,8 +86,8 @@
86 86 *
87 87 * This constructor should be used for using a ctool from Python.
88 88 ***************************************************************************/
89   -ctool::ctool(const std::string& name, const std::string& version) :
90   - GApplication(name, version)
  89 +ctool::ctool(const std::string& name,
  90 + const std::string& version) : GApplication(name, version)
91 91 {
92 92 // Initialise members
93 93 init_members();
... ... @@ -115,9 +115,10 @@ ctool::ctool(const std::string&amp; name, const std::string&amp; version) :
115 115 * about the usage of the ctool will be shown in the console and the ctool
116 116 * will exit. No log file will be opened in that case.
117 117 ***************************************************************************/
118   -ctool::ctool(const std::string& name, const std::string& version,
119   - int argc, char *argv[]) :
120   - GApplication(name, version, argc, argv)
  118 +ctool::ctool(const std::string& name,
  119 + const std::string& version,
  120 + int argc,
  121 + char* argv[]) : GApplication(name, version, argc, argv)
121 122 {
122 123 // Catch --help option before doing anything else
123 124 if (need_help()) {
... ... @@ -179,8 +180,9 @@ ctool::~ctool(void)
179 180 * @brief Assignment operator
180 181 *
181 182 * @param[in] app Application.
  183 + * @return Application.
182 184 *
183   - * Assigns one ctool to another.
  185 + * Assigns one ctool application to another.
184 186 ***************************************************************************/
185 187 ctool& ctool::operator=(const ctool& app)
186 188 {
... ... @@ -250,11 +252,6 @@ void ctool::init_members(void)
250 252 m_read_ahead = false;
251 253 m_use_xml = false;
252 254  
253   - // Set CTA time reference. G_CTA_MJDREF is the CTA reference MJD,
254   - // which is defined in GCTALib.hpp. This is somehow a kluge. We need
255   - // a better mechanism to implement the CTA reference MJD.
256   - //m_cta_ref.set(G_CTA_MJDREF, "s", "TT", "LOCAL");
257   -
258 255 // Set logger properties
259 256 log.date(true);
260 257  
... ... @@ -276,7 +273,6 @@ void ctool::copy_members(const ctool&amp; app)
276 273 // Copy members
277 274 m_read_ahead = app.m_read_ahead;
278 275 m_use_xml = app.m_use_xml;
279   - //m_cta_ref = app.m_cta_ref;
280 276  
281 277 // Return
282 278 return;
... ... @@ -346,19 +342,20 @@ void ctool::setup_observations(GObservations&amp; obs,
346 342 // Load observations if there are none in the container
347 343 if (obs.size() == 0) {
348 344  
349   - // Get the filename from the "inobs" parameter
350   - GFilename filename = (*this)["inobs"].filename();
351   -
352 345 // Throw an exception if the "inobs" parameter is not a valid
353 346 // filename
354   - if (!is_valid_filename(filename)) {
355   - std::string msg = "The \"inobs\" parameter \""+filename.url()+
  347 + if ((*this)["inobs"].is_undefined()) {
  348 + std::string msg = "The \"inobs\" parameter \""+
  349 + (*this)["inobs"].current_value()+
356 350 "\" is not a valid filename. Please specify "
357 351 "a valid event list, counts cube or "
358 352 "observation definition XML file.";
359 353 throw GException::invalid_value(G_SETUP_OBSERVATION, msg);
360 354 }
361 355  
  356 + // Get the filename from the "inobs" parameter
  357 + GFilename filename = (*this)["inobs"].filename();
  358 +
362 359 // If file does not exist then throw an exceptions
363 360 if (!filename.exists()) {
364 361 std::string msg = "The \"inobs\" parameter \""+filename.url()+
... ... @@ -462,18 +459,19 @@ void ctool::setup_models(GObservations&amp; obs,
462 459 // observation container
463 460 if (obs.models().size() == 0) {
464 461  
465   - // Get models XML filename
466   - GFilename filename = (*this)["inmodel"].filename();
467   -
468 462 // Throw an exception if the "inmodel" parameter is not a valid
469 463 // filename
470   - if (!is_valid_filename(filename)) {
471   - std::string msg = "The \"inmodel\" parameter \""+filename.url()+
  464 + if ((*this)["inmodel"].is_undefined()) {
  465 + std::string msg = "The \"inmodel\" parameter \""+
  466 + (*this)["inmodel"].current_value()+
472 467 "\" is not a valid filename. Please specify "
473 468 "a valid model definition XML file.";
474 469 throw GException::invalid_value(G_SETUP_MODELS, msg);
475 470 }
476 471  
  472 + // Get models XML filename
  473 + GFilename filename = (*this)["inmodel"].filename();
  474 +
477 475 // Load model container and assign it to observations container
478 476 obs.models(GModels(filename.url()));
479 477  
... ... @@ -816,19 +814,20 @@ GCTAObservation ctool::create_cta_obs(void)
816 814 ***************************************************************************/
817 815 void ctool::require_inobs(const std::string& method)
818 816 {
819   - // Get inobs filename
820   - GFilename filename = (*this)["inobs"].filename();
821   -
822 817 // Throw exception if no infile is given
823   - if (!is_valid_filename(filename)) {
  818 + if ((*this)["inobs"].is_undefined()) {
824 819 std::string msg = "A valid file needs to be specified for the "
825   - "\"inobs\" parameter, yet \""+filename.url()+
  820 + "\"inobs\" parameter, yet \""+
  821 + (*this)["inobs"].current_value()+
826 822 "\" was given."
827 823 " Specify a valid observation definition or "
828 824 "FITS file to proceed.";
829 825 throw GException::invalid_value(method, msg);
830 826 }
831 827  
  828 + // Get inobs filename
  829 + GFilename filename = (*this)["inobs"].filename();
  830 +
832 831 // Return
833 832 return;
834 833 }
... ... @@ -845,43 +844,48 @@ void ctool::require_inobs(const std::string&amp; method)
845 844 ***************************************************************************/
846 845 void ctool::require_inobs_nocube(const std::string& method)
847 846 {
848   - // Get inobs filename
849   - GFilename filename = (*this)["inobs"].filename();
  847 + // Continues only if we have a valid filename
  848 + if ((*this)["inobs"].is_valid()) {
850 849  
851   - // Continue only if we have a FITS file
852   - if (filename.is_fits()) {
  850 + // Get inobs filename
  851 + GFilename filename = (*this)["inobs"].filename();
853 852  
854   - // Signal no cube
855   - bool is_cube = false;
  853 + // Continue only if we have a FITS file
  854 + if (filename.is_fits()) {
856 855  
857   - // Try loading file as counts cube. If this is successful then
858   - // throw an exception
859   - try {
  856 + // Signal no cube
  857 + bool is_cube = false;
860 858  
861   - // Load cube from file
862   - GCTAEventCube cube(filename);
  859 + // Try loading file as counts cube. If this is successful then
  860 + // throw an exception
  861 + try {
863 862  
864   - // If we're still alive then signal that we have a cube
865   - is_cube = true;
  863 + // Load cube from file
  864 + GCTAEventCube cube(filename);
866 865  
867   - }
  866 + // If we're still alive then signal that we have a cube
  867 + is_cube = true;
868 868  
869   - // Catch any exceptions
870   - catch (...) {
871   - ;
872   - }
  869 + }
873 870  
874   - // If we have a counts cube then throw an exception
875   - if (is_cube) {
876   - std::string msg = "A counts cube has been specified for the "
877   - "\"inobs\" parameter, yet no counts cube "
878   - "can be specified as input observation."
879   - " Instead, specify an event list or an "
880   - "observation definition file.";
881   - throw GException::invalid_value(method, msg);
882   - }
  871 + // Catch any exceptions
  872 + catch (...) {
  873 + ;
  874 + }
  875 +
  876 + // If we have a counts cube then throw an exception
  877 + if (is_cube) {
  878 + std::string msg = "A counts cube has been specified for the "
  879 + "\"inobs\" parameter, yet no counts cube "
  880 + "can be specified as input observation."
  881 + " Instead, specify an event list or an "
  882 + "observation definition file.";
  883 + throw GException::invalid_value(method, msg);
  884 + }
883 885  
884   - } // endif: we had a FITS file
  886 + } // endif: we had a FITS file
  887 +
  888 + } // endif: filename was valid
885 889  
886 890 // Return
887 891 return;
... ... @@ -1178,8 +1182,8 @@ std::string ctool::set_outfile_name(const std::string&amp; filename)
1178 1182 bool ctool::is_stacked(void)
1179 1183 {
1180 1184 // First query the minimum and maximum energies
1181   - (*this)["emin"].real();
1182   - (*this)["emax"].real();
  1185 + (*this)["emin"].query();
  1186 + (*this)["emax"].query();
1183 1187  
1184 1188 // Now query the number of energy bins and set the stacked flag
1185 1189 bool stacked = ((*this)["enumbins"].integer() > 0) ? true : false;
... ... @@ -1187,13 +1191,13 @@ bool ctool::is_stacked(void)
1187 1191 // If a stacked analysis is requested then query the spatial definition
1188 1192 // of the cube
1189 1193 if (stacked) {
1190   - (*this)["coordsys"].string();
1191   - (*this)["proj"].string();
1192   - (*this)["xref"].real();
1193   - (*this)["yref"].real();
1194   - (*this)["nxpix"].integer();
1195   - (*this)["nypix"].integer();
1196   - (*this)["binsz"].real();
  1194 + (*this)["coordsys"].query();
  1195 + (*this)["proj"].query();
  1196 + (*this)["xref"].query();
  1197 + (*this)["yref"].query();
  1198 + (*this)["nxpix"].query();
  1199 + (*this)["nypix"].query();
  1200 + (*this)["binsz"].query();
1197 1201 }
1198 1202  
1199 1203 // Return stacked flag
... ... @@ -1224,23 +1228,23 @@ bool ctool::is_onoff(void)
1224 1228 if (onoff) {
1225 1229  
1226 1230 // Query csphagen parameters
1227   - (*this)["inexclusion"].filename();
1228   - (*this)["emin"].real();
1229   - (*this)["emax"].real();
1230   - (*this)["enumbins"].integer();
1231   - (*this)["coordsys"].string();
1232   - (*this)["xref"].real();
1233   - (*this)["yref"].real();
  1231 + (*this)["inexclusion"].query();
  1232 + (*this)["emin"].query();
  1233 + (*this)["emax"].query();
  1234 + (*this)["enumbins"].query();
  1235 + (*this)["coordsys"].query();
  1236 + (*this)["xref"].query();
  1237 + (*this)["yref"].query();
1234 1238 if ((*this)["srcshape"].string() == "CIRCLE"){
1235   - (*this)["rad"].real();
  1239 + (*this)["rad"].query();
1236 1240 }
1237 1241 if ((*this)["bkgmethod"].string() == "REFLECTED"){
1238   - (*this)["bkgregmin"].integer();
  1242 + (*this)["bkgregmin"].query();
1239 1243 }
1240   - (*this)["maxoffset"].real();
1241   - (*this)["etruemin"].real();
1242   - (*this)["etruemax"].real();
1243   - (*this)["etruebins"].integer();
  1244 + (*this)["maxoffset"].query();
  1245 + (*this)["etruemin"].query();
  1246 + (*this)["etruemax"].query();
  1247 + (*this)["etruebins"].query();
1244 1248  
1245 1249 } // endif: method was ONOFF
1246 1250  
... ... @@ -1419,38 +1423,28 @@ void ctool::set_obs_response(GCTAObservation* obs)
1419 1423 query_edisp = (*this)["edisp"].boolean();
1420 1424 }
1421 1425  
1422   - // Get filenames
1423   - GFilename expcube((*this)["expcube"].filename());
1424   - GFilename psfcube((*this)["psfcube"].filename());
1425   - GFilename edispcube;
1426   - if (query_edisp) {
1427   - edispcube = (*this)["edispcube"].filename();
1428   - }
1429   - GFilename bkgcube((*this)["bkgcube"].filename());
1430   -
1431 1426 // Extract stacked response information if available
1432   - if (is_valid_filename(expcube) && is_valid_filename(psfcube) &&
1433   - is_valid_filename(bkgcube)) {
1434   -
1435   - // Load exposure, PSF and background cubes
1436   - GCTACubeExposure exposure(expcube);
1437   - GCTACubePsf psf(psfcube);
1438   - GCTACubeBackground background(bkgcube);
  1427 + if ((*this)["expcube"].is_valid() &&
  1428 + (*this)["psfcube"].is_valid() &&
  1429 + (*this)["bkgcube"].is_valid()) {
  1430 +
  1431 + // Load exposure, PSF and background cubes and query energy
  1432 + // dispersion cube
  1433 + GCTACubeExposure exposure((*this)["expcube"].filename());
  1434 + GCTACubePsf psf((*this)["psfcube"].filename());
  1435 + if (query_edisp && (*this)["edispcube"].is_valid()) {
  1436 + (*this)["edispcube"].filename();
  1437 + }
  1438 + GCTACubeBackground background((*this)["bkgcube"].filename());
1439 1439  
1440   - // If querying of energy dispersion cube is requested then
1441   - // query it now
  1440 + // Set response
1442 1441 if (query_edisp) {
1443 1442  
1444   - // If filename is valid then use energy dispersion ...
1445   - if (is_valid_filename(edispcube)) {
1446   -
1447   - // Load energy dispersion cube
1448   - GCTACubeEdisp edisp(edispcube);
1449   -
1450   - // Set response with all four cubes
  1443 + // If energy dispersion cube was provided then use it
  1444 + if ((*this)["edispcube"].is_valid()) {
  1445 + GCTACubeEdisp edisp((*this)["edispcube"].filename());
1451 1446 obs->response(exposure, psf, edisp, background);
1452   -
1453   - } // endif: energy dispersion cube was provided
  1447 + }
1454 1448  
1455 1449 // ... otherwise work without energy dispersion
1456 1450 else {
... ... @@ -1606,12 +1600,9 @@ GObservations ctool::get_observations(const bool&amp; get_response)
1606 1600 // Initialise empty observation container
1607 1601 GObservations obs;
1608 1602  
1609   - // Get the filename from the input parameters
1610   - std::string filename = (*this)["inobs"].filename();
1611   -
1612 1603 // If no observation definition file has been specified then read all
1613 1604 // parameters that are necessary to create an observation from scratch
1614   - if (!is_valid_filename(filename)) {
  1605 + if ((*this)["inobs"].is_undefined()) {
1615 1606  
1616 1607 // Setup a new CTA observation
1617 1608 GCTAObservation cta_obs = create_cta_obs();
... ... @@ -1632,6 +1623,9 @@ GObservations ctool::get_observations(const bool&amp; get_response)
1632 1623 // ... otherwise we have a file name
1633 1624 else {
1634 1625  
  1626 + // Get the filename from the input parameters
  1627 + std::string filename = (*this)["inobs"].filename();
  1628 +
1635 1629 // If file is a FITS file then create an empty CTA observation
1636 1630 // and load file into observation
1637 1631 if (GFilename(filename).is_fits()) {
... ...
src/support/ctool.hpp
... ... @@ -134,7 +134,6 @@ protected:
134 134 const GCTAObservation& obs);
135 135 std::vector<bool> cube_layer_usage(const GEbounds& cube_ebounds,
136 136 const GEbounds& list_ebounds) const;
137   - bool is_valid_filename(const GFilename& filename) const;
138 137 std::string get_gtiname(const std::string& filename,
139 138 const std::string& evtname) const;
140 139 void save_event_list(const GCTAObservation* obs,
... ... @@ -175,19 +174,4 @@ const bool&amp; ctool::read_ahead(void) const
175 174 return (m_read_ahead);
176 175 }
177 176  
178   -
179   -/***********************************************************************//**
180   - * @brief Check of a filename is valid
181   - *
182   - * @return True if filename is valid
183   - *
184   - * Checks whether a filename is not empty and not "NONE".
185   - ***************************************************************************/
186   -inline
187   -bool ctool::is_valid_filename(const GFilename& filename) const
188   -{
189   - return (!filename.is_empty() &&
190   - (gammalib::tolower(filename.url()) != "none"));
191   -}
192   -
193 177 #endif /* CTOOL_HPP */
... ...
test/test_cscript.py
... ... @@ -2,7 +2,7 @@
2 2 # ==========================================================================
3 3 # This scripts performs unit tests for the cspull script.
4 4 #
5   -# Copyright (C) 2016-2017 Juergen Knoedlseder
  5 +# Copyright (C) 2016-2018 Juergen Knoedlseder
6 6 #
7 7 # This program is free software: you can redistribute it and/or modify
8 8 # it under the terms of the GNU General Public License as published by
... ... @@ -115,10 +115,6 @@ class cscript_test(ctools.cscript):
115 115 def check_get_current_rss(self):
116 116 return self._get_current_rss()
117 117  
118   - # Check is_valid_filename() method
119   - def check_is_valid_filename(self, filename):
120   - return self._is_valid_filename(gammalib.GFilename(filename))
121   -
122 118 # Check save_event_list() method
123 119 def check_save_event_list(self, infile, evtname, gtiname, outfile):
124 120 obs = gammalib.GCTAObservation()
... ... @@ -524,14 +520,6 @@ class Test(test):
524 520 # Test cube_layer_usage() method
525 521 # TODO: implement
526 522  
527   - # Test is_valid_filename() method
528   - self.test_assert(empty.check_is_valid_filename(self._model),
529   - 'Check model definiton XML file')
530   - self.test_assert(not empty.check_is_valid_filename(''),
531   - 'Check empty filename')
532   - self.test_assert(not empty.check_is_valid_filename('NONE'),
533   - 'Check "NONE" filename')
534   -
535 523 # Test get_gtiname() method
536 524 # TODO: implement
537 525  
... ...