CMS 3D CMS Logo

/data/git/CMSSW_5_3_11_patch5/src/PhysicsTools/MVAComputer/interface/ProcessRegistry.h

Go to the documentation of this file.
00001 #ifndef PhysicsTools_MVAComputer_ProcessRegistry_h
00002 #define PhysicsTools_MVAComputer_ProcessRegistry_h
00003 // -*- C++ -*-
00004 //
00005 // Package:     MVAComputer
00006 // Class  :     ProcessRegistry
00007 //
00008 
00009 //
00010 // Author:      Christophe Saout <christophe.saout@cern.ch>
00011 // Created:     Sat Apr 24 15:18 CEST 2007
00012 // $Id: ProcessRegistry.h,v 1.9 2011/04/15 17:07:13 wmtan Exp $
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                 static Base_t *create(const char *name,
00071                                       const CalibBase_t *calib,
00072                                       Parent_t *parent = 0);
00073         };
00074 
00075     protected:
00076         friend class Factory;
00077 
00079         ProcessRegistry(const char *name) : name(name)
00080         { registerProcess(name, this); }
00081         virtual ~ProcessRegistry() { unregisterProcess(name); }
00082 
00084         static Base_t *create(const char *name, const CalibBase_t *calib,
00085                               Parent_t *parent);
00086 
00088         virtual Base_t *instance(const char *name, const CalibBase_t *calib,
00089                                  Parent_t *parent) const = 0;
00090 
00091     private:
00092         static void registerProcess(const char *name,
00093                                     const ProcessRegistry *process);
00094         static void unregisterProcess(const char *name);
00095 
00096         typedef std::map<std::string, const ProcessRegistry*> RegistryMap;
00097 
00099         static RegistryMap *getRegistry();
00100 
00101         const char *name;
00102 };
00103 
00104 } // namespace PhysicsTools
00105 
00106 #endif // PhysicsTools_MVAComputer_ProcessRegistry_h