From 49dafdd2b2934613cc9cc78d8c688ed093b687ce Mon Sep 17 00:00:00 2001 From: Robert Butora <robert.butora@inaf.it> Date: Fri, 27 Sep 2024 21:30:12 +0200 Subject: [PATCH] vlkb: in overlap replace json_request with json_region --- .../engine/src/common/include/cutout.hpp | 1 + data-access/engine/src/common/src/cutout.cpp | 14 ++++ .../engine/src/common/src/json_region.hpp | 68 +++++++++++++++++++ data-access/engine/src/vlkb/src/ast.cpp | 14 ---- .../{common => vlkbd}/src/json_request.cpp | 0 .../include => vlkbd/src}/json_request.hpp | 0 6 files changed, 83 insertions(+), 14 deletions(-) create mode 100644 data-access/engine/src/common/src/json_region.hpp rename data-access/engine/src/{common => vlkbd}/src/json_request.cpp (100%) rename data-access/engine/src/{common/include => vlkbd/src}/json_request.hpp (100%) diff --git a/data-access/engine/src/common/include/cutout.hpp b/data-access/engine/src/common/include/cutout.hpp index 65216f8..72adb2f 100644 --- a/data-access/engine/src/common/include/cutout.hpp +++ b/data-access/engine/src/common/include/cutout.hpp @@ -84,6 +84,7 @@ struct coordinates std::vector<std::string> pol; // polarization states FIXME pol should be Set<enums> }; + coordinates parse_coordinates(const std::string region_string); coordinates to_coordinates(const position pos, const band bnd, const time_axis time, const std::vector<std::string> pol); diff --git a/data-access/engine/src/common/src/cutout.cpp b/data-access/engine/src/common/src/cutout.cpp index b1875b3..5fd4e5c 100644 --- a/data-access/engine/src/common/src/cutout.cpp +++ b/data-access/engine/src/common/src/cutout.cpp @@ -1,4 +1,5 @@ +#include "json_region.hpp" #include "cutout.hpp" #include "fitsfiles.hpp" #include "fits_header.hpp" @@ -200,6 +201,19 @@ string to_cfitsio_format_with_axis_type(vector<uint_bounds> bounds) } +coordinates parse_coordinates(const string region_string) +{ + LOG_trace(string(__func__) + " : " + region_string); + + json_region reg(region_string); + coordinates coord = to_coordinates(reg.get_pos(), reg.get_band(), reg.get_time(), reg.get_pol()); + + LOG_STREAM << "coord parsed: " << coord << endl; + + return coord; +} + + coordinates to_coordinates(const position pos, const band bnd, const time_axis time, const std::vector<std::string> pol) { coordinates coord; diff --git a/data-access/engine/src/common/src/json_region.hpp b/data-access/engine/src/common/src/json_region.hpp new file mode 100644 index 0000000..f45fe6e --- /dev/null +++ b/data-access/engine/src/common/src/json_region.hpp @@ -0,0 +1,68 @@ + +#include "cutout.hpp" +#include "cutout_nljson.hpp" +#include "mcutout.hpp" +#include "mcutout_nljson.hpp" + +#include "json.hpp" +#include "io.hpp" +#include <string> +#include <vector> + +using json = nlohmann::json; + +/* All nlohmann-json exception are json::exception <- std::exception. + * So let them be caught by std::excpetion as 'Internal errors' in rpc-call's infinite loop, + * assuming all API syntactic errors were caught in servlet API parser + */ + + +class json_region +{ + public: + + json_region(std::string request_json) + { + LOG_trace(__func__); + + const bool ASSERTS = true; + m_jservice = json::parse(request_json, nullptr, ASSERTS); + + LOG_STREAM << m_jservice.dump() << std::endl; + } + + + position get_pos() + { + return (m_jservice.contains("pos") ? (position) m_jservice.at("pos") : pos_none ); + } + + + band get_band() + { + return (m_jservice.contains("band") ? (band) m_jservice.at("band") : band_none); + } + + + time_axis get_time() + { + return (m_jservice.contains("time") ? (time_axis) m_jservice.at("time") : time_none); + } + + + std::vector<std::string> get_pol() + { + std::vector<std::string> str; + if(m_jservice.contains("pol")) + { + json j = m_jservice.at("pol"); + str = j.get<std::vector<std::string>>(); + } + return str; + } + + + private: + json m_jservice; +}; + diff --git a/data-access/engine/src/vlkb/src/ast.cpp b/data-access/engine/src/vlkb/src/ast.cpp index 562afb2..e01ff01 100644 --- a/data-access/engine/src/vlkb/src/ast.cpp +++ b/data-access/engine/src/vlkb/src/ast.cpp @@ -6,7 +6,6 @@ #include "cutout_ostream.hpp" #include "service_string.hpp" #include "fitsfiles.hpp" // header-string needed -#include "json_request.hpp" // uses json for vlkb-overlap region-string #include "io.hpp" #include "my_assert.hpp" @@ -149,19 +148,6 @@ vector<string> split (const string &s, char delim) } -coordinates parse_coordinates(const string region_string) -{ - LOG_trace(string(__func__) + " : " + region_string); - - json_request req(region_string); - coordinates coord = to_coordinates(req.get_pos(), req.get_band(), req.get_time(), req.get_pol()); - - LOG_STREAM << "coord parsed: " << coord << endl; - - return coord; -} - - int vlkb_overlap(const string& pathname, const string& region, vector<uint_bounds>& bnds) { LOG_trace(__func__); diff --git a/data-access/engine/src/common/src/json_request.cpp b/data-access/engine/src/vlkbd/src/json_request.cpp similarity index 100% rename from data-access/engine/src/common/src/json_request.cpp rename to data-access/engine/src/vlkbd/src/json_request.cpp diff --git a/data-access/engine/src/common/include/json_request.hpp b/data-access/engine/src/vlkbd/src/json_request.hpp similarity index 100% rename from data-access/engine/src/common/include/json_request.hpp rename to data-access/engine/src/vlkbd/src/json_request.hpp -- GitLab