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