Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
MnPrint.h
Go to the documentation of this file.
1// @(#)root/minuit2:$Id$
2// Authors: M. Winkler, F. James, L. Moneta, A. Zsenei 2003-2005
3
4/**********************************************************************
5 * *
6 * Copyright (c) 2005 LCG ROOT Math team, CERN/PH-SFT *
7 * *
8 **********************************************************************/
9
10#ifndef ROOT_Minuit2_MnPrint
11#define ROOT_Minuit2_MnPrint
12
13#include "Minuit2/MnConfig.h"
14
15#include <cassert>
16#include <ios>
17#include <iostream>
18#include <sstream>
19#include <string>
20#include <utility>
21#include <functional>
22
23namespace ROOT {
24namespace Minuit2 {
25
26/**
27 define std::ostream operators for output
28*/
29
30class FunctionMinimum;
31std::ostream &operator<<(std::ostream &, const FunctionMinimum &);
32
33class MinimumState;
34std::ostream &operator<<(std::ostream &, const MinimumState &);
35
37std::ostream &operator<<(std::ostream &, const MnUserParameters &);
38
40std::ostream &operator<<(std::ostream &, const MnUserCovariance &);
41
43std::ostream &operator<<(std::ostream &, const MnGlobalCorrelationCoeff &);
44
46std::ostream &operator<<(std::ostream &, const MnUserParameterState &);
47
49std::ostream &operator<<(std::ostream &, const MnMachinePrecision &);
50
51class MinosError;
52std::ostream &operator<<(std::ostream &, const MinosError &);
53
54class ContoursError;
55std::ostream &operator<<(std::ostream &, const ContoursError &);
56
57// std::pair<double, double> is used by MnContour
58std::ostream &operator<<(std::ostream &os, const std::pair<double, double> &point);
59
60/* Design notes: 1) We want to delay the costly conversion from object references to
61 strings to a point after we have decided whether or not to
62 show that string to the user at all. 2) We want to offer a customization point for
63 external libraries that want to replace the MnPrint logging. The actual
64 implementation is in a separate file, MnPrintImpl.cxx file that external libraries
65 can replace with their own implementation.
66*/
67
68// logging class for messages of varying severity
69class MnPrint {
70public:
71 // want this to be an enum class for strong typing...
72 enum class Verbosity { Error = 0, Warn = 1, Info = 2, Debug = 3, Trace = 4 };
73
74 // ...but also want the values accessible from MnPrint scope for convenience
75 static constexpr auto eError = Verbosity::Error;
76 static constexpr auto eWarn = Verbosity::Warn;
77 static constexpr auto eInfo = Verbosity::Info;
78 static constexpr auto eDebug = Verbosity::Debug;
79 static constexpr auto eTrace = Verbosity::Trace;
80
81 // used for one-line printing of fcn minimum state
82 class Oneline {
83 public:
84 Oneline(double fcn, double edm, int ncalls, int iter = -1);
85 Oneline(const MinimumState &state, int iter = -1);
86 Oneline(const FunctionMinimum &fmin, int iter = -1);
87
88 private:
89 double fFcn, fEdm;
91
92 friend std::ostream &operator<<(std::ostream &os, const Oneline &x);
93 };
94
95 MnPrint(const char *prefix, int level = MnPrint::GlobalLevel());
96 ~MnPrint();
97
98 // set global print level and return the previous one
99 static int SetGlobalLevel(int level);
100
101 // return current global print level
102 static int GlobalLevel();
103
104 // Whether to show the full prefix stack or only the end
105 static void ShowPrefixStack(bool yes);
106
107 static void AddFilter(const char *prefix);
108 static void ClearFilter();
109
110 // set print level and return the previous one
111 int SetLevel(int level);
112
113 // return current print level
114 int Level() const;
115
116 template <class... Ts>
117 void Error(const Ts &... args)
118 {
119 Log(eError, args...);
120 }
121
122 template <class... Ts>
123 void Warn(const Ts &... args)
124 {
125 Log(eWarn, args...);
126 }
127
128 template <class... Ts>
129 void Info(const Ts &... args)
130 {
131 Log(eInfo, args...);
132 }
133
134 template <class... Ts>
135 void Debug(const Ts &... args)
136 {
137 Log(eDebug, args...);
138 }
139
140 template <class... Ts>
141 void Trace(const Ts &... args)
142 {
143 Log(eTrace, args...);
144 }
145
146private:
147 // low level logging
148 template <class... Ts>
149 void Log(Verbosity level, const Ts &... args)
150 {
151 if (Level() < static_cast<int>(level))
152 return;
153 if (Hidden())
154 return;
155
156 std::ostringstream os;
157 StreamPrefix(os);
158 StreamArgs(os, args...);
159 Impl(level, os.str());
160 }
161
162 static void StreamPrefix(std::ostringstream &os);
163
164 // returns true if filters are installed and message is not selected by any filter
165 static bool Hidden();
166
167 // see MnPrintImpl.cxx
168 static void Impl(Verbosity level, const std::string &s);
169
170 // TMP to handle lambda argument correctly, exploiting overload resolution rules
171 template <class T>
172 static auto HandleLambda(std::ostream &os, const T &t, int) -> decltype(t(os), void())
173 {
174 t(os);
175 }
176
177 template <class T>
178 static void HandleLambda(std::ostream &os, const T &t, float)
179 {
180 os << t;
181 }
182
183 static void StreamArgs(std::ostringstream &) {}
184
185 // end of recursion
186 template <class T>
187 static void StreamArgs(std::ostringstream &os, const T &t)
188 {
189 os << " ";
190 HandleLambda(os, t, 0);
191 }
192
193 template <class T, class... Ts>
194 static void StreamArgs(std::ostringstream &os, const T &t, const Ts &... ts)
195 {
196 os << " " << t;
197 StreamArgs(os, ts...);
198 }
199
201};
202
203} // namespace Minuit2
204} // namespace ROOT
205
206#endif // ROOT_Minuit2_MnPrint
Oneline(double fcn, double edm, int ncalls, int iter=-1)
Definition MnPrint.cxx:186
MnPrint(const char *prefix, int level=MnPrint::GlobalLevel())
Definition MnPrint.cxx:86
class holding the full result of the minimization; both internal and external (MnUserParameterState) ...
MinimumState keeps the information (position, Gradient, 2nd deriv, etc) after one minimization step (...
Class holding the result of Minos (lower and upper values) for a specific parameter.
Definition MinosError.h:25
class for global correlation coefficient
Sets the relative floating point (double) arithmetic precision.
friend std::ostream & operator<<(std::ostream &os, const Oneline &x)
Definition MnPrint.cxx:198
Oneline(double fcn, double edm, int ncalls, int iter=-1)
Definition MnPrint.cxx:186
static void StreamArgs(std::ostringstream &os, const T &t, const Ts &... ts)
Definition MnPrint.h:194
static void StreamArgs(std::ostringstream &os, const T &t)
Definition MnPrint.h:187
void Debug(const Ts &... args)
Definition MnPrint.h:135
void Error(const Ts &... args)
Definition MnPrint.h:117
static void ClearFilter()
Definition MnPrint.cxx:106
static void HandleLambda(std::ostream &os, const T &t, float)
Definition MnPrint.h:178
static void StreamArgs(std::ostringstream &)
Definition MnPrint.h:183
void Info(const Ts &... args)
Definition MnPrint.h:129
static constexpr auto eError
Definition MnPrint.h:75
static void AddFilter(const char *prefix)
Definition MnPrint.cxx:101
static bool Hidden()
Definition MnPrint.cxx:158
static int GlobalLevel()
Definition MnPrint.cxx:118
static void ShowPrefixStack(bool yes)
Definition MnPrint.cxx:96
static int SetGlobalLevel(int level)
Definition MnPrint.cxx:111
void Warn(const Ts &... args)
Definition MnPrint.h:123
static constexpr auto eTrace
Definition MnPrint.h:79
void Trace(const Ts &... args)
Definition MnPrint.h:141
static constexpr auto eWarn
Definition MnPrint.h:76
static constexpr auto eInfo
Definition MnPrint.h:77
static void Impl(Verbosity level, const std::string &s)
static auto HandleLambda(std::ostream &os, const T &t, int) -> decltype(t(os), void())
Definition MnPrint.h:172
MnPrint(const char *prefix, int level=MnPrint::GlobalLevel())
Definition MnPrint.cxx:86
static void StreamPrefix(std::ostringstream &os)
Definition MnPrint.cxx:147
int SetLevel(int level)
Definition MnPrint.cxx:123
void Log(Verbosity level, const Ts &... args)
Definition MnPrint.h:149
static constexpr auto eDebug
Definition MnPrint.h:78
Class containing the covariance matrix data represented as a vector of size n*(n+1)/2 Used to hide in...
class which holds the external user and/or internal Minuit representation of the parameters and error...
API class for the user interaction with the parameters; serves as input to the minimizer as well as o...
Double_t x[n]
Definition legend1.C:17
std::ostream & operator<<(std::ostream &, const LAVector &)
Definition MnMatrix.cxx:691