AmpGen 2.1
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
21namespace 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 {
27 size_t pos2=0;
28 do {
29 pos2 = thing.find( "AmpGen::" );
30 if ( pos2 != std::string::npos ) thing = thing.replace( pos2, 8, "" );
31 } while( pos2 != std::string::npos );
32
33 pos2 = thing.find( "std::" );
34 if ( pos2 != std::string::npos ) thing.replace( pos2, 5, "" );
35
36 pos2 = thing.find( "virtual " );
37 if ( pos2 != std::string::npos ) thing = thing.replace( pos2, 8, "" );
38
39 size_t pos = thing.find( "(" );
40
41 if ( pos != std::string::npos ) {
42 return pos < length ? thing.substr( 0, pos ) : thing.substr( 0, length );
43 }
44 return thing.size() < length ? thing : thing.substr( 0, length ) + "...";
45 }
46 inline std::ostream& labelled_stream(const std::string& function_name)
47 {
48 return std::cout << "\033[2;34m" << std::left << std::setw(FCNNAMELENGTH) << trimmedString(function_name) << " INFO " << "\033[0m";
49 }
50 template <typename T> struct debug_type : std::false_type {};
51 }
52}
53
54#define ENABLE_DEBUG(X) \
55 namespace AmpGen { namespace detail { template <> struct debug_type <X> : std::true_type {}; } }
56
59
60#ifdef DEBUGLEVEL
61#define DEBUG( X ) { \
62 std::cout << "\033[2;32m" << std::left << std::setw( AmpGen::detail::FCNNAMELENGTH ) << AmpGen::detail::trimmedString(__PRETTY_FUNCTION__) \
63 << " DEBUG " \
64 << "\033[0m" << X << " " << std::endl; }
65#else
66#define DEBUG( X ) { \
67 if constexpr( AmpGen::detail::debug_type<typename std::decay<decltype(*this)>::type>::value ) { \
68 std::cout << "\033[2;32m" << std::left << std::setw( AmpGen::detail::FCNNAMELENGTH ) << AmpGen::detail::trimmedString(__PRETTY_FUNCTION__) \
69 << " DEBUG " \
70 << "\033[0m" << X << " " << std::endl; } }
71#endif
72
75#define INFO( X ) \
76 AmpGen::detail::labelled_stream(__PRETTY_FUNCTION__) << X << std::endl
77
80#define ERROR( X ) \
81 std::cout << "\033[1;31m" << std::left << std::setw( AmpGen::detail::FCNNAMELENGTH ) << AmpGen::detail::trimmedString( __PRETTY_FUNCTION__ ) \
82 << " ERROR " \
83 << "\033[0m" << X << std::endl
84
87#define FATAL( X ) \
88{ std::cout << "\033[1;31m" << std::left << std::setw( AmpGen::detail::FCNNAMELENGTH ) << AmpGen::detail::trimmedString( __PRETTY_FUNCTION__ ) \
89 << " FATAL " \
90 << "\033[0m" << X << std::endl; \
91 throw std::runtime_error( AmpGen::detail::trimmedString( __PRETTY_FUNCTION__)+ " FATAL" ) ;}
92
93
96#ifdef WARNINGLEVEL
97#define WARNING( X ) \
98 std::cout << "\033[1;35m" << std::left << std::setw( AmpGen::detail::FCNNAMELENGTH ) << AmpGen::detail::trimmedString( __PRETTY_FUNCTION__ ) \
99 << " WARNING " \
100 << "\033[0m" << X << std::endl
101#else
102#define WARNING( X )
103#endif
104
105#endif
std::string trimmedString(std::string thing, const unsigned int &length=FCNNAMELENGTH)
Definition MsgService.h:25
std::ostream & labelled_stream(const std::string &function_name)
Definition MsgService.h:46
static constexpr int FCNNAMELENGTH
Definition MsgService.h:23