CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
47 };
48 
49 //
50 // Singleton for the factory
51 //
52 template <class Factory>
54 public:
55  typedef typename Factory::Base::base_type base_type;
56 
57  static const Factory& instance() {
58  static Factory const obj;
59  return obj;
60  }
61 
62  template <class T>
63  static void registerType(const std::string& className) {
64  Factory& rd = const_cast<Factory&>(instance());
65  delete rd[className];
67  }
68 
69  StaticFFTJetObjectFactory() = delete;
70 };
71 
72 #endif // JetMETCorrections_FFTJetObjects_FFTJetObjectFactory_h
virtual Base * create(const edm::ParameterSet &ps) const =0
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()
DefaultFFTJetObjectFactory & operator=(const DefaultFFTJetObjectFactory &)=delete
static void registerType(const std::string &className)
string end
Definition: dataset.py:937
Base * create(const std::string &derivedType, const edm::ParameterSet &ps) const
Derived * create(const edm::ParameterSet &ps) const override
Factory::Base::base_type base_type
std::string className(const T &t)
Definition: ClassName.h:31