API
 
Loading...
Searching...
No Matches
logMeta.cpp
Go to the documentation of this file.
1/** \file logMeta.cpp
2 * \brief Declares and defines the logMeta class and related classes.
3 * \author Jared R. Males (jaredmales@gmail.com)
4 *
5 * \ingroup logger_files
6 *
7 */
8
9
10#include "logMeta.hpp"
11
12//#include "generated/logTypes.hpp"
13
15
16
17namespace MagAOX
18{
19namespace logger
20{
21
22/*
23logMetaDetail logMemberAccessor( flatlogs::eventCodeT ec,
24 const std::string & memberName
25 )
26{
27 switch(ec)
28 {
29 case telem_stdcam::eventCode:
30 return telem_stdcam::getAccessor(memberName);
31 case telem_telcat::eventCode:
32 return telem_telcat::getAccessor(memberName);
33 case telem_teldata::eventCode:
34 return telem_teldata::getAccessor(memberName);
35 case telem_telpos::eventCode:
36 return telem_telpos::getAccessor(memberName);
37 case telem_stage::eventCode:
38 return telem_stage::getAccessor(memberName);
39 case telem_zaber::eventCode:
40 return telem_zaber::getAccessor(memberName);
41 case telem_dmspeck::eventCode:
42 return telem_dmspeck::getAccessor(memberName);
43 case telem_observer::eventCode:
44 return telem_observer::getAccessor(memberName);
45 case telem_fxngen::eventCode:
46 return telem_fxngen::getAccessor(memberName);
47 case telem_loopgain::eventCode:
48 return telem_loopgain::getAccessor(memberName);
49 default:
50 std::cerr << "Missing logMemberAccessor case entry for " << ec << ": " << memberName << "\n";
51 return logMetaDetail();
52 }
53}*/
54
55
57{
58 setLog(lms);
59}
60
61const std::string & logMeta::device()
62{
63 return m_spec.device;
64}
65
66const std::string & logMeta::keyword()
67{
68 return m_spec.keyword;
69}
70
71const std::string & logMeta::comment()
72{
73 return m_spec.comment;
74}
75
76int logMeta::setLog( const logMetaSpec & lms )
77{
78 m_spec = lms;
80
83 if(m_spec.format == "")
84 {
85 switch(m_detail.valType)
86 {
88 m_spec.format = "%s";
89 break;
90 case valTypes::Bool:
91 m_spec.format = "%d";
92 break;
93 case valTypes::Char:
94 m_spec.format = "%d";
95 break;
96 case valTypes::UChar:
97 m_spec.format = "%u";
98 break;
99 case valTypes::Short:
100 m_spec.format = "%d";
101 break;
102 case valTypes::UShort:
103 m_spec.format = "%u";
104 break;
105 case valTypes::Int:
106 m_spec.format = "%d";
107 break;
108 case valTypes::UInt:
109 m_spec.format = "%u";
110 break;
111 case valTypes::Long:
112 m_spec.format = "%ld";
113 break;
114 case valTypes::ULong:
115 m_spec.format = "%lu";
116 break;
117 case valTypes::Float:
118 m_spec.format = "%G";
119 break;
120 case valTypes::Double:
121 m_spec.format = "%G";
122 break;
124 m_spec.format = "%d";
125 break;
127 m_spec.format = "%G";
128 break;
129 default:
130 std::cerr << "Unrecognised value type for " + m_spec.device + " " + m_spec.keyword + ". Using format %d/\n";
131 m_spec.format = "%d";
132
133 }
134
135 }
136
137
139
140 return 0;
141}
142
143
145 const flatlogs::timespecX & stime,
146 const flatlogs::timespecX & atime
147 )
148{
149 if(m_detail.accessor == nullptr) return "";
150
152 {
153 std::string vs = valueString( lm, stime, atime);
154 if(vs == m_invalidValue)
155 {
156 std::cerr << __FILE__ << " " << __LINE__ << " valueString returned invalid value\n";
157 }
158 return vs;
159 }
160 else
161 {
162 std::string vn = valueNumber( lm, stime, atime);
163 if(vn == m_invalidValue)
164 {
165 std::cerr << __FILE__ << " " << __LINE__ << " valueNumber returned invalid value\n";
166 }
167 return vn;
168 }
169}
170
172 const flatlogs::timespecX & stime,
173 const flatlogs::timespecX & atime
174 )
175{
176 char str[64];
177
179 {
180 switch(m_detail.valType)
181 {
182 case valTypes::Bool:
183 {
184 bool val;
185 if( getLogStateVal(val,lm, m_spec.device,m_spec.eventCode,stime,atime,reinterpret_cast<bool(*)(void*)>(m_detail.accessor), &m_hint) != 0) return m_invalidValue;
186 snprintf(str, sizeof(str), m_spec.format.c_str(), val);
187 return std::string(str);
188 }
189 case valTypes::Char:
190 {
191 char val;
192 if( getLogStateVal(val,lm, m_spec.device,m_spec.eventCode,stime,atime,reinterpret_cast<char(*)(void*)>(m_detail.accessor), &m_hint) != 0)
193 {
194 std::cerr << "getLogStateVal returned error: " << __FILE__ << " " << __LINE__ << "\n";
195 return m_invalidValue;
196 }
197 snprintf(str, sizeof(str), m_spec.format.c_str(), val);
198 return std::string(str);
199 }
200 case valTypes::UChar:
201 {
202 unsigned char val;
203 if( getLogStateVal(val,lm, m_spec.device,m_spec.eventCode,stime,atime,reinterpret_cast<unsigned char(*)(void*)>(m_detail.accessor), &m_hint) != 0) return m_invalidValue;
204 snprintf(str, sizeof(str), m_spec.format.c_str(), val);
205 return std::string(str);
206 }
207 case valTypes::Short:
208 {
209 short val;
210 if( getLogStateVal(val,lm, m_spec.device,m_spec.eventCode,stime,atime,reinterpret_cast<short(*)(void*)>(m_detail.accessor), &m_hint) != 0) return m_invalidValue;
211 snprintf(str, sizeof(str), m_spec.format.c_str(), val);
212 return std::string(str);
213 }
214 case valTypes::UShort:
215 {
216 unsigned short val;
217 if( getLogStateVal(val,lm, m_spec.device,m_spec.eventCode,stime,atime,reinterpret_cast<unsigned short(*)(void*)>(m_detail.accessor), &m_hint) != 0) return m_invalidValue;
218 snprintf(str, sizeof(str), m_spec.format.c_str(), val);
219 return std::string(str);
220 }
221 case valTypes::Int:
222 {
223 int val;
224 if( getLogStateVal(val,lm, m_spec.device,m_spec.eventCode,stime,atime,reinterpret_cast<int(*)(void*)>(m_detail.accessor), &m_hint) != 0) return m_invalidValue;
225 snprintf(str, sizeof(str), m_spec.format.c_str(), val);
226 return std::string(str);
227 }
228 case valTypes::UInt:
229 {
230 unsigned int val;
231 if( getLogStateVal(val,lm, m_spec.device,m_spec.eventCode,stime,atime,reinterpret_cast<unsigned int(*)(void*)>(m_detail.accessor), &m_hint) != 0) return m_invalidValue;
232 snprintf(str, sizeof(str), m_spec.format.c_str(), val);
233 return std::string(str);
234 }
235 case valTypes::Long:
236 {
237 long val;
238 if( getLogStateVal(val,lm, m_spec.device,m_spec.eventCode,stime,atime,reinterpret_cast<long(*)(void*)>(m_detail.accessor), &m_hint) != 0) return m_invalidValue;
239 snprintf(str, sizeof(str), m_spec.format.c_str(), val);
240 return std::string(str);
241 }
242 case valTypes::ULong:
243 {
244 unsigned long val;
245 if( getLogStateVal(val,lm, m_spec.device,m_spec.eventCode,stime,atime,reinterpret_cast<unsigned long(*)(void*)>(m_detail.accessor), &m_hint) != 0) return m_invalidValue;
246 snprintf(str, sizeof(str), m_spec.format.c_str(), val);
247 return std::string(str);
248 }
250 {
251 long long val;
252 if( getLogStateVal(val,lm, m_spec.device,m_spec.eventCode,stime,atime,reinterpret_cast<long long(*)(void*)>(m_detail.accessor), &m_hint) != 0) return m_invalidValue;
253 snprintf(str, sizeof(str), m_spec.format.c_str(), val);
254 return std::string(str);
255 }
257 {
258 unsigned long long val;
259 if( getLogStateVal(val,lm, m_spec.device,m_spec.eventCode,stime,atime,reinterpret_cast<unsigned long long(*)(void*)>(m_detail.accessor), &m_hint) != 0) return m_invalidValue;
260 snprintf(str, sizeof(str), m_spec.format.c_str(), val);
261 return std::string(str);
262 }
263 case valTypes::Float:
264 {
265 float val;
266 if( getLogStateVal(val,lm, m_spec.device,m_spec.eventCode,stime,atime,reinterpret_cast<float(*)(void*)>(m_detail.accessor), &m_hint) != 0) return m_invalidValue;
267 snprintf(str, sizeof(str), m_spec.format.c_str(), val);
268 return std::string(str);
269 }
270 case valTypes::Double:
271 {
272 double val;
273 if( getLogStateVal(val,lm, m_spec.device,m_spec.eventCode,stime,atime,reinterpret_cast<double(*)(void*)>(m_detail.accessor), &m_hint) != 0) return m_invalidValue;
274 snprintf(str, sizeof(str), m_spec.format.c_str(), val);
275 return std::string(str);
276 }
278 {
279 std::vector<bool> val;
280 if( getLogStateVal(val,lm, m_spec.device,m_spec.eventCode,stime,atime,reinterpret_cast<std::vector<bool>(*)(void*)>(m_detail.accessor), &m_hint) != 0) return m_invalidValue;
281
282 if(val.size() == 0) return "";
283
284 std::string res;
285
286 for(size_t n = 0; n < val.size()-1; ++n)
287 {
288 snprintf(str, sizeof(str), m_spec.format.c_str(), (int) val[n]);
289 res += str;
290 res += ',';
291 }
292
293 snprintf(str, sizeof(str), m_spec.format.c_str(), (int) val.back());
294 res += str;
295
296 return res;
297 }
299 {
300 std::vector<float> val;
301 if( getLogStateVal(val,lm, m_spec.device,m_spec.eventCode,stime,atime,reinterpret_cast<std::vector<float>(*)(void*)>(m_detail.accessor), &m_hint) != 0) return m_invalidValue;
302
303 if(val.size() == 0) return "";
304
305 std::string res;
306
307 for(size_t n = 0; n < val.size()-1; ++n)
308 {
309 snprintf(str, sizeof(str), m_spec.format.c_str(), val[n]);
310 res += str;
311 res += ',';
312 }
313
314 snprintf(str, sizeof(str), m_spec.format.c_str(), val.back());
315 res += str;
316
317 std::cerr << "State Vector_Float " << res << '\n';
318 return res;
319 }
320 default:
321 return m_invalidValue;
322 }
323 }
325 {
326 switch(m_detail.valType)
327 {
328 case valTypes::Bool:
329 {
330 bool val;
331 if( getLogContVal(val,lm, m_spec.device,m_spec.eventCode,stime,atime,reinterpret_cast<bool(*)(void*)>(m_detail.accessor), &m_hint) != 0) return m_invalidValue;
332 snprintf(str, sizeof(str), m_spec.format.c_str(), val);
333 return std::string(str);
334 }
335 case valTypes::Char:
336 {
337 char val;
338 if( getLogContVal(val,lm, m_spec.device,m_spec.eventCode,stime,atime,reinterpret_cast<char(*)(void*)>(m_detail.accessor), &m_hint) != 0) return m_invalidValue;
339 snprintf(str, sizeof(str), m_spec.format.c_str(), val);
340 return std::string(str);
341 }
342 case valTypes::UChar:
343 {
344 unsigned char val;
345 if( getLogContVal(val,lm, m_spec.device,m_spec.eventCode,stime,atime,reinterpret_cast<unsigned char(*)(void*)>(m_detail.accessor), &m_hint) != 0) return m_invalidValue;
346 snprintf(str, sizeof(str), m_spec.format.c_str(), val);
347 return std::string(str);
348 }
349 case valTypes::Short:
350 {
351 short val;
352 if( getLogContVal(val,lm, m_spec.device,m_spec.eventCode,stime,atime,reinterpret_cast<short(*)(void*)>(m_detail.accessor), &m_hint) != 0) return m_invalidValue;
353 snprintf(str, sizeof(str), m_spec.format.c_str(), val);
354 return std::string(str);
355 }
356 case valTypes::UShort:
357 {
358 unsigned short val;
359 if( getLogContVal(val,lm, m_spec.device,m_spec.eventCode,stime,atime,reinterpret_cast<unsigned short(*)(void*)>(m_detail.accessor), &m_hint) != 0) return m_invalidValue;
360 snprintf(str, sizeof(str), m_spec.format.c_str(), val);
361 return std::string(str);
362 }
363 case valTypes::Int:
364 {
365 int val;
366 if( getLogContVal(val,lm, m_spec.device,m_spec.eventCode,stime,atime,reinterpret_cast<int(*)(void*)>(m_detail.accessor), &m_hint) != 0) return m_invalidValue;
367 snprintf(str, sizeof(str), m_spec.format.c_str(), val);
368 return std::string(str);
369 }
370 case valTypes::UInt:
371 {
372 unsigned int val;
373 if( getLogContVal(val,lm, m_spec.device,m_spec.eventCode,stime,atime,reinterpret_cast<unsigned int(*)(void*)>(m_detail.accessor), &m_hint) != 0) return m_invalidValue;
374 snprintf(str, sizeof(str), m_spec.format.c_str(), val);
375 return std::string(str);
376 }
377 case valTypes::Long:
378 {
379 long val;
380 if( getLogContVal(val,lm, m_spec.device,m_spec.eventCode,stime,atime,reinterpret_cast<long(*)(void*)>(m_detail.accessor), &m_hint) != 0) return m_invalidValue;
381 snprintf(str, sizeof(str), m_spec.format.c_str(), val);
382 return std::string(str);
383 }
384 case valTypes::ULong:
385 {
386 unsigned long val;
387 if( getLogContVal(val,lm, m_spec.device,m_spec.eventCode,stime,atime,reinterpret_cast<unsigned long(*)(void*)>(m_detail.accessor), &m_hint) != 0) return m_invalidValue;
388 snprintf(str, sizeof(str), m_spec.format.c_str(), val);
389 return std::string(str);
390 }
392 {
393 long long val;
394 if( getLogContVal(val,lm, m_spec.device,m_spec.eventCode,stime,atime,reinterpret_cast<long long(*)(void*)>(m_detail.accessor), &m_hint) != 0) return m_invalidValue;
395 snprintf(str, sizeof(str), m_spec.format.c_str(), val);
396 return std::string(str);
397 }
399 {
400 unsigned long long val;
401 if( getLogContVal(val,lm, m_spec.device,m_spec.eventCode,stime,atime,reinterpret_cast<unsigned long long(*)(void*)>(m_detail.accessor), &m_hint) != 0) return m_invalidValue;
402 snprintf(str, sizeof(str), m_spec.format.c_str(), val);
403 return std::string(str);
404 }
405 case valTypes::Float:
406 {
407 float val;
408 if( getLogContVal(val,lm, m_spec.device,m_spec.eventCode,stime,atime,reinterpret_cast<float(*)(void*)>(m_detail.accessor), &m_hint) != 0) return m_invalidValue;
409 snprintf(str, sizeof(str), m_spec.format.c_str(), val);
410 return std::string(str);
411 }
412 case valTypes::Double:
413 {
414 double val;
415 if( getLogContVal(val,lm, m_spec.device,m_spec.eventCode,stime,atime,reinterpret_cast<double(*)(void*)>(m_detail.accessor), &m_hint) != 0) return m_invalidValue;
416 snprintf(str, sizeof(str), m_spec.format.c_str(), val);
417 return std::string(str);
418 }
419 default:
420 return m_invalidValue;
421 }
422 }
423
424 return m_invalidValue;
425
426}
427
429 const flatlogs::timespecX & stime,
430 const flatlogs::timespecX & atime
431 )
432{
433 std::string val;
435 {
436 if( getLogStateVal(val,lm, m_spec.device,m_spec.eventCode,stime,atime,reinterpret_cast<std::string(*)(void*)>(m_detail.accessor), &m_hint) != 0)
437 {
438 std::cerr << "getLogStateVal returned error " << __FILE__ << " " << __LINE__ << "\n";
439
440 #ifdef HARD_EXIT
441 std::cerr << __FILE__ << " " << __LINE__ << "\n";
442
443 exit(-1);
444 #endif
445 val = m_invalidValue;
446 }
447 }
448 else
449 {
450 std::cerr << "String type specified as something other than state\n";
451 }
452 return val;
453}
454
455mx::fits::fitsHeaderCard<logMeta::verboseT> logMeta::card( logMap<verboseT> &lm,
456 const flatlogs::timespecX & stime,
457 const flatlogs::timespecX & atime
458 )
459{
460 #ifdef DEBUG
461 std::cerr << __FILE__ << " " << __LINE__ << "\n";
462 #endif
463
464 std::string vstr = value(lm, stime, atime);
465
466 #ifdef DEBUG
467 std::cerr << __FILE__ << " " << __LINE__ << "\n";
468 #endif
469
470 std::string keyw;
472 {
473 //Add spaces to make sure hierarch is invoked
474 keyw = m_spec.device + " " + m_spec.keyword;
475 if(keyw.size() < 9)
476 {
477 keyw += std::string(9-keyw.size(), ' ');
478 }
479 }
480 else
481 {
482 keyw = m_spec.keyword;
483 }
484
485 if(vstr == m_invalidValue)
486 {
487 std::cerr << "got invalid value: " << __FILE__ << " " << __LINE__ << "\n";
488 // always a string sentinel value, so return here to skip the valType conditional
489 return mx::fits::fitsHeaderCard<verboseT>(keyw, vstr, m_spec.comment);
490 }
491
493 {
494 return mx::fits::fitsHeaderCard<verboseT>(keyw, vstr, m_spec.comment);
495 }
496 else
497 {
498 return mx::fits::fitsHeaderCard<verboseT>(keyw, vstr.c_str(), m_detail.valType, m_spec.comment);
499 }
500}
501
502} // logger
503} // MagAOX
504
505
506
Declares and defines the logMeta class and related classes.
int getLogContVal(valT &val, logMap< verboseT > &lm, const std::string &appName, flatlogs::eventCodeT ev, const flatlogs::timespecX &stime, const flatlogs::timespecX &atime, valT(*getter)(void *), char **hint=0)
Definition logMeta.hpp:174
int getLogStateVal(valT &val, logMap< verboseT > &lm, const std::string &appName, flatlogs::eventCodeT ev, const flatlogs::timespecX &stime, const flatlogs::timespecX &atime, valT(*getter)(void *), char **hint=0)
Definition logMeta.hpp:101
logMetaDetail logMemberAccessor(flatlogs::eventCodeT ec, const std::string &memberName)
Definition dm.hpp:19
Map of log entries by application name, mapping both to files and to loaded buffers.
Definition logMap.hpp:55
flatlogs::eventCodeT eventCode
Definition logMeta.hpp:27
std::string valueNumber(logMap< verboseT > &lm, const flatlogs::timespecX &stime, const flatlogs::timespecX &atime)
Definition logMeta.cpp:171
const std::string & device()
Definition logMeta.cpp:61
std::string valueString(logMap< verboseT > &lm, const flatlogs::timespecX &stime, const flatlogs::timespecX &atime)
Definition logMeta.cpp:428
logMetaDetail m_detail
Definition logMeta.hpp:276
const std::string & keyword()
Definition logMeta.cpp:66
std::string m_invalidValue
Definition logMeta.hpp:279
logMeta(const logMetaSpec &lms)
Definition logMeta.cpp:56
std::string value(logMap< verboseT > &lm, const flatlogs::timespecX &stime, const flatlogs::timespecX &atime)
Definition logMeta.cpp:144
int setLog(const logMetaSpec &)
Definition logMeta.cpp:76
const std::string & comment()
Definition logMeta.cpp:71
mx::fits::fitsHeaderCard< verboseT > card(logMap< verboseT > &lm, const flatlogs::timespecX &stime, const flatlogs::timespecX &atime)
Definition logMeta.cpp:455
A fixed-width timespec structure.
Definition timespecX.hpp:35