Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-15 08:54:42

0001 //------------------------------- -*- C++ -*- -------------------------------//
0002 // Copyright Celeritas contributors: see top-level COPYRIGHT file for details
0003 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0004 //---------------------------------------------------------------------------//
0005 //! \file celeritas/ext/ScopedRootErrorHandler.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include "corecel/Config.hh"
0010 
0011 #include "corecel/Macros.hh"
0012 
0013 namespace celeritas
0014 {
0015 //---------------------------------------------------------------------------//
0016 /*!
0017  * Install a ROOT Error Handler to redirect the message toward the
0018  * Celeritas Logger.
0019  */
0020 class ScopedRootErrorHandler
0021 {
0022   public:
0023     // Clear ROOT's signal handlers that get installed on startup/activation
0024     static void disable_signal_handler();
0025 
0026     // Install the error handler
0027     ScopedRootErrorHandler();
0028 
0029     // Raise an exception if at least one error has been logged
0030     void throw_if_errors() const;
0031 
0032     // Return to the previous error handler.
0033     ~ScopedRootErrorHandler();
0034     //!@{
0035     //! Prevent copying and moving for RAII class
0036     CELER_DELETE_COPY_MOVE(ScopedRootErrorHandler);
0037     //!@}
0038 
0039   private:
0040     using ErrorHandlerFuncPtr = void (*)(int, bool, char const*, char const*);
0041 
0042     ErrorHandlerFuncPtr previous_{nullptr};
0043     bool prev_errored_{false};
0044 };
0045 
0046 #if !CELERITAS_USE_ROOT
0047 //!@{
0048 //! Do nothing if ROOT is disabled (source file will not be compiled)
0049 inline void ScopedRootErrorHandler::disable_signal_handler() {}
0050 inline ScopedRootErrorHandler::ScopedRootErrorHandler()
0051 {
0052     CELER_DISCARD(previous_);
0053     CELER_DISCARD(prev_errored_);
0054 }
0055 inline ScopedRootErrorHandler::~ScopedRootErrorHandler() {}
0056 inline void ScopedRootErrorHandler::throw_if_errors() const {}
0057 //!@}
0058 #endif
0059 
0060 //---------------------------------------------------------------------------//
0061 }  // namespace celeritas