11 #include <fmt/format.h>
15 using Json = nlohmann::json;
34 AssertIsObject<ErrorType>(json, breadcrumb);
37 if (json.contains(
"initialKeywords")) {
41 if (json.contains(
"keywordRules")) {
51 AssertIsObject<StartDaqV2SpecError>(json, breadcrumb);
53 if (json.contains(
"id")) {
57 if (json.contains(
"filePrefix")) {
61 if (json.contains(
"awaitCompletionInterval")) {
65 throw MakeParseException<ErrorType>(breadcrumb /
"awaitCompletionInterval",
66 "interval must be > 0.0s");
69 std::chrono::duration_cast<std::chrono::milliseconds>(
70 std::chrono::duration<double>(value));
74 auto [json_sources, breadcrumb_sources] = GetMember<ErrorType>(
75 json,
"sources", breadcrumb, [](
Json const& member,
JsonPointer const& breadcrumb) {
76 AssertIsArray<ErrorType>(member, breadcrumb);
79 for (
auto const& json_source : json_sources) {
80 auto breadcrumb_source = breadcrumb_sources / index;
83 if (source_type ==
"primaryDataSource") {
86 result.
sources.emplace_back(std::move(s));
87 }
else if (source_type ==
"metadataSource") {
90 result.
sources.emplace_back(std::move(s));
91 }
else if (source_type ==
"fitsKeywords") {
93 result.
sources.emplace_back(std::move(kws));
94 }
else if (source_type ==
"fitsFile") {
96 result.
sources.emplace_back(std::move(file));
98 throw MakeUnknownVariantException<ErrorType>(
99 breadcrumb_source /
"type",
100 "'primaryDataSource', 'metadataSource', 'fitsFile' or 'fitsKeywords'",
101 source_type.c_str());
111 }
catch (std::exception
const& e) {
112 std::throw_with_nested(
119 return lhs.source_name == rhs.source_name && lhs.rr_uri == rhs.rr_uri &&
120 lhs.keyword_rules == rhs.keyword_rules;
125 return lhs.source_name == rhs.source_name && lhs.rr_uri == rhs.rr_uri &&
126 lhs.keyword_rules == rhs.keyword_rules;
131 return lhs.source_name == rhs.source_name;
135 return lhs.id == rhs.id && lhs.file_prefix == rhs.file_prefix &&
136 lhs.await_completion_interval == rhs.await_completion_interval &&
137 lhs.merge_target == rhs.merge_target && lhs.sources == rhs.sources;
154 out[
"type"] =
"primaryDataSource";
160 out[
"type"] =
"metadataSource";
165 std::visit([&](
auto const& ds) {
to_json(out, ds); }, s);
175 json = nlohmann::json{
178 json[
"awaitCompletionInterval"] = std::chrono::duration_cast<std::chrono::duration<double>>(
nlohmann::json_pointer< Json > JsonPointer
StartDaqV2SpecError ErrorType
KeywordRules ParseKeywordRules(Json const &json, JsonPointer const &breadcrumb)
InitialKeywords ParseInitialKeywords(nlohmann::json const &json, nlohmann::json_pointer< nlohmann::json > const &breadcrumb)
std::optional< MergeTarget > merge_target
std::optional< std::chrono::milliseconds > await_completion_interval
void ParseDataSource(StartDaqV2Spec::DataSource &out, Json const &json, JsonPointer const &breadcrumb)
Parse the common parts of PrimaryDataSource and MetadataSource.
FitsFileSource ParseFitsFileSource(Json const &json, JsonPointer const &breadcrumb)
bool operator==(KeywordFilter const &lhs, KeywordFilter const &rhs) noexcept
FitsKeywordsSource ParseFitsKeywordsSource(Json const &json, JsonPointer const &breadcrumb)
std::variant< PrimaryDataSource, MetadataSource, FitsKeywordsSource, FitsFileSource > DataSourceTypes
StartDaqV2Spec ParseStartDaqV2Spec(nlohmann::json const &json)
Parse StartDaqSpec.
void to_json(nlohmann::json &out, KeywordFilter const &s)
std::vector< DataSourceTypes > sources
Structure with a close mapping from JSON representation in the StartDaqV2 MAL request.
static T Get(Json const &json, char const *name, JsonPointer const &breadcrumb, bool allow_empty=true)
KeywordRules keyword_rules
std::optional< InitialKeywords > initial_keywords