Logo ROOT  
Reference Guide
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 
21 namespace ROOT {
22 namespace Minuit2 {
23 
24 /**
25  define std::ostream operators for output
26 */
27 
28 class FunctionMinimum;
29 std::ostream &operator<<(std::ostream &, const FunctionMinimum &);
30 
31 class MinimumState;
32 std::ostream &operator<<(std::ostream &, const MinimumState &);
33 
34 class LAVector;
35 std::ostream &operator<<(std::ostream &, const LAVector &);
36 
37 class LASymMatrix;
38 std::ostream &operator<<(std::ostream &, const LASymMatrix &);
39 
40 class MnUserParameters;
41 std::ostream &operator<<(std::ostream &, const MnUserParameters &);
42 
43 class MnUserCovariance;
44 std::ostream &operator<<(std::ostream &, const MnUserCovariance &);
45 
46 class MnGlobalCorrelationCoeff;
47 std::ostream &operator<<(std::ostream &, const MnGlobalCorrelationCoeff &);
48 
49 class MnUserParameterState;
50 std::ostream &operator<<(std::ostream &, const MnUserParameterState &);
51 
52 class MnMachinePrecision;
53 std::ostream &operator<<(std::ostream &, const MnMachinePrecision &);
54 
55 class MinosError;
56 std::ostream &operator<<(std::ostream &, const MinosError &);
57 
58 class ContoursError;
59 std::ostream &operator<<(std::ostream &, const ContoursError &);
60 
61 // std::pair<double, double> is used by MnContour
62 std::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
73 class MnPrint {
74 public:
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;
93  int fNcalls, fIter;
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 
143 private:
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 
197  int fLevel;
198 };
199 
200 } // namespace Minuit2
201 } // namespace ROOT
202 
203 #endif // ROOT_Minuit2_MnPrint
ROOT::Minuit2::MnPrint::Verbosity::Error
@ Error
ROOT::Minuit2::MnPrint::~MnPrint
~MnPrint()
Definition: MnPrint.cxx:93
ROOT::Minuit2::MinimumState
MinimumState keeps the information (position, Gradient, 2nd deriv, etc) after one minimization step (...
Definition: MinimumState.h:27
ROOT::Minuit2::MnPrint::Debug
void Debug(const Ts &... args)
Definition: MnPrint.h:138
ROOT::Minuit2::MnPrint::eError
static constexpr auto eError
Definition: MnPrint.h:79
ROOT::Minuit2::MnPrint::Oneline::fFcn
double fFcn
Definition: MnPrint.h:92
ROOT::Minuit2::MnPrint::Oneline::fEdm
double fEdm
Definition: MnPrint.h:92
ROOT::Minuit2::MnPrint::Oneline::Oneline
Oneline(double fcn, double edm, int ncalls, int iter=-1)
Definition: MnPrint.cxx:188
TGeant4Unit::s
static constexpr double s
Definition: TGeant4SystemOfUnits.h:162
ROOT::Minuit2::MnPrint::Oneline
Definition: MnPrint.h:85
x
Double_t x[n]
Definition: legend1.C:17
ROOT::Minuit2::MnPrint::ShowPrefixStack
static void ShowPrefixStack(bool yes)
Definition: MnPrint.cxx:98
ROOT::Minuit2::MnPrint::GlobalLevel
static int GlobalLevel()
Definition: MnPrint.cxx:120
ROOT::Minuit2::MnPrint::Oneline::fNcalls
int fNcalls
Definition: MnPrint.h:93
ROOT::Minuit2::MnPrint::eDebug
static constexpr auto eDebug
Definition: MnPrint.h:82
ROOT::Minuit2::MnPrint::Error
void Error(const Ts &... args)
Definition: MnPrint.h:120
ROOT::Minuit2::MnPrint::Verbosity::Debug
@ Debug
ROOT::Minuit2::MnPrint::Level
int Level() const
Definition: MnPrint.cxx:132
ROOT::Minuit2::MnPrint::Verbosity::Warn
@ Warn
ROOT::Minuit2::MnPrint::Warn
void Warn(const Ts &... args)
Definition: MnPrint.h:126
ROOT::Minuit2::MnPrint::AddFilter
static void AddFilter(const char *prefix)
Definition: MnPrint.cxx:103
ROOT::Minuit2::MnPrint::HandleLambda
static void HandleLambda(std::ostream &os, const T &t, float)
Definition: MnPrint.h:175
ROOT::Minuit2::MnPrint::Verbosity::Info
@ Info
ROOT::Minuit2::MnPrint::StreamArgs
static void StreamArgs(std::ostringstream &)
Definition: MnPrint.h:180
ROOT::Minuit2::MnPrint::ClearFilter
static void ClearFilter()
Definition: MnPrint.cxx:108
ROOT::Minuit2::MnPrint::eWarn
static constexpr auto eWarn
Definition: MnPrint.h:80
ROOT::Minuit2::MnPrint::Oneline::operator<<
friend std::ostream & operator<<(std::ostream &os, const Oneline &x)
Definition: MnPrint.cxx:200
ROOT::Minuit2::MnPrint::SetGlobalLevel
static int SetGlobalLevel(int level)
Definition: MnPrint.cxx:113
ROOT::Minuit2::MnPrint::Log
void Log(Verbosity level, const Ts &... args)
Definition: MnPrint.h:146
ROOT::Minuit2::MnPrint::Oneline::fIter
int fIter
Definition: MnPrint.h:93
ROOT::Minuit2::MnPrint::StreamPrefix
static void StreamPrefix(std::ostringstream &os)
Definition: MnPrint.cxx:149
ROOT::Minuit2::MnPrint::StreamArgs
static void StreamArgs(std::ostringstream &os, const T &t, const Ts &... ts)
Definition: MnPrint.h:191
ROOT::Minuit2::MnPrint::Hidden
static bool Hidden()
Definition: MnPrint.cxx:160
ROOT::Minuit2::MnPrint::StreamArgs
static void StreamArgs(std::ostringstream &os, const T &t)
Definition: MnPrint.h:184
ROOT::Minuit2::MnPrint::Verbosity
Verbosity
Definition: MnPrint.h:76
ROOT::Minuit2::MnPrint::Impl
static void Impl(Verbosity level, const std::string &s)
Definition: MnPrintImpl.cxx:13
ROOT::Minuit2::FunctionMinimum
class holding the full result of the minimization; both internal and external (MnUserParameterState) ...
Definition: FunctionMinimum.h:36
ROOT::Minuit2::operator<<
std::ostream & operator<<(std::ostream &, const FunctionMinimum &)
Definition: MnPrint.cxx:335
ROOT::Minuit2::MnPrint::SetLevel
int SetLevel(int level)
Definition: MnPrint.cxx:125
ROOT::Minuit2::MnPrint::HandleLambda
static auto HandleLambda(std::ostream &os, const T &t, int) -> decltype(t(os), void())
Definition: MnPrint.h:169
ROOT::Math::Chebyshev::T
double T(double x)
Definition: ChebyshevPol.h:34
ROOT::Minuit2::MnPrint::eInfo
static constexpr auto eInfo
Definition: MnPrint.h:81
ROOT
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Definition: EExecutionPolicy.hxx:4
ROOT::Minuit2::MnPrint::fLevel
int fLevel
Definition: MnPrint.h:197
ROOT::Minuit2::MnPrint::MnPrint
MnPrint(const char *prefix, int level=MnPrint::GlobalLevel())
Definition: MnPrint.cxx:88
MnConfig.h
ROOT::Minuit2::MnPrint::Info
void Info(const Ts &... args)
Definition: MnPrint.h:132
ROOT::Minuit2::MnPrint
Definition: MnPrint.h:73