File indexing completed on 2025-01-18 10:06:26
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef Pythia8_Logger_H
0009 #define Pythia8_Logger_H
0010
0011 #include "Pythia8/PythiaStdlib.h"
0012
0013 namespace Pythia8 {
0014
0015 class Settings;
0016
0017
0018
0019
0020
0021
0022
0023 class Logger : private streambuf, public ostream {
0024
0025
0026
0027
0028 struct LogComparer {
0029 bool operator() (const string& a, const string& b) const {
0030 char a1 = a[0], b1 = b[0];
0031 int severityA, severityB;
0032 if (a1 == 'A') severityA = 0;
0033 else if (a1 == 'E') severityA = 1;
0034 else if (a1 == 'W') severityA = 2;
0035 else if (a1 == 'I') severityA = 3;
0036 else if (a1 == 'R') severityA = 4;
0037 else severityA = 5;
0038 if (b1 == 'A') severityB = 0;
0039 else if (b1 == 'E') severityB = 1;
0040 else if (b1 == 'W') severityB = 2;
0041 else if (b1 == 'I') severityB = 3;
0042 else if (b1 == 'R') severityB = 4;
0043 else severityB = 5;
0044 if (severityA != severityB) return severityA < severityB;
0045 return a < b;
0046 }
0047 };
0048
0049 public:
0050
0051
0052 Logger() : ostream(this), infoStreamSave(cout), errStreamSave(cerr),
0053 verbosity(2), printInitSave(true), printNextSave(true), printErrors(true),
0054 isQuietSave(false), useErrorStream(false) { }
0055 virtual ~Logger() {}
0056
0057 void init(Settings& settings);
0058
0059
0060
0061
0062
0063 void reportMsg(string loc, string message, string extraInfo = "",
0064 bool showAlways = false);
0065
0066
0067 void infoMsg(string loc, string message, string extraInfo = "",
0068 bool showAlways = false);
0069
0070
0071 void warningMsg(string loc, string message, string extraInfo = "",
0072 bool showAlways = false);
0073
0074
0075 void errorMsg(string loc, string message, string extraInfo = "",
0076 bool showAlways = false);
0077
0078
0079 void abortMsg(string loc, string message, string extraInfo = "",
0080 bool showAlways = false);
0081
0082
0083 bool isQuiet() const { return isQuietSave; }
0084
0085
0086 bool mayPrintInit() const { return printInitSave && !isQuietSave; }
0087
0088
0089 bool mayPrintNext() const { return printNextSave && !isQuietSave; }
0090
0091
0092 bool mayPrintErrors() const { return printErrors && !isQuietSave; }
0093
0094
0095 void setVerbosity(int verbosityIn) { verbosity = verbosityIn; }
0096 int getVerbosity() const { return verbosity; }
0097
0098
0099 void errorCombine(const Logger& other, string prefix = "");
0100
0101
0102 void errorReset() {messages.clear();}
0103
0104
0105 int errorTotalNumber() const {
0106 int nTot = 0;
0107 for (pair<string, int> messageEntry : messages)
0108 nTot += messageEntry.second;
0109 return nTot;
0110 }
0111
0112
0113 void errorStatistics() const { errorStatistics(infoStreamSave); }
0114 void errorStatistics(ostream& stream) const;
0115
0116 ostream& infoStream() { return infoStreamSave; }
0117 ostream& errorStream() {
0118 return useErrorStream ? errStreamSave : infoStreamSave; }
0119
0120
0121 map<string, int, LogComparer>::iterator begin() {
0122 return messages.begin(); }
0123 map<string, int, LogComparer>::iterator end() {
0124 return messages.end(); }
0125 map<string, int, LogComparer>::const_iterator begin() const {
0126 return messages.begin(); }
0127 map<string, int, LogComparer>::const_iterator end() const {
0128 return messages.end(); }
0129
0130
0131 static constexpr int ABORT = 1;
0132
0133 static constexpr int NORMAL = 2;
0134
0135 static constexpr int REPORT = 3;
0136
0137 private:
0138
0139
0140 map<string, int, LogComparer> messages;
0141
0142
0143
0144 int overflow(int c) override {
0145 infoStreamSave.put(c);
0146 return 0;
0147 }
0148
0149
0150 ostream& infoStreamSave;
0151
0152 ostream& errStreamSave;
0153
0154
0155 int verbosity;
0156 bool printInitSave, printNextSave, printErrors, isQuietSave, useErrorStream;
0157
0158
0159 mutex writeMutex;
0160
0161
0162 void msg(int verbosityLevel, string message, string extraInfo = "",
0163 bool showAlways = false);
0164
0165 };
0166
0167
0168
0169
0170
0171 #define INFO_MSG(...) infoMsg(__METHOD_NAME__, __VA_ARGS__)
0172 #define WARNING_MSG(...) warningMsg(__METHOD_NAME__, __VA_ARGS__)
0173 #define ERROR_MSG(...) errorMsg(__METHOD_NAME__, __VA_ARGS__)
0174 #define ABORT_MSG(...) abortMsg(__METHOD_NAME__, __VA_ARGS__)
0175 #define REPORT_MSG(...) reportMsg(__METHOD_NAME__, __VA_ARGS__)
0176
0177
0178
0179 }
0180
0181 #endif