test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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>
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
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 
35  : std::map<std::string, AbsFFTJetObjectFactory<Base>*>() {}
36 
38  {
39  for (typename std::map<std::string, AbsFFTJetObjectFactory<Base>*>::
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:
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:
86 };
87 
88 #endif // JetMETCorrections_FFTJetObjects_FFTJetObjectFactory_h
virtual Base * create(const edm::ParameterSet &ps) const =0
DefaultFFTJetObjectFactory & operator=(const DefaultFFTJetObjectFactory &)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
static const Factory & instance()
Derived * create(const edm::ParameterSet &ps) const
#define end
Definition: vmac.h:37
static void registerType(const std::string &className)
#define begin
Definition: vmac.h:30
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