Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:10:10

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 namespace GenVector {
0025 inline void Throw(const char *);
0026 }
0027 
0028 // ----------------------------------------------------------------------
0029 // GenVector_exception class definition
0030 //
0031 // This class needs to be entirely contained in this header, otherwise
0032 // the interactive usage of entities such as ROOT::Math::PtEtaPhiMVector
0033 // is not possible because of missing symbols.
0034 // This is due to the fact that the Throw function is used in the inline
0035 // code bu this function is implemented in the Genvector library.
0036 class GenVector_exception : public std::runtime_error {
0037 public:
0038    GenVector_exception(const std::string &s) : runtime_error(s) {}
0039 
0040    // Compiler-generated copy ctor, copy assignment, dtor are fine
0041    // Inherited what() from runtime_error is fine
0042 
0043    static bool EnableThrow()
0044    {
0045       bool tmp = GenVector_exception::IsOn();
0046       IsOn() = true;
0047       return tmp;
0048    }
0049    static bool DisableThrow()
0050    {
0051       bool tmp = GenVector_exception::IsOn();
0052       IsOn() = false;
0053       return tmp;
0054    }
0055 
0056 private:
0057    friend void Throw(GenVector_exception &);
0058    friend void GenVector::Throw(const char *);
0059 
0060    static bool &IsOn()
0061    {
0062       static bool isOn = false;
0063       return isOn;
0064    };
0065 
0066 }; // GenVector_exception
0067 
0068 // ----------------------------------------------------------------------
0069 // Epilog
0070 
0071 /// throw explicitly GenVector exceptions
0072 inline void Throw(GenVector_exception &e)
0073 {
0074    if (GenVector_exception::IsOn())
0075       throw e;
0076 }
0077 
0078 namespace GenVector {
0079 /// function throwing exception, by creating internally a GenVector_exception only when needed
0080 inline void Throw(const char *s)
0081 {
0082    if (!GenVector_exception::IsOn())
0083       return;
0084    GenVector_exception e(s);
0085    throw e;
0086 }
0087 } // namespace GenVector
0088 
0089 } // namespace Math
0090 } // namespace ROOT
0091 
0092 #endif // GENVECTOR_EXCEPTION_H