Alexandria
2.19
Please provide a description of the project.
|
TableWriter implementation for writing tables in FITS format. More...
#include <FitsWriter.h>
Public Types | |
enum | Format { Format::ASCII, Format::BINARY } |
The format of the HDUs a FitsWriter creates. More... | |
Public Member Functions | |
FitsWriter (const std::string &filename, bool override_flag=false) | |
Creates a FitsWriter that writes to a specific file. More... | |
FitsWriter (std::shared_ptr< CCfits::FITS > fits) | |
Creates a FitsWriter that writes to a specific CCfits::FITS object. More... | |
FitsWriter (FitsWriter &&)=default | |
FitsWriter & | operator= (FitsWriter &&)=default |
FitsWriter (const FitsWriter &)=delete | |
FitsWriter & | operator= (const FitsWriter &)=delete |
virtual | ~FitsWriter ()=default |
Destructor. More... | |
FitsWriter & | setFormat (Format format) |
Set the FITS table format. More... | |
FitsWriter & | setHduName (const std::string &name) |
Set the HDU name where the table is written. More... | |
void | addComment (const std::string &message) override |
Adds a comment to the stream. More... | |
![]() | |
TableWriter ()=default | |
TableWriter (TableWriter &&)=default | |
TableWriter & | operator= (TableWriter &&)=default |
TableWriter (const TableWriter &)=delete | |
TableWriter & | operator= (const TableWriter &)=delete |
virtual | ~TableWriter ()=default |
void | addData (const Table &table) |
Appends the contents of the given table to the output. More... | |
Protected Member Functions | |
void | init (const Table &table) override |
void | append (const Table &table) override |
Private Attributes | |
std::string | m_filename = "" |
std::shared_ptr< CCfits::FITS > | m_fits = nullptr |
bool | m_initialized = false |
bool | m_override_file = true |
Format | m_format = Format::BINARY |
std::string | m_hdu_name = "" |
std::vector< std::string > | m_comments {} |
int | m_hdu_index = -1 |
long | m_current_line = 0 |
TableWriter implementation for writing tables in FITS format.
This class allows for both creating new FITS tables or extending existing ones, based on the constructor used and the method setHduName(). For more information see the documentation of the constructors and this method.
The FITS table HDUs can be both in ASCII and binary format. The conventions are the following:
ASCII format:
Binary format:
Note that, at the moment, only fixed length vector columns are supported and that there is no support for vector columns for ASCII FITS tables.
The TUNITn fits keywords are populated using the unit of the of the ColumnDescriptions of the Table. The descriptions of the columns are set as the values of the (non standard) keywords TDESCn.
Definition at line 76 of file FitsWriter.h.
|
strong |
The format of the HDUs a FitsWriter creates.
Enumerator | |
---|---|
ASCII |
FITS ASCII table HDU format. |
BINARY |
FITS binary table HDU format. |
Definition at line 80 of file FitsWriter.h.
|
explicit |
Creates a FitsWriter that writes to a specific file.
If the override_flag is set to true, any pre-existing file will be deleted. If this flag is set to false and there is already an HDU with the name set by the setHduName() method, the table of this HDU will be appended. Otherwise a new table HDU will be added to the file.
Note that when this constructor is used the FITS file will be re-opened each time the addData() method is called. This takes away from the user the responsibility of managing the lifetime of the CCfits::FITS objects, but it might cause performance issues (especially with files with hundreds of HDUs). If this is the case, consider to use the other constructor of this class.
filename | The path of the file to store the FITS table |
override_flag | When true, any existing file will be overridden |
Definition at line 33 of file FitsWriter.cpp.
|
explicit |
Creates a FitsWriter that writes to a specific CCfits::FITS object.
If the given obejct already contain an HDU with the name set by the setHduName() method, the table of this HDU will be appended. Otherwisea new table HDU will be added to the CCfits::FITS object.
This constructor is not handling the opening/closing of the given file, so is should be used when there are performance issues with the other constructor. As the usage of this constructor delegates the management of the lifetime of the CCfits::FITS object to the user, it is recommended to be used only when performance issues have been identified.
fits | A pointer to the CCfits::FITS object to write the table |
Definition at line 35 of file FitsWriter.cpp.
|
default |
|
delete |
|
virtualdefault |
Destructor.
|
overridevirtual |
Adds a comment to the stream.
This method can only be called before any data have been written. The comments are written to the FITS during the first call of addData(). Note that if an existing HDU is being appended (see setHduName() method) all comments are ignored.
message | The message to add |
Elements::Exception | If data have already been written |
Implements Euclid::Table::TableWriter.
Definition at line 55 of file FitsWriter.cpp.
References m_comments, m_initialized, and std::vector< T >::push_back().
|
overrideprotectedvirtual |
Writes to the FITS file the contents of the table, following the rules explained at the class documentation
Implements Euclid::Table::TableWriter.
Definition at line 118 of file FitsWriter.cpp.
References m_current_line, m_filename, m_fits, m_hdu_index, and Euclid::Table::populateColumn().
|
overrideprotectedvirtual |
Creates the FITS file if it needs to be created, the table HDU if the name already exist and writes the comments.
Implements Euclid::Table::TableWriter.
Definition at line 63 of file FitsWriter.cpp.
References BINARY, Euclid::Table::getAsciiFormatList(), Euclid::Table::getBinaryFormatList(), Euclid::Table::getTDIM(), m_comments, m_current_line, m_filename, m_fits, m_format, m_hdu_index, m_hdu_name, m_initialized, m_override_file, std::vector< T >::push_back(), std::string::push_back(), and std::to_string().
|
default |
|
delete |
FitsWriter & Euclid::Table::FitsWriter::setFormat | ( | Format | format | ) |
Set the FITS table format.
It can be set either to ASCII or binary (default). It returns a reference to the FitsWriter so it can be chained with other calls in the same line.
format | One of FitsWriter::Format::ASCII, FitsWriter::Format::BINARY |
Elements::Exception | if writing of data has already started |
Definition at line 37 of file FitsWriter.cpp.
References m_format, and m_initialized.
Referenced by Euclid::GridContainer::GridAxesToFitsHelper< AxesTypes >::addGridAxesToFitsFile().
FitsWriter & Euclid::Table::FitsWriter::setHduName | ( | const std::string & | name | ) |
Set the HDU name where the table is written.
This method has to be called before any data are written and can be used to change the name of the table HDU. If there is already existing a table HDU with this name, any calls to the addData() method will append data to it. Otherwise a new HDU will be added in the FITS file. The default name is the empty string.
name | The name of the HDU to write the table in |
Definition at line 46 of file FitsWriter.cpp.
References m_hdu_name, and m_initialized.
Referenced by Euclid::GridContainer::GridAxesToFitsHelper< AxesTypes >::addGridAxesToFitsFile().
|
private |
Definition at line 198 of file FitsWriter.h.
Referenced by addComment(), and init().
|
private |
Definition at line 200 of file FitsWriter.h.
|
private |
Definition at line 192 of file FitsWriter.h.
|
private |
Definition at line 193 of file FitsWriter.h.
|
private |
Definition at line 196 of file FitsWriter.h.
Referenced by init(), and setFormat().
|
private |
Definition at line 199 of file FitsWriter.h.
|
private |
Definition at line 197 of file FitsWriter.h.
Referenced by init(), and setHduName().
|
private |
Definition at line 194 of file FitsWriter.h.
Referenced by addComment(), init(), setFormat(), and setHduName().
|
private |
Definition at line 195 of file FitsWriter.h.
Referenced by init().