CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Public Attributes | Private Attributes
evf::EPStateMachine Class Reference

#include <EPStateMachine.h>

Inheritance diagram for evf::EPStateMachine:

Public Member Functions

xoap::MessageReference createFSMReplyMsg (const std::string cmd, const std::string state)
 
 EPStateMachine (log4cplus::Logger &logger)
 
void failedTransition (toolbox::Event::Reference e) throw (toolbox::fsm::exception::Exception)
 
void fireEvent (toolbox::Event::Reference e) throw (toolbox::fsm::exception::Exception)
 
template<class T >
void init (T *me)
 
xoap::MessageReference processFSMCommand (const std::string cmdName) throw (xoap::exception::Exception)
 
void reset () throw (toolbox::fsm::exception::Exception)
 
void stateChanged (toolbox::fsm::FiniteStateMachine &fsm) throw (toolbox::fsm::exception::Exception)
 

Public Attributes

toolbox::fsm::State state_
 
xdata::String stateName_
 

Private Attributes

log4cplus::Logger & logger_
 

Detailed Description

Definition at line 15 of file EPStateMachine.h.

Constructor & Destructor Documentation

evf::EPStateMachine::EPStateMachine ( log4cplus::Logger &  logger)

Definition at line 8 of file EPStateMachine.cc.

8  : logger_(logger)
9  {
10  }
std::ostream & logger()
Definition: fwLog.cc:41
log4cplus::Logger & logger_

Member Function Documentation

xoap::MessageReference evf::EPStateMachine::createFSMReplyMsg ( const std::string  cmd,
const std::string  state 
)

Definition at line 33 of file EPStateMachine.cc.

References web.browse_db::env, and lumiQueryAPI::msg.

35  {
36  xoap::MessageReference msg = xoap::createMessage();
37  xoap::SOAPEnvelope env = msg->getSOAPPart().getEnvelope();
38  xoap::SOAPBody body = env.getBody();
39  std::string rStr = cmd + "Response";
40  xoap::SOAPName rName = env.createName(rStr,"xdaq",XDAQ_NS_URI);
41  xoap::SOAPBodyElement rElem = body.addBodyElement(rName);
42  xoap::SOAPName sName = env.createName("state","xdaq",XDAQ_NS_URI);
43  xoap::SOAPElement sElem = rElem.addChildElement(sName);
44  xoap::SOAPName aName = env.createName("stateName","xdaq",XDAQ_NS_URI);
45 
46 
47  sElem.addAttribute(aName, state);
48 
49  return msg;
50  }
string cmd
Definition: asciidump.py:19
char state
Definition: procUtils.cc:75
void evf::EPStateMachine::failedTransition ( toolbox::Event::Reference  e)
throw (toolbox::fsm::exception::Exception
)
inline

Definition at line 68 of file EPStateMachine.h.

References vdt::fe, and logger_.

Referenced by init().

70  {
71  toolbox::fsm::FailedEvent &fe =
72  dynamic_cast<toolbox::fsm::FailedEvent&>(*e);
73 
74  LOG4CPLUS_FATAL(logger_,
75  "Failure occurred when performing transition from: "
76  << fe.getFromState() << " to: " << fe.getToState()
77  << " exception: " << fe.getException().what());
78  }
double & fe
Definition: VDTMath.h:196
log4cplus::Logger & logger_
void evf::EPStateMachine::fireEvent ( toolbox::Event::Reference  e)
throw (toolbox::fsm::exception::Exception
)
inline

Calls FiniteStateMachine::fireEvent() and keeps stateName_ and state_ in sync.

Definition at line 106 of file EPStateMachine.h.

References alignCSCRings::e, edm::hlt::Exception, logger_, state_, and stateName_.

108  {
109  try{
110  FiniteStateMachine::fireEvent(e);
111  }
113  {
114  LOG4CPLUS_ERROR(logger_,"EPStateMachine fireEvent failed "
115  << ex.what());
116  }
117  catch(...)
118  {
119  LOG4CPLUS_ERROR(logger_,"EPStateMachine fireEvent failed "
120  << " Unknown Exception " << " state is "
121  << FiniteStateMachine::getCurrentState());
122  }
123 
124 
125  state_ = FiniteStateMachine::getCurrentState();
126  stateName_ = FiniteStateMachine::getStateName(state_);
127  }
toolbox::fsm::State state_
xdata::String stateName_
log4cplus::Logger & logger_
template<class T >
void evf::EPStateMachine::init ( T me)
inline

Definition at line 32 of file EPStateMachine.h.

References failedTransition(), reset(), and stateChanged().

Referenced by dqm::StateMachine::StateMachine().

