otsdaq  3.09.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 __SYSTEM_ALERT_PREAMBLE__ "System Alert to '"
69 
70 #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'}); }}
71 #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'}); }}
72 
74 
75 #define __SS__ std::stringstream ss; ss << "|" << __MF_DECOR__ << ": " << __COUT_HDR_FL__ << __COUT_HDR__
76 #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__;
77 #define __SS_ONLY_THROW__ throw std::runtime_error(ss.str())
78 #define __SSV__(X) __SS__ << QUOTE(X) << " = " << X
79 
82 #define __CFG_MF_DECOR__ (theConfigurationRecordName_ + "\t<> ")
83 #define __CFG_MF_TYPE__(X) TLOG(X, __MF_SUBJECT__) << __CFG_MF_DECOR__
84 
85 #ifndef __COUT_TO_STD__
86 #define __CFG_COUT_TYPE__(X) __CFG_MF_TYPE__(X)
87 #else
88 #define __CFG_COUT_TYPE__(X) std::cout << QUOTE(X) << ":" << __CFG_MF_DECOR__ << ": " << __COUT_HDR_FL__ << __COUT_HDR__
89 #endif
90 
91 #define __CFG_COUT_ERR__ __CFG_COUT_TYPE__(TLVL_ERROR) << __COUT_HDR__
92 #define __CFG_COUT_WARN__ __CFG_COUT_TYPE__(TLVL_WARNING) << __COUT_HDR__
93 #define __CFG_COUT_INFO__ __CFG_COUT_TYPE__(TLVL_INFO) << __COUT_HDR__
94 #define __CFG_COUT__ __CFG_COUT_TYPE__(TLVL_DEBUG) << __COUT_HDR__
95 #define __CFG_COUTS__(LVL) __CFG_COUT_TYPE__(TLVL_DEBUG + LVL) << __COUT_HDR__
96 #define __CFG_COUTT__ __CFG_COUT_TYPE__(TLVL_TRACE) << __COUT_HDR__
97 #define __CFG_COUTV__(X) __CFG_COUT__ << QUOTE(X) << " = " << (X) << __E__
98 #define __CFG_COUTTV__(X) __CFG_COUTT__ << QUOTE(X) << " = " << (X) << __E__
99 #define __CFG_COUTVS__(LVL,X) __CFG_COUT_TYPE__(TLVL_DEBUG + LVL) << __COUT_HDR__ << QUOTE(X) << " = " << (X) << __E__
100 
101 #define __CFG_SS__ std::stringstream ss; ss << "|" << __CFG_MF_DECOR__ << ": " << __COUT_HDR_FL__ << __COUT_HDR__
102 #define __CFG_SS_THROW__ { __CFG_COUT_ERR__ << "\n" << ss.str(); throw std::runtime_error(ss.str()); }
103 
105 
107 #define __FE_MF_DECOR__ ("FE:" + getInterfaceType() + std::string(":") + getInterfaceUID() + ":" + theConfigurationRecordName_ + "\t<> ")
108 #define __FE_MF_TYPE__(X) TLOG(X, __MF_SUBJECT__) << __FE_MF_DECOR__
109 
110 #ifndef __COUT_TO_STD__
111 #define __FE_COUT_TYPE__(X) __FE_MF_TYPE__(X)
112 #else
113 #define __FE_COUT_TYPE__(X) std::cout << QUOTE(X) << ":" << __FE_MF_DECOR__ << ": " << __COUT_HDR_FL__ << __COUT_HDR__
114 #endif
115 
116 #define __FE_COUT_ERR__ __FE_COUT_TYPE__(TLVL_ERROR) << __COUT_HDR__
117 #define __FE_COUT_WARN__ __FE_COUT_TYPE__(TLVL_WARNING) << __COUT_HDR__
118 #define __FE_COUT_INFO__ __FE_COUT_TYPE__(TLVL_INFO) << __COUT_HDR__
119 #define __FE_COUT__ __FE_COUT_TYPE__(TLVL_DEBUG) << __COUT_HDR__
120 #define __FE_COUTS__(LVL) __FE_COUT_TYPE__(TLVL_DEBUG + LVL) << __COUT_HDR__
121 #define __FE_COUTT__ __FE_COUT_TYPE__(TLVL_TRACE) << __COUT_HDR__
122 #define __FE_COUTV__(X) __FE_COUT__ << QUOTE(X) << " = " << (X) << __E__
123 #define __FE_COUTTV__(X) __FE_COUTT__ << QUOTE(X) << " = " << (X) << __E__
124 #define __FE_COUTVS__(LVL,X) __FE_COUT_TYPE__(TLVL_DEBUG + LVL) << __COUT_HDR__ << QUOTE(X) << " = " << (X) << __E__
125 
126 #define __FE_SS__ std::stringstream ss; ss << "|" << __FE_MF_DECOR__ << ": " << __COUT_HDR_FL__ << __COUT_HDR__
127 #define __FE_SS_THROW__ { __FE_COUT_ERR__ << "\n" << ss.str(); throw std::runtime_error(ss.str()); }
128 
130 
132 #define __GEN_MF_DECOR__ (mfSubject_ + "\t<> ")
133 #define __GEN_MF_TYPE__(X) TLOG(X, __MF_SUBJECT__) << __GEN_MF_DECOR__
134 
135 #ifndef __COUT_TO_STD__
136 #define __GEN_COUT_TYPE__(X) __GEN_MF_TYPE__(X)
137 #else
138 #define __GEN_COUT_TYPE__(X) std::cout << QUOTE(X) << ":" << __GEN_MF_DECOR__ << ": " << __COUT_HDR_FL__ << __COUT_HDR__
139 #endif
140 
141 #define __GEN_COUT_ERR__ __GEN_COUT_TYPE__(TLVL_ERROR) << __COUT_HDR__
142 #define __GEN_COUT_WARN__ __GEN_COUT_TYPE__(TLVL_WARNING) << __COUT_HDR__
143 #define __GEN_COUT_INFO__ __GEN_COUT_TYPE__(TLVL_INFO) << __COUT_HDR__
144 #define __GEN_COUT__ __GEN_COUT_TYPE__(TLVL_DEBUG) << __COUT_HDR__
145 #define __GEN_COUTS__(LVL) __GEN_COUT_TYPE__(TLVL_DEBUG + LVL) << __COUT_HDR__
146 #define __GEN_COUTT__ __GEN_COUT_TYPE__(TLVL_TRACE) << __COUT_HDR__
147 #define __GEN_COUTV__(X) __GEN_COUT__ << QUOTE(X) << " = " << (X) << __E__
148 #define __GEN_COUTTV__(X) __GEN_COUTT__ << QUOTE(X) << " = " << (X) << __E__
149 #define __GEN_COUTVS__(LVL,X) __GEN_COUT_TYPE__(TLVL_DEBUG + LVL) << __COUT_HDR__ << QUOTE(X) << " = " << (X) << __E__
150 
151 #define __GEN_SS__ std::stringstream ss; ss << "|" << __GEN_MF_DECOR__ << ": " << __COUT_HDR_FL__ << __COUT_HDR__
152 #define __GEN_SS_THROW__ { __GEN_COUT_ERR__ << "\n" << ss.str(); throw std::runtime_error(ss.str()); }
153 
155 
158 #define __SUP_MF_DECOR__ (supervisorClassNoNamespace_ + std::string(":") + CorePropertySupervisorBase::getSupervisorUID() + "\t<> ")
159 #define __SUP_MF_TYPE__(X) TLOG(X, __MF_SUBJECT__) << __SUP_MF_DECOR__ //mf::X(supervisorClassNoNamespace_ + "-" + CorePropertySupervisorBase::getSupervisorUID())
160 
161 #ifndef __COUT_TO_STD__
162 #define __SUP_COUT_TYPE__(X) __SUP_MF_TYPE__(X)
163 #else
164 #define __SUP_COUT_TYPE__(X) std::cout << QUOTE(X) << ":" << __SUP_MF_DECOR__ << ": " << __COUT_HDR_FL__ << __COUT_HDR__
165 #endif
166 
167 #define __SUP_COUT_ERR__ __SUP_COUT_TYPE__(TLVL_ERROR) << __COUT_HDR__
168 #define __SUP_COUT_WARN__ __SUP_COUT_TYPE__(TLVL_WARNING) << __COUT_HDR__
169 #define __SUP_COUT_INFO__ __SUP_COUT_TYPE__(TLVL_INFO) << __COUT_HDR__
170 #define __SUP_COUT__ __SUP_COUT_TYPE__(TLVL_DEBUG) << __COUT_HDR__
171 #define __SUP_COUTS__(LVL) __SUP_COUT_TYPE__(TLVL_DEBUG + LVL) << __COUT_HDR__
172 #define __SUP_COUTT__ __SUP_COUT_TYPE__(TLVL_TRACE) << __COUT_HDR__
173 #define __SUP_COUTV__(X) __SUP_COUT__ << QUOTE(X) << " = " << (X) << __E__
174 #define __SUP_COUTTV__(X) __SUP_COUTT__ << QUOTE(X) << " = " << (X) << __E__
175 #define __SUP_COUTVS__(LVL,X) __SUP_COUT_TYPE__(TLVL_DEBUG + LVL) << __COUT_HDR__ << QUOTE(X) << " = " << (X) << __E__
176 
177 #define __SUP_SS__ std::stringstream ss; ss << "|" << __SUP_MF_DECOR__ << ": " << __COUT_HDR_FL__ << __COUT_HDR__
178 #define __SUP_SS_THROW__ { __SUP_COUT_ERR__ << "\n" << ss.str(); throw std::runtime_error(ss.str()); }
179 
181 #define __ENV__(X) StringMacros::otsGetEnvironmentVarable(X, std::string(__SHORTFILE__), __LINE__)
182 
183 //========================================================================================================================
187 #ifdef XDAQ_NOCONST
188 #define XDAQ_CONST_CALL
189 #else
190 #define XDAQ_CONST_CALL const
191 #endif
192 //========================================================================================================================
193 
194 //========================================================================================================================
198 namespace ots
199 {
200 struct __OTS_PAUSE_EXCEPTION__ : public std::exception
201 {
202  __OTS_PAUSE_EXCEPTION__(const std::string& what) : what_(what) {}
203  virtual char const* what() const throw() { return what_.c_str(); }
204  std::string what_;
205 }; //end __OTS_PAUSE_EXCEPTION__ struct
206 } // end namespace ots
207 //========================================================================================================================
211 namespace ots
212 {
213 struct __OTS_STOP_EXCEPTION__ : public std::exception
214 {
215  __OTS_STOP_EXCEPTION__(const std::string& what) : what_(what) {}
216  virtual char const* what() const throw() { return what_.c_str(); }
217  std::string what_;
218 }; // end __OTS_STOP_EXCEPTION__ struct
219 } // end namespace ots
220 
221 //========================================================================================================================
225 namespace ots
226 {
228 {
229  std::string get(const time_t linuxTimeInSeconds = time(0))
230  {
231  std::string retValue(30, '\0'); // known fixed size: Thu Aug 23 14:55:02 2001 CST
232 
233  struct tm tmstruct;
234  ::localtime_r(&linuxTimeInSeconds, &tmstruct);
235  ::strftime(&retValue[0], 30, "%a %b %e %H:%M:%S %Y %Z", &tmstruct);
236  retValue.resize(strlen(retValue.c_str()));
237 
238  return retValue;
239  } //end get()
240 }; //end TimestampString struct
241 } // end namespace ots
242 
243 // clang-format on
244 
245 #endif
defines used also by OtsConfigurationWizardSupervisor