diff --git a/inst/cta/include/GCTAEventList.hpp b/inst/cta/include/GCTAEventList.hpp index 42e251e..e6054b3 100644 --- a/inst/cta/include/GCTAEventList.hpp +++ b/inst/cta/include/GCTAEventList.hpp @@ -40,6 +40,7 @@ class GFilename; class GFitsHDU; class GFitsTable; class GFitsBinTable; +class GFitsTableCol; /* __ Constants __________________________________________________________ */ namespace gammalib { @@ -85,6 +86,7 @@ public: // Implement other methods void append(const GCTAEventAtom& event); + void append_column(const GFitsTableCol& column); void reserve(const int& number); void remove(const int& index, const int& number = 1); void write(GFits& fits, const std::string& evtname, @@ -95,7 +97,6 @@ public: void irf_cache(const std::string& name, const int& index, const double& irf) const; const std::string& gtiname(void) const; - void append_column(GFitsTableCol& col); protected: // Protected methods diff --git a/inst/cta/pyext/GCTAEventList.i b/inst/cta/pyext/GCTAEventList.i index 007249d..762257d 100644 --- a/inst/cta/pyext/GCTAEventList.i +++ b/inst/cta/pyext/GCTAEventList.i @@ -1,7 +1,7 @@ /*************************************************************************** * GCTAEventList.i - CTA event list class * * ----------------------------------------------------------------------- * - * copyright (C) 2011-2016 by Juergen Knoedlseder * + * copyright (C) 2011-2017 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -59,6 +59,7 @@ public: // Implement other methods void append(const GCTAEventAtom& event); + void append_column(const GFitsTableCol& column); void reserve(const int& number); void remove(const int& index, const int& number = 1); void write(GFits& fits, const std::string& evtname, diff --git a/inst/cta/src/GCTAEventList.cpp b/inst/cta/src/GCTAEventList.cpp index 9a2f84d..e03633c 100644 --- a/inst/cta/src/GCTAEventList.cpp +++ b/inst/cta/src/GCTAEventList.cpp @@ -35,6 +35,7 @@ #include "GFits.hpp" #include "GFitsTable.hpp" #include "GFitsBinTable.hpp" +#include "GFitsTableCol.hpp" #include "GFitsTableFloatCol.hpp" #include "GFitsTableDoubleCol.hpp" #include "GFitsTableULongCol.hpp" @@ -46,6 +47,7 @@ /* __ Method name definitions ____________________________________________ */ #define G_OPERATOR "GCTAEventList::operator[](int&)" #define G_ROI "GCTAEventList::roi(GRoi&)" +#define G_APPEND_COLUMN "GCTAEventList::append_column(GFitsTableCol&)" #define G_FETCH "GCTAEventList::fetch()" /* __ Macros _____________________________________________________________ */ @@ -577,27 +579,42 @@ void GCTAEventList::append(const GCTAEventAtom& event) /***********************************************************************//** - * @brief Append a column to m_columns + * @brief Append FITS table column to event list * - * @param[in] col Fits table column to be appended. + * @param[in] column FITS table column to be appended. * - * Appends a fits column to the end of the m_columns vector. + * @exception GException::invalid_argument + * FITS column has incompatible length. + * + * Appends a FITS table column to the event list. The length of the FITS + * column must be identical to the number of events in the event list. ***************************************************************************/ -//void GCTAEventList::append_column(const std::string& colname) -void GCTAEventList::append_column(GFitsTableCol& col) +void GCTAEventList::append_column(const GFitsTableCol& column) { + // Throw an exception if the column has an incompatible length + if (size() != column.length()) { + std::string msg = "Incompatible column length. Attempt to append a " + "column of length "+gammalib::str(column.length())+ + " to an event list with "+gammalib::str(size())+ + " events. Please specify a column of length "+ + gammalib::str(size())+"."; + throw GException::invalid_argument(G_APPEND_COLUMN, msg); + } + // Make sure that the events are online fetch(); + // Clone the FITS column. De-allocation is done when the object is free'd + GFitsTableCol* ptr = column.clone(); + // Append the column - m_columns.push_back(&col); + m_columns.push_back(ptr); // Return return; } - /***********************************************************************//** * @brief Remove events from event list *