CARMA C++
Monitor.h
Go to the documentation of this file.
1 #ifndef SZA_UTIL_MONITOR_H
2 #define SZA_UTIL_MONITOR_H
3 
11 #include <map>
12 #include <string>
13 #include <vector>
14 
15 #include "carma/szaarrayutils/monitor_stream.h"
16 
17 #include "carma/szautil/DataType.h"
18 #include "carma/szautil/RegDate.h"
21 
22 namespace sza {
23  namespace util {
24 
25  class Monitor {
26  public:
27 
31  Monitor(std::string arcDir, std::string calFile, std::string host,
32  std::string start, bool startWasSet,
33  std::string stop, bool stopWasSet,
34  std::string regFile);
35 
39  Monitor(std::string arcDir, std::string calFile,
40  std::string startMjd, std::string stopMjd);
41 
45  Monitor(std::string host, std::string calFile);
46 
50  virtual ~Monitor();
51 
55  void addRegister(std::string regmapName,
56  std::string boardName,
57  std::string regname,
58  RegAspect aspect=REG_PLAIN,
59  MonitorDataType::FormatType=MonitorDataType::FM_UNKNOWN,
60  char* formatString=0,
61  MonitorDataType::FormatType=MonitorDataType::FM_UNKNOWN,
62  CoordRange* range=0);
63 
67  void addRegister(std::string regSpec);
68 
72  sza::array::MsReadState readNextFrame();
73 
78  void getRegister(std::string regmapName, std::string boardName,
79  std::string regname,
80  unsigned* data, CoordRange* range);
81 
82  void getRegister(std::string regmapName, std::string boardName,
83  std::string regname,
84  int* data, CoordRange* range);
85 
86  void getRegister(std::string regmapName, std::string boardName,
87  std::string regname,
88  unsigned long* data, CoordRange* range);
89 
90  void getRegister(std::string regmapName, std::string boardName,
91  std::string regname,
92  long* data, CoordRange* range);
93 
94  void getRegister(std::string regmapName, std::string boardName,
95  std::string regname,
96  float* data, CoordRange* range);
97 
98  void getRegister(std::string regmapName, std::string boardName,
99  std::string regname,
100  double* data, CoordRange* range);
101 
102  void printDoubleRegs();
103  void printUnsignedIntRegs();
104 
109  void readRegs();
110 
111  unsigned countFrames();
112 
117  std::vector<std::vector<double> > readRegsAsDoubles();
118  std::vector<std::vector<std::vector<MonitorDataType> > > readRegsAsDataTypes();
119 
124  void printRegs();
125  void printRegs2();
126 
131  std::vector<double> getRegsAsDoubles();
132  std::vector<std::vector<MonitorDataType> > getRegsAsDataTypes();
133 
134  std::vector<sza::util::RegDescription> selectedRegs() {
135  return selectedRegs_;
136  }
137 
138  std::vector<sza::util::MonitorDataType::FormatType> selectedFormats() {
139  return selectedFormats_;
140  }
141 
142  std::vector<sza::util::MonitorDataType::FormatType> nativeFormats() {
143  return nativeFormats_;
144  }
145 
149  double getRegAsDouble(MonitorDataType val,
150  RegAspect aspect);
151 
155  void run();
156  void runTest();
157 
162  double* getCalSlotPtr(unsigned iSlot=0);
163 
164  void reinitialize();
165 
166  private:
167 
168  enum KeywordType {
169  ADD_REGISTER,
170  READ,
171  UNKNOWN
172  };
173 
174  struct Keyword {
175  std::string keyword;
176  KeywordType type;
177  };
178 
179  static Keyword keywords[];
180  static int nKey_;
181 
182  struct Format {
183  std::string format;
184  MonitorDataType::FormatType type;
185  };
186 
187  static Monitor::Format formats[];
188  static int nFormat_;
189 
190  enum StreamType {
191  MS_FILE = 0x1,
192  MS_NET = 0x2,
193  MS_BOTH = MS_FILE | MS_NET
194  };
195 
196  Monitor::StreamType type_;
197 
198  OutputStream* outputStream_;
199  char fmtString_[100];
200 
201  sza::array::MonitorStream* ms_;
202 
203  std::map<std::string, std::map<std::string, std::map<std::string, RegDescription* > > > regMap_;
204 
205  std::map<std::string, std::map<std::string, std::map<std::string, MonitorDataType::FormatType > > > regSelFormat_;
206 
207  std::map<std::string, std::map<std::string, std::map<std::string, MonitorDataType::FormatType > > > regNatFormat_;
208 
209  std::map<std::string, std::map<std::string, std::map<std::string, RegAspect > > > regAspect_;
210 
211  std::vector<RegDescription> selectedRegs_;
212  std::vector<RegAxisRange> regAxisRanges_;
213  std::vector<RegAspect> aspects_;
214  std::vector<MonitorDataType::FormatType> selectedFormats_;
215  std::vector<MonitorDataType::FormatType> nativeFormats_;
216  std::vector<MonitorSelection> selections_;
217  std::vector<std::string> formatStrings_;
218  std::vector<bool> hasFormatString_;
219 
220  std::string calFile_;
221  std::string host_;
222  std::string regFile_;
223  bool readRegSpecFromFile_;
224 
225  bool initialized_;
226 
227  bool hybrid_;
228 
232  void privateConstructor(std::string arcDir, std::string calFile,
233  std::string host,
234  std::string start, bool startWasSet,
235  std::string stop, bool stopWasSet,
236  std::string regFile);
237 
238  void setMonitoringInterval(unsigned interval);
239 
240  void sendMonitoringInterval();
241 
242  void sendRegisterSelection();
243 
244  void loadCalFile();
245 
246  void changeMonitorStream();
247 
251  double parseDateAndTime(std::string utc);
252 
256  KeywordType readKeyword(InputStream* stream);
257 
261  MonitorDataType::FormatType readFormat(InputStream* stream);
262  char* readFormatString(InputStream* stream);
263 
267  void skipToNextLine(InputStream* stream);
268 
273  void addRegister(RegDescription& desc, MonitorDataType::FormatType format,
274  char* formatString);
275 
279  void addRegisters(std::vector<RegDescription>& regs,
280  MonitorDataType::FormatType format,
281  char* formatString);
282 
287  void addRegister(InputStream* stream);
288 
289  void getRegister(RegDescription* desc,
290  MonitorDataType* data, CoordRange* range);
291 
292  void getSingleRegisterVal(RegDescription* desc,
293  MonitorDataType* data, CoordRange* range);
294 
298  void getRegisterVals(std::vector<MonitorDataType>& data,
299  RegDescription* desc,
300  MonitorDataType* val,
301  RegAxisRange& regAxisRange);
302 
303  public:
304  static MonitorDataType::FormatType
305  formatOf(RegDescription& reg,
306  MonitorDataType::FormatType format=MonitorDataType::FM_UNKNOWN);
307 
308 
309  private:
310  std::string formatStringOf(MonitorDataType::FormatType format,
311  RegAspect aspect);
312 
313  void outputReg(MonitorDataType val, RegAspect aspect, char* formatPtr);
314  MonitorDataType formatReg(MonitorDataType val, RegAspect aspect, std::string& formatStr);
315 
319  void formatRegs(std::vector<MonitorDataType>& vals,
320  MonitorDataType& val,
321  RegAspect aspect, std::string& formatStr);
322 
326  void convertDateToType(MonitorDataType& val);
327 
331  void convertComplexFloatToType(MonitorDataType& val, RegAspect aspect);
332 
333  void doubleToType(double dVal, MonitorDataType& val);
334 
335  }; // End class Monitor
336 
337  } // End namespace util
338 } // End namespace sza
339 
340 
341 
342 #endif // End #ifndef SZA_UTIL_MONITOR_H
Tagged: Tue Jun 22 22:32:16 UTC 2004.
Tagged: Tue Oct 12 09:13:47 PDT 2004.
Tagged: Thu Mar 31 00:12:30 PST 2005.
Tagged: Mon Sep 27 21:37:46 UTC 2004.