Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:59:59

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 geocel/ScopedGeantExceptionHandler.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <memory>
0010 
0011 #include "corecel/Config.hh"
0012 
0013 #include "corecel/Macros.hh"
0014 
0015 class G4VExceptionHandler;
0016 
0017 namespace celeritas
0018 {
0019 //---------------------------------------------------------------------------//
0020 /*!
0021  * Install and clear a Geant exception handler during this class lifetime.
0022  *
0023  * Note that creating a \c G4RunManagerKernel resets the exception
0024  * handler, so errors thrown during setup *CANNOT* be caught by Celeritas, and
0025  * this class can only be used after creating the \c G4RunManager.
0026  *
0027  * \note This error is suitable only for single-threaded runs and multithreaded
0028  * manager thread. The exceptions it throws will terminate a Geant4 worker
0029  * thread.
0030  */
0031 class ScopedGeantExceptionHandler
0032 {
0033   public:
0034     // Construct exception handler
0035     ScopedGeantExceptionHandler();
0036 
0037     // Clear on destruction
0038     ~ScopedGeantExceptionHandler();
0039     //!@{
0040     //! Prevent copying and moving for RAII class
0041     CELER_DELETE_COPY_MOVE(ScopedGeantExceptionHandler);
0042     //!@}
0043 
0044   private:
0045 #if CELERITAS_USE_GEANT4
0046     G4VExceptionHandler* previous_{nullptr};
0047     std::unique_ptr<G4VExceptionHandler> current_;
0048 #endif
0049 };
0050 
0051 #if !CELERITAS_USE_GEANT4
0052 //!@{
0053 //! Do nothing if Geant4 is disabled (source file will not be compiled)
0054 inline ScopedGeantExceptionHandler::ScopedGeantExceptionHandler() {}
0055 inline ScopedGeantExceptionHandler::~ScopedGeantExceptionHandler() {}
0056 //!@}
0057 #endif
0058 
0059 //---------------------------------------------------------------------------//
0060 }  // namespace celeritas