18#include <ciiException.hpp>
31#include <fmt/format.h>
40struct FitsDataTypeValue {
41 static_assert(
true,
"invalid data for fits writer");
45struct FitsDataTypeValue<unsigned char> {
46 static constexpr int DTYPE = TBYTE;
50struct FitsDataTypeValue<signed char> {
51 static constexpr int DTYPE = TSBYTE;
55struct FitsDataTypeValue<bool> {
56 static constexpr int DTYPE = TLOGICAL;
63static_assert(
sizeof(bool) ==
sizeof(
char),
64 "Cfitsio uses 'char' for TLOGICAL internally. Therefore the sizes of 'bool' and "
65 "'char' must match for this implementation to work.");
80struct FitsDataTypeValue<unsigned short> {
81 static constexpr int DTYPE = TUSHORT;
85struct FitsDataTypeValue<signed short> {
86 static constexpr int DTYPE = TSHORT;
90struct FitsDataTypeValue<unsigned int> {
91 static constexpr int DTYPE = TUINT;
95struct FitsDataTypeValue<int> {
96 static constexpr int DTYPE = TINT;
100struct FitsDataTypeValue<unsigned long> {
101 static constexpr int DTYPE = TULONG;
105struct FitsDataTypeValue<long> {
106 static constexpr int DTYPE = TLONG;
110struct FitsDataTypeValue<float> {
111 static constexpr int DTYPE = TFLOAT;
115struct FitsDataTypeValue<unsigned long long> {
116 static constexpr int DTYPE = TULONGLONG;
120struct FitsDataTypeValue<long long> {
121 static constexpr int DTYPE = TLONGLONG;
125struct FitsDataTypeValue<double> {
126 static constexpr int DTYPE = TDOUBLE;
130struct FitsDataTypeValue<std::complex<float>> {
131 static constexpr int DTYPE = TCOMPLEX;
135struct FitsDataTypeValue<std::complex<double>> {
136 static constexpr int DTYPE = TDBLCOMPLEX;
139template <
typename data>
140void TableWriterHelper(fitsfile* fptr,
int colnum,
long firstrow, std::vector<data>& input);
142template <
typename data>
143void TableWriterHelper(fitsfile* fptr,
int colnum,
long firstrow, std::vector<data>& input);
145void ThrowOnBadStatus(
int status,
const std::string& message) {
148 fits_get_errstatus(status, err_text);
150 char fits_buffer[80];
151 while (fits_read_errmsg(fits_buffer)) {
152 buffer += fits_buffer;
155 fmt::format(
"{} {}: {}", message, err_text, buffer));
165 const std::array<
bool,
sizeof...(T)>&
disabled,
168 , m_fits_handle(
nullptr, &CloseFits)
186 for (
auto column : this->m_column_description) {
231 if (m_fits_handle !=
nullptr) {
234 if (
sizeof...(T) <=
column) {
237 if (
length >= 4294967296) {
239 fmt::format(
"length({}) must be less than 2^32",
length));
253 this->SetColumnLength(
column,
x.size());
279 if (this->m_disabled_fields[
element]) {
290 fmt::format(
"dynamic sized type given, but length not given for {}",
291 this->m_column_description[
element].name));
292 }
else if (
x.size() != m_column_length[
element]) {
294 "data size does not match configured length");
296 std::vector<
typename std::decay_t<
decltype(
x)>::value_type>
copy(
297 x.data(),
x.data() + m_column_length[
element].value());
299 FitsDataTypeValue<
typename decltype(
copy)::value_type>::DTYPE,
310 std::vector<
typename std::decay_t<
decltype(
x)>::value_type>
copy(
311 x.data(),
x.data() +
x.size());
313 FitsDataTypeValue<
typename decltype(
copy)::value_type>::DTYPE,
322 }
else if constexpr (std::is_same_v<std::decay_t<
decltype(
x)>, std::string>) {
336 std::decay_t<
decltype(
x)>
copy{
x};
338 FitsDataTypeValue<
decltype(
copy)>::DTYPE,
353 std::apply(
write, data);
359 m_fits_handle.reset(
nullptr);
This is an abstract class that can be used to implement an OutputStage for a Recording Unit.
Definition dataRecorder.hpp:29
Definition fitsDataRecorder.hpp:28
Definition fitsDataRecorder.hpp:71
FitsRecorder(const ColumnDescription &columns, const std::array< bool, sizeof...(T)> &disable={}, const std::string &extension_name="recording")
create a new recorder
Definition fitsDataRecorder.ipp:164
void Open(const std::filesystem::path &file) override
Open a file.
Definition fitsDataRecorder.ipp:175
void SetColumnLength(size_t column, size_t length)
Set the exact length of a column.
Definition fitsDataRecorder.ipp:230
void Write(const std::tuple< T... > &data) override
Write a single row of data.
Definition fitsDataRecorder.ipp:274
void Close() override
Close the currently open file.
Definition fitsDataRecorder.ipp:358
Thrown if an argument passed to a method was invalid.
Definition exceptions.hpp:300
The RtctkException class is the base class for all Rtctk exceptions.
Definition exceptions.hpp:211
Definition commandReplier.cpp:22
constexpr bool IS_STATIC_SPAN_TYPE
Is true if the type is a gsl::span type with fixed size.
Definition typeTraits.hpp:179
void GetFITSTFormWithLength(std::vector< std::string > &input, const gsl::span< std::optional< size_t >, sizeof...(Args)+1 > sizes)
Get a vactor of TFORM strings for a list of types using the custom sizes provided.
Definition fitsColumnFormat.ipp:158
constexpr bool IS_STD_ARRAY_TYPE
Is true if the type is a std::array<U> of some type U.
Definition typeTraits.hpp:149
constexpr bool IS_DYNAMIC_SPAN_TYPE
Is true if the type is a gsl::span type with dynamic size.
Definition typeTraits.hpp:209
constexpr bool IS_VECTOR_TYPE
Is true if the type is a std::vector<U> of some type U.
Definition typeTraits.hpp:47
constexpr bool IS_MATRIX_BUFFER_TYPE
Is true if the type is a MatrixBuffer<U> of some type U.
Definition typeTraits.hpp:77
elt::mal::future< std::string > InjectReqRepEvent(StateMachineEngine &engine)
Definition malEventInjector.hpp:23
FitsRecorder allows to write ColumnData to into fits files in a specified directory.
Utility functions for use in data recording.
Provides useful mechanisms to test various type traits.