LArSoft  v06_85_00
Liquid Argon Software toolkit - http://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"
10 
11 #ifndef CUSTOMPHYSICSTABLE_hh
12 namespace larg4 { class CustomPhysicsTable; }
13 #endif
14 
15 namespace larg4 {
17  {
18  public:
21 
22  virtual bool Registered() = 0;
23  virtual std::string GetName() = 0;
24  virtual G4VPhysicsConstructor * Build() = 0;
25  };
26 
27  template<class T>
29  {
30  public:
32  CustomPhysicsFactory(std::string);
33  virtual ~CustomPhysicsFactory() {};
34  bool Registered ()
35  {return registered;}
36  std::string GetName()
37  { return myName;}
38  virtual G4VPhysicsConstructor * Build();
39 
40 
41  private:
42  std::string myName;
43  bool registered;
44  bool verbose;
45  };
46 }
48 
49 namespace larg4 {
50 
51  template<class T> G4VPhysicsConstructor * CustomPhysicsFactory<T>::Build()
52  {
53  return new T();
54  }
55 
56  template<class T> CustomPhysicsFactory<T>::CustomPhysicsFactory(std::string Name)
57  {
58 
59  // For debugging.
60  verbose=true;
61 
62  if(Name!="")
63  myName=Name;
64  else
65  std::cerr<<"CustomPhysicsFactory Error : Physics registered with no name!"<<std::endl;
66 
67  // register self in physics table - note, factory is actually registered
68  // in static TheCustomPhysicsTable, not the instance created below
69  // which just acts to pass information along
70  new CustomPhysicsTable(this);
71  registered=true;
72  }
73 
74 
75 
77  {
78  registered=false;
79  }
80 
81 }
82 
83 #endif
84 
85 
86 // Sept 2009 - Ben Jones, MIT
Geant4 interface.
virtual std::string GetName()=0
virtual G4VPhysicsConstructor * Build()=0
virtual G4VPhysicsConstructor * Build()