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>
16  virtual Base* create(const edm::ParameterSet& ps) const = 0;
17 };
18 
19 template <class Base, class Derived>
22  inline Derived* create(const edm::ParameterSet& ps) const override { return new Derived(ps); }
23 };
24 
25 template <class Base>
26 struct DefaultFFTJetObjectFactory : public std::map<std::string, AbsFFTJetObjectFactory<Base>*> {
27  typedef Base base_type;
28 
30 
32  for (typename std::map<std::string, AbsFFTJetObjectFactory<Base>*>::iterator it = this->begin(); it != this->end();
33  ++it)
34  delete it->second;
35  }
36 
37  inline Base* create(const std::string& derivedType, const edm::ParameterSet& ps) const {
38  typename std::map<std::string, AbsFFTJetObjectFactory<Base>*>::const_iterator it = this->find(derivedType);
39  if (it == this->end())
40  throw cms::Exception("KeyNotFound")
41  << "Derived type \"" << derivedType << "\" is not registered with the factory\n";
42  return it->second->create(ps);
43  }
44 
45 private:
47  DefaultFFTJetObjectFactory& operator=(const DefaultFFTJetObjectFactory&) = delete;
48 };
49 
50 //
51 // Singleton for the factory
52 //
53 template <class Factory>
55 public:
56  typedef typename Factory::Base::base_type base_type;
57 
58  static const Factory& instance() {
59  static Factory obj;
60  return obj;
61  }
62 
63  template <class T>
64  static void registerType(const std::string& className) {
65  Factory& rd = const_cast<Factory&>(instance());
66  delete rd[className];
68  }
69 
70 private:
71  StaticFFTJetObjectFactory() = delete;
72 };
73 
74 #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:19
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:31