From 8140e337613ed3f1fdfe15f5980a41ae28e4dd98 Mon Sep 17 00:00:00 2001 From: knodlseder <> Date: Mon, 17 Jan 2011 21:22:51 +0000 Subject: [PATCH] new implementation using logger and separate methods --- pyext/ctbin.i | 10 +++++++--- src/ctbin/ctbin.cpp | 223 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------- src/ctbin/ctbin.hpp | 32 ++++++++++++++++++++++++++------ src/ctbin/main.cpp | 2 +- 4 files changed, 223 insertions(+), 44 deletions(-) diff --git a/pyext/ctbin.i b/pyext/ctbin.i index e3370e1..d65819e 100644 --- a/pyext/ctbin.i +++ b/pyext/ctbin.i @@ -1,7 +1,7 @@ /*************************************************************************** * ctbin - CTA data binning tool * * ----------------------------------------------------------------------- * - * copyright (C) 2010 by Jurgen Knodlseder * + * copyright (C) 2010-2011 by Jurgen Knodlseder * * ----------------------------------------------------------------------- * * * * This program is free software; you can redistribute it and/or modify * @@ -30,10 +30,14 @@ class ctbin : public GApplication { public: // Constructors and destructors - ctbin(void) : GApplication(CTBIN_NAME, CTBIN_VERSION) { return; } + ctbin(void); + ctbin(int argc, char *argv[]); + ~ctbin(void); // Methods - int run(void); + void run(void); + void get_parameters(void); + void bin(void); }; diff --git a/src/ctbin/ctbin.cpp b/src/ctbin/ctbin.cpp index 75d26d9..51311fe 100644 --- a/src/ctbin/ctbin.cpp +++ b/src/ctbin/ctbin.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * ctbin - CTA data binning tool * * ----------------------------------------------------------------------- * - * copyright (C) 2010 by Jurgen Knodlseder * + * copyright (C) 2010-2011 by Jurgen Knodlseder * * ----------------------------------------------------------------------- * * * * This program is free software; you can redistribute it and/or modify * @@ -24,36 +24,142 @@ #include "ctbin.hpp" #include "GTools.hpp" +/* __ Debug definitions __________________________________________________ */ + +/* __ Coding definitions _________________________________________________ */ + + +/*========================================================================== + = = + = Constructors/destructors = + = = + ==========================================================================*/ + +/***********************************************************************//** + * @brief Void constructor + ***************************************************************************/ +ctbin::ctbin(void) : GApplication(CTBIN_NAME, CTBIN_VERSION) +{ + // Initialise members + init_members(); + + // Write header into logger + log_header(); + + // Return + return; +} + + +/***********************************************************************//** + * @brief Command line constructor + * + * @param[in] argc Number of arguments in command line. + * @param[in] argv Array of command line arguments. + ***************************************************************************/ +ctbin::ctbin(int argc, char *argv[]) : + GApplication(CTBIN_NAME, CTBIN_VERSION, argc, argv) +{ + // Initialise members + init_members(); + + // Write header into logger + log_header(); + + // Return + return; +} + + +/***********************************************************************//** + * @brief Destructor + ***************************************************************************/ +ctbin::~ctbin(void) +{ + // Free members + free_members(); + + // Return + return; +} + + +/*========================================================================== + = = + = Operators = + = = + ==========================================================================*/ + +/*========================================================================== + = = + = Public methods = + = = + ==========================================================================*/ /***********************************************************************//** * @brief Run gtbin application ***************************************************************************/ -int ctbin::run(void) +void ctbin::run(void) { - // Test dump - std::cout << *this << std::endl; + // Get parameters + get_parameters(); - // Get events and output file names - std::string evfile = par("evfile")->value(); - std::string outfile = par("outfile")->value(); - - // Get clobber - std::string sclobber = par("clobber")->value(); - int clobber = 0; - if (tolower(sclobber) == "yes") - clobber = 1; + // Write parameters into logger + if (logTerse()) { + log_parameters(); + log << std::endl; + } + + // Bin data + bin(); + // Return + return; +} + + +/***********************************************************************//** + * @brief Get application parameters + * + * Get all task parameters from parameter file or (if required) by querying + * the user. + ***************************************************************************/ +void ctbin::get_parameters(void) +{ + // Get parameters + m_evfile = par("evfile")->value(); + m_outfile = par("outfile")->value(); + m_emin = par("emin")->real(); + m_emax = par("emax")->real(); + m_enumbins = par("enumbins")->integer(); + m_proj = par("proj")->value(); + m_coordsys = par("coordsys")->value(); + m_xref = par("xref")->real(); + m_yref = par("yref")->real(); + m_binsz = par("binsz")->real(); + m_nxpix = par("nxpix")->integer(); + m_nypix = par("nypix")->integer(); + + // Return + return; +} + + +/***********************************************************************//** + * @brief Run gtbin application + ***************************************************************************/ +void ctbin::bin(void) +{ // Load events as unbinned data GCTAObservation obs; - obs.load_unbinned(evfile); + obs.load_unbinned(m_evfile); // Setup energy range covered by data GEnergy emin; GEnergy emax; - emin.TeV(todouble(par("emin")->value())); - emax.TeV(todouble(par("emax")->value())); - int enumbins = toint(par("enumbins")->value()); - obs.ebounds()->setlog(emin, emax, enumbins); + emin.TeV(m_emin); + emax.TeV(m_emax); + obs.ebounds()->setlog(emin, emax, m_enumbins); // Setup time range covered by data GTime tstart; @@ -62,18 +168,17 @@ int ctbin::run(void) tstop.met(10000.0); obs.gti()->add(tstart, tstop); - std::cout << obs; - + // Log observation + if (logExplicit()) { + log << std::endl; + log.header1("Observation"); + log << obs << std::endl; + } + // Create skymap - std::string wcs = par("proj")->value(); - std::string coords = par("coordsys")->value(); - double x = todouble(par("xref")->value()); - double y = todouble(par("yref")->value()); - double dx = todouble(par("binsz")->value()); - double dy = todouble(par("binsz")->value()); - int nx = toint(par("nxpix")->value()); - int ny = toint(par("nypix")->value()); - GSkymap map = GSkymap(wcs, coords, x, y, dx, dy, nx, ny, enumbins); + GSkymap map = GSkymap(m_proj, m_coordsys, + m_xref, m_yref, m_binsz, m_binsz, + m_nxpix, m_nypix, m_enumbins); // Fill sky map GCTAEventList* events = (GCTAEventList*)obs.events(); @@ -85,8 +190,8 @@ int ctbin::run(void) GSkyPixel pixel = map.dir2xy(dir); // Skip if pixel is out of range - if (pixel.x() < -0.5 || pixel.x() > (nx-0.5) || - pixel.y() < -0.5 || pixel.y() > (ny-0.5)) + if (pixel.x() < -0.5 || pixel.x() > (m_nxpix-0.5) || + pixel.y() < -0.5 || pixel.y() > (m_nypix-0.5)) continue; // Determine energy bin. Skip if we are outside the energy range @@ -99,15 +204,65 @@ int ctbin::run(void) } // endfor: looped over all events - std::cout << map; + // Log observation + if (logTerse()) { + log << std::endl; + log.header1("Counts map"); + log << map << std::endl; + } // Save counts map GFits file; map.write(&file); obs.ebounds()->write(&file); obs.gti()->write(&file); - file.saveto(outfile, clobber); + file.saveto(m_outfile, clobber()); + + // Return + return; +} + + +/*========================================================================== + = = + = Private methods = + = = + ==========================================================================*/ + +/***********************************************************************//** + * @brief Initialise class members + ***************************************************************************/ +void ctbin::init_members(void) +{ + // Initialise members + m_evfile.clear(); + m_outfile.clear(); + m_emin = 0.0; + m_emax = 0.0; + m_enumbins = 0; + m_proj.clear(); + m_coordsys.clear(); + m_xref = 0.0; + m_yref = 0.0; + m_binsz = 0.0; + m_nxpix = 0; + m_nypix = 0; + + // Set logger properties + log.date(true); + + // Return + return; +} + + +/***********************************************************************//** + * @brief Delete class members + ***************************************************************************/ +void ctbin::free_members(void) +{ + // Free members // Return - return 0; + return; } diff --git a/src/ctbin/ctbin.hpp b/src/ctbin/ctbin.hpp index 03fc90e..12a631a 100644 --- a/src/ctbin/ctbin.hpp +++ b/src/ctbin/ctbin.hpp @@ -1,7 +1,7 @@ /*************************************************************************** * ctbin - CTA data binning tool * * ----------------------------------------------------------------------- * - * copyright (C) 2010 by Jurgen Knodlseder * + * copyright (C) 2010-2011 by Jurgen Knodlseder * * ----------------------------------------------------------------------- * * * * This program is free software; you can redistribute it and/or modify * @@ -36,13 +36,33 @@ class ctbin : public GApplication { public: // Constructors and destructors - ctbin(void) : - GApplication(CTBIN_NAME, CTBIN_VERSION) { return; } - ctbin(int argc, char *argv[]) : - GApplication(CTBIN_NAME, CTBIN_VERSION, argc, argv) { return; } + ctbin(void); + ctbin(int argc, char *argv[]); + ~ctbin(void); // Methods - int run(void); + void run(void); + void get_parameters(void); + void bin(void); + +protected: + // Protected methods + void init_members(void); + void free_members(void); + + // User parameters + std::string m_evfile; //!< Input event list + std::string m_outfile; //!< Output counts map + double m_emin; //!< Lower energy + double m_emax; //!< Upper energy + int m_enumbins; //!< Number of energy bins + std::string m_proj; //!< WCS projection + std::string m_coordsys; //!< Coordinate system + double m_xref; //!< Longitude reference coordinate + double m_yref; //!< Latitude reference coordinate + double m_binsz; //!< Pixel size + int m_nxpix; //!< Number of pixels in longitude + int m_nypix; //!< Number of pixels in latitude }; #endif /* CTBIN_HPP */ diff --git a/src/ctbin/main.cpp b/src/ctbin/main.cpp index d6e09ac..68d5a2a 100644 --- a/src/ctbin/main.cpp +++ b/src/ctbin/main.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * ctbin - CTA data binning main code * * ----------------------------------------------------------------------- * - * copyright (C) 2010 by Jurgen Knodlseder * + * copyright (C) 2010-2011 by Jurgen Knodlseder * * ----------------------------------------------------------------------- * * * * This program is free software; you can redistribute it and/or modify * -- libgit2 0.21.4