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 <sstream>
16#include <utility>
17#include <cassert>
18#include <string>
19#include <ios>
20
21namespace ROOT {
22namespace Minuit2 {
23
24/**
25 define std::ostream operators for output
26*/
27
28class FunctionMinimum;
29std::ostream &operator<<(std::ostream &, const FunctionMinimum &);
30
31class MinimumState;
32std::ostream &operator<<(std::ostream &, const MinimumState &);
33
34class MnUserParameters;
35std::ostream &operator<<(std::ostream &, const MnUserParameters &);
36
37class MnUserCovariance;
38std::ostream &operator<<(std::ostream &, const MnUserCovariance &);
39
40class MnGlobalCorrelationCoeff;
41std::ostream &operator<<(std::ostream &, const MnGlobalCorrelationCoeff &);
42
43class MnUserParameterState;
44std::ostream &operator<<(std::ostream &, const MnUserParameterState &);
45
46class MnMachinePrecision;
47std::ostream &operator<<(std::ostream &, const MnMachinePrecision &);
48
49class MinosError;
50std::ostream &operator<<(std::ostream &, const MinosError &);
51
52class ContoursError;
53std::ostream &operator<<(std::ostream &, const ContoursError &);
54
55// std::pair<double, double> is used by MnContour
56std::ostream &operator<<(std::ostream &os, const std::pair<double, double> &point);
57
58/* Design notes: 1) We want to delay the costly conversion from object references to
59 strings to a point after we have decided whether or not to
60 show that string to the user at all. 2) We want to offer a customization point for
61 external libraries that want to replace the MnPrint logging. The actual
62 implementation is in a separate file, MnPrintImpl.cxx file that external libraries
63 can replace with their own implementation.
64*/
65
66// logging class for messages of varying severity
67class MnPrint {
68public:
69 // want this to be an enum class for strong typing...
70 enum class Verbosity { Error = 0, Warn = 1, Info = 2, Debug = 3, Trace = 4 };
71
72 // ...but also want the values accessible from MnPrint scope for convenience
73 static constexpr auto eError = Verbosity::Error;
74 static constexpr auto eWarn = Verbosity::Warn;
75 static constexpr auto eInfo = Verbosity::Info;
76 static constexpr auto eDebug = Verbosity::Debug;
77 static constexpr auto eTrace = Verbosity::Trace;
78
79 // used for one-line printing of fcn minimum state
80 class Oneline {
81 public:
82 Oneline(double fcn, double edm, int ncalls, int iter = -1);
83 Oneline(const MinimumState &state, int iter = -1);
84 Oneline(const FunctionMinimum &fmin, int iter = -1);
85
86 private:
87 double fFcn, fEdm;
89
90 friend std::ostream &operator<<(std::ostream &os, const Oneline &x);
91 };
92
93 MnPrint(const char *prefix, int level = MnPrint::GlobalLevel());
94 ~MnPrint();
95
96 // set global print level and return the previous one
97 static int SetGlobalLevel(int level);
98
99 // return current global print level
100 static int GlobalLevel();
101
102 // Whether to show the full prefix stack or only the end
103 static void ShowPrefixStack(bool yes);
104
105 static void AddFilter(const char *prefix);
106 static void ClearFilter();
107
108 // set print level and return the previous one
109 int SetLevel(int level);
110
111 // return current print level
112 int Level() const;
113
114 template <class... Ts>
115 void Error(const Ts &... args)
116 {
117 Log(eError, args...);
118 }
119
120 template <class... Ts>
121 void Warn(const Ts &... args)
122 {
123 Log(eWarn, args...);
124 }
125
126 template <class... Ts>
127 void Info(const Ts &... args)
128 {
129 Log(eInfo, args...);
130 }
131
132 template <class... Ts>
133 void Debug(const Ts &... args)
134 {
135 Log(eDebug, args...);
136 }
137
138 template <class... Ts>
139 void Trace(const Ts &... args)
140 {
141 Log(eTrace, args...);
142 }
143
144private:
145 // low level logging
146 template <class... Ts>
147 void Log(Verbosity level, const Ts &... args)
148 {
149 if (Level() < static_cast<int>(level))
150 return;
151 if (Hidden())
152 return;
153
154 std::ostringstream os;
155 StreamPrefix(os);
156 StreamArgs(os, args...);
157 Impl(level, os.str());
158 }
159
160 static void StreamPrefix(std::ostringstream &os);
161
162 // returns true if filters are installed and message is not selected by any filter
163 static bool Hidden();
164
165 // see MnPrintImpl.cxx
166 static void Impl(Verbosity level, const std::string &s);
167
168 // TMP to handle lambda argument correctly, exploiting overload resolution rules
169 template <class T>
170 static auto HandleLambda(std::ostream &os, const T &t, int) -> decltype(t(os), void())
171 {
172 t(os);
173 }
174
175 template <class T>
176 static void HandleLambda(std::ostream &os, const T &t, float)
177 {
178 os << t;
179 }
180
181 static void StreamArgs(std::ostringstream &) {}
182
183 // end of recursion
184 template <class T>
185 static void StreamArgs(std::ostringstream &os, const T &t)
186 {
187 os << " ";
188 HandleLambda(os, t, 0);
189 }
190
191 template <class T, class... Ts>
192 static void StreamArgs(std::ostringstream &os, const T &t, const Ts &... ts)
193 {
194 os << " " << t;
195 StreamArgs(os, ts...);
196 }
197
199};
200
201} // namespace Minuit2
202} // namespace ROOT
203
204#endif // ROOT_Minuit2_MnPrint
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 (...
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:192
static void StreamArgs(std::ostringstream &os, const T &t)
Definition MnPrint.h:185
void Debug(const Ts &... args)
Definition MnPrint.h:133
void Error(const Ts &... args)
Definition MnPrint.h:115
static void ClearFilter()
Definition MnPrint.cxx:106
static void HandleLambda(std::ostream &os, const T &t, float)
Definition MnPrint.h:176
static void StreamArgs(std::ostringstream &)
Definition MnPrint.h:181
void Info(const Ts &... args)
Definition MnPrint.h:127
static constexpr auto eError
Definition MnPrint.h:73
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:121
static constexpr auto eTrace
Definition MnPrint.h:77
void Trace(const Ts &... args)
Definition MnPrint.h:139
static constexpr auto eWarn
Definition MnPrint.h:74
static constexpr auto eInfo
Definition MnPrint.h:75
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:170
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:147
static constexpr auto eDebug
Definition MnPrint.h:76
Double_t x[n]
Definition legend1.C:17
std::ostream & operator<<(std::ostream &, const LAVector &)
Definition MnMatrix.cxx:691
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...