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:
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 const 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
StaticFFTJetObjectFactory::base_type
Factory::Base::base_type base_type
Definition: FFTJetObjectFactory.h:56
StaticFFTJetObjectFactory::instance
static const Factory & instance()
Definition: FFTJetObjectFactory.h:58
ConcreteFFTJetObjectFactory::create
Derived * create(const edm::ParameterSet &ps) const override
Definition: FFTJetObjectFactory.h:22
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
CustomConfigs.Base
def Base(process)
Definition: CustomConfigs.py:17
mps_fire.end
end
Definition: mps_fire.py:242
ConcreteFFTJetObjectFactory
Definition: FFTJetObjectFactory.h:20
DefaultFFTJetObjectFactory
Definition: FFTJetObjectFactory.h:26
getGTfromDQMFile.obj
obj
Definition: getGTfromDQMFile.py:32
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
AbsFFTJetObjectFactory::create
virtual Base * create(const edm::ParameterSet &ps) const =0
edm::ParameterSet
Definition: ParameterSet.h:47
StaticFFTJetObjectFactory
Definition: FFTJetObjectFactory.h:54
StaticFFTJetObjectFactory::registerType
static void registerType(const std::string &className)
Definition: FFTJetObjectFactory.h:64
DefaultFFTJetObjectFactory::create
Base * create(const std::string &derivedType, const edm::ParameterSet &ps) const
Definition: FFTJetObjectFactory.h:37
DefaultFFTJetObjectFactory::~DefaultFFTJetObjectFactory
virtual ~DefaultFFTJetObjectFactory()
Definition: FFTJetObjectFactory.h:31
std
Definition: JetResolutionObject.h:76
AbsFFTJetObjectFactory
Definition: FFTJetObjectFactory.h:14
Exception
Definition: hltDiff.cc:245
ParameterSetfwd.h
DefaultFFTJetObjectFactory::DefaultFFTJetObjectFactory
DefaultFFTJetObjectFactory()
Definition: FFTJetObjectFactory.h:29
Exception.h
className
std::string className(const T &t)
Definition: ClassName.h:31
genParticles_cff.map
map
Definition: genParticles_cff.py:11
StaticFFTJetObjectFactory::StaticFFTJetObjectFactory
StaticFFTJetObjectFactory()=delete
ConcreteFFTJetObjectFactory::~ConcreteFFTJetObjectFactory
~ConcreteFFTJetObjectFactory() override
Definition: FFTJetObjectFactory.h:21
DefaultFFTJetObjectFactory::base_type
Base base_type
Definition: FFTJetObjectFactory.h:27
DefaultFFTJetObjectFactory::operator=
DefaultFFTJetObjectFactory & operator=(const DefaultFFTJetObjectFactory &)=delete
AbsFFTJetObjectFactory::~AbsFFTJetObjectFactory
virtual ~AbsFFTJetObjectFactory()
Definition: FFTJetObjectFactory.h:15