Commit 435eff52f3700f8b02c2c7d41a14ee56943a1ea2

Authored by knodlseder
1 parent 23397076

add copy constructor and assignment operator

src/ctobssim/ctobssim.cpp
... ... @@ -25,7 +25,8 @@
25 25 #include "GTools.hpp"
26 26  
27 27 /* __ Method name definitions ____________________________________________ */
28   -#define G_SIMULATE_SOURCE "ctobssim::simulate_source(GCTAObservation*, GPhotons&)"
  28 +#define G_SIMULATE_SOURCE "ctobssim::simulate_source(GCTAObservation*,"\
  29 + " GPhotons&)"
29 30  
30 31 /* __ Debug definitions __________________________________________________ */
31 32  
... ... @@ -57,8 +58,8 @@ ctobssim::ctobssim(void) : GApplication(CTOBSSIM_NAME, CTOBSSIM_VERSION)
57 58 /***********************************************************************//**
58 59 * @brief Observations constructor
59 60 *
60   - * This method creates an instance of the class by copying an existing
61   - * observations container.
  61 + * This constructor creates an instance of the class that is initialised from
  62 + * an observation container.
62 63 ***************************************************************************/
63 64 ctobssim::ctobssim(GObservations obs) : GApplication(CTOBSSIM_NAME, CTOBSSIM_VERSION)
64 65 {
... ... @@ -97,6 +98,24 @@ ctobssim::ctobssim(int argc, char *argv[]) :
97 98  
98 99  
99 100 /***********************************************************************//**
  101 + * @brief Copy constructor
  102 + *
  103 + * @param[in] app Application.
  104 + ***************************************************************************/
  105 +ctobssim::ctobssim(const ctobssim& app) : GApplication(app)
  106 +{
  107 + // Initialise members
  108 + init_members();
  109 +
  110 + // Copy members
  111 + copy_members(app);
  112 +
  113 + // Return
  114 + return;
  115 +}
  116 +
  117 +
  118 +/***********************************************************************//**
100 119 * @brief Destructor
101 120 ***************************************************************************/
102 121 ctobssim::~ctobssim(void)
... ... @@ -115,6 +134,35 @@ ctobssim::~ctobssim(void)
115 134 = =
116 135 ==========================================================================*/
117 136  
  137 +/***********************************************************************//**
  138 + * @brief Assignment operator
  139 + *
  140 + * @param[in] app Application.
  141 + ***************************************************************************/
  142 +ctobssim& ctobssim::operator= (const ctobssim& app)
  143 +{
  144 + // Execute only if object is not identical
  145 + if (this != &app) {
  146 +
  147 + // Copy base class members
  148 + this->GApplication::operator=(app);
  149 +
  150 + // Free members
  151 + free_members();
  152 +
  153 + // Initialise members
  154 + init_members();
  155 +
  156 + // Copy members
  157 + copy_members(app);
  158 +
  159 + } // endif: object was not identical
  160 +
  161 + // Return this object
  162 + return *this;
  163 +}
  164 +
  165 +
118 166 /*==========================================================================
119 167 = =
120 168 = Public methods =
... ... @@ -146,6 +194,10 @@ void ctobssim::clear(void)
146 194 ***************************************************************************/
147 195 void ctobssim::execute(void)
148 196 {
  197 + // Read ahead output filename so that it gets dumped correctly in the
  198 + // parameters log
  199 + m_outfile = par("outfile")->value();
  200 +
149 201 // Run the simulation
150 202 run();
151 203  
... ... @@ -266,6 +318,9 @@ void ctobssim::save(void)
266 318 log.header1("Save observation");
267 319 }
268 320  
  321 + // Get output filename
  322 + m_outfile = par("outfile")->value();
  323 +
269 324 // Loop over all observation in the container
270 325 int file_num = 0;
271 326 for (int i = 0; i < m_obs.size(); ++i) {
... ... @@ -369,8 +424,7 @@ void ctobssim::get_parameters(void)
369 424 } // endif: there was no observation in the container
370 425  
371 426 // Get other parameters
372   - m_outfile = par("outfile")->value();
373   - m_seed = par("seed")->integer();
  427 + m_seed = par("seed")->integer();
374 428  
375 429 // Initialise random number generator
376 430 m_ran.seed(m_seed);
... ... @@ -510,7 +564,7 @@ GPhotons ctobssim::simulate_photons(const GCTAObservation* obs,
510 564 *
511 565 * @exception GCTAException::no_pointing
512 566 * No valid pointing found in CTA observation
513   - * @exception GException::no_response
  567 + * @exception GCTAException::no_response
514 568 * No valid response found in CTA observation
515 569 *
516 570 * Simulate source events from a photon list for a given CTA observation.
... ... @@ -536,7 +590,7 @@ void ctobssim::simulate_source(GCTAObservation* obs, const GPhotons&amp; photons)
536 590 // is not defined.
537 591 GCTAResponse* rsp = obs->response();
538 592 if (rsp == NULL)
539   - throw GException::no_response(G_SIMULATE_SOURCE);
  593 + throw GCTAException::no_response(G_SIMULATE_SOURCE);
540 594  
541 595 // Make sure that the observation holds a CTA event list. If this
542 596 // is not the case then allocate and attach a CTA event list now.
... ... @@ -751,6 +805,34 @@ void ctobssim::init_members(void)
751 805  
752 806  
753 807 /***********************************************************************//**
  808 + * @brief Copy class members
  809 + *
  810 + * @param[in] app Application.
  811 + ***************************************************************************/
  812 +void ctobssim::copy_members(const ctobssim& app)
  813 +{
  814 + // Copy attributes
  815 + m_infile = app.m_infile;
  816 + m_outfile = app.m_outfile;
  817 + m_caldb = app.m_caldb;
  818 + m_irf = app.m_irf;
  819 + m_obs = app.m_obs;
  820 + m_seed = app.m_seed;
  821 + m_ra = app.m_ra;
  822 + m_dec = app.m_dec;
  823 + m_rad = app.m_rad;
  824 + m_tmin = app.m_tmin;
  825 + m_tmax = app.m_tmax;
  826 + m_emin = app.m_emin;
  827 + m_emax = app.m_emax;
  828 + m_area = app.m_area;
  829 +
  830 + // Return
  831 + return;
  832 +}
  833 +
  834 +
  835 +/***********************************************************************//**
754 836 * @brief Delete class members
755 837 ***************************************************************************/
756 838 void ctobssim::free_members(void)
... ...
src/ctobssim/ctobssim.hpp
... ... @@ -45,8 +45,12 @@ public:
45 45 ctobssim(void);
46 46 explicit ctobssim(GObservations obs);
47 47 ctobssim(int argc, char *argv[]);
  48 + ctobssim(const ctobssim& app);
48 49 virtual ~ctobssim(void);
49 50  
  51 + // Operators
  52 + ctobssim& operator= (const ctobssim& app);
  53 +
50 54 // Methods
51 55 void clear(void);
52 56 void execute(void);
... ... @@ -61,6 +65,7 @@ public:
61 65 protected:
62 66 // Protected methods
63 67 void init_members(void);
  68 + void copy_members(const ctobssim& app);
64 69 void free_members(void);
65 70  
66 71 // User parameters
... ...