DABC (Data Acquisition Backbone Core)  2.9.9
Monitor.h
Go to the documentation of this file.
1 // $Id: Monitor.h 4768 2021-04-26 09:13:07Z linev $
2 
3 /************************************************************
4  * The Data Acquisition Backbone Core (DABC) *
5  ************************************************************
6  * Copyright (C) 2009 - *
7  * GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
8  * Planckstr. 1, 64291 Darmstadt, Germany *
9  * Contact: http://dabc.gsi.de *
10  ************************************************************
11  * This software can be used under the GPL license *
12  * agreements as stated in LICENSE.txt file *
13  * which is part of the distribution. *
14  ************************************************************/
15 
16 #ifndef MBS_Monitor
17 #define MBS_Monitor
18 
19 #ifndef MBS_MonitorSlowControl
20 #include "mbs/MonitorSlowControl.h"
21 #endif
22 
23 #ifndef DABC_SocketThread
24 #include "dabc/SocketThread.h"
25 #endif
26 
27 #ifndef MBS_MbsTypeDefs
28 #include "mbs/MbsTypeDefs.h"
29 #endif
30 
31 
32 namespace mbs {
33 
34 
38 
39  protected:
40 
41  enum IOState {
42  ioInit, // initial state
43  ioRecvHeader, // receiving server info
46  ioError
47  };
48 
49  enum EEvents {
52  };
53 
56  bool fSwapping;
57  uint32_t fSendCmd;
58 
59  virtual void OnThreadAssigned();
60 
61  virtual double ProcessTimeout(double last_diff);
62 
63  virtual void OnRecvCompleted();
64 
65  public:
66 
67  DaqStatusAddon(int fd);
68 
70  };
71 
72  // =====================================================================
73 
74  class DaqLogWorker : public dabc::Worker {
75  protected:
76 
77  struct MbsLogRec {
78  int32_t iOrder;
79  int32_t iType;
80  int32_t iStatus;
81  char fBuffer[512];
82  };
83 
84  std::string fMbsNode;
85  int fPort;
87  bool fFirstRecv;
88 
89  bool CreateAddon();
90 
91  virtual void OnThreadAssigned();
92 
93  virtual double ProcessTimeout(double last_diff);
94 
95  virtual void ProcessEvent(const dabc::EventId&);
96 
97  public:
98  DaqLogWorker(const dabc::Reference& parent, const std::string &name, const std::string &mbsnode, int port);
99  virtual ~DaqLogWorker();
100 
101  virtual std::string RequiredThrdClass() const
102  { return dabc::typeSocketThread; }
103 
104  };
105 
106  // ======================================================================
107 
111  class DaqRemCmdWorker : public dabc::Worker {
112  protected:
113 
114  struct MbsRemCmdRec {
115  uint32_t l_order; /* byte order. Set to 1 by sender */
116  uint32_t l_cmdid; /* command id, 0xffffffff when dummy command is send */
117  uint32_t l_status; /* command completion status */
118  char c_cmd[512]; /* command to execute - or reply info */
119 
120  bool CheckByteOrder() {
121  if (l_order!=1) mbs::SwapData(this, 3*4);
122  return l_order==1;
123  }
124  };
125 
126 
127  enum IOState {
128  ioInit, // initial state
129  ioWaitReply, // waiting for command reply
130  ioError
131  };
132 
133  std::string fMbsNode;
134  int fPort;
135 
137 
140  uint32_t fSendCmdId; // command identifier, send to the MBS with the command
142 
143  virtual void ProcessEvent(const dabc::EventId&);
144 
145  virtual double ProcessTimeout(double last_diff);
146 
147  virtual int ExecuteCommand(dabc::Command cmd);
148 
149  void ProcessNextMbsCommand();
150 
151  virtual void OnThreadAssigned();
152 
153  bool CreateAddon();
154 
155 
156  public:
157  DaqRemCmdWorker(const dabc::Reference& parent, const std::string &name, const std::string &mbsnode, int port);
158 
159  virtual ~DaqRemCmdWorker();
160  };
161 
162 
163  // ======================================================================
164 
168  class PrompterWorker : public dabc::Worker {
169  protected:
170 
171  enum IOState {
172  ioInit, // initial state
173  ioWaitReply, // waiting for command reply
174  ioError
175  };
176 
177  std::string fMbsNode; // real mbs node name
178  int fPort;
179  std::string fPrefix; // prefix used to identify client
180 
182 
184  char fSendBuf[256];
185  uint32_t fRecvBuf[2];
186 
187  virtual void ProcessEvent(const dabc::EventId&);
188 
189  virtual double ProcessTimeout(double last_diff);
190 
191  virtual int ExecuteCommand(dabc::Command cmd);
192 
193  void ProcessNextMbsCommand();
194 
195  virtual void OnThreadAssigned();
196 
197  bool CreateAddon();
198 
199  public:
200  PrompterWorker(const dabc::Reference& parent, const std::string &name, const std::string &mbsnode, int port);
201 
202  virtual ~PrompterWorker();
203  };
204 
205  // ======================================================================
206 
207 
225  protected:
226 
228  unsigned fCounter;
229 
230  std::string fMbsNode;
231  std::string fAlias; // name appeared in hierarchy, node name by default
232  double fPeriod;
233  double fRateInterval;
234  int fHistory;
235  int fStatPort;
237  int fCmdPort;
242  bool fPrintf;
243  std::string fFileStateName;
244  std::string fAcqStateName;
245  std::string fSetupStateName;
246  std::string fRateIntervalName;
247  std::string fHistoryName;
248 
249  void FillStatistic(const std::string &options, const std::string &itemname, mbs::DaqStatus* old_daqst, mbs::DaqStatus* new_daqst, double difftime);
250 
251  void CreateCommandWorker();
252 
253  virtual void OnThreadAssigned();
254 
255  virtual int ExecuteCommand(dabc::Command cmd);
256 
258  void UpdateFileState(int isopen);
260  void UpdateMbsState(int isrunning);
261 
263  void UpdateSetupState(int isloaded);
264 
266  void SetRateInterval(double t);
267 
269  void SetHistoryDepth(int entries);
270 
271  bool IsPrompter() const { return fCmdPort == 6006; }
272 
273  virtual void ProcessTimerEvent(unsigned timer);
274 
275  virtual unsigned WriteRecRawData(void* ptr, unsigned maxsize);
276 
277  public:
278 
279  Monitor(const std::string &name, dabc::Command cmd = nullptr);
280  virtual ~Monitor();
281 
282  virtual std::string RequiredThrdClass() const
283  { return dabc::typeSocketThread; }
284 
285  std::string MbsNodeName() const { return fMbsNode; }
286 
288  void LoggerAddonCreated();
289 
291  void NewMessage(const std::string &msg);
292 
294  void NewSendCommand(const std::string &cmd, int res = -1);
295 
297  void NewStatus(mbs::DaqStatus& stat);
298  };
299 }
300 
301 
302 #endif
Represents command with its arguments.
Definition: Command.h:99
Queue of commands
Definition: CommandsQueue.h:39
Represents objects hierarchy of remote (or local) DABC process.
Definition: Hierarchy.h:285
Reference on the arbitrary object
Definition: Reference.h:73
@ evntSocketLast
from this event number one can add more socket system events
Definition: SocketThread.h:94
Socket addon for handling I/O events.
Definition: SocketThread.h:144
Active object, which is working inside dabc::Thread.
Definition: Worker.h:116
std::string fMbsNode
Definition: Monitor.h:84
DaqLogWorker(const dabc::Reference &parent, const std::string &name, const std::string &mbsnode, int port)
Definition: Monitor.cxx:1101
virtual void ProcessEvent(const dabc::EventId &)
Definition: Monitor.cxx:1152
virtual double ProcessTimeout(double last_diff)
Definition: Monitor.cxx:1144
MbsLogRec fRec
Definition: Monitor.h:86
virtual ~DaqLogWorker()
Definition: Monitor.cxx:1109
virtual std::string RequiredThrdClass() const
Method returns name of required thread class for processor.
Definition: Monitor.h:101
virtual void OnThreadAssigned()
Definition: Monitor.cxx:1135
Worker to handle connection with MBS remote command server.
Definition: Monitor.h:111
void ProcessNextMbsCommand()
Definition: Monitor.cxx:1330
virtual void OnThreadAssigned()
Definition: Monitor.cxx:1214
virtual ~DaqRemCmdWorker()
Definition: Monitor.cxx:1209
uint32_t fSendCmdId
Definition: Monitor.h:140
std::string fMbsNode
Definition: Monitor.h:133
virtual double ProcessTimeout(double last_diff)
Definition: Monitor.cxx:1312
virtual void ProcessEvent(const dabc::EventId &)
Definition: Monitor.cxx:1248
DaqRemCmdWorker(const dabc::Reference &parent, const std::string &name, const std::string &mbsnode, int port)
Definition: Monitor.cxx:1198
MbsRemCmdRec fSendBuf
Definition: Monitor.h:139
MbsRemCmdRec fRecvBuf
Definition: Monitor.h:141
virtual int ExecuteCommand(dabc::Command cmd)
Main method where commands are executed.
Definition: Monitor.cxx:1319
dabc::CommandsQueue fCmds
Definition: Monitor.h:136
Addon class to retrieve status record from MBS server
Definition: Monitor.h:37
IOState fState
Definition: Monitor.h:54
virtual void OnThreadAssigned()
Definition: Monitor.cxx:63
virtual void OnRecvCompleted()
Method called when receive operation is completed.
Definition: Monitor.cxx:96
uint32_t fSendCmd
Definition: Monitor.h:57
virtual double ProcessTimeout(double last_diff)
Definition: Monitor.cxx:88
DaqStatusAddon(int fd)
Definition: Monitor.cxx:52
mbs::DaqStatus fStatus
Definition: Monitor.h:55
mbs::DaqStatus & GetStatus()
Definition: Monitor.h:69
Base class for monitoring of slow control data.
Interface module for MBS monitoring and control.
Definition: Monitor.h:224
double fPeriod
period how often status is requested in seconds
Definition: Monitor.h:232
double fRateInterval
period for measuring the rate averages in seconds
Definition: Monitor.h:233
virtual void OnThreadAssigned()
Definition: Monitor.cxx:280
virtual std::string RequiredThrdClass() const
Method returns name of required thread class for processor.
Definition: Monitor.h:282
int fHistory
length of parameter history buffer
Definition: Monitor.h:234
bool fWaitingLogger
waiting logger to create cmd port
Definition: Monitor.h:238
void SetRateInterval(double t)
set sampling interval for rates calculation
Definition: Monitor.cxx:977
dabc::Hierarchy fHierarchy
Definition: Monitor.h:227
void NewMessage(const std::string &msg)
Called by LogWorker to inform about new message.
Definition: Monitor.cxx:870
int fLoggerPort
port, providing log information
Definition: Monitor.h:236
bool IsPrompter() const
Definition: Monitor.h:271
std::string fFileStateName
name of filestate parameter
Definition: Monitor.h:243
void FillStatistic(const std::string &options, const std::string &itemname, mbs::DaqStatus *old_daqst, mbs::DaqStatus *new_daqst, double difftime)
Definition: Monitor.cxx:316
virtual int ExecuteCommand(dabc::Command cmd)
Main method where commands are executed.
Definition: Monitor.cxx:1032
void UpdateSetupState(int isloaded)
update mbs setup loaded state
Definition: Monitor.cxx:960
void NewSendCommand(const std::string &cmd, int res=-1)
Called by CmdWorker to inform about new command send (or getting reply)
Definition: Monitor.cxx:884
std::string fSetupStateName
name of "daq setup is loaded" parameter
Definition: Monitor.h:245
bool fPrintf
use printf for major debug output
Definition: Monitor.h:242
dabc::Command fWaitingCmd
command waiting when logger channel is ready
Definition: Monitor.h:239
void UpdateMbsState(int isrunning)
update mbs acq running state
Definition: Monitor.cxx:947
Monitor(const std::string &name, dabc::Command cmd=nullptr)
Definition: Monitor.cxx:132
std::string fMbsNode
name of MBS node to connect
Definition: Monitor.h:230
std::string fAlias
Definition: Monitor.h:231
void UpdateFileState(int isopen)
update file on/off state
Definition: Monitor.cxx:934
std::string fRateIntervalName
name of rate sample interval parameter
Definition: Monitor.h:246
dabc::TimeStamp fStatStamp
time when last status was obtained
Definition: Monitor.h:241
int fStatPort
port, providing stat information (normally 6008)
Definition: Monitor.h:235
int fCmdPort
port, providing remote command access
Definition: Monitor.h:237
void SetHistoryDepth(int entries)
set depth of variable history buffer
Definition: Monitor.cxx:993
std::string fHistoryName
name of variable history parameter
Definition: Monitor.h:247
unsigned fCounter
Definition: Monitor.h:228
std::string MbsNodeName() const
Definition: Monitor.h:285
mbs::DaqStatus fStatus
current DAQ status
Definition: Monitor.h:240
void CreateCommandWorker()
Definition: Monitor.cxx:294
void LoggerAddonCreated()
Called by LogWorker to inform that connection is established.
Definition: Monitor.cxx:863
void NewStatus(mbs::DaqStatus &stat)
Called by DaqStatusAddon to inform about new daq status.
Definition: Monitor.cxx:892
virtual void ProcessTimerEvent(unsigned timer)
Method called by framework when timer event is produced.
Definition: Monitor.cxx:826
std::string fAcqStateName
name of acquisition running parameter
Definition: Monitor.h:244
virtual unsigned WriteRecRawData(void *ptr, unsigned maxsize)
Definition: Monitor.cxx:1092
virtual ~Monitor()
Definition: Monitor.cxx:276
Worker to handle connection with MBS prompter.
Definition: Monitor.h:168
char fSendBuf[256]
Definition: Monitor.h:184
std::string fPrefix
Definition: Monitor.h:179
virtual void ProcessEvent(const dabc::EventId &)
Definition: Monitor.cxx:1422
dabc::CommandsQueue fCmds
Definition: Monitor.h:181
void ProcessNextMbsCommand()
Definition: Monitor.cxx:1503
uint32_t fRecvBuf[2]
Definition: Monitor.h:185
virtual double ProcessTimeout(double last_diff)
Definition: Monitor.cxx:1485
std::string fMbsNode
Definition: Monitor.h:177
PrompterWorker(const dabc::Reference &parent, const std::string &name, const std::string &mbsnode, int port)
Definition: Monitor.cxx:1371
virtual ~PrompterWorker()
Definition: Monitor.cxx:1384
virtual void OnThreadAssigned()
Definition: Monitor.cxx:1389
virtual int ExecuteCommand(dabc::Command cmd)
Main method where commands are executed.
Definition: Monitor.cxx:1492
const char * typeSocketThread
Definition: Object.cxx:80
Support for MBS - standard GSI DAQ.
Definition: api.h:36
void SwapData(void *data, unsigned bytessize)
Event structure, exchanged between DABC threads.
Definition: Thread.h:70
Class for acquiring and holding timestamps.
Definition: timing.h:40