ifw-rtmstools 3.0.0
Loading...
Searching...
No Matches
common.hpp
Go to the documentation of this file.
1
6#ifndef RTMSTOOLS2_COMMON_LLNETIO_HPP_
7#define RTMSTOOLS2_COMMON_LLNETIO_HPP_
8
9#include <iostream>
10#include <array>
11#include <thread>
12#include <fmt/format.h>
13
14#include <boost/endian/arithmetic.hpp>
15
16#include <fitsio.h>
17
18//#include <ifw/rtmstools/rtmslib_llnetio/dataType.hpp>
19#include <ifw/fnd/defs/dataType.hpp>
20#include <ifw/fnd/tools/tools.hpp>
21
23
24// The RTMSTOOLS_DEBUG environment variable can be defined to switch on log level
25// debugging in the RTMS-TOOLS lib.
26constexpr const char* RTMSTOOLS_DEBUG = "RTMSTOOLS_DEBUG";
27
28extern int8_t __rtmstools_debug__;
29
30#define RTT_DEBUG \
31 if (__rtmstools_debug__ == -1) { \
32 __rtmstools_debug__ = std::getenv(RTMSTOOLS_DEBUG) != nullptr; \
33 } \
34 if (__rtmstools_debug__)
35
36#define RTT_PRINT(msg) \
37 do { \
38 fmt::print("RTMSTOOLS-DEBUG:{}:{}: {}\n", ifw::rtmstools::rtmslib_llnetio::Time(), IFWLOC, msg); \
39 } while (0);
40
41
42
43 inline double Time() {
44 std::chrono::time_point<std::chrono::system_clock> now = std::chrono::system_clock::now();
45 auto duration = now.time_since_epoch();
46 auto time_now_ns = std::chrono::duration_cast<std::chrono::nanoseconds>(duration).count();
47 return (time_now_ns / 1e9);
48 }
49
50 inline void Sleep(const double sleep_time) {
51 std::chrono::duration<double> chrono_sleep_time(sleep_time);
52 std::this_thread::sleep_for(chrono_sleep_time);
53 }
54
55 void HandleCfitsioError(const std::string& operation,
56 const int cfitsio_status);
57
58 std::tuple<std::vector<uint8_t>, int, int, int, int> LoadFitsImageCube(const char* filename);
59
60 inline int BitpixToFitsDatatype(const int bitpix) {
61 switch (bitpix) {
62 case BYTE_IMG: return TBYTE;
63 case SHORT_IMG: return TSHORT;
64 case USHORT_IMG: return TUSHORT;
65 case LONG_IMG: return TINT; //TLONG;
66 case ULONG_IMG: return TULONG;
67 case LONGLONG_IMG: return TLONGLONG;
68 case ULONGLONG_IMG: return TULONGLONG;
69 case FLOAT_IMG: return TFLOAT;
70 case DOUBLE_IMG: return TDOUBLE;
71 default:
72 std::cerr << "Unknown BITPIX value: " << bitpix << std::endl;
73 return 0; // Return 0 for unknown datatype
74 }
75 }
76
77 inline ifw::fnd::datatype::DataType BitpixToIfwDataType(const int8_t bitpix) {
78 switch (bitpix) {
79 case BYTE_IMG:
80 return ifw::fnd::datatype::DataType::BYTE;
81 case SHORT_IMG:
82 return ifw::fnd::datatype::DataType::INT16;
83 case USHORT_IMG:
84 return ifw::fnd::datatype::DataType::UINT16;
85 case LONG_IMG:
86 return ifw::fnd::datatype::DataType::INT32;
87 case FLOAT_IMG:
88 return ifw::fnd::datatype::DataType::FLOAT;
89 case LONGLONG_IMG:
90 return ifw::fnd::datatype::DataType::INT64;
91 case DOUBLE_IMG:
92 return ifw::fnd::datatype::DataType::DOUBLE;
93 default:
94 return ifw::fnd::datatype::DataType::INVALID;
95 }
96 }
97
98}
99
100#endif // RTMSTOOLS2_COMMON_LLNETIO_HPP_
Logger source file.
Definition common.cpp:16
void Sleep(const double sleep_time)
Definition common.hpp:50
ifw::fnd::datatype::DataType BitpixToIfwDataType(const int8_t bitpix)
Definition common.hpp:77
void HandleCfitsioError(const std::string &operation, const int cfitsio_status)
Definition common.cpp:81
int BitpixToFitsDatatype(const int bitpix)
Definition common.hpp:60
double Time()
Definition common.hpp:43
std::tuple< std::vector< uint8_t >, int, int, int, int > LoadFitsImageCube(const char *filename)
Definition common.cpp:21
int8_t __rtmstools_debug__
Definition common.cpp:18
constexpr const char * RTMSTOOLS_DEBUG
Definition common.hpp:26