LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
CustomPhysicsFactory.hh
Go to the documentation of this file.
1 //
6 #ifndef CUSTOMPHYSICSFACTORY_hh
7 #define CUSTOMPHYSICSFACTORY_hh
8 
9 #include "Geant4/G4VPhysicsConstructor.hh"
11 
12 namespace larg4 {
13  class CustomPhysicsTable;
14 
16  public:
17  explicit CustomPhysicsFactoryBase(std::string const& name) : fName{name}
18  {
19  if (empty(name))
20  std::cerr << "CustomPhysicsFactory Error : Physics registered with no name!" << std::endl;
21  }
22  virtual ~CustomPhysicsFactoryBase() = default;
23 
24  std::string const& GetName() const noexcept { return fName; }
25 
26  virtual G4VPhysicsConstructor* Build() const = 0;
27 
28  private:
29  std::string fName;
30  };
31 
32  template <class T>
34  public:
35  explicit CustomPhysicsFactory(std::string const& name);
36 
37  G4VPhysicsConstructor* Build() const { return new T{}; }
38  };
39 
40  template <class T>
43  {
44  // register self in physics table - note, factory is actually registered
45  // in static TheCustomPhysicsTable, not the instance created below
46  // which just acts to pass information along
47  new CustomPhysicsTable(this);
48  }
49 }
50 
51 #endif
CustomPhysicsFactory(std::string const &name)
Geant4 interface.
CustomPhysicsFactoryBase(std::string const &name)
virtual G4VPhysicsConstructor * Build() const =0
virtual ~CustomPhysicsFactoryBase()=default
G4VPhysicsConstructor * Build() const
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.
Definition: StdUtils.h:109
std::string const & GetName() const noexcept