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