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