From 435eff52f3700f8b02c2c7d41a14ee56943a1ea2 Mon Sep 17 00:00:00 2001 From: knodlseder <> Date: Mon, 7 Feb 2011 13:56:19 +0000 Subject: [PATCH] add copy constructor and assignment operator --- src/ctobssim/ctobssim.cpp | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------- src/ctobssim/ctobssim.hpp | 5 +++++ 2 files changed, 94 insertions(+), 7 deletions(-) diff --git a/src/ctobssim/ctobssim.cpp b/src/ctobssim/ctobssim.cpp index e73eb15..b6aa02a 100644 --- a/src/ctobssim/ctobssim.cpp +++ b/src/ctobssim/ctobssim.cpp @@ -25,7 +25,8 @@ #include "GTools.hpp" /* __ Method name definitions ____________________________________________ */ -#define G_SIMULATE_SOURCE "ctobssim::simulate_source(GCTAObservation*, GPhotons&)" +#define G_SIMULATE_SOURCE "ctobssim::simulate_source(GCTAObservation*,"\ + " GPhotons&)" /* __ Debug definitions __________________________________________________ */ @@ -57,8 +58,8 @@ ctobssim::ctobssim(void) : GApplication(CTOBSSIM_NAME, CTOBSSIM_VERSION) /***********************************************************************//** * @brief Observations constructor * - * This method creates an instance of the class by copying an existing - * observations container. + * This constructor creates an instance of the class that is initialised from + * an observation container. ***************************************************************************/ ctobssim::ctobssim(GObservations obs) : GApplication(CTOBSSIM_NAME, CTOBSSIM_VERSION) { @@ -97,6 +98,24 @@ ctobssim::ctobssim(int argc, char *argv[]) : /***********************************************************************//** + * @brief Copy constructor + * + * @param[in] app Application. + ***************************************************************************/ +ctobssim::ctobssim(const ctobssim& app) : GApplication(app) +{ + // Initialise members + init_members(); + + // Copy members + copy_members(app); + + // Return + return; +} + + +/***********************************************************************//** * @brief Destructor ***************************************************************************/ ctobssim::~ctobssim(void) @@ -115,6 +134,35 @@ ctobssim::~ctobssim(void) = = ==========================================================================*/ +/***********************************************************************//** + * @brief Assignment operator + * + * @param[in] app Application. + ***************************************************************************/ +ctobssim& ctobssim::operator= (const ctobssim& app) +{ + // Execute only if object is not identical + if (this != &app) { + + // Copy base class members + this->GApplication::operator=(app); + + // Free members + free_members(); + + // Initialise members + init_members(); + + // Copy members + copy_members(app); + + } // endif: object was not identical + + // Return this object + return *this; +} + + /*========================================================================== = = = Public methods = @@ -146,6 +194,10 @@ void ctobssim::clear(void) ***************************************************************************/ void ctobssim::execute(void) { + // Read ahead output filename so that it gets dumped correctly in the + // parameters log + m_outfile = par("outfile")->value(); + // Run the simulation run(); @@ -266,6 +318,9 @@ void ctobssim::save(void) log.header1("Save observation"); } + // Get output filename + m_outfile = par("outfile")->value(); + // Loop over all observation in the container int file_num = 0; for (int i = 0; i < m_obs.size(); ++i) { @@ -369,8 +424,7 @@ void ctobssim::get_parameters(void) } // endif: there was no observation in the container // Get other parameters - m_outfile = par("outfile")->value(); - m_seed = par("seed")->integer(); + m_seed = par("seed")->integer(); // Initialise random number generator m_ran.seed(m_seed); @@ -510,7 +564,7 @@ GPhotons ctobssim::simulate_photons(const GCTAObservation* obs, * * @exception GCTAException::no_pointing * No valid pointing found in CTA observation - * @exception GException::no_response + * @exception GCTAException::no_response * No valid response found in CTA observation * * Simulate source events from a photon list for a given CTA observation. @@ -536,7 +590,7 @@ void ctobssim::simulate_source(GCTAObservation* obs, const GPhotons& photons) // is not defined. GCTAResponse* rsp = obs->response(); if (rsp == NULL) - throw GException::no_response(G_SIMULATE_SOURCE); + throw GCTAException::no_response(G_SIMULATE_SOURCE); // Make sure that the observation holds a CTA event list. If this // is not the case then allocate and attach a CTA event list now. @@ -751,6 +805,34 @@ void ctobssim::init_members(void) /***********************************************************************//** + * @brief Copy class members + * + * @param[in] app Application. + ***************************************************************************/ +void ctobssim::copy_members(const ctobssim& app) +{ + // Copy attributes + m_infile = app.m_infile; + m_outfile = app.m_outfile; + m_caldb = app.m_caldb; + m_irf = app.m_irf; + m_obs = app.m_obs; + m_seed = app.m_seed; + m_ra = app.m_ra; + m_dec = app.m_dec; + m_rad = app.m_rad; + m_tmin = app.m_tmin; + m_tmax = app.m_tmax; + m_emin = app.m_emin; + m_emax = app.m_emax; + m_area = app.m_area; + + // Return + return; +} + + +/***********************************************************************//** * @brief Delete class members ***************************************************************************/ void ctobssim::free_members(void) diff --git a/src/ctobssim/ctobssim.hpp b/src/ctobssim/ctobssim.hpp index a0655ac..78ac898 100644 --- a/src/ctobssim/ctobssim.hpp +++ b/src/ctobssim/ctobssim.hpp @@ -45,8 +45,12 @@ public: ctobssim(void); explicit ctobssim(GObservations obs); ctobssim(int argc, char *argv[]); + ctobssim(const ctobssim& app); virtual ~ctobssim(void); + // Operators + ctobssim& operator= (const ctobssim& app); + // Methods void clear(void); void execute(void); @@ -61,6 +65,7 @@ public: protected: // Protected methods void init_members(void); + void copy_members(const ctobssim& app); void free_members(void); // User parameters -- libgit2 0.21.4