otsdaq  3.06.00
CoutMacros.h
1 #ifndef _ots_Cout_Macros_h_
2 #define _ots_Cout_Macros_h_
3 
4 // clang-format off
5 
6 #include <ctime> //for time_t, time(), localtime_r(), strftime()
7 #include <cstring> //for strlen()
8 #include <string.h> //for strstr (not the same as <string>)
9 #include <iostream> //for cout
10 #include <sstream> //for stringstream, std::stringbuf
11 
12 #define TRACEMF_USE_VERBATIM 1 //for trace longer path filenames
13 
14 // #define TSTREAMER_SL_FRC(lvl) (lvl<TLVL_DEBUG) //FIXME uncomment once trace supports #ifdef TSTREAMER_SL_FRC (as of 17-Feb-2026 not defined)
15 #include "TRACE/tracemf.h"
16 
17 
20 #define __SHORTFILE__ (__builtin_strstr(&__FILE__[0], "/srcs/") ? __builtin_strstr(&__FILE__[0], "/srcs/") + 6 : __FILE__)
21 
23 #define __FILENAME__ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
24 
25 #define __E__ std::endl
26 
27 #define __THROW__(X) throw std::runtime_error(X)
28 
32 #define __MF_SUBJECT__ __FILENAME__ // default subject.. others can #undef and re-#define
35 #define QQQQ(X) #X
36 #define QUOTE(X) QQQQ(X)
37 //#define __MF_TYPE__(X) FIXME ?? how to do this ...(__ENV__("OTSDAQ_USING_MF")=="1"?
40 #define __COUT_HDR_F__ __SHORTFILE__ << ""
41 #define __COUT_HDR_L__ ":" << std::dec << __LINE__ << " |\t"
42 #define __COUT_HDR_P__ __PRETTY_FUNCTION__ << "\t"
43 #define __COUT_HDR_FL__ __SHORTFILE__ << "" << __COUT_HDR_L__
44 #define __COUT_HDR_FP__ __SHORTFILE__ << ":" << __COUT_HDR_P__
45 #define __COUT_HDR__ ""//__COUT_HDR_FL__
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 
58 #define __COUT_ERR__ __COUT_TYPE__(TLVL_ERROR) << __COUT_HDR__
59 #define __COUT_WARN__ __COUT_TYPE__(TLVL_WARNING) << __COUT_HDR__
60 #define __COUT_INFO__ __COUT_TYPE__(TLVL_INFO) << __COUT_HDR__
61 #define __COUT__ __COUT_TYPE__(TLVL_DEBUG) << __COUT_HDR__
62 #define __COUTS__(LVL) __COUT_TYPE__(TLVL_DEBUG + LVL) << __COUT_HDR__
63 #define __COUTT__ __COUT_TYPE__(TLVL_TRACE) << __COUT_HDR__
64 #define __COUTV__(X) __COUT__ << QUOTE(X) << " = " << (X) << __E__
65 #define __COUTTV__(X) __COUTT__ << QUOTE(X) << " = " << (X) << __E__
66 #define __COUTVS__(LVL,X) __COUT_TYPE__(TLVL_DEBUG + LVL) << __COUT_HDR__ << QUOTE(X) << " = " << (X) << __E__
67 
68 #define __COUT_MULTI__(LVL,X) {if(TTEST(LVL)) { __COUTS__(LVL) << "Multi-line printout:" << __E__; auto splitArr = StringMacros::getVectorFromString(X, {'\n'}, {} /* whitespace */); for(const auto& split : splitArr) __COUTS__(LVL) << split; }}// StringMacros::coutSplit(X,LVL,{'\n'}); }}
69 #define __COUT_MULTI_LBL__(LVL,X,LABEL) {if(TTEST(LVL)) { __COUTS__(LVL) << "Multi-line " << LABEL << " printout:" << __E__; auto splitArr = StringMacros::getVectorFromString(X, {'\n'}, {} /* whitespace */); for(const auto& split : splitArr) __COUTS__(LVL) << split; }} //StringMacros::coutSplit(X,LVL,{'\n'}); }}
70 
72 
73 #define __SS__ std::stringstream ss; ss << "|" << __MF_DECOR__ << ": " << __COUT_HDR_FL__ << __COUT_HDR__
74 #define __SS_THROW__ { __COUT_ERR__ << "\n" << ss.str(); throw std::runtime_error("At time " + ots::TimestampString().get() + ": \n\n" + ss.str()); } //__SS_THROW__ is in {}'s to prevent surprises to user, e.g. if ... else __SS_THROW__;
75 #define __SS_ONLY_THROW__ throw std::runtime_error(ss.str())
76 #define __SSV__(X) __SS__ << QUOTE(X) << " = " << X
77 
80 #define __CFG_MF_DECOR__ (theConfigurationRecordName_ + "\t<> ")
81 #define __CFG_MF_TYPE__(X) TLOG(X, __MF_SUBJECT__) << __CFG_MF_DECOR__
82 
83 #ifndef __COUT_TO_STD__
84 #define __CFG_COUT_TYPE__(X) __CFG_MF_TYPE__(X)
85 #else
86 #define __CFG_COUT_TYPE__(X) std::cout << QUOTE(X) << ":" << __CFG_MF_DECOR__ << ": " << __COUT_HDR_FL__ << __COUT_HDR__
87 #endif
88 
89 #define __CFG_COUT_ERR__ __CFG_COUT_TYPE__(TLVL_ERROR) << __COUT_HDR__
90 #define __CFG_COUT_WARN__ __CFG_COUT_TYPE__(TLVL_WARNING) << __COUT_HDR__
91 #define __CFG_COUT_INFO__ __CFG_COUT_TYPE__(TLVL_INFO) << __COUT_HDR__
92 #define __CFG_COUT__ __CFG_COUT_TYPE__(TLVL_DEBUG) << __COUT_HDR__
93 #define __CFG_COUTS__(LVL) __CFG_COUT_TYPE__(TLVL_DEBUG + LVL) << __COUT_HDR__
94 #define __CFG_COUTT__ __CFG_COUT_TYPE__(TLVL_TRACE) << __COUT_HDR__
95 #define __CFG_COUTV__(X) __CFG_COUT__ << QUOTE(X) << " = " << (X) << __E__
96 #define __CFG_COUTTV__(X) __CFG_COUTT__ << QUOTE(X) << " = " << (X) << __E__
97 #define __CFG_COUTVS__(LVL,X) __CFG_COUT_TYPE__(TLVL_DEBUG + LVL) << __COUT_HDR__ << QUOTE(X) << " = " << (X) << __E__
98 
99 #define __CFG_SS__ std::stringstream ss; ss << "|" << __CFG_MF_DECOR__ << ": " << __COUT_HDR_FL__ << __COUT_HDR__
100 #define __CFG_SS_THROW__ { __CFG_COUT_ERR__ << "\n" << ss.str(); throw std::runtime_error(ss.str()); }
101 
103 
105 #define __FE_MF_DECOR__ ("FE:" + getInterfaceType() + std::string(":") + getInterfaceUID() + ":" + theConfigurationRecordName_ + "\t<> ")
106 #define __FE_MF_TYPE__(X) TLOG(X, __MF_SUBJECT__) << __FE_MF_DECOR__
107 
108 #ifndef __COUT_TO_STD__
109 #define __FE_COUT_TYPE__(X) __FE_MF_TYPE__(X)
110 #else
111 #define __FE_COUT_TYPE__(X) std::cout << QUOTE(X) << ":" << __FE_MF_DECOR__ << ": " << __COUT_HDR_FL__ << __COUT_HDR__
112 #endif
113 
114 #define __FE_COUT_ERR__ __FE_COUT_TYPE__(TLVL_ERROR) << __COUT_HDR__
115 #define __FE_COUT_WARN__ __FE_COUT_TYPE__(TLVL_WARNING) << __COUT_HDR__
116 #define __FE_COUT_INFO__ __FE_COUT_TYPE__(TLVL_INFO) << __COUT_HDR__
117 #define __FE_COUT__ __FE_COUT_TYPE__(TLVL_DEBUG) << __COUT_HDR__
118 #define __FE_COUTS__(LVL) __FE_COUT_TYPE__(TLVL_DEBUG + LVL) << __COUT_HDR__
119 #define __FE_COUTT__ __FE_COUT_TYPE__(TLVL_TRACE) << __COUT_HDR__
120 #define __FE_COUTV__(X) __FE_COUT__ << QUOTE(X) << " = " << (X) << __E__
121 #define __FE_COUTTV__(X) __FE_COUTT__ << QUOTE(X) << " = " << (X) << __E__
122 #define __FE_COUTVS__(LVL,X) __FE_COUT_TYPE__(TLVL_DEBUG + LVL) << __COUT_HDR__ << QUOTE(X) << " = " << (X) << __E__
123 
124 #define __FE_SS__ std::stringstream ss; ss << "|" << __FE_MF_DECOR__ << ": " << __COUT_HDR_FL__ << __COUT_HDR__
125 #define __FE_SS_THROW__ { __FE_COUT_ERR__ << "\n" << ss.str(); throw std::runtime_error(ss.str()); }
126 
128 
130 #define __GEN_MF_DECOR__ (mfSubject_ + "\t<> ")
131 #define __GEN_MF_TYPE__(X) TLOG(X, __MF_SUBJECT__) << __GEN_MF_DECOR__
132 
133 #ifndef __COUT_TO_STD__
134 #define __GEN_COUT_TYPE__(X) __GEN_MF_TYPE__(X)
135 #else
136 #define __GEN_COUT_TYPE__(X) std::cout << QUOTE(X) << ":" << __GEN_MF_DECOR__ << ": " << __COUT_HDR_FL__ << __COUT_HDR__
137 #endif
138 
139 #define __GEN_COUT_ERR__ __GEN_COUT_TYPE__(TLVL_ERROR) << __COUT_HDR__
140 #define __GEN_COUT_WARN__ __GEN_COUT_TYPE__(TLVL_WARNING) << __COUT_HDR__
141 #define __GEN_COUT_INFO__ __GEN_COUT_TYPE__(TLVL_INFO) << __COUT_HDR__
142 #define __GEN_COUT__ __GEN_COUT_TYPE__(TLVL_DEBUG) << __COUT_HDR__
143 #define __GEN_COUTS__(LVL) __GEN_COUT_TYPE__(TLVL_DEBUG + LVL) << __COUT_HDR__
144 #define __GEN_COUTT__ __GEN_COUT_TYPE__(TLVL_TRACE) << __COUT_HDR__
145 #define __GEN_COUTV__(X) __GEN_COUT__ << QUOTE(X) << " = " << (X) << __E__
146 #define __GEN_COUTTV__(X) __GEN_COUTT__ << QUOTE(X) << " = " << (X) << __E__
147 #define __GEN_COUTVS__(LVL,X) __GEN_COUT_TYPE__(TLVL_DEBUG + LVL) << __COUT_HDR__ << QUOTE(X) << " = " << (X) << __E__
148 
149 #define __GEN_SS__ std::stringstream ss; ss << "|" << __GEN_MF_DECOR__ << ": " << __COUT_HDR_FL__ << __COUT_HDR__
150 #define __GEN_SS_THROW__ { __GEN_COUT_ERR__ << "\n" << ss.str(); throw std::runtime_error(ss.str()); }
151 
153 
156 #define __SUP_MF_DECOR__ (supervisorClassNoNamespace_ + std::string(":") + CorePropertySupervisorBase::getSupervisorUID() + "\t<> ")
157 #define __SUP_MF_TYPE__(X) TLOG(X, __MF_SUBJECT__) << __SUP_MF_DECOR__ //mf::X(supervisorClassNoNamespace_ + "-" + CorePropertySupervisorBase::getSupervisorUID())
158 
159 #ifndef __COUT_TO_STD__
160 #define __SUP_COUT_TYPE__(X) __SUP_MF_TYPE__(X)
161 #else
162 #define __SUP_COUT_TYPE__(X) std::cout << QUOTE(X) << ":" << __SUP_MF_DECOR__ << ": " << __COUT_HDR_FL__ << __COUT_HDR__
163 #endif
164 
165 #define __SUP_COUT_ERR__ __SUP_COUT_TYPE__(TLVL_ERROR) << __COUT_HDR__
166 #define __SUP_COUT_WARN__ __SUP_COUT_TYPE__(TLVL_WARNING) << __COUT_HDR__
167 #define __SUP_COUT_INFO__ __SUP_COUT_TYPE__(TLVL_INFO) << __COUT_HDR__
168 #define __SUP_COUT__ __SUP_COUT_TYPE__(TLVL_DEBUG) << __COUT_HDR__
169 #define __SUP_COUTS__(LVL) __SUP_COUT_TYPE__(TLVL_DEBUG + LVL) << __COUT_HDR__
170 #define __SUP_COUTT__ __SUP_COUT_TYPE__(TLVL_TRACE) << __COUT_HDR__
171 #define __SUP_COUTV__(X) __SUP_COUT__ << QUOTE(X) << " = " << (X) << __E__
172 #define __SUP_COUTTV__(X) __SUP_COUTT__ << QUOTE(X) << " = " << (X) << __E__
173 #define __SUP_COUTVS__(LVL,X) __SUP_COUT_TYPE__(TLVL_DEBUG + LVL) << __COUT_HDR__ << QUOTE(X) << " = " << (X) << __E__
174 
175 #define __SUP_SS__ std::stringstream ss; ss << "|" << __SUP_MF_DECOR__ << ": " << __COUT_HDR_FL__ << __COUT_HDR__
176 #define __SUP_SS_THROW__ { __SUP_COUT_ERR__ << "\n" << ss.str(); throw std::runtime_error(ss.str()); }
177 
179 #define __ENV__(X) StringMacros::otsGetEnvironmentVarable(X, std::string(__SHORTFILE__), __LINE__)
180 
181 //========================================================================================================================
185 #ifdef XDAQ_NOCONST
186 #define XDAQ_CONST_CALL
187 #else
188 #define XDAQ_CONST_CALL const
189 #endif
190 //========================================================================================================================
191 
192 //========================================================================================================================
196 namespace ots
197 {
198 struct __OTS_PAUSE_EXCEPTION__ : public std::exception
199 {
200  __OTS_PAUSE_EXCEPTION__(const std::string& what) : what_(what) {}
201  virtual char const* what() const throw() { return what_.c_str(); }
202  std::string what_;
203 }; //end __OTS_PAUSE_EXCEPTION__ struct
204 } // end namespace ots
205 //========================================================================================================================
209 namespace ots
210 {
211 struct __OTS_STOP_EXCEPTION__ : public std::exception
212 {
213  __OTS_STOP_EXCEPTION__(const std::string& what) : what_(what) {}
214  virtual char const* what() const throw() { return what_.c_str(); }
215  std::string what_;
216 }; // end __OTS_STOP_EXCEPTION__ struct
217 } // end namespace ots
218 
219 //========================================================================================================================
223 namespace ots
224 {
226 {
227  std::string get(const time_t linuxTimeInSeconds = time(0))
228  {
229  std::string retValue(30, '\0'); // known fixed size: Thu Aug 23 14:55:02 2001 CST
230 
231  struct tm tmstruct;
232  ::localtime_r(&linuxTimeInSeconds, &tmstruct);
233  ::strftime(&retValue[0], 30, "%a %b %e %H:%M:%S %Y %Z", &tmstruct);
234  retValue.resize(strlen(retValue.c_str()));
235 
236  return retValue;
237  } //end get()
238 }; //end TimestampString struct
239 } // end namespace ots
240 
241 // clang-format on
242 
243 #endif
defines used also by OtsConfigurationWizardSupervisor