CustomPhysicsFactory.hh
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file CustomPhysicsFactory.h
3 //
4 /// \author seligman@nevis.columbia.edu
5 ////////////////////////////////////////////////////////////////////////
6 #ifndef CUSTOMPHYSICSFACTORY_hh
7 #define CUSTOMPHYSICSFACTORY_hh
8 
9 #include "Geant4/G4VPhysicsConstructor.hh"
11 
12 namespace larg4 {
13  class CustomPhysicsTable;
14 
16  public:
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&
25  GetName() const noexcept
26  {
27  return fName;
28  }
29 
30  virtual G4VPhysicsConstructor* Build() const = 0;
31 
32  private:
34  };
35 
36  template <class T>
38  public:
39  explicit CustomPhysicsFactory(std::string const& name);
40 
41  G4VPhysicsConstructor*
42  Build() const
43  {
44  return new T{};
45  }
46  };
47 
48  template <class T>
51  {
52  // register self in physics table - note, factory is actually registered
53  // in static TheCustomPhysicsTable, not the instance created below
54  // which just acts to pass information along
55  new CustomPhysicsTable(this);
56  }
57 }
58 
59 #endif
static QCString name
Definition: declinfo.cpp:673
std::string string
Definition: nybbler.cc:12
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:97
std::string const & GetName() const noexcept
QTextStream & endl(QTextStream &s)