12 #include <fmt/format.h>
21 template <
class Clock,
class Duration>
22 double MakeTimestamp(std::chrono::time_point<Clock, Duration>
const& ts) {
23 using Seconds = std::chrono::duration<double, std::ratio<1>>;
24 return std::chrono::time_point_cast<Seconds>(ts).time_since_epoch().count();
27 template <
class Clock,
class Duration>
28 void MakeTimepoint(std::chrono::time_point<Clock, Duration>& ts,
double time) {
29 using Seconds = std::chrono::duration<double, std::ratio<1>>;
30 ts = std::chrono::time_point<Clock, Duration>(
31 std::chrono::duration_cast<Duration>(Seconds(time)));
38 j = nlohmann::json{{
"id", p.
id},
45 {
"timestamp", MakeTimestamp(p.
timestamp)}};
50 j = nlohmann::json{{
"category", p.
id.
category},
53 {
"timestamp", MakeTimestamp(p.
timestamp)}};
58 j = nlohmann::json{{
"state", p.
state}};
67 {
"creationTime", std::chrono::nanoseconds(p.
creation_time.time_since_epoch()).count()},
72 {
"keywords", std::move(kws)},
84 j = nlohmann::json{{
"name", p.
name}, {
"rrUri", p.
rr_uri}};
89 if (std::holds_alternative<fits::KeywordVector>(p.
Part())) {
92 j = nlohmann::json::object(
93 {{
"type",
"fitsKeywords"}, {
"sourceName", p.
SourceName()}, {
"keywords", std::move(kws)}});
94 }
else if (std::holds_alternative<std::string>(p.
Part())) {
95 auto const& path = std::get<std::string>(p.
Part());
96 j = nlohmann::json::object(
97 {{
"type",
"fitsFile"}, {
"sourceName", p.
SourceName()}, {
"location", path}});
103 j.at(
"id").get_to(p.
id);
104 j.at(
"fileId").get_to(p.
file_id);
105 j.at(
"state").get_to(p.
state);
106 j.at(
"error").get_to(p.
error);
107 j.at(
"alerts").get_to(p.
alerts);
109 j.at(
"result").get_to(p.
result);
111 j.at(
"timestamp").get_to(ts);
118 j.at(
"key").get_to(p.
id.
key);
121 j.at(
"timestamp").get_to(ts);
127 j.at(
"state").get_to(p.
state);
132 j.at(
"id").get_to(p.
id);
133 j.at(
"fileId").get_to(p.
file_id);
139 j.at(
"awaitInterval").get_to(interval);
141 j.at(
"dpParts").get_to(p.
results);
143 int64_t time_since_epoch_ns;
144 j.at(
"creationTime").get_to(time_since_epoch_ns);
145 using Time = std::chrono::system_clock::time_point;
146 p.
creation_time = Time(std::chrono::nanoseconds(time_since_epoch_ns));
148 if (j.contains(
"specification")) {
155 j.at(
"name").get_to(p.
name);
156 j.at(
"rrUri").get_to(p.
rr_uri);
163 j.at(
"type").get_to(type);
166 if (type ==
"fitsKeywords") {
168 }
else if (type ==
"fitsFile") {
170 j.at(
"location").get_to(path);
173 throw std::invalid_argument(fmt::format(
"Invalid type: {}", type));
Provides information of the location and source of a FITS file or keywords produced by a data acquisi...
auto Part() const noexcept -> PartTypes const &
Holds a std::string path [[user]@host:]path or FITS keywords.
auto SourceName() const noexcept -> std::string const &
Source name of the part.
Declares JSON support for serialization.
Contains data structure for FITS keywords.
Contains declaration of daq::Context.
nlohmann::json SerializeJsonKeywords(std::vector< KeywordVariant > const &keywords)
SerializeJsons keyword to JSON.
std::vector< KeywordVariant > ParseJsonKeywords(char const *keywords)
Parse and return FITS keywords.
StartDaqV2Spec ParseStartDaqV2Spec(nlohmann::json const &json)
Parse StartDaqSpec.
std::string key
Unique key for each alert.
void from_json(nlohmann::json const &j, Status &p)
std::string category
Standardized category.
void to_json(nlohmann::json &j, Status const &p)
Describes an active Data Acquisition alert.
Contains declaration for Status and ObservableStatus.
Structure carrying context needed to start a Data Acquisition and construct a Data Product Specificat...
std::vector< Source > meta_sources
DpParts results
Results from Data Acquisition (FITS files and keywords).
std::string process_name
User defined process name.
std::vector< daq::fits::KeywordVariant > keywords
Keyword list provided by OCM to Data Product.
std::vector< Source > prim_sources
std::chrono::milliseconds await_interval
Interval (and thus duration) of the requests sent to primary sources to await end of recording.
std::optional< json::StartDaqV2Spec > specification
Optional specification, if DAQ was started using StartDaqV2.
std::string file_id
Data Product FileId as specified by OLAS ICD.
std::string dp_name_prefix
Data product file name prefix.
std::chrono::system_clock::time_point creation_time
Time when DAQ was created.
std::string id
DAQ identfier, possibly provided by user.
Persistent status for receiver delivery.
Non observable status object that keeps stores status of data acquisition.
std::string result
Path to resulting data product.
std::map< std::size_t, ReceiverStatus > receivers
Receiver processing (e.g.
std::vector< Alert > alerts
Active alerts.
TimePoint timestamp
Timestamp of last update.