Commit a99233f0aad15bf111bd4edec1137f367277e825
1 parent
ca430714
Integrate GCTAEventList::append-column() method
Showing
3 changed files
with
28 additions
and
9 deletions
inst/cta/include/GCTAEventList.hpp
| @@ -40,6 +40,7 @@ class GFilename; | @@ -40,6 +40,7 @@ class GFilename; | ||
| 40 | class GFitsHDU; | 40 | class GFitsHDU; |
| 41 | class GFitsTable; | 41 | class GFitsTable; |
| 42 | class GFitsBinTable; | 42 | class GFitsBinTable; |
| 43 | +class GFitsTableCol; | ||
| 43 | 44 | ||
| 44 | /* __ Constants __________________________________________________________ */ | 45 | /* __ Constants __________________________________________________________ */ |
| 45 | namespace gammalib { | 46 | namespace gammalib { |
| @@ -85,6 +86,7 @@ public: | @@ -85,6 +86,7 @@ public: | ||
| 85 | 86 | ||
| 86 | // Implement other methods | 87 | // Implement other methods |
| 87 | void append(const GCTAEventAtom& event); | 88 | void append(const GCTAEventAtom& event); |
| 89 | + void append_column(const GFitsTableCol& column); | ||
| 88 | void reserve(const int& number); | 90 | void reserve(const int& number); |
| 89 | void remove(const int& index, const int& number = 1); | 91 | void remove(const int& index, const int& number = 1); |
| 90 | void write(GFits& fits, const std::string& evtname, | 92 | void write(GFits& fits, const std::string& evtname, |
| @@ -95,7 +97,6 @@ public: | @@ -95,7 +97,6 @@ public: | ||
| 95 | void irf_cache(const std::string& name, const int& index, | 97 | void irf_cache(const std::string& name, const int& index, |
| 96 | const double& irf) const; | 98 | const double& irf) const; |
| 97 | const std::string& gtiname(void) const; | 99 | const std::string& gtiname(void) const; |
| 98 | - void append_column(GFitsTableCol& col); | ||
| 99 | 100 | ||
| 100 | protected: | 101 | protected: |
| 101 | // Protected methods | 102 | // Protected methods |
inst/cta/pyext/GCTAEventList.i
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GCTAEventList.i - CTA event list class * | 2 | * GCTAEventList.i - CTA event list class * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2011-2016 by Juergen Knoedlseder * | 4 | + * copyright (C) 2011-2017 by Juergen Knoedlseder * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -59,6 +59,7 @@ public: | @@ -59,6 +59,7 @@ public: | ||
| 59 | 59 | ||
| 60 | // Implement other methods | 60 | // Implement other methods |
| 61 | void append(const GCTAEventAtom& event); | 61 | void append(const GCTAEventAtom& event); |
| 62 | + void append_column(const GFitsTableCol& column); | ||
| 62 | void reserve(const int& number); | 63 | void reserve(const int& number); |
| 63 | void remove(const int& index, const int& number = 1); | 64 | void remove(const int& index, const int& number = 1); |
| 64 | void write(GFits& fits, const std::string& evtname, | 65 | void write(GFits& fits, const std::string& evtname, |
inst/cta/src/GCTAEventList.cpp
| @@ -35,6 +35,7 @@ | @@ -35,6 +35,7 @@ | ||
| 35 | #include "GFits.hpp" | 35 | #include "GFits.hpp" |
| 36 | #include "GFitsTable.hpp" | 36 | #include "GFitsTable.hpp" |
| 37 | #include "GFitsBinTable.hpp" | 37 | #include "GFitsBinTable.hpp" |
| 38 | +#include "GFitsTableCol.hpp" | ||
| 38 | #include "GFitsTableFloatCol.hpp" | 39 | #include "GFitsTableFloatCol.hpp" |
| 39 | #include "GFitsTableDoubleCol.hpp" | 40 | #include "GFitsTableDoubleCol.hpp" |
| 40 | #include "GFitsTableULongCol.hpp" | 41 | #include "GFitsTableULongCol.hpp" |
| @@ -46,6 +47,7 @@ | @@ -46,6 +47,7 @@ | ||
| 46 | /* __ Method name definitions ____________________________________________ */ | 47 | /* __ Method name definitions ____________________________________________ */ |
| 47 | #define G_OPERATOR "GCTAEventList::operator[](int&)" | 48 | #define G_OPERATOR "GCTAEventList::operator[](int&)" |
| 48 | #define G_ROI "GCTAEventList::roi(GRoi&)" | 49 | #define G_ROI "GCTAEventList::roi(GRoi&)" |
| 50 | +#define G_APPEND_COLUMN "GCTAEventList::append_column(GFitsTableCol&)" | ||
| 49 | #define G_FETCH "GCTAEventList::fetch()" | 51 | #define G_FETCH "GCTAEventList::fetch()" |
| 50 | 52 | ||
| 51 | /* __ Macros _____________________________________________________________ */ | 53 | /* __ Macros _____________________________________________________________ */ |
| @@ -577,27 +579,42 @@ void GCTAEventList::append(const GCTAEventAtom& event) | @@ -577,27 +579,42 @@ void GCTAEventList::append(const GCTAEventAtom& event) | ||
| 577 | 579 | ||
| 578 | 580 | ||
| 579 | /***********************************************************************//** | 581 | /***********************************************************************//** |
| 580 | - * @brief Append a column to m_columns | 582 | + * @brief Append FITS table column to event list |
| 581 | * | 583 | * |
| 582 | - * @param[in] col Fits table column to be appended. | 584 | + * @param[in] column FITS table column to be appended. |
| 583 | * | 585 | * |
| 584 | - * Appends a fits column to the end of the m_columns vector. | 586 | + * @exception GException::invalid_argument |
| 587 | + * FITS column has incompatible length. | ||
| 588 | + * | ||
| 589 | + * Appends a FITS table column to the event list. The length of the FITS | ||
| 590 | + * column must be identical to the number of events in the event list. | ||
| 585 | ***************************************************************************/ | 591 | ***************************************************************************/ |
| 586 | -//void GCTAEventList::append_column(const std::string& colname) | ||
| 587 | -void GCTAEventList::append_column(GFitsTableCol& col) | 592 | +void GCTAEventList::append_column(const GFitsTableCol& column) |
| 588 | { | 593 | { |
| 594 | + // Throw an exception if the column has an incompatible length | ||
| 595 | + if (size() != column.length()) { | ||
| 596 | + std::string msg = "Incompatible column length. Attempt to append a " | ||
| 597 | + "column of length "+gammalib::str(column.length())+ | ||
| 598 | + " to an event list with "+gammalib::str(size())+ | ||
| 599 | + " events. Please specify a column of length "+ | ||
| 600 | + gammalib::str(size())+"."; | ||
| 601 | + throw GException::invalid_argument(G_APPEND_COLUMN, msg); | ||
| 602 | + } | ||
| 603 | + | ||
| 589 | // Make sure that the events are online | 604 | // Make sure that the events are online |
| 590 | fetch(); | 605 | fetch(); |
| 591 | 606 | ||
| 607 | + // Clone the FITS column. De-allocation is done when the object is free'd | ||
| 608 | + GFitsTableCol* ptr = column.clone(); | ||
| 609 | + | ||
| 592 | // Append the column | 610 | // Append the column |
| 593 | - m_columns.push_back(&col); | 611 | + m_columns.push_back(ptr); |
| 594 | 612 | ||
| 595 | // Return | 613 | // Return |
| 596 | return; | 614 | return; |
| 597 | } | 615 | } |
| 598 | 616 | ||
| 599 | 617 | ||
| 600 | - | ||
| 601 | /***********************************************************************//** | 618 | /***********************************************************************//** |
| 602 | * @brief Remove events from event list | 619 | * @brief Remove events from event list |
| 603 | * | 620 | * |