Alexandria  2.25.0
SDC-CH common library for the Euclid project
FitsWriter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2022 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_FITSWRITER_H
26 #define _TABLE_FITSWRITER_H
27 
28 #include "Table/TableWriter.h"
29 #include <CCfits/FITS.h>
30 
31 namespace Euclid {
32 namespace Table {
33 
76 class FitsWriter : public TableWriter {
77 
78 public:
80  enum class Format {
82  ASCII,
84  BINARY
85  };
86 
107  explicit FitsWriter(const std::string& filename, bool override_flag = false);
108 
127 
128  FitsWriter(FitsWriter&&) = default;
130 
131  FitsWriter(const FitsWriter&) = delete;
132  FitsWriter& operator=(const FitsWriter&) = delete;
133 
137  virtual ~FitsWriter() = default;
138 
151  FitsWriter& setFormat(Format format);
152 
166  FitsWriter& setHduName(const std::string& name);
167 
180  void addComment(const std::string& message) override;
181 
193  template <typename T>
194  void setHeader(const std::string& key, T&& value, const std::string& comment = "") {
195  m_headers.emplace_back(Header{key, comment, value});
196  }
197 
198 protected:
201  void init(const Table& table) override;
202 
205  void append(const Table& table) override;
206 
207 private:
208  struct Header {
211  };
212 
215  bool m_initialized = false;
216  bool m_override_file = true;
221  int m_hdu_index = -1;
222  long m_current_line = 0;
223 
224 }; /* End of FitsWriter class */
225 
226 } /* namespace Table */
227 } /* namespace Euclid */
228 
229 #endif
TableWriter implementation for writing tables in FITS format.
Definition: FitsWriter.h:76
FitsWriter(const FitsWriter &)=delete
FitsWriter & operator=(const FitsWriter &)=delete
FitsWriter(FitsWriter &&)=default
FitsWriter & setFormat(Format format)
Set the FITS table format.
Definition: FitsWriter.cpp:52
virtual ~FitsWriter()=default
Destructor.
void addComment(const std::string &message) override
Adds a comment to the stream.
Definition: FitsWriter.cpp:70
Format
The format of the HDUs a FitsWriter creates.
Definition: FitsWriter.h:80
@ BINARY
FITS binary table HDU format.
@ ASCII
FITS ASCII table HDU format.
std::vector< Header > m_headers
Definition: FitsWriter.h:220
void append(const Table &table) override
Definition: FitsWriter.cpp:139
FitsWriter(const std::string &filename, bool override_flag=false)
Creates a FitsWriter that writes to a specific file.
Definition: FitsWriter.cpp:47
std::vector< std::string > m_comments
Definition: FitsWriter.h:219
std::shared_ptr< CCfits::FITS > m_fits
Definition: FitsWriter.h:214
void init(const Table &table) override
Definition: FitsWriter.cpp:78
FitsWriter & setHduName(const std::string &name)
Set the HDU name where the table is written.
Definition: FitsWriter.cpp:61
FitsWriter & operator=(FitsWriter &&)=default
void setHeader(const std::string &key, T &&value, const std::string &comment="")
Sets a header key/value pair.
Definition: FitsWriter.h:194
boost::variant< bool, int32_t, int64_t, float, double, std::string, std::vector< bool >, std::vector< int32_t >, std::vector< int64_t >, std::vector< float >, std::vector< double >, NdArray::NdArray< int32_t >, NdArray::NdArray< int64_t >, NdArray::NdArray< float >, NdArray::NdArray< double > > cell_type
The possible cell types.
Definition: Row.h:71
Interface for classes writing tables.
Definition: TableWriter.h:49
Represents a table.
Definition: Table.h:49