Belle II Software  release-06-02-00
RCCommand.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 #include "daq/slc/runcontrol/RCCommand.h"
9 
10 #include "daq/slc/runcontrol/RCState.h"
11 
12 using namespace Belle2;
13 
14 const RCCommand RCCommand::CONFIGURE(101, "RC_CONFIGURE");
15 const RCCommand RCCommand::LOAD(102, "RC_LOAD");
16 const RCCommand RCCommand::START(103, "RC_START");
17 const RCCommand RCCommand::STOP(104, "RC_STOP");
18 const RCCommand RCCommand::RESUME(105, "RC_RESUME");
19 const RCCommand RCCommand::PAUSE(106, "RC_PAUSE");
20 const RCCommand RCCommand::RECOVER(107, "RC_RECOVER");
21 const RCCommand RCCommand::ABORT(108, "RC_ABORT");
22 const RCCommand RCCommand::BOOT(109, "RC_BOOT");
23 const RCCommand RCCommand::STATUS(110, "RC_STATUS");
24 
25 const RCCommand& RCCommand::operator=(const std::string& label)
26 {
27  if (NSMCommand::operator=(label) != Enum::UNKNOWN) return *this;
28  else if (label == CONFIGURE.getLabel()) *this = CONFIGURE;
29  else if (label == LOAD.getLabel()) *this = LOAD;
30  else if (label == START.getLabel()) *this = START;
31  else if (label == STOP.getLabel()) *this = STOP;
32  else if (label == RECOVER.getLabel()) *this = RECOVER;
33  else if (label == RESUME.getLabel()) *this = RESUME;
34  else if (label == PAUSE.getLabel()) *this = PAUSE;
35  else if (label == ABORT.getLabel()) *this = ABORT;
36  else if (label == BOOT.getLabel()) *this = BOOT;
37  else if (label == STATUS.getLabel()) *this = STATUS;
38  else *this = Enum::UNKNOWN;
39  return *this;
40 }
41 
42 const RCCommand& RCCommand::operator=(int id)
43 {
44  if (NSMCommand::operator=(id) != Enum::UNKNOWN) return *this;
45  else if (id == CONFIGURE.getId()) *this = CONFIGURE;
46  else if (id == LOAD.getId()) *this = LOAD;
47  else if (id == START.getId()) *this = START;
48  else if (id == STOP.getId()) *this = STOP;
49  else if (id == RECOVER.getId()) *this = RECOVER;
50  else if (id == RESUME.getId()) *this = RESUME;
51  else if (id == PAUSE.getId()) *this = PAUSE;
52  else if (id == ABORT.getId()) *this = ABORT;
53  else if (id == BOOT.getId()) *this = BOOT;
54  else if (id == STATUS.getId()) *this = STATUS;
55  else *this = Enum::UNKNOWN;
56  return *this;
57 }
58 
59 const RCCommand& RCCommand::operator=(const char* label)
60 {
61  if (label != NULL) *this = std::string(label);
62  else *this = Enum::UNKNOWN;
63  return *this;
64 }
65 
66 int RCCommand::isAvailable(const RCState& state) const
67 {
68  const RCCommand& cmd(*this);
69  if ((cmd == LOAD || cmd == CONFIGURE) &&
70  state == RCState::NOTREADY_S) {
71  return SUGGESTED;
72  /* } else if ((cmd == LOAD || cmd == CONFIGURE) &&
73  state == RCState::READY_S) {
74  return ENABLED;
75  */
76  } else if (cmd == START && state == RCState::READY_S) {
77  return SUGGESTED;
78  } else if (cmd == STOP && (state == RCState::RUNNING_S ||
79  state == RCState::PAUSED_S)) {
80  return SUGGESTED;
81  } else if (cmd == PAUSE && state == RCState::RUNNING_S) {
82  return ENABLED;
83  } else if (cmd == RESUME && state == RCState::PAUSED_S) {
84  return ENABLED;
85  } else if (cmd == ABORT) {
86  return ENABLED;
87  } else if (cmd == RECOVER && state == RCState::ERROR_ES) {
88  return ENABLED;
89  } else if (cmd == BOOT && state == RCState::NOTREADY_S) {
90  return ENABLED;
91  } else {
92  return DISABLED;
93  }
94 }
95 
96 RCState RCCommand::nextState() const
97 {
98  const RCCommand& cmd(*this);
99  if (cmd == LOAD) return RCState::READY_S;
100  else if (cmd == START) return RCState::RUNNING_S;
101  else if (cmd == STOP) return RCState::READY_S;
102  else if (cmd == RESUME) return RCState::RUNNING_S;
103  else if (cmd == PAUSE) return RCState::PAUSED_S;
104  else if (cmd == RECOVER) return RCState::READY_S;
105  else if (cmd == ABORT) return RCState::NOTREADY_S;
106  else if (cmd == BOOT) return RCState::NOTREADY_S;
107  else if (cmd == CONFIGURE) return RCState::NOTREADY_S;
108  else return Enum::UNKNOWN;
109 }
110 
111 RCState RCCommand::nextTState() const
112 {
113  const RCCommand& cmd(*this);
114  if (cmd == CONFIGURE) return RCState::CONFIGURING_TS;
115  else if (cmd == LOAD) return RCState::LOADING_TS;
116  else if (cmd == START) return RCState::STARTING_TS;
117  else if (cmd == STOP) return RCState::STOPPING_TS;
118  else if (cmd == RESUME) return RCState::RUNNING_S;
119  else if (cmd == PAUSE) return RCState::PAUSED_S;
120  else if (cmd == RECOVER) return RCState::RECOVERING_RS;
121  else if (cmd == ABORT) return RCState::ABORTING_RS;
122  else if (cmd == BOOT) return RCState::BOOTING_RS;
123  else return Enum::UNKNOWN;
124 }
Abstract base class for different kinds of events.