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 return res;
318 }
319 default:
320 return m_invalidValue;
321 }
322 }
324 {
325 switch(m_detail.valType)
326 {
327 case valTypes::Bool:
328 {
329 bool val;
330 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;
331 snprintf(str, sizeof(str), m_spec.format.c_str(), val);
332 return std::string(str);
333 }
334 case valTypes::Char:
335 {
336 char val;
337 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;
338 snprintf(str, sizeof(str), m_spec.format.c_str(), val);
339 return std::string(str);
340 }
341 case valTypes::UChar:
342 {
343 unsigned char val;
344 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;
345 snprintf(str, sizeof(str), m_spec.format.c_str(), val);
346 return std::string(str);
347 }
348 case valTypes::Short:
349 {
350 short val;
351 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;
352 snprintf(str, sizeof(str), m_spec.format.c_str(), val);
353 return std::string(str);
354 }
355 case valTypes::UShort:
356 {
357 unsigned short val;
358 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;
359 snprintf(str, sizeof(str), m_spec.format.c_str(), val);
360 return std::string(str);
361 }
362 case valTypes::Int:
363 {
364 int val;
365 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;
366 snprintf(str, sizeof(str), m_spec.format.c_str(), val);
367 return std::string(str);
368 }
369 case valTypes::UInt:
370 {
371 unsigned int val;
372 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;
373 snprintf(str, sizeof(str), m_spec.format.c_str(), val);
374 return std::string(str);
375 }
376 case valTypes::Long:
377 {
378 long val;
379 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;
380 snprintf(str, sizeof(str), m_spec.format.c_str(), val);
381 return std::string(str);
382 }
383 case valTypes::ULong:
384 {
385 unsigned long val;
386 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;
387 snprintf(str, sizeof(str), m_spec.format.c_str(), val);
388 return std::string(str);
389 }
391 {
392 long long val;
393 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;
394 snprintf(str, sizeof(str), m_spec.format.c_str(), val);
395 return std::string(str);
396 }
398 {
399 unsigned long long val;
400 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;
401 snprintf(str, sizeof(str), m_spec.format.c_str(), val);
402 return std::string(str);
403 }
404 case valTypes::Float:
405 {
406 float val;
407 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;
408 snprintf(str, sizeof(str), m_spec.format.c_str(), val);
409 return std::string(str);
410 }
411 case valTypes::Double:
412 {
413 double val;
414 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;
415 snprintf(str, sizeof(str), m_spec.format.c_str(), val);
416 return std::string(str);
417 }
418 default:
419 return m_invalidValue;
420 }
421 }
422
423 return m_invalidValue;
424
425}
426
428 const flatlogs::timespecX & stime,
429 const flatlogs::timespecX & atime
430 )
431{
432 std::string val;
434 {
435 if( getLogStateVal(val,lm, m_spec.device,m_spec.eventCode,stime,atime,reinterpret_cast<std::string(*)(void*)>(m_detail.accessor), &m_hint) != 0)
436 {
437 std::cerr << "getLogStateVal returned error " << __FILE__ << " " << __LINE__ << "\n";
438
439 #ifdef HARD_EXIT
440 std::cerr << __FILE__ << " " << __LINE__ << "\n";
441
442 exit(-1);
443 #endif
444 val = m_invalidValue;
445 }
446 }
447 else
448 {
449 std::cerr << "String type specified as something other than state\n";
450 }
451 return val;
452}
453
454mx::fits::fitsHeaderCard<logMeta::verboseT> logMeta::card( logMap<verboseT> &lm,
455 const flatlogs::timespecX & stime,
456 const flatlogs::timespecX & atime
457 )
458{
459 #ifdef DEBUG
460 std::cerr << __FILE__ << " " << __LINE__ << "\n";
461 #endif
462
463 std::string vstr = value(lm, stime, atime);
464
465 #ifdef DEBUG
466 std::cerr << __FILE__ << " " << __LINE__ << "\n";
467 #endif
468
469 std::string keyw;
471 {
472 //Add spaces to make sure hierarch is invoked
473 keyw = m_spec.device + " " + m_spec.keyword;
474 if(keyw.size() < 9)
475 {
476 keyw += std::string(9-keyw.size(), ' ');
477 }
478 }
479 else
480 {
481 keyw = m_spec.keyword;
482 }
483
484 if(vstr == m_invalidValue)
485 {
486 std::cerr << "got invalid value: " << __FILE__ << " " << __LINE__ << "\n";
487 // always a string sentinel value, so return here to skip the valType conditional
488 return mx::fits::fitsHeaderCard<verboseT>(keyw, vstr, m_spec.comment);
489 }
490
492 {
493 return mx::fits::fitsHeaderCard<verboseT>(keyw, vstr, m_spec.comment);
494 }
495 else
496 {
497 return mx::fits::fitsHeaderCard<verboseT>(keyw, vstr.c_str(), m_detail.valType, m_spec.comment);
498 }
499}
500
501} // logger
502} // MagAOX
503
504
505
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:28
Map of log entries by application name, mapping both to files and to loaded buffers.
Definition logMap.hpp:51
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:427
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:454
A fixed-width timespec structure.
Definition timespecX.hpp:35