CMS 3D CMS Logo

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.7 2007/08/16 15:23:56 saout 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                 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 } // namespace PhysicsTools
00106 
00107 #include "PhysicsTools/MVAComputer/interface/ProcessRegistry.icc"
00108 
00109 #endif // PhysicsTools_MVAComputer_ProcessRegistry_h

Generated on Tue Jun 9 17:41:20 2009 for CMSSW by  doxygen 1.5.4