GammaLib  1.7.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GApplication Class Reference

GammaLib application interface definition. More...

#include <GApplication.hpp>

Inheritance diagram for GApplication:
GBase

Public Member Functions

 GApplication (void)
 Void constructor. More...
 
 GApplication (const std::string &name, const std::string &version)
 Application constructor. More...
 
 GApplication (const std::string &name, const std::string &version, const GApplicationPars &pars)
 Application constructor. More...
 
 GApplication (const std::string &name, const std::string &version, int argc, char *argv[])
 Application constructor. More...
 
 GApplication (const GApplication &app)
 Copy constructor. More...
 
 ~GApplication (void)
 Destructor. More...
 
GApplicationoperator= (const GApplication &app)
 Assignment operator. More...
 
GApplicationParoperator[] (const int &index)
 Parameter access operator. More...
 
const GApplicationParoperator[] (const int &index) const
 Parameter access operator (const version) More...
 
GApplicationParoperator[] (const std::string &name)
 Parameter access operator. More...
 
const GApplicationParoperator[] (const std::string &name) const
 Parameter access operator (const version) More...
 
void clear (void)
 Clear application. More...
 
GApplicationclone (void) const
 Clone application. More...
 
std::string classname (void) const
 Return class name. More...
 
const std::string & name (void) const
 Return application name. More...
 
const std::string & version (void) const
 Return application version. More...
 
double telapse (void) const
 Return application elapsed time in calendar seconds. More...
 
double celapse (void) const
 Return application elapsed time in CPU seconds. More...
 
void logFileOpen (const bool &clobber=true)
 Open log file. More...
 
void logFileClose (void)
 Close log file. More...
 
bool logTerse (void) const
 Signal terse logging. More...
 
bool logNormal (void) const
 Signal normal logging. More...
 
bool logExplicit (void) const
 Signal explicit logging. More...
 
bool logVerbose (void) const
 Signal verbose logging. More...
 
bool logDebug (void) const
 Signal debug logging. More...
 
bool clobber (void) const
 Return clobber. More...
 
bool has_par (const std::string &name) const
 Signal if specified parameter exists. More...
 
const std::string & par_filename (void) const
 Returns parameter filename. More...
 
const std::string & log_filename (void) const
 Returns log filename. More...
 
void log_header (void)
 Write application header in log file. More...
 
void log_trailer (void)
 Write application trailer in log file. More...
 
void log_string (const GChatter &chatter, const std::string &string, const bool &linefeed=true)
 Write string in log file. More...
 
void log_value (const GChatter &chatter, const std::string &name, const std::string &value)
 Write parameter value in log file. More...
 
void log_value (const GChatter &chatter, const std::string &name, const int &value)
 Write parameter value in log file. More...
 
void log_value (const GChatter &chatter, const std::string &name, const double &value)
 Write parameter value in log file. More...
 
void log_header1 (const GChatter &chatter, const std::string &header)
 Write header 1 in log file. More...
 
void log_header2 (const GChatter &chatter, const std::string &header)
 Write header 2 in log file. More...
 
void log_header3 (const GChatter &chatter, const std::string &header)
 Write header 3 in log file. More...
 
void log_parameters (const GChatter &chatter)
 Write application parameters in log file. More...
 
const bool & need_help (void) const
 Signals if –help option has been specified. More...
 
const GApplicationParspars (void) const
 Return application parameters. More...
 
void pars (const GApplicationPars &pars)
 Set application parameters. More...
 
const std::vector< std::string > & args (void) const
 Return command line arguments. More...
 
std::string print (const GChatter &chatter=NORMAL) const
 Print application. More...
 
- Public Member Functions inherited from GBase
virtual ~GBase (void)
 Destructor. More...
 

Public Attributes

GLog log
 Application logger. More...
 

Protected Member Functions

void init_members (void)
 Initialise class members. More...
 
void copy_members (const GApplication &app)
 Copy class members. More...
 
void free_members (void)
 Delete class members. More...
 
void set_log_chatter (void)
 Set chattiness of logger. More...
 
void set_log_filename (void)
 Set log filename from "logfile" parameter. More...
 

Protected Attributes

std::string m_name
 Application name. More...
 
std::string m_version
 Application version. More...
 
std::string m_parfile
 Parameter filename. More...
 
std::string m_logfile
 Log filename. More...
 
std::vector< std::string > m_args
 Command line arguments. More...
 
