Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:59:39

0001 #ifndef Tracker_TkFiniteStateMachine_h
0002 #define Tracker_TkFiniteStateMachine_h
0003 
0004 #include <string>
0005 /**
0006  * Implement a state machine. Each of the ApvAnalysis component can be
0007  * - calibrating: not yet able to give an answer
0008  * - ready: can give an answer, the calibration stays as it is.
0009  * - calibrating:  can give an answer, at the same time the calibration is updated.
0010  * - stuck: a serious error happened.
0011  */
0012 class TkStateMachine {
0013 public:
0014   enum StatusType { ready = 1, calibrating = 2, updating = 3, stuck = 4 };
0015 
0016   bool alreadyCalibrated() const { return (myStatus == updating || myStatus == ready); }
0017   StatusType status() const { return myStatus; }
0018 
0019   void setReady() { myStatus = ready; }
0020   void setUpdating() { myStatus = updating; }
0021   void setCalibrating() { myStatus = calibrating; }
0022   void setStuck() { myStatus = stuck; }
0023 
0024   void setStatus(StatusType in) { myStatus = in; }
0025 
0026   bool isReady() const { return myStatus == ready; }
0027   bool isStuck() const { return myStatus == stuck; }
0028   bool isUpdating() const { return myStatus == updating; }
0029   bool isCalibrating() const { return myStatus == calibrating; }
0030 
0031   std::string statusName() {
0032     if (myStatus == ready)
0033       return "Ready";
0034     if (myStatus == calibrating)
0035       return "Calibrating";
0036     if (myStatus == updating)
0037       return "Updating";
0038     if (myStatus == stuck)
0039       return "Stuck";
0040     return "Unknown Status";
0041   }
0042 
0043 public:
0044   StatusType myStatus;
0045 };
0046 
0047 #endif