Commit ca1bd30deb4f8ba41b2614e9edbcfbd5eaade831
1 parent
51e199a2
Complete classes for instrument module code generation (#2190)
Showing
10 changed files
with
1407 additions
and
7 deletions
inst/com/pyext/GCOMEventCube.i
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GCOMEventCube.i - COMPTEL event bin container class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2012-2016 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2012-2017 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -20,7 +20,7 @@ |
| 20 | 20 | ***************************************************************************/ |
| 21 | 21 | /** |
| 22 | 22 | * @file GCOMEventCube.hpp |
| 23 | - * @brief COMPTEL event bin container class interface definition | |
| 23 | + * @brief COMPTEL event bin container class definition | |
| 24 | 24 | * @author Juergen Knoedlseder |
| 25 | 25 | */ |
| 26 | 26 | %{ |
| ... | ... | @@ -30,9 +30,9 @@ |
| 30 | 30 | |
| 31 | 31 | |
| 32 | 32 | /***********************************************************************//** |
| 33 | - * @class GCTAEventCube | |
| 33 | + * @class GCOMEventCube | |
| 34 | 34 | * |
| 35 | - * @brief CTA event bin container class Python interface | |
| 35 | + * @brief COMPTEL event bin container class | |
| 36 | 36 | ***************************************************************************/ |
| 37 | 37 | class GCOMEventCube : public GEventCube { |
| 38 | 38 | public: | ... | ... |
src/template/GXXXEventAtom.hpp
| ... | ... | @@ -44,9 +44,6 @@ |
| 44 | 44 | ***************************************************************************/ |
| 45 | 45 | class GXXXEventAtom : public GEventAtom { |
| 46 | 46 | |
| 47 | - // Friend classes | |
| 48 | - //friend class GXXXEventList; | |
| 49 | - | |
| 50 | 47 | public: |
| 51 | 48 | // Constructors and destructors |
| 52 | 49 | GXXXEventAtom(void); | ... | ... |
src/template/GXXXEventBin.cpp
0 → 100644
| 1 | +/*************************************************************************** | |
| 2 | + * GXXXEventBin.cpp - [INSTRUMENT] event bin class * | |
| 3 | + * ----------------------------------------------------------------------- * | |
| 4 | + * copyright (C) [YEAR] by [AUTHOR] * | |
| 5 | + * ----------------------------------------------------------------------- * | |
| 6 | + * * | |
| 7 | + * This program is free software: you can redistribute it and/or modify * | |
| 8 | + * it under the terms of the GNU General Public License as published by * | |
| 9 | + * the Free Software Foundation, either version 3 of the License, or * | |
| 10 | + * (at your option) any later version. * | |
| 11 | + * * | |
| 12 | + * This program is distributed in the hope that it will be useful, * | |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
| 15 | + * GNU General Public License for more details. * | |
| 16 | + * * | |
| 17 | + * You should have received a copy of the GNU General Public License * | |
| 18 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. * | |
| 19 | + * * | |
| 20 | + ***************************************************************************/ | |
| 21 | +/** | |
| 22 | + * @file GXXXEventBin.hpp | |
| 23 | + * @brief [INSTRUMENT] event bin class implementation | |
| 24 | + * @author [AUTHOR] | |
| 25 | + */ | |
| 26 | + | |
| 27 | +/* __ Includes ___________________________________________________________ */ | |
| 28 | +#ifdef HAVE_CONFIG_H | |
| 29 | +#include <config.h> | |
| 30 | +#endif | |
| 31 | +#include <cmath> | |
| 32 | +#include <string> | |
| 33 | +#include "GTools.hpp" | |
| 34 | +#include "GXXXEventBin.hpp" | |
| 35 | + | |
| 36 | +/* __ Method name definitions ____________________________________________ */ | |
| 37 | + | |
| 38 | +/* __ Macros _____________________________________________________________ */ | |
| 39 | + | |
| 40 | +/* __ Coding definitions _________________________________________________ */ | |
| 41 | + | |
| 42 | +/* __ Debug definitions __________________________________________________ */ | |
| 43 | + | |
| 44 | + | |
| 45 | +/*========================================================================== | |
| 46 | + = = | |
| 47 | + = Constructors/destructors = | |
| 48 | + = = | |
| 49 | + ==========================================================================*/ | |
| 50 | + | |
| 51 | +/***********************************************************************//** | |
| 52 | + * @brief Void constructor | |
| 53 | + * | |
| 54 | + * Creates an empty [INSTRUMENT] event bin. | |
| 55 | + ***************************************************************************/ | |
| 56 | +GXXXEventBin::GXXXEventBin(void) : GEventBin() | |
| 57 | +{ | |
| 58 | + // Initialise class members for clean destruction | |
| 59 | + init_members(); | |
| 60 | + | |
| 61 | + // Return | |
| 62 | + return; | |
| 63 | +} | |
| 64 | + | |
| 65 | + | |
| 66 | +/***********************************************************************//** | |
| 67 | + * @brief Copy constructor | |
| 68 | + * | |
| 69 | + * @param[in] bin [INSTRUMENT] event bin. | |
| 70 | + ***************************************************************************/ | |
| 71 | +GXXXEventBin::GXXXEventBin(const GXXXEventBin& bin) : GEventBin(bin) | |
| 72 | +{ | |
| 73 | + // Initialise class members for clean destruction | |
| 74 | + init_members(); | |
| 75 | + | |
| 76 | + // Copy members | |
| 77 | + copy_members(bin); | |
| 78 | + | |
| 79 | + // Return | |
| 80 | + return; | |
| 81 | +} | |
| 82 | + | |
| 83 | + | |
| 84 | +/***********************************************************************//** | |
| 85 | + * @brief Destructor | |
| 86 | + ***************************************************************************/ | |
| 87 | +GXXXEventBin::~GXXXEventBin(void) | |
| 88 | +{ | |
| 89 | + // Free members | |
| 90 | + free_members(); | |
| 91 | + | |
| 92 | + // Return | |
| 93 | + return; | |
| 94 | +} | |
| 95 | + | |
| 96 | + | |
| 97 | +/*========================================================================== | |
| 98 | + = = | |
| 99 | + = Operators = | |
| 100 | + = = | |
| 101 | + ==========================================================================*/ | |
| 102 | + | |
| 103 | +/***********************************************************************//** | |
| 104 | + * @brief Assignment operator | |
| 105 | + * | |
| 106 | + * @param[in] bin [INSTRUMENT] event bin. | |
| 107 | + * @return [INSTRUMENT] event bin. | |
| 108 | + ***************************************************************************/ | |
| 109 | +GXXXEventBin& GXXXEventBin::operator=(const GXXXEventBin& bin) | |
| 110 | +{ | |
| 111 | + // Execute only if object is not identical | |
| 112 | + if (this != &bin) { | |
| 113 | + | |
| 114 | + // Copy base class members | |
| 115 | + this->GEventBin::operator=(bin); | |
| 116 | + | |
| 117 | + // Free members | |
| 118 | + free_members(); | |
| 119 | + | |
| 120 | + // Initialise private members for clean destruction | |
| 121 | + init_members(); | |
| 122 | + | |
| 123 | + // Copy members | |
| 124 | + copy_members(bin); | |
| 125 | + | |
| 126 | + } // endif: object was not identical | |
| 127 | + | |
| 128 | + // Return this object | |
| 129 | + return *this; | |
| 130 | +} | |
| 131 | + | |
| 132 | + | |
| 133 | +/*========================================================================== | |
| 134 | + = = | |
| 135 | + = Public methods = | |
| 136 | + = = | |
| 137 | + ==========================================================================*/ | |
| 138 | + | |
| 139 | +/***********************************************************************//** | |
| 140 | + * @brief Clear [INSTRUMENT] event bin | |
| 141 | + * | |
| 142 | + * Clears [INSTRUMENT] event bin by resetting all class members to an | |
| 143 | + * initial state. Any information that was present before will be lost. | |
| 144 | + ***************************************************************************/ | |
| 145 | +void GXXXEventBin::clear(void) | |
| 146 | +{ | |
| 147 | + // Free class members (base and derived classes, derived class first) | |
| 148 | + free_members(); | |
| 149 | + this->GEventBin::free_members(); | |
| 150 | + this->GEvent::free_members(); | |
| 151 | + | |
| 152 | + // Initialise members | |
| 153 | + this->GEvent::init_members(); | |
| 154 | + this->GEventBin::init_members(); | |
| 155 | + init_members(); | |
| 156 | + | |
| 157 | + // Return | |
| 158 | + return; | |
| 159 | +} | |
| 160 | + | |
| 161 | + | |
| 162 | +/***********************************************************************//** | |
| 163 | + * @brief Clone event bin | |
| 164 | + * | |
| 165 | + * @return Pointer to deep copy of [INSTRUMENT] event bin. | |
| 166 | + ***************************************************************************/ | |
| 167 | +GXXXEventBin* GXXXEventBin::clone(void) const | |
| 168 | +{ | |
| 169 | + return new GXXXEventBin(*this); | |
| 170 | +} | |
| 171 | + | |
| 172 | + | |
| 173 | +/***********************************************************************//** | |
| 174 | + * @brief Return size of event bin | |
| 175 | + * | |
| 176 | + * @return Size of event bin (sr MeV s) | |
| 177 | + * | |
| 178 | + * @todo Implement method. | |
| 179 | + ***************************************************************************/ | |
| 180 | +double GXXXEventBin::size(void) const | |
| 181 | +{ | |
| 182 | + // Initialise size | |
| 183 | + double size = 0.0; | |
| 184 | + | |
| 185 | + // TODO: Compute here the bin size of the event bin. | |
| 186 | + | |
| 187 | + // Return bin size | |
| 188 | + return size; | |
| 189 | +} | |
| 190 | + | |
| 191 | + | |
| 192 | +/***********************************************************************//** | |
| 193 | + * @brief Return error in number of counts | |
| 194 | + * | |
| 195 | + * @return Error in number of counts in event bin. | |
| 196 | + * | |
| 197 | + * Returns \f$\sqrt(counts+delta)\f$ as the uncertainty in the number of | |
| 198 | + * counts in the bin. Adding delta avoids uncertainties of 0 which will | |
| 199 | + * lead in the optimisation step to the exlusion of the corresponding bin. | |
| 200 | + * In the actual implementation delta=1e-50. | |
| 201 | + * | |
| 202 | + * @todo The choice of delta has been made somewhat arbitrary, mainly | |
| 203 | + * because the optimizer routines filter error^2 below 1e-100. | |
| 204 | + ***************************************************************************/ | |
| 205 | +double GXXXEventBin::error(void) const | |
| 206 | +{ | |
| 207 | + // Compute uncertainty | |
| 208 | + double error = std::sqrt(counts()+1.0e-50); | |
| 209 | + | |
| 210 | + // Return error | |
| 211 | + return error; | |
| 212 | +} | |
| 213 | + | |
| 214 | + | |
| 215 | +/***********************************************************************//** | |
| 216 | + * @brief Print event information | |
| 217 | + * | |
| 218 | + * @param[in] chatter Chattiness. | |
| 219 | + * @return String containing event information. | |
| 220 | + ***************************************************************************/ | |
| 221 | +std::string GXXXEventBin::print(const GChatter& chatter) const | |
| 222 | +{ | |
| 223 | + // Initialise result string | |
| 224 | + std::string result; | |
| 225 | + | |
| 226 | + // Continue only if chatter is not silent | |
| 227 | + if (chatter != SILENT) { | |
| 228 | + | |
| 229 | + // Append number of counts | |
| 230 | + result.append(gammalib::str(counts())); | |
| 231 | + | |
| 232 | + } // endif: chatter was not silent | |
| 233 | + | |
| 234 | + // Return result | |
| 235 | + return result; | |
| 236 | +} | |
| 237 | + | |
| 238 | + | |
| 239 | +/*========================================================================== | |
| 240 | + = = | |
| 241 | + = Private methods = | |
| 242 | + = = | |
| 243 | + ==========================================================================*/ | |
| 244 | + | |
| 245 | +/***********************************************************************//** | |
| 246 | + * @brief Initialise class members | |
| 247 | + * | |
| 248 | + * This method allocates memory for all event bin attributes and intialises | |
| 249 | + * the attributes to well defined initial values. | |
| 250 | + * | |
| 251 | + * The method assumes that on entry no memory is hold by the member pointers. | |
| 252 | + ***************************************************************************/ | |
| 253 | +void GXXXEventBin::init_members(void) | |
| 254 | +{ | |
| 255 | + // Allocate members | |
| 256 | + m_alloc = true; | |
| 257 | + m_index = -1; // Signals that event bin does not correspond to cube | |
| 258 | + m_dir = new GXXXInstDir; | |
| 259 | + m_time = new GTime; | |
| 260 | + m_energy = new GEnergy; | |
| 261 | + m_counts = new double; | |
| 262 | + | |
| 263 | + // Initialise members | |
| 264 | + m_dir->clear(); | |
| 265 | + m_time->clear(); | |
| 266 | + m_energy->clear(); | |
| 267 | + *m_counts = 0.0; | |
| 268 | + | |
| 269 | + // Return | |
| 270 | + return; | |
| 271 | +} | |
| 272 | + | |
| 273 | + | |
| 274 | +/***********************************************************************//** | |
| 275 | + * @brief Copy class members | |
| 276 | + * | |
| 277 | + * @param[in] bin [INSTRUMENT] event bin. | |
| 278 | + ***************************************************************************/ | |
| 279 | +void GXXXEventBin::copy_members(const GXXXEventBin& bin) | |
| 280 | +{ | |
| 281 | + // First de-allocate existing memory if needed | |
| 282 | + free_members(); | |
| 283 | + | |
| 284 | + // Copy members by cloning | |
| 285 | + m_dir = new GXXXInstDir(*bin.m_dir); | |
| 286 | + m_time = new GTime(*bin.m_time); | |
| 287 | + m_energy = new GEnergy(*bin.m_energy); | |
| 288 | + m_counts = new double(*bin.m_counts); | |
| 289 | + | |
| 290 | + // Copy non-pointer members | |
| 291 | + m_index = bin.m_index; | |
| 292 | + | |
| 293 | + // Signal memory allocation | |
| 294 | + m_alloc = true; | |
| 295 | + | |
| 296 | + // Return | |
| 297 | + return; | |
| 298 | +} | |
| 299 | + | |
| 300 | + | |
| 301 | +/***********************************************************************//** | |
| 302 | + * @brief Delete class members | |
| 303 | + * | |
| 304 | + * This method frees all memory of the class attributes and sets the member | |
| 305 | + * pointers to NULL. This method should only be called if new memory is | |
| 306 | + * allocated immediately afterwards (for example by cloning another event | |
| 307 | + * bin), or upon destruction of the object. | |
| 308 | + * | |
| 309 | + * Note that some logic has been implemented that frees only memory that also | |
| 310 | + * has indeed been allocated by the class. Thus if the class only serves as | |
| 311 | + * container to hold memory pointer allocated by someone else (for example | |
| 312 | + * the GXXXEventCube class), no memory is freed. | |
| 313 | + ***************************************************************************/ | |
| 314 | +void GXXXEventBin::free_members(void) | |
| 315 | +{ | |
| 316 | + // If memory was allocated then free members now | |
| 317 | + if (m_alloc) { | |
| 318 | + if (m_dir != NULL) delete m_dir; | |
| 319 | + if (m_time != NULL) delete m_time; | |
| 320 | + if (m_energy != NULL) delete m_energy; | |
| 321 | + if (m_counts != NULL) delete m_counts; | |
| 322 | + } | |
| 323 | + | |
| 324 | + // Signal member pointers as free | |
| 325 | + m_dir = NULL; | |
| 326 | + m_time = NULL; | |
| 327 | + m_energy = NULL; | |
| 328 | + m_counts = NULL; | |
| 329 | + | |
| 330 | + // Signal memory de-allocation | |
| 331 | + m_alloc = false; | |
| 332 | + | |
| 333 | + // Return | |
| 334 | + return; | |
| 335 | +} | ... | ... |
src/template/GXXXEventBin.hpp
0 → 100644
| 1 | +/*************************************************************************** | |
| 2 | + * GXXXEventBin.hpp - [INSTRUMENT] event bin class * | |
| 3 | + * ----------------------------------------------------------------------- * | |
| 4 | + * copyright (C) [YEAR] by [AUTHOR] * | |
| 5 | + * ----------------------------------------------------------------------- * | |
| 6 | + * * | |
| 7 | + * This program is free software: you can redistribute it and/or modify * | |
| 8 | + * it under the terms of the GNU General Public License as published by * | |
| 9 | + * the Free Software Foundation, either version 3 of the License, or * | |
| 10 | + * (at your option) any later version. * | |
| 11 | + * * | |
| 12 | + * This program is distributed in the hope that it will be useful, * | |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
| 15 | + * GNU General Public License for more details. * | |
| 16 | + * * | |
| 17 | + * You should have received a copy of the GNU General Public License * | |
| 18 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. * | |
| 19 | + * * | |
| 20 | + ***************************************************************************/ | |
| 21 | +/** | |
| 22 | + * @file GXXXEventBin.hpp | |
| 23 | + * @brief [INSTRUMENT] event bin class definition | |
| 24 | + * @author [AUTHOR] | |
| 25 | + */ | |
| 26 | + | |
| 27 | +#ifndef GXXXEVENTBIN_HPP | |
| 28 | +#define GXXXEVENTBIN_HPP | |
| 29 | + | |
| 30 | +/* __ Includes ___________________________________________________________ */ | |
| 31 | +#include "GEventBin.hpp" | |
| 32 | +#include "GEnergy.hpp" | |
| 33 | +#include "GTime.hpp" | |
| 34 | +#include "GXXXInstDir.hpp" | |
| 35 | + | |
| 36 | + | |
| 37 | +/***********************************************************************//** | |
| 38 | + * @class GXXXEventBin | |
| 39 | + * | |
| 40 | + * @brief [INSTRUMENT] event bin class | |
| 41 | + * | |
| 42 | + * This class defines an event bin of the [INSTRUMENT] event cube. | |
| 43 | + * | |
| 44 | + * Since many event bins share the same attributes (for example many bins | |
| 45 | + * will actually have the same energy), it would be a waste of memory to | |
| 46 | + * store all bin attributes together with the bin. Therefore, the | |
| 47 | + * GXXXEventBin class implement it's own memory management. Either the | |
| 48 | + * class allocates memory for all attributes, or it takes pointers to | |
| 49 | + * GXXXEventCube class member that store the information in an efficient | |
| 50 | + * way. | |
| 51 | + * | |
| 52 | + * The data member m_alloc signals in which mode the bin operates. I true, | |
| 53 | + * GXXXEventBin has allocated itself the memory for all attributes, and | |
| 54 | + * hence has to take care about the memory allocation upon destruction. | |
| 55 | + * Otherwise the pointers are just released. | |
| 56 | + ***************************************************************************/ | |
| 57 | +class GXXXEventBin : public GEventBin { | |
| 58 | + | |
| 59 | + // Friend classes | |
| 60 | + friend class GXXXEventCube; | |
| 61 | + | |
| 62 | +public: | |
| 63 | + // Constructors and destructors | |
| 64 | + GXXXEventBin(void); | |
| 65 | + GXXXEventBin(const GXXXEventBin& bin); | |
| 66 | + virtual ~GXXXEventBin(void); | |
| 67 | + | |
| 68 | + // Operators | |
| 69 | + virtual GXXXEventBin& operator=(const GXXXEventBin& bin); | |
| 70 | + | |
| 71 | + // Implemented pure virtual base class methods | |
| 72 | + virtual void clear(void); | |
| 73 | + virtual GXXXEventBin* clone(void) const; | |
| 74 | + virtual std::string classname(void) const; | |
| 75 | + virtual double size(void) const; | |
| 76 | + virtual const GXXXInstDir& dir(void) const; | |
| 77 | + virtual const GEnergy& energy(void) const; | |
| 78 | + virtual const GTime& time(void) const; | |
| 79 | + virtual double counts(void) const; | |
| 80 | + virtual double error(void) const; | |
| 81 | + virtual void counts(const double& counts); | |
| 82 | + virtual std::string print(const GChatter& chatter = NORMAL) const; | |
| 83 | + | |
| 84 | + // Other methods | |
| 85 | + // TODO: Add any further methods that are needed | |
| 86 | + | |
| 87 | +protected: | |
| 88 | + // Protected methods | |
| 89 | + void init_members(void); | |
| 90 | + void copy_members(const GXXXEventBin& bin); | |
| 91 | + void free_members(void); | |
| 92 | + | |
| 93 | + // Protected members | |
| 94 | + bool m_alloc; //!< Signals proper memory allocation | |
| 95 | + int m_index; //!< Dataspace index | |
| 96 | + double* m_counts; //!< Pointer to number of counts | |
| 97 | + GXXXInstDir* m_dir; //!< Pointer to bin direction | |
| 98 | + GTime* m_time; //!< Pointer to bin time | |
| 99 | + GEnergy* m_energy; //!< Pointer to bin energy | |
| 100 | +}; | |
| 101 | + | |
| 102 | + | |
| 103 | +/***********************************************************************//** | |
| 104 | + * @brief Return class name | |
| 105 | + * | |
| 106 | + * @return String containing the class name ("GXXXEventBin"). | |
| 107 | + ***************************************************************************/ | |
| 108 | +inline | |
| 109 | +std::string GXXXEventBin::classname(void) const | |
| 110 | +{ | |
| 111 | + return ("GXXXEventBin"); | |
| 112 | +} | |
| 113 | + | |
| 114 | + | |
| 115 | +/***********************************************************************//** | |
| 116 | + * @brief Return instrument direction | |
| 117 | + * | |
| 118 | + * @return Instrument direction. | |
| 119 | + * | |
| 120 | + * Returns the instrument direction of the event bin. | |
| 121 | + ***************************************************************************/ | |
| 122 | +inline | |
| 123 | +const GXXXInstDir& GXXXEventBin::dir(void) const | |
| 124 | +{ | |
| 125 | + return (*m_dir); | |
| 126 | +} | |
| 127 | + | |
| 128 | + | |
| 129 | +/***********************************************************************//** | |
| 130 | + * @brief Return energy | |
| 131 | + * | |
| 132 | + * @return Energy. | |
| 133 | + * | |
| 134 | + * Returns the energy of the event bin. | |
| 135 | + ***************************************************************************/ | |
| 136 | +inline | |
| 137 | +const GEnergy& GXXXEventBin::energy(void) const | |
| 138 | +{ | |
| 139 | + return (*m_energy); | |
| 140 | +} | |
| 141 | + | |
| 142 | + | |
| 143 | +/***********************************************************************//** | |
| 144 | + * @brief Return time | |
| 145 | + * | |
| 146 | + * @return Time. | |
| 147 | + * | |
| 148 | + * Returns the time of the event bin. | |
| 149 | + ***************************************************************************/ | |
| 150 | +inline | |
| 151 | +const GTime& GXXXEventBin::time(void) const | |
| 152 | +{ | |
| 153 | + return (*m_time); | |
| 154 | +} | |
| 155 | + | |
| 156 | + | |
| 157 | +/***********************************************************************//** | |
| 158 | + * @brief Return number of counts | |
| 159 | + * | |
| 160 | + * @return Number of counts. | |
| 161 | + * | |
| 162 | + * Returns the number of counts in the event bin. | |
| 163 | + ***************************************************************************/ | |
| 164 | +inline | |
| 165 | +double GXXXEventBin::counts(void) const | |
| 166 | +{ | |
| 167 | + return (*m_counts); | |
| 168 | +} | |
| 169 | + | |
| 170 | + | |
| 171 | +/***********************************************************************//** | |
| 172 | + * @brief Set number of counts | |
| 173 | + * | |
| 174 | + * @param[in] counts Number of counts. | |
| 175 | + * | |
| 176 | + * Set the number of counts in the event bin. | |
| 177 | + ***************************************************************************/ | |
| 178 | +inline | |
| 179 | +void GXXXEventBin::counts(const double& counts) | |
| 180 | +{ | |
| 181 | + *m_counts = counts; | |
| 182 | + return; | |
| 183 | +} | |
| 184 | + | |
| 185 | +#endif /* GXXXEVENTBIN_HPP */ | ... | ... |
src/template/GXXXEventBin.i
0 → 100644
| 1 | +/*************************************************************************** | |
| 2 | + * GXXXEventBin.i - [INSTRUMENT] event bin class * | |
| 3 | + * ----------------------------------------------------------------------- * | |
| 4 | + * copyright (C) [YEAR] by [AUTHOR] * | |
| 5 | + * ----------------------------------------------------------------------- * | |
| 6 | + * * | |
| 7 | + * This program is free software: you can redistribute it and/or modify * | |
| 8 | + * it under the terms of the GNU General Public License as published by * | |
| 9 | + * the Free Software Foundation, either version 3 of the License, or * | |
| 10 | + * (at your option) any later version. * | |
| 11 | + * * | |
| 12 | + * This program is distributed in the hope that it will be useful, * | |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
| 15 | + * GNU General Public License for more details. * | |
| 16 | + * * | |
| 17 | + * You should have received a copy of the GNU General Public License * | |
| 18 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. * | |
| 19 | + * * | |
| 20 | + ***************************************************************************/ | |
| 21 | +/** | |
| 22 | + * @file GXXXEventBin.hpp | |
| 23 | + * @brief [INSTRUMENT] event bin class implementation | |
| 24 | + * @author [AUTHOR] | |
| 25 | + */ | |
| 26 | +%{ | |
| 27 | +/* Put headers and other declarations here that are needed for compilation */ | |
| 28 | +#include "GXXXEventBin.hpp" | |
| 29 | +%} | |
| 30 | + | |
| 31 | + | |
| 32 | +/***********************************************************************//** | |
| 33 | + * @class GXXXEventBin | |
| 34 | + * | |
| 35 | + * @brief [INSTRUMENT] event bin class | |
| 36 | + ***************************************************************************/ | |
| 37 | +class GXXXEventBin : public GEventBin { | |
| 38 | + | |
| 39 | +public: | |
| 40 | + // Constructors and destructors | |
| 41 | + GXXXEventBin(void); | |
| 42 | + GXXXEventBin(const GXXXEventBin& bin); | |
| 43 | + virtual ~GXXXEventBin(void); | |
| 44 | + | |
| 45 | + // Implemented pure virtual base class methods | |
| 46 | + virtual void clear(void); | |
| 47 | + virtual GXXXEventBin* clone(void) const; | |
| 48 | + virtual std::string classname(void) const; | |
| 49 | + virtual double size(void) const; | |
| 50 | + virtual const GXXXInstDir& dir(void) const; | |
| 51 | + virtual const GEnergy& energy(void) const; | |
| 52 | + virtual const GTime& time(void) const; | |
| 53 | + virtual double counts(void) const; | |
| 54 | + virtual double error(void) const; | |
| 55 | + virtual void counts(const double& counts); | |
| 56 | + | |
| 57 | + // Other methods | |
| 58 | + // TODO: Copy methods from GXXXEventBin.hpp file | |
| 59 | +}; | |
| 60 | + | |
| 61 | + | |
| 62 | +/***********************************************************************//** | |
| 63 | + * @brief GXXXEventBin class extension | |
| 64 | + ***************************************************************************/ | |
| 65 | +%extend GXXXEventBin { | |
| 66 | + GXXXEventBin copy() { | |
| 67 | + return (*self); | |
| 68 | + } | |
| 69 | +}; | ... | ... |
src/template/GXXXEventCube.cpp
0 → 100644
| 1 | +/*************************************************************************** | |
| 2 | + * GXXXEventCube.cpp - [INSTRUMENT] event bin container class * | |
| 3 | + * ----------------------------------------------------------------------- * | |
| 4 | + * copyright (C) [YEAR] by [AUTHOR] * | |
| 5 | + * ----------------------------------------------------------------------- * | |
| 6 | + * * | |
| 7 | + * This program is free software: you can redistribute it and/or modify * | |
| 8 | + * it under the terms of the GNU General Public License as published by * | |
| 9 | + * the Free Software Foundation, either version 3 of the License, or * | |
| 10 | + * (at your option) any later version. * | |
| 11 | + * * | |
| 12 | + * This program is distributed in the hope that it will be useful, * | |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
| 15 | + * GNU General Public License for more details. * | |
| 16 | + * * | |
| 17 | + * You should have received a copy of the GNU General Public License * | |
| 18 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. * | |
| 19 | + * * | |
| 20 | + ***************************************************************************/ | |
| 21 | +/** | |
| 22 | + * @file GXXXEventCube.hpp | |
| 23 | + * @brief [INSTRUMENT] event bin container class implementation | |
| 24 | + * @author [AUTHOR] | |
| 25 | + */ | |
| 26 | + | |
| 27 | +/* __ Includes ___________________________________________________________ */ | |
| 28 | +#ifdef HAVE_CONFIG_H | |
| 29 | +#include <config.h> | |
| 30 | +#endif | |
| 31 | +#include "GXXXEventCube.hpp" | |
| 32 | + | |
| 33 | +/* __ Method name definitions ____________________________________________ */ | |
| 34 | +#define G_NAXIS "GXXXEventCube::naxis(int)" | |
| 35 | +#define G_SET_ENERGIES "GXXXEventCube::set_energies()" | |
| 36 | +#define G_SET_TIMES "GXXXEventCube::set_times()" | |
| 37 | +#define G_SET_BIN "GXXXEventCube::set_bin(int&)" | |
| 38 | + | |
| 39 | +/* __ Macros _____________________________________________________________ */ | |
| 40 | + | |
| 41 | +/* __ Coding definitions _________________________________________________ */ | |
| 42 | + | |
| 43 | +/* __ Debug definitions __________________________________________________ */ | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | +/*========================================================================== | |
| 48 | + = = | |
| 49 | + = Constructors/destructors = | |
| 50 | + = = | |
| 51 | + ==========================================================================*/ | |
| 52 | + | |
| 53 | +/***********************************************************************//** | |
| 54 | + * @brief Void constructor | |
| 55 | + * | |
| 56 | + * Constructs an empty [INSTRUMENT] event cube. | |
| 57 | + ***************************************************************************/ | |
| 58 | +GXXXEventCube::GXXXEventCube(void) : GEventCube() | |
| 59 | +{ | |
| 60 | + // Initialise members | |
| 61 | + init_members(); | |
| 62 | + | |
| 63 | + // Return | |
| 64 | + return; | |
| 65 | +} | |
| 66 | + | |
| 67 | + | |
| 68 | +/***********************************************************************//** | |
| 69 | + * @brief Load constructor | |
| 70 | + * | |
| 71 | + * @param[in] filename [INSTRUMENT] event cube FITS filename. | |
| 72 | + * | |
| 73 | + * Construct a [INSTRUMENT] event cube by loading it from a FITS file. | |
| 74 | + ***************************************************************************/ | |
| 75 | +GXXXEventCube::GXXXEventCube(const GFilename& filename) : GEventCube() | |
| 76 | +{ | |
| 77 | + // Initialise members | |
| 78 | + init_members(); | |
| 79 | + | |
| 80 | + // Load event cube | |
| 81 | + load(filename); | |
| 82 | + | |
| 83 | + // Return | |
| 84 | + return; | |
| 85 | +} | |
| 86 | + | |
| 87 | + | |
| 88 | +/***********************************************************************//** | |
| 89 | + * @brief Copy constructor | |
| 90 | + * | |
| 91 | + * @param[in] cube [INSTRUMENT] event cube. | |
| 92 | + ***************************************************************************/ | |
| 93 | +GXXXEventCube::GXXXEventCube(const GXXXEventCube& cube) : GEventCube(cube) | |
| 94 | +{ | |
| 95 | + // Initialise members | |
| 96 | + init_members(); | |
| 97 | + | |
| 98 | + // Copy members | |
| 99 | + copy_members(cube); | |
| 100 | + | |
| 101 | + // Return | |
| 102 | + return; | |
| 103 | +} | |
| 104 | + | |
| 105 | + | |
| 106 | +/***********************************************************************//** | |
| 107 | + * @brief Destructor | |
| 108 | + ***************************************************************************/ | |
| 109 | +GXXXEventCube::~GXXXEventCube(void) | |
| 110 | +{ | |
| 111 | + // Free members | |
| 112 | + free_members(); | |
| 113 | + | |
| 114 | + // Return | |
| 115 | + return; | |
| 116 | +} | |
| 117 | + | |
| 118 | + | |
| 119 | +/*========================================================================== | |
| 120 | + = = | |
| 121 | + = Operators = | |
| 122 | + = = | |
| 123 | + ==========================================================================*/ | |
| 124 | + | |
| 125 | +/***********************************************************************//** | |
| 126 | + * @brief Assignment operator | |
| 127 | + * | |
| 128 | + * @param[in] cube [INSTRUMENT] event cube. | |
| 129 | + * @return [INSTRUMENT] event cube. | |
| 130 | + ***************************************************************************/ | |
| 131 | +GXXXEventCube& GXXXEventCube::operator=(const GXXXEventCube& cube) | |
| 132 | +{ | |
| 133 | + // Execute only if object is not identical | |
| 134 | + if (this != &cube) { | |
| 135 | + | |
| 136 | + // Copy base class members | |
| 137 | + this->GEventCube::operator=(cube); | |
| 138 | + | |
| 139 | + // Free members | |
| 140 | + free_members(); | |
| 141 | + | |
| 142 | + // Initialise members | |
| 143 | + init_members(); | |
| 144 | + | |
| 145 | + // Copy members | |
| 146 | + copy_members(cube); | |
| 147 | + | |
| 148 | + } // endif: object was not identical | |
| 149 | + | |
| 150 | + // Return this object | |
| 151 | + return *this; | |
| 152 | +} | |
| 153 | + | |
| 154 | + | |
| 155 | +/***********************************************************************//** | |
| 156 | + * @brief Event bin access operator | |
| 157 | + * | |
| 158 | + * @param[in] index Event index [0,...,size()-1]. | |
| 159 | + * @return Pointer to event bin. | |
| 160 | + * | |
| 161 | + * Returns pointer to an event bin. Note that the returned pointer is in | |
| 162 | + * fact always the same, but the method sets the pointers within the | |
| 163 | + * event bin so that they point to the appropriate information. | |
| 164 | + ***************************************************************************/ | |
| 165 | +GXXXEventBin* GXXXEventCube::operator[](const int& index) | |
| 166 | +{ | |
| 167 | + // Set event bin | |
| 168 | + set_bin(index); | |
| 169 | + | |
| 170 | + // Return pointer | |
| 171 | + return (&m_bin); | |
| 172 | +} | |
| 173 | + | |
| 174 | + | |
| 175 | +/***********************************************************************//** | |
| 176 | + * @brief Event bin access operator (const version) | |
| 177 | + * | |
| 178 | + * @param[in] index Event index [0,...,size()-1]. | |
| 179 | + * @return Const pointer to event bin. | |
| 180 | + * | |
| 181 | + * Returns pointer to an event bin. Note that the returned pointer is in | |
| 182 | + * fact always the same, but the method sets the pointers within the | |
| 183 | + * event bin so that they point to the appropriate information. | |
| 184 | + ***************************************************************************/ | |
| 185 | +const GXXXEventBin* GXXXEventCube::operator[](const int& index) const | |
| 186 | +{ | |
| 187 | + // Set event bin (circumvent const correctness) | |
| 188 | + ((GXXXEventCube*)this)->set_bin(index); | |
| 189 | + | |
| 190 | + // Return pointer | |
| 191 | + return (&m_bin); | |
| 192 | +} | |
| 193 | + | |
| 194 | + | |
| 195 | +/*========================================================================== | |
| 196 | + = = | |
| 197 | + = Public methods = | |
| 198 | + = = | |
| 199 | + ==========================================================================*/ | |
| 200 | + | |
| 201 | +/***********************************************************************//** | |
| 202 | + * @brief Clear [INSTRUMENT] event cube | |
| 203 | + * | |
| 204 | + * Clears [INSTRUMENT] event cube by resetting all class members to an | |
| 205 | + * initial state. Any information that was present before will be lost. | |
| 206 | + ***************************************************************************/ | |
| 207 | +void GXXXEventCube::clear(void) | |
| 208 | +{ | |
| 209 | + // Free class members (base and derived classes, derived class first) | |
| 210 | + free_members(); | |
| 211 | + this->GEventCube::free_members(); | |
| 212 | + this->GEvents::free_members(); | |
| 213 | + | |
| 214 | + // Initialise members | |
| 215 | + this->GEvents::init_members(); | |
| 216 | + this->GEventCube::init_members(); | |
| 217 | + init_members(); | |
| 218 | + | |
| 219 | + // Return | |
| 220 | + return; | |
| 221 | +} | |
| 222 | + | |
| 223 | + | |
| 224 | +/***********************************************************************//** | |
| 225 | + * @brief Clone event cube | |
| 226 | + * | |
| 227 | + * @return Pointer to deep copy of [INSTRUMENT] event cube. | |
| 228 | + ***************************************************************************/ | |
| 229 | +GXXXEventCube* GXXXEventCube::clone(void) const | |
| 230 | +{ | |
| 231 | + return new GXXXEventCube(*this); | |
| 232 | +} | |
| 233 | + | |
| 234 | + | |
| 235 | +/***********************************************************************//** | |
| 236 | + * @brief Return number of bins in event cube | |
| 237 | + * | |
| 238 | + * @return Number of bins in event cube. | |
| 239 | + * | |
| 240 | + * @todo Implement method. | |
| 241 | + ***************************************************************************/ | |
| 242 | +int GXXXEventCube::size(void) const | |
| 243 | +{ | |
| 244 | + // Compute number of bins | |
| 245 | + // TODO: Implement computation | |
| 246 | + int nbins = 0; | |
| 247 | + | |
| 248 | + // Return number of bins | |
| 249 | + return nbins; | |
| 250 | +} | |
| 251 | + | |
| 252 | + | |
| 253 | +/***********************************************************************//** | |
| 254 | + * @brief Return dimension of event cube | |
| 255 | + * | |
| 256 | + * @return Number of dimensions in event cube. | |
| 257 | + * | |
| 258 | + * @todo Implement method. | |
| 259 | + ***************************************************************************/ | |
| 260 | +int GXXXEventCube::dim(void) const | |
| 261 | +{ | |
| 262 | + // Compute dimension | |
| 263 | + // TODO: Implement computation | |
| 264 | + int dim = 0; | |
| 265 | + | |
| 266 | + // Return dimension | |
| 267 | + return dim; | |
| 268 | +} | |
| 269 | + | |
| 270 | + | |
| 271 | +/***********************************************************************//** | |
| 272 | + * @brief Return number of bins in axis | |
| 273 | + * | |
| 274 | + * @param[in] axis Axis [0,...,dim()-1]. | |
| 275 | + * @return Number of bins in axis. | |
| 276 | + * | |
| 277 | + * @exception GException::out_of_range | |
| 278 | + * Axis is out of range. | |
| 279 | + * | |
| 280 | + * Returns the number of bins along a given event cube @p axis. | |
| 281 | + ***************************************************************************/ | |
| 282 | +int GXXXEventCube::naxis(const int& axis) const | |
| 283 | +{ | |
| 284 | + // Optionally check if the axis is valid | |
| 285 | + #if defined(G_RANGE_CHECK) | |
| 286 | + if (axis < 0 || axis >= dim()) { | |
| 287 | + throw GException::out_of_range(G_NAXIS, "[INSTRUMENT] event cube axis", | |
| 288 | + axis, dim()); | |
| 289 | + } | |
| 290 | + #endif | |
| 291 | + | |
| 292 | + // Set result | |
| 293 | + // TODO: Implement computation | |
| 294 | + int naxis = 0; | |
| 295 | + | |
| 296 | + // Return result | |
| 297 | + return naxis; | |
| 298 | +} | |
| 299 | + | |
| 300 | + | |
| 301 | +/***********************************************************************//** | |
| 302 | + * @brief Load [INSTRUMENT] event cube from FITS file | |
| 303 | + * | |
| 304 | + * @param[in] filename FITS file name. | |
| 305 | + * | |
| 306 | + * The method clears the object before loading, thus any events residing in | |
| 307 | + * the object before loading will be lost. | |
| 308 | + ***************************************************************************/ | |
| 309 | +void GXXXEventCube::load(const GFilename& filename) | |
| 310 | +{ | |
| 311 | + // Open FITS file | |
| 312 | + GFits fits(filename); | |
| 313 | + | |
| 314 | + // Read event cube from FITS file | |
| 315 | + read(fits); | |
| 316 | + | |
| 317 | + // Close FITS file | |
| 318 | + fits.close(); | |
| 319 | + | |
| 320 | + // Return | |
| 321 | + return; | |
| 322 | +} | |
| 323 | + | |
| 324 | + | |
| 325 | +/***********************************************************************//** | |
| 326 | + * @brief Save [INSTRUMENT] event cube into FITS file | |
| 327 | + * | |
| 328 | + * @param[in] filename FITS file name. | |
| 329 | + * @param[in] clobber Overwrite existing FITS file? | |
| 330 | + * | |
| 331 | + * Saves the [INSTRUMENT] event cube into a FITS file. | |
| 332 | + ***************************************************************************/ | |
| 333 | +void GXXXEventCube::save(const GFilename& filename, const bool& clobber) const | |
| 334 | +{ | |
| 335 | + // Create empty FITS file | |
| 336 | + GFits fits; | |
| 337 | + | |
| 338 | + // Write event cube into FITS file | |
| 339 | + write(fits); | |
| 340 | + | |
| 341 | + // Save FITS file | |
| 342 | + fits.saveto(filename, clobber); | |
| 343 | + | |
| 344 | + // Close FITS file | |
| 345 | + fits.close(); | |
| 346 | + | |
| 347 | + // Return | |
| 348 | + return; | |
| 349 | +} | |
| 350 | + | |
| 351 | + | |
| 352 | +/***********************************************************************//** | |
| 353 | + * @brief Read [INSTRUMENT] event cube from FITS file | |
| 354 | + * | |
| 355 | + * @param[in] fits FITS file. | |
| 356 | + * | |
| 357 | + * Reads a [INSTRUMENT] event cube from a FITS file. | |
| 358 | + * | |
| 359 | + * @todo Implement method. | |
| 360 | + ***************************************************************************/ | |
| 361 | +void GXXXEventCube::read(const GFits& fits) | |
| 362 | +{ | |
| 363 | + // Clear object | |
| 364 | + clear(); | |
| 365 | + | |
| 366 | + // TODO: Here you have to implement the interface between the class and | |
| 367 | + // the event cube FITS file. | |
| 368 | + | |
| 369 | + // Return | |
| 370 | + return; | |
| 371 | +} | |
| 372 | + | |
| 373 | + | |
| 374 | +/***********************************************************************//** | |
| 375 | + * @brief Write [INSTRUMENT] event cube into FITS file. | |
| 376 | + * | |
| 377 | + * @param[in] file FITS file. | |
| 378 | + * | |
| 379 | + * Writes the [INSTRUMENT] event cube into a FITS file. | |
| 380 | + ***************************************************************************/ | |
| 381 | +void GXXXEventCube::write(GFits& file) const | |
| 382 | +{ | |
| 383 | + // TODO: Here you have to implement the interface between the class and | |
| 384 | + // the event cube FITS file. | |
| 385 | + | |
| 386 | + // Return | |
| 387 | + return; | |
| 388 | +} | |
| 389 | + | |
| 390 | + | |
| 391 | +/***********************************************************************//** | |
| 392 | + * @brief Return number of events in cube | |
| 393 | + * | |
| 394 | + * @return Number of events in event cube. | |
| 395 | + * | |
| 396 | + * This method returns the number of events in the event cube rounded to the | |
| 397 | + * nearest integer. | |
| 398 | + * | |
| 399 | + * @todo Implement method. | |
| 400 | + ***************************************************************************/ | |
| 401 | +int GXXXEventCube::number(void) const | |
| 402 | +{ | |
| 403 | + // Initialise result | |
| 404 | + double number = 0.0; | |
| 405 | + | |
| 406 | + // TODO: Here you have to implement the computation of the number of | |
| 407 | + // events in the cube. | |
| 408 | + | |
| 409 | + // Return | |
| 410 | + return int(number+0.5); | |
| 411 | +} | |
| 412 | + | |
| 413 | + | |
| 414 | +/***********************************************************************//** | |
| 415 | + * @brief Print [INSTRUMENT] event cube information | |
| 416 | + * | |
| 417 | + * @param[in] chatter Chattiness. | |
| 418 | + * @return String containing [INSTRUMENT] event cube information. | |
| 419 | + ***************************************************************************/ | |
| 420 | +std::string GXXXEventCube::print(const GChatter& chatter) const | |
| 421 | +{ | |
| 422 | + // Initialise result string | |
| 423 | + std::string result; | |
| 424 | + | |
| 425 | + // Continue only if chatter is not silent | |
| 426 | + if (chatter != SILENT) { | |
| 427 | + | |
| 428 | + // Append header | |
| 429 | + result.append("=== GXXXEventCube ==="); | |
| 430 | + | |
| 431 | + // Append information | |
| 432 | + result.append("\n"+gammalib::parformat("Number of events")); | |
| 433 | + result.append(gammalib::str(number())); | |
| 434 | + result.append("\n"+gammalib::parformat("Number of elements")); | |
| 435 | + result.append(gammalib::str(size())); | |
| 436 | + result.append("\n"+gammalib::parformat("Energy range")); | |
| 437 | + result.append(gammalib::str(emin().MeV())+" - "); | |
| 438 | + result.append(gammalib::str(emax().MeV())+" MeV"); | |
| 439 | + result.append("\n"+gammalib::parformat("Mean energy")); | |
| 440 | + result.append(m_energy.print(chatter)); | |
| 441 | + result.append("\n"+gammalib::parformat("Energy bin width")); | |
| 442 | + result.append(m_ewidth.print(chatter)); | |
| 443 | + result.append("\n"+gammalib::parformat("Ontime")); | |
| 444 | + result.append(gammalib::str(m_ontime)+" s"); | |
| 445 | + result.append("\n"+gammalib::parformat("Time interval")); | |
| 446 | + result.append(gammalib::str(tstart().jd())+" - "); | |
| 447 | + result.append(gammalib::str(tstop().jd())+" Julian days"); | |
| 448 | + result.append("\n"+gammalib::parformat("Mean time")); | |
| 449 | + result.append(m_time.print(chatter)); | |
| 450 | + | |
| 451 | + // Append additional information | |
| 452 | + // TODO: Add code to append any additional information that might | |
| 453 | + // be relevant. | |
| 454 | + | |
| 455 | + } // endif: chatter was not silent | |
| 456 | + | |
| 457 | + // Return result | |
| 458 | + return result; | |
| 459 | +} | |
| 460 | + | |
| 461 | + | |
| 462 | +/*========================================================================== | |
| 463 | + = = | |
| 464 | + = Private methods = | |
| 465 | + = = | |
| 466 | + ==========================================================================*/ | |
| 467 | + | |
| 468 | +/***********************************************************************//** | |
| 469 | + * @brief Initialise class members | |
| 470 | + ***************************************************************************/ | |
| 471 | +void GXXXEventCube::init_members(void) | |
| 472 | +{ | |
| 473 | + // Initialise members | |
| 474 | + m_bin.clear(); | |
| 475 | + m_time.clear(); | |
| 476 | + m_ontime = 0.0; | |
| 477 | + m_energy.clear(); | |
| 478 | + m_ewidth.clear(); | |
| 479 | + | |
| 480 | + // Prepare event bin | |
| 481 | + init_bin(); | |
| 482 | + | |
| 483 | + // Return | |
| 484 | + return; | |
| 485 | +} | |
| 486 | + | |
| 487 | + | |
| 488 | +/***********************************************************************//** | |
| 489 | + * @brief Copy class members | |
| 490 | + * | |
| 491 | + * @param[in] cube [INSTRUMENT] event cube. | |
| 492 | + * | |
| 493 | + * This method copies the class members from another event cube in the actual | |
| 494 | + * object. It also prepares the event bin member that will be returned in | |
| 495 | + * case of an operator access to the class. | |
| 496 | + ***************************************************************************/ | |
| 497 | +void GXXXEventCube::copy_members(const GXXXEventCube& cube) | |
| 498 | +{ | |
| 499 | + // Copy members. Note that the event bin is not copied as it will | |
| 500 | + // be initialised later. The event bin serves just as a container of | |
| 501 | + // pointers, hence we do not want to copy over the pointers from the | |
| 502 | + // original class. | |
| 503 | + m_time = cube.m_time; | |
| 504 | + m_ontime = cube.m_ontime; | |
| 505 | + m_energy = cube.m_energy; | |
| 506 | + m_ewidth = cube.m_ewidth; | |
| 507 | + | |
| 508 | + // Prepare event bin | |
| 509 | + init_bin(); | |
| 510 | + | |
| 511 | + // Return | |
| 512 | + return; | |
| 513 | +} | |
| 514 | + | |
| 515 | + | |
| 516 | +/***********************************************************************//** | |
| 517 | + * @brief Delete class members | |
| 518 | + ***************************************************************************/ | |
| 519 | +void GXXXEventCube::free_members(void) | |
| 520 | +{ | |
| 521 | + // Return | |
| 522 | + return; | |
| 523 | +} | |
| 524 | + | |
| 525 | + | |
| 526 | +/***********************************************************************//** | |
| 527 | + * @brief Initialise event bin | |
| 528 | + * | |
| 529 | + * Initialises the event bin. The event bin is cleared and all fixed pointers | |
| 530 | + * are set. Only the m_counts and the m_solidangle member of the event bin | |
| 531 | + * will be set to NULL, but these will be set by the set_bin() method | |
| 532 | + * which is called before any event bin access. | |
| 533 | + ***************************************************************************/ | |
| 534 | +void GXXXEventCube::init_bin(void) | |
| 535 | +{ | |
| 536 | + // Prepare event bin | |
| 537 | + m_bin.free_members(); | |
| 538 | + m_bin.m_counts = NULL; //!< Will be set by set_bin method | |
| 539 | + m_bin.m_dir = &m_dir; //!< Content will be set by set_bin method | |
| 540 | + m_bin.m_time = &m_time; //!< Fixed content | |
| 541 | + m_bin.m_energy = &m_energy; //!< Fixed content | |
| 542 | + | |
| 543 | + // Return | |
| 544 | + return; | |
| 545 | +} | |
| 546 | + | |
| 547 | + | |
| 548 | +/***********************************************************************//** | |
| 549 | + * @brief Set event bin | |
| 550 | + * | |
| 551 | + * @param[in] index Event index [0,...,size()-1]. | |
| 552 | + * | |
| 553 | + * @exception GException::out_of_range | |
| 554 | + * Event index is outside valid range. | |
| 555 | + * | |
| 556 | + * Sets the pointers of the event bin to the event cube cell that corresponds | |
| 557 | + * to the specified @p index. | |
| 558 | + * | |
| 559 | + * The event bin is in fact physically stored in the event cube, and only a | |
| 560 | + * single event bin is indeed allocated. This method sets up the pointers in | |
| 561 | + * the event bin so that a client can easily access the information of | |
| 562 | + * individual bins as if they were stored in an array. | |
| 563 | + ***************************************************************************/ | |
| 564 | +void GXXXEventCube::set_bin(const int& index) | |
| 565 | +{ | |
| 566 | + // Optionally check if the index is valid | |
| 567 | + #if defined(G_RANGE_CHECK) | |
| 568 | + if (index < 0 || index >= size()) { | |
| 569 | + throw GException::out_of_range(G_SET_BIN, index, 0, size()-1); | |
| 570 | + } | |
| 571 | + #endif | |
| 572 | + | |
| 573 | + // Set bin index | |
| 574 | + m_bin.m_index = index; | |
| 575 | + | |
| 576 | + // TODO: Set here the pointers of the GXXXEventBin to the event cube | |
| 577 | + // cell that corresponds to the specified index. | |
| 578 | + | |
| 579 | + // Return | |
| 580 | + return; | |
| 581 | +} | ... | ... |
src/template/GXXXEventCube.hpp
0 → 100644
| 1 | +/*************************************************************************** | |
| 2 | + * GXXXEventCube.hpp - [INSTRUMENT] event cube class * | |
| 3 | + * ----------------------------------------------------------------------- * | |
| 4 | + * copyright (C) [YEAR] by [AUTHOR] * | |
| 5 | + * ----------------------------------------------------------------------- * | |
| 6 | + * * | |
| 7 | + * This program is free software: you can redistribute it and/or modify * | |
| 8 | + * it under the terms of the GNU General Public License as published by * | |
| 9 | + * the Free Software Foundation, either version 3 of the License, or * | |
| 10 | + * (at your option) any later version. * | |
| 11 | + * * | |
| 12 | + * This program is distributed in the hope that it will be useful, * | |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
| 15 | + * GNU General Public License for more details. * | |
| 16 | + * * | |
| 17 | + * You should have received a copy of the GNU General Public License * | |
| 18 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. * | |
| 19 | + * * | |
| 20 | + ***************************************************************************/ | |
| 21 | +/** | |
| 22 | + * @file GXXXEventCube.hpp | |
| 23 | + * @brief [INSTRUMENT] event bin container class definition | |
| 24 | + * @author [AUTHOR] | |
| 25 | + */ | |
| 26 | + | |
| 27 | +#ifndef GXXXEVENTCUBE_HPP | |
| 28 | +#define GXXXEVENTCUBE_HPP | |
| 29 | + | |
| 30 | +/* __ Includes ___________________________________________________________ */ | |
| 31 | +#include <string> | |
| 32 | +#include <vector> | |
| 33 | +#include "GEventCube.hpp" | |
| 34 | +#include "GXXXEventBin.hpp" | |
| 35 | +#include "GXXXInstDir.hpp" | |
| 36 | +#include "GSkyDir.hpp" | |
| 37 | +#include "GSkyMap.hpp" | |
| 38 | +#include "GEnergy.hpp" | |
| 39 | +#include "GTime.hpp" | |
| 40 | + | |
| 41 | +/* __ Forward declarations _______________________________________________ */ | |
| 42 | +class GFilename; | |
| 43 | +class GEbounds; | |
| 44 | +class GGti; | |
| 45 | +class GFits; | |
| 46 | + | |
| 47 | + | |
| 48 | +/***********************************************************************//** | |
| 49 | + * @class GXXXEventCube | |
| 50 | + * | |
| 51 | + * @brief [INSTRUMENT] event bin container class | |
| 52 | + * | |
| 53 | + * This class is a container class for [INSTRUMENT] event bins. | |
| 54 | + ***************************************************************************/ | |
| 55 | +class GXXXEventCube : public GEventCube { | |
| 56 | + | |
| 57 | +public: | |
| 58 | + // Constructors and destructors | |
| 59 | + GXXXEventCube(void); | |
| 60 | + explicit GXXXEventCube(const GFilename& filename); | |
| 61 | + GXXXEventCube(const GXXXEventCube& cube); | |
| 62 | + virtual ~GXXXEventCube(void); | |
| 63 | + | |
| 64 | + // Operators | |
| 65 | + virtual GXXXEventCube& operator=(const GXXXEventCube& cube); | |
| 66 | + virtual GXXXEventBin* operator[](const int& index); | |
| 67 | + virtual const GXXXEventBin* operator[](const int& index) const; | |
| 68 | + | |
| 69 | + // Implemented pure virtual base class methods | |
| 70 | + virtual void clear(void); | |
| 71 | + virtual GXXXEventCube* clone(void) const; | |
| 72 | + virtual std::string classname(void) const; | |
| 73 | + virtual int size(void) const; | |
| 74 | + virtual int dim(void) const; | |
| 75 | + virtual int naxis(const int& axis) const; | |
| 76 | + virtual void load(const GFilename& filename); | |
| 77 | + virtual void save(const GFilename& filename, | |
| 78 | + const bool& clobber = false) const; | |
| 79 | + virtual void read(const GFits& file); | |
| 80 | + virtual void write(GFits& file) const; | |
| 81 | + virtual int number(void) const; | |
| 82 | + virtual std::string print(const GChatter& chatter = NORMAL) const; | |
| 83 | + | |
| 84 | + // Other methods | |
| 85 | + // TODO: Add any further methods that are needed | |
| 86 | + | |
| 87 | +protected: | |
| 88 | + // Protected methods | |
| 89 | + void init_members(void); | |
| 90 | + void copy_members(const GXXXEventCube& cube); | |
| 91 | + void free_members(void); | |
| 92 | + virtual void set_energies(void); | |
| 93 | + virtual void set_times(void); | |
| 94 | + void init_bin(void); | |
| 95 | + void set_bin(const int& index); | |
| 96 | + | |
| 97 | + // Protected members | |
| 98 | + GXXXEventBin m_bin; //!< Actual event bin | |
| 99 | + GXXXInstDir m_dir; //!< Actual event direction | |
| 100 | + GTime m_time; //!< Event cube mean time | |
| 101 | + double m_ontime; //!< Event cube ontime (sec) | |
| 102 | + GEnergy m_energy; //!< Event cube mean energy | |
| 103 | + GEnergy m_ewidth; //!< Event cube energy bin width | |
| 104 | +}; | |
| 105 | + | |
| 106 | + | |
| 107 | +/***********************************************************************//** | |
| 108 | + * @brief Return class name | |
| 109 | + * | |
| 110 | + * @return String containing the class name ("GXXXEventCube"). | |
| 111 | + ***************************************************************************/ | |
| 112 | +inline | |
| 113 | +std::string GXXXEventCube::classname(void) const | |
| 114 | +{ | |
| 115 | + return ("GXXXEventCube"); | |
| 116 | +} | |
| 117 | + | |
| 118 | + | |
| 119 | +/***********************************************************************//** | |
| 120 | + * @brief Set energies | |
| 121 | + * | |
| 122 | + * Sets energies. | |
| 123 | + ***************************************************************************/ | |
| 124 | +inline | |
| 125 | +void GXXXEventCube::set_energies(void) | |
| 126 | +{ | |
| 127 | + return; | |
| 128 | +} | |
| 129 | + | |
| 130 | + | |
| 131 | +/***********************************************************************//** | |
| 132 | + * @brief Set times | |
| 133 | + * | |
| 134 | + * Sets times. | |
| 135 | + ***************************************************************************/ | |
| 136 | +inline | |
| 137 | +void GXXXEventCube::set_times(void) | |
| 138 | +{ | |
| 139 | + return; | |
| 140 | +} | |
| 141 | + | |
| 142 | +#endif /* GXXXEVENTCUBE_HPP */ | ... | ... |
src/template/GXXXEventCube.i
0 → 100644
| 1 | +/*************************************************************************** | |
| 2 | + * GXXXEventCube.i - [INSTRUMENT] event bin container class * | |
| 3 | + * ----------------------------------------------------------------------- * | |
| 4 | + * copyright (C) [YEAR] by [AUTHOR] * | |
| 5 | + * ----------------------------------------------------------------------- * | |
| 6 | + * * | |
| 7 | + * This program is free software: you can redistribute it and/or modify * | |
| 8 | + * it under the terms of the GNU General Public License as published by * | |
| 9 | + * the Free Software Foundation, either version 3 of the License, or * | |
| 10 | + * (at your option) any later version. * | |
| 11 | + * * | |
| 12 | + * This program is distributed in the hope that it will be useful, * | |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
| 15 | + * GNU General Public License for more details. * | |
| 16 | + * * | |
| 17 | + * You should have received a copy of the GNU General Public License * | |
| 18 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. * | |
| 19 | + * * | |
| 20 | + ***************************************************************************/ | |
| 21 | +/** | |
| 22 | + * @file GXXXEventCube.i | |
| 23 | + * @brief [INSTRUMENT] event bin container class definition | |
| 24 | + * @author [AUTHOR] | |
| 25 | + */ | |
| 26 | +%{ | |
| 27 | +/* Put headers and other declarations here that are needed for compilation */ | |
| 28 | +#include "GXXXEventCube.hpp" | |
| 29 | +%} | |
| 30 | + | |
| 31 | + | |
| 32 | +/***********************************************************************//** | |
| 33 | + * @class GXXXEventCube | |
| 34 | + * | |
| 35 | + * @brief [INSTRUMENT] event bin container class | |
| 36 | + ***************************************************************************/ | |
| 37 | +class GXXXEventCube : public GEventCube { | |
| 38 | + | |
| 39 | +public: | |
| 40 | + // Constructors and destructors | |
| 41 | + GXXXEventCube(void); | |
| 42 | + explicit GXXXEventCube(const GFilename& filename); | |
| 43 | + GXXXEventCube(const GXXXEventCube& cube); | |
| 44 | + virtual ~GXXXEventCube(void); | |
| 45 | + | |
| 46 | + // Implemented pure virtual base class methods | |
| 47 | + virtual void clear(void); | |
| 48 | + virtual GXXXEventCube* clone(void) const; | |
| 49 | + virtual std::string classname(void) const; | |
| 50 | + virtual int size(void) const; | |
| 51 | + virtual int dim(void) const; | |
| 52 | + virtual int naxis(const int& axis) const; | |
| 53 | + virtual void load(const GFilename& filename); | |
| 54 | + virtual void save(const GFilename& filename, | |
| 55 | + const bool& clobber = false) const; | |
| 56 | + virtual void read(const GFits& file); | |
| 57 | + virtual void write(GFits& file) const; | |
| 58 | + virtual int number(void) const; | |
| 59 | + | |
| 60 | + // Other methods | |
| 61 | + // TODO: Copy methods from GXXXEventCube.hpp file | |
| 62 | +}; | |
| 63 | + | |
| 64 | + | |
| 65 | +/***********************************************************************//** | |
| 66 | + * @brief GXXXEventCube class extension | |
| 67 | + ***************************************************************************/ | |
| 68 | +%extend GXXXEventCube { | |
| 69 | + GXXXEventCube copy() { | |
| 70 | + return (*self); | |
| 71 | + } | |
| 72 | + GXXXEventBin* __getitem__(int index) { | |
| 73 | + if (index >= 0 && index < self->size()) { | |
| 74 | + return (*self)[index]; | |
| 75 | + } | |
| 76 | + else { | |
| 77 | + throw GException::out_of_range("__getitem__(int)", index, self->size()); | |
| 78 | + } | |
| 79 | + } | |
| 80 | + void __setitem__(int index, const GXXXEventBin& val) { | |
| 81 | + if (index>=0 && index < self->size()) { | |
| 82 | + *((*self)[index]) = val; | |
| 83 | + } | |
| 84 | + else { | |
| 85 | + throw GException::out_of_range("__setitem__(int)", index, self->size()); | |
| 86 | + } | |
| 87 | + } | |
| 88 | +}; | ... | ... |
src/template/Makefile.am
src/template/xxx.i
| ... | ... | @@ -46,6 +46,7 @@ |
| 46 | 46 | |
| 47 | 47 | /* __ Include GammaLib typemaps __________________________________________ */ |
| 48 | 48 | %include typemap_GFilename.i |
| 49 | +%include typemap_slices.i | |
| 49 | 50 | |
| 50 | 51 | /* __ Include interface classes __________________________________________ */ |
| 51 | 52 | %import(module="gammalib.base") "GBase.i"; | ... | ... |