Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:59:35

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