otsdaq  v2_04_01
CoutMacros.h
1 #ifndef _ots_Cout_Macros_h_
2 #define _ots_Cout_Macros_h_
3 
4 #include <string.h> //for strstr (not the same as <string>)
5 #include <iostream> //for cout
6 #include <sstream> //for stringstream, std::stringbuf
7 #if MESSAGEFACILITY_HEX_VERSION > 0x20106
8 #include "tracemf.h"
9 #endif
10 
11 // take filename only after srcs/ (this gives by repo name)
12 #define __SHORTFILE__ \
13  (strstr(&__FILE__[0], "/srcs/") ? strstr(&__FILE__[0], "/srcs/") + 6 : __FILE__)
14 
15 // take only file name
16 #define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
17 
18 #define __E__ std::endl
19 
20 //#define __COUT_HDR__ __FILE__ << " : " << __PRETTY_FUNCTION__ << " [" << __LINE__ <<
21 //"]\t"
22 
23 #define __COUT_HDR_FL__ __SHORTFILE__ << " [" << std::dec << __LINE__ << "]\t"
24 #define __COUT_HDR_FP__ __SHORTFILE__ << " : " << __PRETTY_FUNCTION__ << "\t"
25 //#define __COUT_HDR_PL__ __PRETTY_FUNCTION__ << " [" << std::dec << __LINE__ << "]\t"
26 #define __COUT_HDR_F__ __SHORTFILE__ << "\t"
27 #define __COUT_HDR_L__ std::dec << __LINE__ << "\t"
28 #define __COUT_HDR_P__ __PRETTY_FUNCTION__ << "\t"
29 #define __COUT_HDR__ __COUT_HDR_FL__
30 
31 #define __COUT_TYPE__(X) std::cout << QUOTE(X) << ":" << __MF_SUBJECT__ << ":"
32 
33 #define __COUT_ERR__ __COUT_TYPE__(LogError) << __COUT_HDR__
34 #define __COUT_WARN__ __COUT_TYPE__(LogWarning) << __COUT_HDR__
35 #define __COUT_INFO__ __COUT_TYPE__(LogInfo) << __COUT_HDR__
36 #define __COUT__ __COUT_TYPE__(LogDebug) << __COUT_HDR__
37 #define __COUTV__(X) __COUT__ << QUOTE(X) << " = " << X << __E__
38 
39 #define __THROW__(X) throw std::runtime_error(X)
40 
44 
45 #define __MF_SUBJECT__ "ots" // default subject.. others can #undef and re-#define
46 // Note: to turn off MF everywhere, just replace with std::cout here at __MF_TYPE__(X)!
47 
48 #define Q(X) #X
49 #define QUOTE(X) Q(X)
50 //#define __MF_TYPE__(X) FIXME ?? how to do this ...(__ENV__("OTSDAQ_USING_MF")=="1"?
51 // mf::X (__MF_SUBJECT__) : std::cout << QUOTE(X) << ":" << __MF_SUBJECT__ << ":")
52 
53 #define __MF_HDR__ __COUT_HDR__
54 #if MESSAGEFACILITY_HEX_VERSION > 0x20106
55 #define __MF_TYPE__(X) TLOG(X, __MF_SUBJECT__) // for latest artdaq
56 #define __MOUT_ERR__ __MF_TYPE__(TLVL_ERROR) << __MF_HDR__
57 #define __MOUT_WARN__ __MF_TYPE__(TLVL_WARNING) << __MF_HDR__
58 #define __MOUT_INFO__ __MF_TYPE__(TLVL_INFO) << __MF_HDR__
59 #define __MOUT__ __MF_TYPE__(TLVL_DEBUG) << __MF_HDR__
60 #else
61 #define __MF_TYPE__(X) mf::X(__MF_SUBJECT__)
62 #define __MOUT_ERR__ __MF_TYPE__(LogError) << __MF_HDR__
63 #define __MOUT_WARN__ __MF_TYPE__(LogWarning) << __MF_HDR__
64 #define __MOUT_INFO__ __MF_TYPE__(LogInfo) << __MF_HDR__
65 #define __MOUT__ __MF_TYPE__(LogDebug) << __MF_HDR__
66 
67 #endif
68 
69 #define __MOUTV__(X) __MOUT__ << QUOTE(X) << " = " << X
70 
75 #define __MCOUT_ERR__(X) \
76  { \
77  __MOUT_ERR__ << X; \
78  __COUT_ERR__ << X; \
79  }
80 #define __MCOUT_WARN__(X) \
81  { \
82  __MOUT_WARN__ << X; \
83  __COUT_WARN__ << X; \
84  }
85 #define __MCOUT_INFO__(X) \
86  { \
87  __MOUT_INFO__ << X; \
88  __COUT_INFO__ << X; \
89  }
90 #define __MCOUT__(X) \
91  { \
92  __MOUT__ << X; \
93  __COUT__ << X; \
94  }
95 #define __MCOUTV__(X) \
96  { \
97  __MOUTV__(X); \
98  __COUTV__(X); \
99  }
100 
102 
103 #define __SS__ \
104  std::stringstream ss; \
105  ss << ":" << __MF_SUBJECT__ << ":" << __COUT_HDR__
106 #define __SS_THROW__ \
107  __COUT_ERR__ << "\n" << ss.str(); \
108  throw std::runtime_error(ss.str())
109 #define __SS_ONLY_THROW__ throw std::runtime_error(ss.str())
110 #define __SSV__(X) << QUOTE(X) << " = " << X
111 
113 
114 // for configurable objects, add name to subject
115 #define __CFG_COUT_TYPE__(X) \
116  std::cout << QUOTE(X) << ":" << __MF_SUBJECT__ << ":" << theConfigurationRecordName_ \
117  << ":"
118 #define __CFG_MF_TYPE__(X) \
119  mf::X(std::string(__MF_SUBJECT__) + "-" + theConfigurationRecordName_)
120 
121 #define __CFG_MOUT_ERR__ __CFG_MF_TYPE__(LogError) << __COUT_HDR__
122 #define __CFG_MOUT_WARN__ __CFG_MF_TYPE__(LogWarning) << __COUT_HDR__
123 #define __CFG_MOUT_INFO__ __CFG_MF_TYPE__(LogInfo) << __COUT_HDR__
124 #define __CFG_MOUT__ __CFG_MF_TYPE__(LogDebug) << __COUT_HDR__
125 #define __CFG_MOUTV__(X) __CFG_MOUT__ << QUOTE(X) << " = " << X
126 #define __CFG_COUT_ERR__ __CFG_COUT_TYPE__(LogError) << __COUT_HDR__
127 #define __CFG_COUT_WARN__ __CFG_COUT_TYPE__(LogWarning) << __COUT_HDR__
128 #define __CFG_COUT_INFO__ __CFG_COUT_TYPE__(LogInfo) << __COUT_HDR__
129 #define __CFG_COUT__ __CFG_COUT_TYPE__(LogDebug) << __COUT_HDR__
130 #define __CFG_COUTV__(X) __CFG_COUT__ << QUOTE(X) << " = " << X << __E__
131 
132 #define __CFG_MCOUT_ERR__(X) \
133  { \
134  __CFG_MOUT_ERR__ << X; \
135  __CFG_COUT_ERR__ << X; \
136  }
137 #define __CFG_MCOUT_WARN__(X) \
138  { \
139  __CFG_MOUT_WARN__ << X; \
140  __CFG_COUT_WARN__ << X; \
141  }
142 #define __CFG_MCOUT_INFO__(X) \
143  { \
144  __CFG_MOUT_INFO__ << X; \
145  __CFG_COUT_INFO__ << X; \
146  }
147 #define __CFG_MCOUT__(X) \
148  { \
149  __CFG_MOUT__ << X; \
150  __CFG_COUT__ << X; \
151  }
152 #define __CFG_MCOUTV__(X) \
153  { \
154  __CFG_MOUTV__(X); \
155  __CFG_COUTV__(X); \
156  }
157 
158 #define __CFG_SS__ \
159  std::stringstream ss; \
160  ss << ":" << __MF_SUBJECT__ << ":" << theConfigurationRecordName_ << ":" \
161  << __COUT_HDR__
162 #define __CFG_SS_THROW__ \
163  __CFG_COUT_ERR__ << "\n" << ss.str(); \
164  throw std::runtime_error(ss.str())
165 
167 
168 // for front-end interface objects, add name to subject
169 #define __FE_COUT_TYPE__(X) \
170  std::cout << QUOTE(X) << ":FE:" << getInterfaceType() << ":" << getInterfaceUID() \
171  << ":" << theConfigurationRecordName_ << ":"
172 #define __FE_MF_TYPE__(X) \
173  mf::X(std::string("FE-") + getInterfaceType() + "-" + getInterfaceUID() + "-" + \
174  theConfigurationRecordName_)
175 
176 #define __FE_MOUT_ERR__ __FE_MF_TYPE__(LogError) << __COUT_HDR__
177 #define __FE_MOUT_WARN__ __FE_MF_TYPE__(LogWarning) << __COUT_HDR__
178 #define __FE_MOUT_INFO__ __FE_MF_TYPE__(LogInfo) << __COUT_HDR__
179 #define __FE_MOUT__ __FE_MF_TYPE__(LogDebug) << __COUT_HDR__
180 #define __FE_MOUTV__(X) __FE_MOUT__ << QUOTE(X) << " = " << X
181 #define __FE_COUT_ERR__ __FE_COUT_TYPE__(LogError) << __COUT_HDR__
182 #define __FE_COUT_WARN__ __FE_COUT_TYPE__(LogWarning) << __COUT_HDR__
183 #define __FE_COUT_INFO__ __FE_COUT_TYPE__(LogInfo) << __COUT_HDR__
184 #define __FE_COUT__ __FE_COUT_TYPE__(LogDebug) << __COUT_HDR__
185 #define __FE_COUTV__(X) __FE_COUT__ << QUOTE(X) << " = " << X << __E__
186 
187 #define __FE_MCOUT_ERR__(X) \
188  { \
189  __FE_MOUT_ERR__ << X; \
190  __FE_COUT_ERR__ << X; \
191  }
192 #define __FE_MCOUT_WARN__(X) \
193  { \
194  __FE_MOUT_WARN__ << X; \
195  __FE_COUT_WARN__ << X; \
196  }
197 #define __FE_MCOUT_INFO__(X) \
198  { \
199  __FE_MOUT_INFO__ << X; \
200  __FE_COUT_INFO__ << X; \
201  }
202 #define __FE_MCOUT__(X) \
203  { \
204  __FE_MOUT__ << X; \
205  __FE_COUT__ << X; \
206  }
207 #define __FE_MCOUTV__(X) \
208  { \
209  __FE_MOUTV__(X); \
210  __FE_COUTV__(X); \
211  }
212 
213 #define __FE_SS__ \
214  std::stringstream ss; \
215  ss << ":FE:" << getInterfaceType() << ":" << getInterfaceUID() << ":" \
216  << theConfigurationRecordName_ << ":" << __COUT_HDR__
217 #define __FE_SS_THROW__ \
218  __FE_COUT_ERR__ << "\n" << ss.str(); \
219  throw std::runtime_error(ss.str())
220 
222 
223 // for generic decoration override, just have mfSubject declared
224 #define __GEN_COUT_TYPE__(X) std::cout << QUOTE(X) << ":" << mfSubject_ << ":"
225 #define __GEN_MF_TYPE__(X) mf::X(mfSubject_)
226 
227 #define __GEN_MOUT_ERR__ __GEN_MF_TYPE__(LogError) << __COUT_HDR__
228 #define __GEN_MOUT_WARN__ __GEN_MF_TYPE__(LogWarning) << __COUT_HDR__
229 #define __GEN_MOUT_INFO__ __GEN_MF_TYPE__(LogInfo) << __COUT_HDR__
230 #define __GEN_MOUT__ __GEN_MF_TYPE__(LogDebug) << __COUT_HDR__
231 #define __GEN_MOUTV__(X) __GEN_MOUT__ << QUOTE(X) << " = " << X
232 #define __GEN_COUT_ERR__ __GEN_COUT_TYPE__(LogError) << __COUT_HDR__
233 #define __GEN_COUT_WARN__ __GEN_COUT_TYPE__(LogWarning) << __COUT_HDR__
234 #define __GEN_COUT_INFO__ __GEN_COUT_TYPE__(LogInfo) << __COUT_HDR__
235 #define __GEN_COUT__ __GEN_COUT_TYPE__(LogDebug) << __COUT_HDR__
236 #define __GEN_COUTV__(X) __GEN_COUT__ << QUOTE(X) << " = " << X << __E__
237 
238 #define __GEN_MCOUT_ERR__(X) \
239  { \
240  __GEN_MOUT_ERR__ << X; \
241  __GEN_COUT_ERR__ << X; \
242  }
243 #define __GEN_MCOUT_WARN__(X) \
244  { \
245  __GEN_MOUT_WARN__ << X; \
246  __GEN_COUT_WARN__ << X; \
247  }
248 #define __GEN_MCOUT_INFO__(X) \
249  { \
250  __GEN_MOUT_INFO__ << X; \
251  __GEN_COUT_INFO__ << X; \
252  }
253 #define __GEN_MCOUT__(X) \
254  { \
255  __GEN_MOUT__ << X; \
256  __GEN_COUT__ << X; \
257  }
258 #define __GEN_MCOUTV__(X) \
259  { \
260  __GEN_MOUTV__(X); \
261  __GEN_COUTV__(X); \
262  }
263 
264 #define __GEN_SS__ \
265  std::stringstream ss; \
266  ss << ":" << mfSubject_ << ":" << __COUT_HDR__
267 #define __GEN_SS_THROW__ \
268  __GEN_COUT_ERR__ << "\n" << ss.str(); \
269  throw std::runtime_error(ss.str())
270 
272 
273 // for core supervisor objects (with supervisorClassNoNamespace_ defined), add class to
274 // subject
275 #define __SUP_COUT_TYPE__(X) \
276  std::cout << QUOTE(X) << ":" << supervisorClassNoNamespace_ << ":" \
277  << CorePropertySupervisorBase::getSupervisorUID() << ":"
278 #define __SUP_MF_TYPE__(X) \
279  mf::X(supervisorClassNoNamespace_ + "-" + \
280  CorePropertySupervisorBase::getSupervisorUID())
281 
282 #define __SUP_MOUT_ERR__ __SUP_MF_TYPE__(LogError) << __COUT_HDR__
283 #define __SUP_MOUT_WARN__ __SUP_MF_TYPE__(LogWarning) << __COUT_HDR__
284 #define __SUP_MOUT_INFO__ __SUP_MF_TYPE__(LogInfo) << __COUT_HDR__
285 #define __SUP_MOUT__ __SUP_MF_TYPE__(LogDebug) << __COUT_HDR__
286 #define __SUP_MOUTV__(X) __SUP_MOUT__ << QUOTE(X) << " = " << X
287 #define __SUP_COUT_ERR__ __SUP_COUT_TYPE__(LogError) << __COUT_HDR__
288 #define __SUP_COUT_WARN__ __SUP_COUT_TYPE__(LogWarning) << __COUT_HDR__
289 #define __SUP_COUT_INFO__ __SUP_COUT_TYPE__(LogInfo) << __COUT_HDR__
290 #define __SUP_COUT__ __SUP_COUT_TYPE__(LogDebug) << __COUT_HDR__
291 #define __SUP_COUTV__(X) __SUP_COUT__ << QUOTE(X) << " = " << X << __E__
292 
293 #define __SUP_MCOUT_ERR__(X) \
294  { \
295  __SUP_MOUT_ERR__ << X; \
296  __SUP_COUT_ERR__ << X; \
297  }
298 #define __SUP_MCOUT_WARN__(X) \
299  { \
300  __SUP_MOUT_WARN__ << X; \
301  __SUP_COUT_WARN__ << X; \
302  }
303 #define __SUP_MCOUT_INFO__(X) \
304  { \
305  __SUP_MOUT_INFO__ << X; \
306  __SUP_COUT_INFO__ << X; \
307  }
308 #define __SUP_MCOUT__(X) \
309  { \
310  __SUP_MOUT__ << X; \
311  __SUP_COUT__ << X; \
312  }
313 #define __SUP_MCOUTV__(X) \
314  { \
315  __SUP_MOUTV__(X); \
316  __SUP_COUTV__(X); \
317  }
318 
319 #define __SUP_SS__ \
320  std::stringstream ss; \
321  ss << ":" << supervisorClassNoNamespace_ << ":" \
322  << CorePropertySupervisorBase::getSupervisorUID() << ":" << __COUT_HDR__
323 #define __SUP_SS_THROW__ \
324  __SUP_COUT_ERR__ << "\n" << ss.str(); \
325  throw std::runtime_error(ss.str())
326 
327 #define __ENV__(X) \
328  StringMacros::otsGetEnvironmentVarable(X, std::string(__SHORTFILE__), __LINE__)
329 
330 //========================================================================================================================
331 // const_cast away the const
332 // so that otsdaq is compatible with slf6 and slf7 versions of xdaq
333 // where they changed to const xdaq::ApplicationDescriptor* in slf7
334 #ifdef XDAQ_NOCONST
335 #define XDAQ_CONST_CALL
336 #else
337 #define XDAQ_CONST_CALL const
338 #endif
339 //========================================================================================================================
340 
341 //========================================================================================================================
342 // declare special ots soft exception
343 // a SOFT exception thrown during running workloop by a state machine plugin will pause
344 // the global state machine and allow for manual intervention to resume a run.
345 namespace ots
346 {
347 struct __OTS_SOFT_EXCEPTION__ : public std::exception
348 {
349  __OTS_SOFT_EXCEPTION__(const std::string& what) : what_(what) {}
350  virtual char const* what() const throw() { return what_.c_str(); }
351  std::string what_;
352 };
353 
354 } // end namespace ots
355 
356 #endif