API
 
Loading...
Searching...
No Matches
logMeta.hpp
Go to the documentation of this file.
1/** \file logMeta.hpp
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 * History:
8 * - 2020-01-02 created by JRM
9 */
10
11#ifndef logger_logMeta_hpp
12#define logger_logMeta_hpp
13
14#include <mx/ioutils/fits/fitsHeaderCard.hpp>
15// #define HARD_EXIT
16#include "logMap.hpp"
17
18namespace MagAOX
19{
20namespace logger
21{
22
23// This is how the user specifies an item of log meta data (i.e. via a config file)
25{
26 std::string device;
28 std::string member;
29 std::string keyword; // overrides the default
30 std::string format; // overrides the default
31 std::string comment; // overrides the default
32
34 {
35 }
36
37 logMetaSpec( const std::string &dev,
38 const flatlogs::eventCodeT ec,
39 const std::string &memb,
40 const std::string &k,
41 const std::string &f,
42 const std::string &c )
43 : device( dev ), eventCode( ec ), member( memb ), keyword( k ), format( f ), comment( c )
44 {
45 }
46
47 logMetaSpec( const std::string &dev, const flatlogs::eventCodeT ec, const std::string &memb )
48 : device( dev ), eventCode( ec ), member( memb )
49 {
50 }
51};
52
53// This is the data returned by the member accessor.
55{
56 std::string keyword;
57 std::string comment;
58 std::string format;
59 int valType{ -1 };
60 int metaType{ -1 };
61 void *accessor{ nullptr };
62 bool hierarch{ true }; // if false the device name is not included.
63
65 {
66 }
67
68 logMetaDetail( const std::string &k, const std::string &c, const std::string &f, int vt, int mt, void *acc )
69 : keyword( k ), comment( c ), format( f ), valType( vt ), metaType( mt ), accessor( acc )
70 {
71 }
72
73 logMetaDetail( const std::string &k, const std::string &c, const std::string &f, int vt, int mt, void *acc, bool h )
74 : keyword( k ), comment( c ), format( f ), valType( vt ), metaType( mt ), accessor( acc ), hierarch( h )
75 {
76 }
77
78 logMetaDetail( const std::string &k, const std::string &c, int vt, int mt, void *acc, bool h )
79 : keyword( k ), comment( c ), valType( vt ), metaType( mt ), accessor( acc ), hierarch( h )
80 {
81 }
82
83 logMetaDetail( const std::string &k, int vt, int mt, void *acc )
84 : keyword( k ), valType( vt ), metaType( mt ), accessor( acc )
85 {
86 }
87
88 logMetaDetail( const std::string &k, int vt, int mt, void *acc, bool h )
89 : keyword( k ), valType( vt ), metaType( mt ), accessor( acc ), hierarch( h )
90 {
91 }
92};
93
94
95/*logMetaDetail logMemberAccessor( flatlogs::eventCodeT ec,
96 const std::string & memberName
97 );
98*/
99
100template <typename valT, class verboseT = XWC_DEFAULT_VERBOSITY>
101int getLogStateVal( valT &val,
103 const std::string &appName,
105 const flatlogs::timespecX &stime,
106 const flatlogs::timespecX &atime,
107 valT ( *getter )( void * ),
108 char **hint = 0 )
109{
110 char *atprior = nullptr;
111 char *stprior = nullptr;
112
113 char *_hint = nullptr;
114
115 if( hint )
116 _hint = *hint;
117 else
118 _hint = 0;
119
120#ifdef DEBUG
121 std::cerr << __FILE__ << " " << __LINE__ << "\n";
122#endif
123
124 if( lm.getPriorLog( stprior, appName, ev, stime, _hint ) != 0 )
125 {
126 std::cerr << __FILE__ << " " << __LINE__ << " getPriorLog returned error for " << appName << ":" << ev << "\n";
127 return -1;
128 }
129 valT stprV = getter( flatlogs::logHeader::messageBuffer( stprior ) );
130
131 valT atprV;
132
133#ifdef DEBUG
134 std::cerr << __FILE__ << " " << __LINE__ << "\n";
135#endif
136
137 if( lm.getNextLog( atprior, stprior, appName ) != 0 )
138 {
139 std::cerr << __FILE__ << " " << __LINE__ << " getNextLog returned error for " << appName << ":" << ev << "\n";
140 return -1;
141 }
142
143#ifdef DEBUG
144 std::cerr << __FILE__ << " " << __LINE__ << "\n";
145#endif
146
147 while( flatlogs::logHeader::timespec( atprior ) < atime )
148 {
149 atprV = getter( flatlogs::logHeader::messageBuffer( atprior ) );
150 if( atprV != stprV )
151 {
152 val = atprV;
153 if( hint )
154 *hint = stprior;
155 return 0;
156 }
157 stprior = atprior;
158 if( lm.getNextLog( atprior, stprior, appName ) != 0 )
159 {
160 std::cerr << __FILE__ << " " << __LINE__ << " getNextLog returned error for " << appName << ":" << ev
161 << "\n";
162 return -1;
163 }
164 }
165
166 val = stprV;
167
168 if( hint )
169 *hint = stprior;
170 return 0;
171}
172
173template <typename valT, class verboseT = XWC_DEFAULT_VERBOSITY>
174int getLogContVal( valT &val,
176 const std::string &appName,
178 const flatlogs::timespecX &stime,
179 const flatlogs::timespecX &atime,
180 valT ( *getter )( void * ),
181 char **hint = 0 )
182{
183 char *atafter;
184 char *stprior;
185
186 char *_hint;
187 if( hint )
188 _hint = *hint;
189 else
190 _hint = 0;
191
192 flatlogs::timespecX midexp = meanTimespecX( atime, stime );
193
194 // Get log entry before midexp
195 if( lm.getPriorLog( stprior, appName, ev, midexp, _hint ) != 0 )
196 {
197 std::cerr << __FILE__ << " " << __LINE__ << " getPriorLog returned error for " << appName << ":" << ev << "\n";
198 return 1;
199 }
200 valT stprV = getter( flatlogs::logHeader::messageBuffer( stprior ) );
201
202 // Get log entry after.
203 if( lm.getNextLog( atafter, stprior, appName ) != 0 )
204 {
205 std::cerr << __FILE__ << " " << __LINE__ << " getNextLog returned error for " << appName << ":" << ev << "\n";
206#ifdef HARD_EXIT
207 exit( -1 );
208#endif
209 return 1;
210 }
211 valT atprV = getter( flatlogs::logHeader::messageBuffer( atafter ) );
212
213 double st = flatlogs::logHeader::timespec( stprior ).asDouble();
214 double it = midexp.asDouble();
215 double et = flatlogs::logHeader::timespec( atafter ).asDouble();
216
217 val = stprV + ( atprV - stprV ) / ( et - st ) * ( it - st );
218
219 if( hint )
220 *hint = stprior;
221
222 return 0;
223}
224
225/// Manage meta data for a log entry
226/** Handles cases where log is a state, i.e. has one of a finite number of values, or is a
227 * continuous variable, e.g. a temperature.
228 *
229 * Contains the information to construct a FITS header card.
230 */
232{
234
235 public:
237 {
238 String = mx::fits::fitsType<std::string>(),
239 Bool = mx::fits::fitsType<bool>(),
240 Char = mx::fits::fitsType<char>(),
241 UChar = mx::fits::fitsType<unsigned char>(),
242 Short = mx::fits::fitsType<short>(),
243 UShort = mx::fits::fitsType<unsigned short>(),
244 Int = mx::fits::fitsType<int>(),
245 UInt = mx::fits::fitsType<unsigned int>(),
246 Long = mx::fits::fitsType<long>(),
247 ULong = mx::fits::fitsType<unsigned long>(),
248 LongLong = mx::fits::fitsType<long long>(),
249 ULongLong = mx::fits::fitsType<unsigned long long>(),
250 Float = mx::fits::fitsType<float>(),
251 Double = mx::fits::fitsType<double>(),
253 Vector_Bool = 10002,
254 Vector_Char = 10004,
258 Vector_Int = 10012,
259 Vector_UInt = 10014,
260 Vector_Long = 10016,
265 Vector_Double = 10026
266 };
267
273
274 protected:
277
278 bool m_isValid{ false };
279 std::string m_invalidValue{ "invalid" };
280
281 char *m_hint{ nullptr };
282
283 public:
284 logMeta( const logMetaSpec &lms /**< [in] the specification of this meta data entry */ );
285
286 const std::string &device();
287 const std::string &keyword();
288
289 const std::string &comment();
290
291 int setLog( const logMetaSpec & );
292
293 std::string value( logMap<verboseT> &lm, const flatlogs::timespecX &stime, const flatlogs::timespecX &atime );
294
295 std::string valueNumber( logMap<verboseT> &lm, const flatlogs::timespecX &stime, const flatlogs::timespecX &atime );
296
297 std::string valueString( logMap<verboseT> &lm, const flatlogs::timespecX &stime, const flatlogs::timespecX &atime );
298
299 mx::fits::fitsHeaderCard<verboseT>
300 card( logMap<verboseT> &lm, const flatlogs::timespecX &stime, const flatlogs::timespecX &atime );
301};
302
303} // namespace logger
304} // namespace MagAOX
305
306#endif // logger_logMeta_hpp
#define XWC_DEFAULT_VERBOSITY
Definition defaults.hpp:53
uint16_t eventCodeT
The type of an event code (16-bit unsigned int).
Definition logDefs.hpp:40
static void * messageBuffer(bufferPtrT &logBuffer)
Get the message buffer address.
static int timespec(bufferPtrT &logBuffer, const timespecX &ts)
Set the timespec of a log entry.
Declares and defines the logMap 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
Definition dm.hpp:28
Map of log entries by application name, mapping both to files and to loaded buffers.
Definition logMap.hpp:51
int getPriorLog(char *&logBefore, const std::string &appName, const flatlogs::eventCodeT &ev, const flatlogs::timespecX &ts, char *hint=0)
Get the log for an event code which is the first prior to the supplied time.
Definition logMap.hpp:510
int getNextLog(char *&logAfter, char *logCurrent, const std::string &appName)
Get the next log with the same event code which is after the supplied time.
Definition logMap.hpp:634
logMetaDetail(const std::string &k, int vt, int mt, void *acc, bool h)
Definition logMeta.hpp:88
logMetaDetail(const std::string &k, int vt, int mt, void *acc)
Definition logMeta.hpp:83
logMetaDetail(const std::string &k, const std::string &c, const std::string &f, int vt, int mt, void *acc, bool h)
Definition logMeta.hpp:73
logMetaDetail(const std::string &k, const std::string &c, int vt, int mt, void *acc, bool h)
Definition logMeta.hpp:78
logMetaDetail(const std::string &k, const std::string &c, const std::string &f, int vt, int mt, void *acc)
Definition logMeta.hpp:68
flatlogs::eventCodeT eventCode
Definition logMeta.hpp:27
logMetaSpec(const std::string &dev, const flatlogs::eventCodeT ec, const std::string &memb, const std::string &k, const std::string &f, const std::string &c)
Definition logMeta.hpp:37
logMetaSpec(const std::string &dev, const flatlogs::eventCodeT ec, const std::string &memb)
Definition logMeta.hpp:47
Manage meta data for a log entry.
Definition logMeta.hpp:232
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
XWC_DEFAULT_VERBOSITY verboseT
Definition logMeta.hpp:233
std::string m_invalidValue
Definition logMeta.hpp:279
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
double asDouble()
Get the time as a double from a timespecX.