Alexandria  2.16
Please provide a description of the project.
FitsReader.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2020 Euclid Science Ground Segment
3  *
4  * This library is free software; you can redistribute it and/or modify it under
5  * the terms of the GNU Lesser General Public License as published by the Free
6  * Software Foundation; either version 3.0 of the License, or (at your option)
7  * any later version.
8  *
9  * This library is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12  * details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this library; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
25 #ifndef _TABLE_FITSREADER_H
26 #define _TABLE_FITSREADER_H
27 
28 #include <functional>
29 #include <CCfits/CCfits>
30 #include "Table/TableReader.h"
31 
32 namespace Euclid {
33 namespace Table {
34 
75 class FitsReader : public TableReader {
76 
77 public:
78 
92  explicit FitsReader(const CCfits::HDU& hdu);
93 
96  FitsReader(const std::string& filename, int hdu_index=1);
97 
100  FitsReader(const std::string& filename, const std::string& hduName);
101 
102  FitsReader(FitsReader&&) = default;
103  FitsReader& operator=(FitsReader&&) = default;
104 
105  FitsReader(const FitsReader&) = delete;
106  FitsReader& operator=(const FitsReader&) = delete;
107 
111  virtual ~FitsReader() = default;
112 
126  FitsReader& fixColumnNames(std::vector<std::string> column_names);
127 
139  const ColumnInfo& getInfo() override;
140 
144  std::string getComment() override;
145 
147  void skip(long rows) override;
148 
150  bool hasMoreRows() override;
151 
153  std::size_t rowsLeft() override;
154 
155 protected:
156 
158  Table readImpl(long rows) override;
159 
160 private:
161 
162  void readColumnInfo();
163 
164  std::unique_ptr<CCfits::FITS> m_fits {nullptr};
165  std::reference_wrapper<const CCfits::HDU> m_hdu;
166  bool m_reading_started = false;
167  long m_total_rows = -1;
168  long m_current_row = 1;
169  std::vector<std::string> m_column_names {};
170  std::shared_ptr<ColumnInfo> m_column_info;
171 
172 }; /* End of FitsReader class */
173 
174 } /* namespace Table */
175 } /* namespace Euclid */
176 
177 
178 #endif
Interface for classes reading tables.
Definition: TableReader.h:48
const ColumnInfo & getInfo() override
Returns the column information of the table.
Definition: FitsReader.cpp:116
std::shared_ptr< ColumnInfo > m_column_info
Definition: FitsReader.h:170
FitsReader & fixColumnNames(std::vector< std::string > column_names)
Overrides the column names of the table.
Definition: FitsReader.cpp:61
Table readImpl(long rows) override
Implements the TableReader::readImpl() contract.
Definition: FitsReader.cpp:126
std::reference_wrapper< const CCfits::HDU > m_hdu
Definition: FitsReader.h:165
FitsReader(const CCfits::HDU &hdu)
Creates a FitsReader that reads from the given HDU.
Definition: FitsReader.cpp:50
std::size_t rowsLeft() override
Implements the TableReader::rowsLeft() contract.
Definition: FitsReader.cpp:172
std::unique_ptr< CCfits::FITS > m_fits
Definition: FitsReader.h:164
virtual ~FitsReader()=default
Destructor.
FitsReader & operator=(FitsReader &&)=default
std::vector< std::string > m_column_names
Definition: FitsReader.h:169
Represents a table.
Definition: Table.h:49
Provides information about the columns of a Table.
Definition: ColumnInfo.h:52
void skip(long rows) override
Implements the TableReader::skip() contract.
Definition: FitsReader.cpp:162
TableReader implementation for reading FITS tables.
Definition: FitsReader.h:75
bool hasMoreRows() override
Implements the TableReader::hasMoreRows() contract.
Definition: FitsReader.cpp:167
std::string getComment() override
Definition: FitsReader.cpp:121