std::time_t m_tstart
 Calendar start time of execution. More...
 
std::clock_t m_cstart
 Clock start time of execution. More...
 
GApplicationPars m_pars
 Application parameters. More...
 
bool m_pars_loaded
 Application parameters loaded. More...
 
bool m_need_help
 –help specified More...
 

Detailed Description

GammaLib application interface definition.

This class provides the base class for ftools-like executables based on GammaLib. The ftools-like executables will be implemented as derived classes, and automatically have access to task parameters and the application logger.

Definition at line 49 of file GApplication.hpp.

Constructor & Destructor Documentation

GApplication::GApplication ( void  )

Void constructor.

Constructs an empty application.

Definition at line 55 of file GApplication.cpp.

References init_members().

Referenced by clone().

GApplication::GApplication ( const std::string &  name,
const std::string &  version 
)

Application constructor.

Parameters
[in]nameApplication name.
[in]versionApplication version.

Constructs an application from an application name and version. The constructor will set the parameter filename to "<name>.par" and the log filename to "<name>".log. The parameters will be loaded from the parameter file.

No log file will be opened. To open the log file an explicit call to the logFileOpen() method is required.

This constructor should be used for Python scripts.

Definition at line 81 of file GApplication.cpp.

References init_members(), GApplicationPars::load(), m_logfile, m_name, m_parfile, m_pars, m_pars_loaded, m_version, name(), par_filename(), set_log_chatter(), set_log_filename(), and version().

GApplication::GApplication ( const std::string &  name,
const std::string &  version,
const GApplicationPars pars 
)

Application constructor.

Parameters
[in]nameApplication name.
[in]versionApplication version.
[in]parsApplication parameters.

Constructs an application from an application name and version. The constructor will set the parameter filename to "<name>.par" and the log filename to "<name>".log. The parameters will be loaded from the parameter file.

No log file will be opened. To open the log file an explicit call to the logFileOpen() method is required.

This constructor should be used for Python scripts.

Definition at line 126 of file GApplication.cpp.

References init_members(), m_logfile, m_name, m_parfile, m_pars, m_pars_loaded, m_version, name(), pars(), set_log_chatter(), set_log_filename(), and version().

GApplication::GApplication ( const std::string &  name,
const std::string &  version,
int  argc,
char *  argv[] 
)

Application constructor.

Parameters
[in]nameApplication name.
[in]versionApplication version.
[in]argcNumber of command line arguments
[in]argvCommand line arguments

Constructs an application from an application name, version and a number argc of command line arguments argv.

This constructor should be used for C++ applications.

Definition at line 169 of file GApplication.cpp.

References init_members(), GApplicationPars::load(), m_args, m_logfile, m_name, m_need_help, m_parfile, m_pars, m_pars_loaded, m_version, name(), par_filename(), set_log_chatter(), set_log_filename(), gammalib::strip_whitespace(), and version().

GApplication::GApplication ( const GApplication app)

Copy constructor.

Parameters
[in]appApplication.

Definition at line 228 of file GApplication.cpp.

References copy_members(), and init_members().

GApplication::~GApplication ( void  )

Destructor.

Definition at line 244 of file GApplication.cpp.

References free_members().

Member Function Documentation

const std::vector< std::string > & GApplication::args ( void  ) const
inline

Return command line arguments.

Returns
Command line arguments.

Definition at line 329 of file GApplication.hpp.

References m_args.

double GApplication::celapse ( void  ) const

Return application elapsed time in CPU seconds.

Returns
Application elapsed time in CPU seconds.

Definition at line 368 of file GApplication.cpp.

References m_cstart.

Referenced by log_trailer().

std::string GApplication::classname ( void  ) const
inlinevirtual

Return class name.

Returns
String containing the class name ("GApplication").

Implements GBase.

Definition at line 150 of file GApplication.hpp.

void GApplication::clear ( void  )
virtual
bool GApplication::clobber ( void  ) const

Return clobber.

Returns
True if the clobber parameter is true.

The clobber indicates if existing files should be overwritten.

Definition at line 534 of file GApplication.cpp.

References m_pars.

GApplication * GApplication::clone ( void  ) const
virtual

Clone application.

Returns
Pointer to deep copy of application.

Implements GBase.

Definition at line 337 of file GApplication.cpp.

References GApplication().

void GApplication::copy_members ( const GApplication app)
protected

Copy class members.

