CMS 3D CMS Logo

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:
101  : ProcessRegistry<Base_t, CalibBase_t, Parent_t>(name) {}
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
PhysicsTools::ProcessRegistry::name
const char * name
Definition: ProcessRegistry.h:85
PhysicsTools::ProcessRegistry::~ProcessRegistry
virtual ~ProcessRegistry()
Definition: ProcessRegistry.h:68
PhysicsTools::ProcessRegistry::RegistryMap
tbb::concurrent_unordered_map< std::string, const ProcessRegistry * > RegistryMap
Definition: ProcessRegistry.h:80
PhysicsTools::ProcessRegistry::unregisterProcess
static void unregisterProcess(const char *name)
PhysicsTools::ProcessRegistry::registerProcess
static void registerProcess(const char *name, const ProcessRegistry *process)
PhysicsTools::ProcessRegistry::ProcessRegistry
ProcessRegistry(const char *name)
instantiate registry and registers itself with name
Definition: ProcessRegistry.h:67
calib
Definition: CalibElectron.h:12
PhysicsTools::ProcessRegistryImpl::instance
Base_t * instance(const char *name, const CalibBase_t *calib, Parent_t *parent) const override
virtual method to implement by respective processor instance classes
Definition: ProcessRegistry.h:104
PhysicsTools::ProcessRegistry::Factory::create
static Base_t * create(const char *name, const CalibBase_t *calib, Parent_t *parent=0)
LaserDQM_cfg.process
process
Definition: LaserDQM_cfg.py:3
PhysicsTools
Definition: Histogram.h:13
PhysicsTools::ProcessRegistry::getRegistry
static RegistryMap * getRegistry()
return map of all registered processes, allocate if necessary
PhysicsTools::ProcessRegistryImpl
template to generate a registry singleton for a type.
Definition: ProcessRegistry.h:25
PhysicsTools::ProcessRegistry
Generic registry template for polymorphic processor implementations.
Definition: ProcessRegistry.h:39
class-composition.parent
parent
Definition: class-composition.py:98
PhysicsTools::ProcessRegistry::create
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
PhysicsTools::ProcessRegistry::instance
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
PhysicsTools::ProcessRegistry::Factory
Factory helper class to instantiate a processor.
Definition: ProcessRegistry.h:58