AmpGen
2.1
Toggle main menu visibility
Loading...
Searching...
No Matches
MsgService.h
Go to the documentation of this file.
1
#ifndef AMPGEN_MSGSERVICE_H
2
#define AMPGEN_MSGSERVICE_H
3
13
14
#include <iomanip>
15
#include <iostream>
16
#include <string>
17
#include <type_traits>
18
19
#define WARNINGLEVEL 1
20
21
namespace
AmpGen
{
22
namespace
detail {
23
constexpr
static
int
FCNNAMELENGTH
= 38;
24
25
inline
std::string
trimmedString
(std::string thing,
const
unsigned
int
&length =
FCNNAMELENGTH
) {
26
size_t
pos2 = 0;
27
do
{
28
pos2 = thing.find(
"AmpGen::"
);
29
if
(pos2 != std::string::npos) thing = thing.replace(pos2, 8,
""
);
30
}
while
(pos2 != std::string::npos);
31
32
pos2 = thing.find(
"std::"
);
33
if
(pos2 != std::string::npos) thing.replace(pos2, 5,
""
);
34
35
pos2 = thing.find(
"virtual "
);
36
if
(pos2 != std::string::npos) thing = thing.replace(pos2, 8,
""
);
37
38
size_t
pos = thing.find(
"("
);
39
40
if
(pos != std::string::npos) {
return
pos < length ? thing.substr(0, pos) : thing.substr(0, length); }
41
return
thing.size() < length ? thing : thing.substr(0, length) +
"..."
;
42
}
43
inline
std::ostream &
labelled_stream
(
const
std::string &function_name) {
44
return
std::cout <<
"\033[2;34m"
<< std::left << std::setw(
FCNNAMELENGTH
) <<
trimmedString
(function_name) <<
" INFO "
45
<<
"\033[0m"
;
46
}
47
template
<
typename
T>
struct
debug_type
: std::false_type {};
48
}
49
}
50
51
#define ENABLE_DEBUG(X) \
52
namespace AmpGen { \
53
namespace detail { \
54
template <> struct debug_type<X> : std::true_type {}; \
55
} \
56
}
57
60
61
#ifdef DEBUGLEVEL
62
#define DEBUG(X) \
63
{ \
64
std::cout << "\033[2;32m" << std::left << std::setw(AmpGen::detail::FCNNAMELENGTH) << AmpGen::detail::trimmedString(__PRETTY_FUNCTION__) \
65
<< " DEBUG " \
66
<< "\033[0m" << X << " " << std::endl; \
67
}
68
#else
69
#define DEBUG(X) \
70
{ \
71
if constexpr(AmpGen::detail::debug_type<typename std::decay<decltype(*this)>::type>::value) { \
72
std::cout << "\033[2;32m" << std::left << std::setw(AmpGen::detail::FCNNAMELENGTH) << AmpGen::detail::trimmedString(__PRETTY_FUNCTION__) \
73
<< " DEBUG " \
74
<< "\033[0m" << X << " " << std::endl; \
75
} \
76
}
77
#endif
78
81
#define INFO(X) AmpGen::detail::labelled_stream(__PRETTY_FUNCTION__) << X << std::endl
82
85
#define ERROR(X) \
86
std::cout << "\033[1;31m" << std::left << std::setw(AmpGen::detail::FCNNAMELENGTH) << AmpGen::detail::trimmedString(__PRETTY_FUNCTION__) \
87
<< " ERROR " \
88
<< "\033[0m" << X << std::endl
89
92
#define FATAL(X) \
93
{ \
94
std::cout << "\033[1;31m" << std::left << std::setw(AmpGen::detail::FCNNAMELENGTH) << AmpGen::detail::trimmedString(__PRETTY_FUNCTION__) \
95
<< " FATAL " \
96
<< "\033[0m" << X << std::endl; \
97
throw std::runtime_error(AmpGen::detail::trimmedString(__PRETTY_FUNCTION__) + " FATAL"); \
98
}
99
102
#ifdef WARNINGLEVEL
103
#define WARNING(X) \
104
std::cout << "\033[1;35m" << std::left << std::setw(AmpGen::detail::FCNNAMELENGTH) << AmpGen::detail::trimmedString(__PRETTY_FUNCTION__) \
105
<< " WARNING " \
106
<< "\033[0m" << X << std::endl
107
#else
108
#define WARNING(X)
109
#endif
110
111
#endif
AmpGen::detail::trimmedString
std::string trimmedString(std::string thing, const unsigned int &length=FCNNAMELENGTH)
Definition
MsgService.h:25
AmpGen::detail::labelled_stream
std::ostream & labelled_stream(const std::string &function_name)
Definition
MsgService.h:43
AmpGen::detail::FCNNAMELENGTH
static constexpr int FCNNAMELENGTH
Definition
MsgService.h:23
AmpGen
Definition
AddCPConjugate.h:2
AmpGen::detail::debug_type
Definition
MsgService.h:47
AmpGen
MsgService.h
Generated on
for AmpGen by
1.17.0