ifw-daq 3.1.0
IFW Data Acquisition modules
Loading...
Searching...
No Matches
daqContext.hpp
Go to the documentation of this file.
1/**
2 * @file
3 * @ingroup daq_common_libdaq
4 * @copyright 2022 ESO - European Southern Observatory
5 *
6 * @brief Contains declaration of `daq::Context`.
7 */
8#ifndef OCM_DAQ_DAQ_CONTEXT_HPP_
9#define OCM_DAQ_DAQ_CONTEXT_HPP_
10#include <daq/config.hpp>
11
12#include <chrono>
13#include <string>
14
15#include <daq/dpPart.hpp>
16#include <daq/fits/keyword.hpp>
18
19namespace daq {
20
21/**
22 * Structure carrying context needed to start a Data Acquisition and construct a Data Product
23 * Specification needed to execute merge.
24 *
25 * This information can be serialized and deserialized to facilitate persitant storage.
26 *
27 * In practice this means it must contain:
28 * - Data sources
29 * - Results from acquisition phase (files and keywords)
30 * - Per-DAQ User options
31 *
32 * When creating a Data Product Specification consider:
33 *
34 * - `results` contain files and keywords from data sources and `keywords` the user-provided
35 * keywords via request/reply interface (StartDaq/UpdateKeywords). Both must be considered
36 * when creating the final Data Product Specification.
37 * - `results` is not sorted according.
38 *
39 * @seealso daq::Status
40 * @ingroup daq_common_libdaq
41 */
42struct DaqContext {
43 struct Source {
44 std::string name;
45 std::string rr_uri;
46 };
47 DaqContext() = default;
48 DaqContext(DaqContext const&) = default;
49 DaqContext(DaqContext&&) = default;
51 DaqContext& operator=(DaqContext const&) = default;
52
53 /**
54 * DAQ identfier, possibly provided by user.
55 *
56 * If user does not provide an id for the DAQ when starting it is identical to `file_id`.
57 */
58 std::string id;
59
60 /**
61 * Data Product @a FileId as specified by OLAS ICD.
62 */
63 std::string file_id;
64
65 /**
66 * User defined process name.
67 */
68 std::string process_name;
69
70 /**
71 * Data product file name prefix
72 */
73 std::string dp_name_prefix;
74 std::vector<Source> prim_sources;
75 std::vector<Source> meta_sources;
76
77 /**
78 * Keyword list provided by OCM to Data Product.
79 *
80 * Keywords comes from:
81 * - StartDaq() request
82 * - UpdateKeywords() request
83 * - OCM internal keywords.
84 */
85 std::vector<daq::fits::KeywordVariant> keywords;
86
87 /**
88 * Interval (and thus duration) of the requests sent to primary sources
89 * to await end of recording.
90 * Default is 10 seconds.
91 */
92 std::chrono::milliseconds await_interval = std::chrono::seconds(10);
93
94 /**
95 * Results from Data Acquisition (FITS files and keywords).
96 *
97 * @note The sources are sorted by order of creation, not order they should appear in
98 * DpSpec!
99 */
101
102 /**
103 * Time when DAQ was created. This should correspond to the exact time used for generating the
104 * file_id.
105 */
106 std::chrono::system_clock::time_point creation_time;
107
108 /**
109 * Optional specification, if DAQ was started using StartDaqV2.
110 *
111 * Some fields are duplicated or provided in different format, like dp_name_prefix, prim_sources
112 * and meta_sources.
113 */
114 std::optional<json::StartDaqV2Spec> specification;
115};
116
117bool operator==(DaqContext const& lhs, DaqContext const& rhs) noexcept;
118bool operator==(DaqContext::Source const& lhs, DaqContext::Source const& rhs) noexcept;
119
120/**
121 * Updates (adds or replaces) primary HDU keywords.
122 *
123 * @param out Keywords to update to.
124 * @param in Keywords to format and update from.
125 * @param fmt Keyword formatter.
126 *
127 * @throws fits::UnknownKeyword if keyword is unknown.
128 * @throws std::invalid_argument if an invalid keyword is encountered.
129 */
131 fits::KeywordVector const& in,
132 fits::KeywordFormatter const& fmt);
133/**
134 * Updates (adds or replaces) primary HDU keywords.
135 *
136 * @param ctx Context to modify
137 * @param keywords Keywords to format and update from.
138 * @param fmt Keyword formatter.
139 *
140 * @throws fits::UnknownKeyword if keyword is unknown.
141 * @throws std::invalid_argument if an invalid keyword is encountered.
142 */
143void UpdateKeywords(DaqContext& ctx,
144 fits::KeywordVector const& keywords,
145 fits::KeywordFormatter const& fmt);
146
147/*
148 * Records that a file has been produced for this data acquisition.
149 *
150 * @param ctx Context to modify.
151 * @param files Files to add/record.
152 *
153 * @post Connected observers have been signalled.
154 */
155void AddDpParts(DaqContext& ctx, std::vector<DpPart> const& files);
156
157} // namespace daq
158#endif // #ifndef OCM_DAQ_DAQ_CONTEXT_HPP_
Formats keyword against e.g.
Definition: keyword.hpp:551
Contains declaration for DpPart.
Contains data structure for FITS keywords.
std::vector< KeywordVariant > KeywordVector
Vector of keywords.
Definition: keyword.hpp:423
void UpdateKeywords(fits::KeywordVector &out, fits::KeywordVector const &in, fits::KeywordFormatter const &fmt)
Updates (adds or replaces) primary HDU keywords.
Definition: daqContext.cpp:24
void AddDpParts(DaqContext &ctx, std::vector< DpPart > const &parts)
Definition: daqContext.cpp:47
bool operator==(DaqContext const &lhs, DaqContext const &rhs) noexcept
Definition: daqContext.cpp:12
std::vector< DpPart > DpParts
Definition: dpPart.hpp:66
Structure carrying context needed to start a Data Acquisition and construct a Data Product Specificat...
Definition: daqContext.hpp:42
std::vector< Source > meta_sources
Definition: daqContext.hpp:75
DpParts results
Results from Data Acquisition (FITS files and keywords).
Definition: daqContext.hpp:100
std::string process_name
User defined process name.
Definition: daqContext.hpp:68
std::vector< daq::fits::KeywordVariant > keywords
Keyword list provided by OCM to Data Product.
Definition: daqContext.hpp:85
std::vector< Source > prim_sources
Definition: daqContext.hpp:74
DaqContext(DaqContext const &)=default
std::chrono::milliseconds await_interval
Interval (and thus duration) of the requests sent to primary sources to await end of recording.
Definition: daqContext.hpp:92
std::optional< json::StartDaqV2Spec > specification
Optional specification, if DAQ was started using StartDaqV2.
Definition: daqContext.hpp:114
std::string file_id
Data Product FileId as specified by OLAS ICD.
Definition: daqContext.hpp:63
DaqContext & operator=(DaqContext const &)=default
std::string dp_name_prefix
Data product file name prefix.
Definition: daqContext.hpp:73
std::chrono::system_clock::time_point creation_time
Time when DAQ was created.
Definition: daqContext.hpp:106
DaqContext & operator=(DaqContext &&)=default
DaqContext(DaqContext &&)=default
std::string id
DAQ identfier, possibly provided by user.
Definition: daqContext.hpp:58
DaqContext()=default