CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 #include <string>
19 #include "tbb/concurrent_unordered_map.h"
20 
21 namespace PhysicsTools {
22 
23  // forward declaration
24  template <class Base_t, class CalibBase_t, class Parent_t, class Instance_t, class Calibration_t>
26 
38  template <class Base_t, class CalibBase_t, class Parent_t>
40  public:
41 #ifndef __GCCXML__
42 
43  // template alias to replace the former Registry class
44  template <class Instance_t, class Calibration_t>
46 
47 #endif
48 
58  class Factory {
59  public:
60  static Base_t *create(const char *name, const CalibBase_t *calib, Parent_t *parent = 0);
61  };
62 
63  protected:
64  friend class Factory;
65 
67  ProcessRegistry(const char *name) : name(name) { registerProcess(name, this); }
69 
71  static Base_t *create(const char *name, const CalibBase_t *calib, Parent_t *parent);
72 
74  virtual Base_t *instance(const char *name, const CalibBase_t *calib, Parent_t *parent) const = 0;
75 
76  private:
77  static void registerProcess(const char *name, const ProcessRegistry *process);
78  static void unregisterProcess(const char *name);
79 
80  typedef tbb::concurrent_unordered_map<std::string, const ProcessRegistry *> RegistryMap;
81 
83  static RegistryMap *getRegistry();
84 
85  const char *name;
86  }; // class ProcessRegistry
87 
97  template <class Base_t, class CalibBase_t, class Parent_t, class Instance_t, class Calibration_t>
98  class ProcessRegistryImpl : public ProcessRegistry<Base_t, CalibBase_t, Parent_t> {
99  public:
102 
103  protected:
104  Base_t *instance(const char *name, const CalibBase_t *calib, Parent_t *parent) const override {
105  return new Instance_t(name, dynamic_cast<const Calibration_t *>(calib), parent);
106  }
107  }; // class ProcessRegistryImpl
108 
109 } // namespace PhysicsTools
110 
111 #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.
Base_t * instance(const char *name, const CalibBase_t *calib, Parent_t *parent) const override
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)
tbb::concurrent_unordered_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