Loading src/modules/GeometryBuilderGeant4/GeometryBuilderGeant4Module.cpp +4 −0 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ #include "core/config/exceptions.h" #include "core/geometry/GeometryManager.hpp" #include "core/utils/log.h" #include "tools/geant4/G4ExceptionHandler.hpp" #include "tools/geant4/G4LoggingDestination.hpp" #include "tools/geant4/MTRunManager.hpp" #include "tools/geant4/RunManager.hpp" Loading @@ -44,6 +45,9 @@ using namespace ROOT; GeometryBuilderGeant4Module::GeometryBuilderGeant4Module(Configuration& config, Messenger*, GeometryManager* geo_manager) : Module(config), geo_manager_(geo_manager), run_manager_g4_(nullptr) { // Set exception handler for Geant4 exceptions: G4StateManager::GetStateManager()->SetExceptionHandler(new G4ExceptionHandler()); // Enable multithreading for Geant4 if it has been built with support for it: #ifdef G4MULTITHREADED LOG(INFO) << "Detected Geant4 multithreading capabilities, enabling multithreading support"; Loading src/tools/geant4/G4ExceptionHandler.hpp 0 → 100644 +35 −0 Original line number Diff line number Diff line /** * @file * @brief Set of Geant4 utilities for framework integration * @copyright Copyright (c) 2021 CERN and the Allpix Squared authors. * This software is distributed under the terms of the MIT License, copied verbatim in the file "LICENSE.md". * In applying this license, CERN does not waive the privileges and immunities granted to it by virtue of its status as an * Intergovernmental Organization or submit itself to any jurisdiction. */ #ifndef ALLPIX_GEANT4_EXCEPTIONS_H #define ALLPIX_GEANT4_EXCEPTIONS_H #include "core/module/exceptions.h" #include <G4VExceptionHandler.hh> namespace allpix { /** * @brief Exception handler for Geant4 * * This class is registered with the G4StateManager and handles exceptions thrown in the Geant4 framework. It simply * constructs an \ref allpix::ModuleError exception and throws it, for the frameworkto take further action such as * terminating the run */ class G4ExceptionHandler : public G4VExceptionHandler { public: G4bool Notify(const char*, const char* exceptionCode, G4ExceptionSeverity, const char* description) override { throw ModuleError("Caught Geant4 exception " + std::string(exceptionCode) + ": " + std::string(description)); }; }; } // namespace allpix #endif /* ALLPIX_GEANT4_EXCEPTIONS_H */ Loading
src/modules/GeometryBuilderGeant4/GeometryBuilderGeant4Module.cpp +4 −0 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ #include "core/config/exceptions.h" #include "core/geometry/GeometryManager.hpp" #include "core/utils/log.h" #include "tools/geant4/G4ExceptionHandler.hpp" #include "tools/geant4/G4LoggingDestination.hpp" #include "tools/geant4/MTRunManager.hpp" #include "tools/geant4/RunManager.hpp" Loading @@ -44,6 +45,9 @@ using namespace ROOT; GeometryBuilderGeant4Module::GeometryBuilderGeant4Module(Configuration& config, Messenger*, GeometryManager* geo_manager) : Module(config), geo_manager_(geo_manager), run_manager_g4_(nullptr) { // Set exception handler for Geant4 exceptions: G4StateManager::GetStateManager()->SetExceptionHandler(new G4ExceptionHandler()); // Enable multithreading for Geant4 if it has been built with support for it: #ifdef G4MULTITHREADED LOG(INFO) << "Detected Geant4 multithreading capabilities, enabling multithreading support"; Loading
src/tools/geant4/G4ExceptionHandler.hpp 0 → 100644 +35 −0 Original line number Diff line number Diff line /** * @file * @brief Set of Geant4 utilities for framework integration * @copyright Copyright (c) 2021 CERN and the Allpix Squared authors. * This software is distributed under the terms of the MIT License, copied verbatim in the file "LICENSE.md". * In applying this license, CERN does not waive the privileges and immunities granted to it by virtue of its status as an * Intergovernmental Organization or submit itself to any jurisdiction. */ #ifndef ALLPIX_GEANT4_EXCEPTIONS_H #define ALLPIX_GEANT4_EXCEPTIONS_H #include "core/module/exceptions.h" #include <G4VExceptionHandler.hh> namespace allpix { /** * @brief Exception handler for Geant4 * * This class is registered with the G4StateManager and handles exceptions thrown in the Geant4 framework. It simply * constructs an \ref allpix::ModuleError exception and throws it, for the frameworkto take further action such as * terminating the run */ class G4ExceptionHandler : public G4VExceptionHandler { public: G4bool Notify(const char*, const char* exceptionCode, G4ExceptionSeverity, const char* description) override { throw ModuleError("Caught Geant4 exception " + std::string(exceptionCode) + ": " + std::string(description)); }; }; } // namespace allpix #endif /* ALLPIX_GEANT4_EXCEPTIONS_H */