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 //
13 // Refactoring for gcc 4.7.0 and higher
14 // by Gena Kukartsev following design and advice from Chris Jones
15 // January 2013
16 //
17 
18 
19 
20 #include <string>
21 #include "tbb/concurrent_unordered_map.h"
22 
23 
24 
25 namespace PhysicsTools
26 {
27 
28  // forward declaration
29  template<class Base_t, class CalibBase_t, class Parent_t, class Instance_t, class Calibration_t> class ProcessRegistryImpl;
30 
31 
32 
44  template<class Base_t, class CalibBase_t, class Parent_t>
46  public:
47 
48 
49 #ifndef __GCCXML__
50 
51  // template alias to replace the former Registry class
52  template<class Instance_t, class Calibration_t>
54 
55 #endif
56 
57 
67  class Factory {
68  public:
69  static Base_t *create(const char *name,
70  const CalibBase_t *calib,
71  Parent_t *parent = 0);
72  };
73 
74  protected:
75  friend class Factory;
76 
78  ProcessRegistry(const char *name) : name(name)
79  { registerProcess(name, this); }
81 
83  static Base_t *create(const char *name, const CalibBase_t *calib,
84  Parent_t *parent);
85 
87  virtual Base_t *instance(const char *name, const CalibBase_t *calib,
88  Parent_t *parent) const = 0;
89 
90  private:
91  static void registerProcess(const char *name,
92  const ProcessRegistry *process);
93  static void unregisterProcess(const char *name);
94 
95  typedef tbb::concurrent_unordered_map<std::string, const ProcessRegistry*> RegistryMap;
96 
98  static RegistryMap *getRegistry();
99 
100  const char *name;
101  }; // class ProcessRegistry
102 
103 
113  template<class Base_t, class CalibBase_t, class Parent_t, class Instance_t, class Calibration_t>
114  class ProcessRegistryImpl : public ProcessRegistry<Base_t, CalibBase_t, Parent_t> {
115  public:
117  protected:
118  Base_t *instance(const char *name, const CalibBase_t *calib,
119  Parent_t *parent) const
120  {
121  return new Instance_t(name,
122  dynamic_cast<const Calibration_t*>(calib),
123  parent);
124  }
125  }; // class ProcessRegistryImpl
126 
127 
128 
129 } // namespace PhysicsTools
130 
131 #endif // PhysicsTools_MVAComputer_ProcessRegistry_h
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
tbb::concurrent_unordered_map< std::string, const ProcessRegistry * > RegistryMap
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)
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