Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-22 10:31:21

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