otsdaq  v2_03_00
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 ...(getenv("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 << _E__
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 
112 
113 // for configurable objects, add name to subject
114 #define __CFG_COUT_TYPE__(X) \
115  std::cout << QUOTE(X) << ":" << __MF_SUBJECT__ << ":" << theConfigurationRecordName_ \
116  << ":"
117 #define __CFG_MF_TYPE__(X) \
118  mf::X(std::string(__MF_SUBJECT__) + "-" + theConfigurationRecordName_)
119 
120 #define __CFG_MOUT_ERR__ __CFG_MF_TYPE__(LogError) << __COUT_HDR__
121 #define __CFG_MOUT_WARN__ __CFG_MF_TYPE__(LogWarning) << __COUT_HDR__
122 #define __CFG_MOUT_INFO__ __CFG_MF_TYPE__(LogInfo) << __COUT_HDR__
123 #define __CFG_MOUT__ __CFG_MF_TYPE__(LogDebug) << __COUT_HDR__
124 #define __CFG_MOUTV__(X) __CFG_MOUT__ << QUOTE(X) << " = " << X
125 #define __CFG_COUT_ERR__ __CFG_COUT_TYPE__(LogError) << __COUT_HDR__
126 #define __CFG_COUT_WARN__ __CFG_COUT_TYPE__(LogWarning) << __COUT_HDR__
127 #define __CFG_COUT_INFO__ __CFG_COUT_TYPE__(LogInfo) << __COUT_HDR__
128 #define __CFG_COUT__ __CFG_COUT_TYPE__(LogDebug) << __COUT_HDR__
129 #define __CFG_COUTV__(X) __CFG_COUT__ << QUOTE(X) << " = " << X << __E__
130 
131 #define __CFG_MCOUT_ERR__(X) \
132  { \
133  __CFG_MOUT_ERR__ << X; \
134  __CFG_COUT_ERR__ << X; \
135  }
136 #define __CFG_MCOUT_WARN__(X) \
137  { \
138  __CFG_MOUT_WARN__ << X; \
139  __CFG_COUT_WARN__ << X; \
140  }
141 #define __CFG_MCOUT_INFO__(X) \
142  { \
143  __CFG_MOUT_INFO__ << X; \
144  __CFG_COUT_INFO__ << X; \
145  }
146 #define __CFG_MCOUT__(X) \
147  { \
148  __CFG_MOUT__ << X; \
149  __CFG_COUT__ << X; \
150  }
151 #define __CFG_MCOUTV__(X) \
152  { \
153  __CFG_MOUTV__(X); \
154  __CFG_COUTV__(X); \
155  }
156 
157 #define __CFG_SS__ \
158  std::stringstream ss; \
159  ss << ":" << __MF_SUBJECT__ << ":" << theConfigurationRecordName_ << ":" \
160  << __COUT_HDR__
161 #define __CFG_SS_THROW__ \
162  __CFG_COUT_ERR__ << "\n" << ss.str(); \
163  throw std::runtime_error(ss.str())
164 
166 
167 // for front-end interface objects, add name to subject
168 #define __FE_COUT_TYPE__(X) \
169  std::cout << QUOTE(X) << ":FE:" << getInterfaceType() << ":" << getInterfaceUID() \
170  << ":" << theConfigurationRecordName_ << ":"
171 #define __FE_MF_TYPE__(X) \
172  mf::X(std::string("FE-") + getInterfaceType() + "-" + getInterfaceUID() + "-" + \
173  theConfigurationRecordName_)
174 
175 #define __FE_MOUT_ERR__ __FE_MF_TYPE__(LogError) << __COUT_HDR__
176 #define __FE_MOUT_WARN__ __FE_MF_TYPE__(LogWarning) << __COUT_HDR__
177 #define __FE_MOUT_INFO__ __FE_MF_TYPE__(LogInfo) << __COUT_HDR__
178 #define __FE_MOUT__ __FE_MF_TYPE__(LogDebug) << __COUT_HDR__
179 #define __FE_MOUTV__(X) __FE_MOUT__ << QUOTE(X) << " = " << X
180 #define __FE_COUT_ERR__ __FE_COUT_TYPE__(LogError) << __COUT_HDR__
181 #define __FE_COUT_WARN__ __FE_COUT_TYPE__(LogWarning) << __COUT_HDR__
182 #define __FE_COUT_INFO__ __FE_COUT_TYPE__(LogInfo) << __COUT_HDR__
183 #define __FE_COUT__ __FE_COUT_TYPE__(LogDebug) << __COUT_HDR__
184 #define __FE_COUTV__(X) __FE_COUT__ << QUOTE(X) << " = " << X << __E__
185 
186 #define __FE_MCOUT_ERR__(X) \
187  { \
188  __FE_MOUT_ERR__ << X; \
189  __FE_COUT_ERR__ << X; \
190  }
191 #define __FE_MCOUT_WARN__(X) \
192  { \
193  __FE_MOUT_WARN__ << X; \
194  __FE_COUT_WARN__ << X; \
195  }
196 #define __FE_MCOUT_INFO__(X) \
197  { \
198  __FE_MOUT_INFO__ << X; \
199  __FE_COUT_INFO__ << X; \
200  }
201 #define __FE_MCOUT__(X) \
202  { \
203  __FE_MOUT__ << X; \
204  __FE_COUT__ << X; \
205  }
206 #define __FE_MCOUTV__(X) \
207  { \
208  __FE_MOUTV__(X); \
209  __FE_COUTV__(X); \
210  }
211 
212 #define __FE_SS__ \
213  std::stringstream ss; \
214  ss << ":FE:" << getInterfaceType() << ":" << getInterfaceUID() << ":" \
215  << theConfigurationRecordName_ << ":" << __COUT_HDR__
216 #define __FE_SS_THROW__ \
217  __FE_COUT_ERR__ << "\n" << ss.str(); \
218  throw std::runtime_error(ss.str())
219 
221 
222 // for generic decoration override, just have mfSubject declared
223 #define __GEN_COUT_TYPE__(X) std::cout << QUOTE(X) << ":" << mfSubject_ << ":"
224 #define __GEN_MF_TYPE__(X) mf::X(mfSubject_)
225 
226 #define __GEN_MOUT_ERR__ __GEN_MF_TYPE__(LogError) << __COUT_HDR__
227 #define __GEN_MOUT_WARN__ __GEN_MF_TYPE__(LogWarning) << __COUT_HDR__
228 #define __GEN_MOUT_INFO__ __GEN_MF_TYPE__(LogInfo) << __COUT_HDR__
229 #define __GEN_MOUT__ __GEN_MF_TYPE__(LogDebug) << __COUT_HDR__
230 #define __GEN_MOUTV__(X) __GEN_MOUT__ << QUOTE(X) << " = " << X
231 #define __GEN_COUT_ERR__ __GEN_COUT_TYPE__(LogError) << __COUT_HDR__
232 #define __GEN_COUT_WARN__ __GEN_COUT_TYPE__(LogWarning) << __COUT_HDR__
233 #define __GEN_COUT_INFO__ __GEN_COUT_TYPE__(LogInfo) << __COUT_HDR__
234 #define __GEN_COUT__ __GEN_COUT_TYPE__(LogDebug) << __COUT_HDR__
235 #define __GEN_COUTV__(X) __GEN_COUT__ << QUOTE(X) << " = " << X << __E__
236 
237 #define __GEN_MCOUT_ERR__(X) \
238  { \
239  __GEN_MOUT_ERR__ << X; \
240  __GEN_COUT_ERR__ << X; \
241  }
242 #define __GEN_MCOUT_WARN__(X) \
243  { \
244  __GEN_MOUT_WARN__ << X; \
245  __GEN_COUT_WARN__ << X; \
246  }
247 #define __GEN_MCOUT_INFO__(X) \
248  { \
249  __GEN_MOUT_INFO__ << X; \
250  __GEN_COUT_INFO__ << X; \
251  }
252 #define __GEN_MCOUT__(X) \
253  { \
254  __GEN_MOUT__ << X; \
255  __GEN_COUT__ << X; \
256  }
257 #define __GEN_MCOUTV__(X) \
258  { \
259  __GEN_MOUTV__(X); \
260  __GEN_COUTV__(X); \
261  }
262 
263 #define __GEN_SS__ \
264  std::stringstream ss; \
265  ss << ":" << mfSubject_ << ":" << __COUT_HDR__
266 #define __GEN_SS_THROW__ \
267  __GEN_COUT_ERR__ << "\n" << ss.str(); \
268  throw std::runtime_error(ss.str())
269 
271 
272 // for core supervisor objects (with supervisorClassNoNamespace_ defined), add class to
273 // subject
274 #define __SUP_COUT_TYPE__(X) \
275  std::cout << QUOTE(X) << ":" << supervisorClassNoNamespace_ << ":" \
276  << CorePropertySupervisorBase::getSupervisorUID() << ":"
277 #define __SUP_MF_TYPE__(X) \
278  mf::X(supervisorClassNoNamespace_ + "-" + \
279  CorePropertySupervisorBase::getSupervisorUID())
280 
281 #define __SUP_MOUT_ERR__ __SUP_MF_TYPE__(LogError) << __COUT_HDR__
282 #define __SUP_MOUT_WARN__ __SUP_MF_TYPE__(LogWarning) << __COUT_HDR__
283 #define __SUP_MOUT_INFO__ __SUP_MF_TYPE__(LogInfo) << __COUT_HDR__
284 #define __SUP_MOUT__ __SUP_MF_TYPE__(LogDebug) << __COUT_HDR__
285 #define __SUP_MOUTV__(X) __SUP_MOUT__ << QUOTE(X) << " = " << X
286 #define __SUP_COUT_ERR__ __SUP_COUT_TYPE__(LogError) << __COUT_HDR__
287 #define __SUP_COUT_WARN__ __SUP_COUT_TYPE__(LogWarning) << __COUT_HDR__
288 #define __SUP_COUT_INFO__ __SUP_COUT_TYPE__(LogInfo) << __COUT_HDR__
289 #define __SUP_COUT__ __SUP_COUT_TYPE__(LogDebug) << __COUT_HDR__
290 #define __SUP_COUTV__(X) __SUP_COUT__ << QUOTE(X) << " = " << X << __E__
291 
292 #define __SUP_MCOUT_ERR__(X) \
293  { \
294  __SUP_MOUT_ERR__ << X; \
295  __SUP_COUT_ERR__ << X; \
296  }
297 #define __SUP_MCOUT_WARN__(X) \
298  { \
299  __SUP_MOUT_WARN__ << X; \
300  __SUP_COUT_WARN__ << X; \
301  }
302 #define __SUP_MCOUT_INFO__(X) \
303  { \
304  __SUP_MOUT_INFO__ << X; \
305  __SUP_COUT_INFO__ << X; \
306  }
307 #define __SUP_MCOUT__(X) \
308  { \
309  __SUP_MOUT__ << X; \
310  __SUP_COUT__ << X; \
311  }
312 #define __SUP_MCOUTV__(X) \
313  { \
314  __SUP_MOUTV__(X); \
315  __SUP_COUTV__(X); \
316  }
317 
318 #define __SUP_SS__ \
319  std::stringstream ss; \
320  ss << ":" << supervisorClassNoNamespace_ << ":" \
321  << CorePropertySupervisorBase::getSupervisorUID() << ":" << __COUT_HDR__
322 #define __SUP_SS_THROW__ \
323  __SUP_COUT_ERR__ << "\n" << ss.str(); \
324  throw std::runtime_error(ss.str())
325 
326 //========================================================================================================================
327 // const_cast away the const
328 // so that otsdaq is compatible with slf6 and slf7 versions of xdaq
329 // where they changed to const xdaq::ApplicationDescriptor* in slf7
330 #ifdef XDAQ_NOCONST
331 #define XDAQ_CONST_CALL
332 #else
333 #define XDAQ_CONST_CALL const
334 #endif
335 //========================================================================================================================
336 
337 //========================================================================================================================
338 // declare special ots soft exception
339 // a SOFT exception thrown during runnning workloop by a state machine plugin will pause
340 // the global state machine and allow for manual intervention to resume a run.
341 namespace ots
342 {
343 struct __OTS_SOFT_EXCEPTION__ : public std::exception
344 {
345  __OTS_SOFT_EXCEPTION__(const std::string& what) : what_(what) {}
346  virtual char const* what() const throw() { return what_.c_str(); }
347  std::string what_;
348 };
349 
350 } // namespace ots
351 
352 #endif