File indexing completed on 2024-04-06 12:23:37
0001 #ifndef PhysicsTools_MVAComputer_ProcessRegistry_h
0002 #define PhysicsTools_MVAComputer_ProcessRegistry_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #include <string>
0019 #include "oneapi/tbb/concurrent_unordered_map.h"
0020
0021 namespace PhysicsTools {
0022
0023
0024 template <class Base_t, class CalibBase_t, class Parent_t, class Instance_t, class Calibration_t>
0025 class ProcessRegistryImpl;
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038 template <class Base_t, class CalibBase_t, class Parent_t>
0039 class ProcessRegistry {
0040 public:
0041 #ifndef __GCCXML__
0042
0043
0044 template <class Instance_t, class Calibration_t>
0045 using Registry = ProcessRegistryImpl<Base_t, CalibBase_t, Parent_t, Instance_t, Calibration_t>;
0046
0047 #endif
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058 class Factory {
0059 public:
0060 static Base_t *create(const char *name, const CalibBase_t *calib, Parent_t *parent = 0);
0061 };
0062
0063 protected:
0064 friend class Factory;
0065
0066
0067 ProcessRegistry(const char *name) : name(name) { registerProcess(name, this); }
0068 virtual ~ProcessRegistry() { unregisterProcess(name); }
0069
0070
0071 static Base_t *create(const char *name, const CalibBase_t *calib, Parent_t *parent);
0072
0073
0074 virtual Base_t *instance(const char *name, const CalibBase_t *calib, Parent_t *parent) const = 0;
0075
0076 private:
0077 static void registerProcess(const char *name, const ProcessRegistry *process);
0078 static void unregisterProcess(const char *name);
0079
0080 typedef tbb::concurrent_unordered_map<std::string, const ProcessRegistry *> RegistryMap;
0081
0082
0083 static RegistryMap *getRegistry();
0084
0085 const char *name;
0086 };
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097 template <class Base_t, class CalibBase_t, class Parent_t, class Instance_t, class Calibration_t>
0098 class ProcessRegistryImpl : public ProcessRegistry<Base_t, CalibBase_t, Parent_t> {
0099 public:
0100 ProcessRegistryImpl(const char *name) : ProcessRegistry<Base_t, CalibBase_t, Parent_t>(name) {}
0101
0102 protected:
0103 Base_t *instance(const char *name, const CalibBase_t *calib, Parent_t *parent) const override {
0104 return new Instance_t(name, dynamic_cast<const Calibration_t *>(calib), parent);
0105 }
0106 };
0107
0108 }
0109
0110 #endif