ifw-daq  1.0.0
IFW Data Acquisition modules
conversion.cpp
Go to the documentation of this file.
1 /**
2  * @file
3  * @ingroup daq_ocm_libocmif_suppport
4  * @copyright 2021 ESO - European Southern Observatory
5  *
6  * @brief Contains definitions for ocmif/conversion.hpp
7  */
8 #include <ocmif/conversion.hpp>
9 #include <string_view>
10 #include <fmt/format.h>
11 
12 #include <daq/status.hpp>
13 #include <daq/state.hpp>
14 
15 namespace ocmif {
16 
17 DaqStatus& operator<<(DaqStatus& status, daq::Status const& rhs) {
18  using Seconds = std::chrono::duration<double, std::ratio<1>>;
19  status.setId(rhs.id);
20  // @todo Refactor interal representation to also cover toplevel state
21  status.setState(rhs.state == daq::State::Aborted ? ocmif::StateCompleted
22  : ocmif::StateAcquiring);
23  status.setSubState(MakeState(rhs.state));
24  status.setError(rhs.error);
25  status.setTimestamp(
26  std::chrono::time_point_cast<Seconds>(rhs.timestamp).time_since_epoch().count());
27  status.setMessage("");
28 
29  return status;
30 }
31 
32 ocmif::DaqSubState MakeState(daq::State state) noexcept {
33  using namespace daq;
34  switch (state) {
35  case State::NotStarted:
36  return ocmif::NotStarted;
37  case State::Starting:
38  return ocmif::Starting;
39  case State::Acquiring:
40  return ocmif::Acquiring;
41  case State::Stopping:
42  return ocmif::Stopping;
43  case State::Stopped:
44  return ocmif::Stopped;
45  case State::Aborting:
46  return ocmif::Aborting;
47  case State::Aborted:
48  return ocmif::Aborted;
49  // GCOVR_EXCL_START
50  default:
51  return ocmif::Undefined;
52  // GCOVR_EXCL_STOP
53  };
54 }
55 
56 daq::State MakeState(ocmif::DaqSubState state) {
57  using namespace daq;
58  switch (state) {
59  case ocmif::NotStarted:
60  return State::NotStarted;
61  case ocmif::Starting:
62  return State::Starting;
63  case ocmif::Acquiring:
64  return State::Acquiring;
65  case ocmif::Stopping:
66  return State::Stopping;
67  case ocmif::Stopped:
68  return State::Stopped;
69  case ocmif::Aborting:
70  return State::Aborting;
71  case ocmif::Aborted:
72  return State::Aborted;
73  default:
74  throw std::invalid_argument(fmt::format("Invalid ocmif::DaqSubState value {:d}", state));
75  };
76 }
77 
78 std::string_view ToString(ocmif::DaqState state) noexcept {
79  using namespace std::string_view_literals;
80  switch (state) {
81  case ocmif::StateAcquiring:
82  return "StateAcquiring";
83  case ocmif::StateMerging:
84  return "StateMerging";
85  case ocmif::StateCompleted:
86  return "StateCompleted";
87  case ocmif::DaqState::StateUndefined:
88  [[fallthrough]];
89  default:
90  return "Undefined";
91  };
92 }
93 
94 std::string_view ToString(ocmif::DaqSubState state) noexcept {
95  using namespace std::string_view_literals;
96  switch (state) {
97  case ocmif::DaqSubState::NotStarted:
98  return "NotStarted";
99  case ocmif::DaqSubState::Starting:
100  return "Starting";
101  case ocmif::DaqSubState::Acquiring:
102  return "Acquiring";
103  case ocmif::DaqSubState::Stopping:
104  return "Stopping";
105  case ocmif::DaqSubState::Stopped:
106  return "Stopped";
107  case ocmif::DaqSubState::Aborting:
108  return "Aborting";
109  case ocmif::DaqSubState::Aborted:
110  return "Aborted";
111  case ocmif::DaqSubState::NotScheduled:
112  return "NotScheduled";
113  case ocmif::DaqSubState::Scheduled:
114  return "Scheduled";
115  case ocmif::DaqSubState::Transferring:
116  return "Transferring";
117  case ocmif::DaqSubState::Merging:
118  return "Merging";
119  case ocmif::DaqSubState::Releasing:
120  return "Releasing";
121  case ocmif::DaqSubState::Completed:
122  return "Completed";
123  case ocmif::DaqSubState::Undefined:
124  [[fallthrough]];
125  default:
126  return "Undefined";
127  };
128 }
129 
130 } // namespace ocmif
ocmif::ToString
std::string_view ToString(ocmif::DaqState state) noexcept
Definition: conversion.cpp:78
daq::State
State
Observable states of the data acquisition process.
Definition: state.hpp:41
daq::Status::timestamp
TimePoint timestamp
Definition: status.hpp:56
daq::Status::state
State state
Definition: status.hpp:52
conversion.hpp
Contains support functions for ocmif.
daq
Definition: daqController.cpp:18
ocmif::operator<<
DaqStatus & operator<<(DaqStatus &status, daq::Status const &rhs)
Definition: conversion.cpp:17
ocmif::MakeState
ocmif::DaqSubState MakeState(daq::State state) noexcept
Converts daq::State to DaqSubstate.
Definition: conversion.cpp:32
daq::Status::error
bool error
Definition: status.hpp:53
daq::Status::id
std::string id
Definition: status.hpp:51
status.hpp
Contains declaration for Status and ObservableStatus.
ocmif
Definition: conversion.cpp:15
daq::Status
Non observable status object that keeps stores status of data acquisition.
Definition: status.hpp:32
state.hpp
Declares daq::State and related functions.
daq::State::NotStarted
@ NotStarted
Initial state of data acquisition.