Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:22:13

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