00001 #ifndef PhysicsTools_MVAComputer_ProcessRegistry_h
00002 #define PhysicsTools_MVAComputer_ProcessRegistry_h
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <string>
00016 #include <map>
00017
00018 namespace PhysicsTools {
00019
00031 template<class Base_t, class CalibBase_t, class Parent_t>
00032 class ProcessRegistry {
00033 public:
00043 template<class Instance_t, class Calibration_t>
00044 class Registry : public ProcessRegistry<Base_t, CalibBase_t, Parent_t> {
00045 public:
00046 Registry(const char *name) :
00047 ProcessRegistry<Base_t, CalibBase_t, Parent_t>(name) {}
00048
00049 protected:
00050 Base_t *instance(const char *name, const CalibBase_t *calib,
00051 Parent_t *parent) const
00052 {
00053 return new Instance_t(name,
00054 dynamic_cast<const Calibration_t*>(calib),
00055 parent);
00056 }
00057 };
00058
00068 class Factory {
00069 public:
00070 inline static Base_t *create(const char *name,
00071 const CalibBase_t *calib,
00072 Parent_t *parent = 0)
00073 { return ProcessRegistry::create(name, calib, parent); }
00074 };
00075
00076 protected:
00077 friend class Factory;
00078
00080 ProcessRegistry(const char *name) : name(name)
00081 { registerProcess(name, this); }
00082 virtual ~ProcessRegistry() { unregisterProcess(name); }
00083
00085 static Base_t *create(const char *name, const CalibBase_t *calib,
00086 Parent_t *parent);
00087
00089 virtual Base_t *instance(const char *name, const CalibBase_t *calib,
00090 Parent_t *parent) const = 0;
00091
00092 private:
00093 static void registerProcess(const char *name,
00094 const ProcessRegistry *process);
00095 static void unregisterProcess(const char *name);
00096
00097 typedef std::map<std::string, const ProcessRegistry*> RegistryMap;
00098
00100 static RegistryMap *getRegistry();
00101
00102 const char *name;
00103 };
00104
00105 }
00106
00107 #include "PhysicsTools/MVAComputer/interface/ProcessRegistry.icc"
00108
00109 #endif // PhysicsTools_MVAComputer_ProcessRegistry_h