Parameters
[in]appApplication.

Copies all class members.

Definition at line 926 of file GApplication.cpp.

References log, m_args, m_cstart, m_logfile, m_name, m_need_help, m_parfile, m_pars, m_pars_loaded, m_tstart, and m_version.

Referenced by GApplication(), and operator=().

void GApplication::free_members ( void  )
protected

Delete class members.

Definition at line 951 of file GApplication.cpp.

References logFileClose(), m_pars, m_pars_loaded, par_filename(), and GApplicationPars::save().

Referenced by clear(), operator=(), and ~GApplication().

bool GApplication::has_par ( const std::string &  name) const
inline

Signal if specified parameter exists.

Parameters
[in]nameParameter name.
Returns
True if an application parameter with the specified name exists.

Definition at line 250 of file GApplication.hpp.

References GApplicationPars::contains(), and m_pars.

void GApplication::init_members ( void  )
protected

Initialise class members.

Definition at line 893 of file GApplication.cpp.

References GApplicationPars::clear(), GLog::clear(), log, m_args, m_cstart, m_logfile, m_name, m_need_help, m_parfile, m_pars, m_pars_loaded, m_tstart, and m_version.

Referenced by clear(), GApplication(), and operator=().

const std::string & GApplication::log_filename ( void  ) const
inline

Returns log filename.

Returns
Log filename.

Definition at line 275 of file GApplication.hpp.

References m_logfile, and set_log_filename().

Referenced by logFileOpen().

void GApplication::log_header ( void  )

Write application header in log file.

Dump the application header into the log file. The header is composed of a fixed width block delimined by "*" characters that contains information about the application name and version.

Definition at line 551 of file GApplication.cpp.

References gammalib::centre(), gammalib::fill(), header_width, GLog::indent(), gammalib::left(), log, m_name, and m_version.

Referenced by logFileOpen().

void GApplication::log_header1 ( const GChatter chatter,
const std::string &  header 
)

Write header 1 in log file.

Parameters
[in]chatterMinimum required chattiness
[in]headerHeader string

Writes a header of level 1 into the log file if chattiness is at least chatter.

Definition at line 723 of file GApplication.cpp.

References GLog::header1(), log, and m_pars.

void GApplication::log_header2 ( const GChatter chatter,
const std::string &  header 
)

Write header 2 in log file.

Parameters
[in]chatterMinimum required chattiness
[in]headerHeader string

Writes a header of level 2 into the log file if chattiness is at least chatter.

Definition at line 750 of file GApplication.cpp.

References GLog::header2(), log, and m_pars.

void GApplication::log_header3 ( const GChatter chatter,
const std::string &  header 
)

Write header 3 in log file.

Parameters
[in]chatterMinimum required chattiness
[in]headerHeader string

Writes a header of level 3 into the log file if chattiness is at least chatter.

Definition at line 776 of file GApplication.cpp.

References GLog::header3(), log, and m_pars.

void GApplication::log_parameters ( const GChatter chatter)

Write application parameters in log file.

Parameters
[in]chatterMinimum required chattiness

Writes all application parameters in the log file. For parameters that have not yet been queried the method does not write the current value but signals [not queried].

Definition at line 802 of file GApplication.cpp.

References gammalib::fill(), GLog::header1(), log, GApplicationPars::m_pars, m_pars, name(), and GApplicationPars::size().

void GApplication::log_string ( const GChatter chatter,
const std::string &  string,
const bool &  linefeed = true 
)

Write string in log file.

Parameters
[in]chatterMinimum required chattiness
[in]stringString
[in]linefeedTerminate string with linefeed?

Writes a string into the log file if chattiness is at least chatter. If linefeed is true the string is terminated with a linefeed.

Definition at line 606 of file GApplication.cpp.

References log, and m_pars.

void GApplication::log_trailer ( void  )

Write application trailer in log file.

The application trailer gives the total number of elapsed calendar and CPU seconds.

Definition at line 574 of file GApplication.cpp.

References celapse(), GLog::indent(), log, m_name, and telapse().

Referenced by logFileClose().

void GApplication::log_value ( const GChatter chatter,
const std::string &  name,
const std::string &  value 
)

Write parameter value in log file.

Parameters
[in]chatterMinimum required chattiness
[in]nameParameter name string
[in]valueValue string

Writes a parameter value into the log file if chattiness is at least chatter.

Definition at line 637 of file GApplication.cpp.

