ifw-daq 3.1.0
IFW Data Acquisition modules
Loading...
Searching...
No Matches
dictKeywordFormatter.hpp
Go to the documentation of this file.
1/**
2 * @file
3 * @copyright
4 * (c) Copyright ESO 2024
5 * All Rights Reserved
6 * ESO (eso.org) is an Intergovernmental Organisation, and therefore special legal conditions apply.
7 */
8#ifndef OCM_SERVER_DICTKEYWORDFORMATTER_HPP
9#define OCM_SERVER_DICTKEYWORDFORMATTER_HPP
10
11#include <daq/fits/keyword.hpp>
12
13#include <core/dit/did/did.hpp>
14
15namespace daq {
16
17/**
18 * Format (and validate) keyword according to loaded dictionary. Unknown keywords are rejected.
19 */
21public:
23
24 /**
25 * Load dictionaries or throw exception if not found.
26 * @param dictionaries List of dictionaries to load.
27 */
28 void Load(std::vector<std::string> const& dictionaries);
29
30 /**
31 * @return List of loaded dictionaries.
32 */
33 auto GetDictionaries() const noexcept -> std::vector<std::string> const&;
34
35 /**
36 * @return List of loaded dictionaries as comma separated string.
37 */
38 auto GetDictionariesNames() const -> std::string;
39
40 /**
41 * Look up keyword from loaded dictionaries and format using `Format(fits::KeywordVariant
42 * const&, core::dit::did::Record cont&)`.
43 *
44 * @param keyword keyword to format.
45 * @throw UnknownKeyword if keyword is not in any of the loaded dictionaries.
46 * @throw InvalidKeyword if keyword fails validation.
47 */
48 auto Format(fits::KeywordVariant const& keyword) const -> fits::LiteralKeyword override;
49
50private:
51 std::vector<std::string> m_dictionaries;
52 core::dit::did::Did m_did;
53};
54
55/**
56 * Format and validates using keyword dictionary record.
57 *
58 * Given the keyword the function will check:
59 * - Value type is compatible (int64_t and uint64_t can be promoted to double).
60 * - Parse value if value type is a double.
61 * - If format specifier is provided:
62 * Reformat value for floating point type according to format specification.
63 * - Use comment from @a record if none is provided already.
64 *
65 * @note
66 * ditlib from ifw-core does not make a distinction between HIERARCH ESO keywords and
67 * FITS value keywords.
68 *
69 * When parsing floating point value from a LiteralKeyword there is no check that the parsed
70 * value has more or equal number of decimal places than the requested formatting.
71 */
72auto Format(fits::KeywordVariant const& kw, core::dit::did::Record const& record)
73 -> fits::LiteralKeyword;
74
75} // namespace daq
76#endif // OCM_SERVER_DICTKEYWORDFORMATTER_HPP
Format (and validate) keyword according to loaded dictionary.
auto GetDictionaries() const noexcept -> std::vector< std::string > const &
void Load(std::vector< std::string > const &dictionaries)
Load dictionaries or throw exception if not found.
auto GetDictionariesNames() const -> std::string
auto Format(fits::KeywordVariant const &keyword) const -> fits::LiteralKeyword override
Look up keyword from loaded dictionaries and format using Format(fits::KeywordVariant const&,...
Formats keyword against e.g.
Definition: keyword.hpp:551
Represents the literal 80-character FITS keyword record.
Definition: keyword.hpp:129
Contains data structure for FITS keywords.
std::variant< ValueKeyword, EsoKeyword, LiteralKeyword > KeywordVariant
The different variants of keywords that are supported.
Definition: keyword.hpp:409