Belle II Software  release-08-01-10
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 
26 {
27  NSMCommand::operator=(command);
28  return *this;
29 }
30 
31 const RCCommand& RCCommand::operator=(const std::string& label)
32 {
33  if (NSMCommand::operator=(label) != Enum::UNKNOWN) return *this;
34  else if (label == CONFIGURE.getLabel()) *this = CONFIGURE;
35  else if (label == LOAD.getLabel()) *this = LOAD;
36  else if (label == START.getLabel()) *this = START;
37  else if (label == STOP.getLabel()) *this = STOP;
38  else if (label == RECOVER.getLabel()) *this = RECOVER;
39  else if (label == RESUME.getLabel()) *this = RESUME;
40  else if (label == PAUSE.getLabel()) *this = PAUSE;
41  else if (label == ABORT.getLabel()) *this = ABORT;
42  else if (label == BOOT.getLabel()) *this = BOOT;
43  else if (label == STATUS.getLabel()) *this = STATUS;
44  else *this = Enum::UNKNOWN;
45  return *this;
46 }
47 
48 const RCCommand& RCCommand::operator=(int id)
49 {
50  if (NSMCommand::operator=(id) != Enum::UNKNOWN) return *this;
51  else if (id == CONFIGURE.getId()) *this = CONFIGURE;
52  else if (id == LOAD.getId()) *this = LOAD;
53  else if (id == START.getId()) *this = START;
54  else if (id == STOP.getId()) *this = STOP;
55  else if (id == RECOVER.getId()) *this = RECOVER;
56  else if (id == RESUME.getId()) *this = RESUME;
57  else if (id == PAUSE.getId()) *this = PAUSE;
58  else if (id == ABORT.getId()) *this = ABORT;
59  else if (id == BOOT.getId()) *this = BOOT;
60  else if (id == STATUS.getId()) *this = STATUS;
61  else *this = Enum::UNKNOWN;
62  return *this;
63 }
64 
65 const RCCommand& RCCommand::operator=(const char* label)
66 {
67  if (label != NULL) *this = std::string(label);
68  else *this = Enum::UNKNOWN;
69  return *this;
70 }
71 
72 int RCCommand::isAvailable(const RCState& state) const
73 {
74  const RCCommand& cmd(*this);
75  if ((cmd == LOAD || cmd == CONFIGURE) &&
76  state == RCState::NOTREADY_S) {
77  return SUGGESTED;
78  /* } else if ((cmd == LOAD || cmd == CONFIGURE) &&
79  state == RCState::READY_S) {
80  return ENABLED;
81  */
82  } else if (cmd == START && state == RCState::READY_S) {
83  return SUGGESTED;
84  } else if (cmd == STOP && (state == RCState::RUNNING_S ||
85  state == RCState::PAUSED_S)) {
86  return SUGGESTED;
87  } else if (cmd == PAUSE && state == RCState::RUNNING_S) {
88  return ENABLED;
89  } else if (cmd == RESUME && state == RCState::PAUSED_S) {
90  return ENABLED;
91  } else if (cmd == ABORT) {
92  return ENABLED;
93  } else if (cmd == RECOVER && state == RCState::ERROR_ES) {
94  return ENABLED;
95  } else if (cmd == BOOT && state == RCState::NOTREADY_S) {
96  return ENABLED;
97  } else {
98  return DISABLED;
99  }
100 }
101 
102 RCState RCCommand::nextState() const
103 {
104  const RCCommand& cmd(*this);
105  if (cmd == LOAD) return RCState::READY_S;
106  else if (cmd == START) return RCState::RUNNING_S;
107  else if (cmd == STOP) return RCState::READY_S;
108  else if (cmd == RESUME) return RCState::RUNNING_S;
109  else if (cmd == PAUSE) return RCState::PAUSED_S;
110  else if (cmd == RECOVER) return RCState::READY_S;
111  else if (cmd == ABORT) return RCState::NOTREADY_S;
112  else if (cmd == BOOT) return RCState::NOTREADY_S;
113  else if (cmd == CONFIGURE) return RCState::NOTREADY_S;
114  else return Enum::UNKNOWN;
115 }
116 
117 RCState RCCommand::nextTState() const
118 {
119  const RCCommand& cmd(*this);
120  if (cmd == CONFIGURE) return RCState::CONFIGURING_TS;
121  else if (cmd == LOAD) return RCState::LOADING_TS;
122  else if (cmd == START) return RCState::STARTING_TS;
123  else if (cmd == STOP) return RCState::STOPPING_TS;
124  else if (cmd == RESUME) return RCState::RUNNING_S;
125  else if (cmd == PAUSE) return RCState::PAUSED_S;
126  else if (cmd == RECOVER) return RCState::RECOVERING_RS;
127  else if (cmd == ABORT) return RCState::ABORTING_RS;
128  else if (cmd == BOOT) return RCState::BOOTING_RS;
129  else return Enum::UNKNOWN;
130 }
const NSMCommand & operator=(const NSMCommand &command)
Operator =.
Definition: NSMCommand.cc:32
const RCCommand & operator=(const RCCommand &command)
Operator =.
Definition: RCCommand.cc:25
Abstract base class for different kinds of events.