10 * DAQ state machine interface.
19 * The member method enter() makes a call to the virtual method JDAQCHSM::enterState(...),
21 * - first argument is the state entered;
22 * - second argument is the event that caused the transition;
24 * This method should be overwritten by the run control client to reply to the run control.
31 * Default CHSM constructor.
33 JDAQState(CHSM_STATE_ARGS) :
34 CHSM::state(CHSM_STATE_INIT)
41 * \param event event that triggered transition
42 * \param from pointer to state from where transition started
43 * \return true if all OK; else false
45 bool enter(const CHSM::event& event, CHSM::state* from)
49 dynamic_cast<JDAQCHSM&>(this->chsm()).enterState(*this, event);
51 return CHSM::state::enter(event, from);
53 catch(const std::exception& error) {
63 * \param __name name of state machine
65 JDAQCHSM(CHSM_MACHINE_ARGS, const std::string& __name) :
66 CHSM::machine(CHSM_MACHINE_INIT),
74 * Get name of state machine.
78 const std::string& getName() const
85 * Get detector identifier.
87 * \return detector identifier.
89 int getDetectorID() const
100 int getRunNumber() const
107 * Interface methods for actions corresponding to state transitions.
109 virtual void actionEnter() {}
110 virtual void actionExit() {}
112 virtual void actionInit (int, const char*) {}
113 virtual void actionConfigure (int, const char*) {}
114 virtual void actionStart (int, const char*) {}
115 virtual void actionPause (int, const char*) {}
116 virtual void actionContinue (int, const char*) {}
117 virtual void actionStop (int, const char*) {}
118 virtual void actionReset (int, const char*) {}
119 virtual void actionQuit (int, const char*) {}
121 virtual void actionCheck(int, const char*) {}
122 virtual void actionInput(int, const char*) {}
124 virtual void actionError() {}
125 virtual void actionRecover(int, const char*) {}
130 * Action when entering state.
132 * \param state entered state
133 * \param event event that triggered transition
135 virtual void enterState(const CHSM::state& state, const CHSM::event& event) = 0;
139 * Type definition of action method.
141 typedef void (JDAQCHSM::*action)(int, const char*);
145 * The method to execute the action.
147 * This method shall be implemented in the derived class.
149 * \param __action pointer to action method
150 * \param __event event that triggered the action
152 virtual void execute(action __action, const CHSM::event& __event) = 0;
162chsm<JDAQCHSM> JDAQStateMachine(const std::string __name) {
164 upon enter %{ actionEnter(); %}
165 upon exit %{ actionExit(); %}
170 * Type definition of an event with additional data
172 event ev_daq(int length, const char* buffer);
174 event<ev_daq> ev_init;
175 event<ev_daq> ev_configure;
176 event<ev_daq> ev_start;
177 event<ev_daq> ev_pause;
178 event<ev_daq> ev_continue;
179 event<ev_daq> ev_stop;
180 event<ev_daq> ev_reset;
181 event<ev_daq> ev_quit;
182 event<ev_daq> ev_off;
183 event<ev_daq> ev_check;
184 event<ev_daq> ev_input;
185 event<ev_daq> ev_recover;
188 set Main(RunControl, Responder) is {
191 * The run control cluster.
193 cluster RunControl(Operational, Error) is {
195 cluster Operational(Idle, Standby, Ready, Paused, Running) {
197 ev_error->Error %{ actionError(); %};
201 state<JDAQState> Idle {
203 ev_init->Standby %{ execute(&JDAQCHSM::actionInit, event); %};
204 ev_off %{ JDAQCHSM::exit(); %};
207 state<JDAQState> Standby {
209 ev_configure->Ready %{ execute(&JDAQCHSM::actionConfigure, event); %};
210 ev_reset->Idle %{ execute(&JDAQCHSM::actionReset, event); %};
213 state<JDAQState> Ready {
217 std::istringstream is(std::string(ev_start->buffer, ev_start->length));
219 is >> run_number >> detector_id;
221 execute(&JDAQCHSM::actionStart, event);
225 ev_quit->Standby %{ execute(&JDAQCHSM::actionQuit, event); %};
228 state<JDAQState> Paused {
230 ev_continue->Running %{ execute(&JDAQCHSM::actionContinue, event); %};
231 ev_stop->Standby %{ execute(&JDAQCHSM::actionStop, event); %};
234 state<JDAQState> Running {
236 ev_pause->Paused %{ execute(&JDAQCHSM::actionPause, event); %};
241 state<JDAQState> Error {
243 ev_recover->Operational %{ execute(&JDAQCHSM::actionRecover, event); %};
244 ev_off %{ JDAQCHSM::exit(); %};
249 * This state is used to repond to user commands that are not part of the run control state machine.
253 ev_check %{ execute(&JDAQCHSM::actionCheck, event); %};
254 ev_input %{ execute(&JDAQCHSM::actionInput, event); %};