Commit 3b9e0e5f8d516516586c1e17c853a0843be72189

Authored by Jürgen Knödlseder
1 parent 05cf25d9

ctpsfcube now derives from ctool base class.

pyext/ctpsfcube.i
1 1 /***************************************************************************
2   - * ctpsfcube - CTA PSF cube tool *
  2 + * ctpsfcube - PSF cube generation tool *
3 3 * ----------------------------------------------------------------------- *
4 4 * copyright (C) 2014 by Chia-Chun Lu *
5 5 * ----------------------------------------------------------------------- *
... ... @@ -20,22 +20,21 @@
20 20 ***************************************************************************/
21 21 /**
22 22 * @file ctpsfcube.i
23   - * @brief CTA PSF cube tool definition
  23 + * @brief PSF cube generation tool definition
24 24 * @author Chia-Chun Lu
25 25 */
26 26  
27 27 %{
28 28 /* Put headers and other declarations here that are needed for compilation */
29 29 #include "ctpsfcube.hpp"
30   -#include "GTools.hpp"
31 30 %}
32 31  
33 32 /***********************************************************************//**
34 33 * @class ctpsfcube
35 34 *
36   - * @brief CTA PSF cube tool
  35 + * @brief PSF cube generation tool
37 36 ***************************************************************************/
38   -class ctpsfcube : public GApplication {
  37 +class ctpsfcube : public ctool {
39 38  
40 39 public:
41 40 // Constructors and destructors
... ... @@ -54,7 +53,7 @@ public:
54 53 };
55 54  
56 55 /***********************************************************************//**
57   - * @brief CTA PSF cube tool Python extension
  56 + * @brief PSF cube generation tool Python extension
58 57 ***************************************************************************/
59 58 %extend ctpsfcube {
60 59 ctpsfcube copy() {
... ...
src/ctpsfcube/Makefile.am
1 1 ## Process this file with automake to produce Makefile.in
2 2  
  3 +# Set include directories
  4 +INCLUDES = -I$(top_srcdir)/src/support
  5 +
3 6 # Program name
4 7 bin_PROGRAMS = ctpsfcube
5 8  
... ... @@ -14,7 +17,7 @@ libctpsfcube_la_SOURCES = $(sources)
14 17 ctpsfcube_SOURCES = main.cpp
15 18 ctpsfcube_LDFLAGS = $(LIB_LINK_OPTION) @LDFLAGS@
16 19 ctpsfcube_CPPFLAGS = @CPPFLAGS@
17   -ctpsfcube_LDADD = libctpsfcube.la
  20 +ctpsfcube_LDADD = libctpsfcube.la $(top_srcdir)/src/support/libsupport.la
18 21  
19 22 # Parameter files
20 23 pfilesdir = $(prefix)/syspfiles
... ...
src/ctpsfcube/ctpsfcube.cpp
1 1 /***************************************************************************
2   - * ctpsfcube - CTA PSF cube tool *
  2 + * ctpsfcube - PSF cube generation tool *
3 3 * ----------------------------------------------------------------------- *
4 4 * copyright (C) 2014 by Chia-Chun Lu *
5 5 * ----------------------------------------------------------------------- *
... ... @@ -20,7 +20,7 @@
20 20 ***************************************************************************/
21 21 /**
22 22 * @file ctpsfcube.cpp
23   - * @brief CTA PSF cube tool implementation
  23 + * @brief PSF cube generation tool implementation
24 24 * @author Chia-Chun Lu
25 25 */
26 26  
... ... @@ -34,7 +34,6 @@
34 34 #include "GWcs.hpp"
35 35  
36 36 /* __ Method name definitions ____________________________________________ */
37   -#define G_GET_EBOUNDS "ctpsfcube::get_ebounds()"
38 37 #define G_GET_PARAMETERS "ctpsfcube::get_parameters()"
39 38 #define G_SET_FROM_CNTMAP "ctpsfcube::set_from_cntmap(std::string&)"
40 39  
... ... @@ -52,14 +51,11 @@
52 51 /***********************************************************************//**
53 52 * @brief Void constructor
54 53 ***************************************************************************/
55   -ctpsfcube::ctpsfcube(void) : GApplication(CTPSFCUBE_NAME, CTPSFCUBE_VERSION)
  54 +ctpsfcube::ctpsfcube(void) : ctool(CTPSFCUBE_NAME, CTPSFCUBE_VERSION)
56 55 {
57 56 // Initialise members
58 57 init_members();
59 58  
60   - // Write header into logger
61   - log_header();
62   -
63 59 // Return
64 60 return;
65 61 }
... ... @@ -73,7 +69,8 @@ ctpsfcube::ctpsfcube(void) : GApplication(CTPSFCUBE_NAME, CTPSFCUBE_VERSION)
73 69 * This method creates an instance of the class by copying an existing
74 70 * observations container.
75 71 ***************************************************************************/
76   -ctpsfcube::ctpsfcube(const GObservations& obs) : GApplication(CTPSFCUBE_NAME, CTPSFCUBE_VERSION)
  72 +ctpsfcube::ctpsfcube(const GObservations& obs) :
  73 + ctool(CTPSFCUBE_NAME, CTPSFCUBE_VERSION)
77 74 {
78 75 // Initialise members
79 76 init_members();
... ... @@ -81,9 +78,6 @@ ctpsfcube::ctpsfcube(const GObservations& obs) : GApplication(CTPSFCUBE_NAME, CT
81 78 // Set observations
82 79 m_obs = obs;
83 80  
84   - // Write header into logger
85   - log_header();
86   -
87 81 // Return
88 82 return;
89 83 }
... ... @@ -97,14 +91,11 @@ ctpsfcube::ctpsfcube(const GObservations& obs) : GApplication(CTPSFCUBE_NAME, CT
97 91 * @param[in] argv Array of command line arguments.
98 92 ***************************************************************************/
99 93 ctpsfcube::ctpsfcube(int argc, char *argv[]) :
100   - GApplication(CTPSFCUBE_NAME, CTPSFCUBE_VERSION, argc, argv)
  94 + ctool(CTPSFCUBE_NAME, CTPSFCUBE_VERSION, argc, argv)
101 95 {
102 96 // Initialise members
103 97 init_members();
104 98  
105   - // Write header into logger
106   - log_header();
107   -
108 99 // Return
109 100 return;
110 101 }
... ... @@ -115,7 +106,7 @@ ctpsfcube::ctpsfcube(int argc, char *argv[]) :
115 106 *
116 107 * @param[in] app ctpsfcube application.
117 108 ***************************************************************************/
118   -ctpsfcube::ctpsfcube(const ctpsfcube& app) : GApplication(app)
  109 +ctpsfcube::ctpsfcube(const ctpsfcube& app) : ctool(app)
119 110 {
120 111 // Initialise members
121 112 init_members();
... ... @@ -159,7 +150,7 @@ ctpsfcube& ctpsfcube::operator=(const ctpsfcube& app)
159 150 if (this != &app) {
160 151  
161 152 // Copy base class members
162   - this->GApplication::operator=(app);
  153 + this->ctool::operator=(app);
163 154  
164 155 // Free members
165 156 free_members();
... ... @@ -190,10 +181,12 @@ void ctpsfcube::clear(void)
190 181 {
191 182 // Free members
192 183 free_members();
  184 + this->ctool::free_members();
193 185 this->GApplication::free_members();
194 186  
195 187 // Initialise members
196 188 this->GApplication::init_members();
  189 + this->ctool::init_members();
197 190 init_members();
198 191  
199 192 // Return
... ... @@ -315,6 +308,67 @@ void ctpsfcube::save(void)
315 308 }
316 309  
317 310  
  311 +/*==========================================================================
  312 + = =
  313 + = Private methods =
  314 + = =
  315 + ==========================================================================*/
  316 +
  317 +/***********************************************************************//**
  318 + * @brief Initialise class members
  319 + ***************************************************************************/
  320 +void ctpsfcube::init_members(void)
  321 +{
  322 + // Initialise members
  323 + m_outfile.clear();
  324 + m_apply_edisp = false;
  325 +
  326 + // Initialise protected members
  327 + m_read_ahead = false;
  328 + m_obs.clear();
  329 + m_psfcube.clear();
  330 + m_ebounds.clear();
  331 +
  332 + // Set logger properties
  333 + log.date(true);
  334 +
  335 + // Return
  336 + return;
  337 +}
  338 +
  339 +
  340 +/***********************************************************************//**
  341 + * @brief Copy class members
  342 + *
  343 + * @param[in] app Application.
  344 + ***************************************************************************/
  345 +void ctpsfcube::copy_members(const ctpsfcube& app)
  346 +{
  347 + // Copy attributes
  348 + m_outfile = app.m_outfile;
  349 + m_apply_edisp = app.m_apply_edisp;
  350 +
  351 + // Copy protected members
  352 + m_read_ahead = app.m_read_ahead;
  353 + m_obs = app.m_obs;
  354 + m_psfcube = app.m_psfcube;
  355 + m_ebounds = app.m_ebounds;
  356 +
  357 + // Return
  358 + return;
  359 +}
  360 +
  361 +
  362 +/***********************************************************************//**
  363 + * @brief Delete class members
  364 + ***************************************************************************/
  365 +void ctpsfcube::free_members(void)
  366 +{
  367 + // Return
  368 + return;
  369 +}
  370 +
  371 +
318 372 /***********************************************************************//**
319 373 * @brief Get application parameters
320 374 *
... ... @@ -332,7 +386,7 @@ void ctpsfcube::get_parameters(void)
332 386 }
333 387  
334 388 // Make sure that response is set
335   - set_response();
  389 + set_response(m_obs);
336 390  
337 391 // Read energy dispersion flag
338 392 m_apply_edisp = (*this)["edisp"].boolean();
... ... @@ -354,7 +408,7 @@ void ctpsfcube::get_parameters(void)
354 408 int ndbins = (*this)["anumbins"].integer();
355 409  
356 410 // Get energy definition
357   - get_ebounds();
  411 + m_ebounds = get_ebounds();
358 412  
359 413 // Define PSF cube
360 414 m_psfcube = GCTAMeanPsf(wcs, coordsys, xref, yref,
... ... @@ -419,125 +473,6 @@ void ctpsfcube::get_obs(void)
419 473  
420 474  
421 475 /***********************************************************************//**
422   - * @brief Set observation response
423   - *
424   - * Set response for all observations that have no response.
425   - ***************************************************************************/
426   -void ctpsfcube::set_response(void)
427   -{
428   - // Loop over all observations
429   - for (int i = 0; i < m_obs.size(); ++i) {
430   -
431   - // Is this observation a CTA observation?
432   - GCTAObservation* obs = dynamic_cast<GCTAObservation*>(m_obs[i]);
433   -
434   - // Yes ...
435   - if (obs != NULL) {
436   -
437   - // Set response if we don't have one
438   - if (!obs->has_response()) {
439   -
440   - // Load response information
441   - std::string database = (*this)["caldb"].string();
442   - std::string irf = (*this)["irf"].string();
443   -
444   - // Set calibration database. If specified parameter is a
445   - // directory then use this as the pathname to the calibration
446   - // database. Otherwise interpret this as the instrument name,
447   - // the mission being "cta"
448   - GCaldb caldb;
449   - if (gammalib::dir_exists(database)) {
450   - caldb.rootdir(database);
451   - }
452   - else {
453   - caldb.open("cta", database);
454   - }
455   -
456   - // Set reponse
457   - obs->response(irf, caldb);
458   -
459   - } // endif: observation already has a response
460   -
461   - } // endif: observation was a CTA observation
462   -
463   - } // endfor: looped over all observations
464   -
465   - // Return
466   - return;
467   -}
468   -
469   -
470   -/***********************************************************************//**
471   - * @brief Get energy boundaries from parameters
472   - *
473   - * @exception GException::invalid_value
474   - * Invalid extension name encountered.
475   - *
476   - * Get the energy boundaries from the user parameters.
477   - ***************************************************************************/
478   -void ctpsfcube::get_ebounds(void)
479   -{
480   - // Determine the energy binning alogrithm
481   - std::string ebinalg = (*this)["ebinalg"].string();
482   -
483   - // If we have the binning given by a file then try to get the boundaries
484   - // from that file
485   - if (ebinalg == "FILE") {
486   -
487   - // Get filename
488   - std::string filename = (*this)["ebinfile"].filename();
489   -
490   - // Open fits file to check which extension is given
491   - GFits file(filename);
492   -
493   - // Check first for EBOUNDS extension
494   - if (file.contains("EBOUNDS")) {
495   - file.close();
496   - m_ebounds.load(filename, "EBOUNDS");
497   - }
498   -
499   - // ... then check for ENERGYBINS extension
500   - else if (file.contains("ENERGYBINS")) {
501   - file.close();
502   - m_ebounds.load(filename, "ENERGYBINS");
503   - }
504   -
505   - // ... otherwise throw an exception
506   - else {
507   - file.close();
508   - std::string msg = "No extension with name \"EBOUNDS\" or"
509   - " \"ENERGYBINS\" found in FITS file"
510   - " \""+filename+"\".\n"
511   - "An \"EBOUNDS\" or \"ENERGYBINS\" extension"
512   - " is required if the parameter \"ebinalg\""
513   - " is set to \"FILE\".";
514   - throw GException::invalid_value(G_GET_EBOUNDS, msg);
515   - }
516   - }
517   -
518   - // ... otherwise read emin, emax and nebins
519   - else {
520   -
521   - // Get the relevant parameters
522   - double emin = (*this)["emin"].real();
523   - double emax = (*this)["emax"].real();
524   - int enumbins = (*this)["enumbins"].integer();
525   - bool log = ((*this)["ebinalg"].string() == "LIN") ? false : true;
526   -
527   - // Create energy boundaries
528   - m_ebounds = GEbounds(enumbins,
529   - GEnergy(emin, "TeV"),
530   - GEnergy(emax, "TeV"),
531   - log);
532   -
533   - }
534   -
535   - // Return
536   - return;
537   -}
538   -
539   -
540   -/***********************************************************************//**
541 476 * @brief Set PSF cube definition from counts map
542 477 *
543 478 * @exception GException::invalid_value
... ... @@ -605,69 +540,3 @@ void ctpsfcube::set_from_cntmap(const std::string&amp; filename)
605 540 // Return
606 541 return;
607 542 }
608   -
609   -
610   -/*==========================================================================
611   - = =
612   - = Private methods =
613   - = =
614   - ==========================================================================*/
615   -
616   -/***********************************************************************//**
617   - * @brief Initialise class members
618   - ***************************************************************************/
619   -void ctpsfcube::init_members(void)
620   -{
621   - // Initialise members
622   - m_outfile.clear();
623   - m_apply_edisp = false;
624   -
625   - // Initialise protected members
626   - m_read_ahead = false;
627   - m_obs.clear();
628   - m_psfcube.clear();
629   - m_ebounds.clear();
630   -
631   - // Set logger properties
632   - log.date(true);
633   -
634   - // Return
635   - return;
636   -}
637   -
638   -
639   -/***********************************************************************//**
640   - * @brief Copy class members
641   - *
642   - * @param[in] app Application.
643   - ***************************************************************************/
644   -void ctpsfcube::copy_members(const ctpsfcube& app)
645   -{
646   - // Copy attributes
647   - m_outfile = app.m_outfile;
648   - m_apply_edisp = app.m_apply_edisp;
649   -
650   - // Copy protected members
651   - m_read_ahead = app.m_read_ahead;
652   - m_obs = app.m_obs;
653   - m_psfcube = app.m_psfcube;
654   - m_ebounds = app.m_ebounds;
655   -
656   - // Return
657   - return;
658   -}
659   -
660   -
661   -/***********************************************************************//**
662   - * @brief Delete class members
663   - ***************************************************************************/
664   -void ctpsfcube::free_members(void)
665   -{
666   - // Write separator into logger
667   - if (logTerse()) {
668   - log << std::endl;
669   - }
670   -
671   - // Return
672   - return;
673   -}
... ...
src/ctpsfcube/ctpsfcube.hpp
1 1 /***************************************************************************
2   - * ctpsfcube - CTA PSF cube tool *
  2 + * ctpsfcube - PSF cube generation tool *
3 3 * ----------------------------------------------------------------------- *
4 4 * copyright (C) 2014 by Chia-Chun Lu *
5 5 * ----------------------------------------------------------------------- *
... ... @@ -20,7 +20,7 @@
20 20 ***************************************************************************/
21 21 /**
22 22 * @file ctpsfcube.hpp
23   - * @brief CTA PSF cube tool definition
  23 + * @brief PSF cube generation tool definition
24 24 * @author Chia-Chun Lu
25 25 */
26 26  
... ... @@ -30,6 +30,7 @@
30 30 /* __ Includes ___________________________________________________________ */
31 31 #include "GammaLib.hpp"
32 32 #include "GCTALib.hpp"
  33 +#include "ctool.hpp"
33 34  
34 35 /* __Definitions _________________________________________________________ */
35 36 #define CTPSFCUBE_NAME "ctpsfcube"
... ... @@ -39,9 +40,9 @@
39 40 /***********************************************************************//**
40 41 * @class ctpsfcube
41 42 *
42   - * @brief CTA PSF cube tool
  43 + * @brief PSF cube generation tool
43 44 ***************************************************************************/
44   -class ctpsfcube : public GApplication {
  45 +class ctpsfcube : public ctool {
45 46  
46 47 public:
47 48 // Constructors and destructors
... ... @@ -68,8 +69,6 @@ protected:
68 69 void free_members(void);
69 70 void get_parameters(void);
70 71 void get_obs(void);
71   - void set_response(void);
72   - void get_ebounds(void);
73 72 void set_from_cntmap(const std::string& filename);
74 73  
75 74 // User parameters
... ...
src/support/Makefile.am
1 1 ## Process this file with automake to produce Makefile.in
2 2  
3   -# Set include directories
4   -#INCLUDES =
5   -
6   -# Define package included headers (to be installed)
7   -#pkginclude_HEADERS = ctool.hpp
8   -
9 3 # Define sources for this directory
10 4 sources = ctool.cpp
11 5  
... ...