Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-15 10:28:11

0001 // @(#)root/mathcore:$Id$
0002 // Authors: W. Brown, M. Fischler, L. Moneta    2005
0003 
0004 #ifndef ROOT_Math_GenVector_GenVector_exception
0005 #define ROOT_Math_GenVector_GenVector_exception 1
0006 
0007 // ======================================================================
0008 // $Id $
0009 //
0010 // Define the exception type used throughout this package.
0011 // ======================================================================
0012 
0013 // ----------------------------------------------------------------------
0014 // Prolog
0015 
0016 #include <stdexcept>
0017 #include <string>
0018 
0019 namespace ROOT {
0020 namespace Math {
0021 
0022 class GenVector_exception;
0023 inline void Throw(GenVector_exception &e);
0024 inline void GenVector_Throw(const char *);
0025 
0026 // ----------------------------------------------------------------------
0027 // GenVector_exception class definition
0028 //
0029 // This class needs to be entirely contained in this header, otherwise
0030 // the interactive usage of entities such as ROOT::Math::PtEtaPhiMVector
0031 // is not possible because of missing symbols.
0032 // This is due to the fact that the Throw function is used in the inline
0033 // code bu this function is implemented in the Genvector library.
0034 class GenVector_exception : public std::runtime_error {
0035 public:
0036    GenVector_exception(const std::string &s) : runtime_error(s) {}
0037 
0038    // Compiler-generated copy ctor, copy assignment, dtor are fine
0039    // Inherited what() from runtime_error is fine
0040 
0041    static bool EnableThrow()
0042    {
0043       bool tmp = GenVector_exception::IsOn();
0044       IsOn() = true;
0045       return tmp;
0046    }
0047    static bool DisableThrow()
0048    {
0049       bool tmp = GenVector_exception::IsOn();
0050       IsOn() = false;
0051       return tmp;
0052    }
0053 
0054 private:
0055    friend void Throw(GenVector_exception &);
0056    friend void GenVector_Throw(const char *);
0057 
0058    static bool &IsOn()
0059    {
0060       static bool isOn = false;
0061       return isOn;
0062    };
0063 
0064 }; // GenVector_exception
0065 
0066 // ----------------------------------------------------------------------
0067 // Epilog
0068 
0069 /// throw explicitly GenVector exceptions
0070 inline void Throw(GenVector_exception &e)
0071 {
0072    if (GenVector_exception::IsOn())
0073       throw e;
0074 }
0075 
0076 /// function throwing exception, by creating internally a GenVector_exception only when needed
0077 inline void GenVector_Throw(const char *s)
0078 {
0079    if (!GenVector_exception::IsOn())
0080       return;
0081    GenVector_exception e(s);
0082    throw e;
0083 }
0084 
0085 } // namespace Math
0086 } // namespace ROOT
0087 
0088 #endif // GENVECTOR_EXCEPTION_H