otsdaq  v2_05_02_indev
CoutMacros.h
1 #ifndef _ots_Cout_Macros_h_
2 #define _ots_Cout_Macros_h_
3 
4 // clang-format off
5 
6 #include <string.h> //for strstr (not the same as <string>)
7 #include <iostream> //for cout
8 #include <sstream> //for stringstream, std::stringbuf
9 
10 #define TRACEMF_USE_VERBATIM 1 //for trace longer path filenames
11 #include "tracemf.h"
12 
13 // take filename only after srcs/ (this gives by repo name)
14 // use 'builtin' to try to define at compile time
15 #define __SHORTFILE__ (__builtin_strstr(&__FILE__[0], "/srcs/") ? __builtin_strstr(&__FILE__[0], "/srcs/") + 6 : __FILE__)
16 
17 // take only file name
18 #define __FILENAME__ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
19 
20 #define __E__ std::endl
21 
22 #define __THROW__(X) throw std::runtime_error(X)
23 
24 //un-comment __COUT_TO_STD__ to send __COUT__ directly to std::cout, rather than through message facility
25 //#define __COUT_TO_STD__ 1
26 
30 
31 #define __MF_SUBJECT__ __FILENAME__ // default subject.. others can #undef and re-#define
32 // Note: to turn off MF everywhere, just replace with std::cout here at __MF_TYPE__(X)!
33 
34 #define Q(X) #X
35 #define QUOTE(X) Q(X)
36 //#define __MF_TYPE__(X) FIXME ?? how to do this ...(__ENV__("OTSDAQ_USING_MF")=="1"?
37 // mf::X (__MF_SUBJECT__) : std::cout << QUOTE(X) << ":" << __MF_SUBJECT__ << ":")
38 
39 #define __COUT_HDR_F__ __SHORTFILE__ << "\t"
40 #define __COUT_HDR_L__ "[" << std::dec << __LINE__ << "]\t"
41 #define __COUT_HDR_P__ __PRETTY_FUNCTION__ << "\t"
42 #define __COUT_HDR_FL__ __SHORTFILE__ << " " << __COUT_HDR_L__
43 #define __COUT_HDR_FP__ __SHORTFILE__ << " : " << __COUT_HDR_P__
44 #define __COUT_HDR__ ""//__COUT_HDR_FL__
45 #define __MF_HDR__ ""//__COUT_HDR__
46 
48 #define __MF_DECOR__ (__MF_SUBJECT__)
49 #define __MF_TYPE__(X) TLOG(X, __MF_DECOR__)
50 
51 #ifndef __COUT_TO_STD__
52 #define __COUT_TYPE__(X) __MF_TYPE__(X)
53 #else
54 #define __COUT_TYPE__(X) std::cout << QUOTE(X) << ":" << __MF_DECOR__ << ":" << __COUT_HDR_FL__
55 #endif
56 
57 #define __MOUT_ERR__ __MF_TYPE__(TLVL_ERROR) << __MF_HDR__
58 #define __MOUT_WARN__ __MF_TYPE__(TLVL_WARNING) << __MF_HDR__
59 #define __MOUT_INFO__ __MF_TYPE__(TLVL_INFO) << __MF_HDR__
60 #define __MOUT__ __MF_TYPE__(TLVL_DEBUG) << __MF_HDR__
61 #define __MOUTV__(X) __MOUT__ << QUOTE(X) << " = " << X
62 
63 #define __COUT_ERR__ __COUT_TYPE__(TLVL_ERROR) << __COUT_HDR__
64 #define __COUT_WARN__ __COUT_TYPE__(TLVL_WARNING) << __COUT_HDR__
65 #define __COUT_INFO__ __COUT_TYPE__(TLVL_INFO) << __COUT_HDR__
66 #define __COUT__ __COUT_TYPE__(TLVL_DEBUG) << __COUT_HDR__
67 #define __COUTT__ __COUT_TYPE__(TLVL_TRACE) << __COUT_HDR__
68 #define __COUTV__(X) __COUT__ << QUOTE(X) << " = " << X << __E__
69 #define __COUTTV__(X) __COUTT__ << QUOTE(X) << " = " << X << __E__
70 
71 
76 #define __MCOUT_ERR__(X) { __MOUT_ERR__ << X;} //causes duplicate with mf improvements: { __MOUT_ERR__ << X; __COUT_ERR__ << X; }
77 #define __MCOUT_WARN__(X) { __MOUT_WARN__ << X;} //causes duplicate with mf improvements: { __MOUT_WARN__ << X; __COUT_WARN__ << X; }
78 #define __MCOUT_INFO__(X) { __MOUT_INFO__ << X;} //causes duplicate with mf improvements: { __MOUT_INFO__ << X; __COUT_INFO__ << X; }
79 #define __MCOUT__(X) { __MOUT__ << X;} //causes duplicate with mf improvements: { __MOUT__ << X; __COUT__ << X; }
80 #define __MCOUTV__(X) { __MOUTV__(X);} //causes duplicate with mf improvements: { __MOUTV__(X); __COUTV__(X); }
81 
83 
84 #define __SS__ std::stringstream ss; ss << ":" << __MF_DECOR__ << ":" << __COUT_HDR_FL__ << __COUT_HDR__
85 #define __SS_THROW__ { __COUT_ERR__ << "\n" << ss.str(); throw std::runtime_error(ss.str()); } //put in {}'s to prevent surprises, e.g. if ... else __SS_THROW__;
86 #define __SS_ONLY_THROW__ throw std::runtime_error(ss.str())
87 #define __SSV__(X) __SS__ << QUOTE(X) << " = " << X
88 
90 // for configurable objects, add name to subject
91 #define __CFG_MF_DECOR__ (theConfigurationRecordName_ + "\t<> ")
92 #define __CFG_MF_TYPE__(X) TLOG(X, __MF_SUBJECT__) << __CFG_MF_DECOR__
93 
94 #ifndef __COUT_TO_STD__
95 #define __CFG_COUT_TYPE__(X) __CFG_MF_TYPE__(X)
96 #else
97 #define __CFG_COUT_TYPE__(X) std::cout << QUOTE(X) << ":" << __CFG_MF_DECOR__ << ":" << __COUT_HDR_FL__ << __COUT_HDR__
98 #endif
99 
100 #define __CFG_MOUT_ERR__ __CFG_MF_TYPE__(TLVL_ERROR) << __COUT_HDR__
101 #define __CFG_MOUT_WARN__ __CFG_MF_TYPE__(TLVL_WARNING) << __COUT_HDR__
102 #define __CFG_MOUT_INFO__ __CFG_MF_TYPE__(TLVL_INFO) << __COUT_HDR__
103 #define __CFG_MOUT__ __CFG_MF_TYPE__(TLVL_DEBUG) << __COUT_HDR__
104 #define __CFG_MOUTV__(X) __CFG_MOUT__ << QUOTE(X) << " = " << X
105 #define __CFG_COUT_ERR__ __CFG_COUT_TYPE__(TLVL_ERROR) << __COUT_HDR__
106 #define __CFG_COUT_WARN__ __CFG_COUT_TYPE__(TLVL_WARNING) << __COUT_HDR__
107 #define __CFG_COUT_INFO__ __CFG_COUT_TYPE__(TLVL_INFO) << __COUT_HDR__
108 #define __CFG_COUT__ __CFG_COUT_TYPE__(TLVL_DEBUG) << __COUT_HDR__
109 #define __CFG_COUTV__(X) __CFG_COUT__ << QUOTE(X) << " = " << X << __E__
110 
111 #define __CFG_MCOUT_ERR__(X) { __CFG_MOUT_ERR__ << X;} //causes duplicate with mf improvements: { __CFG_MOUT_ERR__ << X; __CFG_COUT_ERR__ << X; }
112 #define __CFG_MCOUT_WARN__(X) { __CFG_MOUT_WARN__ << X;} //causes duplicate with mf improvements: { __CFG_MOUT_WARN__ << X; __CFG_COUT_WARN__ << X; }
113 #define __CFG_MCOUT_INFO__(X) { __CFG_MOUT_INFO__ << X;} //causes duplicate with mf improvements: { __CFG_MOUT_INFO__ << X; __CFG_COUT_INFO__ << X; }
114 #define __CFG_MCOUT__(X) { __CFG_MOUT__ << X;} //causes duplicate with mf improvements: { __CFG_MOUT__ << X; __CFG_COUT__ << X; }
115 #define __CFG_MCOUTV__(X) { __CFG_MOUTV__(X);} //causes duplicate with mf improvements: { __CFG_MOUTV__(X); __CFG_COUTV__(X); }
116 
117 #define __CFG_SS__ std::stringstream ss; ss << ":" << __CFG_MF_DECOR__ << ":" << __COUT_HDR_FL__ << __COUT_HDR__
118 #define __CFG_SS_THROW__ { __CFG_COUT_ERR__ << "\n" << ss.str(); throw std::runtime_error(ss.str()); }
119 
121 
122 // for front-end interface objects, add name to subject
123 #define __FE_MF_DECOR__ ("FE:" + getInterfaceType() + std::string(":") + getInterfaceUID() + ":" + theConfigurationRecordName_ + "\t<> ")
124 #define __FE_MF_TYPE__(X) TLOG(X, __MF_SUBJECT__) << __FE_MF_DECOR__
125 
126 #ifndef __COUT_TO_STD__
127 #define __FE_COUT_TYPE__(X) __FE_MF_TYPE__(X)
128 #else
129 #define __FE_COUT_TYPE__(X) std::cout << QUOTE(X) << ":" << __FE_MF_DECOR__ << ":" << __COUT_HDR_FL__ << __COUT_HDR__
130 #endif
131 
132 #define __FE_MOUT_ERR__ __FE_MF_TYPE__(TLVL_ERROR) << __COUT_HDR__
133 #define __FE_MOUT_WARN__ __FE_MF_TYPE__(TLVL_WARNING) << __COUT_HDR__
134 #define __FE_MOUT_INFO__ __FE_MF_TYPE__(TLVL_INFO) << __COUT_HDR__
135 #define __FE_MOUT__ __FE_MF_TYPE__(TLVL_DEBUG) << __COUT_HDR__
136 #define __FE_MOUTV__(X) __FE_MOUT__ << QUOTE(X) << " = " << X
137 #define __FE_COUT_ERR__ __FE_COUT_TYPE__(TLVL_ERROR) << __COUT_HDR__
138 #define __FE_COUT_WARN__ __FE_COUT_TYPE__(TLVL_WARNING) << __COUT_HDR__
139 #define __FE_COUT_INFO__ __FE_COUT_TYPE__(TLVL_INFO) << __COUT_HDR__
140 #define __FE_COUT__ __FE_COUT_TYPE__(TLVL_DEBUG) << __COUT_HDR__
141 #define __FE_COUTV__(X) __FE_COUT__ << QUOTE(X) << " = " << X << __E__
142 
143 #define __FE_MCOUT_ERR__(X) { __FE_MOUT_ERR__ << X;} //causes duplicate with mf improvements: { __FE_MOUT_ERR__ << X; __FE_COUT_ERR__ << X; }
144 #define __FE_MCOUT_WARN__(X) { __FE_MOUT_WARN__ << X;} //causes duplicate with mf improvements: { __FE_MOUT_WARN__ << X; __FE_COUT_WARN__ << X; }
145 #define __FE_MCOUT_INFO__(X) { __FE_MOUT_INFO__ << X;} //causes duplicate with mf improvements: { __FE_MOUT_INFO__ << X; __FE_COUT_INFO__ << X; }
146 #define __FE_MCOUT__(X) { __FE_MOUT__ << X;} //causes duplicate with mf improvements: { __FE_MOUT__ << X; __FE_COUT__ << X; }
147 #define __FE_MCOUTV__(X) { __FE_MOUTV__(X);} //causes duplicate with mf improvements: { __FE_MOUTV__(X); __FE_COUTV__(X); }
148 
149 #define __FE_SS__ std::stringstream ss; ss << ":" << __FE_MF_DECOR__ << ":" << __COUT_HDR_FL__ << __COUT_HDR__
150 #define __FE_SS_THROW__ { __FE_COUT_ERR__ << "\n" << ss.str(); throw std::runtime_error(ss.str()); }
151 
153 
154 // for generic decoration override, just have mfSubject declared
155 #define __GEN_MF_DECOR__ (mfSubject_ + "\t<> ")
156 #define __GEN_MF_TYPE__(X) TLOG(X, __MF_SUBJECT__) << __GEN_MF_DECOR__
157 
158 #ifndef __COUT_TO_STD__
159 #define __GEN_COUT_TYPE__(X) __GEN_MF_TYPE__(X)
160 #else
161 #define __GEN_COUT_TYPE__(X) std::cout << QUOTE(X) << ":" << __GEN_MF_DECOR__ << ":" << __COUT_HDR_FL__ << __COUT_HDR__
162 #endif
163 
164 #define __GEN_MOUT_ERR__ __GEN_MF_TYPE__(TLVL_ERROR) << __COUT_HDR__
165 #define __GEN_MOUT_WARN__ __GEN_MF_TYPE__(TLVL_WARNING) << __COUT_HDR__
166 #define __GEN_MOUT_INFO__ __GEN_MF_TYPE__(TLVL_INFO) << __COUT_HDR__
167 #define __GEN_MOUT__ __GEN_MF_TYPE__(TLVL_DEBUG) << __COUT_HDR__
168 #define __GEN_MOUTV__(X) __GEN_MOUT__ << QUOTE(X) << " = " << X
169 #define __GEN_COUT_ERR__ __GEN_COUT_TYPE__(TLVL_ERROR) << __COUT_HDR__
170 #define __GEN_COUT_WARN__ __GEN_COUT_TYPE__(TLVL_WARNING) << __COUT_HDR__
171 #define __GEN_COUT_INFO__ __GEN_COUT_TYPE__(TLVL_INFO) << __COUT_HDR__
172 #define __GEN_COUT__ __GEN_COUT_TYPE__(TLVL_DEBUG) << __COUT_HDR__
173 #define __GEN_COUTV__(X) __GEN_COUT__ << QUOTE(X) << " = " << X << __E__
174 
175 #define __GEN_MCOUT_ERR__(X) { __GEN_MOUT_ERR__ << X;} //causes duplicate with mf improvements: { __GEN_MOUT_ERR__ << X; __GEN_COUT_ERR__ << X; }
176 #define __GEN_MCOUT_WARN__(X) { __GEN_MOUT_WARN__ << X;} //causes duplicate with mf improvements: { __GEN_MOUT_WARN__ << X; __GEN_COUT_WARN__ << X; }
177 #define __GEN_MCOUT_INFO__(X) { __GEN_MOUT_INFO__ << X;} //causes duplicate with mf improvements: { __GEN_MOUT_INFO__ << X; __GEN_COUT_INFO__ << X; }
178 #define __GEN_MCOUT__(X) { __GEN_MOUT__ << X;} //causes duplicate with mf improvements: { __GEN_MOUT__ << X; __GEN_COUT__ << X; }
179 #define __GEN_MCOUTV__(X) { __GEN_MOUTV__(X);} //causes duplicate with mf improvements: { __GEN_MOUTV__(X); __GEN_COUTV__(X); }
180 
181 #define __GEN_SS__ std::stringstream ss; ss << ":" << __GEN_MF_DECOR__ << ":" << __COUT_HDR_FL__ << __COUT_HDR__
182 #define __GEN_SS_THROW__ { __GEN_COUT_ERR__ << "\n" << ss.str(); throw std::runtime_error(ss.str()); }
183 
185 
186 // for core supervisor objects (with supervisorClassNoNamespace_ defined), add class to
187 // subject
188 #define __SUP_MF_DECOR__ (supervisorClassNoNamespace_ + std::string(":") + CorePropertySupervisorBase::getSupervisorUID() + "\t<> ")
189 #define __SUP_MF_TYPE__(X) TLOG(X, __MF_SUBJECT__) << __SUP_MF_DECOR__ //mf::X(supervisorClassNoNamespace_ + "-" + CorePropertySupervisorBase::getSupervisorUID())
190 
191 #ifndef __COUT_TO_STD__
192 #define __SUP_COUT_TYPE__(X) __SUP_MF_TYPE__(X)
193 #else
194 #define __SUP_COUT_TYPE__(X) std::cout << QUOTE(X) << ":" << __SUP_MF_DECOR__ << ":" << __COUT_HDR_FL__ << __COUT_HDR__
195 #endif
196 
197 #define __SUP_MOUT_ERR__ __SUP_MF_TYPE__(TLVL_ERROR) << __COUT_HDR__
198 #define __SUP_MOUT_WARN__ __SUP_MF_TYPE__(TLVL_WARNING) << __COUT_HDR__
199 #define __SUP_MOUT_INFO__ __SUP_MF_TYPE__(TLVL_INFO) << __COUT_HDR__
200 #define __SUP_MOUT__ __SUP_MF_TYPE__(TLVL_DEBUG) << __COUT_HDR__
201 #define __SUP_MOUTV__(X) __SUP_MOUT__ << QUOTE(X) << " = " << X
202 
203 #define __SUP_COUT_ERR__ __SUP_COUT_TYPE__(TLVL_ERROR) << __COUT_HDR__
204 #define __SUP_COUT_WARN__ __SUP_COUT_TYPE__(TLVL_WARNING) << __COUT_HDR__
205 #define __SUP_COUT_INFO__ __SUP_COUT_TYPE__(TLVL_INFO) << __COUT_HDR__
206 #define __SUP_COUT__ __SUP_COUT_TYPE__(TLVL_DEBUG) << __COUT_HDR__
207 #define __SUP_COUTV__(X) __SUP_COUT__ << QUOTE(X) << " = " << X << __E__
208 
209 #define __SUP_MCOUT_ERR__(X) { __SUP_MOUT_ERR__ << X;} //causes duplicate with mf improvements: { __SUP_MOUT_ERR__ << X; __SUP_COUT_ERR__ << X; }
210 #define __SUP_MCOUT_WARN__(X) { __SUP_MOUT_WARN__ << X;} //causes duplicate with mf improvements: { __SUP_MOUT_WARN__ << X; __SUP_COUT_WARN__ << X; }
211 #define __SUP_MCOUT_INFO__(X) { __SUP_MOUT_INFO__ << X;} //causes duplicate with mf improvements: { __SUP_MOUT_INFO__ << X; __SUP_COUT_INFO__ << X; }
212 #define __SUP_MCOUT__(X) { __SUP_MOUT__ << X;} //causes duplicate with mf improvements: { __SUP_MOUT__ << X; __SUP_COUT__ << X; }
213 #define __SUP_MCOUTV__(X) { __SUP_MOUTV__(X);} //causes duplicate with mf improvements: { __SUP_MOUTV__(X); __SUP_COUTV__(X); }
214 
215 #define __SUP_SS__ std::stringstream ss; ss << ":" << __SUP_MF_DECOR__ << ":" << __COUT_HDR_FL__ << __COUT_HDR__
216 #define __SUP_SS_THROW__ { __SUP_COUT_ERR__ << "\n" << ss.str(); throw std::runtime_error(ss.str()); }
217 
218 #define __ENV__(X) StringMacros::otsGetEnvironmentVarable(X, std::string(__SHORTFILE__), __LINE__)
219 
220 //========================================================================================================================
221 // const_cast away the const
222 // so that otsdaq is compatible with slf6 and slf7 versions of xdaq
223 // where they changed to const xdaq::ApplicationDescriptor* in slf7
224 #ifdef XDAQ_NOCONST
225 #define XDAQ_CONST_CALL
226 #else
227 #define XDAQ_CONST_CALL const
228 #endif
229 //========================================================================================================================
230 
231 //========================================================================================================================
232 // declare special ots soft exception
233 // a SOFT exception thrown during running workloop by a state machine plugin will
234 // PAUSE the global state machine and allow for manual intervention to resume a run.
235 namespace ots
236 {
237 struct __OTS_SOFT_EXCEPTION__ : public std::exception
238 {
239  __OTS_SOFT_EXCEPTION__(const std::string& what) : what_(what) {}
240  virtual char const* what() const throw() { return what_.c_str(); }
241  std::string what_;
242 };
243 } // end namespace ots
244 
245 #endif
246 
247 // clang-format on