CMS 3D CMS Logo

FFTJetObjectFactory.h
Go to the documentation of this file.
1 #ifndef JetMETCorrections_FFTJetObjects_FFTJetObjectFactory_h
2 #define JetMETCorrections_FFTJetObjects_FFTJetObjectFactory_h
3 
4 //
5 // Simple factory for objects which can be constructed from ParameterSet
6 //
7 #include <map>
8 #include <string>
9 
12 
13 template<class Base>
15 {
17  virtual Base* create(const edm::ParameterSet& ps) const = 0;
18 };
19 
20 template<class Base, class Derived>
22 {
24  inline Derived* create(const edm::ParameterSet& ps) const override
25  {return new Derived(ps);}
26 };
27 
28 template<class Base>
30  public std::map<std::string, AbsFFTJetObjectFactory<Base>*>
31 {
32  typedef Base base_type;
33 
36 
38  {
40  iterator it = this->begin(); it != this->end(); ++it)
41  delete it->second;
42  }
43 
44  inline Base* create(const std::string& derivedType,
45  const edm::ParameterSet& ps) const
46  {
47  typename std::map<std::string, AbsFFTJetObjectFactory<Base>*>::
48  const_iterator it = this->find(derivedType);
49  if (it == this->end())
50  throw cms::Exception("KeyNotFound")
51  << "Derived type \"" << derivedType
52  << "\" is not registered with the factory\n";
53  return it->second->create(ps);
54  }
55 
56 private:
58  DefaultFFTJetObjectFactory& operator=(const DefaultFFTJetObjectFactory&) = delete;
59 };
60 
61 //
62 // Singleton for the factory
63 //
64 template <class Factory>
66 {
67 public:
68  typedef typename Factory::Base::base_type base_type;
69 
70  static const Factory& instance()
71  {
72  static Factory obj;
73  return obj;
74  }
75 
76  template <class T>
77  static void registerType(const std::string& className)
78  {
79  Factory& rd = const_cast<Factory&>(instance());
80  delete rd[className];
82  }
83 
84 private:
85  StaticFFTJetObjectFactory() = delete;
86 };
87 
88 #endif // JetMETCorrections_FFTJetObjects_FFTJetObjectFactory_h
static PFTauRenderPlugin instance
virtual Base * create(const edm::ParameterSet &ps) const =0
def Base(process)
Derived * create(const edm::ParameterSet &ps) const override
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
static const Factory & instance()
#define end
Definition: vmac.h:39
static void registerType(const std::string &className)
#define begin
Definition: vmac.h:32
Base * create(const std::string &derivedType, const edm::ParameterSet &ps) const
Factory::Base::base_type base_type
std::string className(const T &t)
Definition: ClassName.h:30