CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ProcessRegistry.h
Go to the documentation of this file.
1 #ifndef PhysicsTools_MVAComputer_ProcessRegistry_h
2 #define PhysicsTools_MVAComputer_ProcessRegistry_h
3 // -*- C++ -*-
4 //
5 // Package: MVAComputer
6 // Class : ProcessRegistry
7 //
8 
9 //
10 // Author: Christophe Saout <christophe.saout@cern.ch>
11 // Created: Sat Apr 24 15:18 CEST 2007
12 // $Id: ProcessRegistry.h,v 1.10 2013/01/17 22:42:55 kukartse Exp $
13 //
14 // Refactoring for gcc 4.7.0 and higher
15 // by Gena Kukartsev following design and advice from Chris Jones
16 // January 2013
17 //
18 
19 
20 
21 #include <string>
22 #include <map>
23 
24 
25 
26 namespace PhysicsTools
27 {
28 
29  // forward declaration
30  template<class Base_t, class CalibBase_t, class Parent_t, class Instance_t, class Calibration_t> class ProcessRegistryImpl;
31 
32 
33 
45  template<class Base_t, class CalibBase_t, class Parent_t>
47  public:
48 
49 
50 #ifndef __GCCXML__
51 
52  // template alias to replace the former Registry class
53  template<class Instance_t, class Calibration_t>
55 
56 #endif
57 
58 
68  class Factory {
69  public:
70  static Base_t *create(const char *name,
71  const CalibBase_t *calib,
72  Parent_t *parent = 0);
73  };
74 
75  protected:
76  friend class Factory;
77 
79  ProcessRegistry(const char *name) : name(name)
80  { registerProcess(name, this); }
82 
84  static Base_t *create(const char *name, const CalibBase_t *calib,
85  Parent_t *parent);
86 
88  virtual Base_t *instance(const char *name, const CalibBase_t *calib,
89  Parent_t *parent) const = 0;
90 
91  private:
92  static void registerProcess(const char *name,
93  const ProcessRegistry *process);
94  static void unregisterProcess(const char *name);
95 
96  typedef std::map<std::string, const ProcessRegistry*> RegistryMap;
97 
99  static RegistryMap *getRegistry();
100 
101  const char *name;
102  }; // class ProcessRegistry
103 
104 
114  template<class Base_t, class CalibBase_t, class Parent_t, class Instance_t, class Calibration_t>
115  class ProcessRegistryImpl : public ProcessRegistry<Base_t, CalibBase_t, Parent_t> {
116  public:
118  protected:
119  Base_t *instance(const char *name, const CalibBase_t *calib,
120  Parent_t *parent) const
121  {
122  return new Instance_t(name,
123  dynamic_cast<const Calibration_t*>(calib),
124  parent);
125  }
126  }; // class ProcessRegistryImpl
127 
128 
129 
130 } // namespace PhysicsTools
131 
132 #endif // PhysicsTools_MVAComputer_ProcessRegistry_h
list parent
Definition: dbtoconf.py:74
static Base_t * create(const char *name, const CalibBase_t *calib, Parent_t *parent)
create an instance of name, given a calibration calib and parent parent
static void unregisterProcess(const char *name)
static void registerProcess(const char *name, const ProcessRegistry *process)
template to generate a registry singleton for a type.
MVATrainerComputer * calib
Definition: MVATrainer.cc:64
Base_t * instance(const char *name, const CalibBase_t *calib, Parent_t *parent) const
virtual method to implement by respective processor instance classes
ProcessRegistry(const char *name)
instantiate registry and registers itself with name
virtual Base_t * instance(const char *name, const CalibBase_t *calib, Parent_t *parent) const =0
virtual method to implement by respective processor instance classes
static Base_t * create(const char *name, const CalibBase_t *calib, Parent_t *parent=0)
std::map< std::string, const ProcessRegistry * > RegistryMap
static RegistryMap * getRegistry()
return map of all registered processes, allocate if necessary
Factory helper class to instantiate a processor.
Generic registry template for polymorphic processor implementations.
tuple process
Definition: LaserDQM_cfg.py:3