33  {
34  // Define FSM states
35  addState('H', "Halted" , this, &EPStateMachine::stateChanged);
36  addState('R', "Ready" , this, &EPStateMachine::stateChanged);
37  addState('E', "Enabled" , this, &EPStateMachine::stateChanged);
38  addState('S', "Suspended", this, &EPStateMachine::stateChanged);
39 
40  // Define FSM transitions
41  addStateTransition('H', 'R', "Configure", me, &T::configureAction);
42  addStateTransition('R', 'E', "Enable", me, &T::enableAction);
43  addStateTransition('E', 'R', "Stop", me, &T::stopAction);
44  addStateTransition('E', 'S', "Suspend", me, &T::suspendAction);
45  addStateTransition('S', 'E', "Resume", me, &T::resumeAction);
46  addStateTransition('H', 'H', "Halt", me, &T::nullAction);
47  addStateTransition('R', 'H', "Halt", me, &T::haltAction);
48  addStateTransition('E', 'H', "Halt", me, &T::haltAction);
49  addStateTransition('S', 'H', "Halt", me, &T::haltAction);
50 
51  setFailedStateTransitionAction(this,&EPStateMachine::failedTransition);
52  setFailedStateTransitionChanged(this,&EPStateMachine::stateChanged);
53 
54  setInitialState('H');
55  reset();
56 
57  xoap::bind(me,&T::fireEvent,"Configure", XDAQ_NS_URI);
58  xoap::bind(me,&T::fireEvent,"Stop" , XDAQ_NS_URI);
59  xoap::bind(me,&T::fireEvent,"Enable" , XDAQ_NS_URI);
60  xoap::bind(me,&T::fireEvent,"Suspend" , XDAQ_NS_URI);
61  xoap::bind(me,&T::fireEvent,"Resume" , XDAQ_NS_URI);
62  xoap::bind(me,&T::fireEvent,"Halt" , XDAQ_NS_URI);
63  xoap::bind(me,&T::fireEvent,"Disable" , XDAQ_NS_URI);
64  xoap::bind(me,&T::fireEvent,"Fail" , XDAQ_NS_URI);
65  }
void failedTransition(toolbox::Event::Reference e)
void stateChanged(toolbox::fsm::FiniteStateMachine &fsm)
xoap::MessageReference evf::EPStateMachine::processFSMCommand ( const std::string  cmdName)
throw (xoap::exception::Exception
)

Definition at line 12 of file EPStateMachine.cc.

References alignCSCRings::e, and edm::hlt::Exception.

Referenced by dqm::StateMachine::dispatch().

14  {
15  try
16  {
17  // Change state, calling the appropriate action method
18  toolbox::Event::Reference evtRef(new toolbox::Event(cmdName, this));
19  fireEvent(evtRef);
20  return createFSMReplyMsg(cmdName, stateName_);
21  }
22  catch(xcept::Exception e)
23  {
24  XCEPT_RETHROW(xoap::exception::Exception,
25  "Failed to process " + cmdName, e);
26  }
27  catch(...)
28  {
29  XCEPT_RAISE(xoap::exception::Exception,
30  "Failed to process " + cmdName + " - Unknown exception");
31  }
32  }
void fireEvent(toolbox::Event::Reference e)
xoap::MessageReference createFSMReplyMsg(const std::string cmd, const std::string state)
xdata::String stateName_
void evf::EPStateMachine::reset ( void  )
throw (toolbox::fsm::exception::Exception
)
inline

Calls FiniteStateMachine::reset() and keeps stateName_ and state_ in sync.

Definition at line 93 of file EPStateMachine.h.

References reset(), state_, and stateName_.

Referenced by init().

94  {
96 
97  state_ = FiniteStateMachine::getCurrentState();
98  stateName_ = FiniteStateMachine::getStateName(state_);
99  }
toolbox::fsm::State state_
xdata::String stateName_
void reset(double vett[256])
Definition: TPedValues.cc:11
void evf::EPStateMachine::stateChanged ( toolbox::fsm::FiniteStateMachine &  fsm)
throw (toolbox::fsm::exception::Exception
)
inline

Definition at line 80 of file EPStateMachine.h.

References logger_.

Referenced by init().

82  {
83  LOG4CPLUS_INFO(logger_,
84  "Changed to state: "
85  << getStateName(getCurrentState()));
86  }
log4cplus::Logger & logger_

Member Data Documentation

log4cplus::Logger& evf::EPStateMachine::logger_
private

Definition at line 135 of file EPStateMachine.h.

Referenced by failedTransition(), fireEvent(), and stateChanged().

toolbox::fsm::State evf::EPStateMachine::state_

Application state as an "integer" - to be used in the application

Definition at line 22 of file EPStateMachine.h.

Referenced by fireEvent(), and reset().

xdata::String evf::EPStateMachine::stateName_

Application state as a string - to be used an exported parameter for run-control.

Definition at line 29 of file EPStateMachine.h.

Referenced by fireEvent(), reset(), and dqm::StateMachine::stateName().