File indexing completed on 2025-02-21 09:58:00
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef DD4HEP_CONDITIONSPROCESSOR_H
0014 #define DD4HEP_CONDITIONSPROCESSOR_H
0015
0016
0017 #include <DD4hep/DetElement.h>
0018 #include <DD4hep/Conditions.h>
0019 #include <DD4hep/ConditionsMap.h>
0020
0021
0022 #include <memory>
0023
0024
0025 namespace dd4hep {
0026
0027
0028 namespace cond {
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042 template <typename T> class ConditionsProcessor : public Condition::Processor {
0043
0044 T& processor;
0045 public:
0046
0047 ConditionsProcessor() = delete;
0048
0049 ConditionsProcessor(T& p) : processor(p) {}
0050
0051 ConditionsProcessor(T&& p) = delete;
0052
0053 ConditionsProcessor(ConditionsProcessor&& copy) = default;
0054
0055 ConditionsProcessor(const ConditionsProcessor& copy) = default;
0056
0057 virtual ~ConditionsProcessor() = default;
0058
0059 ConditionsProcessor& operator=(const ConditionsProcessor& copy) = default;
0060
0061 virtual int process(Condition condition) const override {
0062 return (processor)(condition);
0063 }
0064 };
0065
0066 template <typename T> inline
0067 ConditionsProcessor<typename std::remove_reference<T>::type> conditionsProcessor(T&& obj)
0068 { return ConditionsProcessor<typename std::remove_reference<T>::type>(obj); }
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082 template <typename T> class ConditionsProcessorWrapper : public Condition::Processor {
0083 std::unique_ptr<T> processor;
0084 public:
0085
0086 ConditionsProcessorWrapper() = default;
0087
0088 ConditionsProcessorWrapper(T* p) : processor(p) {}
0089
0090 ConditionsProcessorWrapper(const ConditionsProcessorWrapper& copy) = delete;
0091
0092 virtual ~ConditionsProcessorWrapper() = default;
0093
0094 ConditionsProcessorWrapper& operator=(const ConditionsProcessorWrapper& copy) = delete;
0095
0096 virtual int process(Condition c) const override {
0097 return (*(processor.get()))(c);
0098 }
0099 };
0100
0101 template <typename T> inline ConditionsProcessorWrapper<T>* createProcessorWrapper(T* obj) {
0102 return new ConditionsProcessorWrapper<T>(obj);
0103 }
0104
0105 template <typename T> inline ConditionsProcessorWrapper<T> processorWrapper(T* obj) {
0106 return ConditionsProcessorWrapper<T>(obj);
0107 }
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118 template <typename T> class ConditionsCollector {
0119 public:
0120
0121 ConditionsMap& mapping;
0122
0123 T& conditions;
0124 public:
0125
0126 ConditionsCollector(ConditionsMap& m, T& d) : mapping(m), conditions(d) {}
0127
0128 ConditionsCollector(ConditionsMap& m, T&& p) = delete;
0129
0130 ConditionsCollector(ConditionsCollector&& copy) = default;
0131
0132 ConditionsCollector(const ConditionsCollector& copy) = default;
0133
0134 ~ConditionsCollector() = default;
0135
0136 ConditionsCollector& operator=(const ConditionsCollector& copy) = default;
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146 virtual int operator()(DetElement de, int level=0) const final;
0147 };
0148
0149 template <typename T> inline
0150 ConditionsCollector<typename std::remove_reference<T>::type> conditionsCollector(ConditionsMap& m, T&& conditions)
0151 { return ConditionsCollector<typename std::remove_reference<T>::type>(m, conditions); }
0152
0153
0154 }
0155 }
0156 #endif