otsdaq  v2_05_02_indev
Iterator.h
1 #ifndef _ots_Iterator_h
2 #define _ots_Iterator_h
3 
4 #include <mutex> //for std::mutex
5 #include <string>
6 #include "otsdaq/TablePlugins/IterateTable.h"
7 #include "otsdaq/XmlUtilities/HttpXmlDocument.h"
8 
9 #include "otsdaq/ConfigurationInterface/ConfigurationManagerRW.h"
10 
11 namespace ots
12 {
13 class GatewaySupervisor;
14 class ConfigurationManagerRW;
15 
16 class Iterator
17 {
18  friend class GatewaySupervisor;
19 
20  public:
21  Iterator(GatewaySupervisor* supervisor);
22  ~Iterator(void);
23 
24  void playIterationPlan(HttpXmlDocument& xmldoc, const std::string& planName);
25  void pauseIterationPlan(HttpXmlDocument& xmldoc);
26  void haltIterationPlan(HttpXmlDocument& xmldoc);
27  void getIterationPlanStatus(HttpXmlDocument& xmldoc);
28 
29  bool handleCommandRequest(HttpXmlDocument& xmldoc, const std::string& command, const std::string& parameter);
30 
31  private:
32  // begin declaration of iterator workloop members
33  struct IteratorWorkLoopStruct
34  {
35  IteratorWorkLoopStruct(Iterator* iterator, ConfigurationManagerRW* cfgMgr)
36  : theIterator_(iterator)
37  , cfgMgr_(cfgMgr)
38  , originalTrackChanges_(false)
39  , running_(false)
40  , commandBusy_(false)
41  , doPauseAction_(false)
42  , doHaltAction_(false)
43  , doResumeAction_(false)
44  , commandIndex_((unsigned int)-1)
45  {
46  }
47 
48  Iterator* theIterator_;
49  ConfigurationManagerRW* cfgMgr_;
50  bool originalTrackChanges_;
51  std::string originalConfigGroup_;
52  TableGroupKey originalConfigKey_;
53 
54  bool running_, commandBusy_;
55  bool doPauseAction_, doHaltAction_, doResumeAction_;
56 
57  std::string activePlan_;
58  std::vector<IterateTable::Command> commands_;
59  std::vector<unsigned int> commandIterations_;
60  unsigned int commandIndex_;
61  std::vector<unsigned int> stepIndexStack_;
62  time_t originalDurationInSeconds_;
63 
64  // associated with FSM
65  std::string fsmName_, fsmRunAlias_;
66  unsigned int fsmNextRunNumber_;
67  bool runIsDone_;
68 
69  std::vector<std::string> fsmCommandParameters_;
70  std::vector<bool> targetsDone_;
71 
72  }; // end declaration of iterator workloop members
73 
74  static void IteratorWorkLoop(Iterator* iterator);
75  static void startCommand(IteratorWorkLoopStruct* iteratorStruct);
76  static bool checkCommand(IteratorWorkLoopStruct* iteratorStruct);
77 
78  static void startCommandChooseFSM(IteratorWorkLoopStruct* iteratorStruct, const std::string& fsmName);
79 
80  static void startCommandConfigureActive(IteratorWorkLoopStruct* iteratorStruct);
81  static void startCommandConfigureAlias(IteratorWorkLoopStruct* iteratorStruct, const std::string& systemAlias);
82  static void startCommandConfigureGroup(IteratorWorkLoopStruct* iteratorStruct);
83  static bool checkCommandConfigure(IteratorWorkLoopStruct* iteratorStruct);
84 
85  static void startCommandModifyActive(IteratorWorkLoopStruct* iteratorStruct);
86 
87  static void startCommandMacro(IteratorWorkLoopStruct* iteratorStruct, bool isFEMacro);
88  static bool checkCommandMacro(IteratorWorkLoopStruct* iteratorStruct, bool isFEMacro);
89 
90  static void startCommandBeginLabel(IteratorWorkLoopStruct* iteratorStruct);
91  static void startCommandRepeatLabel(IteratorWorkLoopStruct* iteratorStruct);
92 
93  static void startCommandRun(IteratorWorkLoopStruct* iteratorStruct);
94  static bool checkCommandRun(IteratorWorkLoopStruct* iteratorStruct);
95 
96  static bool haltIterator(Iterator* iterator,
97  IteratorWorkLoopStruct* iteratorStruct = 0); //(GatewaySupervisor* theSupervisor, const std::string& fsmName);
98 
99  std::mutex accessMutex_;
100  volatile bool workloopRunning_;
101  volatile bool activePlanIsRunning_;
102  volatile bool iteratorBusy_;
103  volatile bool commandPlay_, commandPause_,
104  commandHalt_; // commands are set by
105  // supervisor thread, and
106  // cleared by iterator thread
107  std::string activePlanName_, lastStartedPlanName_, lastFinishedPlanName_;
108  volatile unsigned int activeCommandIndex_, activeCommandIteration_;
109  std::vector<unsigned int> depthIterationStack_;
110  volatile time_t activeCommandStartTime_;
111  std::string lastFsmName_;
112  std::string errorMessage_;
113 
114  GatewaySupervisor* theSupervisor_;
115 
116  template<class T> // defined in included .icc source
117  static void helpCommandModifyActive(IteratorWorkLoopStruct* iteratorStruct, const T& setValue, bool doTrackGroupChanges);
118 };
119 
120 #include "otsdaq/GatewaySupervisor/Iterator.icc" //for template definitions
121 
122 } // namespace ots
123 
124 #endif