ifw-daq  3.0.1
IFW Data Acquisition modules
state.cpp
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 Definitions from daq/state.hpp
7  */
8 #include <daq/state.hpp>
9 
10 #include <ostream>
11 #include <log4cplus/loggingmacros.h>
12 namespace daq {
13 
14 
15 bool IsFinalState(State state) noexcept {
16  switch (state) {
17  case State::Aborted:
18  case State::Completed:
19  return true;
20  default:
21  return false;
22  }
23 }
24 
25 bool IsAbortableState(State state) noexcept {
26  // If DAQ is already in final state it cannot be aborted.
27  return !IsFinalState(state);
28 }
29 
30 bool IsActiveDpmState(State state) noexcept {
31  switch (state) {
32  case State::Scheduled:
33  case State::Collecting:
34  case State::Merging:
35  case State::Releasing:
37  return true;
38  default:
39  return false;
40  }
41 }
42 
43 bool IsSubsequentState(State state1, State state2) noexcept {
44  if (state1 == state2) {
45  return false;
46  }
47  // If state2 is a final state1 it doesn't matter what state1 is, it cannot occur after a final state
48  if (IsFinalState(state2)) {
49  return false;
50  }
51 
52  // note: We take advantage of that the life-cycle is completely linear, *except* for
53  // aborting + aborted. So those are checked first.
54  // As it's always possible to abort: Aborting can occur state2 any state except Aborted.
55 
56  if ((state2 == State::AbortingAcquiring) || (state2 == State::AbortingMerging)) {
57  // Only subsequent state after Aborting* is Aborted
58  return state1 == State::Aborted;
59  }
60 
61  // What remains is the linear state1s for the normal life-cycle
62  return static_cast<int>(state1) > static_cast<int>(state2);
63 }
64 
65 std::ostream& operator<<(std::ostream& os, State state) {
66  switch (state) {
67  case State::NotStarted:
68  os << "NotStarted";
69  return os;
70  case State::Starting:
71  os << "Starting";
72  return os;
73  case State::Acquiring:
74  os << "Acquiring";
75  return os;
76  case State::Stopping:
77  os << "Stopping";
78  return os;
79  case State::Stopped:
80  os << "Stopped";
81  return os;
82 
84  os << "NotScheduled";
85  return os;
86  case State::Scheduled:
87  os << "Scheduled";
88  return os;
89  case State::Collecting:
90  os << "Collecting";
91  return os;
92  case State::Merging:
93  os << "Merging";
94  return os;
95  case State::Releasing:
96  os << "Releasing";
97  return os;
98 
100  os << "AbortingAcquiring";
101  return os;
103  os << "AbortingMerging";
104  return os;
105  case State::Aborted:
106  os << "Aborted";
107  return os;
108 
109  case State::Completed:
110  os << "Completed";
111  return os;
112  // GCOVR_EXCL_START
113  default:
114  os << "Unknown";
115  return os;
116  // GCOVR_EXCL_STOP
117  }
118 }
119 
120 } // namespace daq
Declares daq::State and related functions.
bool IsActiveDpmState(State state) noexcept
Query whether state is an active (non-final) state executed by DPM.
Definition: state.cpp:30
bool IsSubsequentState(State state1, State state2) noexcept
Compares states and returns whether state1 occurs after state2.
Definition: state.cpp:43
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
@ Completed
Completed DAQ.
@ NotScheduled
Before daq is acknowledged by dpm it remains in NotScheduled.
@ Scheduled
daq is acknowledged by dpm and is scheduled for merging (i.e.
@ Releasing
Releasing Data Product to receivers.
@ Collecting
Input files are being collected.
@ Aborted
Data acquisition has been aborted by user.
@ Merging
DAQ is being merged.
@ Stopping
Transitional state between Acquiring and Stopped.
@ AbortingMerging
Transitional state for aborting during merging.
@ Acquiring
All data sources have reported data acquisition is in progress.
@ Stopped
All data sources have reported they have stopped acquiring data.
@ Starting
Transitional state between NotStarted and Acquiring when sources have not begun acquiring data yet.
@ AbortingAcquiring
Transitional state for aborting during acquisition.
@ NotStarted
Initial state of data acquisition.
bool IsFinalState(State state) noexcept
Query whether state is in a final state.
Definition: state.cpp:15
bool IsAbortableState(State state) noexcept
Query whether state is in an abortable state.
Definition: state.cpp:25