ifw-daq  3.0.1
IFW Data Acquisition modules
dpSpec.hpp
Go to the documentation of this file.
1 /**
2  * @file
3  * @ingroup daq_libjson
4  * @copyright ESO - European Southern Observatory
5  */
6 #ifndef DAQ_DPM_DP_SPEC_HPP
7 #define DAQ_DPM_DP_SPEC_HPP
8 #include <filesystem>
9 #include <optional>
10 #include <string>
11 #include <string_view>
12 #include <variant>
13 #include <vector>
14 
15 #include <nlohmann/json.hpp>
16 
17 #include <daq/fits/keyword.hpp>
19 #include <daq/json/schemaError.hpp>
20 
21 namespace daq::json {
22 
24  using SchemaError::SchemaError;
25 };
26 
27 /**
28  * Close representation of the JSON structure but with stronger types.
29  */
30 struct DpSpec {
31  struct Target {
32  std::string file_id;
33  /**
34  * Optioal user chosen file prefix to make it easier to identify the produced file.
35  */
36  std::string file_prefix;
37  std::optional<FitsFileSource> source;
38  };
39 
40  using SourceTypes = std::variant<FitsKeywordsSource, FitsFileSource>;
41 
42  /**
43  * DAQ id.
44  */
45  std::string id;
46  /**
47  * Describes target which will become the data produtc.
48  */
50 
51  /**
52  * List of sources to create data product from.
53  */
54  std::vector<SourceTypes> sources;
55 
56  /**
57  * Ordered container of receivers where to deliver the target data product.
58  */
60 };
61 
62 /**
63  * Parse JSON to construct the DpSpec structure
64  *
65  * @param spec Data Product Specification to parse.
66  * @throw DpSpecError if JSON structure is invalid. Exception may be nested.
67  */
68 DpSpec ParseDpSpec(nlohmann::json const& spec);
69 
70 /**
71  * Describes parsed location string into its components "host" and "path".
72  */
73 struct Location {
74  /**
75  * @returns `host:path` if host is not empty, otherwise just `path`
76  */
77  std::string RsyncPath() const;
78  std::string host;
79  std::filesystem::path path;
80 };
81 
82 /**
83  * Parse location string from DpSpec into component parts.
84  *
85  * Location string use the format `host:path`, e.g. `10.0.0.1:/path/to/file` with host being
86  * optional.
87  */
88 Location ParseSourceLocation(std::string const& location);
89 
90 void to_json(nlohmann::json& j, DpSpec const& s); // NOLINT
91 void to_json(nlohmann::json& j, DpSpec::Target const& s); // NOLINT
92 void to_json(nlohmann::json& j, DpSpec::SourceTypes const& s); // NOLINT
93 
94 } // namespace daq::json
95 
96 #endif // #ifndef DAQ_DPM_DP_SPEC_HPP
Contains data structure for FITS keywords.
std::string id
DAQ id.
Definition: dpSpec.hpp:45
Location ParseSourceLocation(std::string const &location_str)
Parse location string from DpSpec into component parts.
Definition: dpSpec.cpp:90
DpSpec ParseDpSpec(Json const &json)
Parse JSON to construct the DpSpec structure.
Definition: dpSpec.cpp:47
Target target
Describes target which will become the data produtc.
Definition: dpSpec.hpp:49
std::optional< FitsFileSource > source
Definition: dpSpec.hpp:37
ReceiverList receivers
Ordered container of receivers where to deliver the target data product.
Definition: dpSpec.hpp:59
std::vector< SourceTypes > sources
List of sources to create data product from.
Definition: dpSpec.hpp:54
std::vector< ReceiverTypes > ReceiverList
std::variant< FitsKeywordsSource, FitsFileSource > SourceTypes
Definition: dpSpec.hpp:40
std::string file_prefix
Optioal user chosen file prefix to make it easier to identify the produced file.
Definition: dpSpec.hpp:36
void to_json(nlohmann::json &out, KeywordFilter const &s)
Close representation of the JSON structure but with stronger types.
Definition: dpSpec.hpp:30
Describes parsed location string into its components "host" and "path".
Definition: dpSpec.hpp:73
std::filesystem::path path
Definition: dpSpec.hpp:79
std::string RsyncPath() const
Definition: dpSpec.cpp:121
std::string host
Definition: dpSpec.hpp:78
JSON Schema error.
Definition: schemaError.hpp:18