Commit 435eff52f3700f8b02c2c7d41a14ee56943a1ea2

Authored by knodlseder
1 parent 23397076

add copy constructor and assignment operator

src/ctobssim/ctobssim.cpp
@@ -25,7 +25,8 @@ @@ -25,7 +25,8 @@
25 #include "GTools.hpp" 25 #include "GTools.hpp"
26 26
27 /* __ Method name definitions ____________________________________________ */ 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 /* __ Debug definitions __________________________________________________ */ 31 /* __ Debug definitions __________________________________________________ */
31 32
@@ -57,8 +58,8 @@ ctobssim::ctobssim(void) : GApplication(CTOBSSIM_NAME, CTOBSSIM_VERSION) @@ -57,8 +58,8 @@ ctobssim::ctobssim(void) : GApplication(CTOBSSIM_NAME, CTOBSSIM_VERSION)
57 /***********************************************************************//** 58 /***********************************************************************//**
58 * @brief Observations constructor 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 ctobssim::ctobssim(GObservations obs) : GApplication(CTOBSSIM_NAME, CTOBSSIM_VERSION) 64 ctobssim::ctobssim(GObservations obs) : GApplication(CTOBSSIM_NAME, CTOBSSIM_VERSION)
64 { 65 {
@@ -97,6 +98,24 @@ ctobssim::ctobssim(int argc, char *argv[]) : @@ -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 * @brief Destructor 119 * @brief Destructor
101 ***************************************************************************/ 120 ***************************************************************************/
102 ctobssim::~ctobssim(void) 121 ctobssim::~ctobssim(void)
@@ -115,6 +134,35 @@ 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 = Public methods = 168 = Public methods =
@@ -146,6 +194,10 @@ void ctobssim::clear(void) @@ -146,6 +194,10 @@ void ctobssim::clear(void)
146 ***************************************************************************/ 194 ***************************************************************************/
147 void ctobssim::execute(void) 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 // Run the simulation 201 // Run the simulation
150 run(); 202 run();
151 203
@@ -266,6 +318,9 @@ void ctobssim::save(void) @@ -266,6 +318,9 @@ void ctobssim::save(void)
266 log.header1("Save observation"); 318 log.header1("Save observation");
267 } 319 }
268 320
  321 + // Get output filename
  322 + m_outfile = par("outfile")->value();
  323 +
269 // Loop over all observation in the container 324 // Loop over all observation in the container
270 int file_num = 0; 325 int file_num = 0;
271 for (int i = 0; i < m_obs.size(); ++i) { 326 for (int i = 0; i < m_obs.size(); ++i) {
@@ -369,8 +424,7 @@ void ctobssim::get_parameters(void) @@ -369,8 +424,7 @@ void ctobssim::get_parameters(void)
369 } // endif: there was no observation in the container 424 } // endif: there was no observation in the container
370 425
371 // Get other parameters 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 // Initialise random number generator 429 // Initialise random number generator
376 m_ran.seed(m_seed); 430 m_ran.seed(m_seed);
@@ -510,7 +564,7 @@ GPhotons ctobssim::simulate_photons(const GCTAObservation* obs, @@ -510,7 +564,7 @@ GPhotons ctobssim::simulate_photons(const GCTAObservation* obs,
510 * 564 *
511 * @exception GCTAException::no_pointing 565 * @exception GCTAException::no_pointing
512 * No valid pointing found in CTA observation 566 * No valid pointing found in CTA observation
513 - * @exception GException::no_response 567 + * @exception GCTAException::no_response
514 * No valid response found in CTA observation 568 * No valid response found in CTA observation
515 * 569 *
516 * Simulate source events from a photon list for a given CTA observation. 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,7 +590,7 @@ void ctobssim::simulate_source(GCTAObservation* obs, const GPhotons&amp; photons)
536 // is not defined. 590 // is not defined.
537 GCTAResponse* rsp = obs->response(); 591 GCTAResponse* rsp = obs->response();
538 if (rsp == NULL) 592 if (rsp == NULL)
539 - throw GException::no_response(G_SIMULATE_SOURCE); 593 + throw GCTAException::no_response(G_SIMULATE_SOURCE);
540 594
541 // Make sure that the observation holds a CTA event list. If this 595 // Make sure that the observation holds a CTA event list. If this
542 // is not the case then allocate and attach a CTA event list now. 596 // is not the case then allocate and attach a CTA event list now.
@@ -751,6 +805,34 @@ void ctobssim::init_members(void) @@ -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 * @brief Delete class members 836 * @brief Delete class members
755 ***************************************************************************/ 837 ***************************************************************************/
756 void ctobssim::free_members(void) 838 void ctobssim::free_members(void)
src/ctobssim/ctobssim.hpp
@@ -45,8 +45,12 @@ public: @@ -45,8 +45,12 @@ public:
45 ctobssim(void); 45 ctobssim(void);
46 explicit ctobssim(GObservations obs); 46 explicit ctobssim(GObservations obs);
47 ctobssim(int argc, char *argv[]); 47 ctobssim(int argc, char *argv[]);
  48 + ctobssim(const ctobssim& app);
48 virtual ~ctobssim(void); 49 virtual ~ctobssim(void);
49 50
  51 + // Operators
  52 + ctobssim& operator= (const ctobssim& app);
  53 +
50 // Methods 54 // Methods
51 void clear(void); 55 void clear(void);
52 void execute(void); 56 void execute(void);
@@ -61,6 +65,7 @@ public: @@ -61,6 +65,7 @@ public:
61 protected: 65 protected:
62 // Protected methods 66 // Protected methods
63 void init_members(void); 67 void init_members(void);
  68 + void copy_members(const ctobssim& app);
64 void free_members(void); 69 void free_members(void);
65 70
66 // User parameters 71 // User parameters