src/tools/geant4/MTRunManager.hpp

The MTRunManager class, defines a custom Geant4 RunManager that works with Allpix threads. More…

Namespaces

Name
allpix
Helper class to hold support layers for a detector model.

Classes

Name
class allpix::MTRunManager
A custom run manager for Geant4 that can work with external threads and be used concurrently.

Detailed Description

The MTRunManager class, defines a custom Geant4 RunManager that works with Allpix threads.

Copyright: Copyright (c) 2019-2025 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. SPDX-License-Identifier: MIT

Source code


#ifndef ALLPIX_MT_RUN_MANAGER_H
#define ALLPIX_MT_RUN_MANAGER_H

#include <unordered_map>

#include <G4MTRunManager.hh>

#include "SensitiveDetectorAndFieldConstruction.hpp"

namespace allpix {

    class WorkerRunManager;

    class MTRunManager : public G4MTRunManager {
        friend class WorkerRunManager;

    public:
        MTRunManager();
        ~MTRunManager() override = default;

        void Run(G4int n_event, uint64_t seed1, uint64_t seed2); // NOLINT

        void Initialize() override;

        void InitializeForThread(); // NOLINT

        void TerminateForThread(); // NOLINT

        SensitiveDetectorAndFieldConstruction* GetSDAndFieldConstruction() const { // NOLINT
            return sd_field_construction_.get();
        } // NOLINT

        void
        SetSDAndFieldConstruction(std::unique_ptr<SensitiveDetectorAndFieldConstruction> sd_field_construction) { // NOLINT
            sd_field_construction_ = std::move(sd_field_construction);
        }

        void AbortRun(G4bool softAbort) override; // NOLINT

    protected:
        WorkerActionRequest ThisWorkerWaitForNextAction() override { return WorkerActionRequest::UNDEFINED; }

        void CreateAndStartWorkers() override {}

        void NewActionRequest(WorkerActionRequest) override {}

        G4bool InitializeSeeds(G4int) override { return true; };

        void RequestWorkersProcessCommandsStack() override {}

        G4bool SetUpAnEvent(G4Event*, long&, long&, long&, G4bool) override { return false; } // NOLINT

        G4int SetUpNEvents(G4Event*, G4SeedsQueue*, G4bool) override { return 0; }

        void TerminateWorkers() override {}

        void ThisWorkerEndEventLoop() override {}

        void ThisWorkerProcessCommandsStackDone() override {}

        void ThisWorkerReady() override {}

        void WaitForEndEventLoopWorkers() override {}

        void WaitForReadyWorkers() override {}

    private:
        // \ref WorkerRunManager worker manager that run on each thread.
        static G4ThreadLocal WorkerRunManager* worker_run_manager_;

        std::unique_ptr<SensitiveDetectorAndFieldConstruction> sd_field_construction_{nullptr};
    };
} // namespace allpix

#endif /* ALLPIX_MT_RUN_MANAGER_H */

Updated on 2025-04-30 at 14:49:41 +0000