remage
Simulation framework for HPGe-based experiments
 
Loading...
Searching...
No Matches
RMGWorkerInitialization.hh
1// Copyright (C) 2022 Luigi Pertoldi <https://orcid.org/0000-0002-0467-2571>
2//
3// This program is free software: you can redistribute it and/or modify it under
4// the terms of the GNU Lesser General Public License as published by the Free
5// Software Foundation, either version 3 of the License, or (at your option) any
6// later version.
7//
8// This program is distributed in the hope that it will be useful, but WITHOUT
9// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11// details.
12//
13// You should have received a copy of the GNU Lesser General Public License
14// along with this program. If not, see <https://www.gnu.org/licenses/>.
15
16#ifndef _RMG_WORKER_INITIALIZATION_HH_
17#define _RMG_WORKER_INITIALIZATION_HH_
18
19#include <type_traits>
20
21#include "G4AutoLock.hh"
22#include "G4UserTaskThreadInitialization.hh"
23#include "Randomize.hh"
24
25#include "RMGManager.hh"
26
28namespace {
29 G4Mutex RMGWorkerInitializationRNGMutex = G4MUTEX_INITIALIZER;
30} // namespace
32
41template<typename ThreadInitialization>
42class RMGWorkerInitialization : public ThreadInitialization {
43 static_assert(std::is_base_of_v<G4UserWorkerThreadInitialization, ThreadInitialization>);
44
45 public:
46
47 RMGWorkerInitialization() = default;
48 ~RMGWorkerInitialization() = default;
49
53 void SetupRNGEngine(const CLHEP::HepRandomEngine* aRNGEngine) const override {
54 G4AutoLock l(&RMGWorkerInitializationRNGMutex);
55
56 auto rmg_man = RMGManager::Instance();
57 // Implement custom logic if the user had chosen a random engine, otherwise apply Geant4's
58 // default strategy.
59 if (rmg_man->GetRandEngineSelected()) rmg_man->ApplyRandEngineForCurrentThread();
60 else ThreadInitialization::SetupRNGEngine(aRNGEngine);
61 }
62};
63
64#endif
65
66// vim: tabstop=2 shiftwidth=2 expandtab
static RMGManager * Instance()
Retrieves the singleton instance of RMGManager.
Definition RMGManager.hh:75
void SetupRNGEngine(const CLHEP::HepRandomEngine *aRNGEngine) const override
Install the user-selected random engine on this worker, or fall back to Geant4's.
Definition RMGWorkerInitialization.hh:53