ifw-daq  3.0.0-pre2
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  std::string id;
44  std::vector<SourceTypes> sources;
45 };
46 
47 /**
48  * Parse JSON to construct the DpSpec structure
49  *
50  * @param spec Data Product Specification to parse.
51  * @throw DpSpecError if JSON structure is invalid. Exception may be nested.
52  */
53 DpSpec ParseDpSpec(nlohmann::json const& spec);
54 
55 /**
56  * Describes parsed location string into its components "host" and "path".
57  */
58 struct Location {
59  /**
60  * @returns `host:path` if host is not empty, otherwise just `path`
61  */
62  std::string RsyncPath() const;
63  std::string host;
64  std::filesystem::path path;
65 };
66 
67 /**
68  * Parse location string from DpSpec into component parts.
69  *
70  * Location string use the format `host:path`, e.g. `10.0.0.1:/path/to/file` with host being optional.
71  */
72 Location ParseSourceLocation(std::string const& location);
73 
74 
75 void to_json(nlohmann::json& j, DpSpec const& s); // NOLINT
76 void to_json(nlohmann::json& j, DpSpec::Target const& s); // NOLINT
77 void to_json(nlohmann::json& j, DpSpec::SourceTypes const& s); // NOLINT;
78 
79 } // namespace daq::json
80 
81 #endif // #ifndef DAQ_DPM_DP_SPEC_HPP
Contains data structure for FITS keywords.
std::string id
Definition: dpSpec.hpp:42
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
std::optional< FitsFileSource > source
Definition: dpSpec.hpp:37
std::vector< SourceTypes > sources
Definition: dpSpec.hpp:44
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:58
std::filesystem::path path
Definition: dpSpec.hpp:64
std::string RsyncPath() const
Definition: dpSpec.cpp:121
std::string host
Definition: dpSpec.hpp:63
JSON Schema error.
Definition: schemaError.hpp:18