Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:57:17

0001  #ifndef __FASTJET_ERROR_HH__
0002 #define __FASTJET_ERROR_HH__
0003 
0004 //FJSTARTHEADER
0005 // $Id$
0006 //
0007 // Copyright (c) 2005-2021, Matteo Cacciari, Gavin P. Salam and Gregory Soyez
0008 //
0009 //----------------------------------------------------------------------
0010 // This file is part of FastJet.
0011 //
0012 //  FastJet is free software; you can redistribute it and/or modify
0013 //  it under the terms of the GNU General Public License as published by
0014 //  the Free Software Foundation; either version 2 of the License, or
0015 //  (at your option) any later version.
0016 //
0017 //  The algorithms that underlie FastJet have required considerable
0018 //  development. They are described in the original FastJet paper,
0019 //  hep-ph/0512210 and in the manual, arXiv:1111.6097. If you use
0020 //  FastJet as part of work towards a scientific publication, please
0021 //  quote the version you use and include a citation to the manual and
0022 //  optionally also to hep-ph/0512210.
0023 //
0024 //  FastJet is distributed in the hope that it will be useful,
0025 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
0026 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0027 //  GNU General Public License for more details.
0028 //
0029 //  You should have received a copy of the GNU General Public License
0030 //  along with FastJet. If not, see <http://www.gnu.org/licenses/>.
0031 //----------------------------------------------------------------------
0032 //FJENDHEADER
0033 
0034 #include<iostream>
0035 #include<string>
0036 #include "fastjet/internal/base.hh"
0037 #include "fastjet/config.h"
0038 //#include <exception>
0039 #if (!defined(FASTJET_HAVE_EXECINFO_H)) || defined(__FJCORE__)
0040 #include "fastjet/LimitedWarning.hh"
0041 #endif
0042 #ifdef FASTJET_HAVE_LIMITED_THREAD_SAFETY
0043 #include <atomic>
0044 #include <mutex>
0045 #endif // FASTJET_HAVE_LIMITED_THREAD_SAFETY
0046 
0047 FASTJET_BEGIN_NAMESPACE      // defined in fastjet/internal/base.hh
0048 
0049 /// @ingroup error_handling
0050 /// \class Error
0051 /// base class corresponding to errors that can be thrown by FastJet
0052 class Error{
0053 public:
0054   /// default constructors
0055   Error() {}
0056 
0057   /// ctor from an error message
0058   ///   \param message to be printed
0059   /// Note: in addition to the error message, one can choose to print the
0060   /// backtrace (showing the last few calls before the error) by 
0061   /// using set_print_backtrace(true). The default is "false".
0062   Error(const std::string & message);
0063 
0064   /// virtual dummy dtor
0065   virtual ~Error() {}
0066 
0067   /// the error message
0068   std::string message() const {return _message;}
0069 
0070   /// an alternative access to the error message (more standard)
0071   std::string description() const {return message();}
0072   
0073   /// controls whether the error message (and the backtrace, if its printing is enabled) 
0074   /// is printed out or not
0075   static void set_print_errors(bool print_errors) {_print_errors = print_errors;}
0076 
0077   /// controls whether the backtrace is printed out with the error message or not.
0078   /// The default is "false".
0079   static void set_print_backtrace(bool enabled);
0080 
0081   /// sets the default output stream for all errors; by default
0082   /// cerr; if it's null then error output is suppressed.
0083   static void set_default_stream(std::ostream * ostr) {
0084     _default_ostr = ostr;
0085   }
0086 
0087 #ifdef FASTJET_HAVE_LIMITED_THREAD_SAFETY
0088   /// sets the default output stream for all errors (by default
0089   /// cerr; passing a null pointer prevents errors from being output)
0090   /// The second argument is a mutex that would be used to guarantee 
0091   /// that only a single thread writes to the stream at a time
0092   static void set_default_stream_and_mutex(std::ostream * ostr, std::mutex * stream_mutex) {
0093     _default_ostr = ostr;
0094     _stream_mutex = stream_mutex;
0095   }
0096 #endif // FASTJET_HAVE_LIMITED_THREAD_SAFETY
0097 
0098 private:
0099 
0100 #ifndef __FJCORE__
0101 #if defined(FASTJET_HAVE_EXECINFO_H) && defined(FASTJET_HAVE_DEMANGLING_SUPPORT)
0102   /// demangle a given backtrace symbol
0103   std::string _demangle(const char* symbol);
0104 #endif
0105 #endif
0106 
0107   std::string _message;                ///< error message
0108 
0109 #ifdef FASTJET_HAVE_LIMITED_THREAD_SAFETY
0110   static std::atomic<bool> _print_errors;           ///< do we print anything?
0111   static std::atomic<bool> _print_backtrace;        ///< do we print the backtrace?
0112   static std::atomic<std::ostream *> _default_ostr; ///< the output stream (cerr if not set)
0113   static std::atomic<std::mutex *> _stream_mutex; ///< the mutex for the output stream (nullptr if not set)
0114 #else
0115   static bool _print_errors;           ///< do we print anything?
0116   static bool _print_backtrace;        ///< do we print the backtrace?
0117   static std::ostream * _default_ostr; ///< the output stream (cerr if not set)
0118 #endif // FASTJET_HAVE_LIMITED_THREAD_SAFETY
0119 
0120 
0121 #if (!defined(FASTJET_HAVE_EXECINFO_H)) || defined(__FJCORE__)
0122   static LimitedWarning _execinfo_undefined;
0123 #endif
0124 };
0125 
0126 
0127 /// @ingroup error_handling
0128 /// \class InternalError
0129 /// class corresponding to critical internal errors
0130 /// 
0131 /// This is an error class (derived from Error) meant for serious,
0132 /// critical, internal errors that we still want to be catchable by an
0133 /// end-user [e.g. a serious issue in clustering where the end-user
0134 /// can catch it and retry with a different strategy]
0135 ///
0136 /// Please directly contact the FastJet authors if you see such an
0137 /// error.
0138 class InternalError : public Error{
0139 public:
0140   /// ctor with error message:
0141   /// just add a bit of info to the message and pass it to the base class
0142   InternalError(const std::string & message_in) : Error(std::string("*** CRITICAL INTERNAL FASTJET ERROR *** CONTACT THE AUTHORS *** ") + message_in){ }
0143 };
0144 
0145 FASTJET_END_NAMESPACE
0146 
0147 #endif // __FASTJET_ERROR_HH__