Jpp  15.0.5
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JDAQCHSM.chsm
Go to the documentation of this file.
1 // ; -*- mode: C++; -*-
2 
3 #include "chsm.h"
4 
5 #include <string>
6 #include <sstream>
7 
8 
9 /**
10  * DAQ state machine interface.
11  */
12 class JDAQCHSM :
13  public CHSM::machine
14 {
15 public:
16  /**
17  * DAQ state class.
18  *
19  * The member method enter() makes a call to the virtual method JDAQCHSM::enterState(...),
20  * where:
21  * - first argument is the state entered;
22  * - second argument is the event that caused the transition;
23  *
24  * This method should be overwritten by the run control client to reply to the run control.
25  */
26  class JDAQState :
27  public CHSM::state
28  {
29  public:
30  /**
31  * Default CHSM constructor.
32  */
33  JDAQState(CHSM_STATE_ARGS) :
34  CHSM::state(CHSM_STATE_INIT)
35  {}
36 
37 
38  /**
39  * Enter this state.
40  *
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
44  */
45  bool enter(const CHSM::event& event, CHSM::state* from)
46  {
47  try {
48 
49  dynamic_cast<JDAQCHSM&>(this->chsm()).enterState(*this, event);
50 
51  return CHSM::state::enter(event, from);
52  }
53  catch(const std::exception& error) {
54  return false;
55  }
56  }
57  };
58 
59 
60  /**
61  * Constructor.
62  *
63  * \param __name name of state machine
64  */
65  JDAQCHSM(CHSM_MACHINE_ARGS, const std::string& __name) :
66  CHSM::machine(CHSM_MACHINE_INIT),
67  name (__name),
68  detector_id(-1),
69  run_number (-1)
70  {}
71 
72 
73  /**
74  * Get name of state machine.
75  *
76  * \return name
77  */
78  const std::string& getName() const
79  {
80  return name;
81  }
82 
83 
84  /**
85  * Get detector identifier.
86  *
87  * \return detector identifier.
88  */
89  int getDetectorID() const
90  {
91  return detector_id;
92  }
93 
94 
95  /**
96  * Get run number.
97  *
98  * \return run number
99  */
100  int getRunNumber() const
101  {
102  return run_number;
103  }
104 
105 
106  /**
107  * Interface methods for actions corresponding to state transitions.
108  */
109  virtual void actionEnter() {}
110  virtual void actionExit() {}
111 
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*) {}
120 
121  virtual void actionCheck(int, const char*) {}
122  virtual void actionInput(int, const char*) {}
123 
124  virtual void actionError() {}
125  virtual void actionRecover(int, const char*) {}
126 
127 
128 protected:
129  /**
130  * Action when entering state.
131  *
132  * \param state entered state
133  * \param event event that triggered transition
134  */
135  virtual void enterState(const CHSM::state& state, const CHSM::event& event) = 0;
136 
137 
138  /**
139  * Type definition of action method.
140  */
141  typedef void (JDAQCHSM::*action)(int, const char*);
142 
143 
144  /**
145  * The method to execute the action.
146  *
147  * This method shall be implemented in the derived class.
148  *
149  * \param __action pointer to action method
150  * \param __event event that triggered the action
151  */
152  virtual void execute(action __action, const CHSM::event& __event) = 0;
153 
154  std::string name;
157 };
158 
159 
160 %%
161 
162 chsm<JDAQCHSM> JDAQStateMachine(const std::string __name) {
163 
164  upon enter %{ actionEnter(); %}
165  upon exit %{ actionExit(); %}
166 
167 } is {
168 
169  /**
170  * Type definition of an event with additional data
171  */
172  event ev_daq(int length, const char* buffer);
173 
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;
186 
187 
188  set Main(RunControl, Responder) is {
189 
190  /**
191  * The run control cluster.
192  */
193  cluster RunControl(Operational, Error) is {
194 
195  cluster Operational(Idle, Standby, Ready, Paused, Running) {
196 
197  ev_error->Error %{ actionError(); %};
198 
199  } is {
200 
201  state<JDAQState> Idle {
202 
203  ev_init->Standby %{ execute(&JDAQCHSM::actionInit, event); %};
204  ev_off %{ JDAQCHSM::exit(); %};
205  }
206 
207  state<JDAQState> Standby {
208 
209  ev_configure->Ready %{ execute(&JDAQCHSM::actionConfigure, event); %};
210  ev_reset->Idle %{ execute(&JDAQCHSM::actionReset, event); %};
211  }
212 
213  state<JDAQState> Ready {
214 
215  ev_start->Running %{
216 
217  std::istringstream is(std::string(ev_start->buffer, ev_start->length));
218 
219  is >> run_number >> detector_id;
220 
221  execute(&JDAQCHSM::actionStart, event);
222 
223  %};
224 
225  ev_quit->Standby %{ execute(&JDAQCHSM::actionQuit, event); %};
226  }
227 
228  state<JDAQState> Paused {
229 
230  ev_continue->Running %{ execute(&JDAQCHSM::actionContinue, event); %};
231  ev_stop->Standby %{ execute(&JDAQCHSM::actionStop, event); %};
232  }
233 
234  state<JDAQState> Running {
235 
236  ev_pause->Paused %{ execute(&JDAQCHSM::actionPause, event); %};
237  }
238  }
239 
240 
241  state<JDAQState> Error {
242 
243  ev_recover->Operational %{ execute(&JDAQCHSM::actionRecover, event); %};
244  ev_off %{ JDAQCHSM::exit(); %};
245  }
246  }
247 
248  /**
249  * This state is used to repond to user commands that are not part of the run control state machine.
250  */
251  state Responder {
252 
253  ev_check %{ execute(&JDAQCHSM::actionCheck, event); %};
254  ev_input %{ execute(&JDAQCHSM::actionInput, event); %};
255  }
256  }
257 }
258 
259 %%
260 
261 
262 
set Main(RunControl, Responder) is
Definition: JDAQCHSM.chsm:188
chsm< JDAQCHSM > JDAQStateMachine(const std::string __name)
Definition: JDAQCHSM.chsm:162
virtual void actionError()
Definition: JDAQCHSM.chsm:124
event< ev_daq > ev_continue
Definition: JDAQCHSM.chsm:178
virtual void actionQuit(int, const char *)
Definition: JDAQCHSM.chsm:119
event< ev_daq > ev_reset
Definition: JDAQCHSM.chsm:180
event< ev_daq > ev_recover
Definition: JDAQCHSM.chsm:185
event< ev_daq > ev_stop
Definition: JDAQCHSM.chsm:179
void(JDAQCHSM::* action)(int, const char *)
Type definition of action method.
Definition: JDAQCHSM.chsm:141
virtual void actionInit(int, const char *)
Definition: JDAQCHSM.chsm:112
virtual void actionStop(int, const char *)
Definition: JDAQCHSM.chsm:117
virtual void actionReset(int, const char *)
Definition: JDAQCHSM.chsm:118
virtual void enterState(const CHSM::state &state, const CHSM::event &event)=0
Action when entering state.
event< ev_daq > ev_quit
Definition: JDAQCHSM.chsm:181
int run_number
Definition: JDAQCHSM.chsm:156
virtual void actionPause(int, const char *)
Definition: JDAQCHSM.chsm:115
JDAQState(CHSM_STATE_ARGS)
Default CHSM constructor.
Definition: JDAQCHSM.chsm:33
exit
Definition: JPizza.sh:36
std::string name
Definition: JDAQCHSM.chsm:154
event< ev_daq > ev_pause
Definition: JDAQCHSM.chsm:177
event< ev_daq > ev_input
Definition: JDAQCHSM.chsm:184
virtual void actionEnter()
Interface methods for actions corresponding to state transitions.
Definition: JDAQCHSM.chsm:109
virtual void actionRecover(int, const char *)
Definition: JDAQCHSM.chsm:125
is
Definition: JDAQCHSM.chsm:167
virtual void actionInput(int, const char *)
Definition: JDAQCHSM.chsm:122
DAQ state machine interface.
Definition: JDAQCHSM.chsm:12
then cat ev_configure txt<< EOFdatawriter=$DWRITER_HOST;inputFile=$INPUT_FILE;eventRate_Hz=100.0;EOFfiif[[!-f driver.txt]];thencat > driver txt<< EOFprocess JEventGenerator $HOST ssh\$HOST\$"$JPP_BIN/JEventGenerator -u \$NAME\$ -H \$SERVER\$ -M \$LOGGER\$ -d $DEBUG </dev/null >& dev null& process JDataWriter $HOST ssh $HOST $JPP_BIN JDataWriter u $NAME H $SERVER M $LOGGER d $DEBUG</dev/null >& dev null& enter event ev_init
int getDetectorID() const
Get detector identifier.
Definition: JDAQCHSM.chsm:89
virtual void actionCheck(int, const char *)
Definition: JDAQCHSM.chsm:121
virtual void execute(action __action, const CHSM::event &__event)=0
The method to execute the action.
event< ev_daq > ev_configure
Definition: JDAQCHSM.chsm:175
virtual void actionStart(int, const char *)
Definition: JDAQCHSM.chsm:114
virtual void actionContinue(int, const char *)
Definition: JDAQCHSM.chsm:116
virtual void actionExit()
Definition: JDAQCHSM.chsm:110
int getRunNumber() const
Get run number.
Definition: JDAQCHSM.chsm:100
event< ev_daq > ev_check
Definition: JDAQCHSM.chsm:183
event< ev_daq > ev_off
Definition: JDAQCHSM.chsm:182
bool enter(const CHSM::event &event, CHSM::state *from)
Enter this state.
Definition: JDAQCHSM.chsm:45
int detector_id
Definition: JDAQCHSM.chsm:155
virtual void actionConfigure(int, const char *)
Definition: JDAQCHSM.chsm:113
const std::string & getName() const
Get name of state machine.
Definition: JDAQCHSM.chsm:78
JDAQCHSM(CHSM_MACHINE_ARGS, const std::string &__name)
Constructor.
Definition: JDAQCHSM.chsm:65
DAQ state class.
Definition: JDAQCHSM.chsm:26