Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-27 08:59:00

0001 // @(#)root/minuit2:$Id$
0002 // Authors: M. Winkler, F. James, L. Moneta, A. Zsenei   2003-2005
0003 
0004 /**********************************************************************
0005  *                                                                    *
0006  * Copyright (c) 2005 LCG ROOT Math team,  CERN/PH-SFT                *
0007  *                                                                    *
0008  **********************************************************************/
0009 
0010 #ifndef ROOT_Minuit2_MnPrint
0011 #define ROOT_Minuit2_MnPrint
0012 
0013 #include "Minuit2/MnConfig.h"
0014 
0015 #include <cassert>
0016 #include <ios>
0017 #include <iostream>
0018 #include <sstream>
0019 #include <string>
0020 #include <utility>
0021 #include <functional>
0022 
0023 namespace ROOT {
0024 namespace Minuit2 {
0025 
0026 /**
0027     define std::ostream operators for output
0028 */
0029 
0030 class FunctionMinimum;
0031 std::ostream &operator<<(std::ostream &, const FunctionMinimum &);
0032 
0033 class MinimumState;
0034 std::ostream &operator<<(std::ostream &, const MinimumState &);
0035 
0036 class MnUserParameters;
0037 std::ostream &operator<<(std::ostream &, const MnUserParameters &);
0038 
0039 class MnUserCovariance;
0040 std::ostream &operator<<(std::ostream &, const MnUserCovariance &);
0041 
0042 class MnGlobalCorrelationCoeff;
0043 std::ostream &operator<<(std::ostream &, const MnGlobalCorrelationCoeff &);
0044 
0045 class MnUserParameterState;
0046 std::ostream &operator<<(std::ostream &, const MnUserParameterState &);
0047 
0048 class MnMachinePrecision;
0049 std::ostream &operator<<(std::ostream &, const MnMachinePrecision &);
0050 
0051 class MinosError;
0052 std::ostream &operator<<(std::ostream &, const MinosError &);
0053 
0054 class ContoursError;
0055 std::ostream &operator<<(std::ostream &, const ContoursError &);
0056 
0057 // std::pair<double, double> is used by MnContour
0058 std::ostream &operator<<(std::ostream &os, const std::pair<double, double> &point);
0059 
0060 /* Design notes: 1) We want to delay the costly conversion from object references to
0061    strings to a point after we have decided whether or not to
0062    show that string to the user at all. 2) We want to offer a customization point for
0063    external libraries that want to replace the MnPrint logging. The actual
0064    implementation is in a separate file, MnPrintImpl.cxx file that external libraries
0065    can replace with their own implementation.
0066 */
0067 
0068 // logging class for messages of varying severity
0069 class MnPrint {
0070 public:
0071    // want this to be an enum class for strong typing...
0072    enum class Verbosity { Error = 0, Warn = 1, Info = 2, Debug = 3, Trace = 4 };
0073 
0074    // ...but also want the values accessible from MnPrint scope for convenience
0075    static constexpr auto eError = Verbosity::Error;
0076    static constexpr auto eWarn = Verbosity::Warn;
0077    static constexpr auto eInfo = Verbosity::Info;
0078    static constexpr auto eDebug = Verbosity::Debug;
0079    static constexpr auto eTrace = Verbosity::Trace;
0080 
0081    // used for one-line printing of fcn minimum state
0082    class Oneline {
0083    public:
0084       Oneline(double fcn, double edm, int ncalls, int iter = -1);
0085       Oneline(const MinimumState &state, int iter = -1);
0086       Oneline(const FunctionMinimum &fmin, int iter = -1);
0087 
0088    private:
0089       double fFcn, fEdm;
0090       int fNcalls, fIter;
0091 
0092       friend std::ostream &operator<<(std::ostream &os, const Oneline &x);
0093    };
0094 
0095    MnPrint(const char *prefix, int level = MnPrint::GlobalLevel());
0096    ~MnPrint();
0097 
0098    // set global print level and return the previous one
0099    static int SetGlobalLevel(int level);
0100 
0101    // return current global print level
0102    static int GlobalLevel();
0103 
0104    // Whether to show the full prefix stack or only the end
0105    static void ShowPrefixStack(bool yes);
0106 
0107    static void AddFilter(const char *prefix);
0108    static void ClearFilter();
0109 
0110    // set print level and return the previous one
0111    int SetLevel(int level);
0112 
0113    // return current print level
0114    int Level() const;
0115 
0116    template <class... Ts>
0117    void Error(const Ts &... args)
0118    {
0119       Log(eError, args...);
0120    }
0121 
0122    template <class... Ts>
0123    void Warn(const Ts &... args)
0124    {
0125       Log(eWarn, args...);
0126    }
0127 
0128    template <class... Ts>
0129    void Info(const Ts &... args)
0130    {
0131       Log(eInfo, args...);
0132    }
0133 
0134    template <class... Ts>
0135    void Debug(const Ts &... args)
0136    {
0137       Log(eDebug, args...);
0138    }
0139 
0140    template <class... Ts>
0141    void Trace(const Ts &... args)
0142    {
0143       Log(eTrace, args...);
0144    }
0145 
0146 private:
0147    // low level logging
0148    template <class... Ts>
0149    void Log(Verbosity level, const Ts &... args)
0150    {
0151       if (Level() < static_cast<int>(level))
0152          return;
0153       if (Hidden())
0154          return;
0155 
0156       std::ostringstream os;
0157       StreamPrefix(os);
0158       StreamArgs(os, args...);
0159       Impl(level, os.str());
0160    }
0161 
0162    static void StreamPrefix(std::ostringstream &os);
0163 
0164    // returns true if filters are installed and message is not selected by any filter
0165    static bool Hidden();
0166 
0167    // see MnPrintImpl.cxx
0168    static void Impl(Verbosity level, const std::string &s);
0169 
0170    // TMP to handle lambda argument correctly, exploiting overload resolution rules
0171    template <class T>
0172    static auto HandleLambda(std::ostream &os, const T &t, int) -> decltype(t(os), void())
0173    {
0174       t(os);
0175    }
0176 
0177    template <class T>
0178    static void HandleLambda(std::ostream &os, const T &t, float)
0179    {
0180       os << t;
0181    }
0182 
0183    static void StreamArgs(std::ostringstream &) {}
0184 
0185    // end of recursion
0186    template <class T>
0187    static void StreamArgs(std::ostringstream &os, const T &t)
0188    {
0189       os << " ";
0190       HandleLambda(os, t, 0);
0191    }
0192 
0193    template <class T, class... Ts>
0194    static void StreamArgs(std::ostringstream &os, const T &t, const Ts &... ts)
0195    {
0196       os << " " << t;
0197       StreamArgs(os, ts...);
0198    }
0199 
0200    int fLevel;
0201 };
0202 
0203 } // namespace Minuit2
0204 } // namespace ROOT
0205 
0206 #endif // ROOT_Minuit2_MnPrint