References log, m_pars, and gammalib::parformat().

void GApplication::log_value ( const GChatter chatter,
const std::string &  name,
const int &  value 
)

Write parameter value in log file.

Parameters
[in]chatterMinimum required chattiness
[in]nameParameter name string
[in]valueInteger value

Writes a parameter value into the log file if chattiness is at least chatter.

Definition at line 666 of file GApplication.cpp.

References log, m_pars, and gammalib::parformat().

void GApplication::log_value ( const GChatter chatter,
const std::string &  name,
const double &  value 
)

Write parameter value in log file.

Parameters
[in]chatterMinimum required chattiness
[in]nameParameter name string
[in]valueFloating point value

Writes a parameter value into the log file if chattiness is at least chatter.

Definition at line 695 of file GApplication.cpp.

References log, m_pars, and gammalib::parformat().

bool GApplication::logDebug ( void  ) const

Signal debug logging.

Returns
True if the debugging mode has been selected.

The debug level is used for application debugging.

Definition at line 517 of file GApplication.cpp.

References m_pars.

bool GApplication::logExplicit ( void  ) const

Signal explicit logging.

Returns
True if at least explicit logging is requested.

The explicit level is used for detailed application information that should be logged in detailed studies (chatter >= 3).

Definition at line 483 of file GApplication.cpp.

References m_pars.

void GApplication::logFileClose ( void  )

Close log file.

Close the log file. In case that some characters have been written through the logger a trailer will be appended to the logger before closing the log file. The trailer informs about the computation time used by the application.

Definition at line 416 of file GApplication.cpp.

References GLog::close(), GLog::is_open(), log, log_trailer(), and GLog::written_size().

Referenced by free_members().

void GApplication::logFileOpen ( const bool &  clobber = true)

Open log file.

Parameters
[in]clobberOverwrite (true) or append (false) to existing file (defaults to true)

Opens application log file and sets the logger chattiness dependent on the chatter parameter of the application.

Definition at line 387 of file GApplication.cpp.

References log, log_filename(), log_header(), GLog::open(), and set_log_chatter().

bool GApplication::logNormal ( void  ) const

Signal normal logging.

Returns
True if at least normal logging is requested.

The normal level is used for standard application information that should be logged in normal operations (chatter >= 2).

Definition at line 465 of file GApplication.cpp.

References m_pars.

bool GApplication::logTerse ( void  ) const

Signal terse logging.

Returns
True if at least terse logging is requested.

The terse level is used for the most crucial application information that should be logged in all cases (chatter >= 1).

Definition at line 447 of file GApplication.cpp.

References m_pars.

bool GApplication::logVerbose ( void  ) const

Signal verbose logging.

Returns
True if verbose logging is requested.

The verbose level is used for full application information (chatter >= 4).

Definition at line 500 of file GApplication.cpp.

References m_pars.

const std::string & GApplication::name ( void  ) const
inline

Return application name.

Returns
Application name.

Definition at line 225 of file GApplication.hpp.

References m_name.

Referenced by clear(), GApplication(), log_parameters(), and print().

const bool & GApplication::need_help ( void  ) const
inline

Signals if –help option has been specified.

Returns
True if –help option has been specified.

Definition at line 291 of file GApplication.hpp.

References m_need_help.

GApplication & GApplication::operator= ( const GApplication app)

Assignment operator.

Parameters
[in]appApplication.
Returns
Application.

Definition at line 266 of file GApplication.cpp.

References copy_members(), free_members(), and init_members().

GApplicationPar & GApplication::operator[] ( const int &  index)
inline

Parameter access operator.

Parameters
[in]indexParameter index [0,...,pars().size()-1].
Returns
Reference to application parameter

Returns a reference to the application parameter with the given index. No range checking is performed for the index.

Definition at line 197 of file GApplication.hpp.

References m_pars.

const GApplicationPar & GApplication::operator[] ( const int &  index) const
inline

Parameter access operator (const version)

Parameters
[in]indexParameter index [0,...,pars().size()-1].
Returns
Constant reference to application parameter

Returns a const reference to the application parameter with the given index. No range checking is performed for the index.

Definition at line 213 of file GApplication.hpp.

References m_pars.

GApplicationPar & GApplication::operator[] ( const std::string &  name)
inline

Parameter access operator.

Parameters
[in]nameParameter name.
Returns
Reference to application parameter.

