ifw-daq  3.0.0-pre2
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 
26 bool IsSubsequentState(State state1, State state2) noexcept {
27  if (state1 == state2) {
28  return false;
29  }
30  // If state2 is a final state1 it doesn't matter what state1 is, it cannot occur after a final state
31  if (IsFinalState(state2)) {
32  return false;
33  }
34 
35  // note: We take advantage of that the life-cycle is completely linear, *except* for
36  // aborting + aborted. So those are checked first.
37  // As it's always possible to abort: Aborting can occur state2 any state except Aborted.
38 
39  if ((state2 == State::AbortingAcquiring) || (state2 == State::AbortingMerging)) {
40  // Only subsequent state after Aborting* is Aborted
41  return state1 == State::Aborted;
42  }
43 
44  // What remains is the linear state1s for the normal life-cycle
45  return static_cast<int>(state1) > static_cast<int>(state2);
46 }
47 
48 std::ostream& operator<<(std::ostream& os, State state) {
49  switch (state) {
50  case State::NotStarted:
51  os << "NotStarted";
52  return os;
53  case State::Starting:
54  os << "Starting";
55  return os;
56  case State::Acquiring:
57  os << "Acquiring";
58  return os;
59  case State::Stopping:
60  os << "Stopping";
61  return os;
62  case State::Stopped:
63  os << "Stopped";
64  return os;
65 
67  os << "NotScheduled";
68  return os;
69  case State::Scheduled:
70  os << "Scheduled";
71  return os;
73  os << "Transferring";
74  return os;
75  case State::Merging:
76  os << "Merging";
77  return os;
78  case State::Releasing:
79  os << "Releasing";
80  return os;
81 
83  os << "AbortingAcquiring";
84  return os;
86  os << "AbortingMerging";
87  return os;
88  case State::Aborted:
89  os << "Aborted";
90  return os;
91 
92  case State::Completed:
93  os << "Completed";
94  return os;
95  // GCOVR_EXCL_START
96  default:
97  os << "Unknown";
98  return os;
99  // GCOVR_EXCL_STOP
100  }
101 }
102 
103 } // namespace daq
Declares daq::State and related functions.
daqif::DaqStatus & operator<<(daqif::DaqStatus &status, daq::Status const &rhs)
Convert daq::Status -> daqif::DaqStatus by populating from rhs.
Definition: conversion.cpp:18
bool IsSubsequentState(State state1, State state2) noexcept
Compares states and returns whether state1 occurs after state2.
Definition: state.cpp:26
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.
@ 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.
@ Transferring
Input files are being transferred.
@ 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