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},
44 {
"timestamp", MakeTimestamp(p.
timestamp)}};
49 j = nlohmann::json{{
"category", p.
id.
category},
52 {
"timestamp", MakeTimestamp(p.
timestamp)}};
61 {
"creationTime", std::chrono::nanoseconds(p.
creation_time.time_since_epoch()).count()},
66 {
"keywords", std::move(kws)},
78 j = nlohmann::json{{
"name", p.
name}, {
"rrUri", p.
rr_uri}};
83 if (std::holds_alternative<fits::KeywordVector>(p.
Part())) {
86 j = nlohmann::json::object(
87 {{
"type",
"fitsKeywords"}, {
"sourceName", p.
SourceName()}, {
"keywords", std::move(kws)}});
88 }
else if (std::holds_alternative<std::string>(p.
Part())) {
89 auto const& path = std::get<std::string>(p.
Part());
90 j = nlohmann::json::object(
91 {{
"type",
"fitsFile"}, {
"sourceName", p.
SourceName()}, {
"location", path}});
97 j.at(
"id").get_to(p.
id);
98 j.at(
"fileId").get_to(p.
file_id);
99 j.at(
"state").get_to(p.
state);
100 j.at(
"error").get_to(p.
error);
101 j.at(
"alerts").get_to(p.
alerts);
102 j.at(
"result").get_to(p.
result);
104 j.at(
"timestamp").get_to(ts);
111 j.at(
"key").get_to(p.
id.
key);
114 j.at(
"timestamp").get_to(ts);
120 j.at(
"id").get_to(p.
id);
121 j.at(
"fileId").get_to(p.
file_id);
127 j.at(
"awaitInterval").get_to(interval);
129 j.at(
"dpParts").get_to(p.
results);
131 int64_t time_since_epoch_ns;
132 j.at(
"creationTime").get_to(time_since_epoch_ns);
133 using Time = std::chrono::system_clock::time_point;
134 p.
creation_time = Time(std::chrono::nanoseconds(time_since_epoch_ns));
136 if (j.contains(
"specification")) {
143 j.at(
"name").get_to(p.
name);
144 j.at(
"rrUri").get_to(p.
rr_uri);
151 j.at(
"type").get_to(type);
154 if (type ==
"fitsKeywords") {
156 }
else if (type ==
"fitsFile") {
158 j.at(
"location").get_to(path);
161 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.
NLOHMANN_JSON_SERIALIZE_ENUM(State, { {State::NotStarted, "NotStarted"}, {State::Starting, "Starting"}, {State::Acquiring, "Acquiring"}, {State::Stopping, "Stopping"}, {State::Stopped, "Stopped"}, {State::NotScheduled, "NotScheduled"}, {State::Scheduled, "Scheduled"}, {State::Transferring, "Transferring"}, {State::Merging, "Merging"}, {State::Releasing, "Releasing"}, {State::AbortingAcquiring, "AbortingAcquiring"}, {State::AbortingMerging, "AbortingMerging"}, {State::Aborted, "Aborted"}, {State::Completed, "Completed"}, }) void to_json(nlohmann void to_json(nlohmann::json &j, Alert 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.
Non observable status object that keeps stores status of data acquisition.
std::string result
Path to resulting data product.
std::vector< Alert > alerts
Active alerts.