ifw-daq  3.0.1
IFW Data Acquisition modules
conversion.hpp
Go to the documentation of this file.
1 /**
2  * @file
3  * @ingroup daq_libdaq
4  * @copyright 2022 ESO - European Southern Observatory
5  *
6  * @brief Contains support functions for daqif
7  */
8 #ifndef DAQ_CONVERSION_HPP_
9 #define DAQ_CONVERSION_HPP_
10 #include "config.hpp"
11 
12 #include <daqif/state.hpp>
13 
14 #include <chrono>
15 #include <filesystem>
16 #include <string_view>
17 
18 namespace daq {
19 struct Status;
20 enum class State;
21 
22 /**
23  * Convert daq::Status -> daqif::DaqStatus by populating from @a rhs.
24  */
25 daqif::DaqStatus& operator<<(daqif::DaqStatus& status, Status const& rhs);
26 
27 template <class Clock, class Duration = typename Clock::duration>
28 double FromTimePoint(std::chrono::time_point<Clock, Duration> const& time);
29 
30 template <class Clock, class Duration = typename Clock::duration>
31 std::chrono::time_point<Clock, Duration> ToTimePoint(double time);
32 
33 /**
34  * Convert daqif::DaqStatus -> daq::Status by populating from @a rhs.
35  */
36 Status& operator<<(Status& status, daqif::DaqStatus const& rhs);
37 
38 /**
39  * Populate @a space from @a rhs.
40  */
41 std::filesystem::space_info&
42 operator<<(std::filesystem::space_info& space, daqif::StorageStatus const& rhs);
43 
44 /**
45  * Populate @a storage from @a rhs.
46  */
47 daqif::StorageStatus& operator<<(daqif::StorageStatus& storage, std::filesystem::space_info& rhs);
48 
49 /**
50  * Converts daq::State to DaqSubstate.
51  */
52 daqif::FullState MakeState(State state) noexcept;
53 
54 /**
55  * Converts the full state to daq::State.
56  */
57 daq::State MakeState(daqif::FullState state) noexcept;
58 
59 /**
60  * @return string representation of enumeration.
61  */
62 std::string_view ToString(daqif::DaqState state) noexcept;
63 
64 /**
65  * @return string representation of enumeration.
66  */
67 std::string_view ToString(daqif::DaqSubState state) noexcept;
68 
69 template <class Clock, class Duration>
70 double FromTimePoint(std::chrono::time_point<Clock, Duration> const& time) {
71  using Seconds = std::chrono::duration<double, std::ratio<1>>;
72  return std::chrono::time_point_cast<Seconds>(time).time_since_epoch().count();
73 }
74 
75 template <class Clock, class Duration>
76 std::chrono::time_point<Clock, Duration> ToTimePoint(double duration) {
77  using Seconds = std::chrono::duration<double, std::ratio<1>>;
78  return std::chrono::time_point<Clock, Duration>(
79  std::chrono::duration_cast<Duration>(Seconds(duration)));
80 }
81 } // namespace daq
82 #endif // #ifndef DAQ_CONVERSION_HPP_
Contains State support functions for daqif.
daqif::FullState MakeState(State state) noexcept
Converts daq::State to DaqSubstate.
Definition: conversion.cpp:63
std::string_view ToString(daqif::DaqState state) noexcept
Definition: conversion.cpp:146
std::ostream & operator<<(std::ostream &os, AsyncProcessIf const &proc)
Formats proc representation in the form [<pid>] <args>
State
Observable states of the data acquisition process.
Definition: state.hpp:39
double FromTimePoint(std::chrono::time_point< Clock, Duration > const &time)
Definition: conversion.hpp:70
std::chrono::time_point< Clock, Duration > ToTimePoint(double time)
Definition: conversion.hpp:76
Describes the full state and substate.
Definition: state.hpp:17
Config class header file.