Commit 86fe21ad authored by Simon Spannagel's avatar Simon Spannagel
Browse files

Merge branch 'movingExceptionHandler' into 'master'

Moved Geant4 exception handler initialisation to Worker constructors.

See merge request allpix-squared/allpix-squared!824
parents 85efd796 0a8b7761
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -10,5 +10,5 @@ random_seed = 0

[GeometryBuilderGeant4]

#PASS (ERROR) [I:GeometryBuilderGeant4] Overlapping volumes detected.
#PASS (FATAL) [I:GeometryBuilderGeant4] Error during execution of run:\nCaught Geant4 exception GeomVol1002: Overlap with volume already placed
#LABEL coverage
+2 −11
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
#include <utility>

#include <G4GlobalConfig.hh>
#include <G4StateManager.hh>
#include <G4UImanager.hh>
#include <G4UIterminal.hh>
#include <G4Version.hh>
@@ -36,7 +35,6 @@
#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"
@@ -47,9 +45,6 @@ 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";
@@ -126,20 +121,16 @@ void GeometryBuilderGeant4Module::initialize() {
    check_dataset_g4("G4NEUTRONXSDATA");
#endif

    // Suppress all stdout output due to a part in Geant4 where G4cout is not used
    SUPPRESS_STREAM(std::cout);

    // Create the G4 run manager. If multithreading was requested we use the custom run manager
    // that support calling BeamOn operations in parallel. Otherwise we use default manager.
    if(multithreadingEnabled()) {
        LOG(DEBUG) << "Making a multi-thread RunManager";
        run_manager_g4_ = std::make_unique<MTRunManager>();
    } else {
        LOG(DEBUG) << "Making a single-thread RunManager";
        run_manager_g4_ = std::make_unique<RunManager>();
    }

    // Release stdout again
    RELEASE_STREAM(std::cout);

    // Set the geometry construction to use
    run_manager_g4_->SetUserInitialization(geometry_construction_);

+5 −0
Original line number Diff line number Diff line
@@ -13,8 +13,11 @@
#include "G4LoggingDestination.hpp"
#include "WorkerRunManager.hpp"

#include <G4StateManager.hh>
#include <G4UImanager.hh>

#include "tools/geant4/G4ExceptionHandler.hpp"

using namespace allpix;

G4ThreadLocal WorkerRunManager* MTRunManager::worker_run_manager_ = nullptr;
@@ -22,6 +25,8 @@ G4ThreadLocal WorkerRunManager* MTRunManager::worker_run_manager_ = nullptr;
MTRunManager::MTRunManager() {
    G4UImanager* ui_g4 = G4UImanager::GetUIpointer();
    ui_g4->SetCoutDestination(G4LoggingDestination::getInstance());
    // Set exception handler for Geant4 exceptions:
    G4StateManager::GetStateManager()->SetExceptionHandler(new G4ExceptionHandler());
}

void MTRunManager::Run(G4int n_event, uint64_t seed1, uint64_t seed2) { // NOLINT
+6 −0
Original line number Diff line number Diff line
@@ -14,12 +14,18 @@

#include <array>

#include <G4StateManager.hh>
#include <G4UImanager.hh>

#include "tools/geant4/G4ExceptionHandler.hpp"

using namespace allpix;

RunManager::RunManager() {
    G4UImanager* ui_g4 = G4UImanager::GetUIpointer();
    ui_g4->SetCoutDestination(G4LoggingDestination::getInstance());
    // Set exception handler for Geant4 exceptions:
    G4StateManager::GetStateManager()->SetExceptionHandler(new G4ExceptionHandler());
}

void RunManager::Run(G4int n_event, uint64_t seed1, uint64_t seed2) { // NOLINT
+5 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
#include <atomic>

#include <G4MTRunManager.hh>
#include <G4StateManager.hh>
#include <G4Threading.hh>
#include <G4TransportationManager.hh>
#include <G4UImanager.hh>
@@ -29,6 +30,8 @@
#include <G4WorkerRunManager.hh>
#include <G4WorkerThread.hh>

#include "tools/geant4/G4ExceptionHandler.hpp"

using namespace allpix;

namespace {
@@ -39,6 +42,8 @@ namespace {
WorkerRunManager::WorkerRunManager() {
    G4UImanager* ui_g4 = G4UImanager::GetUIpointer();
    ui_g4->SetCoutDestination(G4LoggingDestination::getInstance());
    // Set exception handler for Geant4 exceptions:
    G4StateManager::GetStateManager()->SetExceptionHandler(new G4ExceptionHandler());
}

WorkerRunManager::~WorkerRunManager() {