Commit a99233f0aad15bf111bd4edec1137f367277e825

Authored by Jürgen Knödlseder
1 parent ca430714

Integrate GCTAEventList::append-column() method

inst/cta/include/GCTAEventList.hpp
... ... @@ -40,6 +40,7 @@ class GFilename;
40 40 class GFitsHDU;
41 41 class GFitsTable;
42 42 class GFitsBinTable;
  43 +class GFitsTableCol;
43 44  
44 45 /* __ Constants __________________________________________________________ */
45 46 namespace gammalib {
... ... @@ -85,6 +86,7 @@ public:
85 86  
86 87 // Implement other methods
87 88 void append(const GCTAEventAtom& event);
  89 + void append_column(const GFitsTableCol& column);
88 90 void reserve(const int& number);
89 91 void remove(const int& index, const int& number = 1);
90 92 void write(GFits& fits, const std::string& evtname,
... ... @@ -95,7 +97,6 @@ public:
95 97 void irf_cache(const std::string& name, const int& index,
96 98 const double& irf) const;
97 99 const std::string& gtiname(void) const;
98   - void append_column(GFitsTableCol& col);
99 100  
100 101 protected:
101 102 // Protected methods
... ...
inst/cta/pyext/GCTAEventList.i
1 1 /***************************************************************************
2 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 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -59,6 +59,7 @@ public:
59 59  
60 60 // Implement other methods
61 61 void append(const GCTAEventAtom& event);
  62 + void append_column(const GFitsTableCol& column);
62 63 void reserve(const int& number);
63 64 void remove(const int& index, const int& number = 1);
64 65 void write(GFits& fits, const std::string& evtname,
... ...
inst/cta/src/GCTAEventList.cpp
... ... @@ -35,6 +35,7 @@
35 35 #include "GFits.hpp"
36 36 #include "GFitsTable.hpp"
37 37 #include "GFitsBinTable.hpp"
  38 +#include "GFitsTableCol.hpp"
38 39 #include "GFitsTableFloatCol.hpp"
39 40 #include "GFitsTableDoubleCol.hpp"
40 41 #include "GFitsTableULongCol.hpp"
... ... @@ -46,6 +47,7 @@
46 47 /* __ Method name definitions ____________________________________________ */
47 48 #define G_OPERATOR "GCTAEventList::operator[](int&)"
48 49 #define G_ROI "GCTAEventList::roi(GRoi&)"
  50 +#define G_APPEND_COLUMN "GCTAEventList::append_column(GFitsTableCol&)"
49 51 #define G_FETCH "GCTAEventList::fetch()"
50 52  
51 53 /* __ Macros _____________________________________________________________ */
... ... @@ -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 604 // Make sure that the events are online
590 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 610 // Append the column
593   - m_columns.push_back(&col);
  611 + m_columns.push_back(ptr);
594 612  
595 613 // Return
596 614 return;
597 615 }
598 616  
599 617  
600   -
601 618 /***********************************************************************//**
602 619 * @brief Remove events from event list
603 620 *
... ...