ctools 2.1.0.dev
Loading...
Searching...
No Matches
ctool.hpp
Go to the documentation of this file.
1/***************************************************************************
2 * ctool - ctool base class *
3 * ----------------------------------------------------------------------- *
4 * copyright (C) 2014-2022 by Juergen Knoedlseder *
5 * ----------------------------------------------------------------------- *
6 * *
7 * This program is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation, either version 3 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
19 * *
20 ***************************************************************************/
21/**
22 * @file ctool.hpp
23 * @brief ctool base class definition
24 * @author Juergen Knoedlseder
25 */
26
27#ifndef CTOOL_HPP
28#define CTOOL_HPP
29
30/* __ Includes ___________________________________________________________ */
31#include "GammaLib.hpp"
32#include "GCTALib.hpp"
33
34/* __Definitions _________________________________________________________ */
35
36/* __ Constants __________________________________________________________ */
37
38
39/***********************************************************************//**
40 * @class ctool
41 *
42 * @brief Base class for ctools
43 *
44 * This class is the generic base class for all ctools. It enforces
45 * implementation of the clear(), run() and save() methods by all ctools,
46 * and it implements the execute() method.
47 *
48 * The class also provides a number of helper methods for ctools.
49 ***************************************************************************/
50class ctool : public GApplication {
51public:
52 // Constructors and destructors
53 ctool(const std::string& name,
54 const std::string& version);
55 ctool(const std::string& name,
56 const std::string& version,
57 const GApplicationPars& pars);
58 ctool(const std::string& name,
59 const std::string& version,
60 int argc,
61 char* argv[]);
62 ctool(const ctool& app);
63 virtual ~ctool(void);
64
65 // Operators
66 ctool& operator=(const ctool& app);
67
68 // Pure virtual methods
69 virtual void clear(void) = 0;
70 virtual void process(void) = 0;
71 virtual void save(void) = 0;
72
73 // Public methods
74 virtual void run(void);
75 virtual void execute(void);
76
77#ifdef SWIG
78public:
79#else
80protected:
81#endif
82 // Protected methods
83 void init_members(void);
84 void copy_members(const ctool& app);
85 void free_members(void);
86 void sync_pfiles(void);
87 const bool& read_ahead(void) const;
88
89 // Protected high-level setup methods
90 void setup_observations(GObservations& obs, const bool& response = true,
91 const bool& list = true,
92 const bool& cube = true);
93 void setup_models(GObservations& obs, const std::string& name = "");
94
95 // Protected methods that create objects from user parameters
96 GEbounds create_ebounds(void);
97 GEnergies create_energies(void);
98 GSkyMap create_map(const GObservations& obs);
99 GCTAEventCube create_cube(const GObservations& obs);
100 GCTAObservation create_cta_obs(void);
101
102 // Protected methods that check user parameters
103 void require_inobs(const std::string& method);
104 void require_inobs_nolist(const std::string& method);
105 void require_inobs_nocube(const std::string& method);
106
107 // Protected methods that extract user parameters
108 GCTARoi get_roi(const GCTAPointing& pnt = GCTAPointing());
109 GEbounds get_ebounds(void);
110 GGti get_gti(const GTimeReference& ref);
111 GCTAPointing get_pointing(void);
112 GSkyDir get_skydir(void);
113 std::string set_outfile_name(const std::string& filename);
114
115 // Protected methods that query user parameters
116 bool is_stacked(void);
117 bool is_onoff(void);
118
119 // Protected methods for logging
120 void log_parameters(const GChatter& chatter);
121 void log_observations(const GChatter& chatter,
122 const GObservations& obs,
123 const std::string& what = "Observation");
124 void log_models(const GChatter& chatter,
125 const GModels& models,
126 const std::string& what = "Model");
127
128 // Protected support methods
129 void set_response(GObservations& obs);
130 std::vector<bool> set_edisp(GObservations& obs, const bool& edisp) const;
131 void restore_edisp(GObservations& obs,
132 const std::vector<bool>& edisp) const;
133 void set_obs_response(GCTAObservation* obs);
134 GObservations get_observations(const bool& get_response = true);
135 GSkyDir get_mean_pointing(const GObservations& obs);
136 size_t get_current_rss(void);
137 std::string get_obs_header(const GObservation* obs) const;
138 GEnergies insert_energy_boundaries(const GEnergies& energies,
139 const GCTAObservation& obs);
140 std::vector<bool> cube_layer_usage(const GEbounds& cube_ebounds,
141 const GEbounds& list_ebounds) const;
142 std::string get_gtiname(const std::string& filename,
143 const std::string& evtname) const;
144 void save_event_list(const GCTAObservation* obs,
145 const std::string& infile,
146 const std::string& evtname,
147 const std::string& gtiname,
148 const std::string& outfile) const;
149
150 // Protected warning strings
151 std::string warn_too_few_energies(const GEnergies& energies) const;
152 std::string warn_xml_suffix(const GFilename& filename) const;
153
154 // Protected members
155 bool m_read_ahead; //!< Read ahead output parameters
156
157protected:
158 // Protected methods
159 void provide_help(void) const;
160
161 // Protected members
162 bool m_use_xml; //!< Use XML file instead of FITS file for observations
163};
164
165
166/***********************************************************************//**
167 * @brief Signal whether parameters should be read ahead
168 *
169 * @return True if parameters should be read ahead
170 *
171 * Ahead reading of parameter is useful in case that some parameters are only
172 * required in a late stage of the processing. By reading them ahead it is
173 * assured that these parameters will be queried at the beginning of the
174 * tool execution.
175 ***************************************************************************/
176inline
177const bool& ctool::read_ahead(void) const
178{
179 return (m_read_ahead);
180}
181
182#endif /* CTOOL_HPP */
Base class for ctools.
Definition ctool.hpp:50
virtual void run(void)
Run ctool.
Definition ctool.cpp:257
virtual void process(void)=0
virtual void clear(void)=0
GEnergies create_energies(void)
Create energies from user parameters.
Definition ctool.cpp:776
void set_obs_response(GCTAObservation *obs)
Set response for CTA observation.
Definition ctool.cpp:1752
std::string warn_too_few_energies(const GEnergies &energies) const
Set warning string if there are too few energies.
Definition ctool.cpp:2386
void set_response(GObservations &obs)
Set response for all CTA observations in container.
Definition ctool.cpp:1614
void require_inobs_nocube(const std::string &method)
Throws exception if inobs parameter is a counts cube.
Definition ctool.cpp:1149
bool m_use_xml
Use XML file instead of FITS file for observations.
Definition ctool.hpp:162
void restore_edisp(GObservations &obs, const std::vector< bool > &edisp) const
Restore energy dispersion flags of CTA observations.
Definition ctool.cpp:1689
GSkyDir get_skydir(void)
Return sky direction from User parameters.
Definition ctool.cpp:1465
GEnergies insert_energy_boundaries(const GEnergies &energies, const GCTAObservation &obs)
Insert observation energy boundaries into list of energies.
Definition ctool.cpp:2119
void save_event_list(const GCTAObservation *obs, const std::string &infile, const std::string &evtname, const std::string &gtiname, const std::string &outfile) const
Save event list into FITS file.
Definition ctool.cpp:2266
ctool(const std::string &name, const std::string &version)
Name constructor.
Definition ctool.cpp:90
void require_inobs_nolist(const std::string &method)
void setup_models(GObservations &obs, const std::string &name="")
Setup model container.
Definition ctool.cpp:545
GEbounds create_ebounds(void)
Create energy boundaries from user parameters.
Definition ctool.cpp:612
void free_members(void)
Delete class members.
Definition ctool.cpp:357
size_t get_current_rss(void)
Get current resident set size (physical memory use) in Bytes.
Definition ctool.cpp:2035
std::string get_gtiname(const std::string &filename, const std::string &evtname) const
Get Good Time Intervals extension name.
Definition ctool.cpp:2352
GSkyMap create_map(const GObservations &obs)
Create a skymap from user parameters.
Definition ctool.cpp:937
void log_observations(const GChatter &chatter, const GObservations &obs, const std::string &what="Observation")
Log observation container.
Definition ctool.cpp:1251
GGti get_gti(const GTimeReference &ref)
Return Good Time Intervals from User parameter.
Definition ctool.cpp:1415
ctool & operator=(const ctool &app)
Assignment operator.
Definition ctool.cpp:221
std::vector< bool > set_edisp(GObservations &obs, const bool &edisp) const
Set energy dispersion to CTA observations.
Definition ctool.cpp:1649
bool is_stacked(void)
Query user parameters for stacked analysis.
Definition ctool.cpp:1531
bool m_read_ahead
Read ahead output parameters.
Definition ctool.hpp:155
GObservations get_observations(const bool &get_response=true)
Get observation container.
Definition ctool.cpp:1885
const bool & read_ahead(void) const
Signal whether parameters should be read ahead.
Definition ctool.hpp:177
void log_parameters(const GChatter &chatter)
Log application parameters.
Definition ctool.cpp:1208
void copy_members(const ctool &app)
Copy class members.
Definition ctool.cpp:343
void sync_pfiles(void)
Synchronise parameter files.
Definition ctool.cpp:370
GCTAObservation create_cta_obs(void)
Create a CTA observation from User parameters.
Definition ctool.cpp:1056
void init_members(void)
Initialise class members.
Definition ctool.cpp:321
virtual ~ctool(void)
Destructor.
Definition ctool.cpp:197
GSkyDir get_mean_pointing(const GObservations &obs)
Derives mean pointing from CTA observations.
Definition ctool.cpp:1979
virtual void execute(void)
Execute ctool.
Definition ctool.cpp:285
void require_inobs(const std::string &method)
Throws exception if inobs parameter is not valid.
Definition ctool.cpp:1119
virtual void save(void)=0
GCTAPointing get_pointing(void)
Return CTA pointing from User parameters.
Definition ctool.cpp:1445
GCTAEventCube create_cube(const GObservations &obs)
Create a CTA event cube from user parameters.
Definition ctool.cpp:1006
void setup_observations(GObservations &obs, const bool &response=true, const bool &list=true, const bool &cube=true)
Setup observation container.
Definition ctool.cpp:431
std::vector< bool > cube_layer_usage(const GEbounds &cube_ebounds, const GEbounds &list_ebounds) const
Determine the counts cube layer usage.
Definition ctool.cpp:2194
bool is_onoff(void)
Query user parameters for On/Off analysis.
Definition ctool.cpp:1571
std::string warn_xml_suffix(const GFilename &filename) const
Set warning string if file has no .xml suffix.
Definition ctool.cpp:2427
std::string get_obs_header(const GObservation *obs) const
Return observation header string.
Definition ctool.cpp:2090
GEbounds get_ebounds(void)
Return energy boundaries from User parameters.
Definition ctool.cpp:1378
std::string set_outfile_name(const std::string &filename)
Set output file name.
Definition ctool.cpp:1491
GCTARoi get_roi(const GCTAPointing &pnt=GCTAPointing())
Return RoI from User parameters.
Definition ctool.cpp:1325
void provide_help(void) const
Dump help text in the console.
Definition ctool.cpp:2467
void log_models(const GChatter &chatter, const GModels &models, const std::string &what="Model")
Log model container.
Definition ctool.cpp:1285