Returns a reference to the application parameter with the given name.

Definition at line 165 of file GApplication.hpp.

References m_pars.

const GApplicationPar & GApplication::operator[] ( const std::string &  name) const
inline

Parameter access operator (const version)

Parameters
[in]nameParameter name.
Returns
Constant reference to application parameter

Returns a const reference to the application parameter with the given name.

Definition at line 181 of file GApplication.hpp.

References m_pars.

const std::string & GApplication::par_filename ( void  ) const
inline

Returns parameter filename.

Returns
Parameter filename.

Definition at line 262 of file GApplication.hpp.

References m_parfile.

Referenced by clear(), free_members(), and GApplication().

const GApplicationPars & GApplication::pars ( void  ) const
inline

Return application parameters.

Returns
Application parameters.

Definition at line 304 of file GApplication.hpp.

References m_pars.

Referenced by GApplication(), and pars().

void GApplication::pars ( const GApplicationPars pars)
inline

Set application parameters.

Parameters
[in]parsApplication parameters.

Definition at line 316 of file GApplication.hpp.

References m_pars, and pars().

std::string GApplication::print ( const GChatter chatter = NORMAL) const
virtual

Print application.

Parameters
[in]chatterChattiness.
Returns
String containing application information.

Implements GBase.

Definition at line 845 of file GApplication.cpp.

References m_args, GApplicationPars::m_pars, m_pars, name(), gammalib::parformat(), SILENT, GApplicationPars::size(), and version().

void GApplication::set_log_chatter ( void  )
protected

Set chattiness of logger.

Definition at line 969 of file GApplication.cpp.

References GLog::chatter(), log, and m_pars.

Referenced by clear(), GApplication(), and logFileOpen().

void GApplication::set_log_filename ( void  )
protected

Set log filename from "logfile" parameter.

If the application parameters contain a "logfile" parameter then set the file name of the log file from this parameter.

In case that the file name is not valid, the file name will be set to an empty string, which will prevent opening a log file.

Definition at line 999 of file GApplication.cpp.

References GApplicationPars::contains(), m_logfile, and m_pars.

Referenced by clear(), GApplication(), and log_filename().

double GApplication::telapse ( void  ) const

Return application elapsed time in calendar seconds.

Returns
Application elapsed time in calendar seconds.

Definition at line 349 of file GApplication.cpp.

References m_tstart.

Referenced by log_trailer().

const std::string & GApplication::version ( void  ) const
inline

Return application version.

Returns
Application version.

Definition at line 237 of file GApplication.hpp.

References m_version.

Referenced by clear(), GApplication(), and print().

Member Data Documentation

std::vector<std::string> GApplication::m_args
protected

Command line arguments.

Definition at line 135 of file GApplication.hpp.

Referenced by args(), copy_members(), GApplication(), init_members(), and print().

std::clock_t GApplication::m_cstart
protected

Clock start time of execution.

Definition at line 137 of file GApplication.hpp.

Referenced by celapse(), copy_members(), and init_members().

std::string GApplication::m_logfile
protected

Log filename.

Definition at line 134 of file GApplication.hpp.

Referenced by clear(), copy_members(), GApplication(), init_members(), log_filename(), and set_log_filename().

std::string GApplication::m_name
protected

Application name.

Definition at line 131 of file GApplication.hpp.

Referenced by clear(), copy_members(), GApplication(), init_members(), log_header(), log_trailer(), and name().

bool GApplication::m_need_help
protected

–help specified

Definition at line 140 of file GApplication.hpp.

Referenced by copy_members(), GApplication(), init_members(), and need_help().

std::string GApplication::m_parfile
protected

Parameter filename.

Definition at line 133 of file GApplication.hpp.

Referenced by clear(), copy_members(), GApplication(), init_members(), and par_filename().

bool GApplication::m_pars_loaded
protected

Application parameters loaded.

Definition at line 139 of file GApplication.hpp.

Referenced by clear(), copy_members(), free_members(), GApplication(), and init_members().

std::time_t GApplication::m_tstart
protected

Calendar start time of execution.

Definition at line 136 of file GApplication.hpp.

Referenced by copy_members(), init_members(), and telapse().

std::string GApplication::m_version
protected

Application version.

Definition at line 132 of file GApplication.hpp.

Referenced by clear(), copy_members(), GApplication(), init_members(), log_header(), and version().


The documentation for this class was generated from the following files: