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