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, Trace = 4 };
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 static constexpr auto eTrace = Verbosity::Trace;
84
85 // used for one-line printing of fcn minimum state
86 class Oneline {
87 public:
88 Oneline(double fcn, double edm, int ncalls, int iter = -1);
89 Oneline(const MinimumState &state, int iter = -1);
90 Oneline(const FunctionMinimum &fmin, int iter = -1);
91
92 private:
93 double fFcn, fEdm;
95
96 friend std::ostream &operator<<(std::ostream &os, const Oneline &x);
97 };
98
99 MnPrint(const char *prefix, int level = MnPrint::GlobalLevel());
100 ~MnPrint();
101
102 // set global print level and return the previous one
103 static int SetGlobalLevel(int level);
104
105 // return current global print level
106 static int GlobalLevel();
107
108 // Whether to show the full prefix stack or only the end
109 static void ShowPrefixStack(bool yes);
110
111 static void AddFilter(const char *prefix);
112 static void ClearFilter();
113
114 // Whether to cut the maximum number of parameters shown for vector and matrices
115 // set maximum number of printed parameters and return previous value
116 // A negative value will mean all parameters are printed
117 static int SetMaxNP(int value);
118
119 // retrieve maximum number of printed parameters
120 static int MaxNP();
121
122 // set print level and return the previous one
123 int SetLevel(int level);
124
125 // return current print level
126 int Level() const;
127
128 template <class... Ts>
129 void Error(const Ts &... args)
130 {
131 Log(eError, args...);
132 }
133
134 template <class... Ts>
135 void Warn(const Ts &... args)
136 {
137 Log(eWarn, args...);
138 }
139
140 template <class... Ts>
141 void Info(const Ts &... args)
142 {
143 Log(eInfo, args...);
144 }
145
146 template <class... Ts>
147 void Debug(const Ts &... args)
148 {
149 Log(eDebug, args...);
150 }
151
152 template <class... Ts>
153 void Trace(const Ts &... args)
154 {
155 Log(eTrace, args...);
156 }
157
158private:
159 // low level logging
160 template <class... Ts>
161 void Log(Verbosity level, const Ts &... args)
162 {
163 if (Level() < static_cast<int>(level))
164 return;
165 if (Hidden())
166 return;
167
168 std::ostringstream os;
169 StreamPrefix(os);
170 StreamArgs(os, args...);
171 Impl(level, os.str());
172 }
173
174 static void StreamPrefix(std::ostringstream &os);
175
176 // returns true if filters are installed and message is not selected by any filter
177 static bool Hidden();
178
179 // see MnPrintImpl.cxx
180 static void Impl(Verbosity level, const std::string &s);
181
182 // TMP to handle lambda argument correctly, exploiting overload resolution rules
183 template <class T>
184 static auto HandleLambda(std::ostream &os, const T &t, int) -> decltype(t(os), void())
185 {
186 t(os);
187 }
188
189 template <class T>
190 static void HandleLambda(std::ostream &os, const T &t, float)
191 {
192 os << t;
193 }
194
195 static void StreamArgs(std::ostringstream &) {}
196
197 // end of recursion
198 template <class T>
199 static void StreamArgs(std::ostringstream &os, const T &t)
200 {
201 os << " ";
202 HandleLambda(os, t, 0);
203 }
204
205 template <class T, class... Ts>
206 static void StreamArgs(std::ostringstream &os, const T &t, const Ts &... ts)
207 {
208 os << " " << t;
209 StreamArgs(os, ts...);
210 }
211
213};
214
215} // namespace Minuit2
216} // namespace ROOT
217
218#endif // ROOT_Minuit2_MnPrint
TBuffer & operator<<(TBuffer &buf, const Tmpl *obj)
Definition TBuffer.h:399
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
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:213
static void StreamArgs(std::ostringstream &os, const T &t, const Ts &... ts)
Definition MnPrint.h:206
static void StreamArgs(std::ostringstream &os, const T &t)
Definition MnPrint.h:199
static int SetMaxNP(int value)
Definition MnPrint.cxx:139
void Debug(const Ts &... args)
Definition MnPrint.h:147
void Error(const Ts &... args)
Definition MnPrint.h:129
static void ClearFilter()
Definition MnPrint.cxx:110
static void HandleLambda(std::ostream &os, const T &t, float)
Definition MnPrint.h:190
static void StreamArgs(std::ostringstream &)
Definition MnPrint.h:195
void Info(const Ts &... args)
Definition MnPrint.h:141
static constexpr auto eError
Definition MnPrint.h:79
static void AddFilter(const char *prefix)
Definition MnPrint.cxx:105
static bool Hidden()
Definition MnPrint.cxx:173
static int GlobalLevel()
Definition MnPrint.cxx:122
static void ShowPrefixStack(bool yes)
Definition MnPrint.cxx:100
static int SetGlobalLevel(int level)
Definition MnPrint.cxx:115
void Warn(const Ts &... args)
Definition MnPrint.h:135
static constexpr auto eTrace
Definition MnPrint.h:83
void Trace(const Ts &... args)
Definition MnPrint.h:153
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:184
static void StreamPrefix(std::ostringstream &os)
Definition MnPrint.cxx:162
int SetLevel(int level)
Definition MnPrint.cxx:127
void Log(Verbosity level, const Ts &... args)
Definition MnPrint.h:161
static constexpr auto eDebug
Definition MnPrint.h:82
Double_t x[n]
Definition legend1.C:17
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.