File indexing completed on 2025-01-30 10:22:13
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef ROOT_Minuit2_MnPrint
0011 #define ROOT_Minuit2_MnPrint
0012
0013 #include "Minuit2/MnConfig.h"
0014
0015 #include <sstream>
0016 #include <utility>
0017 #include <cassert>
0018 #include <string>
0019 #include <ios>
0020
0021 namespace ROOT {
0022 namespace Minuit2 {
0023
0024
0025
0026
0027
0028 class FunctionMinimum;
0029 std::ostream &operator<<(std::ostream &, const FunctionMinimum &);
0030
0031 class MinimumState;
0032 std::ostream &operator<<(std::ostream &, const MinimumState &);
0033
0034 class LAVector;
0035 std::ostream &operator<<(std::ostream &, const LAVector &);
0036
0037 class LASymMatrix;
0038 std::ostream &operator<<(std::ostream &, const LASymMatrix &);
0039
0040 class MnUserParameters;
0041 std::ostream &operator<<(std::ostream &, const MnUserParameters &);
0042
0043 class MnUserCovariance;
0044 std::ostream &operator<<(std::ostream &, const MnUserCovariance &);
0045
0046 class MnGlobalCorrelationCoeff;
0047 std::ostream &operator<<(std::ostream &, const MnGlobalCorrelationCoeff &);
0048
0049 class MnUserParameterState;
0050 std::ostream &operator<<(std::ostream &, const MnUserParameterState &);
0051
0052 class MnMachinePrecision;
0053 std::ostream &operator<<(std::ostream &, const MnMachinePrecision &);
0054
0055 class MinosError;
0056 std::ostream &operator<<(std::ostream &, const MinosError &);
0057
0058 class ContoursError;
0059 std::ostream &operator<<(std::ostream &, const ContoursError &);
0060
0061
0062 std::ostream &operator<<(std::ostream &os, const std::pair<double, double> &point);
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073 class MnPrint {
0074 public:
0075
0076 enum class Verbosity { Error = 0, Warn = 1, Info = 2, Debug = 3, Trace = 4 };
0077
0078
0079 static constexpr auto eError = Verbosity::Error;
0080 static constexpr auto eWarn = Verbosity::Warn;
0081 static constexpr auto eInfo = Verbosity::Info;
0082 static constexpr auto eDebug = Verbosity::Debug;
0083 static constexpr auto eTrace = Verbosity::Trace;
0084
0085
0086 class Oneline {
0087 public:
0088 Oneline(double fcn, double edm, int ncalls, int iter = -1);
0089 Oneline(const MinimumState &state, int iter = -1);
0090 Oneline(const FunctionMinimum &fmin, int iter = -1);
0091
0092 private:
0093 double fFcn, fEdm;
0094 int fNcalls, fIter;
0095
0096 friend std::ostream &operator<<(std::ostream &os, const Oneline &x);
0097 };
0098
0099 MnPrint(const char *prefix, int level = MnPrint::GlobalLevel());
0100 ~MnPrint();
0101
0102
0103 static int SetGlobalLevel(int level);
0104
0105
0106 static int GlobalLevel();
0107
0108
0109 static void ShowPrefixStack(bool yes);
0110
0111 static void AddFilter(const char *prefix);
0112 static void ClearFilter();
0113
0114
0115
0116
0117 static int SetMaxNP(int value);
0118
0119
0120 static int MaxNP();
0121
0122
0123 int SetLevel(int level);
0124
0125
0126 int Level() const;
0127
0128 template <class... Ts>
0129 void Error(const Ts &... args)
0130 {
0131 Log(eError, args...);
0132 }
0133
0134 template <class... Ts>
0135 void Warn(const Ts &... args)
0136 {
0137 Log(eWarn, args...);
0138 }
0139
0140 template <class... Ts>
0141 void Info(const Ts &... args)
0142 {
0143 Log(eInfo, args...);
0144 }
0145
0146 template <class... Ts>
0147 void Debug(const Ts &... args)
0148 {
0149 Log(eDebug, args...);
0150 }
0151
0152 template <class... Ts>
0153 void Trace(const Ts &... args)
0154 {
0155 Log(eTrace, args...);
0156 }
0157
0158 private:
0159
0160 template <class... Ts>
0161 void Log(Verbosity level, const Ts &... args)
0162 {
0163 if (Level() < static_cast<int>(level))
0164 return;
0165 if (Hidden())
0166 return;
0167
0168 std::ostringstream os;
0169 StreamPrefix(os);
0170 StreamArgs(os, args...);
0171 Impl(level, os.str());
0172 }
0173
0174 static void StreamPrefix(std::ostringstream &os);
0175
0176
0177 static bool Hidden();
0178
0179
0180 static void Impl(Verbosity level, const std::string &s);
0181
0182
0183 template <class T>
0184 static auto HandleLambda(std::ostream &os, const T &t, int) -> decltype(t(os), void())
0185 {
0186 t(os);
0187 }
0188
0189 template <class T>
0190 static void HandleLambda(std::ostream &os, const T &t, float)
0191 {
0192 os << t;
0193 }
0194
0195 static void StreamArgs(std::ostringstream &) {}
0196
0197
0198 template <class T>
0199 static void StreamArgs(std::ostringstream &os, const T &t)
0200 {
0201 os << " ";
0202 HandleLambda(os, t, 0);
0203 }
0204
0205 template <class T, class... Ts>
0206 static void StreamArgs(std::ostringstream &os, const T &t, const Ts &... ts)
0207 {
0208 os << " " << t;
0209 StreamArgs(os, ts...);
0210 }
0211
0212 int fLevel;
0213 };
0214
0215 }
0216 }
0217
0218 #endif