CARMA C++
DagMLNode.h
1 /*
2  * Fault System DAG Markup Language Node Objects
3  *
4  * Copyright (c) 2010 Ira W. Snyder <iws@ovro.caltech.edu>
5  */
6 
7 #ifndef DAGMLNODE_H
8 #define DAGMLNODE_H
9 
10 #include <list>
11 #include <map>
12 #include <string>
13 #include <iomanip>
14 
15 #include <boost/shared_ptr.hpp>
16 #include <boost/regex.hpp>
17 
18 #include <xercesc/dom/DOM.hpp>
19 
20 #include <carma/monitor/types.h>
24 
25 #include <carma/fault/DagMLExpr.h>
26 
27 /*----------------------------------------------------------------------------*/
28 /* Helpful Typedefs */
29 /*----------------------------------------------------------------------------*/
30 
31 /* this pre-declaration is unfortunately necessary */
32 class DagMLNode;
33 
34 /* A STL-safe pointer for the DagMLNode class */
35 typedef boost::shared_ptr<DagMLNode> DagMLNodePtr;
36 
37 /* Various containers for the DagMLNode type */
38 typedef std::list<DagMLNodePtr> DagMLNodeList;
39 typedef std::map<std::string, DagMLNodePtr> DagMLNodeMap;
40 
41 struct DagMLNodeUpdateInfo
42 {
43  const carma::monitor::MonitorSystem *inputCms;
44  const carma::monitor::MonitorSystem *outputCms;
45  const VariableMap &varmap;
46  const bool varmap_changed;
47  const DagMLNodeMap &gather_map;
48  const DagMLNodeMap &monitor_map;
49 
50  DagMLNodeUpdateInfo(const carma::monitor::MonitorSystem *inputCms,
51  const carma::monitor::MonitorSystem *outputCms,
52  const VariableMap &varmap,
53  const bool varmap_changed,
54  const DagMLNodeMap &gather_map,
55  const DagMLNodeMap &monitor_map);
56 };
57 
58 /*----------------------------------------------------------------------------*/
59 /* Base object for all DAG ML object types */
60 /*----------------------------------------------------------------------------*/
61 
62 class DagMLNode
63 {
64  public:
65 
66  /* Fault System Internal Error Effects */
67  enum EffectBits {
68  EFFECT_NONE = 0,
69  EFFECT_DRIVE = (1 << 0),
70  EFFECT_MONITORDATA = (1 << 1),
71  EFFECT_OFFLINE = (1 << 2),
72  EFFECT_PHASELOCK = (1 << 3),
73  };
74 
75  /* All node types a-la the Xerces-C DOM */
76  enum NodeTypes {
77  BAD_NODE,
78  BF_OUTPUT_NODE,
79  GATHER_NODE,
80  GATHER_REF_NODE,
81  IF_NODE,
82  MP_NODE,
83  MP_REF_NODE,
84  TOP_NODE,
85  TRANSIENT_NODE,
86  VARMAP_SCOPE_NODE,
87  };
88 
89  /* Construct a DagMLNode from a DOMElement */
90  DagMLNode(xercesc::DOMElement *elem, const enum NodeTypes type);
91  virtual ~DagMLNode();
92 
93  /* Render this object as a string */
94  virtual std::string print() const = 0;
95 
96  /* Substitute from variable map and update internal state */
97  virtual void update(const DagMLNodeUpdateInfo &info) = 0;
98 
99  /* Check that the internal references are ok for evaluation */
100  virtual void check() const = 0;
101 
102  /* Return the name representation of this object */
103  virtual const std::string& getName() const;
104 
105  /* Return the type of this object a-la Xerces-C DOM */
106  virtual enum DagMLNode::NodeTypes getType() const;
107 
108  /* Add a child to this node */
109  virtual void addChild(DagMLNodePtr child);
110  virtual const DagMLNodeList& getChildren() const;
111 
112  protected:
113  enum DagMLNode::NodeTypes node_type_;
114  std::string name_;
115 
116  /* the first-level children of this node */
117  DagMLNodeList children_;
118 };
119 
120 /*----------------------------------------------------------------------------*/
121 /* Top-of-tree Node Specialization */
122 /*----------------------------------------------------------------------------*/
123 
124 class DagTopNode : public DagMLNode
125 {
126  public:
127 
128  DagTopNode(xercesc::DOMElement *elem);
129  std::string print() const;
130  void update(const DagMLNodeUpdateInfo &info);
131  void check() const;
132 };
133 
134 /*----------------------------------------------------------------------------*/
135 /* Monitor Point Specialization */
136 /*----------------------------------------------------------------------------*/
137 
138 class DagMPNode : public DagMLNode
139 {
140  public:
141 
142  DagMPNode(xercesc::DOMElement *elem);
143  std::string print() const;
144  void update(const DagMLNodeUpdateInfo &info);
145  void check() const;
146 
147  /* Evaluate the node for validity (instantaneous) */
148  bool isValid() const;
149 
150  /* Get the error bit */
151  enum DagMLNode::EffectBits getErrorBit() const;
152 
153  /* Observer Disable Alarm */
154  void setDisableAlarm(bool disable);
155  bool getDisableAlarm() const;
156 
157  /* Get the number of frames after which the alarm should sound */
158  unsigned int getAlarmAfterFrames() const;
159 
160  /* Get the tagID */
161  carma::monitor::tagIDType getTagID() const;
162 
163  /* Get the sound file */
164  std::string getSound() const;
165 
166  /* Get the alarm prefix */
167  unsigned int getAlarmPrefix() const;
168 
169  /* Get the silent status */
170  bool getSilent() const;
171 
172  protected:
173 
174  /* Metadata about the MP */
175  unsigned int alarm_after_frames_;
176  enum DagMLNode::EffectBits bit_;
177 
178  /* Soft Disable Alarm */
179  bool disable_alarm_;
180 
181  /* Alarm Sound */
182  std::string sound_;
183 
184  /* Alarm Prefix */
185  unsigned int prefix_;
186 
187  /* Silent Alarm (email-only) */
188  bool silent_;
189 
190  /* Real underlying MonitorPoint */
192 };
193 
194 /*----------------------------------------------------------------------------*/
195 /* Monitor Point Ref Specialization */
196 /*----------------------------------------------------------------------------*/
197 
198 class DagMPRefNode : public DagMLNode
199 {
200  public:
201  DagMPRefNode(xercesc::DOMElement *elem);
202  std::string print() const;
203  void update(const DagMLNodeUpdateInfo &info);
204  void check() const;
205 
206  /* No children allowed! */
207  void addChild(DagMLNodePtr child);
208 
209  /* Get target node (or NULL) */
210  DagMLNodePtr getTarget() const;
211 
212  protected:
213  DagMLNodePtr cached_target_;
214  bool update_success_;
215 };
216 
217 /*----------------------------------------------------------------------------*/
218 /* Gather Node Specialization */
219 /*----------------------------------------------------------------------------*/
220 
221 class DagGatherNode : public DagMLNode
222 {
223  public:
224  DagGatherNode(xercesc::DOMElement *elem);
225  std::string print() const;
226  void update(const DagMLNodeUpdateInfo &info);
227  void check() const;
228 
229  protected:
230 
231 };
232 
233 /*----------------------------------------------------------------------------*/
234 /* Gather Ref Specialization */
235 /*----------------------------------------------------------------------------*/
236 
237 class DagGatherRefNode : public DagMLNode
238 {
239  public:
240  DagGatherRefNode(xercesc::DOMElement *elem);
241  std::string print() const;
242  void update(const DagMLNodeUpdateInfo &info);
243  void check() const;
244 
245  /* No children allowed! */
246  void addChild(DagMLNodePtr child);
247 
248  /* Get target node (or NULL) */
249  DagMLNodePtr getTarget() const;
250 
251  protected:
252  DagMLNodePtr cached_target_;
253  bool update_success_;
254 };
255 
256 /*----------------------------------------------------------------------------*/
257 /* Blank Flag Output Specialization */
258 /*----------------------------------------------------------------------------*/
259 
260 class DagBFOutputNode : public DagMLNode
261 {
262  public:
263  DagBFOutputNode(xercesc::DOMElement *elem);
264  std::string print() const;
265  void update(const DagMLNodeUpdateInfo &info);
266  void check() const;
267 
268  unsigned int getAstroBandNumber() const;
269  unsigned int getAstroInputNumber() const;
270 
271  /* Set the MonitorPoint value */
272  void setOutputValue(uint32_t bitmask);
273 
274  protected:
275  unsigned int astroband_;
276  unsigned int astroinput_;
277 
278  /* Real underlying MonitorPoint */
280 };
281 
282 /*----------------------------------------------------------------------------*/
283 /* Transient Preds Specialization */
284 /*----------------------------------------------------------------------------*/
285 
286 class DagTransientNode : public DagMLNode
287 {
288  public:
289  enum Conditions {
290  ALARM_ENABLE_SUBARRAY,
291  CORRELATOR_NOISE_OFF,
292  };
293 
294  DagTransientNode(xercesc::DOMElement *elem);
295  std::string print() const;
296  void update(const DagMLNodeUpdateInfo &info);
297  void check() const;
298 
299  enum DagTransientNode::Conditions getCondition() const;
300  int getSubarrayNumber() const;
301 
302  protected:
303  enum DagTransientNode::Conditions condition_;
304  std::string subarray_;
305  int subarray_num_;
306 };
307 
308 /*----------------------------------------------------------------------------*/
309 /* If Specialization */
310 /*----------------------------------------------------------------------------*/
311 
312 class DagIfNode : public DagMLNode
313 {
314  public:
315  DagIfNode(xercesc::DOMElement *elem);
316  std::string print() const;
317  void update(const DagMLNodeUpdateInfo &info);
318  void check() const;
319 
320  /* is the underlying reference valid */
321  bool isValid() const;
322 
323  /* is the if condition satisfied? */
324  bool allowPassThrough();
325 
326  protected:
327  std::string mp_str_;
328  std::string val_;
329  bool negate_;
330 
331  boost::regex regex_;
332 
333  /* Real underlying MonitorPoint */
335 
336  /* allow pass through this iteration */
337  bool allow_pass_through_;
338 };
339 
340 /*----------------------------------------------------------------------------*/
341 /* varmap_scope specialization */
342 /*----------------------------------------------------------------------------*/
343 
344 class DagVarmapScopeNode : public DagMLNode
345 {
346  public:
347  DagVarmapScopeNode(xercesc::DOMElement *elem);
348  std::string print() const;
349  void update(const DagMLNodeUpdateInfo &info);
350  void check() const;
351 
352  /* is the underlying reference valid */
353  bool isValid() const;
354 
355  /* force the variable map to be marked as changed */
356  void forceChange();
357 
358  /* add to variable map if the monitor point is valid */
359  void addToVariableMap(VariableMap &varmap, bool &changed);
360 
361  protected:
362  /* set the substitution and changed value */
363  void setSubstitution(const std::string &s);
364 
365  std::string var_;
366  std::string mp_str_;
367 
368  /* track the current substitution and whether it has changed */
369  std::string subst_;
370  bool changed_;
371 
372  /* Real underlying MonitorPoint */
374 };
375 
376 /*----------------------------------------------------------------------------*/
377 /* Bad Node Specialization */
378 /*----------------------------------------------------------------------------*/
379 
380 class DagBadNode : public DagMLNode
381 {
382  public:
383  DagBadNode(xercesc::DOMElement *elem);
384  std::string print() const;
385  void update(const DagMLNodeUpdateInfo &info);
386  void check() const;
387 
388  /* Get the error bit */
389  enum DagMLNode::EffectBits getErrorBit() const;
390 
391  protected:
392  enum DagMLNode::EffectBits bit_;
393 
394 };
395 
396 /*----------------------------------------------------------------------------*/
397 /* Printing support for all DagMLNode derived classes */
398 /*----------------------------------------------------------------------------*/
399 
400 inline std::ostream& operator<<(std::ostream &os, const DagMLNode &node)
401 {
402  return os << node.print();
403 }
404 
405 inline std::ostream& operator<<(std::ostream &os, const enum DagMLNode::EffectBits &bit)
406 {
407  std::string s;
408 
409  switch (bit) {
410  case DagMLNode::EFFECT_NONE:
411  s = "NONE";
412  break;
413  case DagMLNode::EFFECT_DRIVE:
414  s = "DRIVE";
415  break;
416  case DagMLNode::EFFECT_MONITORDATA:
417  s = "MONITORDATA";
418  break;
419  case DagMLNode::EFFECT_OFFLINE:
420  s = "OFFLINE";
421  break;
422  case DagMLNode::EFFECT_PHASELOCK:
423  s = "PHASELOCK";
424  break;
425  default:
426  s = "UNKNOWN";
427  break;
428  }
429 
430  return os << s;
431 }
432 
433 #endif /* DAGMLNODE_H */
434 
435 /* vim: set ts=8 sts=8 sw=8 noet tw=92: */
std::ostream & operator<<(::std::ostream &os, const carma::dbms::Table &table)
Classes that provide the pecializations of monitor points and sense poiints for different datatypes...
Abstract base class for all monitor points.
The monitor system base class.
Abstract base class for a monitor point.
Definition: MonitorPoint.h:68
Byte value (unsigned char) monitor point.
Monitor system base class.
Definition: MonitorSystem.h:81
type definitions for monitor system