Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Geant4Manager.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Geant4Manager.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2023 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #pragma once
10 
11 #include <memory>
12 #include <mutex>
13 #include <string>
14 #include <unordered_map>
15 
16 class G4RunManager;
17 class G4VUserPhysicsList;
18 
19 namespace ActsExamples {
20 
21 class PhysicsListFactory;
22 class Geant4Manager;
23 
38 struct Geant4Handle {
39  std::mutex mutex;
40  int logLevel{};
41  std::unique_ptr<G4RunManager> runManager;
42  G4VUserPhysicsList *physicsList;
44 
45  Geant4Handle(int logLevel, std::unique_ptr<G4RunManager> runManager,
46  std::unique_ptr<G4VUserPhysicsList> physicsList,
48  Geant4Handle(const Geant4Handle &) = delete;
49  Geant4Handle &operator=(const Geant4Handle &) = delete;
50  ~Geant4Handle();
51 
55  void tweakLogging(int level) const;
56 };
57 
60  public:
61  static Geant4Manager &instance();
62 
64  static void tweakLogging(G4RunManager &runManager, int level);
65 
66  std::shared_ptr<Geant4Handle> currentHandle() const;
67 
69  std::shared_ptr<Geant4Handle> createHandle(int logLevel,
70  const std::string &physicsList);
71 
73  std::shared_ptr<Geant4Handle> createHandle(
74  int logLevel, std::unique_ptr<G4VUserPhysicsList> physicsList,
75  std::string physicsListName);
76 
80  std::string name, std::shared_ptr<PhysicsListFactory> physicsListFactory);
81  std::unique_ptr<G4VUserPhysicsList> createPhysicsList(
82  const std::string &name) const;
83 
85  const std::unordered_map<std::string, std::shared_ptr<PhysicsListFactory>>
86  &getPhysicsListFactories() const;
87 
88  private:
89  Geant4Manager();
91 
92  bool m_created = false;
93  std::weak_ptr<Geant4Handle> m_handle;
94  std::unordered_map<std::string, std::shared_ptr<PhysicsListFactory>>
96 };
97 
98 } // namespace ActsExamples